Remove_legacy_service_chain_code

Change-Id: I6b08d3bc8784673968bb4ab4f3ad6dd1e7787cf1
This commit is contained in:
pulkitvajpayee07 2022-06-28 11:00:08 +05:30
parent e935b89402
commit c1e2442978
9 changed files with 0 additions and 1288 deletions

View File

@ -93,8 +93,6 @@ class Purge(n_purge.Purge):
'external_segment', 'policy_rule_set',
'policy_rule', 'policy_classifier',
'policy_action', 'network_service_policy',
'servicechain_instance', 'servicechain_spec',
'servicechain_node', 'service_profile',
'application_policy_group']
deleted = {}
failed = {}

View File

@ -1,452 +0,0 @@
# Copyright 2012 OpenStack Foundation.
# All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
import json
import logging
import os
from heatclient.common import template_utils
from neutronclient._i18n import _
from neutronclient.common import exceptions as exc
from neutronclient.common import utils as n_utils
from neutronclient.neutron import v2_0 as neutronV20
from gbpclient.common import utils
class ListServiceChainInstance(neutronV20.ListCommand):
"""List service chain instances that belong to a given tenant."""
resource = 'servicechain_instance'
log = logging.getLogger(__name__ + '.ListServiceChainInstance')
_formatters = {}
list_columns = ['id', 'name', 'description', 'servicechain_spec', 'port']
pagination_support = True
sorting_support = True
class ShowServiceChainInstance(neutronV20.ShowCommand):
"""Show information of a given service chain instance."""
resource = 'servicechain_instance'
log = logging.getLogger(__name__ + '.ShowServiceChainInstance')
class CreateServiceChainInstance(neutronV20.CreateCommand):
"""Create a service chain instance."""
resource = 'servicechain_instance'
log = logging.getLogger(__name__ + '.CreateServiceChainInstance')
def add_known_arguments(self, parser):
parser.add_argument(
'name',
help=_('Name for the Service Chain Instance.'))
parser.add_argument(
'--description',
help=_('Description of the Service Chain Instance.'))
parser.add_argument(
'--service-chain-spec', dest='servicechain_spec',
help=_('Service Chain Spec ID or the Service Chain Spec name'))
parser.add_argument(
'--provider-ptg', dest='provider_ptg',
help=_('Destination Policy Target Group ID of the Provider.'))
parser.add_argument(
'--consumer-ptg', dest='consumer_ptg',
help=_('Source Policy Target Group ID of the Consumer.'))
parser.add_argument(
'--param-values', dest='param_values',
help=_('Name,Value pairs of Service Configuration Parameters for '
'Service Chain Node.'))
def args2body(self, parsed_args):
body = {self.resource: {}, }
if parsed_args.servicechain_spec:
body[self.resource]['servicechain_spec'] = \
neutronV20.find_resourceid_by_name_or_id(
self.get_client(), 'servicechain_spec',
parsed_args.servicechain_spec)
if parsed_args.provider_ptg:
body[self.resource]['provider_ptg'] = \
neutronV20.find_resourceid_by_name_or_id(
self.get_client(), 'policy_target_group',
parsed_args.provider_ptg)
if parsed_args.consumer_ptg:
body[self.resource]['consumer_ptg'] = \
neutronV20.find_resourceid_by_name_or_id(
self.get_client(), 'policy_target_group',
parsed_args.consumer_ptg)
neutronV20.update_dict(parsed_args, body[self.resource],
['name', 'tenant_id', 'description',
'param_values'])
return body
class UpdateServiceChainInstance(neutronV20.UpdateCommand):
"""Update a given service chain instance."""
resource = 'servicechain_instance'
log = logging.getLogger(__name__ + '.UpdateServiceChainInstance')
def add_known_arguments(self, parser):
parser.add_argument(
'--service-chain-spec', dest='servicechain_spec',
help=_('Service Chain Spec ID or the Service Chain Spec name'))
parser.add_argument(
'--provider-ptg', dest='provider_ptg',
help=_('Destination Policy Target Group ID of the Provider.'))
parser.add_argument(
'--consumer-ptg', dest='consumer_ptg',
help=_('Source Policy Target Group ID of the Consumer.'))
parser.add_argument(
'--param-values', dest='param_values',
help=_('Name,Value pairs of Service Configuration Parameters for '
'Service Chain Node.'))
def args2body(self, parsed_args):
body = {self.resource: {}, }
if parsed_args.servicechain_spec:
body[self.resource]['servicechain_spec'] = \
neutronV20.find_resourceid_by_name_or_id(
self.get_client(), 'servicechain_spec',
parsed_args.servicechain_spec)
if parsed_args.provider_ptg:
body[self.resource]['provider_ptg'] = \
neutronV20.find_resourceid_by_name_or_id(
self.get_client(), 'policy_target_group',
parsed_args.provider_ptg)
if parsed_args.consumer_ptg:
body[self.resource]['consumer_ptg'] = \
neutronV20.find_resourceid_by_name_or_id(
self.get_client(), 'policy_target_group',
parsed_args.consumer_ptg)
neutronV20.update_dict(parsed_args, body[self.resource],
['name', 'description', 'param_values'])
return body
class DeleteServiceChainInstance(neutronV20.DeleteCommand):
"""Delete a given service chain instance."""
resource = 'servicechain_instance'
log = logging.getLogger(__name__ + '.DeleteServiceChainInstance')
class ListServiceProfile(neutronV20.ListCommand):
"""List service profiles that belong to a given tenant."""
resource = 'service_profile'
log = logging.getLogger(__name__ + '.ListServiceProfile')
_formatters = {}
list_columns = ['id', 'name', 'description', 'service_type']
pagination_support = True
sorting_support = True
class ShowServiceProfile(neutronV20.ShowCommand):
"""Show information of a given service profile."""
resource = 'service_profile'
log = logging.getLogger(__name__ + '.ShowServiceProfile')
class CreateServiceProfile(neutronV20.CreateCommand):
"""Create a service profile."""
resource = 'service_profile'
log = logging.getLogger(__name__ + '.CreateServiceProfile')
def add_known_arguments(self, parser):
parser.add_argument(
'name',
help=_('Name for the Service Profile.'))
parser.add_argument(
'--description',
help=_('Description of the Service Profile.'))
n_utils.add_boolean_argument(
parser, '--shared', dest='shared',
help=_('Shared flag'))
parser.add_argument(
'--vendor',
help=_('Vendor providing the service node'))
parser.add_argument(
'--insertion-mode',
help=_('Insertion mode of the service'))
parser.add_argument(
'--servicetype', dest='service_type',
help=_('Type of the service'))
parser.add_argument(
'--service-flavor',
help=_('Flavor of the service'))
def args2body(self, parsed_args):
body = {self.resource: {}, }
neutronV20.update_dict(parsed_args, body[self.resource],
['name', 'description', 'tenant_id', 'shared',
'vendor', 'insertion_mode', 'service_type',
'service_flavor'])
return body
class UpdateServiceProfile(neutronV20.UpdateCommand):
"""Update a given service profile."""
resource = 'service_profile'
log = logging.getLogger(__name__ + '.UpdateServiceProfile')
def add_known_arguments(self, parser):
parser.add_argument(
'--name',
help=_('Name for the Service Profile.'))
parser.add_argument(
'--description',
help=_('Description of the Service Profile.'))
n_utils.add_boolean_argument(
parser, '--shared', dest='shared',
help=_('Shared flag'))
parser.add_argument(
'--vendor',
help=_('Vendor providing the service node'))
parser.add_argument(
'--insertion-mode',
help=_('Insertion mode of the service'))
parser.add_argument(
'--servicetype', dest='service_type',
help=_('Type of the service'))
parser.add_argument(
'--service-flavor',
help=_('Flavor of the service'))
def args2body(self, parsed_args):
body = {self.resource: {}, }
neutronV20.update_dict(parsed_args, body[self.resource],
['name', 'description', 'shared', 'vendor',
'insertion_mode', 'service_type',
'service_flavor'])
return body
class DeleteServiceProfile(neutronV20.DeleteCommand):
"""Delete a given service profile."""
resource = 'service_profile'
log = logging.getLogger(__name__ + '.DeleteServiceProfile')
class ListServiceChainNode(neutronV20.ListCommand):
"""List service chain nodes that belong to a given tenant."""
resource = 'servicechain_node'
log = logging.getLogger(__name__ + '.ListServiceChainNode')
_formatters = {}
list_columns = ['id', 'name', 'description', 'service_type']
pagination_support = True
sorting_support = True
class ShowServiceChainNode(neutronV20.ShowCommand):
"""Show information of a given service chain node."""
resource = 'servicechain_node'
log = logging.getLogger(__name__ + '.ShowServiceChainNode')
class CreateServiceChainNode(neutronV20.CreateCommand):
"""Create a service chain node."""
resource = 'servicechain_node'
log = logging.getLogger(__name__ + '.CreateServiceChainNode')
def add_known_arguments(self, parser):
parser.add_argument(
'name',
help=_('Name for the Service Chain Node.'))
parser.add_argument(
'--description',
help=_('Description of the Service Chain Node.'))
parser.add_argument(
'--servicetype', dest='service_type',
help=_('Service type ID or the Service Type name'))
parser.add_argument(
'--service-profile',
help=_('Service Profile name or UUID'))
parser.add_argument(
'--config',
help=_('Service Configuration for the Service Chain Node.'))
n_utils.add_boolean_argument(
parser, '--shared', dest='shared',
help=_('Shared flag'))
parser.add_argument(
'--template-file',
help=_('Service Configuration Template for the Service Chain '
'Node.'))
parser.add_argument(
'--param-names', dest='param_names',
help=_('List of Configuration Parameter Names for Service '
'Chain Node.'))
def args2body(self, parsed_args):
body = {self.resource: {}, }
if parsed_args.service_profile:
body[self.resource]['service_profile_id'] = \
neutronV20.find_resourceid_by_name_or_id(
self.get_client(), 'service_profile',
parsed_args.service_profile)
if parsed_args.template_file:
if os.path.isfile(parsed_args.template_file):
tpl_files, template = template_utils.get_template_contents(
parsed_args.template_file)
parsed_args.config = json.dumps(template)
else:
raise exc.NeutronClientException("File %s does not exist. "
"Please check the path"
% parsed_args.template_file)
neutronV20.update_dict(parsed_args, body[self.resource],
['name', 'service_type', 'config', 'shared',
'tenant_id', 'param_names', 'description'])
return body
class UpdateServiceChainNode(neutronV20.UpdateCommand):
"""Update a given service chain node."""
resource = 'servicechain_node'
log = logging.getLogger(__name__ + '.UpdateServiceChainNode')
def add_known_arguments(self, parser):
parser.add_argument(
'--servicetype', dest='service_type',
help=_('Service type ID or the Service Type name'))
parser.add_argument(
'--service-profile',
help=_('Service Profile name or UUID'))
parser.add_argument(
'--config',
help=_('Service Configuration for the Service Chain Node.'))
n_utils.add_boolean_argument(
parser, '--shared', dest='shared',
help=_('Shared flag'))
def args2body(self, parsed_args):
body = {self.resource: {}, }
if parsed_args.service_profile:
body[self.resource]['service_profile_id'] = \
neutronV20.find_resourceid_by_name_or_id(
self.get_client(), 'service_profile',
parsed_args.service_profile)
neutronV20.update_dict(parsed_args, body[self.resource],
['name', 'service_type', 'config', 'shared',
'description'])
return body
class DeleteServiceChainNode(neutronV20.DeleteCommand):
"""Delete a given service chain node."""
resource = 'servicechain_node'
log = logging.getLogger(__name__ + '.DeleteServiceChainNode')
class ListServiceChainSpec(neutronV20.ListCommand):
"""List service chain specs that belong to a given tenant."""
resource = 'servicechain_spec'
log = logging.getLogger(__name__ + '.ListServiceChainSpec')
_formatters = {}
list_columns = ['id', 'name', 'description', 'nodes']
pagination_support = True
sorting_support = True
class ShowServiceChainSpec(neutronV20.ShowCommand):
"""Show information of a given service chain spec."""
resource = 'servicechain_spec'
log = logging.getLogger(__name__ + '.ShowServiceChainSpec')
class CreateServiceChainSpec(neutronV20.CreateCommand):
"""Create a service chain spec."""
resource = 'servicechain_spec'
log = logging.getLogger(__name__ + '.CreateServiceChainSpec')
def add_known_arguments(self, parser):
parser.add_argument(
'name',
help=_('Name for the Service Chain Spec.'))
parser.add_argument(
'--description',
help=_('Description of the Service Chain Specification.'))
parser.add_argument(
'--nodes', metavar='NODES', type=utils.str2list,
help=_('Comma separated list of Service Chain Nodes'))
n_utils.add_boolean_argument(
parser, '--shared', dest='shared',
help=_('Shared flag'))
def args2body(self, parsed_args):
body = {self.resource: {}, }
if parsed_args.nodes:
body[self.resource]['nodes'] = [
neutronV20.find_resourceid_by_name_or_id(
self.get_client(),
'servicechain_node',
elem) for elem in parsed_args.nodes]
neutronV20.update_dict(parsed_args, body[self.resource],
['name', 'tenant_id', 'description', 'shared'])
return body
class UpdateServiceChainSpec(neutronV20.UpdateCommand):
"""Update a given service chain spec."""
resource = 'servicechain_spec'
log = logging.getLogger(__name__ + '.UpdateServiceChainSpec')
def add_known_arguments(self, parser):
parser.add_argument(
'--nodes', type=utils.str2list,
help=_('New comma separated list of Service Chain Nodes '
'(to unset use "")'))
n_utils.add_boolean_argument(
parser, '--shared', dest='shared',
help=_('Shared flag'))
def args2body(self, parsed_args):
body = {self.resource: {}, }
if parsed_args.nodes == []:
body[self.resource]['nodes'] = []
elif parsed_args.nodes:
body[self.resource]['nodes'] = [
neutronV20.find_resourceid_by_name_or_id(
self.get_client(),
'servicechain_node',
elem) for elem in parsed_args.nodes]
neutronV20.update_dict(parsed_args, body[self.resource],
['name', 'description', 'shared'])
return body
class DeleteServiceChainSpec(neutronV20.DeleteCommand):
"""Delete a given service chain spec."""
resource = 'servicechain_spec'
log = logging.getLogger(__name__ + '.DeleteServiceChainSpec')

