def on_post(self, request, response):
        """Register a new provider.

        :param request: Falcon request object.
        :type request: :obj:`falcon.request`
        :param response: Falcon response object.
        :type response: :obj:`falcon.response`
        """
        self.request = request
        if not any([
                self.iut_provider, self.log_area_provider,
                self.execution_space_provider
        ]):
            raise falcon.HTTPBadRequest(
                "Missing parameters",
                "At least one of 'iut_provider', 'log_area_provider' "
                "& 'execution_space_provider' is a required parameter.",
            )
        etos = ETOS("ETOS Environment Provider", os.getenv("HOSTNAME"),
                    "Environment Provider")
        jsontas = JsonTas()
        registry = ProviderRegistry(etos, jsontas)
        if self.iut_provider:
            registry.register_iut_provider(self.iut_provider)
        if self.execution_space_provider:
            registry.register_execution_space_provider(
                self.execution_space_provider)
        if self.log_area_provider:
            registry.register_log_area_provider(self.log_area_provider)
        response.status = falcon.HTTP_204
Beispiel #2
0
    def on_post(self, request, response):
        """Register a new provider.

        :param request: Falcon request object.
        :type request: :obj:`falcon.request`
        :param response: Falcon response object.
        :type response: :obj:`falcon.response`
        """
        etos = ETOS("ETOS Environment Provider", os.getenv("HOSTNAME"),
                    "Environment Provider")
        jsontas = JsonTas()
        registry = ProviderRegistry(etos, jsontas, self.database())
        registered = register(
            registry,
            iut_provider=get_iut_provider(request),
            log_area_provider=get_log_area_provider(request),
            execution_space_provider=get_execution_space_provider(request),
        )
        if registered is False:
            raise falcon.HTTPBadRequest(
                "Missing parameters",
                "At least one of 'iut_provider', 'log_area_provider' "
                "& 'execution_space_provider' is a required parameter.",
            )
        response.status = falcon.HTTP_204
Beispiel #3
0
    def release(self, response, task_id):  # pylint:disable=too-many-locals
        """Release an environment.

        :param response: Response object to edit and return.
        :type response: :obj:`falcon.response`
        :param task_id: Task to release.
        :type task_id: str
        """
        etos = ETOS(
            "ETOS Environment Provider",
            os.getenv("HOSTNAME"),
            "Environment Provider",
        )
        jsontas = JsonTas()
        registry = ProviderRegistry(etos, jsontas, self.database())
        task_result = self.celery_worker.AsyncResult(task_id)
        success, message = release_environment(etos, jsontas, registry,
                                               task_result, task_id)
        if not success:
            response.media = {
                "error": "Failed to release environment",
                "details": message,
                "status": task_result.status if task_result else "PENDING",
            }
            return
        response.status = falcon.HTTP_200
        response.media = {
            "status": task_result.status if task_result else "PENDING"
        }
Beispiel #4
0
    def on_post(self, request, response):
        """Verify that all parameters are available and configure the provider registry.

        :param request: Falcon request object.
        :type request: :obj:`falcon.request`
        :param response: Falcon response object.
        :type response: :obj:`falcon.response`
        """
        etos = ETOS("ETOS Environment Provider", os.getenv("HOSTNAME"),
                    "Environment Provider")
        jsontas = JsonTas()
        registry = ProviderRegistry(etos, jsontas, self.database())
        suite_id = get_suite_id(request)
        FORMAT_CONFIG.identifier = suite_id

        success, message = configure(
            registry,
            get_iut_provider_id(request),
            get_execution_space_provider_id(request),
            get_log_area_provider_id(request),
            get_dataset(request),
            get_suite_id(request),
        )
        if not success:
            self.logger.error(message)
            raise falcon.HTTPBadRequest("Bad request", message)
        response.status = falcon.HTTP_200
