From 7cff96bfd39513baf52f3f2f99b000b8be4a8041 Mon Sep 17 00:00:00 2001 From: Adan Saenz Date: Mon, 13 Jan 2014 12:27:14 -0600 Subject: [PATCH 1/2] Added Openstack compute support for add_security_group and remove_security_group --- lib/fog/openstack/compute.rb | 2 ++ .../requests/compute/add_security_group.rb | 24 +++++++++++++++++++ .../requests/compute/remove_security_group.rb | 24 +++++++++++++++++++ tests/openstack/requests/compute/helper.rb | 5 ++++ .../requests/compute/server_tests.rb | 11 +++++++++ 5 files changed, 66 insertions(+) create mode 100644 lib/fog/openstack/requests/compute/add_security_group.rb create mode 100644 lib/fog/openstack/requests/compute/remove_security_group.rb diff --git a/lib/fog/openstack/compute.rb b/lib/fog/openstack/compute.rb index 5eb4aafbf..81965765f 100644 --- a/lib/fog/openstack/compute.rb +++ b/lib/fog/openstack/compute.rb @@ -74,6 +74,8 @@ module Fog request :server_diagnostics request :boot_from_snapshot request :reset_server_state + request :add_security_group + request :remove_security_group # Server Extenstions request :get_console_output diff --git a/lib/fog/openstack/requests/compute/add_security_group.rb b/lib/fog/openstack/requests/compute/add_security_group.rb new file mode 100644 index 000000000..0f9b4dc00 --- /dev/null +++ b/lib/fog/openstack/requests/compute/add_security_group.rb @@ -0,0 +1,24 @@ +module Fog + module Compute + class OpenStack + class Real + + def add_security_group(server_id, group_name) + body = {'addSecurityGroup' => { "name" => group_name } } + server_action(server_id, body) + end + + end + + class Mock + + def update_server(server_id, group_name) + response = Excon::Response.new + response.status = 200 + response + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/openstack/requests/compute/remove_security_group.rb b/lib/fog/openstack/requests/compute/remove_security_group.rb new file mode 100644 index 000000000..a9b7ae783 --- /dev/null +++ b/lib/fog/openstack/requests/compute/remove_security_group.rb @@ -0,0 +1,24 @@ +module Fog + module Compute + class OpenStack + class Real + + def remove_security_group(server_id, group_name) + body = {'removeSecurityGroup' => { "name" => group_name } } + server_action(server_id, body) + end + + end + + class Mock + + def update_server(server_id, group_name) + response = Excon::Response.new + response.status = 200 + response + end + + end + end + end +end \ No newline at end of file diff --git a/tests/openstack/requests/compute/helper.rb b/tests/openstack/requests/compute/helper.rb index 43a1b6d9b..ed240284c 100644 --- a/tests/openstack/requests/compute/helper.rb +++ b/tests/openstack/requests/compute/helper.rb @@ -35,3 +35,8 @@ def set_password_enabled pw_enabled = ENV['OPENSTACK_SET_PASSWORD_ENABLED'] || "true" return pw_enabled == "true" end + +def get_security_group_ref + compute = Fog::Compute[:openstack] + ENV['OPENSTACK_SECURITY_GROUP_REF'] || compute.list_security_groups.body['security_groups'].first['name'] +end diff --git a/tests/openstack/requests/compute/server_tests.rb b/tests/openstack/requests/compute/server_tests.rb index f693cd941..2875c6ca5 100644 --- a/tests/openstack/requests/compute/server_tests.rb +++ b/tests/openstack/requests/compute/server_tests.rb @@ -49,6 +49,7 @@ Shindo.tests('Fog::Compute[:openstack] | server requests', ['openstack']) do @image_id = get_image_ref @snapshot_id = nil @flavor_id = get_flavor_ref + @security_group_name = get_security_group_ref tests('#create_server("test", #{@image_id} , 19)').formats(@create_format, false) do data = Fog::Compute[:openstack].create_server("test", @image_id, @flavor_id).body['server'] @@ -112,6 +113,16 @@ Shindo.tests('Fog::Compute[:openstack] | server requests', ['openstack']) do Fog::Compute[:openstack].update_server(@server_id, :name => 'fogupdatedserver') end Fog::Compute[:openstack].servers.get(@server_id).wait_for { ready? } + + #ADD SECURITY GROUP + tests("#add_security_group(#{@server_id}, #{@security_group_name})").succeeds do + Fog::Compute[:openstack].add_security_group(@server_id, @security_group_name) + end + + #REMOVE SECURITY GROUP + tests("#remove_security_group(#{@server_id}, #{@security_group_name})").succeeds do + Fog::Compute[:openstack].remove_security_group(@server_id, @security_group_name) + end #CREATE IMAGE WITH METADATA tests("#create_image(#{@server_id}, 'fog')").formats('image' => @image_format) do From 819e2cdfc2777286643f03c990cdc3181cce856b Mon Sep 17 00:00:00 2001 From: Adan Saenz Date: Tue, 14 Jan 2014 10:27:47 -0600 Subject: [PATCH 2/2] Fixed method names for Mock objects for add/remove_security_group --- lib/fog/openstack/requests/compute/add_security_group.rb | 2 +- lib/fog/openstack/requests/compute/remove_security_group.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/fog/openstack/requests/compute/add_security_group.rb b/lib/fog/openstack/requests/compute/add_security_group.rb index 0f9b4dc00..a5e91e0a0 100644 --- a/lib/fog/openstack/requests/compute/add_security_group.rb +++ b/lib/fog/openstack/requests/compute/add_security_group.rb @@ -12,7 +12,7 @@ module Fog class Mock - def update_server(server_id, group_name) + def add_security_group(server_id, group_name) response = Excon::Response.new response.status = 200 response diff --git a/lib/fog/openstack/requests/compute/remove_security_group.rb b/lib/fog/openstack/requests/compute/remove_security_group.rb index a9b7ae783..3c226f58f 100644 --- a/lib/fog/openstack/requests/compute/remove_security_group.rb +++ b/lib/fog/openstack/requests/compute/remove_security_group.rb @@ -12,7 +12,7 @@ module Fog class Mock - def update_server(server_id, group_name) + def remove_security_group(server_id, group_name) response = Excon::Response.new response.status = 200 response