View File

@ -39,7 +39,6 @@ from neutronclient.version import __version__
from gbpclient.gbp.v2_0 import groupbasedpolicy as gbp
from gbpclient.gbp.v2_0 import purge
from gbpclient.gbp.v2_0 import servicechain
VERSION = '2.0'
NEUTRON_API_VERSION = '2.0'
@ -158,36 +157,6 @@ COMMAND_V2 = {
'policy-rule-set-list': gbp.ListPolicyRuleSet,
'policy-rule-set-show': gbp.ShowPolicyRuleSet,
'purge': purge.Purge,
'service-profile-list': servicechain.ListServiceProfile,
'service-profile-show': servicechain.ShowServiceProfile,
'service-profile-create': servicechain.CreateServiceProfile,
'service-profile-delete': servicechain.DeleteServiceProfile,
'service-profile-update': servicechain.UpdateServiceProfile,
'servicechain-node-list': servicechain.ListServiceChainNode,
'servicechain-node-show': servicechain.ShowServiceChainNode,
'servicechain-node-create': servicechain.CreateServiceChainNode,
'servicechain-node-delete': servicechain.DeleteServiceChainNode,
'servicechain-node-update': servicechain.UpdateServiceChainNode,
'servicechain-spec-list': servicechain.ListServiceChainSpec,
'servicechain-spec-show': servicechain.ShowServiceChainSpec,
'servicechain-spec-create': servicechain.CreateServiceChainSpec,
'servicechain-spec-delete': servicechain.DeleteServiceChainSpec,
'servicechain-spec-update': servicechain.UpdateServiceChainSpec,
'servicechain-instance-list': (
servicechain.ListServiceChainInstance
),
'servicechain-instance-show': (
servicechain.ShowServiceChainInstance
),
'servicechain-instance-create': (
servicechain.CreateServiceChainInstance
),
'servicechain-instance-delete': (
servicechain.DeleteServiceChainInstance
),
'servicechain-instance-update': (
servicechain.UpdateServiceChainInstance
),
'pt-create': gbp.CreatePolicyTarget,
'pt-delete': gbp.DeletePolicyTarget,
'pt-update': gbp.UpdatePolicyTarget,
@ -253,36 +222,6 @@ COMMAND_V2 = {
'prs-update': gbp.UpdatePolicyRuleSet,
'prs-list': gbp.ListPolicyRuleSet,
'prs-show': gbp.ShowPolicyRuleSet,
'sp-list': servicechain.ListServiceProfile,
'sp-show': servicechain.ShowServiceProfile,
'sp-create': servicechain.CreateServiceProfile,
'sp-delete': servicechain.DeleteServiceProfile,
'sp-update': servicechain.UpdateServiceProfile,
'scn-list': servicechain.ListServiceChainNode,
'scn-show': servicechain.ShowServiceChainNode,
'scn-create': servicechain.CreateServiceChainNode,
'scn-delete': servicechain.DeleteServiceChainNode,
'scn-update': servicechain.UpdateServiceChainNode,
'scs-list': servicechain.ListServiceChainSpec,
'scs-show': servicechain.ShowServiceChainSpec,
'scs-create': servicechain.CreateServiceChainSpec,
'scs-delete': servicechain.DeleteServiceChainSpec,
'scs-update': servicechain.UpdateServiceChainSpec,
'sci-list': (
servicechain.ListServiceChainInstance
),
'sci-show': (
servicechain.ShowServiceChainInstance
),
'sci-create': (
servicechain.CreateServiceChainInstance
),
'sci-delete': (
servicechain.DeleteServiceChainInstance
),
'sci-update': (
servicechain.UpdateServiceChainInstance
),
}
COMMANDS = {'2.0': COMMAND_V2}

View File

@ -23,6 +23,4 @@ class CLITestV20Purge(test_cli20_purge.CLITestV20Purge):
'policy_rule_set', 'policy_rule',
'policy_classifier', 'policy_action',
'network_service_policy',
'servicechain_instance', 'servicechain_spec',
'servicechain_node', 'service_profile',
'application_policy_group']

