Merge "Add mode and properties to portgroup OSC plugin"

This commit is contained in:
Jenkins 2016-12-26 13:19:43 +00:00 committed by Gerrit Code Review
commit 2f404e834d
4 changed files with 137 additions and 8 deletions

View File

@ -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="<key=value>",
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="<key=value>",
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="<key>",
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,

View File

@ -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):

View File

@ -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 = []

View File

@ -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.