From c99ec284db181c7f9c72ce1163ba1ea45fe369d0 Mon Sep 17 00:00:00 2001
From: Aradhana Singh <aradhana1.singh>
Date: Thu, 6 Oct 2016 21:51:01 +0000
Subject: [PATCH] Add description field port create & port set

This patchset
1. adds description field to openstack port create and
 openstack port set.
2. updates method _add_updatable_args with 4 spaces instead
 of existing 8 spaces

Partially Implements: blueprint neutron-client-descriptions
Partially Implements: blueprint network-commands-options

Change-Id: I4598e555722b1de7bc47f3a9be0fd81eacfcb572
---
 doc/source/command-objects/port.rst           | 10 +++
 openstackclient/network/v2/port.py            | 87 ++++++++++---------
 .../tests/unit/network/v2/fakes.py            |  1 +
 .../tests/unit/network/v2/test_port.py        |  8 ++
 ...-client-descriptions-b65dd776f78b5a73.yaml |  6 ++
 5 files changed, 72 insertions(+), 40 deletions(-)
 create mode 100644 releasenotes/notes/bp-neutron-client-descriptions-b65dd776f78b5a73.yaml

diff --git a/doc/source/command-objects/port.rst b/doc/source/command-objects/port.rst
index e3e783ada8..6b318faf74 100644
--- a/doc/source/command-objects/port.rst
+++ b/doc/source/command-objects/port.rst
@@ -18,6 +18,7 @@ Create new port
 
     os port create
         --network <network>
+        [--description <description>]
         [--fixed-ip subnet=<subnet>,ip-address=<ip-address>]
         [--device <device-id>]
         [--device-owner <device-owner>]
@@ -33,6 +34,10 @@ Create new port
 
     Network this port belongs to (name or ID)
 
+.. option:: --description <description>
+
+    Description of this port
+
 .. option:: --fixed-ip subnet=<subnet>,ip-address=<ip-address>
 
     Desired IP and/or subnet (name or ID) for this port:
@@ -144,6 +149,7 @@ Set port properties
 .. code:: bash
 
     os port set
+        [--description <description>]
         [--fixed-ip subnet=<subnet>,ip-address=<ip-address>]
         [--no-fixed-ip]
         [--device <device-id>]
@@ -156,6 +162,10 @@ Set port properties
         [--name <name>]
         <port>
 
+.. option:: --description <description>
+
+    Description of this port
+
 .. option:: --fixed-ip subnet=<subnet>,ip-address=<ip-address>
 
     Desired IP and/or subnet (name or ID) for this port:
diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py
index 92b286a9e8..bd777d717c 100644
--- a/openstackclient/network/v2/port.py
+++ b/openstackclient/network/v2/port.py
@@ -109,6 +109,8 @@ def _get_attrs(client_manager, parsed_args):
             'The --host-id option is deprecated, '
             'please use --host instead.'
         ))
+    if parsed_args.description is not None:
+        attrs['description'] = parsed_args.description
     if parsed_args.fixed_ip is not None:
         attrs['fixed_ips'] = parsed_args.fixed_ip
     if parsed_args.device:
@@ -180,46 +182,51 @@ def _prepare_fixed_ips(client_manager, parsed_args):
 
 
 def _add_updatable_args(parser):
-        # NOTE(dtroyer): --device-id is deprecated in Mar 2016.  Do not
-        #                remove before 3.x release or Mar 2017.
-        device_group = parser.add_mutually_exclusive_group()
-        device_group.add_argument(
-            '--device',
-            metavar='<device-id>',
-            help=_("Port device ID")
-        )
-        device_group.add_argument(
-            '--device-id',
-            metavar='<device-id>',
-            help=argparse.SUPPRESS,
-        )
-        parser.add_argument(
-            '--device-owner',
-            metavar='<device-owner>',
-            help=_("Device owner of this port. This is the entity that uses "
-                   "the port (for example, network:dhcp).")
-        )
-        parser.add_argument(
-            '--vnic-type',
-            metavar='<vnic-type>',
-            choices=['direct', 'direct-physical', 'macvtap',
-                     'normal', 'baremetal'],
-            help=_("VNIC type for this port (direct | direct-physical | "
-                   "macvtap | normal | baremetal, default: normal)")
-        )
-        # NOTE(dtroyer): --host-id is deprecated in Mar 2016.  Do not
-        #                remove before 3.x release or Mar 2017.
-        host_group = parser.add_mutually_exclusive_group()
-        host_group.add_argument(
-            '--host',
-            metavar='<host-id>',
-            help=_("Allocate port on host <host-id> (ID only)")
-        )
-        host_group.add_argument(
-            '--host-id',
-            metavar='<host-id>',
-            help=argparse.SUPPRESS,
-        )
+    parser.add_argument(
+        '--description',
+        metavar='<description>',
+        help=_("Description of this port")
+    )
+    # NOTE(dtroyer): --device-id is deprecated in Mar 2016.  Do not
+    #                remove before 3.x release or Mar 2017.
+    device_group = parser.add_mutually_exclusive_group()
+    device_group.add_argument(
+        '--device',
+        metavar='<device-id>',
+        help=_("Port device ID")
+    )
+    device_group.add_argument(
+        '--device-id',
+        metavar='<device-id>',
+        help=argparse.SUPPRESS,
+    )
+    parser.add_argument(
+        '--device-owner',
+        metavar='<device-owner>',
+        help=_("Device owner of this port. This is the entity that uses "
+               "the port (for example, network:dhcp).")
+    )
+    parser.add_argument(
+        '--vnic-type',
+        metavar='<vnic-type>',
+        choices=['direct', 'direct-physical', 'macvtap',
+                 'normal', 'baremetal'],
+        help=_("VNIC type for this port (direct | direct-physical | "
+               "macvtap | normal | baremetal, default: normal)")
+    )
+    # NOTE(dtroyer): --host-id is deprecated in Mar 2016.  Do not
+    #                remove before 3.x release or Mar 2017.
+    host_group = parser.add_mutually_exclusive_group()
+    host_group.add_argument(
+        '--host',
+        metavar='<host-id>',
+        help=_("Allocate port on host <host-id> (ID only)")
+    )
+    host_group.add_argument(
+        '--host-id',
+        metavar='<host-id>',
+        help=argparse.SUPPRESS,
+    )
 
 
 class CreatePort(command.ShowOne):
