summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmando Migliaccio <armamig@gmail.com>2016-08-29 22:01:49 -0700
committerArmando Migliaccio <armamig@gmail.com>2016-08-29 22:19:16 -0700
commit89d4a9a2eafc256b8a88234e93aba296fd0bf586 (patch)
treed62ecbbd2fed5852d286bf2c0098f8775d0a2aea
parent93b6fe1d4f0049f04b9379b223073e939408ff12 (diff)
downloadpython-neutronclient-89d4a9a2eafc256b8a88234e93aba296fd0bf586.tar.gz
Make trunk commands handle description for trunk resources
Depends-on: Ie3149e206fe8a83631dd9d42d344fea3f03dc0db Partially-implements: blueprint vlan-aware-vms Change-Id: Ie721beb78a4a3b6da9e0f68167b91be043b7034e
-rw-r--r--doc/source/usage/osc/v2/network-trunk.rst10
-rw-r--r--neutronclient/osc/v2/trunk/network_trunk.py18
-rw-r--r--neutronclient/tests/unit/osc/v2/trunk/fakes.py5
-rw-r--r--neutronclient/tests/unit/osc/v2/trunk/test_network_trunk.py55
4 files changed, 68 insertions, 20 deletions
diff --git a/doc/source/usage/osc/v2/network-trunk.rst b/doc/source/usage/osc/v2/network-trunk.rst
index 5a79310..a39e3bd 100644
--- a/doc/source/usage/osc/v2/network-trunk.rst
+++ b/doc/source/usage/osc/v2/network-trunk.rst
@@ -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='
diff --git a/neutronclient/osc/v2/trunk/network_trunk.py b/neutronclient/osc/v2/trunk/network_trunk.py
index e3eed82..5ba9b9a 100644
--- a/neutronclient/osc/v2/trunk/network_trunk.py
+++ b/neutronclient/osc/v2/trunk/network_trunk.py
@@ -45,6 +45,11 @@ class CreateNetworkTrunk(command.ShowOne):
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>',
required=True,
@@ -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 += (
@@ -180,6 +187,11 @@ class SetNetworkTrunk(command.Command):
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=>',
action=parseractions.MultiKeyValueAction, dest='set_subports',
@@ -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:
diff --git a/neutronclient/tests/unit/osc/v2/trunk/fakes.py b/neutronclient/tests/unit/osc/v2/trunk/fakes.py
index 0eb6f97..1acbcc3 100644
--- a/neutronclient/tests/unit/osc/v2/trunk/fakes.py
+++ b/neutronclient/tests/unit/osc/v2/trunk/fakes.py
@@ -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,
diff --git a/neutronclient/tests/unit/osc/v2/trunk/test_network_trunk.py b/neutronclient/tests/unit/osc/v2/trunk/test_network_trunk.py
index 5bb5ea2..ee16fd0 100644
--- a/neutronclient/tests/unit/osc/v2/trunk/test_network_trunk.py
+++ b/neutronclient/tests/unit/osc/v2/trunk/test_network_trunk.py
@@ -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',