Add is-smartnic port attribute to port command
Support Smart NIC ports creation by using port argument is-smartnic. Story: #2003346 Change-Id: Ie954b1ad8e6987a8a7a349051825a2043ecc54ac
This commit is contained in:
@@ -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)
|
||||
|
@@ -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))
|
||||
|
@@ -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'])
|
||||
|
@@ -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))
|
||||
|
@@ -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,
|
||||
|
@@ -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',
|
||||
|
@@ -0,0 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Adds support for creating Smart NIC ports by adding is-smartnic port
|
||||
attribute to port command.
|
Reference in New Issue
Block a user