Skip to content

Commit 3412147

Browse files
committed
Add "qinq-vlan" and "no-qinq-vlan" params to the "network create" cmd
Depends-On: https://review.opendev.org/c/openstack/openstacksdk/+/939703 Related-Bug: #1915151 Change-Id: Icacf83c20c3650a9d75f665f020b8818e1b4a585
1 parent e761ef8 commit 3412147

4 files changed

Lines changed: 67 additions & 5 deletions

File tree

openstackclient/network/v2/network.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from cliff import columns as cliff_columns
1616
from osc_lib.cli import format_columns
17+
from osc_lib import exceptions
1718
from osc_lib import utils
1819
from osc_lib.utils import tags as _tag
1920

@@ -60,11 +61,7 @@ def _get_columns_network(item):
6061
'ipv6_address_scope_id': 'ipv6_address_scope',
6162
'tags': 'tags',
6263
}
63-
# TODO(slaweq): temporary, until
64-
# https://review.opendev.org/c/openstack/openstacksdk/+/939703 will be
65-
# merged this new column should be hidden from the output (it is just to
66-
# make unit tests in the openstacksdk patch happy)
67-
hidden_columns = ['location', 'tenant_id', 'is_vlan_qinq']
64+
hidden_columns = ['location', 'tenant_id']
6865
return utils.get_osc_show_columns_for_sdk_resource(
6966
item, column_map, hidden_columns
7067
)
@@ -353,6 +350,25 @@ def update_parser_network(self, parser):
353350
),
354351
)
355352

353+
vlan_qinq_grp = parser.add_mutually_exclusive_group()
354+
vlan_qinq_grp.add_argument(
355+
'--qinq-vlan',
356+
action='store_true',
357+
help=self.enhance_help_neutron(
358+
_("Enable VLAN QinQ (S-Tag ethtype 0x8a88) " "for the network")
359+
),
360+
)
361+
vlan_qinq_grp.add_argument(
362+
'--no-qinq-vlan',
363+
action='store_true',
364+
help=self.enhance_help_neutron(
365+
_(
366+
"Disable VLAN QinQ (S-Tag ethtype 0x8a88) "
367+
"for the network"
368+
)
369+
),
370+
)
371+
356372
_add_additional_network_options(parser)
357373
_tag.add_tag_option_to_parser_for_create(
358374
parser, _('network'), enhance_help=self.enhance_help_neutron
@@ -376,6 +392,19 @@ def take_action_network(self, client, parsed_args):
376392
attrs['vlan_transparent'] = True
377393
if parsed_args.no_transparent_vlan:
378394
attrs['vlan_transparent'] = False
395+
396+
if parsed_args.qinq_vlan:
397+
attrs['vlan_qinq'] = True
398+
if parsed_args.no_qinq_vlan:
399+
attrs['vlan_qinq'] = False
400+
401+
if attrs.get('vlan_transparent') and attrs.get('vlan_qinq'):
402+
msg = _(
403+
"--transparent-vlan and --qinq-vlan can not be both enabled "
404+
"for the network."
405+
)
406+
raise exceptions.CommandError(msg)
407+
379408
attrs.update(
380409
self._parse_extra_properties(parsed_args.extra_properties)
381410
)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,7 @@ def create_one_network(attrs=None):
14191419
'availability_zone_hints': [],
14201420
'is_default': False,
14211421
'is_vlan_transparent': True,
1422+
'is_vlan_qinq': False,
14221423
'port_security_enabled': True,
14231424
'qos_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
14241425
'ipv4_address_scope': 'ipv4' + uuid.uuid4().hex,

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
6363
'ipv6_address_scope',
6464
'is_default',
6565
'is_vlan_transparent',
66+
'is_vlan_qinq',
6667
'mtu',
6768
'name',
6869
'port_security_enabled',
@@ -103,6 +104,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
103104
network.RouterExternalColumn(_network.is_router_external),
104105
_network.is_shared,
105106
_network.is_vlan_transparent,
107+
_network.is_vlan_qinq,
106108
_network.status,
107109
_network.segments,
108110
format_columns.ListColumn(_network.subnet_ids),
@@ -190,6 +192,7 @@ def test_create_all_options(self):
190192
"--qos-policy",
191193
self.qos_policy.id,
192194
"--transparent-vlan",
195+
"--no-qinq-vlan",
193196
"--enable-port-security",
194197
"--dns-domain",
195198
"example.org.",
@@ -210,6 +213,7 @@ def test_create_all_options(self):
210213
('segmentation_id', '400'),
211214
('qos_policy', self.qos_policy.id),
212215
('transparent_vlan', True),
216+
('qinq_vlan', False),
213217
('enable_port_security', True),
214218
('name', self._network.name),
215219
('dns_domain', 'example.org.'),
@@ -234,6 +238,7 @@ def test_create_all_options(self):
234238
'provider:segmentation_id': '400',
235239
'qos_policy_id': self.qos_policy.id,
236240
'vlan_transparent': True,
241+
'vlan_qinq': False,
237242
'port_security_enabled': True,
238243
'dns_domain': 'example.org.',
239244
}
@@ -246,13 +251,15 @@ def test_create_other_options(self):
246251
"--enable",
247252
"--no-share",
248253
"--disable-port-security",
254+
"--qinq-vlan",
249255
self._network.name,
250256
]
251257
verifylist = [
252258
('enable', True),
253259
('no_share', True),
254260
('name', self._network.name),
255261
('external', False),
262+
('qinq_vlan', True),
256263
('disable_port_security', True),
257264
]
258265

