Can not set portgroup mode as a number

When creating portgroup, mode accepts a string or a number, e.g.:
active-backup or 1.

While setting new mode for an existing portgroup will raise an error, if
the mode is passed as a number:

    # openstack --os-baremetal-api-version 1.26 baremetal port group \
    set c42f9bf8-3b5d-4673-b6c1-832c10e4fecf --mode 1
    Invalid input for field/attribute mode. Value: '1'. Wrong type. Expected
    '<type 'unicode'>', got '<type 'int'>' (HTTP 400)

This patch add quotes to mode string to avoid unwanted conversion.

Change-Id: I1bfe6d203c5420f06c8d7ead487250da1847e103
Closes-Bug: #1745099
This commit is contained in:
Kaifeng Wang 2018-01-24 15:10:15 +08:00
parent 26602ce40f
commit 677a4d8235
2 changed files with 18 additions and 1 deletions

View File

@ -379,7 +379,7 @@ class SetBaremetalPortGroup(command.Command):
'add', ["standalone_ports_supported=False"]))
if parsed_args.mode:
properties.extend(utils.args_array_to_patch(
'add', ["mode=%s" % parsed_args.mode]))
'add', ["mode=\"%s\"" % parsed_args.mode]))
if parsed_args.extra:
properties.extend(utils.args_array_to_patch(

View File

@ -546,6 +546,23 @@ class TestBaremetalPortGroupSet(TestBaremetalPortGroup):
[{'path': '/mode', 'value': new_portgroup_mode,
'op': 'add'}])
def test_baremetal_portgroup_set_mode_int(self):
new_portgroup_mode = '4'
arglist = [
baremetal_fakes.baremetal_portgroup_uuid,
'--mode', new_portgroup_mode]
verifylist = [
('portgroup', baremetal_fakes.baremetal_portgroup_uuid),
('mode', new_portgroup_mode)]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self.baremetal_mock.portgroup.update.assert_called_once_with(
baremetal_fakes.baremetal_portgroup_uuid,
[{'path': '/mode', 'value': new_portgroup_mode,
'op': 'add'}])
def test_baremetal_portgroup_set_node_uuid(self):
new_node_uuid = 'nnnnnn-uuuuuuuu'
arglist = [