diff --git a/devops-service/commands/server.rb b/devops-service/commands/server.rb index 8cff5ae..b99b766 100644 --- a/devops-service/commands/server.rb +++ b/devops-service/commands/server.rb @@ -138,6 +138,7 @@ module ServerCommands end bo.close status = $?.to_i + out << "\nBootstrap exit status: #{status}\n" end return status end diff --git a/devops-service/features/api_v2/filter.feature b/devops-service/features/api_v2/00_list/filter.feature similarity index 100% rename from devops-service/features/api_v2/filter.feature rename to devops-service/features/api_v2/00_list/filter.feature diff --git a/devops-service/features/api_v2/flavor.feature b/devops-service/features/api_v2/00_list/flavor.feature similarity index 100% rename from devops-service/features/api_v2/flavor.feature rename to devops-service/features/api_v2/00_list/flavor.feature diff --git a/devops-service/features/api_v2/group.feature b/devops-service/features/api_v2/00_list/group.feature similarity index 100% rename from devops-service/features/api_v2/group.feature rename to devops-service/features/api_v2/00_list/group.feature diff --git a/devops-service/features/api_v2/network.feature b/devops-service/features/api_v2/00_list/network.feature similarity index 100% rename from devops-service/features/api_v2/network.feature rename to devops-service/features/api_v2/00_list/network.feature diff --git a/devops-service/features/api_v2/provider.feature b/devops-service/features/api_v2/00_list/provider.feature similarity index 100% rename from devops-service/features/api_v2/provider.feature rename to devops-service/features/api_v2/00_list/provider.feature diff --git a/devops-service/features/api_v2/templates.feature b/devops-service/features/api_v2/00_list/templates.feature similarity index 100% rename from devops-service/features/api_v2/templates.feature rename to devops-service/features/api_v2/00_list/templates.feature diff --git a/devops-service/features/api_v2/10_create/00_filter.feature b/devops-service/features/api_v2/10_create/00_filter.feature new file mode 100644 index 0000000..2fc767d --- /dev/null +++ b/devops-service/features/api_v2/10_create/00_filter.feature @@ -0,0 +1,29 @@ +@filter +Feature: Filters + + @openstack + Scenario: Add openstack image filter + When I send PUT '/v2.0/filter/openstack/image' query with JSON body + """ + [ + "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 the object should contains key 'images' with array and array should contains strings '08093b30-8393-42c3-8fb3-c4df56deb967' + + @ec2 + Scenario: Add ec2 image filter + When I send PUT '/v2.0/filter/ec2/image' query with JSON body + """ + [ + "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 the object should contains key 'images' with array and array should contains strings 'ami-63071b0a' + diff --git a/devops-service/features/api_v2/20_delete/99_filter.feature b/devops-service/features/api_v2/20_delete/99_filter.feature new file mode 100644 index 0000000..054e9cb --- /dev/null +++ b/devops-service/features/api_v2/20_delete/99_filter.feature @@ -0,0 +1,29 @@ +@filter +Feature: Filters + + @openstack + Scenario: Delete openstack image filter + When I send DELETE '/v2.0/filter/openstack/image' query with JSON body + """ + [ + "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 the object should contains key 'images' with array and array should not contains strings '08093b30-8393-42c3-8fb3-c4df56deb967' + + @ec2 + Scenario: Delete ec2 image filter + When I send DELETE '/v2.0/filter/ec2/image' query with JSON body + """ + [ + "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 the object should contains key 'images' with array and array should not contains strings 'ami-63071b0a' + diff --git a/devops-service/features/step_definitions/http_queries_steps.rb b/devops-service/features/step_definitions/http_queries_steps.rb index 103b542..91ab188 100644 --- a/devops-service/features/step_definitions/http_queries_steps.rb +++ b/devops-service/features/step_definitions/http_queries_steps.rb @@ -27,10 +27,22 @@ When(/^I send POST '(.*)' query with params '(.*)'$/) do |path, params| res = post(path, p, DEFAULT_HEADERS) end +When(/^I send POST '(.*)' query with JSON body$/) do |path, body| + res = post_body(path, body, DEFAULT_HEADERS) +end + When(/^I send DELETE '(.*)' query$/) do |path| delete(path, {}, DEFAULT_HEADERS) end +When(/^I send DELETE '(.*)' query with JSON body$/) do |path, body| + res = delete_body(path, body, DEFAULT_HEADERS) +end + +When(/^I send PUT '(.*)' query with JSON body$/) do |path, body| + res = put_body(path, body, DEFAULT_HEADERS) +end + Then(/^response should be '(\d+)'$/) do |code| assert(code.to_i == last_response.status, "Status is not #{code}, it is #{last_response.status}") end diff --git a/devops-service/features/step_definitions/json_steps.rb b/devops-service/features/step_definitions/json_steps.rb index 178a747..ce6956f 100644 --- a/devops-service/features/step_definitions/json_steps.rb +++ b/devops-service/features/step_definitions/json_steps.rb @@ -20,7 +20,7 @@ end Then(/^the JSON response should be an array$/) do body = JSON.parse(last_response.body) - assert body.is_a?(Array), "Body is not an array" + assert body.is_a?(Array), "Body is not an array: #{last_response.body}" end Then(/^the JSON response should be an object$/) do @@ -42,3 +42,40 @@ Then(/^response should be JSON object like:$/) do |string| assert obj.key?(key), "Object has no key '#{key}'" end end + +Then(/^the array should contains strings '(.*)'$/) do |string| + buf = string.split(",") + array = JSON.parse(last_response.body) + buf.each do |v| + assert array.include?(v), "Array should contains '#{v}'" + end +end + +Then(/^the array should not contains strings '(.*)'$/) do |string| + buf = string.split(",") + array = JSON.parse(last_response.body) + buf.each do |v| + assert !array.include?(v), "Array should not contains '#{v}'" + end +end + +Then(/^the object should contains key '(.*)' with array and array should contains strings '(.*)'$/) do |key, string| + buf = string.split(",") + obj = JSON.parse(last_response.body) + assert obj.key?(key), "Object should has a key '#{key}'" + assert obj[key].is_a?(Array), "Object should has an array '#{key}'" + buf.each do |v| + assert obj[key].include?(v), "'#{key}' array should contains '#{v}'" + end +end + +Then(/^the object should contains key '(.*)' with array and array should not contains strings '(.*)'$/) do |key, string| + buf = string.split(",") + obj = JSON.parse(last_response.body) + assert obj.key?(key), "Object should has a key '#{key}'" + assert obj[key].is_a?(Array), "Object should has an array '#{key}'" + buf.each do |v| + assert !obj[key].include?(v), "'#{key}' array should not contains '#{v}'" + end +end + diff --git a/devops-service/features/support/env.rb b/devops-service/features/support/env.rb index fb25c7b..2f6ff62 100644 --- a/devops-service/features/support/env.rb +++ b/devops-service/features/support/env.rb @@ -73,15 +73,30 @@ class RequestSender end def post path, query, headers={} + post_body(path, JSON.pretty_generate(query), headers) + end + + def post_body path, body, headers={} submit do |http| http.receive_timeout = 0 #!!! bring out to appropriate server step - http.post(create_url(path), JSON.pretty_generate(query), default_headers.merge(headers)) + http.post(create_url(path), body, default_headers.merge(headers)) + end + end + + def put_body path, body, headers={} + submit do |http| + http.receive_timeout = 0 #!!! bring out to appropriate server step + http.put(create_url(path), body, default_headers.merge(headers)) end end def delete path, query, headers={} + delete_body(path, JSON.pretty_generate(query), headers) + end + + def delete_body path, body, headers={} submit do |http| - http.delete(create_url(path), JSON.pretty_generate(query), default_headers.merge(headers)) + http.delete(create_url(path), body, default_headers.merge(headers)) end end