def clear_etos_lib_configurations():
    """Make sure that etos library configuration is cleared after each test."""
    config = Config()
    debug = Debug()
    yield
    config.reset()
    debug.events_received.clear()
    debug.events_published.clear()
Exemple #2
0
    def test_configure_environment_provider(self, mock_client):
        """Test that configure requests are proxied to the environment provider.

        Approval criteria:
            - Requests to configure shall be redirected to the environment provider.
            - HTTP status code shall be 204.

        Test steps::
            1. Send a POST request to configure.
            2. Verify that the status code is 204.
            3. Verify that the request was sent to the environment provider.
        """
        mock_client().__aenter__.return_value = mock_client
        mock_client.post().__aenter__.return_value = mock_client
        mock_client.status = 200
        mock_client.post.reset_mock()

        self.logger.info("STEP: Send a POST request to configure.")
        response = self.client.post(
            "environment_provider/configure",
            json={
                "suite_id": "f5d5bc7b-c6b8-406f-a997-43c8217e32c1",
                "dataset": {},
                "iut_provider": "iut",
                "execution_space_provider": "execution_space",
                "log_area_provider": "log_area",
            },
        )

        self.logger.info("STEP: Verify that the status code is 204.")
        assert response.status_code == 204

        self.logger.info(
            "STEP: Verify that the request was sent to the environment provider."
        )
        debug = Debug()
        mock_client.post.assert_called_once_with(
            f"{debug.environment_provider}/configure",
            json={
                "suite_id": "f5d5bc7b-c6b8-406f-a997-43c8217e32c1",
                "dataset": {},
                "execution_space_provider": "execution_space",
                "iut_provider": "iut",
                "log_area_provider": "log_area",
            },
            headers={
                "Content-Type": "application/json",
                "Accept": "application/json"
            },
        )
 def setUpClass(cls):
     """Create a debug instance."""
     cls.main_suite_id = "577381ad-8356-4939-ab77-02e7abe06699"
     cls.debug = Debug()
Exemple #4
0
 def __init__(self):
     """Graphql query handler."""
     self.transport_protocol = RequestsHTTPTransport
     self.utils = Utils()
     self.debug = Debug()
Exemple #5
0
 def teardown_method():
     """Cleanup events from ETOS library debug."""
     Debug().events_received.clear()
     Debug().events_published.clear()
Exemple #6
0
    def test_start_etos(self, mock_client, graphql_execute_mock,
                        download_suite_mock):
        """Test that POST requests to /etos attempts to start ETOS tests.

        Approval criteria:
            - POST requests to ETOS shall return 200.
            - POST requests to ETOS shall attempt to send TERCC.
            - POST requests to ETOS shall configure environment provider.

        Test steps::
            1. Send a POST request to etos.
            2. Verify that the status code is 200.
            3. Verify that a TERCC was sent.
            4. Verify that the environment provider was configured.
        """
        mock_client().__aenter__.return_value = mock_client
        mock_client.post().__aenter__.return_value = mock_client
        mock_client.status = 200
        mock_client.post.reset_mock()

        graphql_execute_mock.return_value = {
            "artifactCreated": {
                "edges": [{
                    "node": {
                        "meta": {
                            "id": "cda58701-5614-49bf-9101-11b71a5721fb"
                        }
                    }
                }]
            }
        }
        download_suite_mock.return_value = [{
            "name":
            "TestRouters",
            "priority":
            1,
            "recipes": [{
                "constraints": [
                    {
                        "key": "ENVIRONMENT",
                        "value": {}
                    },
                    {
                        "key": "PARAMETERS",
                        "value": {}
                    },
                    {
                        "key": "COMMAND",
                        "value": "exit 0"
                    },
                    {
                        "key": "TEST_RUNNER",
                        "value": "TestRunner"
                    },
                    {
                        "key": "EXECUTE",
                        "value": []
                    },
                    {
                        "key": "CHECKOUT",
                        "value": ["echo 'checkout'"]
                    },
                ],
                "id":
                "132a7499-7ad4-4c4a-8a66-4e9ac95c7885",
                "testCase": {
                    "id": "test_start_etos",
                    "tracker": "Github",
                    "url": "https://github.com/eiffel-community/etos-api",
                },
            }],
        }]
        self.logger.info("STEP: Send a POST request to etos.")
        response = self.client.post(
            "/etos",
            json={
                "artifact_identity": "pkg:testing/etos",
                "test_suite_url": "http://localhost/my_test.json",
            },
        )
        self.logger.info("STEP: Verify that the status code is 200.")
        assert response.status_code == 200
        self.logger.info("STEP: Verify that a TERCC was sent.")
        debug = Debug()
        tercc = None
        for event in debug.events_published:
            if event.meta.type == "EiffelTestExecutionRecipeCollectionCreatedEvent":
                tercc = event
                break
        assert tercc is not None
        assert response.json().get("tercc") == tercc.meta.event_id
        self.logger.info(
            "STEP: Verify that the environment provider was configured.")
        mock_client.post.assert_called_once_with(
            f"{debug.environment_provider}/configure",
            json={
                "suite_id": tercc.meta.event_id,
                "dataset": {},
                "execution_space_provider": "default",
                "iut_provider": "default",
                "log_area_provider": "default",
            },
            headers={
                "Content-Type": "application/json",
                "Accept": "application/json"
            },
        )
