Skip to content

Commit 78b1803

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Support for stateless security groups"
2 parents 74a7c1d + 5e62411 commit 78b1803

5 files changed

Lines changed: 54 additions & 1 deletion

File tree

openstackclient/network/v2/security_group.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,19 @@ def update_parser_network(self, parser):
120120
metavar='<project>',
121121
help=self.enhance_help_neutron(_("Owner's project (name or ID)"))
122122
)
123+
stateful_group = parser.add_mutually_exclusive_group()
124+
stateful_group.add_argument(
125+
"--stateful",
126+
action='store_true',
127+
default=None,
128+
help=_("Security group is stateful (Default)")
129+
)
130+
stateful_group.add_argument(
131+
"--stateless",
132+
action='store_true',
133+
default=None,
134+
help=_("Security group is stateless")
135+
)
123136
identity_common.add_project_domain_option_to_parser(
124137
parser, enhance_help=self.enhance_help_neutron)
125138
_tag.add_tag_option_to_parser_for_create(
@@ -138,6 +151,10 @@ def take_action_network(self, client, parsed_args):
138151
attrs = {}
139152
attrs['name'] = parsed_args.name
140153
attrs['description'] = self._get_description(parsed_args)
154+
if parsed_args.stateful:
155+
attrs['stateful'] = True
156+
if parsed_args.stateless:
157+
attrs['stateful'] = False
141158
if parsed_args.project is not None:
142159
identity_client = self.app.client_manager.identity
143160
project_id = identity_common.find_project(
@@ -315,6 +332,19 @@ def update_parser_common(self, parser):
315332
metavar="<description>",
316333
help=_("New security group description")
317334
)
335+
stateful_group = parser.add_mutually_exclusive_group()
336+
stateful_group.add_argument(
337+
"--stateful",
338+
action='store_true',
339+
default=None,
340+
help=_("Security group is stateful (Default)")
341+
)
342+
stateful_group.add_argument(
343+
"--stateless",
344+
action='store_true',
345+
default=None,
346+
help=_("Security group is stateless")
347+
)
318348
return parser
319349

320350
def update_parser_network(self, parser):
@@ -331,6 +361,10 @@ def take_action_network(self, client, parsed_args):
331361
attrs['name'] = parsed_args.name
332362
if parsed_args.description is not None:
333363
attrs['description'] = parsed_args.description
364+
if parsed_args.stateful:
365+
attrs['stateful'] = True
366+
if parsed_args.stateless:
367+
attrs['stateful'] = False
334368
# NOTE(rtheis): Previous behavior did not raise a CommandError
335369
# if there were no updates. Maintain this behavior and issue
336370
# the update.

openstackclient/tests/functional/network/v2/test_security_group.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,18 @@ def test_security_group_list(self):
4242
def test_security_group_set(self):
4343
other_name = uuid.uuid4().hex
4444
raw_output = self.openstack(
45-
'security group set --description NSA --name ' +
45+
'security group set --description NSA --stateless --name ' +
4646
other_name + ' ' + self.NAME
4747
)
4848
self.assertEqual('', raw_output)
4949

5050
cmd_output = json.loads(self.openstack(
5151
'security group show -f json ' + other_name))
5252
self.assertEqual('NSA', cmd_output['description'])
53+
self.assertFalse(cmd_output['stateful'])
5354

5455
def test_security_group_show(self):
5556
cmd_output = json.loads(self.openstack(
5657
'security group show -f json ' + self.NAME))
5758
self.assertEqual(self.NAME, cmd_output['name'])
59+
self.assertTrue(cmd_output['stateful'])

openstackclient/tests/unit/network/v2/fakes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,7 @@ def create_one_security_group(attrs=None):
12271227
'id': 'security-group-id-' + uuid.uuid4().hex,
12281228
'name': 'security-group-name-' + uuid.uuid4().hex,
12291229
'description': 'security-group-description-' + uuid.uuid4().hex,
1230+
'stateful': True,
12301231
'project_id': 'project-id-' + uuid.uuid4().hex,
12311232
'security_group_rules': [],
12321233
'tags': []

openstackclient/tests/unit/network/v2/test_security_group_network.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class TestCreateSecurityGroupNetwork(TestSecurityGroupNetwork):
4949
'name',
5050
'project_id',
5151
'rules',
52+
'stateful',
5253
'tags',
5354
)
5455

@@ -58,6 +59,7 @@ class TestCreateSecurityGroupNetwork(TestSecurityGroupNetwork):
5859
_security_group.name,
5960
_security_group.project_id,
6061
security_group.NetworkSecurityGroupRulesColumn([]),
62+
_security_group.stateful,
6163
_security_group.tags,
6264
)
6365

@@ -101,20 +103,23 @@ def test_create_all_options(self):
101103
'--description', self._security_group.description,
102104
'--project', self.project.name,
103105
'--project-domain', self.domain.name,
106+
'--stateful',
104107
self._security_group.name,
105108
]
106109
verifylist = [
107110
('description', self._security_group.description),
108111
('name', self._security_group.name),
109112
('project', self.project.name),
110113
('project_domain', self.domain.name),
114+
('stateful', self._security_group.stateful),
111115
]
112116
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
113117

114118
columns, data = self.cmd.take_action(parsed_args)
115119

116120
self.network.create_security_group.assert_called_once_with(**{
117121
'description': self._security_group.description,
122+
'stateful': self._security_group.stateful,
118123
'name': self._security_group.name,
119124
'tenant_id': self.project.id,
120125
})
@@ -421,11 +426,13 @@ def test_set_all_options(self):
421426
arglist = [
422427
'--name', new_name,
423428
'--description', new_description,
429+
'--stateful',
424430
self._security_group.name,
425431
]
426432
verifylist = [
427433
('description', new_description),
428434
('group', self._security_group.name),
435+
('stateful', self._security_group.stateful),
429436
('name', new_name),
430437
]
431438

@@ -435,6 +442,7 @@ def test_set_all_options(self):
435442
attrs = {
436443
'description': new_description,
437444
'name': new_name,
445+
'stateful': True,
438446
}
439447
self.network.update_security_group.assert_called_once_with(
440448
self._security_group,
@@ -489,6 +497,7 @@ class TestShowSecurityGroupNetwork(TestSecurityGroupNetwork):
489497
'name',
490498
'project_id',
491499
'rules',
500+
'stateful',
492501
'tags',
493502
)
494503

@@ -499,6 +508,7 @@ class TestShowSecurityGroupNetwork(TestSecurityGroupNetwork):
499508
_security_group.project_id,
500509
security_group.NetworkSecurityGroupRulesColumn(
501510
[_security_group_rule._info]),
511+
_security_group.stateful,
502512
_security_group.tags,
503513
)
504514

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- |
4+
Add ``--stateful`` and ``--stateless`` option to the
5+
``security group create`` and ``security group set`` commands
6+
to support stateful and stateless security groups.

0 commit comments

Comments
 (0)