Beispiel #5
0
    def test_get_configuration_missing(self):
        """Test that if a configuration is missing, a partial result is returned.

        Approval criteria:
            - The configure backend shall return a partial configuration if configuration
              is missing.

        Test steps:
            1. Store a faulty configuration into the database.
            2. Verify that it is possible to get the partial configuration.
        """
        database = FakeDatabase()
        test_suite_id = "ca51601e-6c9a-4b5d-8038-7dc2561283d2"
        test_dataset = {"dataset": "test"}
        self.logger.info(
            "STEP: Store a faulty configuration into the database.")
        database.writer.hset(f"EnvironmentProvider:{test_suite_id}", "Dataset",
                             json.dumps(test_dataset))

        self.logger.info(
            "STEP: Verify that it is possible to get the partial configuration."
        )
        registry = ProviderRegistry(ETOS("", "", ""), JsonTas(), database)
        stored_configuration = get_configuration(registry, test_suite_id)
        self.assertDictEqual(
            stored_configuration,
            {
                "dataset": test_dataset,
                "iut_provider": None,
                "execution_space_provider": None,
                "log_area_provider": None,
            },
        )
    def test_register_log_area_provider(self):
        """Test that the register backend can register log area providers.

        Approval criteria:
            - The register backend shall be able to register a log area provider.

        Test steps:
            1. Register a log area provider with the register backend.
            2. Verify that the log area provider was stored in the database.
        """
        fake_database = FakeDatabase()
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        jsontas = JsonTas()
        provider = {
            "log": {
                "id": "log_area_provider_test",
                "list": {"available": [], "possible": []},
            }
        }
        provider_registry = ProviderRegistry(etos, jsontas, fake_database)
        self.logger.info(
            "STEP: Register a log area provider with the register backend."
        )
        response = register(provider_registry, log_area_provider=provider)

        self.logger.info(
            "STEP: Verify that the log area provider was stored in the database."
        )
        stored_provider = json.loads(
            fake_database.reader.hget(
                "EnvironmentProvider:LogAreaProviders", "log_area_provider_test"
            )
        )
        self.assertDictEqual(stored_provider, provider)
        self.assertTrue(response)
    def test_release_environment_no_task_result(self):
        """Test that it is not possible to release an environment without task results.

        Approval criteria:
            - The environment provider shall not attempt to release environments with results.

        Test steps:
            1. Attempt to release an environment without a task ID.
            2. Verify that the release fails.
        """
        database = FakeDatabase()
        test_release_id = "ce63f53e-1797-42bb-ae72-861a0b6b7ef6"
        worker = FakeCelery("thisdoesnotexist", "SUCCESS", {})
        jsontas = JsonTas()
        etos = ETOS("", "", "")
        registry = ProviderRegistry(etos, jsontas, database)
        self.logger.info(
            "STEP: Attempt to release an environment without a task ID.")
        success, _ = release_environment(
            etos,
            jsontas,
            registry,
            worker.AsyncResult(test_release_id),
            test_release_id,
        )

        self.logger.info("STEP: Verify that the release fails.")
        self.assertFalse(success)
    def on_post(self, request, response):
        """Verify that all parameters are available and configure the provider registry.

        :param request: Falcon request object.
        :type request: :obj:`falcon.request`
        :param response: Falcon response object.
        :type response: :obj:`falcon.response`
        """
        self.request = request
        etos = ETOS("ETOS Environment Provider", os.getenv("HOSTNAME"),
                    "Environment Provider")
        jsontas = JsonTas()
        self.registry = ProviderRegistry(etos, jsontas)
        try:
            assert self.suite_id is not None, "Invalid suite ID"
            FORMAT_CONFIG.identifier = self.suite_id
            iut_provider = self.iut_provider
            log_area_provider = self.log_area_provider
            execution_space_provider = self.execution_space_provider
            assert (
                iut_provider is not None
            ), f"No such IUT provider {self.request.media.get('iut_provider')}"
            assert execution_space_provider is not None, (
                "No such execution space provider"
                f"{self.request.media.get('execution_space_provider')}")
            assert (
                log_area_provider is not None
            ), f"No such log area provider {self.request.media.get('log_area_provider')}"
            assert self.dataset is not None, "Invalid dataset."
            response.media = {
                "IUTProvider": iut_provider,
                "ExecutionSpaceProvider": execution_space_provider,
                "LogAreaProvider": log_area_provider,
            }
            self.registry.configure_environment_provider_for_suite(
                self.suite_id,
                iut_provider,
                log_area_provider,
                execution_space_provider,
                self.dataset,
            )
        except AssertionError as exception:
            raise falcon.HTTPBadRequest("Invalid provider", str(exception))
    def on_get(request, response):
        """Get an already configured environment based on suite ID.

        Use only to verify that the environment has been configured properly.

        :param request: Falcon request object.
        :type request: :obj:`falcon.request`
        :param response: Falcon response object.
        :type response: :obj:`falcon.response`
        """
        suite_id = request.get_param("suite_id")
        FORMAT_CONFIG.identifier = suite_id
        etos = ETOS("ETOS Environment Provider", os.getenv("HOSTNAME"),
                    "Environment Provider")
        jsontas = JsonTas()
        registry = ProviderRegistry(etos, jsontas)
        if suite_id is None:
            raise falcon.HTTPBadRequest("Missing parameters",
                                        "'suite_id' is a required parameter.")
        response.status = falcon.HTTP_200
        iut_provider = registry.iut_provider(suite_id)
        log_area_provider = registry.log_area_provider(suite_id)
        execution_space_provider = registry.execution_space_provider(suite_id)
        response.media = {
            "iut_provider":
            iut_provider.ruleset if iut_provider else None,
            "log_area_provider":
            log_area_provider.ruleset if log_area_provider else None,
            "execution_space_provider":
            execution_space_provider.ruleset
            if execution_space_provider else None,
            "dataset":
            registry.dataset(suite_id),
        }
    def test_register_provider_none(self):
        """Test that the register backend return false if no provider is supplied.

        Approval criteria:
            - The register backend shall return False if no provider is supplied.

        Test steps:
            1. Register no provider with the register backend.
            2. Verify that the register backend return False.
        """
        fake_database = FakeDatabase()
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        jsontas = JsonTas()
        provider_registry = ProviderRegistry(etos, jsontas, fake_database)

        self.logger.info("STEP: Register no provider with the register backend.")
        response = register(provider_registry)

        self.logger.info("STEP: Verify that the register backend return False.")
        self.assertFalse(response)
