Esempio n. 1
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 log areas 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_LOG_AREA_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",
            }
        )
        log_area = LogArea(test_log_area=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(log_area)
Esempio n. 2
0
    def test_provider_stop(self):
        """Test that it is possible to checkin an external log area provider.

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

        Test steps::
            1. Initialize an external provider.
            2. Send a stop request for a single log area.
            3. Verify that the stop endpoint is called.
        """
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        etos.config.set("WAIT_FOR_LOG_AREA_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",
            }
        )
        log_area = LogArea(test_log_area=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 log area.")
            provider.checkin(log_area)
            self.logger.info("STEP: Verify that the stop endpoint is called.")
            self.assertEqual(server.nbr_of_requests, 1)
            self.assertEqual(server.requests, [[log_area.as_dict]])