1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
# 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.
from tempest_lib.common.utils import data_utils
from functional.common import test
BASIC_LIST_HEADERS = ['ID', 'Name']
class IdentityTests(test.TestCase):
"""Functional tests for Identity commands. """
USER_FIELDS = ['email', 'enabled', 'id', 'name', 'project_id',
'username', 'domain_id', 'default_project_id']
PROJECT_FIELDS = ['enabled', 'id', 'name', 'description', 'domain_id']
TOKEN_FIELDS = ['expires', 'id', 'project_id', 'user_id']
ROLE_FIELDS = ['id', 'name', 'links', 'domain_id']
SERVICE_FIELDS = ['id', 'enabled', 'name', 'type', 'description']
ENDPOINT_FIELDS = ['id', 'region', 'service_id', 'service_name',
'service_type', 'enabled', 'publicurl',
'adminurl', 'internalurl']
EC2_CREDENTIALS_FIELDS = ['access', 'project_id', 'secret',
'trust_id', 'user_id']
EC2_CREDENTIALS_LIST_HEADERS = ['Access', 'Secret',
'Project ID', 'User ID']
CATALOG_LIST_HEADERS = ['Name', 'Type', 'Endpoints']
ENDPOINT_LIST_HEADERS = ['ID', 'Region', 'Service Name', 'Service Type']
@classmethod
def setUpClass(cls):
if hasattr(super(IdentityTests, cls), 'setUpClass'):
super(IdentityTests, cls).setUpClass()
# create dummy project
cls.project_name = data_utils.rand_name('TestProject')
cls.project_description = data_utils.rand_name('description')
cls.openstack(
'project create '
'--description %(description)s '
'--enable '
'%(name)s' % {'description': cls.project_description,
'name': cls.project_name})
@classmethod
def tearDownClass(cls):
cls.openstack('project delete %s' % cls.project_name)
if hasattr(super(IdentityTests, cls), 'tearDownClass'):
super(IdentityTests, cls).tearDownClass()
def _create_dummy_project(self, add_clean_up=True):
project_name = data_utils.rand_name('TestProject')
project_description = data_utils.rand_name('description')
raw_output = self.openstack(
'project create '
'--description %(description)s '
'--enable %(name)s' % {'description': project_description,
'name': project_name})
items = self.parse_show(raw_output)
self.assert_show_fields(items, self.PROJECT_FIELDS)
project = self.parse_show_as_object(raw_output)
if add_clean_up:
self.addCleanup(
self.openstack,
'project delete %s' % project['id'])
return project_name
def _create_dummy_user(self, add_clean_up=True):
username = data_utils.rand_name('TestUser')
password = data_utils.rand_name('password')
email = data_utils.rand_name() + '@example.com'
raw_output = self.openstack(
'user create '
'--project %(project)s '
'--password %(password)s '
'--email %(email)s '
'--enable '
'%(name)s' % {'project': self.project_name,
'email': email,
'password': password,
'name': username})
items = self.parse_show(raw_output)
self.assert_show_fields(items, self.USER_FIELDS)
if add_clean_up:
self.addCleanup(
self.openstack,
'user delete %s' % self.parse_show_as_object(raw_output)['id'])
return username
def _create_dummy_role(self, add_clean_up=True):
role_name = data_utils.rand_name('TestRole')
raw_output = self.openstack('role create %s' % role_name)
items = self.parse_show(raw_output)
self.assert_show_fields(items, self.ROLE_FIELDS)
role = self.parse_show_as_object(raw_output)
self.assertEqual(role_name, role['name'])
if add_clean_up:
self.addCleanup(
self.openstack,
'role delete %s' % role['id'])
return role_name
def _create_dummy_ec2_credentials(self, add_clean_up=True):
raw_output = self.openstack('ec2 credentials create')
items = self.parse_show(raw_output)
self.assert_show_fields(items, self.EC2_CREDENTIALS_FIELDS)
ec2_credentials = self.parse_show_as_object(raw_output)
access_key = ec2_credentials['access']
if add_clean_up:
self.addCleanup(
self.openstack,
'ec2 credentials delete %s' % access_key)
return access_key
def _create_dummy_token(self, add_clean_up=True):
raw_output = self.openstack('token issue')
items = self.parse_show(raw_output)
self.assert_show_fields(items, self.TOKEN_FIELDS)
token = self.parse_show_as_object(raw_output)
if add_clean_up:
self.addCleanup(self.openstack,
'token revoke %s' % token['id'])
return token['id']
def _create_dummy_service(self, add_clean_up=True):
service_name = data_utils.rand_name('TestService')
description = data_utils.rand_name('description')
type_name = data_utils.rand_name('TestType')
raw_output = self.openstack(
'service create '
'--name %(name)s '
'--description %(description)s '
'%(type)s' % {'name': service_name,
'description': description,
'type': type_name})
items = self.parse_show(raw_output)
self.assert_show_fields(items, self.SERVICE_FIELDS)
if add_clean_up:
service = self.parse_show_as_object(raw_output)
self.addCleanup(self.openstack,
'service delete %s' % service['id'])
return service_name
def _create_dummy_endpoint(self, add_clean_up=True):
region_id = data_utils.rand_name('TestRegion')
service_name = self._create_dummy_service()
public_url = data_utils.rand_url()
admin_url = data_utils.rand_url()
internal_url = data_utils.rand_url()
raw_output = self.openstack(
'endpoint create '
'--publicurl %(publicurl)s '
'--adminurl %(adminurl)s '
'--internalurl %(internalurl)s '
'--region %(region)s '
'%(service)s' % {'publicurl': public_url,
'adminurl': admin_url,
'internalurl': internal_url,
'region': region_id,
'service': service_name})
items = self.parse_show(raw_output)
self.assert_show_fields(items, self.ENDPOINT_FIELDS)
endpoint = self.parse_show_as_object(raw_output)
if add_clean_up:
self.addCleanup(
self.openstack,
'endpoint delete %s' % endpoint['id'])
return endpoint['id']
|