Esempio n. 1
0
def start_task(deploy_uuid, config, task=None):
    """Start a task.

    Task is a list of benchmarks that will be called one by one, results of
    execution will be stored in DB.

    :param deploy_uuid: UUID of the deployment
    :param config: a dict with a task configuration
    """
    deployment = objects.Deployment.get(deploy_uuid)
    task = task or objects.Task(deployment_uuid=deploy_uuid)
    LOG.info("Benchmark Task %s on Deployment %s" %
             (task['uuid'], deployment['uuid']))
    benchmark_engine = engine.BenchmarkEngine(config, task)
    endpoint = deployment['endpoints']

    try:
        benchmark_engine.bind(endpoint)
        benchmark_engine.validate()
        benchmark_engine.run()
    except exceptions.InvalidTaskException:
        # NOTE(boris-42): We don't log anything, because it's normal situation
        #                 that user put wrong config.
        pass
    except Exception:
        deployment.update_status(consts.DeployStatus.DEPLOY_INCONSISTENT)
        raise
Esempio n. 2
0
 def test_create_and_delete_status(self, mock_task_create,
                                   mock_task_delete):
     mock_task_create.return_value = self.task
     task = objects.Task()
     task.delete(status=consts.TaskStatus.FINISHED)
     mock_task_delete.assert_called_once_with(
         self.task["uuid"], status=consts.TaskStatus.FINISHED)
Esempio n. 3
0
    def start(cls, deployment, config, task=None, abort_on_sla_failure=False):
        """Start a task.

        Task is a list of benchmarks that will be called one by one, results of
        execution will be stored in DB.

        :param deployment: UUID or name of the deployment
        :param config: a dict with a task configuration
        :param task: Task object. If None, it will be created
        :param abort_on_sla_failure: if True, the execution of a benchmark
                                     scenario will stop when any SLA check
                                     for it fails
        """
        deployment = objects.Deployment.get(deployment)
        task = task or objects.Task(deployment_uuid=deployment["uuid"])
        LOG.info("Benchmark Task %s on Deployment %s" %
                 (task["uuid"], deployment["uuid"]))
        benchmark_engine = engine.BenchmarkEngine(
            config,
            task,
            admin=deployment["admin"],
            users=deployment["users"],
            abort_on_sla_failure=abort_on_sla_failure)

        try:
            benchmark_engine.validate()
            benchmark_engine.run()
        except exceptions.InvalidTaskException:
            # NOTE(boris-42): We don't log anything, because it's a normal
            #                 situation when a user puts a wrong config.
            pass
        except Exception:
            deployment.update_status(consts.DeployStatus.DEPLOY_INCONSISTENT)
            raise
Esempio n. 4
0
 def test_update(self, mock_create, mock_update):
     mock_create.return_value = self.task
     mock_update.return_value = {'opt': 'val2'}
     deploy = objects.Task(opt='val1')
     deploy._update({'opt': 'val2'})
     mock_update.assert_called_once_with(self.task['uuid'], {'opt': 'val2'})
     self.assertEqual(deploy['opt'], 'val2')
Esempio n. 5
0
 def test_update_verification_log(self, mock_update):
     mock_update.return_value = self.task
     task = objects.Task(task=self.task)
     task.update_verification_log({"a": "fake"})
     mock_update.assert_called_once_with(
         self.task['uuid'],
         {'verification_log': json.dumps({"a": "fake"})}
     )
Esempio n. 6
0
 def test_update_status(self, mock_update):
     mock_update.return_value = self.task
     task = objects.Task(task=self.task)
     task.update_status(consts.TaskStatus.FINISHED)
     mock_update.assert_called_once_with(
         self.task['uuid'],
         {'status': consts.TaskStatus.FINISHED},
     )
Esempio n. 7
0
 def test_update(self, mock_task_create, mock_task_update):
     mock_task_create.return_value = self.task
     mock_task_update.return_value = {"opt": "val2"}
     deploy = objects.Task(opt="val1")
     deploy._update({"opt": "val2"})
     mock_task_update.assert_called_once_with(self.task["uuid"],
                                              {"opt": "val2"})
     self.assertEqual(deploy["opt"], "val2")
Esempio n. 8
0
 def test_set_failed(self, mock_update):
     mock_update.return_value = self.task
     task = objects.Task(task=self.task)
     task.set_failed()
     mock_update.assert_called_once_with(
         self.task['uuid'],
         {'failed': True, 'status': 'failed', 'verification_log': '""'},
     )
Esempio n. 9
0
def create_task(deploy_uuid, tag):
    """Create a task without starting it.

    Task is a list of benchmarks that will be called one by one, results of
    execution will be stored in DB.

    :param deploy_uuid: UUID of the deployment
    :param tag: tag for this task
    """
    return objects.Task(deployment_uuid=deploy_uuid, tag=tag)
Esempio n. 10
0
 def test_set_failed(self, mock_task_update):
     mock_task_update.return_value = self.task
     task = objects.Task(task=self.task)
     task.set_failed()
     mock_task_update.assert_called_once_with(
         self.task["uuid"],
         {
             "status": consts.TaskStatus.FAILED,
             "verification_log": "\"\""
         },
     )
