Пример #1
0
    def execute_preparation_steps(self, iut, preparation_steps):
        """Execute the preparation steps for the environment provider on an IUT.

        :param iut: IUT to prepare for execution.
        :type iut: :obj:`environment_provider.lib.iut.Iut`
        :param preparation_steps: Steps to execute to prepare an IUT.
        :type preparation_steps: dict
        """
        FORMAT_CONFIG.identifier = self.config.get("SUITE_ID")
        try:
            with self.lock:
                dataset = self.dataset.copy()
                dataset.add("config", self.config)
            jsontas = JsonTas(dataset=dataset)
            steps = {}
            dataset.add("iut", iut)
            dataset.add("steps", steps)
            for step, definition in preparation_steps.items():
                definition = OrderedDict(**definition)
                self.logger.info("Executing step %r", step)
                step_result = jsontas.run(json_data=definition)
                self.logger.info("%r", step_result)
                if not step_result:
                    self.logger.error("Failed to execute step %r", step)
                    return False, iut
                steps[step] = step_result
        except Exception as exception:  # pylint:disable=broad-except
            self.logger.error("Failure when preparing IUT %r", iut)
            self.logger.error("%r", exception)
            return False, iut
        return True, iut
Пример #2
0
    def execute(self):
        """Execute wait datastructure.

        Waiting for will requires a 'query_tree' which is a collection of all requests
        that are 'below' the 'wait' datastructure. This is to keep track of the queries
        that have executed before (but not the results of these queries).

        This query tree is then executed in the :meth:`jsontas.jsontas.JsonTas.resolve` method,
        which can be considered weird. We're executing JsonTas inside of a JsonTas query.
        But this is the only way to re-run a query tree.

        :return: None and the result of re-running a query tree.
        :rtype: Tuple
        """
        if self.data.get("for"):
            return None, self.data.get("for")
        # This is a circular import.
        # pylint:disable=cyclic-import
        # pylint:disable=import-outside-toplevel
        from jsontas.jsontas import JsonTas
        jsontas = JsonTas(self.dataset)
        value = None
        query_tree = self.dataset.get("query_tree")
        for value in self.wait(jsontas.resolve,
                               self.data.get("timeout"),
                               self.data.get("interval"),
                               json_data=query_tree.get("for")):
            if value:
                break
        return None, value or self.data.get("else")
    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)
Пример #4
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,
            },
        )
Пример #5
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
    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)
Пример #7
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"
        }
Пример #8
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
    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),
        }
