예제 #1
0
파일: api.py 프로젝트: x-ion-de/rally
    def verify(cls, deployment, set_name, regex, tempest_config):
        """Start verifying.

        :param deployment: UUID or name of a deployment.
        :param set_name: Valid name of tempest test set.
        :param regex: Regular expression of test
        :param tempest_config: User specified Tempest config file
        :returns: Verification object
        """

        deployment_uuid = objects.Deployment.get(deployment)["uuid"]

        verification = objects.Verification(deployment_uuid=deployment_uuid)
        verifier = tempest.Tempest(deployment_uuid,
                                   verification=verification,
                                   tempest_config=tempest_config)
        if not verifier.is_installed():
            print("Tempest is not installed for specified deployment.")
            print("Installing Tempest for deployment %s" % deploy)
            verifier.install()
        LOG.info("Starting verification of deployment: %s" % deploy)

        verification.set_running()
        verifier.verify(set_name=set_name, regex=regex)

        return verification
예제 #2
0
    def test_show(self, mock_objects_verification,
                  mock_verification_result_get, mock_verification_get,
                  mock_print_list):

        class Test_dummy():
            data = {"test_cases": {"test_a": {"name": "test_a", "time": 20,
                                              "status": "PASS"},
                                   "test_b": {"name": "test_b", "time": 20,
                                              "status": "SKIP"},
                                   "test_c": {"name": "test_c", "time": 20,
                                              "status": "FAIL"}}}

        verification_id = "39121186-b9a4-421d-b094-6c6b270cf9e9"
        total_fields = ["UUID", "Deployment UUID", "Set name", "Tests",
                        "Failures", "Created at", "Status"]
        fields = ["name", "time", "status"]
        verification = mock.MagicMock()
        tests = Test_dummy()
        mock_verification_result_get.return_value = tests
        mock_verification_get.return_value = verification
        mock_objects_verification.return_value = 1
        values = [objects.Verification(t)
                  for t in six.itervalues(tests.data["test_cases"])]
        self.verify.show(verification_id)
        self.assertEqual([mock.call([verification], fields=total_fields),
                          mock.call(values, fields, sortby_index=0)],
                         mock_print_list.call_args_list)
        mock_verification_get.assert_called_once_with(verification_id)
        mock_verification_result_get.assert_called_once_with(verification_id)
예제 #3
0
    def test_init_without_create(self, mock_create):
        verification = objects.Verification(db_object=self.db_obj)

        self.assertEqual(0, mock_create.call_count)
        self.assertEqual(self.db_obj["failures"], verification.failures)
        self.assertEqual(self.db_obj["tests"], verification.tests)
        self.assertEqual(self.db_obj["errors"], verification.errors)
        self.assertEqual(self.db_obj["time"], verification.time)
예제 #4
0
    def test_finish_verification(self, mock_update, mock_create):
        verification = objects.Verification(db_object=self.db_obj)
        fake_results = fakes.get_fake_test_case()
        verification.finish_verification(fake_results["total"],
                                         fake_results["test_cases"])

        expected_values = {"status": "finished"}
        expected_values.update(fake_results["total"])
        mock_update.assert_called_with(self.db_obj["uuid"], expected_values)

        expected_data = fake_results["total"].copy()
        expected_data["test_cases"] = fake_results["test_cases"]
        mock_create.assert_called_once_with(verification.uuid, expected_data)
예제 #5
0
    def test_finish_verification(self, mock_update, mock_create):
        verification = objects.Verification(db_object=self.db_obj)
        fake_results = fakes.get_fake_test_case()
        verification.finish_verification(fake_results['total'],
                                         fake_results['test_cases'])

        expected_values = {'status': 'finished'}
        expected_values.update(fake_results['total'])
        mock_update.assert_called_with(self.db_obj['uuid'], expected_values)

        expected_data = fake_results['total'].copy()
        expected_data['test_cases'] = fake_results['test_cases']
        mock_create.assert_called_once_with(verification.uuid, expected_data)
예제 #6
0
    def show(self, verification_uuid=None, sort_by="name", detailed=False):
        """Display results table of the verification."""

        try:
            sortby_index = ("name", "duration").index(sort_by)
        except ValueError:
            print("Sorry, but verification results can't be sorted "
                  "by '%s'." % sort_by)
            return 1

        try:
            verification = db.verification_get(verification_uuid)
            tests = db.verification_result_get(verification_uuid)
        except exceptions.NotFoundException as e:
            print(six.text_type(e))
            return 1

        print("Total results of verification:\n")
        total_fields = [
            "UUID", "Deployment UUID", "Set name", "Tests", "Failures",
            "Created at", "Status"
        ]
        cliutils.print_list([verification], fields=total_fields)

        print("\nTests:\n")
        fields = ["name", "time", "status"]

        values = [
            objects.Verification(test)
            for test in six.itervalues(tests.data["test_cases"])
        ]
        cliutils.print_list(values, fields, sortby_index=sortby_index)

        if detailed:
            for test in six.itervalues(tests.data["test_cases"]):
                if test["status"] == "FAIL":
                    header = cliutils.make_header(
                        "FAIL: %(name)s\n"
                        "Time: %(time)s\n"
                        "Type: %(type)s" % {
                            "name": test["name"],
                            "time": test["time"],
                            "type": test["failure"]["type"]
                        })
                    formatted_test = "%(header)s%(log)s\n" % {
                        "header": header,
                        "log": test["failure"]["log"]
                    }
                    print(formatted_test)
예제 #7
0
def verify(deploy_id, set_name, regex):
    """Start verifying.

    :param deploy_id: a UUID of a deployment.
    :param set_name: Valid name of tempest test set.
    :param regex: Regular expression of test
    """

    verification = objects.Verification(deployment_uuid=deploy_id)
    verifier = tempest.Tempest(deploy_id, verification=verification)
    if not verifier.is_installed():
        print("Tempest is not installed for specified deployment.")
        print("Installing Tempest for deployment %s" % deploy_id)
        verifier.install()
    LOG.info("Starting verification of deployment: %s" % deploy_id)

    verification.set_running()
    verifier.verify(set_name=set_name, regex=regex)
예제 #8
0
 def test_set_failed(self, mock_update):
     mock_update.return_value = self.db_obj
     verification = objects.Verification(db_object=self.db_obj)
     verification.set_failed()
     mock_update.assert_called_once_with(self.db_obj["uuid"],
                                         {"status": "failed"})
예제 #9
0
 def test_create_and_delete(self, mock_create, mock_delete):
     verification = objects.Verification(db_object=self.db_obj)
     verification.delete()
     mock_delete.assert_called_once_with(self.db_obj["uuid"])
예제 #10
0
 def test_init_with_create(self, mock_create):
     objects.Verification(deployment_uuid="some_deployment_uuid")
     mock_create.assert_called_once_with("some_deployment_uuid")
예제 #11
0
 def test_set_failed(self, mock_update):
     mock_update.return_value = self.db_obj
     verification = objects.Verification(db_object=self.db_obj)
     verification.set_failed()
     mock_update.assert_called_once_with(self.db_obj['uuid'],
                                         {'status': 'failed'})