diff options
author | Hamdy Khader <hamdyk@mellanox.com> | 2019-01-09 13:52:18 +0200 |
---|---|---|
committer | Hamdy Khader <hamdyk@mellanox.com> | 2019-02-18 14:15:46 +0200 |
commit | 3ca40ce88fbcb11326babc8e3ee46f8fcff7cdd3 (patch) | |
tree | 06dc316b9e63a061acdce2da3d04f8c8c915b77d | |
parent | e8a6d447f803c115ed57064e6fada3e9d6f30794 (diff) | |
download | python-ironicclient-3ca40ce88fbcb11326babc8e3ee46f8fcff7cdd3.tar.gz |
Add is-smartnic port attribute to port command
Support Smart NIC ports creation by using port argument is-smartnic.
Story: #2003346
Change-Id: Ie954b1ad8e6987a8a7a349051825a2043ecc54ac
-rw-r--r-- | ironicclient/osc/v1/baremetal_port.py | 26 | ||||
-rw-r--r-- | ironicclient/tests/unit/osc/v1/test_baremetal_port.py | 53 | ||||
-rw-r--r-- | ironicclient/tests/unit/v1/test_port.py | 4 | ||||
-rw-r--r-- | ironicclient/tests/unit/v1/test_port_shell.py | 2 | ||||
-rw-r--r-- | ironicclient/v1/port.py | 2 | ||||
-rw-r--r-- | ironicclient/v1/resource_fields.py | 2 | ||||
-rw-r--r-- | releasenotes/notes/add-is-smartnic-port-attr-ed46d887aec276ed.yaml | 5 |
7 files changed, 89 insertions, 5 deletions
diff --git a/ironicclient/osc/v1/baremetal_port.py b/ironicclient/osc/v1/baremetal_port.py index 3e934fe..df70da9 100644 --- a/ironicclient/osc/v1/baremetal_port.py +++ b/ironicclient/osc/v1/baremetal_port.py @@ -98,6 +98,12 @@ class CreateBaremetalPort(command.ShowOne): help=_("Name of the physical network to which this port is " "connected.")) + parser.add_argument( + '--is-smartnic', + dest='is_smartnic', + action='store_true', + help=_("Indicates whether this Port is a Smart NIC port")) + return parser def take_action(self, parsed_args): @@ -123,6 +129,8 @@ class CreateBaremetalPort(command.ShowOne): if k in field_list and v is not None) fields = utils.args_array_to_dict(fields, 'extra') fields = utils.args_array_to_dict(fields, 'local_link_connection') + if parsed_args.is_smartnic: + fields['is_smartnic'] = parsed_args.is_smartnic port = baremetal_client.port.create(**fields) data = dict([(f, getattr(port, f, '')) for f in @@ -215,6 +223,12 @@ class UnsetBaremetalPort(command.Command): dest='physical_network', help=_("Unset the physical network on this baremetal port.")) + parser.add_argument( + '--is-smartnic', + dest='is_smartnic', + action='store_true', + help=_("Set Port as not Smart NIC port")) + return parser def take_action(self, parsed_args): @@ -232,6 +246,9 @@ class UnsetBaremetalPort(command.Command): if parsed_args.physical_network: properties.extend(utils.args_array_to_patch('remove', ['physical_network'])) + if parsed_args.is_smartnic: + properties.extend(utils.args_array_to_patch( + 'add', ["is_smartnic=False"])) if properties: baremetal_client.port.update(parsed_args.port, properties) @@ -309,6 +326,12 @@ class SetBaremetalPort(command.Command): help=_("Set the name of the physical network to which this port " "is connected.")) + parser.add_argument( + '--is-smartnic', + dest='is_smartnic', + action='store_true', + help=_("Set port to be Smart NIC port")) + return parser def take_action(self, parsed_args): @@ -342,6 +365,9 @@ class SetBaremetalPort(command.Command): parsed_args.physical_network] properties.extend(utils.args_array_to_patch('add', physical_network)) + if parsed_args.is_smartnic: + is_smartnic = ["is_smartnic=%s" % parsed_args.is_smartnic] + properties.extend(utils.args_array_to_patch('add', is_smartnic)) if properties: baremetal_client.port.update(parsed_args.port, properties) diff --git a/ironicclient/tests/unit/osc/v1/test_baremetal_port.py b/ironicclient/tests/unit/osc/v1/test_baremetal_port.py index ca831d1..03cee91 100644 --- a/ironicclient/tests/unit/osc/v1/test_baremetal_port.py +++ b/ironicclient/tests/unit/osc/v1/test_baremetal_port.py @@ -66,7 +66,7 @@ class TestCreateBaremetalPort(TestBaremetalPort): # Set expected values args = { 'address': baremetal_fakes.baremetal_port_address, - 'node_uuid': baremetal_fakes.baremetal_uuid, + 'node_uuid': baremetal_fakes.baremetal_uuid } self.baremetal_mock.port.create.assert_called_once_with(**args) @@ -249,11 +249,29 @@ class TestCreateBaremetalPort(TestBaremetalPort): args = { 'address': baremetal_fakes.baremetal_port_address, 'node_uuid': baremetal_fakes.baremetal_uuid, - 'physical_network': baremetal_fakes.baremetal_port_physical_network + 'physical_network': + baremetal_fakes.baremetal_port_physical_network } self.baremetal_mock.port.create.assert_called_once_with(**args) + def test_baremetal_port_create_smartnic(self): + arglist = [ + baremetal_fakes.baremetal_port_address, + '--node', baremetal_fakes.baremetal_uuid, + '--is-smartnic'] + verifylist = [ + ('node_uuid', baremetal_fakes.baremetal_uuid), + ('address', baremetal_fakes.baremetal_port_address), + ('is_smartnic', True)] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + self.cmd.take_action(parsed_args) + args = { + 'address': baremetal_fakes.baremetal_port_address, + 'node_uuid': baremetal_fakes.baremetal_uuid, + 'is_smartnic': True} + self.baremetal_mock.port.create.assert_called_once_with(**args) + class TestShowBaremetalPort(TestBaremetalPort): def setUp(self): @@ -397,6 +415,18 @@ class TestBaremetalPortUnset(TestBaremetalPort): 'port', [{'path': '/physical_network', 'op': 'remove'}]) + def test_baremetal_port_unset_is_smartnic(self): + arglist = ['port', '--is-smartnic'] + verifylist = [('port', 'port'), + ('is_smartnic', True)] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + self.baremetal_mock.port.update.assert_called_once_with( + 'port', + [{'path': '/is_smartnic', 'op': 'add', 'value': 'False'}]) + class TestBaremetalPortSet(TestBaremetalPort): def setUp(self): @@ -549,6 +579,22 @@ class TestBaremetalPortSet(TestBaremetalPort): self.cmd.take_action(parsed_args) self.assertFalse(self.baremetal_mock.port.update.called) + def test_baremetal_port_set_is_smartnic(self): + arglist = [ + baremetal_fakes.baremetal_port_uuid, + '--is-smartnic'] + verifylist = [ + ('port', baremetal_fakes.baremetal_port_uuid), + ('is_smartnic', True)] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + self.baremetal_mock.port.update.assert_called_once_with( + baremetal_fakes.baremetal_port_uuid, + [{'path': '/is_smartnic', 'value': 'True', + 'op': 'add'}]) + class TestBaremetalPortDelete(TestBaremetalPort): def setUp(self): @@ -704,7 +750,7 @@ class TestBaremetalPortList(TestBaremetalPort): collist = ('UUID', 'Address', 'Created At', 'Extra', 'Node UUID', 'Local Link Connection', 'Portgroup UUID', 'PXE boot enabled', 'Physical Network', 'Updated At', - 'Internal Info') + 'Internal Info', 'Is Smart NIC port') self.assertEqual(collist, columns) datalist = (( @@ -718,6 +764,7 @@ class TestBaremetalPortList(TestBaremetalPort): '', '', '', + '', '' ), ) self.assertEqual(datalist, tuple(data)) diff --git a/ironicclient/tests/unit/v1/test_port.py b/ironicclient/tests/unit/v1/test_port.py index 8817381..89a9478 100644 --- a/ironicclient/tests/unit/v1/test_port.py +++ b/ironicclient/tests/unit/v1/test_port.py @@ -29,6 +29,7 @@ PORT = {'uuid': '11111111-2222-3333-4444-555555555555', 'local_link_connection': {}, 'portgroup_uuid': '55555555-4444-3333-2222-111111111111', 'physical_network': 'physnet1', + 'is_smartnic': False, 'extra': {}} PORT2 = {'uuid': '55555555-4444-3333-2222-111111111111', @@ -38,6 +39,7 @@ PORT2 = {'uuid': '55555555-4444-3333-2222-111111111111', 'local_link_connection': {}, 'portgroup_uuid': '55555555-4444-3333-2222-111111111111', 'physical_network': 'physnet2', + 'is_smartnic': True, 'extra': {}} CREATE_PORT = copy.deepcopy(PORT) @@ -303,6 +305,7 @@ class PortManagerTest(testtools.TestCase): port.local_link_connection) self.assertEqual(PORT['portgroup_uuid'], port.portgroup_uuid) self.assertEqual(PORT['physical_network'], port.physical_network) + self.assertEqual(PORT['is_smartnic'], port.is_smartnic) def test_ports_show_by_address(self): port = self.mgr.get_by_address(PORT['address']) @@ -319,6 +322,7 @@ class PortManagerTest(testtools.TestCase): port.local_link_connection) self.assertEqual(PORT['portgroup_uuid'], port.portgroup_uuid) self.assertEqual(PORT['physical_network'], port.physical_network) + self.assertEqual(PORT['is_smartnic'], port.is_smartnic) def test_port_show_fields(self): port = self.mgr.get(PORT['uuid'], fields=['uuid', 'address']) diff --git a/ironicclient/tests/unit/v1/test_port_shell.py b/ironicclient/tests/unit/v1/test_port_shell.py index ce0e587..862b074 100644 --- a/ironicclient/tests/unit/v1/test_port_shell.py +++ b/ironicclient/tests/unit/v1/test_port_shell.py @@ -33,7 +33,7 @@ class PortShellTest(utils.BaseTestCase): p_shell._print_port_show(port) exp = ['address', 'created_at', 'extra', 'node_uuid', 'physical_network', 'updated_at', 'uuid', 'pxe_enabled', - 'local_link_connection', 'internal_info', + 'local_link_connection', 'internal_info', 'is_smartnic', 'portgroup_uuid'] act = actual.keys() self.assertEqual(sorted(exp), sorted(act)) diff --git a/ironicclient/v1/port.py b/ironicclient/v1/port.py index 384a849..bffcf5a 100644 --- a/ironicclient/v1/port.py +++ b/ironicclient/v1/port.py @@ -29,7 +29,7 @@ class PortManager(base.CreateManager): resource_class = Port _creation_attributes = ['address', 'extra', 'local_link_connection', 'node_uuid', 'physical_network', 'portgroup_uuid', - 'pxe_enabled', 'uuid'] + 'pxe_enabled', 'uuid', 'is_smartnic'] _resource_name = 'ports' def list(self, address=None, limit=None, marker=None, sort_key=None, diff --git a/ironicclient/v1/resource_fields.py b/ironicclient/v1/resource_fields.py index a0d6f3e..9dd2504 100644 --- a/ironicclient/v1/resource_fields.py +++ b/ironicclient/v1/resource_fields.py @@ -129,6 +129,7 @@ class Resource(object): 'physical_network': 'Physical Network', 'id': 'ID', 'connector_id': 'Connector ID', + 'is_smartnic': 'Is Smart NIC port', } def __init__(self, field_ids, sort_excluded=None, override_labels=None): @@ -305,6 +306,7 @@ PORT_DETAILED_RESOURCE = Resource( 'physical_network', 'updated_at', 'internal_info', + 'is_smartnic', ], sort_excluded=[ 'extra', diff --git a/releasenotes/notes/add-is-smartnic-port-attr-ed46d887aec276ed.yaml b/releasenotes/notes/add-is-smartnic-port-attr-ed46d887aec276ed.yaml new file mode 100644 index 0000000..444bae0 --- /dev/null +++ b/releasenotes/notes/add-is-smartnic-port-attr-ed46d887aec276ed.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Adds support for creating Smart NIC ports by adding is-smartnic port + attribute to port command.
\ No newline at end of file |