Merge "Add "trusted" attribute to the "port""
This commit is contained in:
commit
79e01a5533
@ -93,6 +93,7 @@ def _get_columns(item):
|
||||
'status': 'status',
|
||||
'tags': 'tags',
|
||||
'trunk_details': 'trunk_details',
|
||||
'trusted': 'trusted',
|
||||
'updated_at': 'updated_at',
|
||||
}
|
||||
return (
|
||||
@ -222,6 +223,10 @@ def _get_attrs(client_manager, parsed_args):
|
||||
and parsed_args.hardware_offload_type
|
||||
):
|
||||
attrs['hardware_offload_type'] = parsed_args.hardware_offload_type
|
||||
if parsed_args.not_trusted:
|
||||
attrs['trusted'] = False
|
||||
if parsed_args.trusted:
|
||||
attrs['trusted'] = True
|
||||
|
||||
return attrs
|
||||
|
||||
@ -388,6 +393,25 @@ def _add_updatable_args(parser, create=False):
|
||||
'(repeat option to set multiple hints)'
|
||||
),
|
||||
)
|
||||
port_trusted = parser.add_mutually_exclusive_group()
|
||||
port_trusted.add_argument(
|
||||
'--trusted',
|
||||
action='store_true',
|
||||
help=_(
|
||||
"Set port to be trusted. This will be populated into the "
|
||||
"'binding:profile' dictionary and passed to the services "
|
||||
"which expect it in this dictionary (for example, Nova)"
|
||||
),
|
||||
)
|
||||
port_trusted.add_argument(
|
||||
'--not-trusted',
|
||||
action='store_true',
|
||||
help=_(
|
||||
"Set port to be not trusted. This will be populated into the "
|
||||
"'binding:profile' dictionary and passed to the services "
|
||||
"which expect it in this dictionary (for example, Nova)"
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
# TODO(abhiraut): Use the SDK resource mapped attribute names once the
|
||||
@ -1137,6 +1161,11 @@ class SetPort(common.NeutronCommandWithExtraArgs):
|
||||
raise exceptions.CommandError(msg)
|
||||
attrs['hints'] = expanded_hints
|
||||
|
||||
if parsed_args.not_trusted:
|
||||
attrs['trusted'] = False
|
||||
if parsed_args.trusted:
|
||||
attrs['trusted'] = True
|
||||
|
||||
attrs.update(
|
||||
self._parse_extra_properties(parsed_args.extra_properties)
|
||||
)
|
||||
|
@ -1676,6 +1676,7 @@ def create_one_port(attrs=None):
|
||||
'qos_network_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
|
||||
'qos_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
|
||||
'tags': [],
|
||||
'trusted': None,
|
||||
'propagate_uplink_status': False,
|
||||
'location': 'MUNCHMUNCHMUNCH',
|
||||
}
|
||||
|
@ -73,6 +73,7 @@ class TestPort(network_fakes.TestNetworkV2):
|
||||
'security_group_ids',
|
||||
'status',
|
||||
'tags',
|
||||
'trusted',
|
||||
'trunk_details',
|
||||
'updated_at',
|
||||
)
|
||||
@ -114,6 +115,7 @@ class TestPort(network_fakes.TestNetworkV2):
|
||||
format_columns.ListColumn(fake_port.security_group_ids),
|
||||
fake_port.status,
|
||||
format_columns.ListColumn(fake_port.tags),
|
||||
fake_port.trusted,
|
||||
fake_port.trunk_details,
|
||||
fake_port.updated_at,
|
||||
)
|
||||
@ -1111,6 +1113,50 @@ class TestCreatePort(TestPort):
|
||||
def test_create_with_hardware_offload_type_null(self):
|
||||
self._test_create_with_hardware_offload_type()
|
||||
|
||||
def _test_create_with_trusted_field(self, trusted):
|
||||
arglist = [
|
||||
'--network',
|
||||
self._port.network_id,
|
||||
'test-port',
|
||||
]
|
||||
if trusted:
|
||||
arglist += ['--trusted']
|
||||
else:
|
||||
arglist += ['--not-trusted']
|
||||
|
||||
verifylist = [
|
||||
(
|
||||
'network',
|
||||
self._port.network_id,
|
||||
),
|
||||
('name', 'test-port'),
|
||||
]
|
||||
if trusted:
|
||||
verifylist.append(('trusted', True))
|
||||
else:
|
||||
verifylist.append(('trusted', False))
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
create_args = {
|
||||
'admin_state_up': True,
|
||||
'network_id': self._port.network_id,
|
||||
'name': 'test-port',
|
||||
}
|
||||
create_args['trusted'] = trusted
|
||||
self.network_client.create_port.assert_called_once_with(**create_args)
|
||||
|
||||
self.assertEqual(set(self.columns), set(columns))
|
||||
self.assertCountEqual(self.data, data)
|
||||
|
||||
def test_create_with_trusted_true(self):
|
||||
self._test_create_with_trusted_field(True)
|
||||
|
||||
def test_create_with_trusted_false(self):
|
||||
self._test_create_with_trusted_field(False)
|
||||
|
||||
|
||||
class TestDeletePort(TestPort):
|
||||
# Ports to delete.
|
||||
@ -2520,6 +2566,35 @@ class TestSetPort(TestPort):
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def _test_set_trusted_field(self, trusted):
|
||||
arglist = [self._port.id]
|
||||
if trusted:
|
||||
arglist += ['--trusted']
|
||||
else:
|
||||
arglist += ['--not-trusted']
|
||||
|
||||
verifylist = [
|
||||
('port', self._port.id),
|
||||
]
|
||||
if trusted:
|
||||
verifylist.append(('trusted', True))
|
||||
else:
|
||||
verifylist.append(('trusted', False))
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.network_client.update_port.assert_called_once_with(
|
||||
self._port, **{'trusted': trusted}
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_set_trusted_true(self):
|
||||
self._test_set_trusted_field(True)
|
||||
|
||||
def test_set_trusted_false(self):
|
||||
self._test_set_trusted_field(False)
|
||||
|
||||
|
||||
class TestShowPort(TestPort):
|
||||
# The port to show.
|
||||
|
@ -0,0 +1,7 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Add ``trusted`` attribute to the ``port create`` and ``port set`` commands.
|
||||
It can be set to ``true`` with ``--trusted`` and to ``false`` with
|
||||
``--not-trusted`` CLI arguments passed to the ``port create`` and ``port
|
||||
set`` commands``
|
Loading…
x
Reference in New Issue
Block a user