Esempio n. 1
0
    def _cleanup_tenant_resources(self, resources_plural_name,
                                  resources_singular_name):
        """Cleans up tenant resources.

        :param resources_plural_name: plural name for resources
        :param resources_singular_name: singular name for resource. Expected
            to be part of resource deletion method name (obj._delete_%s)
        """
        for user, tenant_id in (utils.iterate_per_tenants(
                self.context.get("users", []))):
            manila_scenario = manila_utils.ManilaScenario({
                "user": user,
                "config": {
                    "api_versions": self.context["config"].get(
                        "api_versions", [])}
            })
            resources = self.context["tenants"][tenant_id][CONTEXT_NAME].get(
                resources_plural_name, [])
            for resource in resources:
                logger = logging.ExceptionLogger(
                    LOG,
                    _("Failed to delete %(name)s %(id)s for tenant %(t)s.") % {
                        "id": resource, "t": tenant_id,
                        "name": resources_singular_name})
                with logger:
                    delete_func = getattr(
                        manila_scenario,
                        "_delete_%s" % resources_singular_name)
                    delete_func(resource)
Esempio n. 2
0
 def cleanup(self):
     for user, tenant_id in self._iterate_per_tenants():
         with logging.ExceptionLogger(
                 LOG, "Unable to delete security group: %s." %
                 user["secgroup"]["name"]):
             clients = osclients.Clients(user["credential"])
             clients.neutron().delete_security_group(user["secgroup"]["id"])
Esempio n. 3
0
 def _delete_floating_ip(self, server, fip):
     with logging.ExceptionLogger(
             LOG, _("Unable to delete IP: %s") % fip["ip"]):
         if self.check_ip_address(fip["ip"])(server):
             self._dissociate_floating_ip(server, fip["ip"])
             network_wrapper.wrap(self.clients, self).delete_floating_ip(
                 fip["id"], wait=True)
Esempio n. 4
0
    def _remove_default_security_group(self):
        """Delete default security group for tenants."""
        clients = osclients.Clients(self.credential)

        if consts.Service.NEUTRON not in clients.services().values():
            return

        use_sg, msg = network.wrap(clients,
                                   self).supports_extension("security-group")
        if not use_sg:
            LOG.debug("Security group context is disabled: %s" % msg)
            return

        for user, tenant_id in rutils.iterate_per_tenants(
                self.context["users"]):
            with logging.ExceptionLogger(
                    LOG, "Unable to delete default security group"):
                uclients = osclients.Clients(user["credential"])
                security_groups = uclients.neutron()\
                    .list_security_groups(tenant_id=tenant_id)
                default = [
                    sg for sg in security_groups["security_groups"]
                    if sg["name"] == "default"
                ]
                if default:
                    clients.neutron().delete_security_group(default[0]["id"])
Esempio n. 5
0
    def delete_one_image(self, user, custom_image):
        """Delete the image created for the user and tenant."""

        with logging.ExceptionLogger(
                LOG, "Unable to delete image %s" % custom_image.id):

            glance_service = image.Image(user["credential"].clients())
            glance_service.delete_image(custom_image.id)
Esempio n. 6
0
 def cleanup(self):
     """Delete created flavors."""
     clients = osclients.Clients(self.context["admin"]["credential"])
     for flavor in self.context["flavors"].values():
         with logging.ExceptionLogger(
                 LOG,
                 _("Can't delete flavor %s") % flavor["id"]):
             rutils.retry(3, clients.nova().flavors.delete, flavor["id"])
             LOG.debug("Flavor is deleted %s" % flavor["id"])
Esempio n. 7
0
 def _delete_floating_ip(self, server, fip):
     with logging.ExceptionLogger(LOG,
                                  "Unable to delete IP: %s" % fip["ip"]):
         if self.check_ip_address(fip["ip"])(server):
             self._dissociate_floating_ip(server, fip["ip"])
             with atomic.ActionTimer(self, "neutron.delete_floating_ip"):
                 network_wrapper.wrap(self.clients,
                                      self).delete_floating_ip(fip["id"],
                                                               wait=True)
Esempio n. 8
0
 def cleanup(self):
     net_wrapper = network_wrapper.wrap(
         osclients.Clients(self.context["admin"]["credential"]),
         self, config=self.config)
     for tenant_id, tenant_ctx in self.context["tenants"].items():
         for network in tenant_ctx.get("networks", []):
             with logging.ExceptionLogger(
                     LOG,
                     "Failed to delete network for tenant %s" % tenant_id):
                 net_wrapper.delete_network(network)
