Ejemplo n.º 1
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).delete_floating_ip(fip["id"],
                                                               wait=True)
Ejemplo n.º 2
0
 def cleanup(self):
     """Delete created flavors."""
     clients = osclients.Clients(self.context["admin"]["endpoint"])
     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"])
Ejemplo n.º 3
0
 def cleanup(self):
     for tenant_id, tenant_ctx in six.iteritems(self.context["tenants"]):
         for network in tenant_ctx.get("networks", []):
             with logging.ExceptionLogger(
                     LOG,
                     _("Failed to delete network for tenant %s")
                     % tenant_id):
                 self.net_wrapper.delete_network(network)
Ejemplo n.º 4
0
 def cleanup(self):
     for user, tenant_id in rutils.iterate_per_tenants(
             self.context["users"]):
         glance = osclients.Clients(user["endpoint"]).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)
Ejemplo n.º 5
0
 def cleanup(self):
     net_wrapper = network_wrapper.wrap(
         osclients.Clients(self.context["admin"]["endpoint"]), self.config)
     for tenant_id, tenant_ctx in six.iteritems(self.context["tenants"]):
         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)
Ejemplo n.º 6
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["endpoint"])
             clients.nova().security_groups.get(
                 user["secgroup"]["id"]).delete()
Ejemplo n.º 7
0
 def cleanup(self):
     net_wrapper = network_wrapper.wrap(
         osclients.Clients(self.context["admin"]["endpoint"]),
         self.task, config=self.config)
     for tenant_id, tenant_ctx in six.iteritems(self.context["tenants"]):
         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"])
Ejemplo n.º 8
0
    def _remove_role(self, admin_endpoint, role):
        """Remove given role from users.

        :param admin_endpoint: The base url.
        :param role: dictionary with role parameters (id, name).
        """
        client = keystone.wrap(osclients.Clients(admin_endpoint).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"])
    def delete_one_image(self, user, custom_image):
        """Delete the image created for the user and tenant."""

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

        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)
Ejemplo n.º 10
0
    def test_context(self, mock_is_debug):
        # Prepare
        mock_is_debug.return_value = True

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

        # Run
        with log.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)
Ejemplo n.º 11
0
    def _remove_default_security_group(self):
        """Delete default security group for tenants."""
        clients = osclients.Clients(self.endpoint)

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

        use_sg, msg = network.wrap(clients).supports_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["endpoint"])
                sg = uclients.nova().security_groups.find(name="default")
                clients.neutron().delete_security_group(sg.id)