本文整理汇总了Python中tempest.common.utils.data_utils.rand_name函数的典型用法代码示例。如果您正苦于以下问题:Python rand_name函数的具体用法?Python rand_name怎么用?Python rand_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rand_name函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_copy_object_across_containers
def test_copy_object_across_containers(self):
# create a container to use as asource container
src_container_name = data_utils.rand_name(name="TestSourceContainer")
self.container_client.create_container(src_container_name)
self.containers.append(src_container_name)
# create a container to use as a destination container
dst_container_name = data_utils.rand_name(name="TestDestinationContainer")
self.container_client.create_container(dst_container_name)
self.containers.append(dst_container_name)
# create object in source container
object_name = data_utils.rand_name(name="Object")
data = data_utils.arbitrary_string(size=len(object_name) * 2, base_text=object_name)
resp, _ = self.object_client.create_object(src_container_name, object_name, data)
# set object metadata
meta_key = data_utils.rand_name(name="test-")
meta_value = data_utils.rand_name(name="MetaValue-")
orig_metadata = {meta_key: meta_value}
resp, _ = self.object_client.update_object_metadata(src_container_name, object_name, orig_metadata)
self.assertIn(int(resp["status"]), HTTP_SUCCESS)
self.assertHeaders(resp, "Object", "POST")
# copy object from source container to destination container
resp, _ = self.object_client.copy_object_across_containers(
src_container_name, object_name, dst_container_name, object_name
)
self.assertEqual(resp["status"], "201")
self.assertHeaders(resp, "Object", "PUT")
# check if object is present in destination container
resp, body = self.object_client.get_object(dst_container_name, object_name)
self.assertEqual(body, data)
actual_meta_key = "x-object-meta-" + meta_key
self.assertIn(actual_meta_key, resp)
self.assertEqual(resp[actual_meta_key], meta_value)
示例2: test_aggregate_create_update_with_az
def test_aggregate_create_update_with_az(self):
# Update an aggregate and ensure properties are updated correctly
self.useFixture(fixtures.LockFixture('availability_zone'))
aggregate_name = rand_name(self.aggregate_name_prefix)
az_name = rand_name(self.az_name_prefix)
resp, aggregate = self.client.create_aggregate(aggregate_name, az_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
self.assertEqual(200, resp.status)
self.assertEqual(aggregate_name, aggregate['name'])
self.assertEqual(az_name, aggregate['availability_zone'])
self.assertIsNotNone(aggregate['id'])
aggregate_id = aggregate['id']
new_aggregate_name = aggregate_name + '_new'
new_az_name = az_name + '_new'
resp, resp_aggregate = self.client.update_aggregate(aggregate_id,
new_aggregate_name,
new_az_name)
self.assertEqual(200, resp.status)
self.assertEqual(new_aggregate_name, resp_aggregate['name'])
self.assertEqual(new_az_name, resp_aggregate['availability_zone'])
resp, aggregates = self.client.list_aggregates()
self.assertEqual(200, resp.status)
self.assertIn((aggregate_id, new_aggregate_name, new_az_name),
map(lambda x:
(x['id'], x['name'], x['availability_zone']),
aggregates))
示例3: test_create_update_delete_domain
def test_create_update_delete_domain(self):
d_name = data_utils.rand_name('domain-')
d_desc = data_utils.rand_name('domain-desc-')
domain = self.client.create_domain(
d_name, description=d_desc)
self.addCleanup(self._delete_domain, domain['id'])
self.assertIn('id', domain)
self.assertIn('description', domain)
self.assertIn('name', domain)
self.assertIn('enabled', domain)
self.assertIn('links', domain)
self.assertIsNotNone(domain['id'])
self.assertEqual(d_name, domain['name'])
self.assertEqual(d_desc, domain['description'])
self.assertEqual(True, domain['enabled'])
new_desc = data_utils.rand_name('new-desc-')
new_name = data_utils.rand_name('new-name-')
updated_domain = self.client.update_domain(
domain['id'], name=new_name, description=new_desc)
self.assertIn('id', updated_domain)
self.assertIn('description', updated_domain)
self.assertIn('name', updated_domain)
self.assertIn('enabled', updated_domain)
self.assertIn('links', updated_domain)
self.assertIsNotNone(updated_domain['id'])
self.assertEqual(new_name, updated_domain['name'])
self.assertEqual(new_desc, updated_domain['description'])
self.assertEqual('true', str(updated_domain['enabled']).lower())
fetched_domain = self.client.get_domain(domain['id'])
self.assertEqual(new_name, fetched_domain['name'])
self.assertEqual(new_desc, fetched_domain['description'])
self.assertEqual('true', str(fetched_domain['enabled']).lower())
示例4: test_project_create_with_parent
def test_project_create_with_parent(self):
# Create root project without providing a parent_id
self.data.setup_test_domain()
domain_id = self.data.domain['id']
root_project_name = data_utils.rand_name('root_project')
root_project = self.projects_client.create_project(
root_project_name, domain_id=domain_id)['project']
self.addCleanup(
self.projects_client.delete_project, root_project['id'])
root_project_id = root_project['id']
parent_id = root_project['parent_id']
self.assertEqual(root_project_name, root_project['name'])
# If not provided, the parent_id must point to the top level
# project in the hierarchy, i.e. its domain
self.assertEqual(domain_id, parent_id)
# Create a project using root_project_id as parent_id
project_name = data_utils.rand_name('project')
project = self.projects_client.create_project(
project_name, domain_id=domain_id,
parent_id=root_project_id)['project']
self.addCleanup(self.projects_client.delete_project, project['id'])
parent_id = project['parent_id']
self.assertEqual(project_name, project['name'])
self.assertEqual(root_project_id, parent_id)
示例5: test_create_delete_token
def test_create_delete_token(self):
# get a token by username and password
user_name = data_utils.rand_name(name='user-')
user_password = data_utils.rand_name(name='pass-')
# first:create a tenant
tenant_name = data_utils.rand_name(name='tenant-')
resp, tenant = self.client.create_tenant(tenant_name)
self.assertEqual(200, resp.status)
self.data.tenants.append(tenant)
# second:create a user
resp, user = self.client.create_user(user_name, user_password,
tenant['id'], '')
self.assertEqual(200, resp.status)
self.data.users.append(user)
# then get a token for the user
rsp, body = self.token_client.auth(user_name,
user_password,
tenant['name'])
access_data = json.loads(body)['access']
self.assertEqual(rsp['status'], '200')
self.assertEqual(access_data['token']['tenant']['name'],
tenant['name'])
# then delete the token
token_id = access_data['token']['id']
resp, body = self.client.delete_token(token_id)
self.assertEqual(resp['status'], '204')
示例6: test_create_update_get_delete_record
def test_create_update_get_delete_record(self):
# Create Domain
name = data_utils.rand_name('domain') + '.com.'
email = data_utils.rand_name('dns') + '@testmail.com'
_, domain = self.dns_domains_client.create_domain(name, email)
self.addCleanup(self.dns_domains_client.delete_domain, domain['id'])
# Create Record
r_name = 'www.' + name
r_data = "192.0.2.4"
_, record = self.client.create_record(domain_id=domain['id'],
name=r_name, data=r_data,
type='A')
self.addCleanup(self._delete_record, domain['id'], record['id'])
self.assertIsNotNone(record['id'])
self.assertEqual(domain['id'], record['domain_id'])
self.assertEqual(r_name, record['name'])
self.assertEqual(r_data, record['data'])
self.assertEqual('A', record['type'])
# Update Record with data and ttl
r_data1 = "192.0.2.5"
r_ttl = 3600
_, update_record = self.client.update_record(domain_id=domain['id'],
record_id=record['id'],
name=r_name, type='A',
data=r_data1, ttl=r_ttl)
self.assertEqual(r_data1, update_record['data'])
self.assertEqual(r_ttl, update_record['ttl'])
# GET record
_, get_record = self.client.get_record(domain_id=domain['id'],
record_id=record['id'])
self.assertEqual(update_record['data'], get_record['data'])
self.assertEqual(update_record['name'], get_record['name'])
self.assertEqual(update_record['type'], get_record['type'])
self.assertEqual(update_record['ttl'], get_record['ttl'])
self.assertEqual(update_record['domain_id'], get_record['domain_id'])
示例7: test_get_updated_quotas
def test_get_updated_quotas(self):
# Verify that GET shows the updated quota set of project
project_name = data_utils.rand_name('cpu_quota_project')
project_desc = project_name + '-desc'
project = self.identity_utils.create_project(name=project_name,
description=project_desc)
project_id = project['id']
self.addCleanup(self.identity_utils.delete_project, project_id)
self.adm_client.update_quota_set(project_id, ram='5120')
quota_set = self.adm_client.show_quota_set(project_id)['quota_set']
self.assertEqual(5120, quota_set['ram'])
# Verify that GET shows the updated quota set of user
user_name = data_utils.rand_name('cpu_quota_user')
password = data_utils.rand_name('password')
email = user_name + '@testmail.tm'
user = self.identity_utils.create_user(username=user_name,
password=password,
project=project,
email=email)
if 'user' in user:
user = user['user']
user_id = user['id']
self.addCleanup(self.identity_utils.delete_user, user_id)
self.adm_client.update_quota_set(project_id,
user_id=user_id,
ram='2048')
quota_set = self.adm_client.show_quota_set(
project_id, user_id=user_id)['quota_set']
self.assertEqual(2048, quota_set['ram'])
示例8: test_list_alarm_definitions_with_severity
def test_list_alarm_definitions_with_severity(self):
name = data_utils.rand_name('alarm_definition')
expression = 'avg(cpu_utilization) >= 1000'
alarm_definition = helpers.create_alarm_definition(
name=name,
description="description",
expression=expression,
severity="LOW")
resp, res_body_create_alarm_def = self.monasca_client.\
create_alarm_definitions(alarm_definition)
self.assertEqual(201, resp.status)
name = data_utils.rand_name('alarm_definition')
expression = 'avg(cpu_utilization) >= 1000'
alarm_definition = helpers.create_alarm_definition(
name=name,
description="description",
expression=expression,
severity="MEDIUM")
resp, res_body_create_alarm_def = self.monasca_client.\
create_alarm_definitions(alarm_definition)
self.assertEqual(201, resp.status)
query_param = '?severity=MEDIUM'
resp, response_body = self.monasca_client.\
list_alarm_definitions(query_param)
self._verify_list_alarm_definitions_response_body(resp, response_body)
elements = response_body['elements']
self._verify_list_get_alarm_definitions_elements(
elements, 1, res_body_create_alarm_def)
links = response_body['links']
self._verify_list_alarm_definitions_links(links)
示例9: test_create_alarm_definition_with_notification
def test_create_alarm_definition_with_notification(self):
notification_name = data_utils.rand_name('notification-')
notification_type = 'EMAIL'
notification_address = '[email protected]'
resp, response_body = self.monasca_client.create_notification_method(
name=notification_name, type=notification_type,
address=notification_address)
notification_id = self._verify_create_notification_method(
resp, response_body, notification_name, notification_type,
notification_address)
# Create an alarm definition
alarm_def_name = data_utils.rand_name('monitoring_alarm_definition')
expression = "mem_total_mb > 0"
alarm_definition = helpers.create_alarm_definition(
name=alarm_def_name,
expression=expression,
alarm_actions=[notification_id],
ok_actions=[notification_id],
undetermined_actions=[notification_id],
severity="LOW")
resp, response_body = self.monasca_client.create_alarm_definitions(
alarm_definition)
self._verify_create_alarm_definitions(resp, response_body,
alarm_definition)
self.assertEqual(notification_id, response_body['ok_actions'][0])
self.assertEqual(notification_id, response_body['alarm_actions'][0])
self.assertEqual(notification_id,
response_body['undetermined_actions'][0])
self._delete_notification(notification_id)
示例10: test_create_get_delete_service
def test_create_get_delete_service(self):
# GET Service
# Creating a Service
name = data_utils.rand_name('service')
s_type = data_utils.rand_name('type')
description = data_utils.rand_name('description')
service_data = self.services_client.create_service(
name=name, type=s_type,
description=description)['OS-KSADM:service']
self.assertFalse(service_data['id'] is None)
self.addCleanup(self._del_service, service_data['id'])
# Verifying response body of create service
self.assertIn('id', service_data)
self.assertIn('name', service_data)
self.assertEqual(name, service_data['name'])
self.assertIn('type', service_data)
self.assertEqual(s_type, service_data['type'])
self.assertIn('description', service_data)
self.assertEqual(description, service_data['description'])
# Get service
fetched_service = (
self.services_client.show_service(service_data['id'])
['OS-KSADM:service'])
# verifying the existence of service created
self.assertIn('id', fetched_service)
self.assertEqual(fetched_service['id'], service_data['id'])
self.assertIn('name', fetched_service)
self.assertEqual(fetched_service['name'], service_data['name'])
self.assertIn('type', fetched_service)
self.assertEqual(fetched_service['type'], service_data['type'])
self.assertIn('description', fetched_service)
self.assertEqual(fetched_service['description'],
service_data['description'])
示例11: test_list_alarm_definitions_with_multiple_dimensions
def test_list_alarm_definitions_with_multiple_dimensions(self):
# Create an alarm definition with random dimensions
name = data_utils.rand_name('alarm_definition')
dimensions = {data_utils.rand_name('key-1'): data_utils.rand_name('value-1'),
data_utils.rand_name('key-2'): data_utils.rand_name('value-2')}
dimension_strings = [key + '=' + value for key, value in dimensions.items()]
expression = 'avg(cpu_utilization{' + ','.join(dimension_strings) + '}) >= 1000'
alarm_definition = helpers.create_alarm_definition(
name=name,
description="description",
expression=expression)
resp, res_body_create_alarm_def = self.monasca_client.\
create_alarm_definitions(alarm_definition)
self.assertEqual(201, resp.status)
# List alarms
query_dimensions = [key + ':' + value for key, value in dimensions.items()]
query_parms = '?dimensions=' + ','.join(query_dimensions)
resp, response_body = self.monasca_client.list_alarm_definitions(query_parms)
self._verify_list_alarm_definitions_response_body(resp, response_body)
elements = response_body['elements']
self._verify_list_get_alarm_definitions_elements(
elements, 1, res_body_create_alarm_def)
links = response_body['links']
self._verify_list_alarm_definitions_links(links)
示例12: test_aggregate_basic_ops
def test_aggregate_basic_ops(self):
self.useFixture(fixtures.LockFixture('availability_zone'))
az = 'foo_zone'
aggregate_name = data_utils.rand_name('aggregate-scenario')
aggregate = self._create_aggregate(name=aggregate_name,
availability_zone=az)
metadata = {'meta_key': 'meta_value'}
self._set_aggregate_metadata(aggregate, metadata)
host = self._get_host_name()
self._add_host(aggregate['id'], host)
self._check_aggregate_details(aggregate, aggregate_name, az, [host],
metadata)
aggregate_name = data_utils.rand_name('renamed-aggregate-scenario')
# Updating the name alone. The az must be specified again otherwise
# the tempest client would send None in the put body
aggregate = self._update_aggregate(aggregate, aggregate_name, az)
new_metadata = {'foo': 'bar'}
self._set_aggregate_metadata(aggregate, new_metadata)
self._check_aggregate_details(aggregate, aggregate['name'], az,
[host], new_metadata)
示例13: test_get_updated_quotas
def test_get_updated_quotas(self):
# Verify that GET shows the updated quota set of tenant
tenant_name = data_utils.rand_name('cpu_quota_tenant_')
tenant_desc = tenant_name + '-desc'
identity_client = self.os_adm.identity_client
_, tenant = identity_client.create_tenant(name=tenant_name,
description=tenant_desc)
tenant_id = tenant['id']
self.addCleanup(identity_client.delete_tenant, tenant_id)
self.adm_client.update_quota_set(tenant_id, ram='5120')
resp, quota_set = self.adm_client.get_quota_set(tenant_id)
self.assertEqual(200, resp.status)
self.assertEqual(5120, quota_set['ram'])
# Verify that GET shows the updated quota set of user
user_name = data_utils.rand_name('cpu_quota_user_')
password = data_utils.rand_name('password-')
email = user_name + '@testmail.tm'
_, user = identity_client.create_user(name=user_name,
password=password,
tenant_id=tenant_id,
email=email)
user_id = user['id']
self.addCleanup(identity_client.delete_user, user_id)
self.adm_client.update_quota_set(tenant_id,
user_id=user_id,
ram='2048')
resp, quota_set = self.adm_client.get_quota_set(tenant_id,
user_id=user_id)
self.assertEqual(200, resp.status)
self.assertEqual(2048, quota_set['ram'])
示例14: _create_creds
def _create_creds(self, suffix=None, admin=False):
rand_name_root = rand_name(self.name)
if suffix:
rand_name_root += suffix
tenant_name = rand_name_root + "-tenant"
tenant_desc = tenant_name + "-desc"
rand_name_root = rand_name(self.name)
tenant = self._create_tenant(name=tenant_name,
description=tenant_desc)
if suffix:
rand_name_root += suffix
username = rand_name_root + "-user"
email = rand_name_root + "@example.com"
user = self._create_user(username, self.password,
tenant, email)
if admin:
role = None
try:
roles = self._list_roles()
if self.tempest_client:
role = next(r for r in roles if r['name'] == 'admin')
else:
role = next(r for r in roles if r.name == 'admin')
except StopIteration:
msg = "No admin role found"
raise exceptions.NotFound(msg)
if self.tempest_client:
self._assign_user_role(tenant['id'], user['id'], role['id'])
else:
self._assign_user_role(tenant.id, user.id, role.id)
return user, tenant
示例15: _create_type_and_volume
def _create_type_and_volume(self, backend_name_key, with_prefix):
# Volume/Type creation
type_name = data_utils.rand_name('Type')
vol_name = data_utils.rand_name('Volume')
spec_key_with_prefix = "capabilities:volume_backend_name"
spec_key_without_prefix = "volume_backend_name"
if with_prefix:
extra_specs = {spec_key_with_prefix: backend_name_key}
else:
extra_specs = {spec_key_without_prefix: backend_name_key}
self.type = self.volume_types_client.create_volume_type(
type_name, extra_specs=extra_specs)
self.volume_type_id_list.append(self.type['id'])
params = {self.name_field: vol_name, 'volume_type': type_name}
self.volume = self.admin_volume_client.create_volume(size=1,
**params)
if with_prefix:
self.volume_id_list_with_prefix.append(self.volume['id'])
else:
self.volume_id_list_without_prefix.append(
self.volume['id'])
self.admin_volume_client.wait_for_volume_status(
self.volume['id'], 'available')