View File

@ -1,170 +0,0 @@
# Copyright 2015 OpenStack Foundation.
# All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
import sys
from gbpclient.gbp.v2_0 import servicechain
from gbpclient.tests.unit import test_cli20
class CLITestV20ServiceProfileJSON(test_cli20.CLITestV20Base):
def setUp(self):
super(CLITestV20ServiceProfileJSON, self).setUp()
def test_create_service_profile_with_mandatory_params(self):
"""service-profile-create with all mandatory params."""
resource = 'service_profile'
cmd = servicechain.CreateServiceProfile(test_cli20.MyApp(sys.stdout),
None)
name = 'my-name'
tenant_id = 'my-tenant'
my_id = 'my-id'
args = ['--tenant-id', tenant_id, name]
position_names = ['name', ]
position_values = [name, ]
self._test_create_resource(resource, cmd, name, my_id, args,
position_names, position_values,
tenant_id=tenant_id)
def test_create_service_profile_with_all_params(self):
"""service-profile-create with all params."""
resource = 'service_profile'
cmd = servicechain.CreateServiceProfile(test_cli20.MyApp(sys.stdout),
None)
name = 'my-name'
description = 'My Service Profile'
tenant_id = 'my-tenant'
shared = 'true'
vendor = 'vendor'
insertion_mode = 'some mode'
service_type = 'servicetype1'
service_flavor = 'cherry-garcia'
my_id = 'my-id'
args = ['--description', description,
'--tenant-id', tenant_id,
'--shared', shared,
'--vendor', vendor,
'--insertion-mode', insertion_mode,
'--servicetype', service_type,
'--service-flavor', service_flavor,
name]
position_names = ['name', ]
position_values = [name, ]
self._test_create_resource(resource, cmd, name, my_id, args,
position_names, position_values,
description=description,
tenant_id=tenant_id,
shared=shared,
vendor=vendor,
insertion_mode=insertion_mode,
service_type=service_type,
service_flavor=service_flavor)
def test_list_service_profiles(self):
"""service-profile-list."""
resources = 'service_profiles'
cmd = servicechain.ListServiceProfile(test_cli20.MyApp(sys.stdout),
None)
self._test_list_resources(resources, cmd, True)
def test_list_service_profiles_pagination(self):
"""service-profile-list."""
resources = 'service_profiles'
cmd = servicechain.ListServiceProfile(test_cli20.MyApp(sys.stdout),
None)
self._test_list_resources_with_pagination(resources, cmd)
def test_list_service_profiles_sort(self):
"""service-profile-list --sort-key name --sort-key id --sort-key asc
--sort-key desc
"""
resources = 'service_profiles'
cmd = servicechain.ListServiceProfile(test_cli20.MyApp(sys.stdout),
None)
self._test_list_resources(resources, cmd,
sort_key=["name", "id"],
sort_dir=["asc", "desc"])
def test_list_service_profiles_limit(self):
"""service-profile-list -P."""
resources = 'service_profiles'
cmd = servicechain.ListServiceProfile(test_cli20.MyApp(sys.stdout),
None)
self._test_list_resources(resources, cmd, page_size=1000)
def test_show_service_profile_id(self):
"""service-profile-show test_id."""
resource = 'service_profile'
cmd = servicechain.ShowServiceProfile(test_cli20.MyApp(sys.stdout),
None)
args = ['--fields', 'id', self.test_id]
self._test_show_resource(resource, cmd, self.test_id, args, ['id'])
def test_show_service_profile_id_name(self):
"""service-profile-show."""
resource = 'service_profile'
cmd = servicechain.ShowServiceProfile(test_cli20.MyApp(sys.stdout),
None)
args = ['--fields', 'id', '--fields', 'name', self.test_id]
self._test_show_resource(resource, cmd, self.test_id,
args, ['id', 'name'])
def test_update_service_profile(self):
"""service-profile-update myid --name myname --tags a b."""
resource = 'service_profile'
cmd = servicechain.UpdateServiceProfile(test_cli20.MyApp(sys.stdout),
None)
self._test_update_resource(resource, cmd, 'myid',
['myid', '--name', 'myname',
'--tags', 'a', 'b'],
{'name': 'myname', 'tags': ['a', 'b'], })
def test_update_service_profile_with_all_params(self):
resource = 'service_profile'
cmd = servicechain.UpdateServiceProfile(test_cli20.MyApp(sys.stdout),
None)
name = 'new-name'
description = 'My Updated Service Profile'
shared = 'true'
vendor = 'open-source'
insertion_mode = 'another mode'
service_type = 'servicetype2'
service_flavor = 'phish-food'
body = {
'name': name,
'description': description,
'shared': shared,
'vendor': vendor,
'insertion_mode': insertion_mode,
'service_type': service_type,
'service_flavor': service_flavor}
args = ['myid', '--name', name,
'--description', description,
'--shared', shared,
'--vendor', vendor,
'--insertion-mode', insertion_mode,
'--servicetype', service_type,
'--service-flavor', service_flavor]
self._test_update_resource(resource, cmd, 'myid', args, body)
def test_delete_service_profile(self):
"""service-profile-delete my-id."""
resource = 'service_profile'
cmd = servicechain.DeleteServiceProfile(test_cli20.MyApp(sys.stdout),
None)
my_id = 'my-id'
args = [my_id]
self._test_delete_resource(resource, cmd, my_id, args)

