How to use the rally.exceptions function in rally

To help you get started, we’ve selected a few rally examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / rally-openstack / tests / unit / plugins / openstack / test_osclients.py View on Github external
def test_verified_keystone_user_not_admin(self):
        self.auth_ref.role_names = ["notadmin"]
        self.assertRaises(exceptions.InvalidAdminException,
                          self.clients.verified_keystone)
github openstack / rally / tests / unit / deploy / serverprovider / providers / test_lxc.py View on Github external
def test_validate_too_small_network(self):
        config = self.config.copy()
        config["containers_per_host"] = 42
        self.assertRaises(exceptions.InvalidConfigException,
                          lxc.LxcProvider, self.deployment, config)
github openstack / rally-openstack / tests / unit / scenarios / nova / test_utils.py View on Github external
self.clients("nova").servers.get(return_value=fake_server)
        nova_scenario = utils.NovaScenario(context=self.context)
        nova_scenario._migrate(fake_server, skip_compute_nodes_check=True,
                               skip_host_check=True)

        self.mock_wait_for_status.mock.assert_called_once_with(
            fake_server,
            ready_statuses=["VERIFY_RESIZE"],
            update_resource=self.mock_get_from_manager.mock.return_value,
            check_interval=CONF.openstack.nova_server_migrate_poll_interval,
            timeout=CONF.openstack.nova_server_migrate_timeout)
        self.mock_get_from_manager.mock.assert_called_once_with()
        self._test_atomic_action_timer(nova_scenario.atomic_actions(),
                                       "nova.migrate")

        self.assertRaises(rally_exceptions.RallyException,
                          nova_scenario._migrate,
                          fake_server, skip_compute_nodes_check=True,
                          skip_host_check=False)
        self.assertRaises(rally_exceptions.RallyException,
                          nova_scenario._migrate,
                          fake_server, skip_compute_nodes_check=False,
                          skip_host_check=True)
github openstack / rally / tests / unit / plugins / openstack / scenarios / cinder / test_volume_types.py View on Github external
def test_create_and_list_volume_types_with_fails(self):
        # Negative case: type isn't listed
        mock_service = self.mock_cinder.return_value
        fake_type = mock.Mock()
        pool_list = [mock.Mock(), mock.Mock(), mock.Mock()]
        description = "rally tests creating types"
        is_public = False

        scenario = volume_types.CreateAndListVolumeTypes(self._get_context())
        mock_service.create_volume_type.return_value = fake_type
        mock_service.list_types.return_value = pool_list
        self.assertRaises(rally_exceptions.RallyAssertionError,
                          scenario.run,
                          description=description, is_public=is_public)

        mock_service.create_volume_type.assert_called_once_with(
            description=description, is_public=is_public)
        mock_service.list_types.assert_called_once_with()
github openstack / rally-openstack / tests / unit / test_validators.py View on Github external
clients = self.context[
            "users"][0]["credential"].clients.return_value
        clients.glance().images.get = mock.Mock()

        result = self.validator.validate(self.context, config, None, None)
        self.assertIsNone(result)

        mock_glance_image.assert_called_once_with(
            context={"admin": {
                "credential": self.context["users"][0]["credential"]}})
        mock_glance_image.return_value.pre_process.assert_called_once_with(
            config["args"]["image"], config={})
        clients.glance().images.get.assert_called_with("image_id")

        exs = [exceptions.InvalidScenarioArgument(),
               glance_exc.HTTPNotFound()]
        for ex in exs:
            clients.glance().images.get.side_effect = ex

            e = self.assertRaises(
                validators.validation.ValidationError,
                self.validator.validate, self.context, config, None, None)

            self.assertEqual("Image 'fake_image' not found", e.message)
github openstack / rally / rally / cli / commands / task.py View on Github external
def _delete_single_task(tid, force):
            try:
                api.task.delete(task_uuid=tid, force=force)
                print("Successfully deleted task `%s`" % tid)
            except exceptions.DBConflict as e:
                print(e)
                print("Use '--force' option to delete the task with vague "
                      "state.")
github openstack / rally / rally / common / objects / task.py View on Github external
def abort(self, soft=False):
        current_status = self.get_status(self.task["uuid"])

        if current_status in self.NOT_IMPLEMENTED_STAGES_FOR_ABORT:
            raise exceptions.RallyException(
                "Failed to abort task '%(uuid)s'. It doesn't implemented "
                "for '%(stages)s' stages. Current task status is '%(status)s'."
                % {"uuid": self.task["uuid"], "status": current_status,
                   "stages": ", ".join(self.NOT_IMPLEMENTED_STAGES_FOR_ABORT)})
        elif current_status in [consts.TaskStatus.FINISHED,
                                consts.TaskStatus.CRASHED,
                                consts.TaskStatus.ABORTED]:
            raise exceptions.RallyException(
                "Failed to abort task '%s', since it already finished."
                % self.task["uuid"])

        new_status = (consts.TaskStatus.SOFT_ABORTING
                      if soft else consts.TaskStatus.ABORTING)
        self.update_status(new_status, allowed_statuses=(
            consts.TaskStatus.RUNNING, consts.TaskStatus.SOFT_ABORTING))
github openstack / rally / rally / deployment / serverprovider / providers / openstack.py View on Github external
def get_image_uuid(self):
        """Get image uuid. Download image if necessary."""

        image_uuid = self.config["image"].get("uuid")
        if image_uuid:
            return image_uuid
        else:
            if not self.glance:
                raise exceptions.InvalidConfigException(
                    "If glance is not available in the service catalog"
                    " obtained by the openstack server provider, then"
                    " images cannot be uploaded so the uuid of an"
                    " existing image must be specified in the"
                    " deployment config."
                )

        for image in self.glance.images.list():
            if image.checksum == self.config["image"]["checksum"]:
                LOG.info(_("Found image with appropriate checksum. Using it."))
                return image.id

        LOG.info(_("Downloading new image %s") % self.config["image"]["url"])
        image = self.glance.images.create(
            name=self.config["image"]["name"],
            copy_from=self.config["image"]["url"],
github openstack / rally / rally / deployment / serverprovider / providers / openstack.py View on Github external
def destroy_servers(self):
        for resource in self.resources.get_all(type=SERVER_TYPE):
            try:
                self.nova.servers.delete(resource["info"]["id"])
            except novaclient.exceptions.NotFound:
                LOG.warning("Nova instance %s not found, so not deleting." %
                            resource["info"]["id"])
            try:
                self.resources.delete(resource.id)
            except exceptions.ResourceNotFound:
                LOG.warning(
                    "Instance resource record not found in DB, not removing."
                    " Deployment: %(deployment)s Instance ID:%(id)s"
                    " Instance Nova UUID:%(uuid)s" %
                    dict(deployment=resource.deployment_uuid,
                         id=resource.id,
                         uuid=resource["info"]["id"]
                         )
                )
        for resource in self.resources.get_all(type=KEYPAIR_TYPE):
            try:
                self.nova.keypairs.delete(resource["info"]["id"])
            except novaclient.exceptions.NotFound:
                LOG.warning("Nova keypair %s not found, so not deleting." %
                            resource["info"]["id"])
            try: