Merge "Make trunk commands handle description for trunk resources"
This commit is contained in:
commit
fdc9f02de0
@ -37,6 +37,7 @@ Create a network trunk for a given project
|
||||
[--subport <port=,segmentation-type=,segmentation-id=>]
|
||||
[--enable | --disable]
|
||||
[--project <project> [--project-domain <project-domain>]]
|
||||
[--description <description>]
|
||||
<name>
|
||||
|
||||
.. option:: --parent-port <parent-port>
|
||||
@ -65,6 +66,10 @@ Create a network trunk for a given project
|
||||
Domain the project belongs to (name or ID).
|
||||
This can be used in case collisions between project names exist.
|
||||
|
||||
.. option:: --description <description>
|
||||
|
||||
A description of the trunk.
|
||||
|
||||
network trunk delete
|
||||
--------------------
|
||||
|
||||
@ -106,6 +111,7 @@ Set network trunk properties
|
||||
|
||||
os network trunk set
|
||||
[--name <name>]
|
||||
[--description <description>]
|
||||
[--subport <port=,segmentation-type=,segmentation-id=>]
|
||||
[--enable | --disable]
|
||||
<trunk>
|
||||
@ -114,6 +120,10 @@ Set network trunk properties
|
||||
|
||||
Set trunk name
|
||||
|
||||
.. option:: --description <description>
|
||||
|
||||
A description of the trunk.
|
||||
|
||||
.. option:: --subport <port=,segmentation-type=,segmentation-id=>
|
||||
|
||||
Subport to add. Subport is of form 'port=<name or ID>,segmentation-type=,segmentation-ID='
|
||||
|
@ -44,6 +44,11 @@ class CreateNetworkTrunk(command.ShowOne):
|
||||
metavar='<name>',
|
||||
help=_("Name of the trunk to create")
|
||||
)
|
||||
parser.add_argument(
|
||||
'--description',
|
||||
metavar='<description>',
|
||||
help=_("A description of the trunk")
|
||||
)
|
||||
parser.add_argument(
|
||||
'--parent-port',
|
||||
metavar='<parent-port>',
|
||||
@ -141,12 +146,14 @@ class ListNetworkTrunk(command.Lister):
|
||||
headers = (
|
||||
'ID',
|
||||
'Name',
|
||||
'Parent Port'
|
||||
'Parent Port',
|
||||
'Description'
|
||||
)
|
||||
columns = (
|
||||
'id',
|
||||
'name',
|
||||
'port_id'
|
||||
'port_id',
|
||||
'description'
|
||||
)
|
||||
if parsed_args.long:
|
||||
headers += (
|
||||
@ -179,6 +186,11 @@ class SetNetworkTrunk(command.Command):
|
||||
metavar="<name>",
|
||||
help=_("Set trunk name")
|
||||
)
|
||||
parser.add_argument(
|
||||
'--description',
|
||||
metavar='<description>',
|
||||
help=_("A description of the trunk")
|
||||
)
|
||||
parser.add_argument(
|
||||
'--subport',
|
||||
metavar='<port=,segmentation-type=,segmentation-id=>',
|
||||
@ -313,6 +325,8 @@ def _get_attrs_for_trunk(client_manager, parsed_args):
|
||||
attrs = {}
|
||||
if parsed_args.name is not None:
|
||||
attrs['name'] = str(parsed_args.name)
|
||||
if parsed_args.description is not None:
|
||||
attrs['description'] = str(parsed_args.description)
|
||||
if parsed_args.enable:
|
||||
attrs['admin_state_up'] = True
|
||||
if parsed_args.disable:
|
||||
|
@ -24,8 +24,8 @@ class FakeTrunk(object):
|
||||
:param Dictionary attrs:
|
||||
A dictionary with all attributes
|
||||
:return:
|
||||
A Dictionary with id, name, admin_state_up,
|
||||
port_id, sub_ports, status and project_id
|
||||
A Dictionary with id, name, description, admin_state_up, port_id,
|
||||
sub_ports, status and project_id
|
||||
"""
|
||||
attrs = attrs or {}
|
||||
|
||||
@ -33,6 +33,7 @@ class FakeTrunk(object):
|
||||
trunk_attrs = {
|
||||
'id': 'trunk-id-' + uuid.uuid4().hex,
|
||||
'name': 'trunk-name-' + uuid.uuid4().hex,
|
||||
'description': '',
|
||||
'port_id': 'port-' + uuid.uuid4().hex,
|
||||
'admin_state_up': True,
|
||||
'project_id': 'project-id-' + uuid.uuid4().hex,
|
||||
|
@ -36,6 +36,7 @@ class TestCreateNetworkTrunk(test_fakes.TestNeutronClientOSCV2):
|
||||
|
||||
columns = (
|
||||
'admin_state_up',
|
||||
'description',
|
||||
'id',
|
||||
'name',
|
||||
'port_id',
|
||||
@ -43,15 +44,18 @@ class TestCreateNetworkTrunk(test_fakes.TestNeutronClientOSCV2):
|
||||
'status',
|
||||
'sub_ports',
|
||||
)
|
||||
data = (
|
||||
trunk._format_admin_state(_trunk['admin_state_up']),
|
||||
_trunk['id'],
|
||||
_trunk['name'],
|
||||
_trunk['port_id'],
|
||||
_trunk['project_id'],
|
||||
_trunk['status'],
|
||||
utils.format_list_of_dicts(_trunk['sub_ports']),
|
||||
)
|
||||
|
||||
def get_data(self):
|
||||
return (
|
||||
trunk._format_admin_state(self._trunk['admin_state_up']),
|
||||
self._trunk['description'],
|
||||
self._trunk['id'],
|
||||
self._trunk['name'],
|
||||
self._trunk['port_id'],
|
||||
self._trunk['project_id'],
|
||||
self._trunk['status'],
|
||||
utils.format_list_of_dicts(self._trunk['sub_ports']),
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
super(TestCreateNetworkTrunk, self).setUp()
|
||||
@ -59,6 +63,7 @@ class TestCreateNetworkTrunk(test_fakes.TestNeutronClientOSCV2):
|
||||
new=_get_id).start()
|
||||
self.neutronclient.create_trunk = mock.Mock(
|
||||
return_value={trunk.TRUNK: self._trunk})
|
||||
self.data = self.get_data()
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = trunk.CreateNetworkTrunk(self.app, self.namespace)
|
||||
@ -92,9 +97,12 @@ class TestCreateNetworkTrunk(test_fakes.TestNeutronClientOSCV2):
|
||||
self.assertEqual(self.data, data)
|
||||
|
||||
def test_create_full_options(self):
|
||||
self._trunk['description'] = 'foo description'
|
||||
self.data = self.get_data()
|
||||
subport = self._trunk['sub_ports'][0]
|
||||
arglist = [
|
||||
"--disable",
|
||||
"--description", self._trunk['description'],
|
||||
"--parent-port", self._trunk['port_id'],
|
||||
"--subport", 'port=%(port)s,segmentation-type=%(seg_type)s,'
|
||||
'segmentation-id=%(seg_id)s' % {
|
||||
@ -105,6 +113,7 @@ class TestCreateNetworkTrunk(test_fakes.TestNeutronClientOSCV2):
|
||||
]
|
||||
verifylist = [
|
||||
('name', self._trunk['name']),
|
||||
('description', self._trunk['description']),
|
||||
('parent_port', self._trunk['port_id']),
|
||||
('add_subports', [{
|
||||
'port': subport['port_id'],
|
||||
@ -119,6 +128,7 @@ class TestCreateNetworkTrunk(test_fakes.TestNeutronClientOSCV2):
|
||||
|
||||
self.neutronclient.create_trunk.assert_called_once_with({
|
||||
trunk.TRUNK: {'name': self._trunk['name'],
|
||||
'description': self._trunk['description'],
|
||||
'admin_state_up': False,
|
||||
'sub_ports': [subport],
|
||||
'port_id': self._trunk['port_id']}
|
||||
@ -229,6 +239,7 @@ class TestShowNetworkTrunk(test_fakes.TestNeutronClientOSCV2):
|
||||
|
||||
columns = (
|
||||
'admin_state_up',
|
||||
'description',
|
||||
'id',
|
||||
'name',
|
||||
'port_id',
|
||||
@ -238,6 +249,7 @@ class TestShowNetworkTrunk(test_fakes.TestNeutronClientOSCV2):
|
||||
)
|
||||
data = (
|
||||
trunk._format_admin_state(_trunk['admin_state_up']),
|
||||
_trunk['description'],
|
||||
_trunk['id'],
|
||||
_trunk['name'],
|
||||
_trunk['port_id'],
|
||||
@ -289,6 +301,7 @@ class TestListNetworkTrunk(test_fakes.TestNeutronClientOSCV2):
|
||||
'ID',
|
||||
'Name',
|
||||
'Parent Port',
|
||||
'Description'
|
||||
)
|
||||
columns_long = columns + (
|
||||
'Status',
|
||||
@ -300,6 +313,7 @@ class TestListNetworkTrunk(test_fakes.TestNeutronClientOSCV2):
|
||||
t['id'],
|
||||
t['name'],
|
||||
t['port_id'],
|
||||
t['description']
|
||||
))
|
||||
data_long = []
|
||||
for t in _trunks:
|
||||
@ -307,6 +321,7 @@ class TestListNetworkTrunk(test_fakes.TestNeutronClientOSCV2):
|
||||
t['id'],
|
||||
t['name'],
|
||||
t['port_id'],
|
||||
t['description'],
|
||||
t['status'],
|
||||
trunk._format_admin_state(t['admin_state_up']),
|
||||
))
|
||||
@ -356,6 +371,7 @@ class TestSetNetworkTrunk(test_fakes.TestNeutronClientOSCV2):
|
||||
'admin_state_up',
|
||||
'id',
|
||||
'name',
|
||||
'description',
|
||||
'port_id',
|
||||
'project_id',
|
||||
'status',
|
||||
@ -365,6 +381,7 @@ class TestSetNetworkTrunk(test_fakes.TestNeutronClientOSCV2):
|
||||
trunk._format_admin_state(_trunk['admin_state_up']),
|
||||
_trunk['id'],
|
||||
_trunk['name'],
|
||||
_trunk['description'],
|
||||
_trunk['port_id'],
|
||||
_trunk['project_id'],
|
||||
_trunk['status'],
|
||||
@ -383,26 +400,32 @@ class TestSetNetworkTrunk(test_fakes.TestNeutronClientOSCV2):
|
||||
# Get the command object to test
|
||||
self.cmd = trunk.SetNetworkTrunk(self.app, self.namespace)
|
||||
|
||||
def test_set_network_trunk_name(self):
|
||||
def _test_set_network_trunk_attr(self, attr, value):
|
||||
arglist = [
|
||||
'--name', 'trunky',
|
||||
self._trunk['name'],
|
||||
'--%s' % attr, value,
|
||||
self._trunk[attr],
|
||||
]
|
||||
verifylist = [
|
||||
('name', 'trunky'),
|
||||
('trunk', self._trunk['name']),
|
||||
(attr, value),
|
||||
('trunk', self._trunk[attr]),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
attrs = {
|
||||
'name': 'trunky',
|
||||
attr: value,
|
||||
}
|
||||
self.neutronclient.update_trunk.assert_called_once_with(
|
||||
self._trunk['name'], {trunk.TRUNK: attrs})
|
||||
self._trunk[attr], {trunk.TRUNK: attrs})
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_set_network_trunk_name(self):
|
||||
self._test_set_network_trunk_attr('name', 'trunky')
|
||||
|
||||
def test_test_set_network_trunk_description(self):
|
||||
self._test_set_network_trunk_attr('description', 'description')
|
||||
|
||||
def test_set_network_trunk_admin_state_up_disable(self):
|
||||
arglist = [
|
||||
'--disable',
|
||||
|
Loading…
x
Reference in New Issue
Block a user