Exemple #7
0
def parse_args(args):
    """Parse command line parameters.

    Args:
      args ([str]): command line parameters as list of strings

    Returns:
      :obj:`argparse.Namespace`: command line parameters namespace
    """
    parser = argparse.ArgumentParser(
        description="Client for executing test automation suites in ETOS")
    parser.add_argument(
        "-i",
        "--identity",
        help="Artifact created identity purl to execute test suite on.",
        **environ_or_required("IDENTITY"))
    parser.add_argument("-s",
                        "--test-suite",
                        help="Test suite execute. Either URL or name.",
                        **environ_or_required("TEST_SUITE"))

    parser.add_argument("--no-tty",
                        help="Disable features requiring a tty.",
                        action="store_true")
    parser.add_argument(
        "-w",
        "--workspace",
        default=os.getenv("WORKSPACE", os.getcwd()),
        help="Which workspace to do all the work in.",
    )
    parser.add_argument(
        "-a",
        "--artifact-dir",
        default="artifacts",
        help="Where test artifacts should be stored. Relative to workspace.",
    )
    parser.add_argument(
        "-r",
        "--report-dir",
        default="reports",
        help="Where test reports should be stored. Relative to workspace.",
    )
    parser.add_argument(
        "-d",
        "--download-reports",
        default=None,
        help="Should we download reports. Can be 'yes', 'y', 'no', 'n'.",
    )

    parser.add_argument("--iut-provider",
                        default="default",
                        help="Which IUT provider to use.")
    parser.add_argument(
        "--execution-space-provider",
        default="default",
        help="Which execution space provider to use.",
    )
    parser.add_argument("--log-area-provider",
                        default="default",
                        help="Which log area provider to use.")
    parser.add_argument(
        "--dataset",
        default="{}",
        help=("Additional dataset information to the environment provider. "
              "Check with your provider which information can be supplied."),
    )

    parser.add_argument(
        "--cluster",
        default=Debug().etos_api,
        help="Cluster should be in the form of URL to tester-api.",
    )
    parser.add_argument(
        "--version",
        action="version",
        version="etos_client {ver}".format(ver=__version__),
    )
    parser.add_argument(
        "-v",
        "--verbose",
        dest="loglevel",
        help="set loglevel to DEBUG",
        action="store_const",
        default=logging.WARNING,
        const=logging.DEBUG,
    )
    return parser.parse_args(args)
 def setUpClass(cls):
     """Create a debug instance."""
     cls.debug = Debug()
Exemple #9
0
    logger.info("Hello!")
    >>> [2020-12-16 10:35:00][cb7c8cd9-40a6-4ecc-8321-a1eae6beae35] INFO: Hello!

"""
import sys
from pathlib import Path
import threading
import logging
import logging.config
from box import Box
from etos_lib.logging.filter import EtosFilter
from etos_lib.logging.formatter import EtosLogFormatter
from etos_lib.lib.debug import Debug

DEFAULT_CONFIG = Path(__file__).parent.joinpath("default_config.yaml")
DEFAULT_LOG_PATH = Debug().default_log_path

FORMAT_CONFIG = threading.local()


def setup_file_logging(config, log_filter):
    """Set up logging to file using the ETOS log formatter.

    Cofiguration file parameters ('file' must exist or no file handler is set up):

        logging:
          file:
            # Log level for file logging. Default=DEBUG.
            loglevel: INFO
            # Where to store logfile. Default=/home/you/etos/output.log.json
            logfile: path/to/log/file