Beispiel #11
0
    def on_get(self, request, response):
        """Get an already configured environment based on suite ID.

        Use only to verify that the environment has been configured properly.

        :param request: Falcon request object.
        :type request: :obj:`falcon.request`
        :param response: Falcon response object.
        :type response: :obj:`falcon.response`
        """
        etos = ETOS("ETOS Environment Provider", os.getenv("HOSTNAME"),
                    "Environment Provider")
        jsontas = JsonTas()
        registry = ProviderRegistry(etos, jsontas, self.database())

        suite_id = get_suite_id(request)
        if suite_id is None:
            raise falcon.HTTPBadRequest("Missing parameters",
                                        "'suite_id' is a required parameter.")
        FORMAT_CONFIG.identifier = suite_id
        response.status = falcon.HTTP_200
        response.media = get_configuration(registry, suite_id)
Beispiel #12
0
    def test_configure_missing_parameter(self):
        """Test that the configure backend does not configure if any parameter is missing.

        Approval criteria:
            - The configure backend shall return False and not configure if any parameter
              is missing.

        Test steps:
            1. Attempt to configure the environment provider without any parameters.
            2. Verify that False was returned and no configuration was made.
        """
        database = FakeDatabase()
        self.logger.info(
            "STEP: Attempt to configure the environment provider without any parameters."
        )
        registry = ProviderRegistry(ETOS("", "", ""), JsonTas(), database)
        success, _ = configure(registry, None, None, None, None, None)

        self.logger.info(
            "STEP: Verify that False was returned and no configuration was made."
        )
        self.assertFalse(success)
        self.assertDictEqual(database.db_dict, {})
    def test_register_execution_space_provider(self):
        """Test that the register backend can register execution space providers.

        Approval criteria:
            - The register backend shall be able to register an execution space provider.

        Test steps:
            1. Register an execution space provider with the register backend.
            2. Verify that the execution space provider was stored in the database.
        """
        fake_database = FakeDatabase()
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        jsontas = JsonTas()
        provider = {
            "execution_space": {
                "id": "execution_space_provider_test",
                "list": {"available": [{"identifier": "123"}], "possible": []},
            }
        }
        provider_registry = ProviderRegistry(etos, jsontas, fake_database)
        self.logger.info(
            "STEP: Register an execution space provider with the register backend."
        )
        response = register(provider_registry, execution_space_provider=provider)

        self.logger.info(
            "STEP: Verify that the execution space provider was stored in the database."
        )
        stored_provider = json.loads(
            fake_database.reader.hget(
                "EnvironmentProvider:ExecutionSpaceProviders",
                "execution_space_provider_test",
            )
        )
        self.assertDictEqual(stored_provider, provider)
        self.assertTrue(response)
    def test_register_all_providers(self):
        """Test that the register backend can register all providers.

        Approval criteria:
            - The register backend shall be able to register all providers.

        Test steps:
            1. Register one of each provider with the register backend.
            2. Verify that the providers were stored in the database.
        """
        fake_database = FakeDatabase()
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        jsontas = JsonTas()
        test_iut_provider = {
            "iut": {
                "id": "iut_provider_test",
                "list": {"available": [], "possible": []},
            }
        }
        test_execution_space_provider = {
            "execution_space": {
                "id": "execution_space_provider_test",
                "list": {"available": [{"identifier": "123"}], "possible": []},
            }
        }
        test_log_area_provider = {
            "log": {
                "id": "log_area_provider_test",
                "list": {"available": [], "possible": []},
            }
        }
        provider_registry = ProviderRegistry(etos, jsontas, fake_database)
        self.logger.info(
            "STEP: Register one of each provider with the register backend."
        )
        response = register(
            provider_registry,
            iut_provider=test_iut_provider,
            log_area_provider=test_log_area_provider,
            execution_space_provider=test_execution_space_provider,
        )

        self.logger.info("STEP: Verify that the providers were stored in the database.")
        stored_execution_space_provider = json.loads(
            fake_database.reader.hget(
                "EnvironmentProvider:ExecutionSpaceProviders",
                "execution_space_provider_test",
            )
        )
        self.assertDictEqual(
            stored_execution_space_provider,
            test_execution_space_provider,
        )
        stored_log_area_provider = json.loads(
            fake_database.reader.hget(
                "EnvironmentProvider:LogAreaProviders", "log_area_provider_test"
            )
        )
        self.assertDictEqual(stored_log_area_provider, test_log_area_provider)
        stored_iut_provider = json.loads(
            fake_database.reader.hget(
                "EnvironmentProvider:IUTProviders", "iut_provider_test"
            )
        )
        self.assertDictEqual(stored_iut_provider, test_iut_provider)
        self.assertTrue(response)
