Fix the neutron-port resource with binding options

Parameters of type dict must be at the end of the
shell command to not cause conflict with the network name

current shell generated

/usr/bin/neutron port-create --format=shell --name=testport \
--fixed-ip ip_address=172.19.0.2 --binding:host_id=aio \
--binding:profile type=dict interface_name=veth1 net-edge1-gw1

this fails since it matches the first word without "--" to the network
name

correct call

/usr/bin/neutron port-create --format=shell --name=testport \
--fixed-ip ip_address=172.19.0.2 --binding:host_id=aio net-edge1-gw1 \
--binding:profile type=dict interface_name=veth1

Change-Id: Iaa24d52f4f42e0535ad2d0aed1c0a67178af091a
This commit is contained in:
Alex Ruiz Estradera 2016-08-24 17:31:48 +02:00
parent 7ad7a07e50
commit 24a60a49d9
3 changed files with 23 additions and 7 deletions

View File

@ -51,6 +51,7 @@ Puppet::Type.type(:neutron_port).provide(
def create
opts = Array.new
dict_opts = Array.new
if @resource[:admin_state_up] == "False"
opts << "--admin-state-down"
@ -60,14 +61,14 @@ Puppet::Type.type(:neutron_port).provide(
# The spec says that multiple ip addresses may be specified, but this
# doesn't seem to work yet.
opts << "--fixed-ip"
opts << @resource[:ip_address].map{|ip|"ip_address=#{ip}"}.join(',')
opts << resource[:ip_address].map{|ip|"ip_address=#{ip}"}.join(',')
end
if @resource[:subnet_name]
# The spec says that multiple subnets may be specified, but this doesn't
# seem to work yet.
opts << "--fixed-ip"
opts << @resource[:subnet_name].map{|s|"subnet_id=#{s}"}.join(',')
opts << resource[:subnet_name].map{|s|"subnet_id=#{s}"}.join(',')
end
if @resource[:tenant_name]
@ -86,7 +87,9 @@ Puppet::Type.type(:neutron_port).provide(
if @resource[:binding_profile]
binding_profile_opts = @resource[:binding_profile].map{|k,v| "#{k}=#{v}"}.join(' ')
opts << "--binding:profile type=dict #{binding_profile_opts}"
dict_opts << "--binding:profile"
dict_opts << "type=dict"
dict_opts << "#{binding_profile_opts}"
end
results = auth_neutron(
@ -94,7 +97,8 @@ Puppet::Type.type(:neutron_port).provide(
"--format=shell",
"--name=#{resource[:name]}",
opts,
resource[:network_name]
resource[:network_name],
dict_opts
)
attrs = self.class.parse_creation_output(results)

View File

@ -0,0 +1,11 @@
---
fixes:
- Parameters of type dict must be at the end of the
shell command to not cause conflict with the network name.
Neutron cli picks up the network name as the first parameter
without "--" prefix, thus tresting type=dict as the network
name instead of the real network name because it comes before.
By providing the special dictionary type commands after the
network name the behaviour of the cli is bypassed and neutron
takes the network name and proceeds interpreting parameters
with special format ( not in the form of --<param>=<value> )

View File

@ -49,7 +49,8 @@ tenant_id="60f9544eb94c42a6b7e8e98c2be981b1"'
provider.expects(:auth_neutron).with('port-create',
'--format=shell', "--name=#{port_attrs[:name]}",
["--tenant_id=#{port_attrs[:tenant_id]}"],
port_attrs[:network_name]).returns(output)
port_attrs[:network_name],
[]).returns(output)
provider.create
end
@ -98,9 +99,9 @@ binding_profile="{\"interface_name\": \"eth1\"}"'
'--format=shell', "--name=#{port_attrs[:name]}",
["--tenant_id=#{port_attrs[:tenant_id]}",
"--binding:host_id=#{port_attrs[:binding_host_id]}",
"--binding:profile type=dict interface_name=#{port_attrs[:binding_profile]['interface_name']}",
],
port_attrs[:network_name]).returns(output)
port_attrs[:network_name],
['--binding:profile','type=dict','interface_name=eth1']).returns(output)
provider.create
end