filters and images tests
This commit is contained in:
parent
7880fa5a58
commit
4dbc43416f
9
devops-service/commands/bootstrap_templates.rb
Normal file
9
devops-service/commands/bootstrap_templates.rb
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
module BootstrapTemplatesCommands
|
||||||
|
|
||||||
|
def get_templates
|
||||||
|
res = []
|
||||||
|
Dir.foreach("#{ENV["HOME"]}/.chef/bootstrap/") {|f| res.push(f[0..-5]) if f.end_with?(".erb")} if File.exists? "#{ENV["HOME"]}/.chef/bootstrap/"
|
||||||
|
res
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@ -1,10 +1,12 @@
|
|||||||
require "db/exceptions/invalid_record"
|
require "db/exceptions/invalid_record"
|
||||||
require "db/mongo/models/mongo_model"
|
require "db/mongo/models/mongo_model"
|
||||||
require "commands/image"
|
require "commands/image"
|
||||||
|
require "commands/bootstrap_templates"
|
||||||
|
|
||||||
class Image < MongoModel
|
class Image < MongoModel
|
||||||
|
|
||||||
include ImageCommands
|
include ImageCommands
|
||||||
|
include BootstrapTemplatesCommands
|
||||||
|
|
||||||
attr_accessor :id, :provider, :remote_user, :name, :bootstrap_template
|
attr_accessor :id, :provider, :remote_user, :name, :bootstrap_template
|
||||||
types :id => {:type => String, :empty => false},
|
types :id => {:type => String, :empty => false},
|
||||||
@ -17,6 +19,11 @@ class Image < MongoModel
|
|||||||
super
|
super
|
||||||
images = get_images(DevopsService.mongo, self.provider)
|
images = get_images(DevopsService.mongo, self.provider)
|
||||||
raise InvalidRecord.new "Invalid image id '#{self.id}' for provider '#{self.provider}', please check image filters" unless images.map{|i| i["id"]}.include?(self.id)
|
raise InvalidRecord.new "Invalid image id '#{self.id}' for provider '#{self.provider}', please check image filters" unless images.map{|i| i["id"]}.include?(self.id)
|
||||||
|
|
||||||
|
if self.bootstrap_template
|
||||||
|
templates = get_templates
|
||||||
|
raise InvalidRecord.new "Invalid bootstrap template '#{self.bootstrap_template}' for image '#{self.id}'" unless templates.include?(self.bootstrap_template)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize p={}
|
def initialize p={}
|
||||||
|
|||||||
@ -14,7 +14,7 @@ Feature: Filters
|
|||||||
"08093b30-8393-42c3-8fb3-c4df56deb967"
|
"08093b30-8393-42c3-8fb3-c4df56deb967"
|
||||||
]
|
]
|
||||||
"""
|
"""
|
||||||
Then response should be '415'
|
Then response should be '406'
|
||||||
|
|
||||||
@openstack
|
@openstack
|
||||||
Scenario: Add openstack image filter without header 'Content-Type'
|
Scenario: Add openstack image filter without header 'Content-Type'
|
||||||
@ -24,7 +24,7 @@ Feature: Filters
|
|||||||
"08093b30-8393-42c3-8fb3-c4df56deb967"
|
"08093b30-8393-42c3-8fb3-c4df56deb967"
|
||||||
]
|
]
|
||||||
"""
|
"""
|
||||||
Then response should be '406'
|
Then response should be '415'
|
||||||
|
|
||||||
@openstack
|
@openstack
|
||||||
Scenario: Add openstack image filter, invalid body: empty
|
Scenario: Add openstack image filter, invalid body: empty
|
||||||
@ -109,7 +109,7 @@ Feature: Filters
|
|||||||
"ami-63071b0a"
|
"ami-63071b0a"
|
||||||
]
|
]
|
||||||
"""
|
"""
|
||||||
Then response should be '415'
|
Then response should be '406'
|
||||||
|
|
||||||
@ec2
|
@ec2
|
||||||
Scenario: Add ec2 image filter without header 'Content-Type'
|
Scenario: Add ec2 image filter without header 'Content-Type'
|
||||||
@ -119,7 +119,7 @@ Feature: Filters
|
|||||||
"ami-63071b0a"
|
"ami-63071b0a"
|
||||||
]
|
]
|
||||||
"""
|
"""
|
||||||
Then response should be '406'
|
Then response should be '415'
|
||||||
|
|
||||||
@ec2
|
@ec2
|
||||||
Scenario: Add ec2 image filter, invalid body: empty
|
Scenario: Add ec2 image filter, invalid body: empty
|
||||||
|
|||||||
@ -121,6 +121,20 @@ Feature: Manage images
|
|||||||
When I send GET '/v2.0/image/foo' query with user without privileges
|
When I send GET '/v2.0/image/foo' query with user without privileges
|
||||||
Then response should be '401'
|
Then response should be '401'
|
||||||
|
|
||||||
|
@openstack
|
||||||
|
Scenario: Create openstack image with ec2 provider
|
||||||
|
When I send POST '/v2.0/image' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "ec2",
|
||||||
|
"name": "freebsd-10.0",
|
||||||
|
"remote_user": "root",
|
||||||
|
"bootstrap_template": "chef_freebsd",
|
||||||
|
"id": "08093b30-8393-42c3-8fb3-c4df56deb967"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
@openstack
|
@openstack
|
||||||
Scenario: Create openstack image with invalid provider
|
Scenario: Create openstack image with invalid provider
|
||||||
When I send POST '/v2.0/image' query with JSON body
|
When I send POST '/v2.0/image' query with JSON body
|
||||||
@ -247,6 +261,20 @@ Feature: Manage images
|
|||||||
"""
|
"""
|
||||||
Then response should be '400'
|
Then response should be '400'
|
||||||
|
|
||||||
|
@openstack
|
||||||
|
Scenario: Create openstack image with invalid bootstrap_template - unknown
|
||||||
|
When I send POST '/v2.0/image' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "openstack",
|
||||||
|
"name": "freebsd-10.0",
|
||||||
|
"remote_user": "root",
|
||||||
|
"bootstrap_template": "unknown",
|
||||||
|
"id": "08093b30-8393-42c3-8fb3-c4df56deb967"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
@openstack
|
@openstack
|
||||||
Scenario: Create openstack image with invalid id - array
|
Scenario: Create openstack image with invalid id - array
|
||||||
When I send POST '/v2.0/image' query with JSON body
|
When I send POST '/v2.0/image' query with JSON body
|
||||||
@ -290,6 +318,20 @@ Feature: Manage images
|
|||||||
Then response should be '201'
|
Then response should be '201'
|
||||||
And the Content-Type header should include 'application/json'
|
And the Content-Type header should include 'application/json'
|
||||||
|
|
||||||
|
@ec2
|
||||||
|
Scenario: Create ec2 image with openstack provider
|
||||||
|
When I send POST '/v2.0/image' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "openstack",
|
||||||
|
"name": "test-ec2",
|
||||||
|
"remote_user": "ec2-user",
|
||||||
|
"bootstrap_template": null,
|
||||||
|
"id": "ami-63071b0a"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
@ec2
|
@ec2
|
||||||
Scenario: Create ec2 image with invalid provider
|
Scenario: Create ec2 image with invalid provider
|
||||||
When I send POST '/v2.0/image' query with JSON body
|
When I send POST '/v2.0/image' query with JSON body
|
||||||
@ -416,6 +458,20 @@ Feature: Manage images
|
|||||||
"""
|
"""
|
||||||
Then response should be '400'
|
Then response should be '400'
|
||||||
|
|
||||||
|
@ec2
|
||||||
|
Scenario: Create ec2 image with invalid bootstrap_template - unknown
|
||||||
|
When I send POST '/v2.0/image' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "ec2",
|
||||||
|
"name": "test-ec2",
|
||||||
|
"remote_user": "ec2-user",
|
||||||
|
"bootstrap_template": "unknown",
|
||||||
|
"id": "ami-63071b0a"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
@ec2
|
@ec2
|
||||||
Scenario: Create ec2 image with invalid id - array
|
Scenario: Create ec2 image with invalid id - array
|
||||||
When I send POST '/v2.0/image' query with JSON body
|
When I send POST '/v2.0/image' query with JSON body
|
||||||
@ -460,7 +516,7 @@ Feature: Manage images
|
|||||||
And the Content-Type header should include 'application/json'
|
And the Content-Type header should include 'application/json'
|
||||||
|
|
||||||
@ec2
|
@ec2
|
||||||
Scenario: Get info for single image
|
Scenario: Get info for single ec2 image
|
||||||
When I send GET '/v2.0/image/ami-63071b0a' query
|
When I send GET '/v2.0/image/ami-63071b0a' query
|
||||||
Then response should be '200'
|
Then response should be '200'
|
||||||
And the Content-Type header should include 'application/json'
|
And the Content-Type header should include 'application/json'
|
||||||
@ -475,3 +531,38 @@ Feature: Manage images
|
|||||||
"id": "ami-63071b0a"
|
"id": "ami-63071b0a"
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ec2
|
||||||
|
Scenario: Get info for single ec2 image without headers 'Accept'
|
||||||
|
When I send GET '/v2.0/image/ami-63071b0a' query without headers 'Accept'
|
||||||
|
Then response should be '406'
|
||||||
|
|
||||||
|
@openstack
|
||||||
|
Scenario: Get info for single openstack image
|
||||||
|
When I send GET '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query
|
||||||
|
Then response should be '200'
|
||||||
|
And the Content-Type header should include 'application/json'
|
||||||
|
And the JSON response should be an object
|
||||||
|
And response should be JSON object like:
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "openstack",
|
||||||
|
"name": "freebsd-10.0",
|
||||||
|
"remote_user": "root",
|
||||||
|
"bootstrap_template": "chef_freebsd",
|
||||||
|
"id": "08093b30-8393-42c3-8fb3-c4df56deb967"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
@openstack
|
||||||
|
Scenario: Get info for single openstack image without headers 'Accept'
|
||||||
|
When I send GET '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query without headers 'Accept'
|
||||||
|
Then response should be '406'
|
||||||
|
|
||||||
|
Scenario: Get info for single unknown image
|
||||||
|
When I send GET '/v2.0/image/foo' query
|
||||||
|
Then response should be '404'
|
||||||
|
|
||||||
|
Scenario: Get image path
|
||||||
|
When I send GET '/v2.0/image' query
|
||||||
|
Then response should be '404'
|
||||||
|
|||||||
@ -1,23 +0,0 @@
|
|||||||
@image
|
|
||||||
Feature: delete image
|
|
||||||
|
|
||||||
@openstack
|
|
||||||
Scenario: Delete openstack image with user without privileges
|
|
||||||
When I send DELETE '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query with user without privileges
|
|
||||||
Then response should be '401'
|
|
||||||
|
|
||||||
@openstack
|
|
||||||
Scenario: Delete openstack image
|
|
||||||
When I send DELETE '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query
|
|
||||||
Then response should be '200'
|
|
||||||
|
|
||||||
@ec2
|
|
||||||
Scenario: Delete ec2 image with user without privileges
|
|
||||||
When I send DELETE '/v2.0/image/ami-63071b0a' query with user without privileges
|
|
||||||
Then response should be '401'
|
|
||||||
|
|
||||||
@ec2
|
|
||||||
Scenario: Delete ec2 image
|
|
||||||
When I send DELETE '/v2.0/image/ami-63071b0a' query
|
|
||||||
Then response should be '200'
|
|
||||||
|
|
||||||
442
devops-service/features/api_v2/20_update/10_image.feature
Normal file
442
devops-service/features/api_v2/20_update/10_image.feature
Normal file
@ -0,0 +1,442 @@
|
|||||||
|
@image
|
||||||
|
Feature: Update images
|
||||||
|
|
||||||
|
@openstack
|
||||||
|
Scenario: Update openstack image with ec2 provider
|
||||||
|
When I send PUT '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "ec2",
|
||||||
|
"name": "freebsd-10.0",
|
||||||
|
"remote_user": "root",
|
||||||
|
"bootstrap_template": "chef_freebsd",
|
||||||
|
"id": "08093b30-8393-42c3-8fb3-c4df56deb967"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
|
@openstack
|
||||||
|
Scenario: Update openstack image with invalid provider
|
||||||
|
When I send PUT '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "foo",
|
||||||
|
"name": "freebsd-10.0",
|
||||||
|
"remote_user": "root",
|
||||||
|
"bootstrap_template": "chef_freebsd",
|
||||||
|
"id": "08093b30-8393-42c3-8fb3-c4df56deb967"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
|
@openstack
|
||||||
|
Scenario: Update openstack image with invalid provider - array
|
||||||
|
When I send PUT '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": ["foo"],
|
||||||
|
"name": "freebsd-10.0",
|
||||||
|
"remote_user": "root",
|
||||||
|
"bootstrap_template": "chef_freebsd",
|
||||||
|
"id": "08093b30-8393-42c3-8fb3-c4df56deb967"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
|
@openstack
|
||||||
|
Scenario: Update openstack image with invalid provider - hash
|
||||||
|
When I send PUT '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": {},
|
||||||
|
"name": "freebsd-10.0",
|
||||||
|
"remote_user": "root",
|
||||||
|
"bootstrap_template": "chef_freebsd",
|
||||||
|
"id": "08093b30-8393-42c3-8fb3-c4df56deb967"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
|
@openstack
|
||||||
|
Scenario: Update openstack image with invalid name - hash
|
||||||
|
When I send PUT '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "openstack",
|
||||||
|
"name": {},
|
||||||
|
"remote_user": "root",
|
||||||
|
"bootstrap_template": "chef_freebsd",
|
||||||
|
"id": "08093b30-8393-42c3-8fb3-c4df56deb967"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
|
@openstack
|
||||||
|
Scenario: Update openstack image with invalid name - array
|
||||||
|
When I send PUT '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "openstack",
|
||||||
|
"name": [],
|
||||||
|
"remote_user": "root",
|
||||||
|
"bootstrap_template": "chef_freebsd",
|
||||||
|
"id": "08093b30-8393-42c3-8fb3-c4df56deb967"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
|
@openstack
|
||||||
|
Scenario: Update openstack image with invalid remote_user - hash
|
||||||
|
When I send PUT '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "openstack",
|
||||||
|
"name": "freebsd-10.0",
|
||||||
|
"remote_user": {},
|
||||||
|
"bootstrap_template": "chef_freebsd",
|
||||||
|
"id": "08093b30-8393-42c3-8fb3-c4df56deb967"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
|
@openstack
|
||||||
|
Scenario: Update openstack image with invalid remote_user - array
|
||||||
|
When I send PUT '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "openstack",
|
||||||
|
"name": "freebsd-10.0",
|
||||||
|
"remote_user": [],
|
||||||
|
"bootstrap_template": "chef_freebsd",
|
||||||
|
"id": "08093b30-8393-42c3-8fb3-c4df56deb967"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
|
@openstack
|
||||||
|
Scenario: Update openstack image with invalid bootstrap_template - array
|
||||||
|
When I send PUT '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "openstack",
|
||||||
|
"name": "freebsd-10.0",
|
||||||
|
"remote_user": "root",
|
||||||
|
"bootstrap_template": [],
|
||||||
|
"id": "08093b30-8393-42c3-8fb3-c4df56deb967"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
|
@openstack
|
||||||
|
Scenario: Update openstack image with invalid bootstrap_template - hash
|
||||||
|
When I send PUT '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "openstack",
|
||||||
|
"name": "freebsd-10.0",
|
||||||
|
"remote_user": "root",
|
||||||
|
"bootstrap_template": {},
|
||||||
|
"id": "08093b30-8393-42c3-8fb3-c4df56deb967"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
|
@openstack
|
||||||
|
Scenario: Update openstack image with invalid bootstrap_template - unknown
|
||||||
|
When I send PUT '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "openstack",
|
||||||
|
"name": "freebsd-10.0",
|
||||||
|
"remote_user": "root",
|
||||||
|
"bootstrap_template": "unknown",
|
||||||
|
"id": "08093b30-8393-42c3-8fb3-c4df56deb967"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
|
@openstack
|
||||||
|
Scenario: Update openstack image with invalid id - array
|
||||||
|
When I send PUT '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "openstack",
|
||||||
|
"name": "freebsd-10.0",
|
||||||
|
"remote_user": "root",
|
||||||
|
"bootstrap_template": "chef_freebsd",
|
||||||
|
"id": []
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '200'
|
||||||
|
And the Content-Type header should include 'application/json'
|
||||||
|
And the JSON response should be an object
|
||||||
|
And response should be JSON object like:
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"message" : "Image '08093b30-8393-42c3-8fb3-c4df56deb967' has been updated"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
@openstack
|
||||||
|
Scenario: Update openstack image with invalid id - hash
|
||||||
|
When I send PUT '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "openstack",
|
||||||
|
"name": "freebsd-10.0",
|
||||||
|
"remote_user": "root",
|
||||||
|
"bootstrap_template": "chef_freebsd",
|
||||||
|
"id": {}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '200'
|
||||||
|
And the Content-Type header should include 'application/json'
|
||||||
|
And the JSON response should be an object
|
||||||
|
And response should be JSON object like:
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"message" : "Image '08093b30-8393-42c3-8fb3-c4df56deb967' has been updated"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
@openstack
|
||||||
|
Scenario: Update openstack image
|
||||||
|
When I send PUT '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "openstack",
|
||||||
|
"name": "freebsd-10.0",
|
||||||
|
"remote_user": "root",
|
||||||
|
"bootstrap_template": "chef_freebsd",
|
||||||
|
"id": "08093b30-8393-42c3-8fb3-c4df56deb967"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '200'
|
||||||
|
And the Content-Type header should include 'application/json'
|
||||||
|
And the JSON response should be an object
|
||||||
|
And response should be JSON object like:
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"message" : "Image '08093b30-8393-42c3-8fb3-c4df56deb967' has been updated"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
@ec2
|
||||||
|
Scenario: Update ec2 image with openstack provider
|
||||||
|
When I send PUT '/v2.0/image/ami-63071b0a' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "openstack",
|
||||||
|
"name": "test-ec2",
|
||||||
|
"remote_user": "ec2-user",
|
||||||
|
"bootstrap_template": null,
|
||||||
|
"id": "ami-63071b0a"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
|
@ec2
|
||||||
|
Scenario: Update ec2 image with invalid provider
|
||||||
|
When I send PUT '/v2.0/image/ami-63071b0a' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "foo",
|
||||||
|
"name": "test-ec2",
|
||||||
|
"remote_user": "ec2-user",
|
||||||
|
"bootstrap_template": null,
|
||||||
|
"id": "ami-63071b0a"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
|
@ec2
|
||||||
|
Scenario: Update ec2 image with invalid provider - array
|
||||||
|
When I send PUT '/v2.0/image/ami-63071b0a' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": ["foo"],
|
||||||
|
"name": "test-ec2",
|
||||||
|
"remote_user": "ec2-user",
|
||||||
|
"bootstrap_template": null,
|
||||||
|
"id": "ami-63071b0a"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
|
@ec2
|
||||||
|
Scenario: Update ec2 image with invalid provider - hash
|
||||||
|
When I send PUT '/v2.0/image/ami-63071b0a' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": {},
|
||||||
|
"name": "test-ec2",
|
||||||
|
"remote_user": "ec2-user",
|
||||||
|
"bootstrap_template": null,
|
||||||
|
"id": "ami-63071b0a"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
|
@ec2
|
||||||
|
Scenario: Update ec2 image with invalid name - hash
|
||||||
|
When I send PUT '/v2.0/image/ami-63071b0a' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "ec2",
|
||||||
|
"name": {},
|
||||||
|
"remote_user": "ec2-user",
|
||||||
|
"bootstrap_template": null,
|
||||||
|
"id": "ami-63071b0a"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
|
@ec2
|
||||||
|
Scenario: Update ec2 image with invalid name - array
|
||||||
|
When I send PUT '/v2.0/image/ami-63071b0a' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "ec2",
|
||||||
|
"name": [],
|
||||||
|
"remote_user": "ec2-user",
|
||||||
|
"bootstrap_template": null,
|
||||||
|
"id": "ami-63071b0a"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
|
@ec2
|
||||||
|
Scenario: Update ec2 image with invalid remote_user - hash
|
||||||
|
When I send PUT '/v2.0/image/ami-63071b0a' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "ec2",
|
||||||
|
"name": "test-ec2",
|
||||||
|
"remote_user": {},
|
||||||
|
"bootstrap_template": null,
|
||||||
|
"id": "ami-63071b0a"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
|
@ec2
|
||||||
|
Scenario: Update ec2 image with invalid remote_user - array
|
||||||
|
When I send PUT '/v2.0/image/ami-63071b0a' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "ec2",
|
||||||
|
"name": "test-ec2",
|
||||||
|
"remote_user": [],
|
||||||
|
"bootstrap_template": null,
|
||||||
|
"id": "ami-63071b0a"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
|
@ec2
|
||||||
|
Scenario: Update ec2 image with invalid bootstrap_template - array
|
||||||
|
When I send PUT '/v2.0/image/ami-63071b0a' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "ec2",
|
||||||
|
"name": "test-ec2",
|
||||||
|
"remote_user": "ec2-user",
|
||||||
|
"bootstrap_template": [],
|
||||||
|
"id": "ami-63071b0a"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
|
@ec2
|
||||||
|
Scenario: Update ec2 image with invalid bootstrap_template - hash
|
||||||
|
When I send PUT '/v2.0/image/ami-63071b0a' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "ec2",
|
||||||
|
"name": "test-ec2",
|
||||||
|
"remote_user": "ec2-user",
|
||||||
|
"bootstrap_template": {},
|
||||||
|
"id": "ami-63071b0a"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
|
@ec2
|
||||||
|
Scenario: Update ec2 image with invalid bootstrap_template - unknown
|
||||||
|
When I send PUT '/v2.0/image/ami-63071b0a' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "ec2",
|
||||||
|
"name": "test-ec2",
|
||||||
|
"remote_user": "ec2-user",
|
||||||
|
"bootstrap_template": "unknown",
|
||||||
|
"id": "ami-63071b0a"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '400'
|
||||||
|
|
||||||
|
@ec2
|
||||||
|
Scenario: Update ec2 image with invalid id - array
|
||||||
|
When I send PUT '/v2.0/image/ami-63071b0a' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "ec2",
|
||||||
|
"name": "test-ec2",
|
||||||
|
"remote_user": "ec2-user",
|
||||||
|
"bootstrap_template": null,
|
||||||
|
"id": []
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '200'
|
||||||
|
And the Content-Type header should include 'application/json'
|
||||||
|
And the JSON response should be an object
|
||||||
|
And response should be JSON object like:
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"message" : "Image '08093b30-8393-42c3-8fb3-c4df56deb967' has been updated"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
@ec2
|
||||||
|
Scenario: Update ec2 image with invalid id - hash
|
||||||
|
When I send PUT '/v2.0/image/ami-63071b0a' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "ec2",
|
||||||
|
"name": "test-ec2",
|
||||||
|
"remote_user": "ec2-user",
|
||||||
|
"bootstrap_template": null,
|
||||||
|
"id": {}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '200'
|
||||||
|
And the Content-Type header should include 'application/json'
|
||||||
|
And the JSON response should be an object
|
||||||
|
And response should be JSON object like:
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"message" : "Image '08093b30-8393-42c3-8fb3-c4df56deb967' has been updated"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
@ec2
|
||||||
|
Scenario: Update ec2 image
|
||||||
|
When I send PUT '/v2.0/image/ami-63071b0a' query with JSON body
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"provider": "ec2",
|
||||||
|
"name": "test-ec2",
|
||||||
|
"remote_user": "ec2-user",
|
||||||
|
"bootstrap_template": null,
|
||||||
|
"id": "ami-63071b0a"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then response should be '200'
|
||||||
|
And the Content-Type header should include 'application/json'
|
||||||
|
And the JSON response should be an object
|
||||||
|
And response should be JSON object like:
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"message" : "Image '08093b30-8393-42c3-8fb3-c4df56deb967' has been updated"
|
||||||
|
}
|
||||||
|
"""
|
||||||
52
devops-service/features/api_v2/90_delete/90_image.feature
Normal file
52
devops-service/features/api_v2/90_delete/90_image.feature
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
@image
|
||||||
|
Feature: delete image
|
||||||
|
|
||||||
|
@openstack
|
||||||
|
Scenario: Delete openstack image with user without privileges
|
||||||
|
When I send DELETE '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query with user without privileges
|
||||||
|
Then response should be '401'
|
||||||
|
|
||||||
|
@openstack
|
||||||
|
Scenario: Delete openstack image without header 'Accept'
|
||||||
|
When I send DELETE '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query without header 'Accept'
|
||||||
|
Then response should be '406'
|
||||||
|
|
||||||
|
@openstack
|
||||||
|
Scenario: Delete openstack image
|
||||||
|
When I send DELETE '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query
|
||||||
|
Then response should be '200'
|
||||||
|
And the Content-Type header should include 'application/json'
|
||||||
|
And the JSON response should be an object
|
||||||
|
And response should be JSON object like:
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"message" : "Image '08093b30-8393-42c3-8fb3-c4df56deb967' has been removed"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
@ec2
|
||||||
|
Scenario: Delete ec2 image with user without privileges
|
||||||
|
When I send DELETE '/v2.0/image/ami-63071b0a' query with user without privileges
|
||||||
|
Then response should be '401'
|
||||||
|
|
||||||
|
@ec2
|
||||||
|
Scenario: Delete ec2 image without header 'Accept'
|
||||||
|
When I send DELETE '/v2.0/image/ami-63071b0a' query without header 'Accept'
|
||||||
|
Then response should be '406'
|
||||||
|
|
||||||
|
@ec2
|
||||||
|
Scenario: Delete ec2 image
|
||||||
|
When I send DELETE '/v2.0/image/ami-63071b0a' query
|
||||||
|
Then response should be '200'
|
||||||
|
And the Content-Type header should include 'application/json'
|
||||||
|
And the JSON response should be an object
|
||||||
|
And response should be JSON object like:
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"message" : "Image 'ami-63071b0a' has been removed"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
Scenario: Delete unknown image
|
||||||
|
When I send DELETE '/v2.0/image/foo' query
|
||||||
|
Then response should be '404'
|
||||||
@ -14,7 +14,7 @@ Feature: Filters
|
|||||||
"08093b30-8393-42c3-8fb3-c4df56deb967"
|
"08093b30-8393-42c3-8fb3-c4df56deb967"
|
||||||
]
|
]
|
||||||
"""
|
"""
|
||||||
Then response should be '415'
|
Then response should be '406'
|
||||||
|
|
||||||
@openstack
|
@openstack
|
||||||
Scenario: Delete openstack image filter without header 'Content-Type'
|
Scenario: Delete openstack image filter without header 'Content-Type'
|
||||||
@ -24,7 +24,7 @@ Feature: Filters
|
|||||||
"08093b30-8393-42c3-8fb3-c4df56deb967"
|
"08093b30-8393-42c3-8fb3-c4df56deb967"
|
||||||
]
|
]
|
||||||
"""
|
"""
|
||||||
Then response should be '406'
|
Then response should be '415'
|
||||||
|
|
||||||
@openstack
|
@openstack
|
||||||
Scenario: Delete openstack image filter, invalid body: empty
|
Scenario: Delete openstack image filter, invalid body: empty
|
||||||
@ -99,7 +99,7 @@ Feature: Filters
|
|||||||
"ami-63071b0a"
|
"ami-63071b0a"
|
||||||
]
|
]
|
||||||
"""
|
"""
|
||||||
Then response should be '415'
|
Then response should be '406'
|
||||||
|
|
||||||
@ec2
|
@ec2
|
||||||
Scenario: Delete ec2 image filter without header 'Content-Type'
|
Scenario: Delete ec2 image filter without header 'Content-Type'
|
||||||
@ -109,7 +109,7 @@ Feature: Filters
|
|||||||
"ami-63071b0a"
|
"ami-63071b0a"
|
||||||
]
|
]
|
||||||
"""
|
"""
|
||||||
Then response should be '406'
|
Then response should be '415'
|
||||||
|
|
||||||
@ec2
|
@ec2
|
||||||
Scenario: Delete ec2 image filter, invalid body: empty
|
Scenario: Delete ec2 image filter, invalid body: empty
|
||||||
@ -31,7 +31,7 @@ When(/^I send POST '(.*)' query with JSON body$/) do |path, body|
|
|||||||
end
|
end
|
||||||
|
|
||||||
When(/^I send POST '(.*)' query with JSON body without header '(.*)'$/) do |path, hs, body|
|
When(/^I send POST '(.*)' query with JSON body without header '(.*)'$/) do |path, hs, body|
|
||||||
headers = DEFAULT_HEADERS.select{|h, v| h == hs}
|
headers = DEFAULT_HEADERS.select{|h, v| h != hs}
|
||||||
res = post_body(path, body, headers)
|
res = post_body(path, body, headers)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -43,8 +43,14 @@ When(/^I send DELETE '(.*)' query with JSON body$/) do |path, body|
|
|||||||
res = delete_body(path, body, DEFAULT_HEADERS)
|
res = delete_body(path, body, DEFAULT_HEADERS)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
When(/^I send DELETE '(.*)' query without header '(.*)'$/) do |path, hs|
|
||||||
|
headers = DEFAULT_HEADERS.select{|h, v| h != hs}
|
||||||
|
puts headers
|
||||||
|
res = delete_body(path, nil, headers)
|
||||||
|
end
|
||||||
|
|
||||||
When(/^I send DELETE '(.*)' query with JSON body without header '(.*)'$/) do |path, hs, body|
|
When(/^I send DELETE '(.*)' query with JSON body without header '(.*)'$/) do |path, hs, body|
|
||||||
headers = DEFAULT_HEADERS.select{|h, v| h == hs}
|
headers = DEFAULT_HEADERS.select{|h, v| h != hs}
|
||||||
res = delete_body(path, body, headers)
|
res = delete_body(path, body, headers)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -61,7 +67,7 @@ When(/^I send PUT '(.*)' query with user without privileges$/) do |path|
|
|||||||
end
|
end
|
||||||
|
|
||||||
When(/^I send PUT '(.*)' query with JSON body without header '(.*)'$/) do |path, hs, body|
|
When(/^I send PUT '(.*)' query with JSON body without header '(.*)'$/) do |path, hs, body|
|
||||||
headers = DEFAULT_HEADERS.select{|h, v| h == hs}
|
headers = DEFAULT_HEADERS.select{|h, v| h != hs}
|
||||||
res = put_body(path, body, headers)
|
res = put_body(path, body, headers)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,13 @@
|
|||||||
require "json"
|
require "json"
|
||||||
require "routes/v2.0/base_routes"
|
require "routes/v2.0/base_routes"
|
||||||
require "providers/provider_factory"
|
require "providers/provider_factory"
|
||||||
|
require "commands/bootstrap_templates"
|
||||||
|
|
||||||
module Version2_0
|
module Version2_0
|
||||||
class BootstrapTemplatesRoutes < BaseRoutes
|
class BootstrapTemplatesRoutes < BaseRoutes
|
||||||
|
|
||||||
|
include BootstrapTemplatesCommands
|
||||||
|
|
||||||
def initialize wrapper
|
def initialize wrapper
|
||||||
super wrapper
|
super wrapper
|
||||||
puts "Bootstrap templates routes initialized"
|
puts "Bootstrap templates routes initialized"
|
||||||
@ -24,9 +27,7 @@ module Version2_0
|
|||||||
get "/templates" do
|
get "/templates" do
|
||||||
check_headers :accept
|
check_headers :accept
|
||||||
check_privileges("templates", "r")
|
check_privileges("templates", "r")
|
||||||
res = []
|
json get_templates
|
||||||
Dir.foreach("#{ENV["HOME"]}/.chef/bootstrap/") {|f| res.push(f[0..-5]) if f.end_with?(".erb")} if File.exists? "#{ENV["HOME"]}/.chef/bootstrap/"
|
|
||||||
json res
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -151,7 +151,7 @@ module Version2_0
|
|||||||
image = Image.new(create_object_from_json_body)
|
image = Image.new(create_object_from_json_body)
|
||||||
image.id = params[:image_id]
|
image.id = params[:image_id]
|
||||||
BaseRoutes.mongo.image_update image
|
BaseRoutes.mongo.image_update image
|
||||||
create_response("Image '#{params[:image_id]}' updated")
|
create_response("Image '#{params[:image_id]}' has been updated")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Delete devops image
|
# Delete devops image
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user