Beispiel #15
0
    def test_get_configuration(self):
        """Test that it is possible to get a stored configuration.

        Approval criteria:
            - It shall be possible to get a stored configuration.

        Test steps:
            1. Store a configuration into the database.
            2. Verify that it is possible to get the stored configuration.
        """
        database = FakeDatabase()
        test_suite_id = "8d9344e3-a246-43ec-92b4-fc81ea31067a"
        test_dataset = {"dataset": "test"}
        test_iut_provider = OrderedDict({
            "iut": {
                "id": "iut_provider_test",
                "list": {
                    "available": [],
                    "possible": []
                },
            }
        })
        test_execution_space_provider = OrderedDict({
            "execution_space": {
                "id": "execution_space_provider_test",
                "list": {
                    "available": [{
                        "identifier": "123"
                    }],
                    "possible": []
                },
            }
        })
        test_log_area_provider = OrderedDict({
            "log": {
                "id": "log_area_provider_test",
                "list": {
                    "available": [],
                    "possible": []
                },
            }
        })
        self.logger.info("STEP: Store a configuration into the database.")
        database.writer.hset(f"EnvironmentProvider:{test_suite_id}", "Dataset",
                             json.dumps(test_dataset))
        database.writer.hset(
            f"EnvironmentProvider:{test_suite_id}",
            "IUTProvider",
            json.dumps(test_iut_provider),
        )
        database.writer.hset(
            f"EnvironmentProvider:{test_suite_id}",
            "ExecutionSpaceProvider",
            json.dumps(test_execution_space_provider),
        )
        database.writer.hset(
            f"EnvironmentProvider:{test_suite_id}",
            "LogAreaProvider",
            json.dumps(test_log_area_provider),
        )

        self.logger.info(
            "STEP: Verify that it is possible to get the stored configuration."
        )
        registry = ProviderRegistry(ETOS("", "", ""), JsonTas(), database)
        stored_configuration = get_configuration(registry, test_suite_id)
        self.assertDictEqual(
            stored_configuration,
            {
                "iut_provider":
                test_iut_provider["iut"],
                "execution_space_provider":
                test_execution_space_provider["execution_space"],
                "log_area_provider":
                test_log_area_provider["log"],
                "dataset":
                test_dataset,
            },
        )