Esempio n. 11
0
def task_validate(deploy_uuid, config):
    """Validate a task config against specified deployment.

    :param deploy_uuid: UUID of the deployment
    :param config: a dict with a task configuration
    """
    deployment = objects.Deployment.get(deploy_uuid)
    task = objects.Task(deployment_uuid=deploy_uuid)
    benchmark_engine = engine.BenchmarkEngine(config, task)
    benchmark_engine.bind(admin=deployment["admin"], users=deployment["users"])
    benchmark_engine.validate()
Esempio n. 12
0
    def validate(cls, deployment, config):
        """Validate a task config against specified deployment.

        :param deployment: UUID or name of the deployment
        :param config: a dict with a task configuration
        """
        deployment = objects.Deployment.get(deployment)
        task = objects.Task(deployment_uuid=deployment["uuid"], fake=True)
        benchmark_engine = engine.BenchmarkEngine(config,
                                                  task,
                                                  admin=deployment["admin"],
                                                  users=deployment["users"])
        benchmark_engine.validate()
Esempio n. 13
0
    def create(cls, deployment, tag):
        """Create a task without starting it.

        Task is a list of benchmarks that will be called one by one, results of
        execution will be stored in DB.

        :param deployment: UUID or name of the deployment
        :param tag: tag for this task
        :returns: Task object
        """

        deployment_uuid = objects.Deployment.get(deployment)["uuid"]
        return objects.Task(deployment_uuid=deployment_uuid, tag=tag)
Esempio n. 14
0
    def test_tempest_tests_exists(self, mock_create, mock_tempest):
        mock_create.return_value = {
            'status': 'init',
            'deployment_uuid': 'deployment-uuid',
            'verification_log': '',
            'uuid': 'task-uuid',
            'created_at': '',
            'failed': False,
            'tag': '',
            'id': 42
        }
        mock_tempest().is_installed.return_value = False
        mock_tempest().is_configured.return_value = False
        mock_tempest().discover_tests.return_value = set(
            ["tempest.api.a", "tempest.api.b", "tempest.api.c"])
        task = objects.Task(deployment_uuid='deployment-uuid')
        validator = self._unwrap_validator(validation.tempest_tests_exists)

        result = validator({"args": {"test_name": "a"}}, None, task)
        self.assertTrue(result.is_valid, result.msg)
        mock_tempest().is_installed.assert_called_once_with()
        mock_tempest().is_configured.assert_called_once_with()
        mock_tempest().discover_tests.assert_called_once_with()

        result = validator({"args": {"test_name": "d"}}, None, task)
        self.assertFalse(result.is_valid, result.msg)

        result = validator({"args": {
            "test_name": "tempest.api.a"
        }}, None, task)
        self.assertTrue(result.is_valid, result.msg)
        result = validator({"args": {
            "test_name": "tempest.api.d"
        }}, None, task)
        self.assertFalse(result.is_valid, result.msg)

        result = validator({"args": {
            "test_names": ["tempest.api.a", "b"]
        }}, None, task)
        self.assertTrue(result.is_valid, result.msg)

        result = validator({"args": {
            "test_names": ["tempest.api.j", "e"]
        }}, None, task)
        self.assertFalse(result.is_valid, result.msg)
Esempio n. 15
0
 def test_init_with_fake_true(self, mock_task_create, mock_uuid4):
     task = objects.Task(fake=True)
     self.assertFalse(mock_task_create.called)
     self.assertTrue(mock_uuid4.called)
     self.assertEqual(task["uuid"], mock_uuid4.return_value)
Esempio n. 16
0
 def test_append_results(self, mock_task_result_create):
     task = objects.Task(task=self.task)
     task.append_results("opt", "val")
     mock_task_result_create.assert_called_once_with(
         self.task["uuid"], "opt", "val")
Esempio n. 17
0
 def test_get_results(self, mock_task_result_get_all_by_uuid):
     task = objects.Task(task=self.task)
     results = task.get_results()
     mock_task_result_get_all_by_uuid.assert_called_once_with(
         self.task["uuid"])
     self.assertEqual(results, "foo_results")
Esempio n. 18
0
 def test_init_with_create(self, mock_task_create):
     mock_task_create.return_value = self.task
     task = objects.Task(status=consts.TaskStatus.FAILED)
     mock_task_create.assert_called_once_with(
         {"status": consts.TaskStatus.FAILED})
     self.assertEqual(task["uuid"], self.task["uuid"])
Esempio n. 19
0
 def test_append_results(self, mock_append_results):
     task = objects.Task(task=self.task)
     task.append_results('opt', 'val')
     mock_append_results.assert_called_once_with(self.task['uuid'], 'opt',
                                                 'val')
Esempio n. 20
0
 def test_create_and_delete(self, mock_create, mock_delete):
     mock_create.return_value = self.task
     task = objects.Task()
     task.delete()
     mock_delete.assert_called_once_with(self.task['uuid'], status=None)
Esempio n. 21
0
 def test_init_without_create(self, mock_create):
     task = objects.Task(task=self.task)
     self.assertFalse(mock_create.called)
     self.assertEqual(task['uuid'], self.task['uuid'])
Esempio n. 22
0
 def test_init_with_create(self, mock_create):
     mock_create.return_value = self.task
     task = objects.Task(failed=True)
     mock_create.assert_called_once_with({'failed': True})
     self.assertEqual(task['uuid'], self.task['uuid'])