[apic-mapping] Segmentation Label ext for PT CLI

The patch: https://review.openstack.org/#/c/371962/ introduced a new
extension cisco_apic_gbp_segmentation_label, for the apic policy drivers.
An extension attribute: segmentation_labels, that extends the Policy
Target definition, is being introduced in that extension. The
segementation_labels attribute is a list of strings.

This patch introduces a CLI option: --segmentation-labels for the
policy_target create and update operations. This CLI option accepts
a comma separated string as the option value.

Change-Id: I7ae44111bbe06332f2a2271094ab21c437a40658
This commit is contained in:
Sumit Naiksatam 2016-09-19 16:00:27 -07:00
parent ee827f111e
commit 1d4cbfb193
3 changed files with 50 additions and 2 deletions

View File

@ -93,12 +93,18 @@ class CreatePolicyTarget(neutronV20.CreateCommand):
parser.add_argument(
'name', metavar='NAME',
help=_('Name of Policy Target to create (required argument)'))
parser.add_argument(
'--segmentation-labels', type=utils.str2list,
help=_('Comma separated list of segmentation labels, each label '
'can be upto 255 characters. This option is currently '
'only available with the APIC backend.'))
def args2body(self, parsed_args):
body = {self.resource: {}, }
neutronV20.update_dict(parsed_args, body[self.resource],
['name', 'tenant_id', 'description'])
['name', 'tenant_id', 'description',
'segmentation_labels'])
if parsed_args.policy_target_group:
body[self.resource]['policy_target_group_id'] = \
neutronV20.find_resourceid_by_name_or_id(
@ -145,12 +151,18 @@ class UpdatePolicyTarget(neutronV20.UpdateCommand):
'You can repeat this option.'))
parser.add_argument(
'--fixed_ip', action='append', help=argparse.SUPPRESS)
parser.add_argument(
'--segmentation-labels', type=utils.str2list,
help=_('Comma separated list of segmentation labels, each label '
'can be upto 255 characters. This option is currently '
'only available with the APIC backend.'))
def args2body(self, parsed_args):
body = {self.resource: {}, }
neutronV20.update_dict(parsed_args, body[self.resource],
['name', 'tenant_id', 'description'])
['name', 'tenant_id', 'description',
'segmentation_labels'])
if parsed_args.fixed_ip:
body[self.resource]['fixed_ips'] = parsed_args.fixed_ip

View File

@ -39,6 +39,29 @@ class CLITestV20PolicyTargetJSON(test_cli20.CLITestV20Base):
position_names, position_values,
tenant_id=tenant_id)
def test_create_policy_target_with_segmentation_labels(self):
"""policy-target-create with segmentation labels."""
resource = 'policy_target'
cmd = gbp.CreatePolicyTarget(test_cli20.MyApp(sys.stdout), None)
my_id = 'my-id'
tenant_id = 'my-tenant'
name = 'my-name'
description = 'pt description'
policy_target_group_id = 'policy_target_group_id'
segmentation_labels = "label1,label2"
args = [name,
'--tenant-id', tenant_id,
'--description', description,
'--policy-target-group-id', policy_target_group_id,
'--segmentation-labels', segmentation_labels]
position_names = ['name', 'description', 'policy_target_group_id',
'segmentation_labels']
position_values = [name, description, policy_target_group_id,
['label1', 'label2']]
self._test_create_resource(resource, cmd, name, my_id, args,
position_names, position_values,
tenant_id=tenant_id)
def test_list_policy_targets(self):
resource = 'policy_targets'
cmd = gbp.ListPolicyTarget(test_cli20.MyApp(sys.stdout), None)
@ -84,6 +107,18 @@ class CLITestV20PolicyTargetJSON(test_cli20.CLITestV20Base):
'ip_address': ip_addr}]}
self._test_update_resource(resource, cmd, myid, args, updated_fields)
def test_update_policy_target_with_segmentation_labels(self):
"""policy-target-update with segmentation labels."""
resource = 'policy_target'
cmd = gbp.UpdatePolicyTarget(test_cli20.MyApp(sys.stdout), None)
my_id = 'my-id'
segmentation_labels = "label3,label4"
args = [my_id,
'--segmentation-labels', segmentation_labels]
updated_fields = {"segmentation_labels": ['label3', 'label4']}
self._test_update_resource(resource, cmd, my_id, args,
updated_fields)
def test_delete_policy_target_name(self):
resource = 'policy_target'
cmd = gbp.DeletePolicyTarget(test_cli20.MyApp(sys.stdout), None)

View File

@ -12,6 +12,7 @@ httpretty>=0.8.0,!=0.8.1,!=0.8.2,!=0.8.3
mox3>=0.7.0 # Apache-2.0
oslosphinx!=3.4.0,>=2.5.0 # Apache-2.0
oslotest>=1.10.0 # Apache-2.0
python-keystoneclient<=3.2.0
python-subunit>=0.0.18 # Apache-2.0/BSD
requests-mock>=0.7.0 # Apache-2.0
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2 # BSD