summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/network/v2/security_group_rule.py8
-rw-r--r--openstackclient/tests/unit/network/v2/fakes.py2
-rw-r--r--openstackclient/tests/unit/network/v2/test_security_group_rule.py31
3 files changed, 41 insertions, 0 deletions
diff --git a/openstackclient/network/v2/security_group_rule.py b/openstackclient/network/v2/security_group_rule.py
index e3be44ec..0f3bad3d 100644
--- a/openstackclient/network/v2/security_group_rule.py
+++ b/openstackclient/network/v2/security_group_rule.py
@@ -110,6 +110,11 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne):
def update_parser_network(self, parser):
parser.add_argument(
+ '--description',
+ metavar='<description>',
+ help=_("Set security group rule description")
+ )
+ parser.add_argument(
'--dst-port',
metavar='<port-range>',
action=parseractions.RangeAction,
@@ -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 f1c72461..0846af15 100644
--- a/openstackclient/tests/unit/network/v2/fakes.py
+++ b/openstackclient/tests/unit/network/v2/fakes.py
@@ -952,6 +952,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 96d58e5c..401e042f 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,