Esempio n. 9
0
 def cleanup(self):
     for user, tenant_id in utils.iterate_per_tenants(
             self.context["users"]):
         with logging.ExceptionLogger(
                 LOG,
                 _("Unable to delete secgroup: %s.") %
                 user["secgroup"]["name"]):
             clients = osclients.Clients(user["credential"])
             clients.nova().security_groups.get(
                 user["secgroup"]["id"]).delete()
 def cleanup(self):
     for user, tenant_id in rutils.iterate_per_tenants(
             self.context["users"]):
         glance = osclients.Clients(user["credential"]).glance().images
         for image in self.context["tenants"][tenant_id].get("images", []):
             with logging.ExceptionLogger(
                     LOG,
                     _("Failed to delete network for tenant %s") %
                     tenant_id):
                 glance.delete(image)
 def cleanup(self):
     for user, tenant_id in utils.iterate_per_tenants(
             self.context["users"]):
         with logging.ExceptionLogger(
                 LOG, "Unable to delete security group: %s." %
                 user["secgroup"]["name"]):
             clients = osclients.Clients(user["credential"])
             for port in self.ports:
                 clients.neutron().delete_port(port['id'])
             clients.neutron().delete_security_group(user["secgroup"]["id"])
             clients.neutron().delete_security_group(self.remote_sg['id'])
Esempio n. 12
0
 def cleanup(self):
     net_wrapper = network_wrapper.wrap(
         osclients.Clients(self.context["admin"]["credential"]),
         self, config=self.config)
     for tenant_id, tenant_ctx in self.context["tenants"].items():
         for network in tenant_ctx.get("networks", []):
             for pool in network.get("lb_pools", []):
                 with logging.ExceptionLogger(
                         LOG,
                         _("Failed to delete pool %(pool)s for tenant "
                             "%(tenant)s") % {"pool": pool["pool"]["id"],
                                              "tenant": tenant_id}):
                     if self.config["lbaas_version"] == 1:
                         net_wrapper.delete_v1_pool(pool["pool"]["id"])
Esempio n. 13
0
    def delete_one_image(self, user, custom_image):
        """Delete the image created for the user and tenant."""

        clients = osclients.Clients(user["credential"])

        nova_scenario = nova_utils.NovaScenario(
            context=self.context, clients=clients)

        with logging.ExceptionLogger(
                LOG, _("Unable to delete image %s") % custom_image["id"]):

            custom_image = nova_scenario.clients("nova").images.get(
                custom_image["id"])
            nova_scenario._delete_image(custom_image)
Esempio n. 14
0
    def _remove_role(self, admin_credential, role):
        """Remove given role from users.

        :param admin_credential: The admin credential.
        :param role: dictionary with role parameters (id, name).
        """
        client = keystone.wrap(osclients.Clients(admin_credential).keystone())

        for user in self.context["users"]:
            with logging.ExceptionLogger(
                    LOG, _("Failed to remove role: %s") % role["id"]):
                client.remove_role(
                    user_id=user["id"], role_id=role["id"],
                    project_id=user["tenant_id"])
Esempio n. 15
0
    def test_context(self, mock_is_debug):
        # Prepare
        mock_is_debug.return_value = True

        logger = mock.MagicMock()
        exception = Exception()

        # Run
        with rally_logging.ExceptionLogger(logger, "foo") as e:
            raise exception

        # Assertions
        logger.warning.assert_called_once_with("foo")

        logger.exception.assert_called_once_with(exception)

        logger.debug.assert_called_once_with(exception)

        self.assertEqual(e.exception, exception)
Esempio n. 16
0
    def _remove_default_security_group(self):
        """Delete default security group for tenants."""
        clients = osclients.Clients(self.credential)

        if consts.Service.NEUTRON not in clients.services().values():
            return

        use_sg, msg = network.wrap(clients,
                                   self).supports_extension("security-group")
        if not use_sg:
            LOG.debug("Security group context is disabled: %s" % msg)
            return

        for user, tenant_id in rutils.iterate_per_tenants(
                self.context["users"]):
            with logging.ExceptionLogger(
                    LOG, _("Unable to delete default security group")):
                uclients = osclients.Clients(user["credential"])
                sg = uclients.nova().security_groups.find(name="default")
                clients.neutron().delete_security_group(sg.id)
Esempio n. 17
0
 def _delete_floating_ip(self, server, fip):
     with logging.ExceptionLogger(
             LOG, "Unable to delete IP: %s" % fip["ip"]):
         if self.check_ip_address(fip["ip"])(server):
             self._dissociate_floating_ip(server, fip)
             self.neutron.delete_floatingip(fip["id"])