[CLEANUP] Add ability to specify superclass for cleanup
The superclass is used to determine name patterns that should be matched against when performing cleanup. Implements: blueprint cleanup-refactoring Co-Authored-By: Hai Shi <shihai1992@gmail.com> Change-Id: Ieaf5dac0806d888c867bc644be148691b82af930
This commit is contained in:
parent
2ad316dffc
commit
9bb9e50a28
@ -19,6 +19,7 @@ from rally.common import broker
|
||||
from rally.common.i18n import _
|
||||
from rally.common import logging
|
||||
from rally.common.plugin import discover
|
||||
from rally.common.plugin import plugin
|
||||
from rally.common import utils as rutils
|
||||
from rally import osclients
|
||||
from rally.plugins.openstack.cleanup import base
|
||||
@ -30,7 +31,8 @@ LOG = logging.getLogger(__name__)
|
||||
class SeekAndDestroy(object):
|
||||
cache = {}
|
||||
|
||||
def __init__(self, manager_cls, admin, users, api_versions=None):
|
||||
def __init__(self, manager_cls, admin, users, api_versions=None,
|
||||
resource_classes=None, task_id=None):
|
||||
"""Resource deletion class.
|
||||
|
||||
This class contains method exterminate() that finds and deletes
|
||||
@ -40,11 +42,17 @@ class SeekAndDestroy(object):
|
||||
:param admin: admin credential like in context["admin"]
|
||||
:param users: users credentials like in context["users"]
|
||||
:param api_versions: dict of client API versions
|
||||
:param resource_classes: Resource classes to match resource names
|
||||
against
|
||||
:param task_id: The UUID of task to match resource names against
|
||||
"""
|
||||
self.manager_cls = manager_cls
|
||||
self.admin = admin
|
||||
self.users = users or []
|
||||
self.api_versions = api_versions
|
||||
self.resource_classes = resource_classes or [
|
||||
rutils.RandomNameGeneratorMixin]
|
||||
self.task_id = task_id
|
||||
|
||||
def _get_cached_client(self, user):
|
||||
"""Simplifies initialization and caching OpenStack clients."""
|
||||
@ -120,8 +128,8 @@ class SeekAndDestroy(object):
|
||||
"%(service)s.%(resource)s: %(uuid)s.")
|
||||
% msg_kw)
|
||||
|
||||
def _gen_publisher(self):
|
||||
"""Returns publisher for deletion jobs.
|
||||
def _publisher(self, queue):
|
||||
"""Publisher for deletion jobs.
|
||||
|
||||
This method iterates over all users, lists all resources
|
||||
(using manager_cls) and puts jobs for deletion.
|
||||
@ -132,65 +140,58 @@ class SeekAndDestroy(object):
|
||||
In case of tenant based resource, uuids are fetched only from one user
|
||||
per tenant.
|
||||
"""
|
||||
def _publish(admin, user, manager):
|
||||
try:
|
||||
for raw_resource in rutils.retry(3, manager.list):
|
||||
queue.append((admin, user, raw_resource))
|
||||
except Exception as e:
|
||||
LOG.warning(
|
||||
_("Seems like %s.%s.list(self) method is broken. "
|
||||
"It shouldn't raise any exceptions.")
|
||||
% (manager.__module__, type(manager).__name__))
|
||||
LOG.exception(e)
|
||||
|
||||
def publisher(queue):
|
||||
|
||||
def _publish(admin, user, manager):
|
||||
try:
|
||||
for raw_resource in rutils.retry(3, manager.list):
|
||||
queue.append((admin, user, raw_resource))
|
||||
except Exception as e:
|
||||
LOG.warning(
|
||||
_("Seems like %s.%s.list(self) method is broken. "
|
||||
"It shouldn't raise any exceptions.")
|
||||
% (manager.__module__, type(manager).__name__))
|
||||
LOG.exception(e)
|
||||
|
||||
if self.admin and (not self.users
|
||||
or self.manager_cls._perform_for_admin_only):
|
||||
manager = self.manager_cls(
|
||||
admin=self._get_cached_client(self.admin))
|
||||
_publish(self.admin, None, manager)
|
||||
|
||||
else:
|
||||
visited_tenants = set()
|
||||
admin_client = self._get_cached_client(self.admin)
|
||||
for user in self.users:
|
||||
if (self.manager_cls._tenant_resource
|
||||
and user["tenant_id"] in visited_tenants):
|
||||
continue
|
||||
|
||||
visited_tenants.add(user["tenant_id"])
|
||||
manager = self.manager_cls(
|
||||
admin=admin_client,
|
||||
user=self._get_cached_client(user),
|
||||
tenant_uuid=user["tenant_id"])
|
||||
|
||||
_publish(self.admin, user, manager)
|
||||
|
||||
return publisher
|
||||
|
||||
def _gen_consumer(self):
|
||||
"""Generate method that consumes single deletion job."""
|
||||
|
||||
def consumer(cache, args):
|
||||
"""Execute deletion job."""
|
||||
admin, user, raw_resource = args
|
||||
|
||||
if self.admin and (not self.users
|
||||
or self.manager_cls._perform_for_admin_only):
|
||||
manager = self.manager_cls(
|
||||
resource=raw_resource,
|
||||
admin=self._get_cached_client(admin),
|
||||
user=self._get_cached_client(user),
|
||||
tenant_uuid=user and user["tenant_id"])
|
||||
admin=self._get_cached_client(self.admin))
|
||||
_publish(self.admin, None, manager)
|
||||
|
||||
else:
|
||||
visited_tenants = set()
|
||||
admin_client = self._get_cached_client(self.admin)
|
||||
for user in self.users:
|
||||
if (self.manager_cls._tenant_resource
|
||||
and user["tenant_id"] in visited_tenants):
|
||||
continue
|
||||
|
||||
visited_tenants.add(user["tenant_id"])
|
||||
manager = self.manager_cls(
|
||||
admin=admin_client,
|
||||
user=self._get_cached_client(user),
|
||||
tenant_uuid=user["tenant_id"])
|
||||
|
||||
_publish(self.admin, user, manager)
|
||||
|
||||
def _consumer(self, cache, args):
|
||||
"""Method that consumes single deletion job."""
|
||||
admin, user, raw_resource = args
|
||||
|
||||
manager = self.manager_cls(
|
||||
resource=raw_resource,
|
||||
admin=self._get_cached_client(admin),
|
||||
user=self._get_cached_client(user),
|
||||
tenant_uuid=user and user["tenant_id"])
|
||||
|
||||
if manager.name() == "" or rutils.name_matches_object(
|
||||
manager.name(), *self.resource_classes,
|
||||
task_id=self.task_id, exact=False):
|
||||
self._delete_single_resource(manager)
|
||||
|
||||
return consumer
|
||||
|
||||
def exterminate(self):
|
||||
"""Delete all resources for passed users, admin and resource_mgr."""
|
||||
|
||||
broker.run(self._gen_publisher(), self._gen_consumer(),
|
||||
broker.run(self._publisher, self._consumer,
|
||||
consumers_count=self.manager_cls._threads)
|
||||
|
||||
|
||||
@ -252,7 +253,7 @@ def find_resource_managers(names=None, admin_required=None):
|
||||
|
||||
|
||||
def cleanup(names=None, admin_required=None, admin=None, users=None,
|
||||
api_versions=None):
|
||||
api_versions=None, superclass=plugin.Plugin, task_id=None):
|
||||
"""Generic cleaner.
|
||||
|
||||
This method goes through all plugins. Filter those and left only plugins
|
||||
@ -261,10 +262,9 @@ def cleanup(names=None, admin_required=None, admin=None, users=None,
|
||||
Then goes through all passed users and using cleaners cleans all related
|
||||
resources.
|
||||
|
||||
:param names: Use only resource manages that has name from this list.
|
||||
:param names: Use only resource managers that have names in this list.
|
||||
There are in as _service or
|
||||
(%s.%s % (_service, _resource)) from
|
||||
|
||||
:param admin_required: If None -> return all plugins
|
||||
If True -> return only admin plugins
|
||||
If False -> return only non admin plugins
|
||||
@ -276,11 +276,23 @@ def cleanup(names=None, admin_required=None, admin=None, users=None,
|
||||
"id": <uuid1>,
|
||||
"tenant_id": <uuid2>,
|
||||
"credential": <rally.common.objects.Credential>
|
||||
|
||||
}
|
||||
:param superclass: The plugin superclass to perform cleanup
|
||||
for. E.g., this could be
|
||||
``rally.task.scenario.Scenario`` to cleanup all
|
||||
Scenario resources.
|
||||
:param task_id: The UUID of task
|
||||
"""
|
||||
resource_classes = [cls for cls in discover.itersubclasses(superclass)
|
||||
if issubclass(cls, rutils.RandomNameGeneratorMixin)]
|
||||
if not resource_classes and issubclass(superclass,
|
||||
rutils.RandomNameGeneratorMixin):
|
||||
resource_classes.append(superclass)
|
||||
for manager in find_resource_managers(names, admin_required):
|
||||
LOG.debug("Cleaning up %(service)s %(resource)s objects" %
|
||||
{"service": manager._service,
|
||||
"resource": manager._resource})
|
||||
SeekAndDestroy(manager, admin, users, api_versions).exterminate()
|
||||
SeekAndDestroy(manager, admin, users,
|
||||
api_versions=api_versions,
|
||||
resource_classes=resource_classes,
|
||||
task_id=task_id).exterminate()
|
||||
|
@ -20,13 +20,7 @@ from oslo_config import cfg
|
||||
from saharaclient.api import base as saharaclient_base
|
||||
|
||||
from rally.common import logging
|
||||
from rally.common.plugin import discover
|
||||
from rally.common import utils
|
||||
from rally.plugins.openstack.cleanup import base
|
||||
from rally.plugins.openstack.scenarios.cinder import utils as cinder_utils
|
||||
from rally.plugins.openstack.scenarios.fuel import utils as futils
|
||||
from rally.plugins.openstack.scenarios.keystone import utils as kutils
|
||||
from rally.plugins.openstack.scenarios.nova import utils as nova_utils
|
||||
from rally.plugins.openstack.services.identity import identity
|
||||
from rally.plugins.openstack.wrappers import glance as glance_wrapper
|
||||
from rally.task import utils as task_utils
|
||||
@ -189,16 +183,14 @@ class NovaServer(base.ResourceManager):
|
||||
@base.resource("nova", "server_groups", order=next(_nova_order),
|
||||
tenant_resource=True)
|
||||
class NovaServerGroups(base.ResourceManager):
|
||||
def list(self):
|
||||
return [r for r in self._manager().list()
|
||||
if utils.name_matches_object(r.name, nova_utils.NovaScenario)]
|
||||
pass
|
||||
|
||||
|
||||
@base.resource("nova", "floating_ips", order=next(_nova_order))
|
||||
class NovaFloatingIPs(SynchronizedDeletion, base.ResourceManager):
|
||||
|
||||
def name(self):
|
||||
return None
|
||||
return self.raw_resource.pool
|
||||
|
||||
|
||||
@base.resource("nova", "keypairs", order=next(_nova_order))
|
||||
@ -224,9 +216,7 @@ class NovaQuotas(QuotaMixin, base.ResourceManager):
|
||||
@base.resource("nova", "flavors", order=next(_nova_order),
|
||||
admin_required=True, perform_for_admin_only=True)
|
||||
class NovaFlavors(base.ResourceManager):
|
||||
def list(self):
|
||||
return [r for r in self._manager().list()
|
||||
if utils.name_matches_object(r.name, nova_utils.NovaScenario)]
|
||||
pass
|
||||
|
||||
def is_deleted(self):
|
||||
try:
|
||||
@ -247,11 +237,6 @@ class NovaFloatingIpsBulk(SynchronizedDeletion, base.ResourceManager):
|
||||
def name(self):
|
||||
return None
|
||||
|
||||
def list(self):
|
||||
return [floating_ip for floating_ip in self._manager().list()
|
||||
if utils.name_matches_object(floating_ip.pool,
|
||||
nova_utils.NovaScenario)]
|
||||
|
||||
|
||||
@base.resource("nova", "networks", order=next(_nova_order),
|
||||
admin_required=True, tenant_resource=True)
|
||||
@ -260,26 +245,11 @@ class NovaNetworks(SynchronizedDeletion, base.ResourceManager):
|
||||
def name(self):
|
||||
return self.raw_resource.label
|
||||
|
||||
def list(self):
|
||||
# NOTE(stpierre): any plugin can create a nova network via the
|
||||
# network wrapper, and that network's name will be created
|
||||
# according to its owner's random name generation
|
||||
# parameters. so we need to check if there are nova networks
|
||||
# whose name pattern matches those of any loaded plugin that
|
||||
# implements RandomNameGeneratorMixin
|
||||
classes = list(discover.itersubclasses(utils.RandomNameGeneratorMixin))
|
||||
return [net for net in self._manager().list()
|
||||
if utils.name_matches_object(net.label, *classes)]
|
||||
|
||||
|
||||
@base.resource("nova", "aggregates", order=next(_nova_order),
|
||||
admin_required=True, perform_for_admin_only=True)
|
||||
class NovaAggregate(SynchronizedDeletion, base.ResourceManager):
|
||||
|
||||
def list(self):
|
||||
return [r for r in self._manager().list()
|
||||
if utils.name_matches_object(r.name, nova_utils.NovaScenario)]
|
||||
|
||||
def delete(self):
|
||||
for host in self.raw_resource.hosts:
|
||||
self.raw_resource.remove_host(host)
|
||||
@ -408,6 +378,12 @@ class NeutronV2Loadbalancer(NeutronLbaasV2Mixin):
|
||||
return False
|
||||
|
||||
|
||||
@base.resource("neutron", "floatingip", order=next(_neutron_order),
|
||||
tenant_resource=True)
|
||||
class NeutronFloatingIP(NeutronMixin):
|
||||
pass
|
||||
|
||||
|
||||
@base.resource("neutron", "port", order=next(_neutron_order),
|
||||
tenant_resource=True)
|
||||
class NeutronPort(NeutronMixin):
|
||||
@ -430,12 +406,6 @@ class NeutronPort(NeutronMixin):
|
||||
% self.id())
|
||||
|
||||
|
||||
@base.resource("neutron", "router", order=next(_neutron_order),
|
||||
tenant_resource=True)
|
||||
class NeutronRouter(NeutronMixin):
|
||||
pass
|
||||
|
||||
|
||||
@base.resource("neutron", "subnet", order=next(_neutron_order),
|
||||
tenant_resource=True)
|
||||
class NeutronSubnet(NeutronMixin):
|
||||
@ -448,9 +418,9 @@ class NeutronNetwork(NeutronMixin):
|
||||
pass
|
||||
|
||||
|
||||
@base.resource("neutron", "floatingip", order=next(_neutron_order),
|
||||
@base.resource("neutron", "router", order=next(_neutron_order),
|
||||
tenant_resource=True)
|
||||
class NeutronFloatingIP(NeutronMixin):
|
||||
class NeutronRouter(NeutronMixin):
|
||||
pass
|
||||
|
||||
|
||||
@ -487,10 +457,7 @@ class CinderVolumeBackup(base.ResourceManager):
|
||||
@base.resource("cinder", "volume_types", order=next(_cinder_order),
|
||||
admin_required=True, perform_for_admin_only=True)
|
||||
class CinderVolumeType(base.ResourceManager):
|
||||
def list(self):
|
||||
return [r for r in self._manager().list()
|
||||
if utils.name_matches_object(r.name,
|
||||
cinder_utils.CinderScenario)]
|
||||
pass
|
||||
|
||||
|
||||
@base.resource("cinder", "volume_snapshots", order=next(_cinder_order),
|
||||
@ -862,11 +829,6 @@ class FuelEnvironment(base.ResourceManager):
|
||||
def is_deleted(self):
|
||||
return not self._manager().get(self.id())
|
||||
|
||||
def list(self):
|
||||
return [env for env in self._manager().list()
|
||||
if utils.name_matches_object(env["name"],
|
||||
futils.FuelScenario)]
|
||||
|
||||
|
||||
# WATCHER
|
||||
|
||||
@ -927,11 +889,8 @@ class KeystoneMixin(SynchronizedDeletion):
|
||||
delete_method(self.id())
|
||||
|
||||
def list(self):
|
||||
# TODO(boris-42): We should use such stuff in all list commands.
|
||||
resources = self._resource + "s"
|
||||
list_method = getattr(self._manager(), "list_%s" % resources)
|
||||
return [r for r in list_method()
|
||||
if utils.name_matches_object(r.name, kutils.KeystoneScenario)]
|
||||
return getattr(self._manager(), "list_%s" % resources)()
|
||||
|
||||
|
||||
@base.resource("keystone", "user", order=next(_keystone_order),
|
||||
|
@ -76,8 +76,9 @@ class VolumeGenerator(context.Context):
|
||||
|
||||
@logging.log_task_wrapper(LOG.info, _("Exit context: `Volumes`"))
|
||||
def cleanup(self):
|
||||
# TODO(boris-42): Delete only resources created by this context
|
||||
resource_manager.cleanup(
|
||||
names=["cinder.volumes"],
|
||||
users=self.context.get("users", []),
|
||||
api_versions=self.context["config"].get("api_versions"))
|
||||
api_versions=self.context["config"].get("api_versions"),
|
||||
superclass=cinder_utils.CinderScenario,
|
||||
task_id=self.context["task"]["uuid"])
|
||||
|
@ -49,4 +49,5 @@ class AdminCleanup(base.CleanupMixin, context.Context):
|
||||
admin_required=True,
|
||||
admin=self.context["admin"],
|
||||
users=self.context.get("users", []),
|
||||
api_versions=self.context["config"].get("api_versions"))
|
||||
api_versions=self.context["config"].get("api_versions"),
|
||||
task_id=self.context["task"]["uuid"])
|
||||
|
@ -48,5 +48,6 @@ class UserCleanup(base.CleanupMixin, context.Context):
|
||||
names=self.config,
|
||||
admin_required=False,
|
||||
users=self.context.get("users", []),
|
||||
api_versions=self.context["config"].get("api_versions")
|
||||
api_versions=self.context["config"].get("api_versions"),
|
||||
task_id=self.context["task"]["uuid"]
|
||||
)
|
||||
|
@ -58,6 +58,7 @@ class ZoneGenerator(context.Context):
|
||||
|
||||
@logging.log_task_wrapper(LOG.info, _("Exit context: `Zones`"))
|
||||
def cleanup(self):
|
||||
# TODO(boris-42): Delete only resources created by this context
|
||||
resource_manager.cleanup(names=["designate.zones"],
|
||||
users=self.context.get("users", []))
|
||||
users=self.context.get("users", []),
|
||||
superclass=utils.DesignateScenario,
|
||||
task_id=self.context["task"]["uuid"])
|
||||
|
@ -95,4 +95,6 @@ class EC2ServerGenerator(context.Context):
|
||||
@logging.log_task_wrapper(LOG.info, _("Exit context: `EC2 Servers`"))
|
||||
def cleanup(self):
|
||||
resource_manager.cleanup(names=["ec2.servers"],
|
||||
users=self.context.get("users", []))
|
||||
users=self.context.get("users", []),
|
||||
superclass=ec2_utils.EC2Scenario,
|
||||
task_id=self.context["task"]["uuid"])
|
||||
|
@ -86,4 +86,6 @@ class StackGenerator(context.Context):
|
||||
@logging.log_task_wrapper(LOG.info, _("Exit context: `Stacks`"))
|
||||
def cleanup(self):
|
||||
resource_manager.cleanup(names=["heat.stacks"],
|
||||
users=self.context.get("users", []))
|
||||
users=self.context.get("users", []),
|
||||
superclass=heat_utils.HeatScenario,
|
||||
task_id=self.context["task"]["uuid"])
|
||||
|
@ -25,6 +25,7 @@ from rally import consts
|
||||
from rally import exceptions
|
||||
from rally import osclients
|
||||
from rally.plugins.openstack.cleanup import manager as resource_manager
|
||||
from rally.plugins.openstack.scenarios.murano import utils as murano_utils
|
||||
from rally.task import context
|
||||
|
||||
|
||||
@ -77,4 +78,6 @@ class PackageGenerator(context.Context):
|
||||
@logging.log_task_wrapper(LOG.info, _("Exit context: `Murano packages`"))
|
||||
def cleanup(self):
|
||||
resource_manager.cleanup(names=["murano.packages"],
|
||||
users=self.context.get("users", []))
|
||||
users=self.context.get("users", []),
|
||||
superclass=murano_utils.MuranoScenario,
|
||||
task_id=self.context["task"]["uuid"])
|
||||
|
@ -56,6 +56,7 @@ class Keypair(context.Context):
|
||||
|
||||
@logging.log_task_wrapper(LOG.info, _("Exit context: `keypair`"))
|
||||
def cleanup(self):
|
||||
# TODO(boris-42): Delete only resources created by this context
|
||||
resource_manager.cleanup(names=["nova.keypairs"],
|
||||
users=self.context.get("users", []))
|
||||
users=self.context.get("users", []),
|
||||
superclass=self.__class__,
|
||||
task_id=self.context["task"]["uuid"])
|
||||
|
@ -129,4 +129,6 @@ class ServerGenerator(context.Context):
|
||||
@logging.log_task_wrapper(LOG.info, _("Exit context: `Servers`"))
|
||||
def cleanup(self):
|
||||
resource_manager.cleanup(names=["nova.servers"],
|
||||
users=self.context.get("users", []))
|
||||
users=self.context.get("users", []),
|
||||
superclass=nova_utils.NovaScenario,
|
||||
task_id=self.context["task"]["uuid"])
|
||||
|
@ -176,7 +176,7 @@ class SaharaCluster(context.Context):
|
||||
|
||||
@logging.log_task_wrapper(LOG.info, _("Exit context: `Sahara Cluster`"))
|
||||
def cleanup(self):
|
||||
|
||||
# TODO(boris-42): Delete only resources created by this context
|
||||
resource_manager.cleanup(names=["sahara.clusters"],
|
||||
users=self.context.get("users", []))
|
||||
users=self.context.get("users", []),
|
||||
superclass=utils.SaharaScenario,
|
||||
task_id=self.context["task"]["uuid"])
|
||||
|
@ -125,8 +125,8 @@ class SaharaImage(context.Context):
|
||||
|
||||
@logging.log_task_wrapper(LOG.info, _("Exit context: `Sahara Image`"))
|
||||
def cleanup(self):
|
||||
|
||||
# TODO(boris-42): Delete only resources created by this context
|
||||
if self.context["sahara"]["need_image_cleanup"]:
|
||||
resource_manager.cleanup(names=["glance.images"],
|
||||
users=self.context.get("users", []))
|
||||
users=self.context.get("users", []),
|
||||
superclass=glance_utils.GlanceScenario,
|
||||
task_id=self.context["task"]["uuid"])
|
||||
|
@ -127,7 +127,8 @@ class SaharaInputDataSources(context.Context):
|
||||
res_cleanup.SwiftContainer(
|
||||
resource=self.context["sahara"]["container_name"])
|
||||
|
||||
# TODO(boris-42): Delete only resources created by this context
|
||||
resource_manager.cleanup(
|
||||
names=["sahara.%s" % res for res in resources],
|
||||
users=self.context.get("users", []))
|
||||
users=self.context.get("users", []),
|
||||
superclass=utils.SaharaScenario,
|
||||
task_id=self.context["task"]["uuid"])
|
||||
|
@ -145,7 +145,8 @@ class SaharaJobBinaries(context.Context):
|
||||
def cleanup(self):
|
||||
resources = ["job_binary_internals", "job_binaries"]
|
||||
|
||||
# TODO(boris-42): Delete only resources created by this context
|
||||
resource_manager.cleanup(
|
||||
names=["sahara.%s" % res for res in resources],
|
||||
users=self.context.get("users", []))
|
||||
users=self.context.get("users", []),
|
||||
superclass=utils.SaharaScenario,
|
||||
task_id=self.context["task"]["uuid"])
|
||||
|
@ -19,7 +19,6 @@ from rally.common import utils as rutils
|
||||
from rally import consts
|
||||
from rally import osclients
|
||||
from rally.plugins.openstack.cleanup import manager as resource_manager
|
||||
from rally.plugins.openstack.cleanup import resources as res_cleanup
|
||||
from rally.plugins.openstack.scenarios.sahara import utils
|
||||
from rally.plugins.openstack.scenarios.swift import utils as swift_utils
|
||||
from rally.task import context
|
||||
@ -100,18 +99,9 @@ class SaharaOutputDataSources(context.Context):
|
||||
@logging.log_task_wrapper(LOG.info,
|
||||
_("Exit context: `Sahara Output Data Sources`"))
|
||||
def cleanup(self):
|
||||
for user, tenant_id in rutils.iterate_per_tenants(
|
||||
self.context["users"]):
|
||||
if self.context["tenants"][tenant_id].get(
|
||||
"sahara", {}).get("container", {}).get("name") is not None:
|
||||
for swift_object in (
|
||||
self.context["tenants"][tenant_id]["sahara"]["container"][
|
||||
"output_swift_objects"]):
|
||||
res_cleanup.SwiftObject(swift_object[1])
|
||||
res_cleanup.SwiftContainer(
|
||||
self.context["tenants"][tenant_id].get(
|
||||
"sahara", {}).get("container", {}).get("name"))
|
||||
resources = ["data_sources"]
|
||||
resource_manager.cleanup(
|
||||
names=["sahara.%s" % res for res in resources],
|
||||
users=self.context.get("users", []))
|
||||
users=self.context.get("users", []),
|
||||
superclass=utils.SaharaScenario,
|
||||
task_id=self.context["task"]["uuid"])
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
import mock
|
||||
|
||||
from rally.common import utils
|
||||
from rally.plugins.openstack.cleanup import base
|
||||
from rally.plugins.openstack.cleanup import manager
|
||||
from tests.unit import test
|
||||
@ -172,12 +173,11 @@ class SeekAndDestroyTestCase(test.TestCase):
|
||||
return mock_mgr
|
||||
|
||||
@mock.patch("%s.SeekAndDestroy._get_cached_client" % BASE)
|
||||
def test__gen_publisher_admin(self, mock__get_cached_client):
|
||||
def test__publisher_admin(self, mock__get_cached_client):
|
||||
mock_mgr = self._manager([Exception, Exception, [1, 2, 3]],
|
||||
_perform_for_admin_only=False)
|
||||
admin = mock.MagicMock()
|
||||
publish = manager.SeekAndDestroy(
|
||||
mock_mgr, admin, None)._gen_publisher()
|
||||
publish = manager.SeekAndDestroy(mock_mgr, admin, None)._publisher
|
||||
|
||||
queue = []
|
||||
publish(queue)
|
||||
@ -187,12 +187,12 @@ class SeekAndDestroyTestCase(test.TestCase):
|
||||
self.assertEqual(queue, [(admin, None, x) for x in range(1, 4)])
|
||||
|
||||
@mock.patch("%s.SeekAndDestroy._get_cached_client" % BASE)
|
||||
def test__gen_publisher_admin_only(self, mock__get_cached_client):
|
||||
def test__publisher_admin_only(self, mock__get_cached_client):
|
||||
mock_mgr = self._manager([Exception, Exception, [1, 2, 3]],
|
||||
_perform_for_admin_only=True)
|
||||
admin = mock.MagicMock()
|
||||
publish = manager.SeekAndDestroy(
|
||||
mock_mgr, admin, ["u1", "u2"])._gen_publisher()
|
||||
mock_mgr, admin, ["u1", "u2"])._publisher
|
||||
|
||||
queue = []
|
||||
publish(queue)
|
||||
@ -202,7 +202,7 @@ class SeekAndDestroyTestCase(test.TestCase):
|
||||
self.assertEqual(queue, [(admin, None, x) for x in range(1, 4)])
|
||||
|
||||
@mock.patch("%s.SeekAndDestroy._get_cached_client" % BASE)
|
||||
def test__gen_publisher_user_resource(self, mock__get_cached_client):
|
||||
def test__publisher_user_resource(self, mock__get_cached_client):
|
||||
mock_mgr = self._manager([Exception, Exception, [1, 2, 3],
|
||||
Exception, Exception, [4, 5]],
|
||||
_perform_for_admin_only=False,
|
||||
@ -210,8 +210,7 @@ class SeekAndDestroyTestCase(test.TestCase):
|
||||
|
||||
admin = mock.MagicMock()
|
||||
users = [{"tenant_id": 1, "id": 1}, {"tenant_id": 2, "id": 2}]
|
||||
publish = manager.SeekAndDestroy(
|
||||
mock_mgr, admin, users)._gen_publisher()
|
||||
publish = manager.SeekAndDestroy(mock_mgr, admin, users)._publisher
|
||||
|
||||
queue = []
|
||||
publish(queue)
|
||||
@ -251,7 +250,7 @@ class SeekAndDestroyTestCase(test.TestCase):
|
||||
{"tenant_id": 2, "id": 3}]
|
||||
|
||||
publish = manager.SeekAndDestroy(
|
||||
mock_mgr, None, users)._gen_publisher()
|
||||
mock_mgr, None, users)._publisher
|
||||
|
||||
queue = []
|
||||
publish(queue)
|
||||
@ -277,13 +276,21 @@ class SeekAndDestroyTestCase(test.TestCase):
|
||||
self.assertTrue(mock_log.warning.mock_called)
|
||||
self.assertTrue(mock_log.exception.mock_called)
|
||||
|
||||
@mock.patch("rally.common.utils.name_matches_object")
|
||||
@mock.patch("%s.SeekAndDestroy._get_cached_client" % BASE)
|
||||
@mock.patch("%s.SeekAndDestroy._delete_single_resource" % BASE)
|
||||
def test__gen_consumer(self, mock__delete_single_resource,
|
||||
mock__get_cached_client):
|
||||
def test__consumer(self, mock__delete_single_resource,
|
||||
mock__get_cached_client,
|
||||
mock_name_matches_object):
|
||||
mock_mgr = mock.MagicMock(__name__="Test")
|
||||
resource_classes = [mock.Mock()]
|
||||
task_id = "task_id"
|
||||
mock_name_matches_object.return_value = True
|
||||
|
||||
consumer = manager.SeekAndDestroy(mock_mgr, None, None)._gen_consumer()
|
||||
consumer = manager.SeekAndDestroy(
|
||||
mock_mgr, None, None,
|
||||
resource_classes=resource_classes,
|
||||
task_id=task_id)._consumer
|
||||
|
||||
admin = mock.MagicMock()
|
||||
user1 = {"id": "a", "tenant_id": "uuid1"}
|
||||
@ -305,6 +312,7 @@ class SeekAndDestroyTestCase(test.TestCase):
|
||||
mock_mgr.reset_mock()
|
||||
mock__get_cached_client.reset_mock()
|
||||
mock__delete_single_resource.reset_mock()
|
||||
mock_name_matches_object.reset_mock()
|
||||
|
||||
consumer(cache, (admin, None, "res2"))
|
||||
mock_mgr.assert_called_once_with(
|
||||
@ -320,21 +328,17 @@ class SeekAndDestroyTestCase(test.TestCase):
|
||||
mock__delete_single_resource.assert_called_once_with(
|
||||
mock_mgr.return_value)
|
||||
|
||||
@mock.patch("%s.SeekAndDestroy._gen_consumer" % BASE)
|
||||
@mock.patch("%s.SeekAndDestroy._gen_publisher" % BASE)
|
||||
@mock.patch("%s.broker.run" % BASE)
|
||||
def test_exterminate(self, mock_broker_run, mock__gen_publisher,
|
||||
mock__gen_consumer):
|
||||
|
||||
def test_exterminate(self, mock_broker_run):
|
||||
manager_cls = mock.MagicMock(_threads=5)
|
||||
manager.SeekAndDestroy(manager_cls, None, None).exterminate()
|
||||
cleaner = manager.SeekAndDestroy(manager_cls, None, None)
|
||||
cleaner._publisher = mock.Mock()
|
||||
cleaner._consumer = mock.Mock()
|
||||
cleaner.exterminate()
|
||||
|
||||
mock__gen_publisher.assert_called_once_with()
|
||||
mock__gen_consumer.assert_called_once_with()
|
||||
mock_broker_run.assert_called_once_with(
|
||||
mock__gen_publisher.return_value,
|
||||
mock__gen_consumer.return_value,
|
||||
consumers_count=5)
|
||||
mock_broker_run.assert_called_once_with(cleaner._publisher,
|
||||
cleaner._consumer,
|
||||
consumers_count=5)
|
||||
|
||||
|
||||
class ResourceManagerTestCase(test.TestCase):
|
||||
@ -402,53 +406,70 @@ class ResourceManagerTestCase(test.TestCase):
|
||||
manager.find_resource_managers(names=["fake"],
|
||||
admin_required=False))
|
||||
|
||||
@mock.patch("rally.common.plugin.discover.itersubclasses")
|
||||
@mock.patch("%s.SeekAndDestroy" % BASE)
|
||||
@mock.patch("%s.find_resource_managers" % BASE,
|
||||
return_value=[mock.MagicMock(), mock.MagicMock()])
|
||||
def test_cleanup(self, mock_find_resource_managers, mock_seek_and_destroy):
|
||||
def test_cleanup(self, mock_find_resource_managers, mock_seek_and_destroy,
|
||||
mock_itersubclasses):
|
||||
class A(utils.RandomNameGeneratorMixin):
|
||||
pass
|
||||
|
||||
class B(object):
|
||||
pass
|
||||
|
||||
mock_itersubclasses.return_value = [A, B]
|
||||
|
||||
manager.cleanup(names=["a", "b"], admin_required=True,
|
||||
admin="admin", users=["user"])
|
||||
admin="admin", users=["user"],
|
||||
superclass=A,
|
||||
task_id="task_id")
|
||||
|
||||
mock_find_resource_managers.assert_called_once_with(["a", "b"], True)
|
||||
|
||||
mock_seek_and_destroy.assert_has_calls([
|
||||
mock.call(
|
||||
mock_find_resource_managers.return_value[0], "admin",
|
||||
["user"], None
|
||||
),
|
||||
mock.call(mock_find_resource_managers.return_value[0], "admin",
|
||||
["user"], api_versions=None,
|
||||
resource_classes=[A], task_id="task_id"),
|
||||
mock.call().exterminate(),
|
||||
mock.call(
|
||||
mock_find_resource_managers.return_value[1], "admin",
|
||||
["user"], None
|
||||
),
|
||||
mock.call(mock_find_resource_managers.return_value[1], "admin",
|
||||
["user"], api_versions=None,
|
||||
resource_classes=[A], task_id="task_id"),
|
||||
mock.call().exterminate()
|
||||
])
|
||||
|
||||
@mock.patch("rally.common.plugin.discover.itersubclasses")
|
||||
@mock.patch("%s.SeekAndDestroy" % BASE)
|
||||
@mock.patch("%s.find_resource_managers" % BASE,
|
||||
return_value=[mock.MagicMock(), mock.MagicMock()])
|
||||
def test_cleanup_with_api_versions(self,
|
||||
mock_find_resource_managers,
|
||||
mock_seek_and_destroy):
|
||||
mock_seek_and_destroy,
|
||||
mock_itersubclasses):
|
||||
class A(utils.RandomNameGeneratorMixin):
|
||||
pass
|
||||
|
||||
class B(object):
|
||||
pass
|
||||
|
||||
mock_itersubclasses.return_value = [A, B]
|
||||
|
||||
api_versions = {"cinder": {"version": "1", "service_type": "volume"}}
|
||||
manager.cleanup(names=["a", "b"], admin_required=True,
|
||||
admin="admin", users=["user"],
|
||||
api_versions={"cinder": {
|
||||
"version": "1", "service_type": "volume"
|
||||
}})
|
||||
api_versions=api_versions,
|
||||
superclass=utils.RandomNameGeneratorMixin,
|
||||
task_id="task_id")
|
||||
|
||||
mock_find_resource_managers.assert_called_once_with(["a", "b"], True)
|
||||
|
||||
mock_seek_and_destroy.assert_has_calls([
|
||||
mock.call(
|
||||
mock_find_resource_managers.return_value[0], "admin",
|
||||
["user"],
|
||||
{"cinder": {"service_type": "volume", "version": "1"}}
|
||||
),
|
||||
mock.call(mock_find_resource_managers.return_value[0], "admin",
|
||||
["user"], api_versions=api_versions,
|
||||
resource_classes=[A], task_id="task_id"),
|
||||
mock.call().exterminate(),
|
||||
mock.call(
|
||||
mock_find_resource_managers.return_value[1], "admin",
|
||||
["user"],
|
||||
{"cinder": {"service_type": "volume", "version": "1"}}
|
||||
),
|
||||
mock.call(mock_find_resource_managers.return_value[1], "admin",
|
||||
["user"], api_versions=api_versions,
|
||||
resource_classes=[A], task_id="task_id"),
|
||||
mock.call().exterminate()
|
||||
])
|
||||
|
@ -20,11 +20,7 @@ from neutronclient.common import exceptions as neutron_exceptions
|
||||
from novaclient import exceptions as nova_exc
|
||||
from watcherclient.common.apiclient import exceptions as watcher_exceptions
|
||||
|
||||
from rally.common import utils
|
||||
from rally.plugins.openstack.cleanup import resources
|
||||
from rally.plugins.openstack.scenarios.cinder import utils as cutils
|
||||
from rally.plugins.openstack.scenarios.keystone import utils as kutils
|
||||
from rally.plugins.openstack.scenarios.nova import utils as nutils
|
||||
from tests.unit import test
|
||||
|
||||
BASE = "rally.plugins.openstack.cleanup.resources"
|
||||
@ -140,24 +136,11 @@ class NovaFloatingIPsTestCase(test.TestCase):
|
||||
def test_name(self):
|
||||
fips = resources.NovaFloatingIPs()
|
||||
fips.raw_resource = mock.MagicMock()
|
||||
self.assertIsNone(fips.name())
|
||||
self.assertTrue(fips.name())
|
||||
|
||||
|
||||
class NovaFlavorsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("%s.base.ResourceManager._manager" % BASE)
|
||||
@mock.patch("rally.common.utils.name_matches_object")
|
||||
def test_list(self, mock_name_matches_object,
|
||||
mock_resource_manager__manager):
|
||||
flavors = [mock.MagicMock(name="rally_foo1"),
|
||||
mock.MagicMock(name="rally_foo2"),
|
||||
mock.MagicMock(name="foo3")]
|
||||
mock_name_matches_object.side_effect = [False, True, True]
|
||||
mock_resource_manager__manager().list.return_value = flavors
|
||||
self.assertEqual(flavors[1:], resources.NovaFlavors().list())
|
||||
mock_name_matches_object.assert_has_calls(
|
||||
[mock.call(r.name, nutils.NovaScenario) for r in flavors])
|
||||
|
||||
@mock.patch("%s.base.ResourceManager._manager" % BASE)
|
||||
def test_is_deleted(self, mock_resource_manager__manager):
|
||||
exc = nova_exc.NotFound(404)
|
||||
@ -174,22 +157,6 @@ class NovaFlavorsTestCase(test.TestCase):
|
||||
self.assertRaises(TypeError, flavor.is_deleted)
|
||||
|
||||
|
||||
class NovaAggregatesTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("%s.base.ResourceManager._manager" % BASE)
|
||||
@mock.patch("rally.common.utils.name_matches_object")
|
||||
def test_list(self, mock_name_matches_object,
|
||||
mock_resource_manager__manager):
|
||||
aggregates = [mock.MagicMock(name="rally_foo1"),
|
||||
mock.MagicMock(name="rally_foo2"),
|
||||
mock.MagicMock(name="foo3")]
|
||||
mock_name_matches_object.side_effect = [False, True, True]
|
||||
mock_resource_manager__manager().list.return_value = aggregates
|
||||
self.assertEqual(aggregates[1:], resources.NovaAggregate().list())
|
||||
mock_name_matches_object.assert_has_calls(
|
||||
[mock.call(r.name, nutils.NovaScenario) for r in aggregates])
|
||||
|
||||
|
||||
class NovaServerGroupsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("%s.base.ResourceManager._manager" % BASE)
|
||||
@ -201,10 +168,7 @@ class NovaServerGroupsTestCase(test.TestCase):
|
||||
mock.MagicMock(name="foo3")]
|
||||
mock_name_matches_object.side_effect = [False, True, True]
|
||||
mock_resource_manager__manager().list.return_value = server_groups
|
||||
self.assertEqual(server_groups[1:],
|
||||
resources.NovaServerGroups().list())
|
||||
mock_name_matches_object.assert_has_calls(
|
||||
[mock.call(r.name, nutils.NovaScenario) for r in server_groups])
|
||||
self.assertEqual(server_groups, resources.NovaServerGroups().list())
|
||||
|
||||
|
||||
class NovaSecurityGroupTestCase(test.TestCase):
|
||||
@ -233,20 +197,6 @@ class NovaFloatingIpsBulkTestCase(test.TestCase):
|
||||
fips.raw_resource = mock.MagicMock()
|
||||
self.assertIsNone(fips.name())
|
||||
|
||||
@mock.patch("%s.base.ResourceManager._manager" % BASE)
|
||||
@mock.patch("rally.common.utils.name_matches_object")
|
||||
def test_list(self, mock_name_matches_object,
|
||||
mock_resource_manager__manager):
|
||||
ip_range = [mock.MagicMock(), mock.MagicMock(), mock.MagicMock()]
|
||||
ip_range[0].pool = "a"
|
||||
ip_range[1].pool = "rally_fip_pool_a"
|
||||
ip_range[2].pool = "rally_fip_pool_b"
|
||||
mock_name_matches_object.side_effect = (lambda n, o:
|
||||
n.startswith("rally"))
|
||||
|
||||
mock_resource_manager__manager().list.return_value = ip_range
|
||||
self.assertEqual(ip_range[1:], resources.NovaFloatingIpsBulk().list())
|
||||
|
||||
|
||||
class NovaNetworksTestCase(test.TestCase):
|
||||
|
||||
@ -255,24 +205,6 @@ class NovaNetworksTestCase(test.TestCase):
|
||||
network.raw_resource = mock.MagicMock()
|
||||
self.assertEqual(network.raw_resource.label, network.name())
|
||||
|
||||
@mock.patch("rally.common.plugin.discover.itersubclasses")
|
||||
def test_list(self, mock_itersubclasses):
|
||||
nova_nets = resources.NovaNetworks()
|
||||
|
||||
networks = [mock.Mock(label="rally_abcdefgh_12345678"),
|
||||
mock.Mock(label="rally_12345678_abcdefgh"),
|
||||
mock.Mock(label="foobar")]
|
||||
nova_nets._manager = mock.Mock()
|
||||
nova_nets._manager.return_value.list.return_value = networks
|
||||
|
||||
mock_itersubclasses.return_value = iter(
|
||||
[utils.RandomNameGeneratorMixin])
|
||||
|
||||
self.assertEqual(networks[:2], nova_nets.list())
|
||||
nova_nets._manager.return_value.list.assert_called_once_with()
|
||||
mock_itersubclasses.assert_called_once_with(
|
||||
utils.RandomNameGeneratorMixin)
|
||||
|
||||
|
||||
class EC2MixinTestCase(test.TestCase):
|
||||
|
||||
@ -701,27 +633,18 @@ class KeystoneMixinTestCase(test.TestCase):
|
||||
identity_service = mock_identity.Identity.return_value
|
||||
identity_service.delete_some_resource.assert_called_once_with("id_a")
|
||||
|
||||
@mock.patch("rally.common.utils.name_matches_object")
|
||||
@mock.patch("%s.identity" % BASE)
|
||||
def test_list(self, mock_identity, mock_name_matches_object):
|
||||
def test_list(self, mock_identity):
|
||||
keystone_mixin = self.get_keystone_mixin()
|
||||
keystone_mixin._resource = "fake_resource"
|
||||
keystone_mixin._resource = "some_resource2"
|
||||
keystone_mixin.admin = mock.MagicMock()
|
||||
identity = mock_identity.Identity
|
||||
|
||||
result = [mock.MagicMock(name="rally_foo1"),
|
||||
mock.MagicMock(name="rally_foo2"),
|
||||
mock.MagicMock(name="foo3")]
|
||||
mock_name_matches_object.side_effect = [True, True, False]
|
||||
|
||||
identity_service = mock_identity.Identity.return_value
|
||||
|
||||
identity_service.list_fake_resources.return_value = result
|
||||
|
||||
self.assertSequenceEqual(result[:2], keystone_mixin.list())
|
||||
identity_service.list_fake_resources.assert_called_once_with()
|
||||
|
||||
mock_name_matches_object.assert_has_calls(
|
||||
[mock.call(r.name, kutils.KeystoneScenario) for r in result])
|
||||
self.assertSequenceEqual(
|
||||
identity.return_value.list_some_resource2s.return_value,
|
||||
keystone_mixin.list())
|
||||
identity.assert_called_once_with(keystone_mixin.admin)
|
||||
identity.return_value.list_some_resource2s.assert_called_once_with()
|
||||
|
||||
|
||||
class SwiftMixinTestCase(test.TestCase):
|
||||
@ -905,18 +828,6 @@ class FuelEnvironmentTestCase(test.TestCase):
|
||||
self.assertFalse(fres.is_deleted())
|
||||
mock__manager.return_value.get.assert_called_with(fres.id.return_value)
|
||||
|
||||
@mock.patch("%s.FuelEnvironment._manager" % BASE)
|
||||
@mock.patch("rally.common.utils.name_matches_object")
|
||||
def test_list(self, mock_name_matches_object, mock__manager):
|
||||
envs = [{"name": "rally_one"}, {"name": "rally_two"},
|
||||
{"name": "three"}]
|
||||
mock__manager.return_value.list.return_value = envs
|
||||
mock_name_matches_object.side_effect = (
|
||||
lambda n, o: n.startswith("rally_"))
|
||||
|
||||
fres = resources.FuelEnvironment()
|
||||
self.assertEqual(envs[:-1], fres.list())
|
||||
|
||||
|
||||
class SenlinMixinTestCase(test.TestCase):
|
||||
|
||||
@ -1042,19 +953,3 @@ class WatcherActionPlanTestCase(test.TestCase):
|
||||
|
||||
self.assertEqual("action_plan", watcher._resource)
|
||||
watcher._manager().list.assert_called_once_with(limit=0)
|
||||
|
||||
|
||||
class CinderVolumeTypeTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("%s.base.ResourceManager._manager" % BASE)
|
||||
@mock.patch("rally.common.utils.name_matches_object")
|
||||
def test_list(self, mock_name_matches_object,
|
||||
mock_resource_manager__manager):
|
||||
volume_types = [mock.MagicMock(name="foo1"),
|
||||
mock.MagicMock(name="rally_foo2"),
|
||||
mock.MagicMock(name="rally_foo3")]
|
||||
mock_name_matches_object.side_effect = [False, True, True]
|
||||
mock_resource_manager__manager().list.return_value = volume_types
|
||||
self.assertEqual(volume_types[1:], resources.CinderVolumeType().list())
|
||||
mock_name_matches_object.assert_has_calls(
|
||||
[mock.call(r.name, cutils.CinderScenario) for r in volume_types])
|
||||
|
@ -19,6 +19,7 @@ import jsonschema
|
||||
import mock
|
||||
|
||||
from rally.plugins.openstack.context.cinder import volumes
|
||||
from rally.plugins.openstack.scenarios.cinder import utils as cinder_utils
|
||||
from tests.unit import fakes
|
||||
from tests.unit import test
|
||||
|
||||
@ -136,9 +137,10 @@ class VolumeGeneratorTestCase(test.ScenarioTestCase):
|
||||
volumes_ctx = volumes.VolumeGenerator(self.context)
|
||||
volumes_ctx.cleanup()
|
||||
|
||||
mock_cleanup.assert_called_once_with(names=["cinder.volumes"],
|
||||
users=self.context["users"],
|
||||
api_versions=None)
|
||||
mock_cleanup.assert_called_once_with(
|
||||
names=["cinder.volumes"], users=self.context["users"],
|
||||
api_versions=None, superclass=cinder_utils.CinderScenario,
|
||||
task_id=self.context["task"]["uuid"])
|
||||
|
||||
@mock.patch("%s.cinder.volumes.resource_manager.cleanup" % CTX)
|
||||
def test_cleanup_api_versions(self, mock_cleanup):
|
||||
@ -190,4 +192,6 @@ class VolumeGeneratorTestCase(test.ScenarioTestCase):
|
||||
mock_cleanup.assert_called_once_with(
|
||||
names=["cinder.volumes"],
|
||||
users=self.context["users"],
|
||||
api_versions=api_version)
|
||||
api_versions=api_version,
|
||||
superclass=cinder_utils.CinderScenario,
|
||||
task_id=self.context["task"]["uuid"])
|
||||
|
@ -16,6 +16,7 @@
|
||||
import jsonschema
|
||||
import mock
|
||||
|
||||
from rally.common import utils
|
||||
from rally.plugins.openstack.context.cleanup import admin
|
||||
from rally.plugins.openstack.context.cleanup import base
|
||||
from tests.unit import test
|
||||
@ -45,16 +46,22 @@ class AdminCleanupTestCase(test.TestCase):
|
||||
self.assertRaises(jsonschema.ValidationError,
|
||||
admin.AdminCleanup.validate, {})
|
||||
|
||||
@mock.patch("rally.common.plugin.discover.itersubclasses")
|
||||
@mock.patch("%s.manager.find_resource_managers" % BASE,
|
||||
return_value=[mock.MagicMock(), mock.MagicMock()])
|
||||
@mock.patch("%s.manager.SeekAndDestroy" % BASE)
|
||||
def test_cleanup(self, mock_seek_and_destroy, mock_find_resource_managers):
|
||||
def test_cleanup(self, mock_seek_and_destroy, mock_find_resource_managers,
|
||||
mock_itersubclasses):
|
||||
class ResourceClass(utils.RandomNameGeneratorMixin):
|
||||
pass
|
||||
|
||||
mock_itersubclasses.return_value = [ResourceClass]
|
||||
|
||||
ctx = {
|
||||
"config": {"admin_cleanup": ["a", "b"]},
|
||||
"admin": mock.MagicMock(),
|
||||
"users": mock.MagicMock(),
|
||||
"task": mock.MagicMock()
|
||||
"task": {"uuid": "task_id"}
|
||||
}
|
||||
|
||||
admin_cleanup = admin.AdminCleanup(ctx)
|
||||
@ -63,27 +70,34 @@ class AdminCleanupTestCase(test.TestCase):
|
||||
|
||||
mock_find_resource_managers.assert_called_once_with(("a", "b"), True)
|
||||
mock_seek_and_destroy.assert_has_calls([
|
||||
mock.call(
|
||||
mock_find_resource_managers.return_value[0],
|
||||
ctx["admin"],
|
||||
ctx["users"],
|
||||
None),
|
||||
mock.call(mock_find_resource_managers.return_value[0],
|
||||
ctx["admin"],
|
||||
ctx["users"],
|
||||
api_versions=None,
|
||||
resource_classes=[ResourceClass],
|
||||
task_id="task_id"),
|
||||
mock.call().exterminate(),
|
||||
mock.call(
|
||||
mock_find_resource_managers.return_value[1],
|
||||
ctx["admin"],
|
||||
ctx["users"],
|
||||
None),
|
||||
mock.call(mock_find_resource_managers.return_value[1],
|
||||
ctx["admin"],
|
||||
ctx["users"],
|
||||
api_versions=None,
|
||||
resource_classes=[ResourceClass],
|
||||
task_id="task_id"),
|
||||
mock.call().exterminate()
|
||||
])
|
||||
|
||||
@mock.patch("rally.common.plugin.discover.itersubclasses")
|
||||
@mock.patch("%s.manager.find_resource_managers" % BASE,
|
||||
return_value=[mock.MagicMock(), mock.MagicMock()])
|
||||
@mock.patch("%s.manager.SeekAndDestroy" % BASE)
|
||||
def test_cleanup_admin_with_api_versions(
|
||||
self,
|
||||
mock_seek_and_destroy,
|
||||
mock_find_resource_managers):
|
||||
def test_cleanup_admin_with_api_versions(self,
|
||||
mock_seek_and_destroy,
|
||||
mock_find_resource_managers,
|
||||
mock_itersubclasses):
|
||||
class ResourceClass(utils.RandomNameGeneratorMixin):
|
||||
pass
|
||||
|
||||
mock_itersubclasses.return_value = [ResourceClass]
|
||||
|
||||
ctx = {
|
||||
"config":
|
||||
@ -106,16 +120,18 @@ class AdminCleanupTestCase(test.TestCase):
|
||||
|
||||
mock_find_resource_managers.assert_called_once_with(("a", "b"), True)
|
||||
mock_seek_and_destroy.assert_has_calls([
|
||||
mock.call(
|
||||
mock_find_resource_managers.return_value[0],
|
||||
ctx["admin"],
|
||||
ctx["users"],
|
||||
ctx["config"]["api_versions"]),
|
||||
mock.call(mock_find_resource_managers.return_value[0],
|
||||
ctx["admin"],
|
||||
ctx["users"],
|
||||
api_versions=ctx["config"]["api_versions"],
|
||||
resource_classes=[ResourceClass],
|
||||
task_id=ctx["task"]["uuid"]),
|
||||
mock.call().exterminate(),
|
||||
mock.call(
|
||||
mock_find_resource_managers.return_value[1],
|
||||
ctx["admin"],
|
||||
ctx["users"],
|
||||
ctx["config"]["api_versions"]),
|
||||
mock.call(mock_find_resource_managers.return_value[1],
|
||||
ctx["admin"],
|
||||
ctx["users"],
|
||||
api_versions=ctx["config"]["api_versions"],
|
||||
resource_classes=[ResourceClass],
|
||||
task_id=ctx["task"]["uuid"]),
|
||||
mock.call().exterminate()
|
||||
])
|
||||
|
@ -16,6 +16,7 @@
|
||||
import jsonschema
|
||||
import mock
|
||||
|
||||
from rally.common import utils
|
||||
from rally.plugins.openstack.context.cleanup import base
|
||||
from rally.plugins.openstack.context.cleanup import user
|
||||
from tests.unit import test
|
||||
@ -45,15 +46,22 @@ class UserCleanupTestCase(test.TestCase):
|
||||
self.assertRaises(jsonschema.ValidationError,
|
||||
user.UserCleanup.validate, {})
|
||||
|
||||
@mock.patch("rally.common.plugin.discover.itersubclasses")
|
||||
@mock.patch("%s.manager.find_resource_managers" % BASE,
|
||||
return_value=[mock.MagicMock(), mock.MagicMock()])
|
||||
@mock.patch("%s.manager.SeekAndDestroy" % BASE)
|
||||
def test_cleanup(self, mock_seek_and_destroy, mock_find_resource_managers):
|
||||
def test_cleanup(self, mock_seek_and_destroy, mock_find_resource_managers,
|
||||
mock_itersubclasses):
|
||||
|
||||
class ResourceClass(utils.RandomNameGeneratorMixin):
|
||||
pass
|
||||
|
||||
mock_itersubclasses.return_value = [ResourceClass]
|
||||
|
||||
ctx = {
|
||||
"config": {"cleanup": ["a", "b"]},
|
||||
"users": mock.MagicMock(),
|
||||
"task": mock.MagicMock()
|
||||
"task": {"uuid": "task_id"}
|
||||
}
|
||||
|
||||
admin_cleanup = user.UserCleanup(ctx)
|
||||
@ -61,25 +69,31 @@ class UserCleanupTestCase(test.TestCase):
|
||||
admin_cleanup.cleanup()
|
||||
|
||||
mock_find_resource_managers.assert_called_once_with(("a", "b"), False)
|
||||
|
||||
mock_seek_and_destroy.assert_has_calls([
|
||||
mock.call(
|
||||
mock_find_resource_managers.return_value[0],
|
||||
None, ctx["users"], None),
|
||||
mock.call(mock_find_resource_managers.return_value[0],
|
||||
None, ctx["users"], api_versions=None,
|
||||
resource_classes=[ResourceClass], task_id="task_id"),
|
||||
mock.call().exterminate(),
|
||||
mock.call(
|
||||
mock_find_resource_managers.return_value[1],
|
||||
None, ctx["users"], None),
|
||||
mock.call(mock_find_resource_managers.return_value[1],
|
||||
None, ctx["users"], api_versions=None,
|
||||
resource_classes=[ResourceClass], task_id="task_id"),
|
||||
mock.call().exterminate()
|
||||
])
|
||||
|
||||
@mock.patch("rally.common.plugin.discover.itersubclasses")
|
||||
@mock.patch("%s.manager.find_resource_managers" % BASE,
|
||||
return_value=[mock.MagicMock(), mock.MagicMock()])
|
||||
@mock.patch("%s.manager.SeekAndDestroy" % BASE)
|
||||
def test_cleanup_user_with_api_versions(
|
||||
self,
|
||||
mock_seek_and_destroy,
|
||||
mock_find_resource_managers):
|
||||
mock_find_resource_managers,
|
||||
mock_itersubclasses):
|
||||
|
||||
class ResourceClass(utils.RandomNameGeneratorMixin):
|
||||
pass
|
||||
|
||||
mock_itersubclasses.return_value = [ResourceClass]
|
||||
|
||||
ctx = {
|
||||
"config":
|
||||
@ -93,7 +107,7 @@ class UserCleanupTestCase(test.TestCase):
|
||||
},
|
||||
"admin": mock.MagicMock(),
|
||||
"users": mock.MagicMock(),
|
||||
"task": mock.MagicMock()
|
||||
"task": {"uuid": "task_id"}
|
||||
}
|
||||
|
||||
user_cleanup = user.UserCleanup(ctx)
|
||||
@ -102,16 +116,18 @@ class UserCleanupTestCase(test.TestCase):
|
||||
|
||||
mock_find_resource_managers.assert_called_once_with({}, False)
|
||||
mock_seek_and_destroy.assert_has_calls([
|
||||
mock.call(
|
||||
mock_find_resource_managers.return_value[0],
|
||||
None,
|
||||
ctx["users"],
|
||||
ctx["config"]["api_versions"]),
|
||||
mock.call(mock_find_resource_managers.return_value[0],
|
||||
None,
|
||||
ctx["users"],
|
||||
api_versions=ctx["config"]["api_versions"],
|
||||
resource_classes=[ResourceClass],
|
||||
task_id="task_id"),
|
||||
mock.call().exterminate(),
|
||||
mock.call(
|
||||
mock_find_resource_managers.return_value[1],
|
||||
None,
|
||||
ctx["users"],
|
||||
ctx["config"]["api_versions"]),
|
||||
mock.call(mock_find_resource_managers.return_value[1],
|
||||
None,
|
||||
ctx["users"],
|
||||
api_versions=ctx["config"]["api_versions"],
|
||||
resource_classes=[ResourceClass],
|
||||
task_id="task_id"),
|
||||
mock.call().exterminate()
|
||||
])
|
||||
|
@ -18,6 +18,7 @@ import copy
|
||||
import mock
|
||||
|
||||
from rally.plugins.openstack.context.designate import zones
|
||||
from rally.plugins.openstack.scenarios.designate import utils
|
||||
from tests.unit import test
|
||||
|
||||
CTX = "rally.plugins.openstack.context"
|
||||
@ -124,5 +125,8 @@ class ZoneGeneratorTestCase(test.ScenarioTestCase):
|
||||
zones_ctx = zones.ZoneGenerator(self.context)
|
||||
zones_ctx.cleanup()
|
||||
|
||||
mock_cleanup.assert_called_once_with(names=["designate.zones"],
|
||||
users=self.context["users"])
|
||||
mock_cleanup.assert_called_once_with(
|
||||
names=["designate.zones"],
|
||||
users=self.context["users"],
|
||||
superclass=utils.DesignateScenario,
|
||||
task_id=self.context["task"]["uuid"])
|
||||
|
@ -17,6 +17,7 @@ import copy
|
||||
import mock
|
||||
|
||||
from rally.plugins.openstack.context.ec2 import servers
|
||||
from rally.plugins.openstack.scenarios.ec2 import utils as ec2_utils
|
||||
from tests.unit import fakes
|
||||
from tests.unit import test
|
||||
|
||||
@ -105,5 +106,8 @@ class EC2ServerGeneratorTestCase(test.TestCase):
|
||||
servers_ctx = servers.EC2ServerGenerator(context)
|
||||
servers_ctx.cleanup()
|
||||
|
||||
mock_cleanup.assert_called_once_with(names=["ec2.servers"],
|
||||
users=context["users"])
|
||||
mock_cleanup.assert_called_once_with(
|
||||
names=["ec2.servers"],
|
||||
users=context["users"],
|
||||
superclass=ec2_utils.EC2Scenario,
|
||||
task_id=context["task"]["uuid"])
|
||||
|
@ -16,6 +16,7 @@
|
||||
import mock
|
||||
|
||||
from rally.plugins.openstack.context.heat import stacks
|
||||
from rally.plugins.openstack.scenarios.heat import utils as heat_utils
|
||||
from tests.unit import fakes
|
||||
from tests.unit import test
|
||||
|
||||
@ -90,5 +91,8 @@ class TestStackGenerator(test.ScenarioTestCase):
|
||||
})
|
||||
stack_ctx = stacks.StackGenerator(self.context)
|
||||
stack_ctx.cleanup()
|
||||
mock_cleanup.assert_called_once_with(names=["heat.stacks"],
|
||||
users=self.context["users"])
|
||||
mock_cleanup.assert_called_once_with(
|
||||
names=["heat.stacks"],
|
||||
users=self.context["users"],
|
||||
superclass=heat_utils.HeatScenario,
|
||||
task_id=self.context["task"]["uuid"])
|
||||
|
@ -16,6 +16,7 @@
|
||||
import mock
|
||||
|
||||
from rally.plugins.openstack.context.murano import murano_packages
|
||||
from rally.plugins.openstack.scenarios.murano import utils as murano_utils
|
||||
from tests.unit import test
|
||||
|
||||
CTX = "rally.plugins.openstack.context.murano.murano_packages"
|
||||
@ -89,8 +90,11 @@ class MuranoPackageGeneratorTestCase(test.TestCase):
|
||||
murano_ctx.setup()
|
||||
murano_ctx.cleanup()
|
||||
|
||||
mock_cleanup.assert_called_once_with(names=["murano.packages"],
|
||||
users=murano_ctx.context["users"])
|
||||
mock_cleanup.assert_called_once_with(
|
||||
names=["murano.packages"],
|
||||
users=murano_ctx.context["users"],
|
||||
superclass=murano_utils.MuranoScenario,
|
||||
task_id=murano_ctx.context["task"]["uuid"])
|
||||
|
||||
@mock.patch("%s.osclients" % CTX)
|
||||
@mock.patch("%s.resource_manager.cleanup" % CTX)
|
||||
@ -107,5 +111,8 @@ class MuranoPackageGeneratorTestCase(test.TestCase):
|
||||
murano_ctx.setup()
|
||||
murano_ctx.cleanup()
|
||||
|
||||
mock_cleanup.assert_called_once_with(names=["murano.packages"],
|
||||
users=murano_ctx.context["users"])
|
||||
mock_cleanup.assert_called_once_with(
|
||||
names=["murano.packages"],
|
||||
users=murano_ctx.context["users"],
|
||||
superclass=murano_utils.MuranoScenario,
|
||||
task_id=ctx_dict["task"]["uuid"])
|
||||
|
@ -72,8 +72,11 @@ class KeyPairContextTestCase(test.TestCase):
|
||||
def test_keypair_cleanup(self, mock_cleanup):
|
||||
keypair_ctx = keypairs.Keypair(self.ctx_with_keys)
|
||||
keypair_ctx.cleanup()
|
||||
mock_cleanup.assert_called_once_with(names=["nova.keypairs"],
|
||||
users=self.ctx_with_keys["users"])
|
||||
mock_cleanup.assert_called_once_with(
|
||||
names=["nova.keypairs"],
|
||||
users=self.ctx_with_keys["users"],
|
||||
superclass=keypairs.Keypair,
|
||||
task_id=self.ctx_with_keys["task"]["uuid"])
|
||||
|
||||
@mock.patch("rally.osclients.Clients")
|
||||
def test_keypair_generate(self, mock_clients):
|
||||
|
@ -18,6 +18,7 @@ import copy
|
||||
import mock
|
||||
|
||||
from rally.plugins.openstack.context.nova import servers
|
||||
from rally.plugins.openstack.scenarios.nova import utils as nova_utils
|
||||
from tests.unit import fakes
|
||||
from tests.unit import test
|
||||
|
||||
@ -169,5 +170,8 @@ class ServerGeneratorTestCase(test.ScenarioTestCase):
|
||||
servers_ctx = servers.ServerGenerator(self.context)
|
||||
servers_ctx.cleanup()
|
||||
|
||||
mock_cleanup.assert_called_once_with(names=["nova.servers"],
|
||||
users=self.context["users"])
|
||||
mock_cleanup.assert_called_once_with(
|
||||
names=["nova.servers"],
|
||||
users=self.context["users"],
|
||||
superclass=nova_utils.NovaScenario,
|
||||
task_id=self.context["task"]["uuid"])
|
||||
|
@ -17,6 +17,7 @@ from oslo_config import cfg
|
||||
|
||||
from rally import exceptions
|
||||
from rally.plugins.openstack.context.sahara import sahara_cluster
|
||||
from rally.plugins.openstack.scenarios.sahara import utils as sahara_utils
|
||||
from tests.unit import test
|
||||
|
||||
CONF = cfg.CONF
|
||||
@ -106,8 +107,11 @@ class SaharaClusterTestCase(test.ScenarioTestCase):
|
||||
mock_sahara_scenario__launch_cluster.assert_has_calls(
|
||||
launch_cluster_calls)
|
||||
sahara_ctx.cleanup()
|
||||
mock_cleanup.assert_called_once_with(names=["sahara.clusters"],
|
||||
users=self.context["users"])
|
||||
mock_cleanup.assert_called_once_with(
|
||||
names=["sahara.clusters"],
|
||||
users=self.context["users"],
|
||||
superclass=sahara_utils.SaharaScenario,
|
||||
task_id=self.context["task"]["uuid"])
|
||||
|
||||
@mock.patch("%s.sahara_cluster.utils.SaharaScenario._launch_cluster" % CTX,
|
||||
return_value=mock.MagicMock(id=42))
|
||||
|
@ -16,6 +16,7 @@ import mock
|
||||
|
||||
from rally import exceptions
|
||||
from rally.plugins.openstack.context.sahara import sahara_image
|
||||
from rally.plugins.openstack.scenarios.glance import utils as glance_utils
|
||||
from tests.unit import test
|
||||
|
||||
|
||||
@ -122,8 +123,11 @@ class SaharaImageTestCase(test.ScenarioTestCase):
|
||||
sahara_update_tags_calls)
|
||||
|
||||
sahara_ctx.cleanup()
|
||||
mock_cleanup.assert_called_once_with(names=["glance.images"],
|
||||
users=ctx["users"])
|
||||
mock_cleanup.assert_called_once_with(
|
||||
names=["glance.images"],
|
||||
users=ctx["users"],
|
||||
superclass=glance_utils.GlanceScenario,
|
||||
task_id=ctx["task"]["uuid"])
|
||||
|
||||
@mock.patch("%s.glance.utils.GlanceScenario._create_image" % SCN,
|
||||
return_value=mock.MagicMock(id=42))
|
||||
|
@ -15,6 +15,7 @@
|
||||
import mock
|
||||
|
||||
from rally.plugins.openstack.context.sahara import sahara_input_data_sources
|
||||
from rally.plugins.openstack.scenarios.sahara import utils as sahara_utils
|
||||
from tests.unit import test
|
||||
|
||||
CTX = "rally.plugins.openstack.context.sahara"
|
||||
@ -89,7 +90,9 @@ class SaharaInputDataSourcesTestCase(test.ScenarioTestCase):
|
||||
|
||||
mock_cleanup.assert_called_once_with(
|
||||
names=["sahara.data_sources"],
|
||||
users=self.context["users"])
|
||||
users=self.context["users"],
|
||||
superclass=sahara_utils.SaharaScenario,
|
||||
task_id=self.context["task"]["uuid"])
|
||||
|
||||
@mock.patch("requests.get")
|
||||
@mock.patch("%s.sahara_input_data_sources.osclients" % CTX)
|
||||
@ -155,4 +158,6 @@ class SaharaInputDataSourcesTestCase(test.ScenarioTestCase):
|
||||
|
||||
mock_resource_manager.cleanup.assert_called_once_with(
|
||||
names=["sahara.data_sources"],
|
||||
users=self.context["users"])
|
||||
users=self.context["users"],
|
||||
superclass=sahara_utils.SaharaScenario,
|
||||
task_id=self.context["task"]["uuid"])
|
||||
|
@ -15,6 +15,7 @@
|
||||
import mock
|
||||
|
||||
from rally.plugins.openstack.context.sahara import sahara_job_binaries
|
||||
from rally.plugins.openstack.scenarios.sahara import utils as sahara_utils
|
||||
from tests.unit import test
|
||||
|
||||
CTX = "rally.plugins.openstack.context.sahara"
|
||||
@ -110,7 +111,9 @@ class SaharaJobBinariesTestCase(test.ScenarioTestCase):
|
||||
|
||||
mock_cleanup.assert_called_once_with(
|
||||
names=["sahara.job_binary_internals", "sahara.job_binaries"],
|
||||
users=self.context["users"])
|
||||
users=self.context["users"],
|
||||
superclass=sahara_utils.SaharaScenario,
|
||||
task_id=self.context["task"]["uuid"])
|
||||
|
||||
@mock.patch("%s.sahara_job_binaries.requests" % CTX)
|
||||
@mock.patch("%s.sahara_job_binaries.osclients" % CTX)
|
||||
|
@ -16,6 +16,7 @@ import mock
|
||||
|
||||
from rally.common import objects
|
||||
from rally.plugins.openstack.context.sahara import sahara_output_data_sources
|
||||
from rally.plugins.openstack.scenarios.sahara import utils as sahara_utils
|
||||
from tests.unit import test
|
||||
|
||||
CTX = "rally.plugins.openstack.context.sahara"
|
||||
@ -99,7 +100,9 @@ class SaharaOutputDataSourcesTestCase(test.ScenarioTestCase):
|
||||
|
||||
mock_cleanup.assert_called_once_with(
|
||||
names=["sahara.data_sources"],
|
||||
users=self.context["users"])
|
||||
users=self.context["users"],
|
||||
superclass=sahara_utils.SaharaScenario,
|
||||
task_id=self.context["task"]["uuid"])
|
||||
|
||||
@mock.patch("%s.sahara_output_data_sources.osclients" % CTX)
|
||||
def test_setup_inputs_swift(self, mock_osclients):
|
||||
|
Loading…
x
Reference in New Issue
Block a user