@@ -264,6 +271,7 @@ def test_create_other_options(self):
264271
'admin_state_up': True,
265272
'name': self._network.name,
266273
'shared': False,
274+
'vlan_qinq': True,
267275
'port_security_enabled': False,
268276
}
269277
)
@@ -309,6 +317,19 @@ def test_create_with_tags(self):
309317
def test_create_with_no_tag(self):
310318
self._test_create_with_tag(add_tags=False)
311319

320+
def test_create_with_vlan_qinq_and_transparency_enabled(self):
321+
arglist = [
322+
"--transparent-vlan",
323+
"--qinq-vlan",
324+
self._network.name,
325+
]
326+
verifylist = []
327+
328+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
329+
self.assertRaises(
330+
exceptions.CommandError, self.cmd.take_action, parsed_args
331+
)
332+
312333

313334
class TestCreateNetworkIdentityV2(
314335
identity_fakes_v2.FakeClientMixin,
@@ -332,6 +353,7 @@ class TestCreateNetworkIdentityV2(
332353
'ipv6_address_scope',
333354
'is_default',
334355
'is_vlan_transparent',
356+
'is_vlan_qinq',
335357
'mtu',
336358
'name',
337359
'port_security_enabled',
@@ -372,6 +394,7 @@ class TestCreateNetworkIdentityV2(
372394
network.RouterExternalColumn(_network.is_router_external),
373395
_network.is_shared,
374396
_network.is_vlan_transparent,
397+
_network.is_vlan_qinq,
375398
_network.status,
376399
_network.segments,
377400
format_columns.ListColumn(_network.subnet_ids),
@@ -1149,6 +1172,7 @@ class TestShowNetwork(TestNetwork):
11491172
'ipv6_address_scope',
11501173
'is_default',
11511174
'is_vlan_transparent',
1175+
'is_vlan_qinq',
11521176
'mtu',
11531177
'name',
11541178
'port_security_enabled',
@@ -1189,6 +1213,7 @@ class TestShowNetwork(TestNetwork):
11891213
network.RouterExternalColumn(_network.is_router_external),
11901214
_network.is_shared,
11911215
_network.is_vlan_transparent,
1216+
_network.is_vlan_qinq,
11921217
_network.status,
11931218
_network.segments,
11941219
format_columns.ListColumn(_network.subnet_ids),
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
features:
3+
- |
4+
Add ``qinq-vlan`` and ``no-qinq-vlan`` arguments to the ``network create``
5+
command. It will enable/disable QinQ feature for the created network.
6+
This new argument is mutually exclusive with the ``transparent-vlan`` - only
7+
one of them can be set to ``True`` for the network.

0 commit comments

Comments
 (0)