[Scenario] Split Scenarios - P4
Move under plugins/openstack: * Quotas * Keystone * Authenticate * EC2 Implements: blueprint split-plugins Change-Id: I26dfe2418445e4cc772c8d2baffb50894e5f4c05
This commit is contained in:
parent
b07e51e2c5
commit
787b35a650
112
rally/plugins/openstack/scenarios/authenticate/authenticate.py
Normal file
112
rally/plugins/openstack/scenarios/authenticate/authenticate.py
Normal file
@ -0,0 +1,112 @@
|
||||
# Copyright 2014 Red Hat, Inc. <http://www.redhat.com>
|
||||
#
|
||||
# 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 rally.benchmark.scenarios import base
|
||||
from rally.benchmark import validation
|
||||
|
||||
|
||||
class Authenticate(base.Scenario):
|
||||
"""Benchmark scenarios for the authentication mechanism.
|
||||
|
||||
Benchmark scenarios for different types of OpenStack clients like Keystone,
|
||||
Nova etc.
|
||||
"""
|
||||
|
||||
@validation.required_openstack(users=True)
|
||||
@base.scenario()
|
||||
def keystone(self):
|
||||
"""Check Keystone Client."""
|
||||
self.clients("keystone")
|
||||
|
||||
@validation.number("repetitions", minval=1)
|
||||
@validation.required_openstack(users=True)
|
||||
@base.scenario()
|
||||
def validate_glance(self, repetitions):
|
||||
"""Check Glance Client to ensure validation of token.
|
||||
|
||||
Creation of the client does not ensure validation of the token.
|
||||
We have to do some minimal operation to make sure token gets validated.
|
||||
In following we are checking for non-existent image.
|
||||
|
||||
:param repetitions: number of times to validate
|
||||
"""
|
||||
glance_client = self.clients("glance")
|
||||
image_name = "__intentionally_non_existent_image___"
|
||||
for i in range(repetitions):
|
||||
with base.AtomicAction(self, "authenticate.validate_glance"):
|
||||
list(glance_client.images.list(name=image_name))
|
||||
|
||||
@validation.number("repetitions", minval=1)
|
||||
@validation.required_openstack(users=True)
|
||||
@base.scenario()
|
||||
def validate_nova(self, repetitions):
|
||||
"""Check Nova Client to ensure validation of token.
|
||||
|
||||
Creation of the client does not ensure validation of the token.
|
||||
We have to do some minimal operation to make sure token gets validated.
|
||||
|
||||
:param repetitions: number of times to validate
|
||||
"""
|
||||
nova_client = self.clients("nova")
|
||||
for i in range(repetitions):
|
||||
with base.AtomicAction(self, "authenticate.validate_nova"):
|
||||
nova_client.flavors.list()
|
||||
|
||||
@validation.number("repetitions", minval=1)
|
||||
@validation.required_openstack(users=True)
|
||||
@base.scenario()
|
||||
def validate_cinder(self, repetitions):
|
||||
"""Check Cinder Client to ensure validation of token.
|
||||
|
||||
Creation of the client does not ensure validation of the token.
|
||||
We have to do some minimal operation to make sure token gets validated.
|
||||
|
||||
:param repetitions: number of times to validate
|
||||
"""
|
||||
cinder_client = self.clients("cinder")
|
||||
for i in range(repetitions):
|
||||
with base.AtomicAction(self, "authenticate.validate_cinder"):
|
||||
cinder_client.volume_types.list()
|
||||
|
||||
@validation.number("repetitions", minval=1)
|
||||
@validation.required_openstack(users=True)
|
||||
@base.scenario()
|
||||
def validate_neutron(self, repetitions):
|
||||
"""Check Neutron Client to ensure validation of token.
|
||||
|
||||
Creation of the client does not ensure validation of the token.
|
||||
We have to do some minimal operation to make sure token gets validated.
|
||||
|
||||
:param repetitions: number of times to validate
|
||||
"""
|
||||
neutron_client = self.clients("neutron")
|
||||
for i in range(repetitions):
|
||||
with base.AtomicAction(self, "authenticate.validate_neutron"):
|
||||
neutron_client.get_auth_info()
|
||||
|
||||
@validation.number("repetitions", minval=1)
|
||||
@validation.required_openstack(users=True)
|
||||
@base.scenario()
|
||||
def validate_heat(self, repetitions):
|
||||
"""Check Heat Client to ensure validation of token.
|
||||
|
||||
Creation of the client does not ensure validation of the token.
|
||||
We have to do some minimal operation to make sure token gets validated.
|
||||
|
||||
:param repetitions: number of times to validate
|
||||
"""
|
||||
heat_client = self.clients("heat")
|
||||
for i in range(repetitions):
|
||||
with base.AtomicAction(self, "authenticate.validate_heat"):
|
||||
list(heat_client.stacks.list(limit=0))
|
0
rally/plugins/openstack/scenarios/ec2/__init__.py
Normal file
0
rally/plugins/openstack/scenarios/ec2/__init__.py
Normal file
44
rally/plugins/openstack/scenarios/ec2/servers.py
Normal file
44
rally/plugins/openstack/scenarios/ec2/servers.py
Normal file
@ -0,0 +1,44 @@
|
||||
# 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.
|
||||
|
||||
from rally.benchmark.scenarios import base
|
||||
from rally.benchmark import types
|
||||
from rally.benchmark import validation
|
||||
from rally.common import log as logging
|
||||
from rally import consts
|
||||
from rally.plugins.openstack.scenarios.ec2 import utils
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EC2Servers(utils.EC2Scenario):
|
||||
"""Benchmark scenarios for servers using EC2."""
|
||||
|
||||
@types.set(image=types.EC2ImageResourceType,
|
||||
flavor=types.EC2FlavorResourceType)
|
||||
@validation.image_valid_on_flavor("flavor", "image")
|
||||
@validation.required_services(consts.Service.EC2)
|
||||
@validation.required_openstack(users=True)
|
||||
@base.scenario(context={"cleanup": ["ec2"]})
|
||||
def boot_server(self, image, flavor, **kwargs):
|
||||
"""Boot a server.
|
||||
|
||||
Assumes that cleanup is done elsewhere.
|
||||
|
||||
:param image: image to be used to boot an instance
|
||||
:param flavor: flavor to be used to boot an instance
|
||||
:param kwargs: optional additional arguments for server creation
|
||||
"""
|
||||
self._boot_server(image, flavor, **kwargs)
|
86
rally/plugins/openstack/scenarios/ec2/utils.py
Normal file
86
rally/plugins/openstack/scenarios/ec2/utils.py
Normal file
@ -0,0 +1,86 @@
|
||||
# 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 time
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
from rally.benchmark.scenarios import base
|
||||
from rally.benchmark import utils as bench_utils
|
||||
|
||||
|
||||
EC2_BENCHMARK_OPTS = [
|
||||
cfg.FloatOpt(
|
||||
"ec2_server_boot_prepoll_delay",
|
||||
default=1.0,
|
||||
help="Time to sleep after boot before polling for status"
|
||||
),
|
||||
cfg.FloatOpt(
|
||||
"ec2_server_boot_timeout",
|
||||
default=300.0,
|
||||
help="Server boot timeout"
|
||||
),
|
||||
cfg.FloatOpt(
|
||||
"ec2_server_boot_poll_interval",
|
||||
default=1.0,
|
||||
help="Server boot poll interval"
|
||||
)
|
||||
]
|
||||
|
||||
CONF = cfg.CONF
|
||||
benchmark_group = cfg.OptGroup(name="benchmark",
|
||||
title="benchmark options")
|
||||
CONF.register_opts(EC2_BENCHMARK_OPTS, group=benchmark_group)
|
||||
|
||||
|
||||
def ec2_resource_is(status):
|
||||
"""Check status for EC2."""
|
||||
|
||||
return lambda resource: resource.state.upper() == status.upper()
|
||||
|
||||
|
||||
class EC2Scenario(base.Scenario):
|
||||
"""Base class for EC2 scenarios with basic atomic actions."""
|
||||
|
||||
RESOURCE_NAME_PREFIX = "rally_ec2server_"
|
||||
RESOURCE_NAME_LENGTH = 16
|
||||
|
||||
@base.atomic_action_timer("ec2.boot_server")
|
||||
def _boot_server(self, image_id, flavor_name, **kwargs):
|
||||
"""Boot a server.
|
||||
|
||||
Returns when the server is actually booted and in "Running" state.
|
||||
|
||||
:param image_id: ID of the image to be used for server creation
|
||||
:param flavor_name: Name of the flavor to be used for server creation
|
||||
:param kwargs: other optional parameters to initialize the server
|
||||
:returns: EC2 Server instance
|
||||
"""
|
||||
reservation = self.clients("ec2").run_instances(
|
||||
image_id=image_id, instance_type=flavor_name, **kwargs)
|
||||
server = reservation.instances[0]
|
||||
|
||||
time.sleep(CONF.benchmark.ec2_server_boot_prepoll_delay)
|
||||
server = bench_utils.wait_for(
|
||||
server,
|
||||
is_ready=ec2_resource_is("RUNNING"),
|
||||
update_resource=self._update_resource,
|
||||
timeout=CONF.benchmark.ec2_server_boot_timeout,
|
||||
check_interval=CONF.benchmark.ec2_server_boot_poll_interval
|
||||
)
|
||||
return server
|
||||
|
||||
def _update_resource(self, resource):
|
||||
resource.update()
|
||||
return resource
|
166
rally/plugins/openstack/scenarios/keystone/basic.py
Normal file
166
rally/plugins/openstack/scenarios/keystone/basic.py
Normal file
@ -0,0 +1,166 @@
|
||||
# Copyright 2013: Mirantis Inc.
|
||||
# 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.
|
||||
|
||||
from rally.benchmark.scenarios import base
|
||||
from rally.benchmark import validation
|
||||
from rally.plugins.openstack.scenarios.keystone import utils as kutils
|
||||
|
||||
|
||||
class KeystoneBasic(kutils.KeystoneScenario):
|
||||
"""Basic benchmark scenarios for Keystone."""
|
||||
|
||||
@validation.number("name_length", minval=10)
|
||||
@validation.required_openstack(admin=True)
|
||||
@base.scenario(context={"admin_cleanup": ["keystone"]})
|
||||
def create_user(self, name_length=10, **kwargs):
|
||||
"""Create a keystone user with random name.
|
||||
|
||||
:param name_length: length of the random part of user name
|
||||
:param kwargs: Other optional parameters to create users like
|
||||
"tenant_id", "enabled".
|
||||
"""
|
||||
self._user_create(name_length=name_length, **kwargs)
|
||||
|
||||
@validation.number("name_length", minval=10)
|
||||
@validation.required_openstack(admin=True)
|
||||
@base.scenario(context={"admin_cleanup": ["keystone"]})
|
||||
def create_delete_user(self, name_length=10, **kwargs):
|
||||
"""Create a keystone user with random name and then delete it.
|
||||
|
||||
:param name_length: length of the random part of user name
|
||||
:param kwargs: Other optional parameters to create users like
|
||||
"tenant_id", "enabled".
|
||||
"""
|
||||
user = self._user_create(name_length=name_length, **kwargs)
|
||||
self._resource_delete(user)
|
||||
|
||||
@validation.number("name_length", minval=10)
|
||||
@validation.required_openstack(admin=True)
|
||||
@base.scenario(context={"admin_cleanup": ["keystone"]})
|
||||
def create_tenant(self, name_length=10, **kwargs):
|
||||
"""Create a keystone tenant with random name.
|
||||
|
||||
:param name_length: length of the random part of tenant name
|
||||
:param kwargs: Other optional parameters
|
||||
"""
|
||||
self._tenant_create(name_length=name_length, **kwargs)
|
||||
|
||||
@validation.number("name_length", minval=10)
|
||||
@validation.number("users_per_tenant", minval=1)
|
||||
@validation.required_openstack(admin=True)
|
||||
@base.scenario(context={"admin_cleanup": ["keystone"]})
|
||||
def create_tenant_with_users(self, users_per_tenant, name_length=10,
|
||||
**kwargs):
|
||||
"""Create a keystone tenant and several users belonging to it.
|
||||
|
||||
:param name_length: length of the random part of tenant/user name
|
||||
:param users_per_tenant: number of users to create for the tenant
|
||||
:param kwargs: Other optional parameters for tenant creation
|
||||
:returns: keystone tenant instance
|
||||
"""
|
||||
tenant = self._tenant_create(name_length=name_length, **kwargs)
|
||||
self._users_create(tenant, users_per_tenant=users_per_tenant,
|
||||
name_length=name_length)
|
||||
|
||||
@validation.number("name_length", minval=10)
|
||||
@validation.required_openstack(admin=True)
|
||||
@base.scenario(context={"admin_cleanup": ["keystone"]})
|
||||
def create_and_list_users(self, name_length=10, **kwargs):
|
||||
"""Create a keystone user with random name and list all users.
|
||||
|
||||
:param name_length: length of the random part of user name
|
||||
:param kwargs: Other optional parameters to create users like
|
||||
"tenant_id", "enabled".
|
||||
"""
|
||||
self._user_create(name_length=name_length, **kwargs)
|
||||
self._list_users()
|
||||
|
||||
@validation.number("name_length", minval=10)
|
||||
@validation.required_openstack(admin=True)
|
||||
@base.scenario(context={"admin_cleanup": ["keystone"]})
|
||||
def create_and_list_tenants(self, name_length=10, **kwargs):
|
||||
"""Create a keystone tenant with random name and list all tenants.
|
||||
|
||||
:param name_length: length of the random part of tenant name
|
||||
:param kwargs: Other optional parameters
|
||||
"""
|
||||
self._tenant_create(name_length=name_length, **kwargs)
|
||||
self._list_tenants()
|
||||
|
||||
@validation.required_openstack(admin=True)
|
||||
@base.scenario(context={"admin_cleanup": ["keystone"]})
|
||||
def get_entities(self):
|
||||
"""Get instance of a tenant, user, role and service by id's."""
|
||||
tenant = self._tenant_create(name_length=5)
|
||||
user = self._user_create(name_length=10)
|
||||
role = self._role_create()
|
||||
self._get_tenant(tenant.id)
|
||||
self._get_user(user.id)
|
||||
self._get_role(role.id)
|
||||
service = self._get_service_by_name("keystone")
|
||||
self._get_service(service.id)
|
||||
|
||||
@validation.required_openstack(admin=True)
|
||||
@base.scenario(context={"admin_cleanup": ["keystone"]})
|
||||
def create_and_delete_service(self, name=None, service_type=None,
|
||||
description=None):
|
||||
"""Create and delete service.
|
||||
|
||||
:param name: name of the service
|
||||
:param service_type: type of the service
|
||||
:param description: description of the service
|
||||
"""
|
||||
service = self._service_create(name, service_type, description)
|
||||
self._delete_service(service.id)
|
||||
|
||||
@validation.number("name_length", minval=10)
|
||||
@validation.required_openstack(admin=True)
|
||||
@base.scenario(context={"admin_cleanup": ["keystone"]})
|
||||
def create_update_and_delete_tenant(self, name_length=10, **kwargs):
|
||||
"""Create, update and delete tenant.
|
||||
|
||||
:param name_length: length of the random part of tenant name
|
||||
:param kwargs: Other optional parameters for tenant creation
|
||||
"""
|
||||
tenant = self._tenant_create(name_length=name_length, **kwargs)
|
||||
self._update_tenant(tenant)
|
||||
self._resource_delete(tenant)
|
||||
|
||||
@validation.number("password_length", minval=10)
|
||||
@validation.number("name_length", minval=10)
|
||||
@validation.required_openstack(admin=True)
|
||||
@base.scenario(context={"admin_cleanup": ["keystone"]})
|
||||
def create_user_update_password(self, name_length=10, password_length=10):
|
||||
"""Create user and update password for that user.
|
||||
|
||||
:param name_length: length of the user name
|
||||
:param password_length: length of the password
|
||||
"""
|
||||
password = self._generate_random_name(length=password_length)
|
||||
user = self._user_create(name_length=name_length)
|
||||
self._update_user_password(user.id, password)
|
||||
|
||||
@validation.required_openstack(admin=True)
|
||||
@base.scenario(context={"admin_cleanup": ["keystone"]})
|
||||
def create_and_list_services(self, name=None, service_type=None,
|
||||
description=None):
|
||||
"""Create and list services.
|
||||
|
||||
:param name: name of the service
|
||||
:param service_type: type of the service
|
||||
:param description: description of the service
|
||||
"""
|
||||
self._service_create(name, service_type, description)
|
||||
self._list_services()
|
189
rally/plugins/openstack/scenarios/keystone/utils.py
Normal file
189
rally/plugins/openstack/scenarios/keystone/utils.py
Normal file
@ -0,0 +1,189 @@
|
||||
# Copyright 2013: Mirantis Inc.
|
||||
# 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 uuid
|
||||
|
||||
from rally.benchmark.scenarios import base
|
||||
|
||||
|
||||
def is_temporary(resource):
|
||||
return resource.name.startswith(KeystoneScenario.RESOURCE_NAME_PREFIX)
|
||||
|
||||
|
||||
class KeystoneScenario(base.Scenario):
|
||||
"""Base class for Keystone scenarios with basic atomic actions."""
|
||||
|
||||
RESOURCE_NAME_PREFIX = "rally_keystone_"
|
||||
|
||||
@base.atomic_action_timer("keystone.create_user")
|
||||
def _user_create(self, name_length=10, email=None, **kwargs):
|
||||
"""Creates keystone user with random name.
|
||||
|
||||
:param name_length: length of generated (random) part of name
|
||||
:param kwargs: Other optional parameters to create users like
|
||||
"tenant_id", "enabled".
|
||||
:returns: keystone user instance
|
||||
"""
|
||||
name = self._generate_random_name(length=name_length)
|
||||
# NOTE(boris-42): password and email parameters are required by
|
||||
# keystone client v2.0. This should be cleanuped
|
||||
# when we switch to v3.
|
||||
password = kwargs.pop("password", str(uuid.uuid4()))
|
||||
email = email or (name + "@rally.me")
|
||||
return self.admin_clients("keystone").users.create(
|
||||
name, password=password, email=email, **kwargs)
|
||||
|
||||
def _resource_delete(self, resource):
|
||||
""""Delete keystone resource."""
|
||||
r = "keystone.delete_%s" % resource.__class__.__name__.lower()
|
||||
with base.AtomicAction(self, r):
|
||||
resource.delete()
|
||||
|
||||
@base.atomic_action_timer("keystone.create_tenant")
|
||||
def _tenant_create(self, name_length=10, **kwargs):
|
||||
"""Creates keystone tenant with random name.
|
||||
|
||||
:param name_length: length of generated (random) part of name
|
||||
:param kwargs: Other optional parameters
|
||||
:returns: keystone tenant instance
|
||||
"""
|
||||
name = self._generate_random_name(length=name_length)
|
||||
return self.admin_clients("keystone").tenants.create(name, **kwargs)
|
||||
|
||||
@base.atomic_action_timer("keystone.create_service")
|
||||
def _service_create(self, name=None, service_type="rally_test_type",
|
||||
description=None):
|
||||
"""Creates keystone service with random name.
|
||||
|
||||
:param name: name of the service
|
||||
:param service_type: type of the service
|
||||
:param description: description of the service
|
||||
:returns: keystone service instance
|
||||
"""
|
||||
name = name or self._generate_random_name(prefix="rally_test_service_")
|
||||
description = description or self._generate_random_name(
|
||||
prefix="rally_test_service_description_")
|
||||
return self.admin_clients("keystone").services.create(name,
|
||||
service_type,
|
||||
description)
|
||||
|
||||
@base.atomic_action_timer("keystone.create_users")
|
||||
def _users_create(self, tenant, users_per_tenant, name_length=10):
|
||||
"""Adds users to a tenant.
|
||||
|
||||
:param tenant: tenant object
|
||||
:param users_per_tenant: number of users in per tenant
|
||||
:param name_length: length of generated (random) part of name for user
|
||||
"""
|
||||
for i in range(users_per_tenant):
|
||||
name = self._generate_random_name(length=name_length)
|
||||
password = name
|
||||
email = (name + "@rally.me")
|
||||
self.admin_clients("keystone").users.create(
|
||||
name, password=password, email=email, tenant_id=tenant.id)
|
||||
|
||||
@base.atomic_action_timer("keystone.create_role")
|
||||
def _role_create(self, name_length=5):
|
||||
"""Creates keystone user role with random name.
|
||||
|
||||
:param name_length: length of generated (random) part of role name
|
||||
:returns: keystone user role instance
|
||||
"""
|
||||
role = self.admin_clients("keystone").roles.create(
|
||||
self._generate_random_name(length=name_length))
|
||||
return role
|
||||
|
||||
@base.atomic_action_timer("keystone.list_users")
|
||||
def _list_users(self):
|
||||
"""List users."""
|
||||
return self.admin_clients("keystone").users.list()
|
||||
|
||||
@base.atomic_action_timer("keystone.list_tenants")
|
||||
def _list_tenants(self):
|
||||
"""List tenants."""
|
||||
return self.admin_clients("keystone").tenants.list()
|
||||
|
||||
@base.atomic_action_timer("keystone.service_list")
|
||||
def _list_services(self):
|
||||
"""List services."""
|
||||
return self.admin_clients("keystone").services.list()
|
||||
|
||||
@base.atomic_action_timer("keystone.get_tenant")
|
||||
def _get_tenant(self, tenant_id):
|
||||
"""Get given tenant.
|
||||
|
||||
:param tenant_id: tenant object
|
||||
"""
|
||||
return self.admin_clients("keystone").tenants.get(tenant_id)
|
||||
|
||||
@base.atomic_action_timer("keystone.get_user")
|
||||
def _get_user(self, user_id):
|
||||
"""Get given user.
|
||||
|
||||
:param user_id: user object
|
||||
"""
|
||||
return self.admin_clients("keystone").users.get(user_id)
|
||||
|
||||
@base.atomic_action_timer("keystone.get_role")
|
||||
def _get_role(self, role_id):
|
||||
"""Get given user role.
|
||||
|
||||
:param role_id: user role object
|
||||
"""
|
||||
return self.admin_clients("keystone").roles.get(role_id)
|
||||
|
||||
@base.atomic_action_timer("keystone.get_service")
|
||||
def _get_service(self, service_id):
|
||||
"""Get service with given service id.
|
||||
|
||||
:param service_id: id for service object
|
||||
"""
|
||||
return self.admin_clients("keystone").services.get(service_id)
|
||||
|
||||
def _get_service_by_name(self, name):
|
||||
for i in self._list_services():
|
||||
if i.name == name:
|
||||
return i
|
||||
|
||||
@base.atomic_action_timer("keystone.delete_service")
|
||||
def _delete_service(self, service_id):
|
||||
"""Delete service.
|
||||
|
||||
:param service_id: service to be deleted
|
||||
"""
|
||||
self.admin_clients("keystone").services.delete(service_id)
|
||||
|
||||
@base.atomic_action_timer("keystone.update_tenant")
|
||||
def _update_tenant(self, tenant, name=None, description=None):
|
||||
"""Update tenant name and description.
|
||||
|
||||
:param tenant: tenant to be updated
|
||||
:param name: tenant name to be set
|
||||
:param description: tenant description to be set
|
||||
"""
|
||||
name = name or (tenant.name + "_updated")
|
||||
description = description or (tenant.name + "_description_updated")
|
||||
self.admin_clients("keystone").tenants.update(tenant.id,
|
||||
name, description)
|
||||
|
||||
@base.atomic_action_timer("keystone.update_user_password")
|
||||
def _update_user_password(self, user_id, password):
|
||||
"""Update user password.
|
||||
|
||||
:param user_id: id of the user
|
||||
:param password: new password
|
||||
"""
|
||||
self.admin_clients("keystone").users.update_password(user_id,
|
||||
password)
|
82
rally/plugins/openstack/scenarios/quotas/quotas.py
Normal file
82
rally/plugins/openstack/scenarios/quotas/quotas.py
Normal file
@ -0,0 +1,82 @@
|
||||
# Copyright 2014: Kylin Cloud
|
||||
# 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.
|
||||
|
||||
from rally.benchmark.scenarios import base
|
||||
from rally.benchmark import validation
|
||||
from rally import consts
|
||||
from rally.plugins.openstack.scenarios.quotas import utils
|
||||
|
||||
|
||||
class Quotas(utils.QuotasScenario):
|
||||
"""Benchmark scenarios for quotas."""
|
||||
|
||||
@validation.required_services(consts.Service.NOVA)
|
||||
@validation.required_openstack(admin=True, users=True)
|
||||
@base.scenario(context={"admin_cleanup": ["nova.quotas"]})
|
||||
def nova_update(self, max_quota=1024):
|
||||
"""Update quotas for Nova.
|
||||
|
||||
:param max_quota: Max value to be updated for quota.
|
||||
"""
|
||||
self._update_quotas("nova", self.context["tenant"]["id"],
|
||||
max_quota)
|
||||
|
||||
@validation.required_services(consts.Service.NOVA)
|
||||
@validation.required_openstack(admin=True, users=True)
|
||||
@base.scenario(context={"admin_cleanup": ["nova.quotas"]})
|
||||
def nova_update_and_delete(self, max_quota=1024):
|
||||
"""Update and delete quotas for Nova.
|
||||
|
||||
:param max_quota: Max value to be updated for quota.
|
||||
"""
|
||||
|
||||
self._update_quotas("nova", self.context["tenant"]["id"],
|
||||
max_quota)
|
||||
self._delete_quotas("nova", self.context["tenant"]["id"])
|
||||
|
||||
@validation.required_services(consts.Service.CINDER)
|
||||
@validation.required_openstack(admin=True, users=True)
|
||||
@base.scenario(context={"admin_cleanup": ["cinder.quotas"]})
|
||||
def cinder_update(self, max_quota=1024):
|
||||
"""Update quotas for Cinder.
|
||||
|
||||
:param max_quota: Max value to be updated for quota.
|
||||
"""
|
||||
self._update_quotas("cinder", self.context["tenant"]["id"],
|
||||
max_quota)
|
||||
|
||||
@validation.required_services(consts.Service.CINDER)
|
||||
@validation.required_openstack(admin=True, users=True)
|
||||
@base.scenario(context={"admin_cleanup": ["cinder.quotas"]})
|
||||
def cinder_update_and_delete(self, max_quota=1024):
|
||||
"""Update and Delete quotas for Cinder.
|
||||
|
||||
:param max_quota: Max value to be updated for quota.
|
||||
"""
|
||||
self._update_quotas("cinder", self.context["tenant"]["id"],
|
||||
max_quota)
|
||||
self._delete_quotas("cinder", self.context["tenant"]["id"])
|
||||
|
||||
@validation.required_services(consts.Service.NEUTRON)
|
||||
@validation.required_openstack(admin=True, users=True)
|
||||
@base.scenario(context={"admin_cleanup": ["neutron.quota"]})
|
||||
def neutron_update(self, max_quota=1024):
|
||||
"""Update quotas for neutron.
|
||||
|
||||
:param max_quota: Max value to be updated for quota.
|
||||
"""
|
||||
quota_update_fn = self.admin_clients("neutron").update_quota
|
||||
self._update_quotas("neutron", self.context["tenant"]["id"],
|
||||
max_quota, quota_update_fn)
|
78
rally/plugins/openstack/scenarios/quotas/utils.py
Normal file
78
rally/plugins/openstack/scenarios/quotas/utils.py
Normal file
@ -0,0 +1,78 @@
|
||||
# Copyright 2014: Kylin Cloud
|
||||
# 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 random
|
||||
|
||||
from rally.benchmark.scenarios import base
|
||||
|
||||
|
||||
class QuotasScenario(base.Scenario):
|
||||
"""Base class for quotas scenarios with basic atomic actions."""
|
||||
|
||||
@base.atomic_action_timer("quotas.update_quotas")
|
||||
def _update_quotas(self, component, tenant_id, max_quota=1024,
|
||||
quota_update_fn=None):
|
||||
"""Updates quotas.
|
||||
|
||||
:param component: Component for the quotas.
|
||||
:param tenant_id: The project_id for the quotas to be updated.
|
||||
:param max_quota: Max value to be updated for quota.
|
||||
:param quota_update_fn: Client quota update function.
|
||||
|
||||
Standard OpenStack clients use quotas.update().
|
||||
Use `quota_update_fn` to override for non-standard clients.
|
||||
|
||||
:returns: Updated quotas dictionary.
|
||||
"""
|
||||
quotas = self._generate_quota_values(max_quota, component)
|
||||
if quota_update_fn:
|
||||
return quota_update_fn(tenant_id, **quotas)
|
||||
return self.admin_clients(component).quotas.update(tenant_id, **quotas)
|
||||
|
||||
@base.atomic_action_timer("quotas.delete_quotas")
|
||||
def _delete_quotas(self, component, tenant_id):
|
||||
"""Delete quotas.
|
||||
|
||||
:param component: Component for the quotas.
|
||||
:param tenant_id: The project_id for the quotas to be updated.
|
||||
"""
|
||||
self.admin_clients(component).quotas.delete(tenant_id)
|
||||
|
||||
def _generate_quota_values(self, max_quota, component):
|
||||
quotas = {}
|
||||
if component == "nova":
|
||||
quotas = {
|
||||
"metadata_items": random.randint(-1, max_quota),
|
||||
"key_pairs": random.randint(-1, max_quota),
|
||||
"injected_file_content_bytes": random.randint(-1, max_quota),
|
||||
"injected_file_path_bytes": random.randint(-1, max_quota),
|
||||
"ram": random.randint(-1, max_quota),
|
||||
"instances": random.randint(-1, max_quota),
|
||||
"injected_files": random.randint(-1, max_quota),
|
||||
"cores": random.randint(-1, max_quota)
|
||||
}
|
||||
elif component == "cinder":
|
||||
quotas = {
|
||||
"volumes": random.randint(-1, max_quota),
|
||||
"snapshots": random.randint(-1, max_quota),
|
||||
"gigabytes": random.randint(-1, max_quota),
|
||||
}
|
||||
elif component == "neutron":
|
||||
quota = {}
|
||||
for key in ["network", "subnet", "port", "router", "floatingip",
|
||||
"security_group", "security_group_rule"]:
|
||||
quota[key] = random.randint(-1, max_quota)
|
||||
quotas = {"body": {"quota": quota}}
|
||||
return quotas
|
@ -0,0 +1,34 @@
|
||||
# Copyright (C) 2014 Yahoo! Inc. All Rights Reserved.
|
||||
# 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 mock
|
||||
|
||||
from rally.plugins.openstack.scenarios.authenticate import authenticate
|
||||
from tests.unit import fakes
|
||||
from tests.unit import test
|
||||
|
||||
|
||||
class AuthenticateTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.osclients")
|
||||
def test_keystone(self, mock_osclients):
|
||||
fc = fakes.FakeClients()
|
||||
mock_osclients.Clients.return_value = fc
|
||||
|
||||
scenario = authenticate.Authenticate(admin_clients=mock_osclients,
|
||||
clients=mock_osclients)
|
||||
|
||||
scenario.keystone()
|
||||
self.assertEqual(scenario._clients.keystone.call_count, 1)
|
48
tests/unit/plugins/openstack/scenarios/ec2/test_servers.py
Normal file
48
tests/unit/plugins/openstack/scenarios/ec2/test_servers.py
Normal file
@ -0,0 +1,48 @@
|
||||
# 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 mock
|
||||
|
||||
from rally.plugins.openstack.scenarios.ec2 import servers
|
||||
from tests.unit import test
|
||||
|
||||
|
||||
UTILS = "rally.plugins.openstack.scenarios.ec2.utils."
|
||||
|
||||
|
||||
class EC2ServersTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.benchmark.utils.wait_for",
|
||||
return_value="running_server")
|
||||
@mock.patch(UTILS + "ec2_resource_is", return_value="foo_state")
|
||||
@mock.patch(UTILS + "time")
|
||||
@mock.patch(UTILS + "CONF")
|
||||
def test_boot_server(self, mock_conf, mock_time, mock_is, mock_wait):
|
||||
mock_conf.benchmark.ec2_server_boot_prepoll_delay = "foo_delay"
|
||||
mock_conf.benchmark.ec2_server_boot_timeout = "foo_timeout"
|
||||
mock_conf.benchmark.ec2_server_boot_poll_interval = "foo_interval"
|
||||
|
||||
scenario = servers.EC2Servers()
|
||||
scenario._update_resource = "foo_update"
|
||||
mock_instances = mock.Mock(instances=["foo_inst"])
|
||||
scenario.clients = mock.Mock()
|
||||
scenario.clients("ec2").run_instances.return_value = mock_instances
|
||||
server = scenario._boot_server("foo_image", "foo_flavor", foo="bar")
|
||||
|
||||
mock_wait.assert_called_once_with("foo_inst", is_ready="foo_state",
|
||||
update_resource="foo_update",
|
||||
timeout="foo_timeout",
|
||||
check_interval="foo_interval")
|
||||
mock_time.sleep.assert_called_once_with("foo_delay")
|
||||
self.assertEqual(server, "running_server")
|
75
tests/unit/plugins/openstack/scenarios/ec2/test_utils.py
Normal file
75
tests/unit/plugins/openstack/scenarios/ec2/test_utils.py
Normal file
@ -0,0 +1,75 @@
|
||||
# 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 mock
|
||||
from oslo_config import cfg
|
||||
from oslotest import mockpatch
|
||||
|
||||
from rally.plugins.openstack.scenarios.ec2 import utils
|
||||
from tests.unit import test
|
||||
|
||||
EC2_UTILS = "rally.plugins.openstack.scenarios.ec2.utils"
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class EC2UtilsTestCase(test.TestCase):
|
||||
|
||||
def test_ec2_resource_is(self):
|
||||
resource = mock.MagicMock(state="RUNNING")
|
||||
resource_is = utils.ec2_resource_is("RUNNING")
|
||||
self.assertTrue(resource_is(resource))
|
||||
resource.state = "PENDING"
|
||||
self.assertFalse(resource_is(resource))
|
||||
|
||||
def test__update_resource(self):
|
||||
resource = mock.MagicMock()
|
||||
utils.EC2Scenario()._update_resource(resource)
|
||||
resource.update.assert_called_once_with()
|
||||
|
||||
|
||||
class EC2ScenarioTestCase(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(EC2ScenarioTestCase, self).setUp()
|
||||
self.server = mock.MagicMock()
|
||||
self.reservation = mock.MagicMock(instances=[self.server])
|
||||
self.res_is = mockpatch.Patch(EC2_UTILS + ".ec2_resource_is")
|
||||
self.update_res = mockpatch.Patch(
|
||||
EC2_UTILS + ".EC2Scenario._update_resource")
|
||||
self.wait_for = mockpatch.Patch(EC2_UTILS + ".bench_utils.wait_for")
|
||||
self.useFixture(self.wait_for)
|
||||
self.useFixture(self.res_is)
|
||||
self.useFixture(self.update_res)
|
||||
self.useFixture(mockpatch.Patch("time.sleep"))
|
||||
|
||||
def _test_atomic_action_timer(self, atomic_actions, name):
|
||||
action_duration = atomic_actions.get(name)
|
||||
self.assertIsNotNone(action_duration)
|
||||
self.assertIsInstance(action_duration, float)
|
||||
|
||||
@mock.patch(EC2_UTILS + ".EC2Scenario.clients")
|
||||
def test__boot_server(self, mock_clients):
|
||||
mock_clients("ec2").run_instances.return_value = self.reservation
|
||||
ec2_scenario = utils.EC2Scenario(context={})
|
||||
return_server = ec2_scenario._boot_server("image", "flavor")
|
||||
expected = mock.call(
|
||||
self.server, is_ready=self.res_is.mock(),
|
||||
update_resource=self.update_res.mock,
|
||||
check_interval=CONF.benchmark.ec2_server_boot_poll_interval,
|
||||
timeout=CONF.benchmark.ec2_server_boot_timeout)
|
||||
self.assertEqual([expected], self.wait_for.mock.mock_calls)
|
||||
self.res_is.mock.assert_has_calls([mock.call("RUNNING")])
|
||||
self.assertEqual(self.wait_for.mock(), return_server)
|
||||
self._test_atomic_action_timer(ec2_scenario.atomic_actions(),
|
||||
"ec2.boot_server")
|
183
tests/unit/plugins/openstack/scenarios/keystone/test_basic.py
Normal file
183
tests/unit/plugins/openstack/scenarios/keystone/test_basic.py
Normal file
@ -0,0 +1,183 @@
|
||||
# Copyright 2013: Mirantis Inc.
|
||||
# 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 mock
|
||||
|
||||
from rally.plugins.openstack.scenarios.keystone import basic
|
||||
from tests.unit import test
|
||||
|
||||
BASE = "rally.plugins.openstack.scenarios.keystone."
|
||||
BASIC = BASE + "basic.KeystoneBasic."
|
||||
|
||||
|
||||
class KeystoneBasicTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(BASIC + "_generate_random_name")
|
||||
def test_create_user(self, mock_gen_name):
|
||||
scenario = basic.KeystoneBasic()
|
||||
mock_gen_name.return_value = "teeeest"
|
||||
scenario._user_create = mock.MagicMock()
|
||||
scenario.create_user(name_length=20, password="tttt", tenant_id="id")
|
||||
scenario._user_create.assert_called_once_with(name_length=20,
|
||||
password="tttt",
|
||||
tenant_id="id")
|
||||
|
||||
@mock.patch(BASIC + "_generate_random_name")
|
||||
def test_create_delete_user(self, mock_gen_name):
|
||||
create_result = mock.MagicMock()
|
||||
|
||||
scenario = basic.KeystoneBasic()
|
||||
scenario._user_create = mock.MagicMock(return_value=create_result)
|
||||
scenario._resource_delete = mock.MagicMock()
|
||||
mock_gen_name.return_value = "teeeest"
|
||||
|
||||
scenario.create_delete_user(name_length=30, email="abcd", enabled=True)
|
||||
|
||||
scenario._user_create.assert_called_once_with(name_length=30,
|
||||
email="abcd",
|
||||
enabled=True)
|
||||
scenario._resource_delete.assert_called_once_with(create_result)
|
||||
|
||||
@mock.patch(BASIC + "_generate_random_name")
|
||||
def test_create_tenant(self, mock_gen_name):
|
||||
scenario = basic.KeystoneBasic()
|
||||
mock_gen_name.return_value = "teeeest"
|
||||
scenario._tenant_create = mock.MagicMock()
|
||||
scenario.create_tenant(name_length=20, enabled=True)
|
||||
scenario._tenant_create.assert_called_once_with(name_length=20,
|
||||
enabled=True)
|
||||
|
||||
@mock.patch(BASIC + "_generate_random_name")
|
||||
def test_create_tenant_with_users(self, mock_gen_name):
|
||||
scenario = basic.KeystoneBasic()
|
||||
mock_gen_name.return_value = "teeeest"
|
||||
fake_tenant = mock.MagicMock()
|
||||
scenario._tenant_create = mock.MagicMock(return_value=fake_tenant)
|
||||
scenario._users_create = mock.MagicMock()
|
||||
scenario.create_tenant_with_users(users_per_tenant=1, name_length=20,
|
||||
enabled=True)
|
||||
scenario._tenant_create.assert_called_once_with(name_length=20,
|
||||
enabled=True)
|
||||
scenario._users_create.assert_called_once_with(fake_tenant,
|
||||
users_per_tenant=1,
|
||||
name_length=20)
|
||||
|
||||
@mock.patch(BASIC + "_generate_random_name")
|
||||
def test_create_and_list_users(self, mock_gen_name):
|
||||
scenario = basic.KeystoneBasic()
|
||||
mock_gen_name.return_value = "teeeest"
|
||||
scenario._user_create = mock.MagicMock()
|
||||
scenario._list_users = mock.MagicMock()
|
||||
scenario.create_and_list_users(name_length=20, password="tttt",
|
||||
tenant_id="id")
|
||||
scenario._user_create.assert_called_once_with(name_length=20,
|
||||
password="tttt",
|
||||
tenant_id="id")
|
||||
scenario._list_users.assert_called_once_with()
|
||||
|
||||
@mock.patch(BASIC + "_generate_random_name")
|
||||
def test_create_and_list_tenants(self, mock_gen_name):
|
||||
scenario = basic.KeystoneBasic()
|
||||
mock_gen_name.return_value = "teeeest"
|
||||
scenario._tenant_create = mock.MagicMock()
|
||||
scenario._list_tenants = mock.MagicMock()
|
||||
scenario.create_and_list_tenants(name_length=20, enabled=True)
|
||||
scenario._tenant_create.assert_called_once_with(name_length=20,
|
||||
enabled=True)
|
||||
scenario._list_tenants.assert_called_with()
|
||||
|
||||
@mock.patch(BASIC + "_generate_random_name")
|
||||
def test_get_entities(self, mock_gen_name):
|
||||
scenario = basic.KeystoneBasic()
|
||||
mock_gen_name.return_value = "teeeeest"
|
||||
fake_tenant = mock.MagicMock()
|
||||
fake_user = mock.MagicMock()
|
||||
fake_role = mock.MagicMock()
|
||||
fake_service = mock.MagicMock()
|
||||
scenario._tenant_create = mock.MagicMock(return_value=fake_tenant)
|
||||
scenario._user_create = mock.MagicMock(return_value=fake_user)
|
||||
scenario._role_create = mock.MagicMock(return_value=fake_role)
|
||||
scenario._get_tenant = mock.MagicMock(return_value=fake_tenant)
|
||||
scenario._get_user = mock.MagicMock(return_value=fake_user)
|
||||
scenario._get_role = mock.MagicMock(return_value=fake_role)
|
||||
scenario._get_service_by_name = mock.MagicMock(
|
||||
return_value=fake_service)
|
||||
scenario._get_service = mock.MagicMock(return_value=fake_service)
|
||||
scenario.get_entities()
|
||||
scenario._tenant_create.assert_called_once_with(name_length=5)
|
||||
scenario._user_create.assert_called_once_with(name_length=10)
|
||||
scenario._role_create.assert_called_once_with()
|
||||
scenario._get_tenant.assert_called_once_with(fake_tenant.id)
|
||||
scenario._get_user.assert_called_once_with(fake_user.id)
|
||||
scenario._get_role.assert_called_once_with(fake_role.id)
|
||||
scenario._get_service_by_name("keystone")
|
||||
scenario._get_service.assert_called_once_with(fake_service.id)
|
||||
|
||||
def test_create_and_delete_service(self):
|
||||
scenario = basic.KeystoneBasic()
|
||||
name = "Rally_test_service"
|
||||
service_type = "rally_test_type"
|
||||
description = "test_description"
|
||||
fake_service = mock.MagicMock()
|
||||
scenario._service_create = mock.MagicMock(return_value=fake_service)
|
||||
scenario._delete_service = mock.MagicMock()
|
||||
scenario.create_and_delete_service(name=name,
|
||||
service_type=service_type,
|
||||
description=description)
|
||||
scenario._service_create.assert_called_once_with(name,
|
||||
service_type,
|
||||
description)
|
||||
scenario._delete_service.assert_called_once_with(fake_service.id)
|
||||
|
||||
def test_create_update_and_delete_tenant(self):
|
||||
scenario = basic.KeystoneBasic()
|
||||
fake_tenant = mock.MagicMock()
|
||||
scenario._tenant_create = mock.MagicMock(return_value=fake_tenant)
|
||||
scenario._update_tenant = mock.MagicMock()
|
||||
scenario._resource_delete = mock.MagicMock()
|
||||
scenario.create_update_and_delete_tenant()
|
||||
scenario._update_tenant.assert_called_once_with(fake_tenant)
|
||||
scenario._resource_delete.assert_called_once_with(fake_tenant)
|
||||
|
||||
def test_create_user_update_password(self):
|
||||
scenario = basic.KeystoneBasic()
|
||||
fake_password = "pswd"
|
||||
fake_user = mock.MagicMock()
|
||||
scenario._user_create = mock.MagicMock(return_value=fake_user)
|
||||
scenario._generate_random_name = mock.MagicMock(
|
||||
return_value=fake_password)
|
||||
scenario._update_user_password = mock.MagicMock()
|
||||
|
||||
scenario.create_user_update_password(name_length=9, password_length=9)
|
||||
scenario._generate_random_name.assert_called_once_with(length=9)
|
||||
scenario._user_create.assert_called_once_with(name_length=9)
|
||||
scenario._update_user_password.assert_called_once_with(fake_user.id,
|
||||
fake_password)
|
||||
|
||||
def test_create_and_list_services(self):
|
||||
scenario = basic.KeystoneBasic()
|
||||
name = "Rally_test_service"
|
||||
service_type = "rally_test_type"
|
||||
description = "test_description"
|
||||
fake_service = mock.MagicMock()
|
||||
scenario._service_create = mock.MagicMock(return_value=fake_service)
|
||||
scenario._list_services = mock.MagicMock()
|
||||
scenario.create_and_list_services(name=name,
|
||||
service_type=service_type,
|
||||
description=description)
|
||||
scenario._service_create.assert_called_once_with(name,
|
||||
service_type,
|
||||
description)
|
||||
scenario._list_services.assert_called_once_with()
|
309
tests/unit/plugins/openstack/scenarios/keystone/test_utils.py
Normal file
309
tests/unit/plugins/openstack/scenarios/keystone/test_utils.py
Normal file
@ -0,0 +1,309 @@
|
||||
# Copyright 2013: Mirantis Inc.
|
||||
# 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 mock
|
||||
import six
|
||||
|
||||
from rally.plugins.openstack.scenarios.keystone import utils
|
||||
from tests.unit import fakes
|
||||
from tests.unit import test
|
||||
|
||||
UTILS = "rally.plugins.openstack.scenarios.keystone.utils."
|
||||
|
||||
|
||||
class KeystoneUtilsTestCase(test.TestCase):
|
||||
|
||||
def test_RESOURCE_NAME_PREFIX(self):
|
||||
self.assertIsInstance(utils.KeystoneScenario.RESOURCE_NAME_PREFIX,
|
||||
six.string_types)
|
||||
# Prefix must be long enough to guarantee that resource
|
||||
# to be recognized as created by rally
|
||||
self.assertTrue(
|
||||
len(utils.KeystoneScenario.RESOURCE_NAME_PREFIX) > 7)
|
||||
|
||||
def test_is_temporary(self):
|
||||
prefix = utils.KeystoneScenario.RESOURCE_NAME_PREFIX
|
||||
tests = [
|
||||
(fakes.FakeResource(name=prefix + "abc"), True),
|
||||
(fakes.FakeResource(name="another"), False),
|
||||
(fakes.FakeResource(name=prefix[:-3] + "abc"), False)
|
||||
]
|
||||
|
||||
for resource, is_valid in tests:
|
||||
self.assertEqual(utils.is_temporary(resource), is_valid)
|
||||
|
||||
|
||||
class KeystoneScenarioTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(UTILS + "uuid.uuid4", return_value="pwd")
|
||||
@mock.patch(UTILS + "KeystoneScenario._generate_random_name",
|
||||
return_value="abc")
|
||||
def test_user_create(self, mock_gen_name, mock_uuid4):
|
||||
user = {}
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.users.create = mock.MagicMock(return_value=user)
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
|
||||
result = scenario._user_create()
|
||||
|
||||
self.assertEqual(user, result)
|
||||
fake_keystone.users.create.assert_called_once_with(
|
||||
mock_gen_name.return_value,
|
||||
password=mock_uuid4.return_value,
|
||||
email=mock_gen_name.return_value + "@rally.me")
|
||||
mock_uuid4.assert_called_with()
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.create_user")
|
||||
|
||||
@mock.patch(UTILS + "KeystoneScenario._generate_random_name")
|
||||
def test_role_create(self, mock_gen_name):
|
||||
name = "abc"
|
||||
mock_gen_name.return_value = name
|
||||
|
||||
role = {}
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.roles.create = mock.MagicMock(return_value=role)
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
|
||||
result = scenario._role_create()
|
||||
|
||||
self.assertEqual(role, result)
|
||||
fake_keystone.roles.create.assert_called_once_with(name)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.create_role")
|
||||
|
||||
def test_user_delete(self):
|
||||
resource = fakes.FakeResource()
|
||||
resource.delete = mock.MagicMock()
|
||||
|
||||
scenario = utils.KeystoneScenario()
|
||||
scenario._resource_delete(resource)
|
||||
resource.delete.assert_called_once_with()
|
||||
r = "keystone.delete_%s" % resource.__class__.__name__.lower()
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(), r)
|
||||
|
||||
@mock.patch(UTILS + "KeystoneScenario._generate_random_name")
|
||||
def test_tenant_create(self, mock_gen_name):
|
||||
name = "abc"
|
||||
mock_gen_name.return_value = name
|
||||
|
||||
tenant = {}
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.tenants.create = mock.MagicMock(return_value=tenant)
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
|
||||
result = scenario._tenant_create()
|
||||
|
||||
self.assertEqual(tenant, result)
|
||||
fake_keystone.tenants.create.assert_called_once_with(name)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.create_tenant")
|
||||
|
||||
@mock.patch(UTILS + "KeystoneScenario._generate_random_name")
|
||||
def test_service_create(self, mock_gen_name):
|
||||
name = "abc"
|
||||
mock_gen_name.return_value = name
|
||||
service_type = name + "service_type"
|
||||
description = name + "_description"
|
||||
|
||||
service = {}
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.services.create = mock.MagicMock(return_value=service)
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
|
||||
result = scenario._service_create(name=name,
|
||||
service_type=service_type,
|
||||
description=description)
|
||||
|
||||
self.assertEqual(service, result)
|
||||
fake_keystone.services.create.assert_called_once_with(name,
|
||||
service_type,
|
||||
description)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.create_service")
|
||||
|
||||
@mock.patch(UTILS + "KeystoneScenario._generate_random_name")
|
||||
def test_tenant_create_with_users(self, mock_gen_name):
|
||||
name = "abc"
|
||||
mock_gen_name.return_value = name
|
||||
|
||||
tenant = mock.MagicMock()
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.users.create = mock.MagicMock()
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
|
||||
scenario._users_create(tenant, users_per_tenant=1, name_length=10)
|
||||
|
||||
fake_keystone.users.create.assert_called_once_with(
|
||||
name, password=name, email=name + "@rally.me",
|
||||
tenant_id=tenant.id)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.create_users")
|
||||
|
||||
def test_list_users(self):
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.users.list = mock.MagicMock()
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
scenario._list_users()
|
||||
fake_keystone.users.list.assert_called_once_with()
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.list_users")
|
||||
|
||||
def test_list_tenants(self):
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.tenants.list = mock.MagicMock()
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
scenario._list_tenants()
|
||||
fake_keystone.tenants.list.assert_called_once_with()
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.list_tenants")
|
||||
|
||||
def test_list_services(self):
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.services.list = mock.MagicMock()
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
|
||||
scenario._list_services()
|
||||
|
||||
fake_keystone.services.list.assert_called_once_with()
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.service_list")
|
||||
|
||||
def test_delete_service(self):
|
||||
service = mock.MagicMock()
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.services.delete = mock.MagicMock()
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
|
||||
scenario._delete_service(service_id=service.id)
|
||||
|
||||
fake_keystone.services.delete.assert_called_once_with(service.id)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.delete_service")
|
||||
|
||||
def test_get_tenant(self):
|
||||
tenant = mock.MagicMock()
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.tenants.get = mock.MagicMock(return_value=tenant)
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
|
||||
scenario._get_tenant(tenant_id=tenant.id)
|
||||
|
||||
fake_keystone.tenants.get.assert_called_once_with(tenant.id)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.get_tenant")
|
||||
|
||||
def test_get_user(self):
|
||||
user = mock.MagicMock()
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.users.get = mock.MagicMock(return_value=user)
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
|
||||
scenario._get_user(user_id=user.id)
|
||||
|
||||
fake_keystone.users.get.assert_called_once_with(user.id)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.get_user")
|
||||
|
||||
def test_get_role(self):
|
||||
role = mock.MagicMock()
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.roles.get = mock.MagicMock(return_value=role)
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
|
||||
scenario._get_role(role_id=role.id)
|
||||
|
||||
fake_keystone.roles.get.assert_called_once_with(role.id)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.get_role")
|
||||
|
||||
def test_get_service(self):
|
||||
service = mock.MagicMock()
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.services.get = mock.MagicMock(return_value=service)
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
|
||||
scenario._get_service(service_id=service.id)
|
||||
|
||||
fake_keystone.services.get.assert_called_once_with(service.id)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.get_service")
|
||||
|
||||
def test_update_tenant(self):
|
||||
tenant = mock.MagicMock()
|
||||
description = tenant.name + "_description_updated_test"
|
||||
name = tenant.name + "test_updated_test"
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.tenants.update = mock.MagicMock()
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
|
||||
scenario._update_tenant(tenant=tenant, name=name,
|
||||
description=description)
|
||||
|
||||
fake_keystone.tenants.update.assert_called_once_with(tenant.id, name,
|
||||
description)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.update_tenant")
|
||||
|
||||
def test_update_user_password(self):
|
||||
password = "pswd"
|
||||
user = mock.MagicMock()
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.users.update_password = mock.MagicMock()
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
|
||||
scenario._update_user_password(password=password, user_id=user.id)
|
||||
|
||||
fake_keystone.users.update_password.assert_called_once_with(user.id,
|
||||
password)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.update_user_password")
|
||||
|
||||
def test_get_service_by_name(self):
|
||||
scenario = utils.KeystoneScenario()
|
||||
svc_foo, svc_bar = mock.Mock(), mock.Mock()
|
||||
scenario._list_services = mock.Mock(return_value=[svc_foo, svc_bar])
|
||||
self.assertEqual(scenario._get_service_by_name(svc_bar.name), svc_bar)
|
||||
self.assertIsNone(scenario._get_service_by_name("spam"))
|
68
tests/unit/plugins/openstack/scenarios/quotas/test_quotas.py
Normal file
68
tests/unit/plugins/openstack/scenarios/quotas/test_quotas.py
Normal file
@ -0,0 +1,68 @@
|
||||
# Copyright 2014: Kylin Cloud
|
||||
# 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 mock
|
||||
|
||||
from rally.plugins.openstack.scenarios.quotas import quotas
|
||||
from tests.unit import test
|
||||
|
||||
|
||||
class QuotasTestCase(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(QuotasTestCase, self).setUp()
|
||||
self.context = {
|
||||
"user": {"tenant_id": "fake"},
|
||||
"tenant": {"id": "fake"}
|
||||
}
|
||||
|
||||
def test_nova_update(self):
|
||||
scenario = quotas.Quotas(self.context)
|
||||
scenario._update_quotas = mock.MagicMock()
|
||||
scenario.nova_update(max_quota=1024)
|
||||
scenario._update_quotas.assert_called_once_with("nova", "fake", 1024)
|
||||
|
||||
def test_nova_update_and_delete(self):
|
||||
scenario = quotas.Quotas(self.context)
|
||||
scenario._update_quotas = mock.MagicMock()
|
||||
scenario._delete_quotas = mock.MagicMock()
|
||||
scenario.nova_update_and_delete(max_quota=1024)
|
||||
scenario._update_quotas.assert_called_once_with("nova", "fake", 1024)
|
||||
scenario._delete_quotas.assert_called_once_with("nova", "fake")
|
||||
|
||||
def test_cinder_update(self):
|
||||
scenario = quotas.Quotas(self.context)
|
||||
scenario._update_quotas = mock.MagicMock()
|
||||
scenario.cinder_update(max_quota=1024)
|
||||
scenario._update_quotas.assert_called_once_with("cinder", "fake", 1024)
|
||||
|
||||
def test_cinder_update_and_delete(self):
|
||||
scenario = quotas.Quotas(self.context)
|
||||
scenario._update_quotas = mock.MagicMock()
|
||||
scenario._delete_quotas = mock.MagicMock()
|
||||
scenario.cinder_update_and_delete(max_quota=1024)
|
||||
scenario._update_quotas.assert_called_once_with("cinder", "fake", 1024)
|
||||
scenario._delete_quotas.assert_called_once_with("cinder", "fake")
|
||||
|
||||
@mock.patch("rally.benchmark.scenarios.base.Scenario.admin_clients")
|
||||
def test_neutron_update(self, mock_clients):
|
||||
scenario = quotas.Quotas(self.context)
|
||||
|
||||
scenario._update_quotas = mock.MagicMock()
|
||||
mock_quota_update_fn = mock_clients().update_quota
|
||||
scenario.neutron_update(max_quota=1024)
|
||||
scenario._update_quotas.assert_called_once_with("neutron", "fake",
|
||||
1024,
|
||||
mock_quota_update_fn)
|
118
tests/unit/plugins/openstack/scenarios/quotas/test_utils.py
Normal file
118
tests/unit/plugins/openstack/scenarios/quotas/test_utils.py
Normal file
@ -0,0 +1,118 @@
|
||||
# Copyright 2014: Kylin Cloud
|
||||
# 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 mock
|
||||
import six
|
||||
|
||||
from rally.plugins.openstack.scenarios.quotas import utils
|
||||
from tests.unit import fakes
|
||||
from tests.unit import test
|
||||
|
||||
|
||||
class QuotasScenarioTestCase(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(QuotasScenarioTestCase, self).setUp()
|
||||
|
||||
def test__update_quotas(self):
|
||||
tenant_id = "fake_tenant"
|
||||
quotas = {
|
||||
"metadata_items": 10,
|
||||
"key_pairs": 10,
|
||||
"injected_file_content_bytes": 1024,
|
||||
"injected_file_path_bytes": 1024,
|
||||
"ram": 5120,
|
||||
"instances": 10,
|
||||
"injected_files": 10,
|
||||
"cores": 10,
|
||||
}
|
||||
fake_nova = fakes.FakeNovaClient()
|
||||
fake_nova.quotas.update = mock.MagicMock(return_value=quotas)
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._nova = fake_nova
|
||||
scenario = utils.QuotasScenario(admin_clients=fake_clients)
|
||||
scenario._generate_quota_values = mock.MagicMock(return_value=quotas)
|
||||
|
||||
result = scenario._update_quotas("nova", tenant_id)
|
||||
|
||||
self.assertEqual(quotas, result)
|
||||
fake_nova.quotas.update.assert_called_once_with(tenant_id, **quotas)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"quotas.update_quotas")
|
||||
|
||||
def test__update_quotas_fn(self):
|
||||
tenant_id = "fake_tenant"
|
||||
quotas = {
|
||||
"metadata_items": 10,
|
||||
"key_pairs": 10,
|
||||
"injected_file_content_bytes": 1024,
|
||||
"injected_file_path_bytes": 1024,
|
||||
"ram": 5120,
|
||||
"instances": 10,
|
||||
"injected_files": 10,
|
||||
"cores": 10,
|
||||
}
|
||||
fake_nova = fakes.FakeNovaClient()
|
||||
fake_nova.quotas.update = mock.MagicMock(return_value=quotas)
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._nova = fake_nova
|
||||
scenario = utils.QuotasScenario(admin_clients=fake_clients)
|
||||
scenario._generate_quota_values = mock.MagicMock(return_value=quotas)
|
||||
|
||||
mock_quota = mock.Mock(return_value=quotas)
|
||||
|
||||
result = scenario._update_quotas("nova", tenant_id,
|
||||
quota_update_fn=mock_quota)
|
||||
|
||||
self.assertEqual(quotas, result)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"quotas.update_quotas")
|
||||
|
||||
def test__generate_quota_values_nova(self):
|
||||
max_quota = 1024
|
||||
scenario = utils.QuotasScenario(admin_clients=fakes.FakeClients())
|
||||
quotas = scenario._generate_quota_values(max_quota, "nova")
|
||||
for k, v in six.iteritems(quotas):
|
||||
self.assertTrue(-1 <= v <= max_quota)
|
||||
|
||||
def test__generate_quota_values_cinder(self):
|
||||
max_quota = 1024
|
||||
scenario = utils.QuotasScenario(admin_clients=fakes.FakeClients())
|
||||
quotas = scenario._generate_quota_values(max_quota, "cinder")
|
||||
for k, v in six.iteritems(quotas):
|
||||
self.assertTrue(-1 <= v <= max_quota)
|
||||
|
||||
def test__generate_quota_values_neutron(self):
|
||||
max_quota = 1024
|
||||
scenario = utils.QuotasScenario(admin_clients=fakes.FakeClients())
|
||||
quotas = scenario._generate_quota_values(max_quota, "neutron")
|
||||
for v in six.itervalues(quotas):
|
||||
for v1 in six.itervalues(v):
|
||||
for v2 in six.itervalues(v1):
|
||||
self.assertTrue(-1 <= v2 <= max_quota)
|
||||
|
||||
def test__delete_quotas(self):
|
||||
tenant_id = "fake_tenant"
|
||||
fake_nova = fakes.FakeNovaClient()
|
||||
fake_nova.quotas.delete = mock.MagicMock()
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._nova = fake_nova
|
||||
scenario = utils.QuotasScenario(admin_clients=fake_clients)
|
||||
|
||||
scenario._delete_quotas("nova", tenant_id)
|
||||
|
||||
fake_nova.quotas.delete.assert_called_once_with(tenant_id)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"quotas.delete_quotas")
|
Loading…
x
Reference in New Issue
Block a user