View File

@ -1,145 +0,0 @@
# Copyright 2012 OpenStack Foundation.
# All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
import sys
from gbpclient.gbp.v2_0 import servicechain as sc
from gbpclient.tests.unit import test_cli20
class CLITestV20ServiceChainInstanceJSON(test_cli20.CLITestV20Base):
def setUp(self):
super(CLITestV20ServiceChainInstanceJSON, self).setUp()
def test_create_servicechain_instance_with_mandatory_params(self):
"""service-chain-instance-create with all mandatory params."""
resource = 'servicechain_instance'
cmd = sc.CreateServiceChainInstance(test_cli20.MyApp(sys.stdout), None)
name = 'my-name'
tenant_id = 'my-tenant'
my_id = 'my-id'
args = ['--tenant-id', tenant_id, name]
position_names = ['name', ]
position_values = [name, ]
self._test_create_resource(resource, cmd, name, my_id, args,
position_names, position_values,
tenant_id=tenant_id)
def test_create_servicechain_instance_with_all_params(self):
"""service-chain-instance-create with all params."""
resource = 'servicechain_instance'
cmd = sc.CreateServiceChainInstance(test_cli20.MyApp(sys.stdout), None)
name = 'my-name'
servicechain_spec_id = 'service-chain-spec-id'
tenant_id = 'my-tenant'
description = 'My Service Chain Instance'
my_id = 'my-id'
config_params = 'config'
args = ['--service-chain-spec', servicechain_spec_id,
'--tenant-id', tenant_id,
'--param-values', config_params,
'--description', description,
name]
position_names = ['name', ]
position_values = [name, ]
self._test_create_resource(resource, cmd, name, my_id, args,
position_names, position_values,
servicechain_spec=servicechain_spec_id,
tenant_id=tenant_id,
param_values=config_params,
description=description)
def test_list_servicechain_instances(self):
"""service-chain-instance-list."""
resources = 'servicechain_instances'
cmd = sc.ListServiceChainInstance(test_cli20.MyApp(sys.stdout), None)
self._test_list_resources(resources, cmd, True)
def test_list_servicechain_instances_pagination(self):
"""service-chain-instance-list."""
resources = 'servicechain_instances'
cmd = sc.ListServiceChainInstance(test_cli20.MyApp(sys.stdout), None)
self._test_list_resources_with_pagination(resources, cmd)
def test_list_servicechain_instances_sort(self):
"""service-chain-instance-list --sort-key name --sort-key id
--sort-key asc --sort-key desc
"""
resources = 'servicechain_instances'
cmd = sc.ListServiceChainInstance(test_cli20.MyApp(sys.stdout), None)
self._test_list_resources(resources, cmd,
sort_key=["name", "id"],
sort_dir=["asc", "desc"])
def test_list_servicechain_instances_limit(self):
"""service-chain-instance-list -P."""
resources = 'servicechain_instances'
cmd = sc.ListServiceChainInstance(test_cli20.MyApp(sys.stdout), None)
self._test_list_resources(resources, cmd, page_size=1000)
def test_show_servicechain_instance_id(self):
"""service-chain-instance-show test_id."""
resource = 'servicechain_instance'
cmd = sc.ShowServiceChainInstance(test_cli20.MyApp(sys.stdout), None)
args = ['--fields', 'id', self.test_id]
self._test_show_resource(resource, cmd, self.test_id, args, ['id'])
def test_show_servicechain_instance_id_name(self):
"""service-chain-instance-show."""
resource = 'servicechain_instance'
cmd = sc.ShowServiceChainInstance(test_cli20.MyApp(sys.stdout), None)
args = ['--fields', 'id', '--fields', 'name', self.test_id]
self._test_show_resource(resource, cmd, self.test_id,
args, ['id', 'name'])
def test_update_servicechain_instance(self):
"""service-chain-instance-update myid --name myname --tags a b."""
resource = 'servicechain_instance'
cmd = sc.UpdateServiceChainInstance(test_cli20.MyApp(sys.stdout), None)
self._test_update_resource(resource, cmd, 'myid',
['myid', '--name', 'myname',
'--tags', 'a', 'b'],
{'name': 'myname', 'tags': ['a', 'b'], })
def test_update_servicechain_instance_with_chainspec(self):
resource = 'servicechain_instance'
cmd = sc.UpdateServiceChainInstance(test_cli20.MyApp(sys.stdout), None)
body = {
'servicechain_spec': 'my-spec-id'
}
args = ['myid', '--service-chain-spec', 'my-spec-id']
self._test_update_resource(resource, cmd, 'myid', args, body)
def test_update_servicechain_instance_with_chainspec_and_port(self):
resource = 'servicechain_instance'
cmd = sc.UpdateServiceChainInstance(test_cli20.MyApp(sys.stdout), None)
body = {
'name': 'newname',
'servicechain_spec': 'my-spec-id',
'port': 'my-port-id'
}
args = ['myid', '--name', 'newname',
'--service-chain-spec', 'my-spec-id',
'--port', 'my-port-id']
self._test_update_resource(resource, cmd, 'myid', args, body)
def test_delete_servicechain_instance(self):
"""service-chain-instance-delete my-id."""
resource = 'servicechain_instance'
cmd = sc.DeleteServiceChainInstance(test_cli20.MyApp(sys.stdout), None)
my_id = 'my-id'
args = [my_id]
self._test_delete_resource(resource, cmd, my_id, args)

