From ccc5555fa94f00095d7350070e220497e2104567 Mon Sep 17 00:00:00 2001 From: Maurice Schreiber Date: Wed, 5 Aug 2015 15:09:21 +0200 Subject: [PATCH 1/3] [openstack] fix subnet update & create regarding to empty vanilla options, add allocation_pools option --- lib/fog/openstack/models/network/subnet.rb | 2 +- .../openstack/requests/network/create_subnet.rb | 2 +- .../openstack/requests/network/update_subnet.rb | 15 ++++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/fog/openstack/models/network/subnet.rb b/lib/fog/openstack/models/network/subnet.rb index 5bf52db77..29dab7b54 100644 --- a/lib/fog/openstack/models/network/subnet.rb +++ b/lib/fog/openstack/models/network/subnet.rb @@ -27,7 +27,7 @@ module Fog end def update - requires :id, :network_id, :cidr, :ip_version + requires :id merge_attributes(service.update_subnet(self.id, self.attributes).body['subnet']) self diff --git a/lib/fog/openstack/requests/network/create_subnet.rb b/lib/fog/openstack/requests/network/create_subnet.rb index db52ae3fd..aad7cef07 100644 --- a/lib/fog/openstack/requests/network/create_subnet.rb +++ b/lib/fog/openstack/requests/network/create_subnet.rb @@ -14,7 +14,7 @@ module Fog vanilla_options = [:name, :gateway_ip, :allocation_pools, :dns_nameservers, :host_routes, :enable_dhcp, :tenant_id] - vanilla_options.reject{ |o| options[o].nil? unless o == :gateway_ip }.each do |key| + vanilla_options.select{ |o| options.key?(o) }.each do |key| data['subnet'][key] = options[key] end diff --git a/lib/fog/openstack/requests/network/update_subnet.rb b/lib/fog/openstack/requests/network/update_subnet.rb index 34a765188..d0e0a9c46 100644 --- a/lib/fog/openstack/requests/network/update_subnet.rb +++ b/lib/fog/openstack/requests/network/update_subnet.rb @@ -5,8 +5,8 @@ module Fog def update_subnet(subnet_id, options = {}) data = { 'subnet' => {} } - vanilla_options = [:name, :gateway_ip, :dns_nameservers, - :host_routes, :enable_dhcp] + vanilla_options = [:name, :gateway_ip, :allocation_pools, + :dns_nameservers, :host_routes, :enable_dhcp] vanilla_options.select{ |o| options.key?(o) }.each do |key| data['subnet'][key] = options[key] end @@ -24,11 +24,12 @@ module Fog def update_subnet(subnet_id, options = {}) response = Excon::Response.new if subnet = list_subnets.body['subnets'].find { |_| _['id'] == subnet_id } - subnet['name'] = options[:name] - subnet['gateway_ip'] = options[:gateway_ip] - subnet['dns_nameservers'] = options[:dns_nameservers] - subnet['host_routes'] = options[:host_routes] - subnet['enable_dhcp'] = options[:enable_dhcp] + subnet['name'] = options[:name] + subnet['gateway_ip'] = options[:gateway_ip] + subnet['dns_nameservers'] = options[:dns_nameservers] + subnet['host_routes'] = options[:host_routes] + subnet['allocation_pools'] = options[:allocation_pools] + subnet['enable_dhcp'] = options[:enable_dhcp] response.body = { 'subnet' => subnet } response.status = 200 response From e4ce9804dec13b7ab13a83b19887d28250bdf127 Mon Sep 17 00:00:00 2001 From: Maurice Schreiber Date: Wed, 5 Aug 2015 15:16:28 +0200 Subject: [PATCH 2/3] [openstack] mock create subnet array options --- lib/fog/openstack/requests/network/create_subnet.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/fog/openstack/requests/network/create_subnet.rb b/lib/fog/openstack/requests/network/create_subnet.rb index aad7cef07..2265de4a2 100644 --- a/lib/fog/openstack/requests/network/create_subnet.rb +++ b/lib/fog/openstack/requests/network/create_subnet.rb @@ -38,9 +38,9 @@ module Fog 'cidr' => cidr, 'ip_version' => ip_version, 'gateway_ip' => options[:gateway_ip], - 'allocation_pools' => options[:allocation_pools], - 'dns_nameservers' => options[:dns_nameservers], - 'host_routes' => options[:host_routes], + 'allocation_pools' => options[:allocation_pools] || [], + 'dns_nameservers' => options[:dns_nameservers] || [], + 'host_routes' => options[:host_routes] || [], 'enable_dhcp' => options[:enable_dhcp], 'tenant_id' => options[:tenant_id] } From 788482b1a9708adec407fbfaf684bc74edbaff42 Mon Sep 17 00:00:00 2001 From: Maurice Schreiber Date: Wed, 5 Aug 2015 15:39:49 +0200 Subject: [PATCH 3/3] [openstack] fix broken subnet test --- lib/fog/openstack/requests/network/create_subnet.rb | 6 +++--- lib/fog/openstack/requests/network/update_subnet.rb | 6 +++--- tests/openstack/requests/network/subnet_tests.rb | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/fog/openstack/requests/network/create_subnet.rb b/lib/fog/openstack/requests/network/create_subnet.rb index 2265de4a2..aad7cef07 100644 --- a/lib/fog/openstack/requests/network/create_subnet.rb +++ b/lib/fog/openstack/requests/network/create_subnet.rb @@ -38,9 +38,9 @@ module Fog 'cidr' => cidr, 'ip_version' => ip_version, 'gateway_ip' => options[:gateway_ip], - 'allocation_pools' => options[:allocation_pools] || [], - 'dns_nameservers' => options[:dns_nameservers] || [], - 'host_routes' => options[:host_routes] || [], + 'allocation_pools' => options[:allocation_pools], + 'dns_nameservers' => options[:dns_nameservers], + 'host_routes' => options[:host_routes], 'enable_dhcp' => options[:enable_dhcp], 'tenant_id' => options[:tenant_id] } diff --git a/lib/fog/openstack/requests/network/update_subnet.rb b/lib/fog/openstack/requests/network/update_subnet.rb index d0e0a9c46..24d87de34 100644 --- a/lib/fog/openstack/requests/network/update_subnet.rb +++ b/lib/fog/openstack/requests/network/update_subnet.rb @@ -26,9 +26,9 @@ module Fog if subnet = list_subnets.body['subnets'].find { |_| _['id'] == subnet_id } subnet['name'] = options[:name] subnet['gateway_ip'] = options[:gateway_ip] - subnet['dns_nameservers'] = options[:dns_nameservers] - subnet['host_routes'] = options[:host_routes] - subnet['allocation_pools'] = options[:allocation_pools] + subnet['dns_nameservers'] = options[:dns_nameservers] || [] + subnet['host_routes'] = options[:host_routes] || [] + subnet['allocation_pools'] = options[:allocation_pools] || [] subnet['enable_dhcp'] = options[:enable_dhcp] response.body = { 'subnet' => subnet } response.status = 200 diff --git a/tests/openstack/requests/network/subnet_tests.rb b/tests/openstack/requests/network/subnet_tests.rb index ada254d39..bb9ac7154 100644 --- a/tests/openstack/requests/network/subnet_tests.rb +++ b/tests/openstack/requests/network/subnet_tests.rb @@ -38,8 +38,8 @@ Shindo.tests('Fog::Network[:openstack] | subnet requests', ['openstack']) do tests('#update_subnet').formats({'subnet' => @subnet_format}) do subnet_id = Fog::Network[:openstack].subnets.all.first.id attributes = {:name => 'subnet_name', :gateway_ip => '10.2.2.1', - :dns_nameservers => [], :host_routes => [], - :enable_dhcp => true} + :allocation_pools => [], :dns_nameservers => [], + :host_routes => [], :enable_dhcp => true} Fog::Network[:openstack].update_subnet(subnet_id, attributes).body end