From 05edf5499f22659d82d7594059c6fff97c7b169e Mon Sep 17 00:00:00 2001 From: Vladyslav Drok Date: Tue, 20 Dec 2016 12:32:37 +0200 Subject: [PATCH] Add mode and properties to portgroup OSC plugin This change adds the respective options to the OSC plugin. Related-Bug: #1618754 Change-Id: I90086e2ca83e4e157b5a72b0dd224791f7387a63 --- ironicclient/osc/v1/baremetal_portgroup.py | 46 +++++++++- ironicclient/tests/unit/osc/v1/fakes.py | 8 +- .../unit/osc/v1/test_baremetal_portgroup.py | 87 ++++++++++++++++++- ...roup-mode-properties-0a3023cf905adaef.yaml | 4 +- 4 files changed, 137 insertions(+), 8 deletions(-) diff --git a/ironicclient/osc/v1/baremetal_portgroup.py b/ironicclient/osc/v1/baremetal_portgroup.py index 732e1be87..4c4c9a478 100644 --- a/ironicclient/osc/v1/baremetal_portgroup.py +++ b/ironicclient/osc/v1/baremetal_portgroup.py @@ -58,6 +58,19 @@ class CreateBaremetalPortGroup(command.ShowOne): action='append', help="Record arbitrary key/value metadata. " "Can be specified multiple times.") + parser.add_argument( + '--mode', + help='Mode of the port group. For possible values, refer to ' + 'https://www.kernel.org/doc/Documentation/networking' + '/bonding.txt.') + parser.add_argument( + '--property', + dest='properties', + metavar="", + action='append', + help="Key/value property related to this port group's " + "configuration. Can be specified multiple times." + ) standalone_ports_group = parser.add_mutually_exclusive_group() standalone_ports_group.add_argument( '--support-standalone-ports', @@ -78,7 +91,8 @@ class CreateBaremetalPortGroup(command.ShowOne): self.log.debug("take_action(%s)" % parsed_args) baremetal_client = self.app.client_manager.baremetal - field_list = ['node_uuid', 'address', 'name', 'uuid', 'extra'] + field_list = ['node_uuid', 'address', 'name', 'uuid', 'extra', 'mode', + 'properties'] fields = dict((k, v) for (k, v) in vars(parsed_args).items() if k in field_list and v is not None) if parsed_args.support_standalone_ports: @@ -87,6 +101,7 @@ class CreateBaremetalPortGroup(command.ShowOne): fields['standalone_ports_supported'] = False fields = utils.args_array_to_dict(fields, 'extra') + fields = utils.args_array_to_dict(fields, 'properties') portgroup = baremetal_client.portgroup.create(**fields) data = dict([(f, getattr(portgroup, f, '')) for f in @@ -319,6 +334,18 @@ class SetBaremetalPortGroup(command.Command): help='Extra to set on this baremetal port group ' '(repeat option to set multiple extras).', ) + parser.add_argument( + '--mode', + help='Mode of the port group. For possible values, refer to ' + 'https://www.kernel.org/doc/Documentation/networking' + '/bonding.txt.') + parser.add_argument( + '--property', + dest='properties', + metavar="", + action='append', + help="Key/value property related to this port group's " + "configuration (repeat option to set multiple properties).") standalone_ports_group = parser.add_mutually_exclusive_group() standalone_ports_group.add_argument( '--support-standalone-ports', @@ -358,10 +385,16 @@ class SetBaremetalPortGroup(command.Command): if parsed_args.unsupport_standalone_ports: properties.extend(utils.args_array_to_patch( 'add', ["standalone_ports_supported=False"])) + if parsed_args.mode: + properties.extend(utils.args_array_to_patch( + 'add', ["mode=%s" % parsed_args.mode])) if parsed_args.extra: properties.extend(utils.args_array_to_patch( 'add', ['extra/' + x for x in parsed_args.extra])) + if parsed_args.properties: + properties.extend(utils.args_array_to_patch( + 'add', ['properties/' + x for x in parsed_args.properties])) if properties: baremetal_client.portgroup.update(parsed_args.portgroup, @@ -399,6 +432,14 @@ class UnsetBaremetalPortGroup(command.Command): help='Extra to unset on this baremetal port group ' '(repeat option to unset multiple extras).', ) + parser.add_argument( + "--property", + dest='properties', + metavar="", + action='append', + help='Property to unset on this baremetal port group ' + '(repeat option to unset multiple properties).', + ) return parser @@ -417,6 +458,9 @@ class UnsetBaremetalPortGroup(command.Command): if parsed_args.extra: properties.extend(utils.args_array_to_patch('remove', ['extra/' + x for x in parsed_args.extra])) + if parsed_args.properties: + properties.extend(utils.args_array_to_patch( + 'remove', ['properties/' + x for x in parsed_args.properties])) if properties: baremetal_client.portgroup.update(parsed_args.portgroup, diff --git a/ironicclient/tests/unit/osc/v1/fakes.py b/ironicclient/tests/unit/osc/v1/fakes.py index c7522f598..665192aed 100644 --- a/ironicclient/tests/unit/osc/v1/fakes.py +++ b/ironicclient/tests/unit/osc/v1/fakes.py @@ -77,14 +77,20 @@ BAREMETAL_DRIVER_PASSTHRU = {"lookup": {"attach": "false", baremetal_portgroup_uuid = 'ppp-gggggg-pppp' baremetal_portgroup_name = 'Portgroup-name' baremetal_portgroup_address = 'AA:BB:CC:CC:BB:AA' +baremetal_portgroup_mode = 'active-backup' baremetal_portgroup_extra = {'key1': 'value1', 'key2': 'value2'} +baremetal_portgroup_properties = {'key1': 'value11', + 'key2': 'value22'} PORTGROUP = {'uuid': baremetal_portgroup_uuid, 'name': baremetal_portgroup_name, 'node_uuid': baremetal_uuid, 'address': baremetal_portgroup_address, - 'extra': baremetal_portgroup_extra} + 'extra': baremetal_portgroup_extra, + 'mode': baremetal_portgroup_mode, + 'properties': baremetal_portgroup_properties, + } class TestBaremetal(utils.TestCommand): diff --git a/ironicclient/tests/unit/osc/v1/test_baremetal_portgroup.py b/ironicclient/tests/unit/osc/v1/test_baremetal_portgroup.py index 2a1df88b0..a7b0d14ff 100644 --- a/ironicclient/tests/unit/osc/v1/test_baremetal_portgroup.py +++ b/ironicclient/tests/unit/osc/v1/test_baremetal_portgroup.py @@ -183,6 +183,34 @@ class TestCreateBaremetalPortGroup(TestBaremetalPortGroup): self.baremetal_mock.portgroup.create.assert_called_once_with(**args) + def test_baremetal_portgroup_create_mode_properties(self): + arglist = [ + '--node', baremetal_fakes.baremetal_uuid, + '--mode', baremetal_fakes.baremetal_portgroup_mode, + '--property', 'key1=value11', + '--property', 'key2=value22' + ] + + verifylist = [ + ('node_uuid', baremetal_fakes.baremetal_uuid), + ('mode', baremetal_fakes.baremetal_portgroup_mode), + ('properties', ['key1=value11', 'key2=value22']) + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + # DisplayCommandBase.take_action() returns two tuples + self.cmd.take_action(parsed_args) + + # Set expected values + args = { + 'node_uuid': baremetal_fakes.baremetal_uuid, + 'mode': baremetal_fakes.baremetal_portgroup_mode, + 'properties': baremetal_fakes.baremetal_portgroup_properties + } + + self.baremetal_mock.portgroup.create.assert_called_once_with(**args) + def test_baremetal_portgroup_create_no_options(self): arglist = [] verifylist = [] @@ -223,15 +251,19 @@ class TestShowBaremetalPortGroup(TestBaremetalPortGroup): self.baremetal_mock.portgroup.get.assert_called_with(*args, fields=None) - collist = ('address', 'extra', 'name', 'node_uuid', 'uuid') + collist = ('address', 'extra', 'mode', 'name', 'node_uuid', + 'properties', 'uuid') self.assertEqual(collist, columns) datalist = ( baremetal_fakes.baremetal_portgroup_address, baremetal_fakes.baremetal_portgroup_extra, + baremetal_fakes.baremetal_portgroup_mode, baremetal_fakes.baremetal_portgroup_name, baremetal_fakes.baremetal_uuid, - baremetal_fakes.baremetal_portgroup_uuid) + baremetal_fakes.baremetal_portgroup_properties, + baremetal_fakes.baremetal_portgroup_uuid, + ) self.assertEqual(datalist, tuple(data)) @@ -365,8 +397,8 @@ class TestBaremetalPortGroupList(TestBaremetalPortGroup): baremetal_fakes.baremetal_portgroup_name, '', '', - '', - ''),) + baremetal_fakes.baremetal_portgroup_mode, + baremetal_fakes.baremetal_portgroup_properties),) self.assertEqual(datalist, tuple(data)) def test_baremetal_portgroup_list_fields(self): @@ -497,6 +529,23 @@ class TestBaremetalPortGroupSet(TestBaremetalPortGroup): [{'path': '/address', 'value': new_portgroup_address, 'op': 'add'}]) + def test_baremetal_portgroup_set_mode(self): + new_portgroup_mode = '802.3ad' + 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 = [ @@ -573,6 +622,21 @@ class TestBaremetalPortGroupSet(TestBaremetalPortGroup): [{'path': '/extra/key1', 'value': 'val1', 'op': 'add'}, {'path': '/extra/key2', 'value': 'val2', 'op': 'add'}]) + def test_baremetal_portgroup_set_multiple_properties(self): + arglist = ['portgroup', + '--property', 'key3=val3', + '--property', 'key4=val4'] + verifylist = [('portgroup', 'portgroup'), + ('properties', ['key3=val3', 'key4=val4'])] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + self.baremetal_mock.portgroup.update.assert_called_once_with( + 'portgroup', + [{'path': '/properties/key3', 'value': 'val3', 'op': 'add'}, + {'path': '/properties/key4', 'value': 'val4', 'op': 'add'}]) + def test_baremetal_portgroup_set_no_options(self): arglist = [] verifylist = [] @@ -651,6 +715,21 @@ class TestBaremetalPortGroupUnset(TestBaremetalPortGroup): [{'path': '/extra/key1', 'op': 'remove'}, {'path': '/extra/key2', 'op': 'remove'}]) + def test_baremetal_portgroup_unset_multiple_properties(self): + arglist = ['portgroup', + '--property', 'key1', + '--property', 'key2'] + verifylist = [('portgroup', 'portgroup'), + ('properties', ['key1', 'key2'])] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + self.baremetal_mock.portgroup.update.assert_called_once_with( + 'portgroup', + [{'path': '/properties/key1', 'op': 'remove'}, + {'path': '/properties/key2', 'op': 'remove'}]) + def test_baremetal_portgroup_unset_no_options(self): arglist = [] verifylist = [] diff --git a/releasenotes/notes/add-portgroup-mode-properties-0a3023cf905adaef.yaml b/releasenotes/notes/add-portgroup-mode-properties-0a3023cf905adaef.yaml index e1ae9e265..029961b3b 100644 --- a/releasenotes/notes/add-portgroup-mode-properties-0a3023cf905adaef.yaml +++ b/releasenotes/notes/add-portgroup-mode-properties-0a3023cf905adaef.yaml @@ -1,5 +1,5 @@ --- features: - Mode and properties fields were added to the portgroup object, along with - respective arguments for the ironic CLI, they are available starting with - ironic API microversion 1.26. + respective arguments for the ironic CLI and the OpenStackClient plugin, + they are available starting with ironic API microversion 1.26.