View File

@ -1,183 +0,0 @@
# Copyright 2012 OpenStack Foundation.
# All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
import sys
from gbpclient.gbp.v2_0 import servicechain
from gbpclient.tests.unit import test_cli20
class CLITestV20ServiceChainNodeJSON(test_cli20.CLITestV20Base):
def setUp(self):
super(CLITestV20ServiceChainNodeJSON, self).setUp()
def test_create_servicechain_node_with_mandatory_params(self):
"""service-chain-node-create with all mandatory params."""
resource = 'servicechain_node'
cmd = servicechain.CreateServiceChainNode(test_cli20.MyApp(sys.stdout),
None)
name = 'my-name'
tenant_id = 'my-tenant'
my_id = 'my-id'
args = ['--tenant-id', tenant_id, name]
position_names = ['name', ]
position_values = [name, ]
self._test_create_resource(resource, cmd, name, my_id, args,
position_names, position_values,
tenant_id=tenant_id)
def test_create_servicechain_node_with_all_params(self):
"""service-chain-node-create with all params."""
resource = 'servicechain_node'
cmd = servicechain.CreateServiceChainNode(test_cli20.MyApp(sys.stdout),
None)
name = 'my-name'
service_type = 'servicetype1'
config = 'config1'
tenant_id = 'my-tenant'
description = 'My Service Chain Node'
service_profile_id = 'my-service-profile'
my_id = 'my-id'
shared = 'true'
args = ['--servicetype', service_type,
'--config', config,
'--tenant-id', tenant_id,
'--description', description,
'--service-profile', service_profile_id,
'--shared', shared,
name]
position_names = ['name', ]
position_values = [name, ]
self._test_create_resource(resource, cmd, name, my_id, args,
position_names, position_values,
service_type=service_type, config=config,
tenant_id=tenant_id,
description=description,
service_profile_id=service_profile_id,
shared=shared)
def test_list_servicechain_nodes(self):
"""service-chain-node-list."""
resources = 'servicechain_nodes'
cmd = servicechain.ListServiceChainNode(test_cli20.MyApp(sys.stdout),
None)
self._test_list_resources(resources, cmd, True)
def test_list_servicechain_nodes_pagination(self):
"""service-chain-node-list."""
resources = 'servicechain_nodes'
cmd = servicechain.ListServiceChainNode(test_cli20.MyApp(sys.stdout),
None)
self._test_list_resources_with_pagination(resources, cmd)
def test_list_servicechain_nodes_sort(self):
"""service-chain-node-list --sort-key name --sort-key id --sort-key asc
--sort-key desc
"""
resources = 'servicechain_nodes'
cmd = servicechain.ListServiceChainNode(test_cli20.MyApp(sys.stdout),
None)
self._test_list_resources(resources, cmd,
sort_key=["name", "id"],
sort_dir=["asc", "desc"])
def test_list_servicechain_nodes_limit(self):
"""service-chain-node-list -P."""
resources = 'servicechain_nodes'
cmd = servicechain.ListServiceChainNode(test_cli20.MyApp(sys.stdout),
None)
self._test_list_resources(resources, cmd, page_size=1000)
def test_show_servicechain_node_id(self):
"""service-chain-node-show test_id."""
resource = 'servicechain_node'
cmd = servicechain.ShowServiceChainNode(test_cli20.MyApp(sys.stdout),
None)
args = ['--fields', 'id', self.test_id]
self._test_show_resource(resource, cmd, self.test_id, args, ['id'])
def test_show_servicechain_node_id_name(self):
"""service-chain-node-show."""
resource = 'servicechain_node'
cmd = servicechain.ShowServiceChainNode(test_cli20.MyApp(sys.stdout),
None)
args = ['--fields', 'id', '--fields', 'name', self.test_id]
self._test_show_resource(resource, cmd, self.test_id,
args, ['id', 'name'])
def test_update_servicechain_node(self):
"""service-chain-node-update myid --name myname --tags a b."""
resource = 'servicechain_node'
cmd = servicechain.UpdateServiceChainNode(test_cli20.MyApp(sys.stdout),
None)
self._test_update_resource(resource, cmd, 'myid',
['myid', '--name', 'myname',
'--tags', 'a', 'b'],
{'name': 'myname', 'tags': ['a', 'b'], })
def test_update_servicechain_node_with_all_params(self):
resource = 'servicechain_node'
cmd = servicechain.UpdateServiceChainNode(test_cli20.MyApp(sys.stdout),
None)
shared = 'true'
body = {
'name': 'new_name',
'description': 'new_description',
'service_profile_id': 'new_service_profile_id',
'shared': shared,
}
args = ['myid', '--name', 'new_name',
'--description', 'new_description',
'--service-profile', 'new_service_profile_id',
'--shared', shared]
self._test_update_resource(resource, cmd, 'myid', args, body)
# REVISIT(rkukura): Not sure why the following two methods are
# needed, since allow_put for both the service_type and config
# attributes is False.
def test_update_servicechain_node_with_servicetype(self):
resource = 'servicechain_node'
cmd = servicechain.UpdateServiceChainNode(test_cli20.MyApp(sys.stdout),
None)
body = {
'service_type': 'service_type1'
}
args = ['myid', '--servicetype', 'service_type1']
self._test_update_resource(resource, cmd, 'myid', args, body)
def test_update_servicechain_node_with_type_and_config(self):
resource = 'servicechain_node'
cmd = servicechain.UpdateServiceChainNode(test_cli20.MyApp(sys.stdout),
None)
body = {
'name': 'newname',
'service_type': 'service_type1',
'config': 'config1',
}
args = ['myid', '--name', 'newname',
'--servicetype', 'service_type1',
'--config', 'config1']
self._test_update_resource(resource, cmd, 'myid', args, body)
def test_delete_servicechain_node(self):
"""service-chain-node-delete my-id."""
resource = 'servicechain_node'
cmd = servicechain.DeleteServiceChainNode(test_cli20.MyApp(sys.stdout),
None)
my_id = 'my-id'
args = [my_id]
self._test_delete_resource(resource, cmd, my_id, args)

