From 52c4a55d43248d87737613509930242244b6ff3c Mon Sep 17 00:00:00 2001 From: Sindhu Devale Date: Sun, 6 Nov 2016 22:56:00 -0600 Subject: [PATCH] Add 'description' option This patch adds '--description' option to os security group rule create cmd. Change-Id: I604bcdeb4658d2dcc4d860a87e704e186cca5225 Partially-Implements: blueprint network-commands-options Partially-Implements: blueprint neutron-client-descriptions --- .../command-objects/security-group-rule.rst | 7 +++++ .../network/v2/security_group_rule.py | 8 +++++ .../tests/unit/network/v2/fakes.py | 2 ++ .../network/v2/test_security_group_rule.py | 31 +++++++++++++++++++ ...-client-descriptions-a80902b4295843cf.yaml | 3 ++ 5 files changed, 51 insertions(+) diff --git a/doc/source/command-objects/security-group-rule.rst b/doc/source/command-objects/security-group-rule.rst index 5284b2dc22..69c9fabc54 100644 --- a/doc/source/command-objects/security-group-rule.rst +++ b/doc/source/command-objects/security-group-rule.rst @@ -22,6 +22,7 @@ Create a new security group rule [--ingress | --egress] [--ethertype ] [--project [--project-domain ]] + [--description ] .. option:: --src-ip @@ -97,6 +98,12 @@ Create a new security group rule *Network version 2 only* +.. option:: --description + + Set security group rule description + + *Network version 2 only* + .. describe:: Create rule in this security group (name or ID) diff --git a/openstackclient/network/v2/security_group_rule.py b/openstackclient/network/v2/security_group_rule.py index e3be44ece7..0f3bad3d3b 100644 --- a/openstackclient/network/v2/security_group_rule.py +++ b/openstackclient/network/v2/security_group_rule.py @@ -109,6 +109,11 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne): return parser def update_parser_network(self, parser): + parser.add_argument( + '--description', + metavar='', + help=_("Set security group rule description") + ) parser.add_argument( '--dst-port', metavar='', @@ -235,6 +240,9 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne): attrs = {} attrs['protocol'] = self._get_protocol(parsed_args) + if parsed_args.description is not None: + attrs['description'] = parsed_args.description + # NOTE(rtheis): A direction must be specified and ingress # is the default. if parsed_args.ingress or not parsed_args.egress: diff --git a/openstackclient/tests/unit/network/v2/fakes.py b/openstackclient/tests/unit/network/v2/fakes.py index 94727ae3ca..31f3be7563 100644 --- a/openstackclient/tests/unit/network/v2/fakes.py +++ b/openstackclient/tests/unit/network/v2/fakes.py @@ -951,6 +951,8 @@ class FakeSecurityGroupRule(object): # Set default attributes. security_group_rule_attrs = { + 'description': 'security-group-rule-description-' + + uuid.uuid4().hex, 'direction': 'ingress', 'ethertype': 'IPv4', 'id': 'security-group-rule-id-' + uuid.uuid4().hex, diff --git a/openstackclient/tests/unit/network/v2/test_security_group_rule.py b/openstackclient/tests/unit/network/v2/test_security_group_rule.py index 96d58e5c00..401e042f35 100644 --- a/openstackclient/tests/unit/network/v2/test_security_group_rule.py +++ b/openstackclient/tests/unit/network/v2/test_security_group_rule.py @@ -60,6 +60,7 @@ class TestCreateSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork): network_fakes.FakeSecurityGroup.create_one_security_group() expected_columns = ( + 'description', 'direction', 'ethertype', 'id', @@ -81,6 +82,7 @@ class TestCreateSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork): self.network.create_security_group_rule = mock.Mock( return_value=self._security_group_rule) self.expected_data = ( + self._security_group_rule.description, self._security_group_rule.direction, self._security_group_rule.ethertype, self._security_group_rule.id, @@ -452,6 +454,33 @@ class TestCreateSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork): self.assertEqual(self.expected_columns, columns) self.assertEqual(self.expected_data, data) + def test_create_with_description(self): + self._setup_security_group_rule({ + 'description': 'Setting SGR', + }) + arglist = [ + '--description', self._security_group_rule.description, + self._security_group.id, + ] + verifylist = [ + ('description', self._security_group_rule.description), + ('group', self._security_group.id), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + columns, data = (self.cmd.take_action(parsed_args)) + + self.network.create_security_group_rule.assert_called_once_with(**{ + 'description': self._security_group_rule.description, + 'direction': self._security_group_rule.direction, + 'ethertype': self._security_group_rule.ethertype, + 'protocol': self._security_group_rule.protocol, + 'remote_ip_prefix': self._security_group_rule.remote_ip_prefix, + 'security_group_id': self._security_group.id, + }) + self.assertEqual(self.expected_columns, columns) + self.assertEqual(self.expected_data, data) + class TestCreateSecurityGroupRuleCompute(TestSecurityGroupRuleCompute): @@ -1075,6 +1104,7 @@ class TestShowSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork): network_fakes.FakeSecurityGroupRule.create_one_security_group_rule() columns = ( + 'description', 'direction', 'ethertype', 'id', @@ -1088,6 +1118,7 @@ class TestShowSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork): ) data = ( + _security_group_rule.description, _security_group_rule.direction, _security_group_rule.ethertype, _security_group_rule.id, diff --git a/releasenotes/notes/bp-neutron-client-descriptions-a80902b4295843cf.yaml b/releasenotes/notes/bp-neutron-client-descriptions-a80902b4295843cf.yaml index 83a0090251..3135d0d73c 100644 --- a/releasenotes/notes/bp-neutron-client-descriptions-a80902b4295843cf.yaml +++ b/releasenotes/notes/bp-neutron-client-descriptions-a80902b4295843cf.yaml @@ -7,3 +7,6 @@ features: Add ``--description`` option to ``router set`` and ``router create`` commands. [Blueprint :oscbp:`network-commands-options`] + | + Adds ``--description`` option to ``security group rule create``. + [Blueprint :oscbp:`network-commands-options`]