Пример #10
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`
        """
        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
Пример #11
0
    def __init__(self, suite_id, database):
        """Initialize ETOS, dataset, provider registry and splitter.

        :param suite_id: Suite ID to get an environment for
        :type suite_id: str
        :param database: Database class to use.
        :type database: class
        """
        self.suite_id = suite_id
        FORMAT_CONFIG.identifier = suite_id
        self.logger.info("Initializing EnvironmentProvider task.")
        self.etos = ETOS(
            "ETOS Environment Provider", os.getenv("HOSTNAME"), "Environment Provider"
        )
        with self.lock:
            # Since celery workers can share memory between them we need to make the configuration
            # of ETOS library unique as it uses the memory sharing feature with the internal
            # configuration dictionary.
            # The impact of not doing this is that the environment provider would re-use
            # another workers configuration instead of using its own.
            self.etos.config.config = deepcopy(
                self.etos.config.config
            )  # pylint:disable=protected-access
            self.jsontas = JsonTas()
            self.dataset = self.jsontas.dataset

        self.dataset.add("json_dumps", JsonDumps)
        self.dataset.add("uuid_generate", UuidGenerate)
        self.dataset.add("join", Join)
        self.registry = ProviderRegistry(self.etos, self.jsontas, database)
        self.splitter = Splitter(self.etos, {})
Пример #12
0
    def test_request_and_wait(self):
        """Test that the external log area provider can checkout log areas.

        Approval criteria:
            - The external log area provider shall request an external provider and
              checkout log areas.

        Test steps::
            1. Initialize an external provider.
            2. Send a checkout request via the external log area provider.
            3. Verify that the provider returns a list of checked out log areas.
        """
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        etos.config.set("WAIT_FOR_LOG_AREA_TIMEOUT", 10)
        jsontas = JsonTas()
        identity = PackageURL.from_string("pkg:testing/etos")
        jsontas.dataset.merge(
            {
                "identity": identity,
                "artifact_id": "artifactid",
                "artifact_created": "artifactcreated",
                "artifact_published": "artifactpublished",
                "tercc": "tercc",
                "dataset": {},
                "context": "context",
            }
        )
        start_id = "1"
        test_id = "logarea123"
        provider_id = "test_request_and_wait"
        # First request is 'start'.
        # Second request is 'status'.
        # Third request is 'stop' which should not be requested in this test.
        with FakeServer(
            ["ok", "ok", "no_content"],
            [
                {"id": start_id},
                {"log_areas": [{"test_id": test_id}], "status": "DONE"},
                {},
            ],
        ) as server:
            ruleset = {
                "id": provider_id,
                "status": {"host": server.host},
                "start": {"host": server.host},
                "stop": {"host": server.host},
            }
            self.logger.info("STEP: Initialize an external provider.")
            provider = Provider(etos, jsontas, ruleset)
            self.logger.info(
                "STEP: Send a checkout request via the external log area provider."
            )
            log_areas = provider.request_and_wait_for_log_areas()
            self.logger.info(
                "STEP: Verify that the provider returns a list of checked out log areas."
            )
            dict_log_areas = [log_area.as_dict for log_area in log_areas]
            test_log_areas = [LogArea(provider_id=provider_id, test_id=test_id).as_dict]
            self.assertEqual(dict_log_areas, test_log_areas)
Пример #13
0
    def test_provider_stop_many(self):
        """Test that it is possible to checkin an external execution space provider with many
           execution spaces.

        Approval criteria:
            - It shall be possible to send stop to an external execution space provider
              with multiple execution spaces.

        Test steps::
            1. Initialize an external provider.
            2. Send a stop request for multiple execution spaces.
            3. Verify that the stop endpoint is called.
        """
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        etos.config.set("WAIT_FOR_EXECUTION_SPACE_TIMEOUT", 1)
        jsontas = JsonTas()
        execution_spaces = [
            ExecutionSpace(test_execution_space=1),
            ExecutionSpace(test_execution_space=2),
        ]
        jsontas.dataset.merge({
            "identity":
            PackageURL.from_string("pkg:testing/etos"),
            "artifact_id":
            "artifactid",
            "artifact_created":
            "artifactcreated",
            "artifact_published":
            "artifactpublished",
            "tercc":
            "tercc",
            "dataset": {},
            "context":
            "context",
            "execution_spaces":
            execution_spaces,
        })
        dict_execution_spaces = [
            execution_space.as_dict for execution_space in execution_spaces
        ]

        with FakeServer("no_content", {}) as server:
            ruleset = {
                "id": "test_provider_stop_many",
                "stop": {
                    "host": server.host
                }
            }
            self.logger.info("STEP: Initialize an external provider.")
            provider = Provider(etos, jsontas, ruleset)
            self.logger.info(
                "STEP: Send a stop request for multiple execution spaces.")
            provider.checkin_all()
            self.logger.info("STEP: Verify that the stop endpoint is called.")
            self.assertEqual(server.nbr_of_requests, 1)
            self.assertEqual(server.requests, [dict_execution_spaces])
Пример #14
0
def main(args):
    """Entry point allowing external calls.

    Args:
      args ([str]): command line parameter list
    """
    args = parse_args(args)
    setup_logging(args.loglevel)
    jsontas = JsonTas()
    if args.dataset:
        with open(args.dataset) as json_file:
            dataset = json.load(json_file)
        jsontas.dataset.merge(dataset)

    data = jsontas.run(json_file=args.json_file)
    if args.output:
        with open(args.output, "w") as output_file:
            json.dump(data, output_file)
    else:
        pprint(data)
Пример #15
0
    def test_provider_status_http_exceptions(self):
        """Test that the wait method handles HTTP errors.

        Approvial criteria:
            - The wait method shall raise ExecutionSpaceNotAvailable on 404 errors.
            - The wait method shall raise RuntimeError on 400 errors.

        Test steps::
            1. For status [400, 404]:
                1.1 Initialize an external provider.
                1.2 Send a status request for a started execution space provider.
                1.3 Verify that the wait method raises the correct exception.
        """
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        etos.config.set("WAIT_FOR_EXECUTION_SPACE_TIMEOUT", 1)
        jsontas = JsonTas()
        jsontas.dataset.merge({
            "identity":
            PackageURL.from_string("pkg:testing/etos"),
            "artifact_id":
            "artifactid",
            "artifact_created":
            "artifactcreated",
            "artifact_published":
            "artifactpublished",
            "tercc":
            "tercc",
            "dataset": {},
            "context":
            "context",
        })
        self.logger.info("STEP: For status [400, 404]:")
        for status, exception in (
            ("bad_request", RuntimeError),
            ("not_found", ExecutionSpaceNotAvailable),
        ):
            with FakeServer(status, {"error": "failure"}) as server:
                ruleset = {
                    "id": "test_provider_status_http_exceptions",
                    "status": {
                        "host": server.host
                    },
                }
                self.logger.info("STEP: Initialize an external provider.")
                provider = Provider(etos, jsontas, ruleset)
                self.logger.info(
                    "STEP: Send a status request for a started execution space provider."
                )
                with self.assertRaises(exception):
                    self.logger.info(
                        "STEP: Verify that the wait method raises the correct exception."
                    )
                    provider.wait("1")
Пример #16
0
    def execute(self):
        """Execute expand.

        :return: None and a list of values.
        :rtype: tuple
        """
        # This is a circular import.
        # pylint:disable=cyclic-import
        # pylint:disable=import-outside-toplevel
        from jsontas.jsontas import JsonTas
        jsontas = JsonTas(self.dataset)
        query_tree = self.dataset.get("query_tree")
        amount = self.data.get("to", 0)

        evaluated = []
        for index in range(amount):
            value = deepcopy(query_tree.get("value"))
            self.dataset.add("expand_index", index)
            self.dataset.add("expand_value", value)
            evaluated.append(jsontas.resolve(json_data=value))
        return None, evaluated
Пример #17
0
    def test_provider_status_pending(self):
        """Test that the wait method waits on status PENDING.

        Approvial criteria:
            - The wait method shall call the status endpoint, waiting on PENDING.

        Test steps::
            1. Initialize an external provider.
            2. Send a status request for a started execution space provider.
            3. Verify that the wait method waits on PENDING.
        """
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        etos.config.set("WAIT_FOR_EXECUTION_SPACE_TIMEOUT", 10)
        jsontas = JsonTas()
        jsontas.dataset.merge({
            "identity":
            PackageURL.from_string("pkg:testing/etos"),
            "artifact_id":
            "artifactid",
            "artifact_created":
            "artifactcreated",
            "artifact_published":
            "artifactpublished",
            "tercc":
            "tercc",
            "dataset": {},
            "context":
            "context",
        })
        responses = [{
            "status": "PENDING"
        }, {
            "status": "PENDING"
        }, {
            "status": "DONE"
        }]
        with FakeServer("ok", responses.copy()) as server:
            ruleset = {
                "id": "test_provider_status_pending",
                "status": {
                    "host": server.host
                },
            }
            self.logger.info("STEP: Initialize an external provider.")
            provider = Provider(etos, jsontas, ruleset)
            self.logger.info(
                "STEP: Send a status request for a started execution space provider."
            )
            provider.wait("1")
            self.logger.info(
                "STEP: Verify that the wait method waits on PENDING.")
            self.assertEqual(server.nbr_of_requests, len(responses))
Пример #18
0
    def __init__(self, product):
        """Initialize.

        :param product: Dictionary to set attributes from.
                        Should be the response from pool plugin list.
        :type product: dict
        """
        self.test_runner = {}
        self.config = Config()
        self.config.set("scripts", [])
        self.steps = {
            "environment": self.load_environment,
            "commands": self.commands
        }

        product["identity"] = PackageURL.from_string(product["identity"])
        for key, value in product.items():
            setattr(self, key, value)
        self._product_dict = product
        self.jsontas = JsonTas()
        self.jsontas.dataset.add("iut", self._product_dict)
        self.prepare()
Пример #19
0
    def test_provider_status_failed(self):
        """Test that the wait method raises ExecutionSpaceCheckoutFailed on FAILED status.

        Approvial criteria:
            - The wait method shall raise ExecutionSpaceCheckoutFailed on a FAILED status.

        Test steps::
            1. Initialize an external provider.
            2. Send a status request for a started execution space provider.
            3. Verify that the wait method raises ExecutionSpaceCheckoutFailed.
        """
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        etos.config.set("WAIT_FOR_EXECUTION_SPACE_TIMEOUT", 1)
        jsontas = JsonTas()
        jsontas.dataset.merge({
            "identity":
            PackageURL.from_string("pkg:testing/etos"),
            "artifact_id":
            "artifactid",
            "artifact_created":
            "artifactcreated",
            "artifact_published":
            "artifactpublished",
            "tercc":
            "tercc",
            "dataset": {},
            "context":
            "context",
        })
        description = "something failed!"
        with FakeServer("ok", {
                "status": "FAILED",
                "description": description
        }) as server:
            ruleset = {
                "id": "test_provider_status_failed",
                "status": {
                    "host": server.host
                },
            }
            self.logger.info("STEP: Initialize an external provider.")
            provider = Provider(etos, jsontas, ruleset)
            self.logger.info(
                "STEP: Send a status request for a started execution space provider."
            )
            with self.assertRaises(ExecutionSpaceCheckoutFailed):
                self.logger.info(
                    "STEP: Verify that the wait method raises ExecutionSpaceCheckoutFailed."
                )
                provider.wait("1")
Пример #20
0
    def test_provider_status(self):
        """Test that the wait method waits for status DONE and exits with response.

        Approvial criteria:
            - The wait method shall call the status endpoint and return on DONE.

        Test steps::
            1. Initialize an external provider.
            2. Send a status request for a started execution space provider.
            3. Verify that the wait method returns response on DONE.
        """
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        etos.config.set("WAIT_FOR_EXECUTION_SPACE_TIMEOUT", 1)
        jsontas = JsonTas()
        jsontas.dataset.merge({
            "identity":
            PackageURL.from_string("pkg:testing/etos"),
            "artifact_id":
            "artifactid",
            "artifact_created":
            "artifactcreated",
            "artifact_published":
            "artifactpublished",
            "tercc":
            "tercc",
            "dataset": {},
            "context":
            "context",
        })
        test_id = "123"
        with FakeServer("ok", {
                "status": "DONE",
                "test_id": test_id
        }) as server:
            ruleset = {
                "id": "test_provider_status",
                "status": {
                    "host": server.host
                }
            }
            self.logger.info("STEP: Initialize an external provider.")
            provider = Provider(etos, jsontas, ruleset)
            self.logger.info(
                "STEP: Send a status request for a started execution space provider."
            )
            response = provider.wait("1")
            self.logger.info(
                "STEP: Verify that the wait method return response on DONE.")
            self.assertEqual(response.get("test_id"), test_id)
Пример #21
0
    def test_provider_start_http_exception(self):
        """Test that the start method tries again if there's an HTTP error.

        Approval criteria:
            - The start method shall try again on HTTP errors.

        Test steps::
            1. Initialize an external provider.
            2. Send a start request that fails.
            3. Verify that the start method tries again on HTTP errors.
        """
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        jsontas = JsonTas()
        jsontas.dataset.merge({
            "identity":
            PackageURL.from_string("pkg:testing/etos"),
            "artifact_id":
            "artifactid",
            "artifact_created":
            "artifactcreated",
            "artifact_published":
            "artifactpublished",
            "tercc":
            "tercc",
            "dataset": {},
            "context":
            "context",
        })
        expected_start_id = "123"

        with FakeServer(["bad_request", "ok"], [{}, {
                "id": expected_start_id
        }]) as server:
            ruleset = {
                "id": "test_provider_start_http_exception",
                "start": {
                    "host": server.host
                },
            }
            self.logger.info("STEP: Initialize an external provider.")
            provider = Provider(etos, jsontas, ruleset)
            self.logger.info("STEP: Send a start request that fails.")
            start_id = provider.start(1, 2)
            self.logger.info(
                "STEP: Verify that the start method tries again on HTTP errors."
            )
            self.assertGreaterEqual(server.nbr_of_requests, 2)
            self.assertEqual(start_id, expected_start_id)
Пример #22
0
    def test_provider_start_timeout(self):
        """Test that the start method raises a TimeoutError.

        Approval criteria:
            - The start method shall raise TimeoutError if the timeout is reached.

        Test steps::
            1. Initialize an external provider.
            2. Send a start request which will never finish.
            3. Verify that the start method raises TimeoutError.
        """
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        jsontas = JsonTas()
        jsontas.dataset.merge({
            "identity":
            PackageURL.from_string("pkg:testing/etos"),
            "artifact_id":
            "artifactid",
            "artifact_created":
            "artifactcreated",
            "artifact_published":
            "artifactpublished",
            "tercc":
            "tercc",
            "dataset": {},
            "context":
            "context",
        })
        os.environ["ETOS_DEFAULT_HTTP_TIMEOUT"] = "1"

        with FakeServer("bad_request", {}) as server:
            ruleset = {
                "id": "test_provider_start_timeout",
                "start": {
                    "host": server.host
                },
            }
            self.logger.info("STEP: Initialize an external provider.")
            provider = Provider(etos, jsontas, ruleset)
            self.logger.info(
                "STEP: Send a start request which will never finish.")

            with self.assertRaises(TimeoutError):
                self.logger.info(
                    "STEP: Verify that the start method raises TimeoutError.")
                provider.start(1, 2)
Пример #23
0
    def test_provider_stop_failed(self):
        """Test that the checkin method raises an ExecutionSpaceCheckinFailed exception.

        Approval criteria:
            - The checkin method shall fail with an ExecutionSpaceCheckinFailed exception.

        Test steps::
            1. Initialize an external provider.
            2. Send a stop request that fails.
            3. Verify that the checkin method raises ExecutionSpaceCheckinFailed exception.
        """
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        etos.config.set("WAIT_FOR_EXECUTION_SPACE_TIMEOUT", 1)
        jsontas = JsonTas()
        jsontas.dataset.merge({
            "identity":
            PackageURL.from_string("pkg:testing/etos"),
            "artifact_id":
            "artifactid",
            "artifact_created":
            "artifactcreated",
            "artifact_published":
            "artifactpublished",
            "tercc":
            "tercc",
            "dataset": {},
            "context":
            "context",
        })
        execution_space = ExecutionSpace(test_execution_space=1)

        with FakeServer("bad_request", {"error": "no"}) as server:
            ruleset = {
                "id": "test_provider_stop_failed",
                "stop": {
                    "host": server.host
                }
            }
            self.logger.info("STEP: Initialize an external provider.")
            provider = Provider(etos, jsontas, ruleset)
            self.logger.info("STEP: Send a stop request that fails.")
            with self.assertRaises(ExecutionSpaceCheckinFailed):
                self.logger.info(
                    "STEP: Verify that the checkin method raises ExecutionSpaceCheckinFailed "
                    "exception.")
                provider.checkin(execution_space)
Пример #24
0
    def test_provider_stop_timeout(self):
        """Test that the checkin method raises a TimeoutError when timed out.

        Approval criteria:
            - The checkin method shall raise TimeoutError when timed out.

        Test steps::
            1. Initialize an external provider.
            2. Send a stop request for IUTs that times out.
            3. Verify that the checkin method raises a TimeoutError.
        """
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        etos.config.set("WAIT_FOR_IUT_TIMEOUT", 1)
        jsontas = JsonTas()
        jsontas.dataset.merge({
            "identity":
            PackageURL.from_string("pkg:testing/etos"),
            "artifact_id":
            "artifactid",
            "artifact_created":
            "artifactcreated",
            "artifact_published":
            "artifactpublished",
            "tercc":
            "tercc",
            "dataset": {},
            "context":
            "context",
        })
        iut = Iut(test_iut=1)
        with FakeServer("bad_request", {}) as server:
            ruleset = {
                "id": "test_provider_stop_timeout",
                "stop": {
                    "host": server.host
                },
            }
            self.logger.info("STEP: Initialize an external provider.")
            provider = Provider(etos, jsontas, ruleset)
            self.logger.info("STEP: Send a stop request that fails.")
            with self.assertRaises(TimeoutError):
                self.logger.info(
                    "STEP: Verify that the checkin method raises a TimeoutError."
                )
                provider.checkin(iut)
Пример #25
0
    def test_provider_stop(self):
        """Test that it is possible to checkin an external IUT provider.

        Approval criteria:
            - It shall be possible to send stop to an external IUT provider.

        Test steps::
            1. Initialize an external provider.
            2. Send a stop request for a single IUT.
            3. Verify that the stop endpoint is called.
        """
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        etos.config.set("WAIT_FOR_IUT_TIMEOUT", 1)
        jsontas = JsonTas()
        jsontas.dataset.merge({
            "identity":
            PackageURL.from_string("pkg:testing/etos"),
            "artifact_id":
            "artifactid",
            "artifact_created":
            "artifactcreated",
            "artifact_published":
            "artifactpublished",
            "tercc":
            "tercc",
            "dataset": {},
            "context":
            "context",
        })
        iut = Iut(test_iut=1)

        with FakeServer("no_content", {}) as server:
            ruleset = {
                "id": "test_provider_stop",
                "stop": {
                    "host": server.host
                }
            }
            self.logger.info("STEP: Initialize an external provider.")
            provider = Provider(etos, jsontas, ruleset)
            self.logger.info("STEP: Send a stop request for a single IUT.")
            provider.checkin(iut)
            self.logger.info("STEP: Verify that the stop endpoint is called.")
            self.assertEqual(server.nbr_of_requests, 1)
            self.assertEqual(server.requests, [[iut.as_dict]])
Пример #26
0
    def test_provider_start(self):
        """Test that it is possible to start an external execution space provider.

        Approval criteria:
            - It shall be possible to send start to an external execution space provider.

        Test steps::
            1. Initialize an external provider.
            2. Send a start request.
            3. Verify that the ID from the start request is returned.
        """
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        jsontas = JsonTas()
        jsontas.dataset.merge({
            "identity":
            PackageURL.from_string("pkg:testing/etos"),
            "artifact_id":
            "artifactid",
            "artifact_created":
            "artifactcreated",
            "artifact_published":
            "artifactpublished",
            "tercc":
            "tercc",
            "dataset": {},
            "context":
            "context",
        })
        expected_start_id = "123"

        with FakeServer("ok", {"id": expected_start_id}) as server:
            ruleset = {
                "id": "test_provider_start",
                "start": {
                    "host": server.host
                }
            }
            self.logger.info("STEP: Initialize an external provider.")
            provider = Provider(etos, jsontas, ruleset)
            self.logger.info("STEP: Send a start request.")
            start_id = provider.start(1, 2)
            self.logger.info(
                "STEP: Verify that the ID from the start request is returned.")
            self.assertEqual(start_id, expected_start_id)
Пример #27
0
    def test_provider_status_timeout(self):
        """Test that the wait method raises TimeoutError when timed out.

        Approvial criteria:
            - The wait method shall raise TimeoutError when timed out.

        Test steps::
            1. Initialize an external provider.
            2. Send a status request that times out.
            3. Verify that the wait method raises TimeoutError.
        """
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        etos.config.set("WAIT_FOR_EXECUTION_SPACE_TIMEOUT", 1)
        jsontas = JsonTas()
        jsontas.dataset.merge({
            "identity":
            PackageURL.from_string("pkg:testing/etos"),
            "artifact_id":
            "artifactid",
            "artifact_created":
            "artifactcreated",
            "artifact_published":
            "artifactpublished",
            "tercc":
            "tercc",
            "dataset": {},
            "context":
            "context",
        })
        with FakeServer("internal_server_error", {}) as server:
            ruleset = {
                "id": "test_provider_status_timeout",
                "status": {
                    "host": server.host
                },
            }
            self.logger.info("STEP: Initialize an external provider.")
            provider = Provider(etos, jsontas, ruleset)
            self.logger.info("STEP: Send a status request that times out.")
            with self.assertRaises(TimeoutError):
                self.logger.info(
                    "STEP: Verify that the wait method raises TimeoutError.")
                provider.wait("1")
Пример #28
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`
        """
        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 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)
Пример #30
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)