View File

@ -1,161 +0,0 @@
# Copyright 2012 OpenStack Foundation.
# All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
import sys
from gbpclient.gbp.v2_0 import servicechain
from gbpclient.tests.unit import test_cli20
class CLITestV20ServiceChainSpecJSON(test_cli20.CLITestV20Base):
def setUp(self):
super(CLITestV20ServiceChainSpecJSON, self).setUp()
def test_create_servicechain_spec_with_mandatory_params(self):
"""service-chain-spec-create with all mandatory params."""
resource = 'servicechain_spec'
cmd = servicechain.CreateServiceChainSpec(test_cli20.MyApp(sys.stdout),
None)
name = 'my-name'
tenant_id = 'my-tenant'
my_id = 'my-id'
args = ['--tenant-id', tenant_id, name]
position_names = ['name', ]
position_values = [name, ]
self._test_create_resource(resource, cmd, name, my_id, args,
position_names, position_values,
tenant_id=tenant_id)
def test_create_servicechain_spec_with_all_params(self):
"""service-chain-spec-create with all params."""
resource = 'servicechain_spec'
cmd = servicechain.CreateServiceChainSpec(test_cli20.MyApp(sys.stdout),
None)
name = 'my-name'
nodes_arg = 'node1,node2'
nodes_res = ['node1', 'node2']
tenant_id = 'my-tenant'
description = 'My Service Chain Spec'
my_id = 'my-id'
shared = 'true'
args = ['--nodes', nodes_arg,
'--tenant-id', tenant_id,
'--description', description,
'--shared', shared,
name]
position_names = ['name', ]
position_values = [name, ]
self._test_create_resource(resource, cmd, name, my_id, args,
position_names, position_values,
nodes=nodes_res, tenant_id=tenant_id,
description=description, shared=shared)
def test_list_servicechain_specs(self):
"""service-chain-spec-list."""
resources = 'servicechain_specs'
cmd = servicechain.ListServiceChainSpec(test_cli20.MyApp(sys.stdout),
None)
self._test_list_resources(resources, cmd, True)
def test_list_servicechain_specs_pagination(self):
"""service-chain-spec-list."""
resources = 'servicechain_specs'
cmd = servicechain.ListServiceChainSpec(test_cli20.MyApp(sys.stdout),
None)
self._test_list_resources_with_pagination(resources, cmd)
def test_list_servicechain_specs_sort(self):
"""service-chain-spec-list --sort-key name --sort-key id --sort-key asc
--sort-key desc
"""
resources = 'servicechain_specs'
cmd = servicechain.ListServiceChainSpec(test_cli20.MyApp(sys.stdout),
None)
self._test_list_resources(resources, cmd,
sort_key=["name", "id"],
sort_dir=["asc", "desc"])
def test_list_servicechain_specs_limit(self):
"""service-chain-spec-list -P."""
resources = 'servicechain_specs'
cmd = servicechain.ListServiceChainSpec(test_cli20.MyApp(sys.stdout),
None)
self._test_list_resources(resources, cmd, page_size=1000)
def test_show_servicechain_spec_id(self):
"""service-chain-spec-show test_id."""
resource = 'servicechain_spec'
cmd = servicechain.ShowServiceChainSpec(test_cli20.MyApp(sys.stdout),
None)
args = ['--fields', 'id', self.test_id]
self._test_show_resource(resource, cmd, self.test_id, args, ['id'])
def test_show_servicechain_spec_id_name(self):
"""service-chain-spec-show."""
resource = 'servicechain_spec'
cmd = servicechain.ShowServiceChainSpec(test_cli20.MyApp(sys.stdout),
None)
args = ['--fields', 'id', '--fields', 'name', self.test_id]
self._test_show_resource(resource, cmd, self.test_id,
args, ['id', 'name'])
def test_update_servicechain_spec(self):
"""service-chain-spec-update myid --name myname --tags a b."""
resource = 'servicechain_spec'
cmd = servicechain.UpdateServiceChainSpec(test_cli20.MyApp(sys.stdout),
None)
self._test_update_resource(resource, cmd, 'myid',
['myid', '--name', 'myname',
'--tags', 'a', 'b'],
{'name': 'myname', 'tags': ['a', 'b'], })
def test_update_servicechain_node_with_all_params(self):
resource = 'servicechain_spec'
cmd = servicechain.UpdateServiceChainSpec(test_cli20.MyApp(sys.stdout),
None)
shared = 'true'
nodes_arg = 'node1,node2'
nodes_res = ['node1', 'node2']
body = {
'name': 'new_name',
'description': 'new_description',
'nodes': nodes_res,
'shared': shared
}
args = ['myid', '--name', 'new_name',
'--description', 'new_description',
'--nodes', nodes_arg,
'--shared', shared]
self._test_update_resource(resource, cmd, 'myid', args, body)
def test_update_servicechain_node_unset_nodes(self):
resource = 'servicechain_spec'
cmd = servicechain.UpdateServiceChainSpec(test_cli20.MyApp(sys.stdout),
None)
nodes_arg = ''
nodes_res = []
body = {'nodes': nodes_res}
args = ['myid', '--nodes', nodes_arg]
self._test_update_resource(resource, cmd, 'myid', args, body)
def test_delete_servicechain_spec(self):
"""service-chain-spec-delete my-id."""
resource = 'servicechain_spec'
cmd = servicechain.DeleteServiceChainSpec(test_cli20.MyApp(sys.stdout),
None)
my_id = 'my-id'
args = [my_id]
self._test_delete_resource(resource, cmd, my_id, args)

