mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[openstack|network] fixing broken tests; added deprecation warning about removing support for passing model objects into the request layer.
This commit is contained in:
parent
b83441333c
commit
a3472c5af0
4 changed files with 51 additions and 9 deletions
|
@ -32,7 +32,8 @@ module Fog
|
|||
|
||||
def create
|
||||
requires :name
|
||||
response = service.create_router(self.name, self.attributes)
|
||||
|
||||
response = service.create_router(self.name, options)
|
||||
merge_attributes(response.body['router'])
|
||||
|
||||
self
|
||||
|
@ -40,7 +41,7 @@ module Fog
|
|||
|
||||
def update
|
||||
requires :id
|
||||
response = service.update_router(self.id, self.attributes)
|
||||
response = service.update_router(self.id, options)
|
||||
merge_attributes(response.body['router'])
|
||||
self
|
||||
end
|
||||
|
@ -51,6 +52,21 @@ module Fog
|
|||
true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def options
|
||||
options = self.attributes.dup
|
||||
|
||||
if options[:external_gateway_info]
|
||||
if options[:external_gateway_info].is_a?(Fog::Network::OpenStack::Network)
|
||||
options[:external_gateway_info] = { :network_id => options[:external_gateway_info].id }
|
||||
else
|
||||
options[:external_gateway_info] = { :network_id => options[:external_gateway_info]}
|
||||
end
|
||||
end
|
||||
options
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,15 +14,26 @@ module Fog
|
|||
:admin_state_up,
|
||||
:tenant_id,
|
||||
:network_id,
|
||||
:external_gateway_info,
|
||||
:status,
|
||||
:subnet_id
|
||||
]
|
||||
|
||||
vanilla_options.reject{ |o| options[o].nil? }.each do |key|
|
||||
data['router'][key] = options[key]
|
||||
end
|
||||
|
||||
egi = options[:external_gateway_info]
|
||||
if egi
|
||||
if egi.is_a?(Fog::Network::OpenStack::Network)
|
||||
Fog::Logger.deprecation "Passing a model objects into options[:external_gateway_info] is deprecated. \
|
||||
Please pass external external gateway as follows options[:external_gateway_info] = { :network_id => NETWORK_ID }]"
|
||||
data['router'][:external_gateway_info] = { :network_id => egi.id }
|
||||
elsif egi.is_a?(Hash) and egi[:network_id]
|
||||
data['router'][:external_gateway_info] = egi
|
||||
else
|
||||
raise ArgumentError.new('Invalid external_gateway_info attribute')
|
||||
end
|
||||
end
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:expects => [201],
|
||||
|
@ -36,6 +47,18 @@ module Fog
|
|||
def create_router(name, options = {})
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
|
||||
egi = options[:external_gateway_info]
|
||||
if egi
|
||||
if egi.is_a?(Fog::Network::OpenStack::Network)
|
||||
Fog::Logger.deprecation "Passing a model objects into options[:external_gateway_info] is deprecated. \
|
||||
Please pass external external gateway as follows options[:external_gateway_info] = { :network_id => NETWORK_ID }]"
|
||||
data['router'][:external_gateway_info] = { :network_id => egi.id }
|
||||
else egi.is_a?(Hash) and egi[:network_id]
|
||||
data['router'][:external_gateway_info] = egi
|
||||
end
|
||||
end
|
||||
|
||||
data = {
|
||||
'router' => {
|
||||
:id => Fog::Mock.random_numbers(6).to_s,
|
||||
|
|
|
@ -30,6 +30,8 @@ module Fog
|
|||
egi = options[:external_gateway_info]
|
||||
if egi
|
||||
if egi.is_a?(Fog::Network::OpenStack::Network)
|
||||
Fog::Logger.deprecation "Passing a model objects into options[:external_gateway_info] is deprecated. \
|
||||
Please pass external external gateway as follows options[:external_gateway_info] = { :network_id => NETWORK_ID }]"
|
||||
data['router'][:external_gateway_info] = { :network_id => egi.id }
|
||||
elsif egi.is_a?(Hash) and egi[:network_id]
|
||||
data['router'][:external_gateway_info] = egi
|
||||
|
@ -60,11 +62,11 @@ module Fog
|
|||
egi = options[:external_gateway_info]
|
||||
if egi
|
||||
if egi.is_a?(Fog::Network::OpenStack::Network)
|
||||
Fog::Logger.deprecation "Passing a model objects into options[:external_gateway_info] is deprecated. \
|
||||
Please pass external external gateway as follows options[:external_gateway_info] = { :network_id => NETWORK_ID }]"
|
||||
router[:external_gateway_info] = { :network_id => egi.id }
|
||||
elsif egi.is_a?(Hash) and egi[:network_id]
|
||||
else egi.is_a?(Hash) and egi[:network_id]
|
||||
router[:external_gateway_info] = egi
|
||||
else
|
||||
raise ArgumentError.new('Invalid external_gateway_info attribute')
|
||||
end
|
||||
end
|
||||
options.keys.each do |k|
|
||||
|
|
|
@ -11,9 +11,10 @@ Shindo.tests("Fog::Network[:openstack] | router", ['openstack']) do
|
|||
end
|
||||
|
||||
tests('#update') do
|
||||
test 'router name' do
|
||||
test('router name') do
|
||||
@instance.name = 'new_name'
|
||||
@instance.update.name == 'new_name'
|
||||
@instance.update
|
||||
@instance.name == 'new_name'
|
||||
end
|
||||
# Needs code from issue #1598
|
||||
#test 'external_gateway_info' do
|
||||
|
|
Loading…
Reference in a new issue