Example #1
0
    def molecule_config(self):
        """Reads all the molecule base configuration files present and adds them
        in the self.molecule_config field.

        :return: A list of one or multiple dictionaries including the content of
                 the molecule base configuration file(s)
        """
        configs = []
        config_files_list = self.molecule_config_files()
        if config_files_list:
            for config_file in config_files_list:
                configs.append(load_yaml(config_file))

        return configs
Example #2
0
    def tox_cases(self):
        """Returns a list of TestCase objects that can be queried to create
        the structure of a test environment.

        :return: List of TestCase objects"""

        # pylint: disable=fixme
        # TODO(ssbarnea): Detect and enable only those tests that do exist
        # to avoid confusing tox user.
        ANSIBLE_TEST_COMMANDS: Dict[str, Dict[str, Any]] = {
            "integration": {
                "args": ["--requirements"],
                "requires": "tests/integration",
            },
            "network-integration": {
                "args": ["--requirements"],
                "requires": "tests/network-integration",
            },
            # sanity tests do not need presence of sanity check or even tests
            # folder
            "sanity": {
                "args": ["--requirements"],
                "requires": ""
            },
            "shell": {
                "args": ["--requirements"]
            },
            "units": {
                "args": ["--requirements"],
                "requires": "tests/unit",
            },
            "windows-integration": {
                "args": ["--requirements"],
                "requires": "tests/windows-integration",
            },
            # special commands (not supported by us yet)
            "coverage": {
                "requires": "tests/unit"
            },
            "env": {},
        }

        # Append posargs if any to each command
        for value in ANSIBLE_TEST_COMMANDS.values():
            if "args" not in value:
                value["args"] = copy.deepcopy(self.tox.posargs)
            else:
                value["args"].extend(self.tox.posargs)
            if "--python" not in self.tox.posargs:
                value["args"].extend([
                    "--python", f"{sys.version_info[0]}.{sys.version_info[1]}"
                ])

        tox_cases = []
        for scenario in self.scenarios:
            tox_cases.append(ToxMoleculeCase(scenario))

        # if we are inside a collection, we also enable ansible-test support
        galaxy_file = path.join(self.directory, "galaxy.yml")
        if path.isfile(galaxy_file):
            galaxy_config = load_yaml(galaxy_file)
            for command in ANSIBLE_TEST_COMMANDS:
                if not path.exists(
                        path.join(
                            self.directory,
                            ANSIBLE_TEST_COMMANDS[command].get("requires", ""),
                        )):
                    continue
                try:
                    tox_cases.append(
                        ToxAnsibleTestCase(
                            command,
                            args=ANSIBLE_TEST_COMMANDS[command]["args"],
                            galaxy_config=galaxy_config,
                        ))
                except RuntimeError as exc:
                    logging.warning(str(exc))

        tox_cases.append(ToxLintCase(tox_cases))
        return tox_cases
Example #3
0
    def tox_cases(self):
        """Returns a list of TestCase objects that can be queried to create
        the structure of a test environment.

        :return: List of TestCase objects"""

        # pylint: disable=fixme
        # TODO(ssbarnea): Detect and enable only those tests that do exist
        # to avoid confusing tox user.
        docker_present = use_docker()
        platform = self.options.ansible_test_platform
        if (platform == "auto" and docker_present) or platform == "docker":
            opts = ["--docker", "default"]
        elif platform in ("auto", "venv"):
            opts = ["--venv"]
        else:
            opts = []

        # We use --venv because otherwise we risk getting errors from the
        # system environment, especially as one of tests performed is
        # 'pip check'.
        ANSIBLE_TEST_COMMANDS: Dict[str, Dict[str, Any]] = {
            "integration": {
                "args": ["--requirements", *opts],
                "requires": "tests/integration",
            },
            "network-integration": {
                "args": ["--requirements", *opts],
                "requires": "tests/network-integration",
            },
            # sanity tests do not need presence of sanity check or even tests
            # folder
            "sanity": {"args": ["--requirements", *opts], "requires": ""},
            "shell": {"args": ["--requirements", *opts]},
            "units": {
                "args": ["--requirements", *opts],
                "requires": "tests/unit",
            },
            "windows-integration": {
                "args": ["--requirements", *opts],
                "requires": "tests/windows-integration",
            },
            # special commands (not supported by us yet)
            "coverage": {"requires": "tests/unit"},
            "env": {},
        }

        # Append posargs if any to each command
        for value in ANSIBLE_TEST_COMMANDS.values():
            if "args" not in value:
                value["args"] = copy.deepcopy(self.tox.posargs)
            else:
                value["args"].extend(self.tox.posargs)
            if (
                "--python" not in self.tox.posargs
                and self.options.ansible_test_platform == "auto"
            ):
                value["args"].extend(
                    ["--python", f"{sys.version_info[0]}.{sys.version_info[1]}"]
                )

        tox_cases = []
        drivers = {s.driver for s in self.scenarios if s.driver}
        for scenario in self.scenarios:
            tox_cases.append(ToxMoleculeCase(scenario, drivers=drivers))

        # if we are inside a collection, we also enable ansible-test support
        galaxy_file = path.join(self.directory, "galaxy.yml")
        if path.isfile(galaxy_file):
            galaxy_config = load_yaml(galaxy_file)
            for command in ANSIBLE_TEST_COMMANDS.items():
                if not path.exists(
                    path.join(
                        self.directory,
                        command[1].get("requires", ""),
                    )
                ):
                    continue
                try:
                    tox_cases.append(
                        ToxAnsibleTestCase(
                            command[0],
                            args=command[1]["args"],
                            galaxy_config=galaxy_config,
                        )
                    )
                except RuntimeError as exc:
                    logging.warning(str(exc))

        tox_cases.append(ToxLintCase(tox_cases))
        return tox_cases
Example #4
0
 def config(self):
     """Reads the molecule.yml file. Adds it to the self.config
     field."""
     return load_yaml(self.scenario_file)