View File

@ -148,14 +148,6 @@ class Client(clientV2_0.Client):
policy_rule_path = "/grouppolicy/policy_rules/%s"
policy_rule_sets_path = "/grouppolicy/policy_rule_sets"
policy_rule_set_path = "/grouppolicy/policy_rule_sets/%s"
service_profiles_path = "/servicechain/service_profiles"
service_profile_path = "/servicechain/service_profiles/%s"
servicechain_nodes_path = "/servicechain/servicechain_nodes"
servicechain_node_path = "/servicechain/servicechain_nodes/%s"
servicechain_specs_path = "/servicechain/servicechain_specs"
servicechain_spec_path = "/servicechain/servicechain_specs/%s"
servicechain_instances_path = "/servicechain/servicechain_instances"
servicechain_instance_path = "/servicechain/servicechain_instances/%s"
# API has no way to report plurals, so we have to hard code them
EXTED_PLURALS = {'policy_targets': 'policy_target',
@ -508,110 +500,6 @@ class Client(clientV2_0.Client):
"""Deletes the specified Policy Rule Set."""
return self.delete(self.policy_rule_set_path % (policy_rule_set))
def list_service_profiles(self, retrieve_all=True, **_params):
"""Fetches a list of all service profiles for a tenant."""
# Pass filters in "params" argument to do_request
return self.list('service_profiles', self.service_profiles_path,
retrieve_all, **_params)
def show_service_profile(self, service_profile, **_params):
"""Fetches information of a certain service profile."""
return self.get(self.service_profile_path % (service_profile),
params=_params)
def create_service_profile(self, body=None):
"""Creates a new service profile."""
return self.post(self.service_profiles_path, body=body)
def update_service_profile(self, service_profile, body=None):
"""Updates a service profile."""
return self.put(self.service_profile_path % (service_profile),
body=body)
def delete_service_profile(self, service_profile):
"""Deletes the specified service profile."""
return self.delete(self.service_profile_path % (service_profile))
def list_servicechain_nodes(self, retrieve_all=True, **_params):
"""Fetches a list of all service chain nodes for a tenant."""
# Pass filters in "params" argument to do_request
return self.list('servicechain_nodes', self.servicechain_nodes_path,
retrieve_all, **_params)
def show_servicechain_node(self, servicechain_node, **_params):
"""Fetches information of a certain service chain node."""
return self.get(self.servicechain_node_path % (servicechain_node),
params=_params)
def create_servicechain_node(self, body=None):
"""Creates a new service chain node."""
return self.post(self.servicechain_nodes_path, body=body)
def update_servicechain_node(self, servicechain_node, body=None):
"""Updates a service chain node."""
return self.put(self.servicechain_node_path % (servicechain_node),
body=body)
def delete_servicechain_node(self, servicechain_node):
"""Deletes the specified service chain node."""
return self.delete(self.servicechain_node_path % (servicechain_node))
def list_servicechain_specs(self, retrieve_all=True, **_params):
"""Fetches a list of all service chain specs for a tenant."""
# Pass filters in "params" argument to do_request
return self.list('servicechain_specs', self.servicechain_specs_path,
retrieve_all, **_params)
def show_servicechain_spec(self, servicechain_spec, **_params):
"""Fetches information of a certain service chain spec."""
return self.get(self.servicechain_spec_path % (servicechain_spec),
params=_params)
def create_servicechain_spec(self, body=None):
"""Creates a new service chain spec."""
return self.post(self.servicechain_specs_path, body=body)
def update_servicechain_spec(self, servicechain_spec, body=None):
"""Updates a service chain spec."""
return self.put(self.servicechain_spec_path % (servicechain_spec),
body=body)
def delete_servicechain_spec(self, servicechain_spec):
"""Deletes the specified service chain spec."""
return self.delete(self.servicechain_spec_path % (servicechain_spec))
def list_servicechain_instances(self, retrieve_all=True, **_params):
"""Fetches a list of all service chain instances for a tenant."""
# Pass filters in "params" argument to do_request
return self.list('servicechain_instances',
self.servicechain_instances_path,
retrieve_all, **_params)
def show_servicechain_instance(self, servicechain_instance, **_params):
"""Fetches information of a certain service chain instance."""
return self.get(self.servicechain_instance_path %
(servicechain_instance), params=_params)
def create_servicechain_instance(self, body=None):
"""Creates a new service chain instance."""
return self.post(self.servicechain_instances_path, body=body)
def update_servicechain_instance(self, servicechain_instance, body=None):
"""Updates a service chain instance."""
return self.put(self.servicechain_instance_path %
(servicechain_instance), body=body)
def delete_servicechain_instance(self, servicechain_instance):
"""Deletes the specified service chain instance."""
return self.delete(self.servicechain_instance_path %
(servicechain_instance))
def purge(self, tenant_id):
purge_obj = gbpclient_purge.PurgeAPI(None, None, self)
purge_obj.take_action(tenant_id)