Beispiel #16
0
    def test_configure_empty_dataset(self):
        """Test that it is possible to configure the environment provider if dataset is empty.

        Approval criteria:
            - It shall be possible to configure using an empty dataset.

        Test steps:
            1. Add providers into the database.
            2. Attempt to configure the environment provider with an empty dataset.
            3. Verify that the configuration was stored in the database.
        """
        database = FakeDatabase()
        test_iut_provider = {
            "iut": {
                "id": "iut_provider_test",
                "list": {
                    "available": [],
                    "possible": []
                },
            }
        }
        test_execution_space_provider = {
            "execution_space": {
                "id": "execution_space_provider_test",
                "list": {
                    "available": [{
                        "identifier": "123"
                    }],
                    "possible": []
                },
            }
        }
        test_log_area_provider = {
            "log": {
                "id": "log_area_provider_test",
                "list": {
                    "available": [],
                    "possible": []
                },
            }
        }
        self.logger.info("STEP: Add providers into the database.")
        database.writer.hset(
            "EnvironmentProvider:ExecutionSpaceProviders",
            test_execution_space_provider["execution_space"]["id"],
            json.dumps(test_execution_space_provider),
        )
        database.writer.hset(
            "EnvironmentProvider:IUTProviders",
            test_iut_provider["iut"]["id"],
            json.dumps(test_iut_provider),
        )
        database.writer.hset(
            "EnvironmentProvider:LogAreaProviders",
            test_log_area_provider["log"]["id"],
            json.dumps(test_log_area_provider),
        )

        test_suite_id = "740d1e2a-2309-4c53-beda-569da70c315c"
        test_dataset = {}
        registry = ProviderRegistry(ETOS("", "", ""), JsonTas(), database)
        self.logger.info(
            "STEP: Attempt to configure the environment provider with an empty dataset."
        )
        success, _ = configure(
            registry,
            test_iut_provider["iut"]["id"],
            test_execution_space_provider["execution_space"]["id"],
            test_log_area_provider["log"]["id"],
            test_dataset,
            test_suite_id,
        )

        self.logger.info(
            "STEP: Verify that the configuration was stored in the database.")
        self.assertTrue(success)
        stored_iut_provider = json.loads(
            database.reader.hget(f"EnvironmentProvider:{test_suite_id}",
                                 "IUTProvider"))
        self.assertDictEqual(stored_iut_provider, test_iut_provider)
        stored_execution_space_provider = json.loads(
            database.reader.hget(f"EnvironmentProvider:{test_suite_id}",
                                 "ExecutionSpaceProvider"))
        self.assertDictEqual(stored_execution_space_provider,
                             test_execution_space_provider)
        stored_log_area_provider = json.loads(
            database.reader.hget(f"EnvironmentProvider:{test_suite_id}",
                                 "LogAreaProvider"))
        self.assertDictEqual(stored_log_area_provider, test_log_area_provider)
        stored_dataset = json.loads(
            database.reader.hget(f"EnvironmentProvider:{test_suite_id}",
                                 "Dataset"))
        self.assertDictEqual(stored_dataset, test_dataset)
    def release(response, task_id):
        """Release an environment.

        :param response: Response object to edit and return.
        :type response: :obj:`falcon.response`
        :param task_id: Task to release.
        :type task_id: str
        """
        try:
            task_result = APP.AsyncResult(task_id)
            result = {
                "status": task_result.status,
            }
            response.status = falcon.HTTP_200
            if task_result.result:
                etos = ETOS(
                    "ETOS Environment Provider",
                    os.getenv("HOSTNAME"),
                    "Environment Provider",
                )
                jsontas = JsonTas()
                registry = ProviderRegistry(etos, jsontas)
                failure = None
                for suite in task_result.result.get("suites", []):
                    try:
                        iut = suite.get("iut")
                        ruleset = registry.get_iut_provider_by_id(
                            iut.get("provider_id"))
                        provider = IutProvider(etos, jsontas, ruleset["iut"])
                        provider.checkin(Iut(**iut))
                    except Exception as exception:  # pylint:disable=broad-except
                        failure = exception

                    try:
                        executor = suite.get("executor")
                        ruleset = registry.get_execution_space_provider_by_id(
                            executor.get("provider_id"))
                        provider = ExecutionSpaceProvider(
                            etos, jsontas, ruleset["execution_space"])
                        provider.checkin(ExecutionSpace(**executor))
                    except Exception as exception:  # pylint:disable=broad-except
                        failure = exception

                    try:
                        log_area = suite.get("log_area")
                        ruleset = registry.get_log_area_provider_by_id(
                            log_area.get("provider_id"))
                        provider = LogAreaProvider(etos, jsontas,
                                                   ruleset["log"])
                        provider.checkin(LogArea(**log_area))
                    except Exception as exception:  # pylint:disable=broad-except
                        failure = exception
                task_result.forget()
                if failure:
                    raise failure
                response.media = {**result}
            else:
                response.media = {
                    "warning": f"Nothing to release with task_id '{task_id}'",
                    **result,
                }
        except Exception as exception:  # pylint:disable=broad-except
            traceback.print_exc()
            response.media = {
                "error": str(exception),
                "details": traceback.format_exc(),
                **result,
            }