diff --git a/openstackclient/tests/unit/network/v2/fakes.py b/openstackclient/tests/unit/network/v2/fakes.py
index 94727ae3ca..8994517e4e 100644
--- a/openstackclient/tests/unit/network/v2/fakes.py
+++ b/openstackclient/tests/unit/network/v2/fakes.py
@@ -427,6 +427,7 @@ class FakePort(object):
             'binding:vif_details': {},
             'binding:vif_type': 'ovs',
             'binding:vnic_type': 'normal',
+            'description': 'description-' + uuid.uuid4().hex,
             'device_id': 'device-id-' + uuid.uuid4().hex,
             'device_owner': 'compute:nova',
             'dns_assignment': [{}],
diff --git a/openstackclient/tests/unit/network/v2/test_port.py b/openstackclient/tests/unit/network/v2/test_port.py
index a2aceab173..110f713e67 100644
--- a/openstackclient/tests/unit/network/v2/test_port.py
+++ b/openstackclient/tests/unit/network/v2/test_port.py
@@ -41,6 +41,7 @@ class TestPort(network_fakes.TestNetworkV2):
             'binding_vif_details',
             'binding_vif_type',
             'binding_vnic_type',
+            'description',
             'device_id',
             'device_owner',
             'dns_assignment',
@@ -65,6 +66,7 @@ class TestPort(network_fakes.TestNetworkV2):
             utils.format_dict(fake_port.binding_vif_details),
             fake_port.binding_vif_type,
             fake_port.binding_vnic_type,
+            fake_port.description,
             fake_port.device_id,
             fake_port.device_owner,
             utils.format_list_of_dicts(fake_port.dns_assignment),
@@ -130,6 +132,7 @@ class TestCreatePort(TestPort):
             '--mac-address', 'aa:aa:aa:aa:aa:aa',
             '--fixed-ip', 'subnet=%s,ip-address=10.0.0.2'
             % self.fake_subnet.id,
+            '--description', self._port.description,
             '--device', 'deviceid',
             '--device-owner', 'fakeowner',
             '--disable',
@@ -146,6 +149,7 @@ class TestCreatePort(TestPort):
                 'fixed_ip',
                 [{'subnet': self.fake_subnet.id, 'ip-address': '10.0.0.2'}]
             ),
+            ('description', self._port.description),
             ('device', 'deviceid'),
             ('device_owner', 'fakeowner'),
             ('disable', True),
@@ -163,6 +167,7 @@ class TestCreatePort(TestPort):
             'mac_address': 'aa:aa:aa:aa:aa:aa',
             'fixed_ips': [{'subnet_id': self.fake_subnet.id,
                            'ip_address': '10.0.0.2'}],
+            'description': self._port.description,
             'device_id': 'deviceid',
             'device_owner': 'fakeowner',
             'admin_state_up': False,
@@ -565,6 +570,7 @@ class TestSetPort(TestPort):
 
     def test_set_that(self):
         arglist = [
+            '--description', 'newDescription',
             '--enable',
             '--vnic-type', 'macvtap',
             '--binding-profile', 'foo=bar',
@@ -573,6 +579,7 @@ class TestSetPort(TestPort):
             self._port.name,
         ]
         verifylist = [
+            ('description', 'newDescription'),
             ('enable', True),
             ('vnic_type', 'macvtap'),
             ('binding_profile', {'foo': 'bar'}),
@@ -589,6 +596,7 @@ class TestSetPort(TestPort):
             'binding:vnic_type': 'macvtap',
             'binding:profile': {'foo': 'bar'},
             'binding:host_id': 'binding-host-id-xxxx',
+            'description': 'newDescription',
             'name': 'newName',
         }
         self.network.update_port.assert_called_once_with(self._port, **attrs)
diff --git a/releasenotes/notes/bp-neutron-client-descriptions-b65dd776f78b5a73.yaml b/releasenotes/notes/bp-neutron-client-descriptions-b65dd776f78b5a73.yaml
new file mode 100644
index 0000000000..625a4e76db
--- /dev/null
+++ b/releasenotes/notes/bp-neutron-client-descriptions-b65dd776f78b5a73.yaml
@@ -0,0 +1,6 @@
+---
+features:
+  - |
+    Add ``--description`` option to ``port set`` and
+    ``port create`` commands.
+    [Blueprint :oscbp:`neutron-client-descriptions`]