class Configure:
    """Configure endpoint for environment provider. Configure an environment for checkout.

    This endpoint should be called before attempting to checkout an environment so that
    the environment provider is configured to handle it.
    """

    request = None
    registry = None

    @property
    def suite_id(self):
        """Suite ID from media parameters."""
        suite_id = self.request.media.get("suite_id")
        if suite_id is None:
            raise falcon.HTTPBadRequest("Missing parameters",
                                        "'suite_id' is a required parameter.")
        return suite_id

    @property
    def iut_provider(self):
        """Get IUT provider from media parameters."""
        iut_provider = self.request.media.get("iut_provider")
        if iut_provider is None:
            raise falcon.HTTPBadRequest(
                "Missing parameters",
                "'iut_provider' is a required parameter.")
        return self.registry.get_iut_provider_by_id(iut_provider)

    @property
    def execution_space_provider(self):
        """Get execution space provider from media parameters."""
        execution_space_provider = self.request.media.get(
            "execution_space_provider")
        if execution_space_provider is None:
            raise falcon.HTTPBadRequest(
                "Missing parameters",
                "'execution_space_provider' is a required parameter.",
            )
        return self.registry.get_execution_space_provider_by_id(
            execution_space_provider)

    @property
    def log_area_provider(self):
        """Get log area provider from media parameters."""
        log_area_provider = self.request.media.get("log_area_provider")
        if log_area_provider is None:
            raise falcon.HTTPBadRequest(
                "Missing parameters",
                "'log_area_provider' is a required parameter.")
        return self.registry.get_log_area_provider_by_id(log_area_provider)

    @property
    def dataset(self):
        """Get dataset from media parameters."""
        dataset = self.request.media.get("dataset")
        if dataset is None:
            raise falcon.HTTPBadRequest("Missing parameters",
                                        "'dataset' is a required parameter.")
        return dataset

    def on_post(self, request, response):
        """Verify that all parameters are available and configure the provider registry.

        :param request: Falcon request object.
        :type request: :obj:`falcon.request`
        :param response: Falcon response object.
        :type response: :obj:`falcon.response`
        """
        self.request = request
        etos = ETOS("ETOS Environment Provider", os.getenv("HOSTNAME"),
                    "Environment Provider")
        jsontas = JsonTas()
        self.registry = ProviderRegistry(etos, jsontas)
        try:
            assert self.suite_id is not None, "Invalid suite ID"
            FORMAT_CONFIG.identifier = self.suite_id
            iut_provider = self.iut_provider
            log_area_provider = self.log_area_provider
            execution_space_provider = self.execution_space_provider
            assert (
                iut_provider is not None
            ), f"No such IUT provider {self.request.media.get('iut_provider')}"
            assert execution_space_provider is not None, (
                "No such execution space provider"
                f"{self.request.media.get('execution_space_provider')}")
            assert (
                log_area_provider is not None
            ), f"No such log area provider {self.request.media.get('log_area_provider')}"
            assert self.dataset is not None, "Invalid dataset."
            response.media = {
                "IUTProvider": iut_provider,
                "ExecutionSpaceProvider": execution_space_provider,
                "LogAreaProvider": log_area_provider,
            }
            self.registry.configure_environment_provider_for_suite(
                self.suite_id,
                iut_provider,
                log_area_provider,
                execution_space_provider,
                self.dataset,
            )
        except AssertionError as exception:
            raise falcon.HTTPBadRequest("Invalid provider", str(exception))

    @staticmethod
    def on_get(request, response):
        """Get an already configured environment based on suite ID.

        Use only to verify that the environment has been configured properly.

        :param request: Falcon request object.
        :type request: :obj:`falcon.request`
        :param response: Falcon response object.
        :type response: :obj:`falcon.response`
        """
        suite_id = request.get_param("suite_id")
        FORMAT_CONFIG.identifier = suite_id
        etos = ETOS("ETOS Environment Provider", os.getenv("HOSTNAME"),
                    "Environment Provider")
        jsontas = JsonTas()
        registry = ProviderRegistry(etos, jsontas)
        if suite_id is None:
            raise falcon.HTTPBadRequest("Missing parameters",
                                        "'suite_id' is a required parameter.")
        response.status = falcon.HTTP_200
        iut_provider = registry.iut_provider(suite_id)
        log_area_provider = registry.log_area_provider(suite_id)
        execution_space_provider = registry.execution_space_provider(suite_id)
        response.media = {
            "iut_provider":
            iut_provider.ruleset if iut_provider else None,
            "log_area_provider":
            log_area_provider.ruleset if log_area_provider else None,
            "execution_space_provider":
            execution_space_provider.ruleset
            if execution_space_provider else None,
            "dataset":
            registry.dataset(suite_id),
        }
    def test_release_environment(self):
        """Test that it is possible to release an environment.

        Approval criteria:
            - It shall be possible to release an environment.

        Note:
            - This is not perfectly testable today due to how the providers are used
              when checking in provider items.

        Test steps:
            1. Attempt to release an environment.
            2. Verify that it was possible to release that environment.
        """
        database = FakeDatabase()
        test_iut_provider = OrderedDict({
            "iut": {
                "id": "iut_provider_test",
                "list": {
                    "available": [],
                    "possible": []
                },
            }
        })
        test_execution_space_provider = OrderedDict({
            "execution_space": {
                "id": "execution_space_provider_test",
                "list": {
                    "available": [{
                        "identifier": "123"
                    }],
                    "possible": []
                },
            }
        })
        test_log_area_provider = OrderedDict({
            "log": {
                "id": "log_area_provider_test",
                "list": {
                    "available": [],
                    "possible": []
                },
            }
        })
        database.writer.hset(
            "EnvironmentProvider:ExecutionSpaceProviders",
            test_execution_space_provider["execution_space"]["id"],
            json.dumps(test_execution_space_provider),
        )
        database.writer.hset(
            "EnvironmentProvider:IUTProviders",
            test_iut_provider["iut"]["id"],
            json.dumps(test_iut_provider),
        )
        database.writer.hset(
            "EnvironmentProvider:LogAreaProviders",
            test_log_area_provider["log"]["id"],
            json.dumps(test_log_area_provider),
        )
        iut = {"id": "test_iut", "provider_id": test_iut_provider["iut"]["id"]}
        executor = {
            "id": "test_executor",
            "provider_id":
            test_execution_space_provider["execution_space"]["id"],
        }
        log_area = {
            "id": "test_log_area",
            "provider_id": test_log_area_provider["log"]["id"],
        }
        jsontas = JsonTas()
        etos = ETOS("", "", "")
        registry = ProviderRegistry(etos, jsontas, database)

        test_release_id = "ce63f53e-1797-42bb-ae72-861a0b6b7ef6"
        worker = FakeCelery(
            test_release_id,
            "SUCCESS",
            {
                "suites": [{
                    "iut": iut,
                    "executor": executor,
                    "log_area": log_area,
                }]
            },
        )
        self.logger.info("STEP: Attempt to release an environment.")
        success, _ = release_environment(
            etos,
            jsontas,
            registry,
            worker.AsyncResult(test_release_id),
            test_release_id,
        )

        self.logger.info(
            "STEP: Verify that it was possible to release that environment.")
        self.assertTrue(success)
        self.assertIsNone(worker.AsyncResult(test_release_id))
    def test_release_environment_failure(self):
        """Test that a failure is returned when there is a problem with releasing.

        Approval criteria:
            - The environment provider shall return failure if one provider failed.

        Note:
            - This is not perfectly testable today due to how the providers are used
              when checking in provider items.

        Test steps:
            1. Release an environment where one provider will fail to check in.
            2. Verify that the release return failure.
        """
        database = FakeDatabase()
        test_iut_provider = {
            "iut": {
                "id": "iut_provider_test",
                "list": {
                    "available": [],
                    "possible": []
                },
            }
        }
        test_execution_space_provider = {
            "execution_space": {
                "id": "execution_space_provider_test",
                "list": {
                    "available": [{
                        "identifier": "123"
                    }],
                    "possible": []
                },
                "checkin": False,
            }
        }
        test_log_area_provider = {
            "log": {
                "id": "log_area_provider_test",
                "list": {
                    "available": [],
                    "possible": []
                },
            }
        }
        database.writer.hset(
            "EnvironmentProvider:ExecutionSpaceProviders",
            test_execution_space_provider["execution_space"]["id"],
            json.dumps(test_execution_space_provider),
        )
        database.writer.hset(
            "EnvironmentProvider:IUTProviders",
            test_iut_provider["iut"]["id"],
            json.dumps(test_iut_provider),
        )
        database.writer.hset(
            "EnvironmentProvider:LogAreaProviders",
            test_log_area_provider["log"]["id"],
            json.dumps(test_log_area_provider),
        )
        registry = ProviderRegistry(ETOS("", "", ""), JsonTas(), database)

        iut = {"id": "test_iut", "provider_id": test_iut_provider["iut"]["id"]}
        executor = {
            "id": "test_executor",
            "provider_id":
            test_execution_space_provider["execution_space"]["id"],
        }
        log_area = {
            "id": "test_log_area",
            "provider_id": test_log_area_provider["log"]["id"],
        }
        jsontas = JsonTas()
        etos = ETOS("", "", "")
        registry = ProviderRegistry(etos, jsontas, database)

        test_release_id = "ce63f53e-1797-42bb-ae72-861a0b6b7ef6"
        worker = FakeCelery(
            test_release_id,
            "SUCCESS",
            {
                "suites": [{
                    "iut": iut,
                    "executor": executor,
                    "log_area": log_area,
                }]
            },
        )

        self.logger.info(
            "STEP: Release an environment where one provider will fail to check in."
        )
        success, _ = release_environment(
            etos,
            jsontas,
            registry,
            worker.AsyncResult(test_release_id),
            test_release_id,
        )

        self.logger.info("STEP: Verify that the release return failure.")
        self.assertFalse(success)
        self.assertIsNone(worker.AsyncResult(test_release_id))