示例#1
0
def test_command_init_scenario(temp_dir, DRIVER):
    """Verify that init scenario works."""
    role_directory = os.path.join(temp_dir.strpath, "test-init")
    cmd = ["molecule", "init", "role", "test-init"]
    result = run_command(cmd)
    assert result.returncode == 0

    with change_dir_to(role_directory):
        molecule_directory = pytest.helpers.molecule_directory()
        scenario_directory = os.path.join(molecule_directory, "test-scenario")
        options = {"role_name": "test-init", "driver-name": DRIVER}
        cmd = [
            "molecule",
            "init",
            "scenario",
            "test-scenario",
            *util.dict2args(options),
        ]
        result = run_command(cmd)
        assert result.returncode == 0

        assert os.path.isdir(scenario_directory)

        cmd = ["molecule", "--debug", "test", "-s", "test-scenario"]
        result = run_command(cmd)
        assert result.returncode == 0
示例#2
0
    def bake(self):
        """
        Bake an ``ansible-galaxy`` command so it's ready to execute and returns \
        None.

        :return: None
        """
        options = self.options
        verbose_flag = util.verbose_flag(options)

        self._sh_command = util.BakedCommand(
            cmd=[self.command, *self.COMMANDS, *util.dict2args(options), *verbose_flag],
            env=self.env,
        )
示例#3
0
    def bake(self):
        """
        Bake a ``testinfra`` command so it's ready to execute and returns None.

        :return: None
        """
        options = self.options
        verbose_flag = util.verbose_flag(options)
        args = verbose_flag + self.additional_files_or_dirs

        self._testinfra_command = util.BakedCommand(
            cmd=["pytest", *util.dict2args(options), *self._tests, *args],
            cwd=self._config.scenario.directory,
            env=self.env,
        )
示例#4
0
    def bake(self):
        """
        Bake an ``ansible-playbook`` command so it's ready to execute and \
        returns ``None``.

        :return: None
        """
        if not self._playbook:
            return

        # Pass a directory as inventory to let Ansible merge the multiple
        # inventory sources located under
        self.add_cli_arg("inventory",
                         self._config.provisioner.inventory_directory)
        options = util.merge_dicts(self._config.provisioner.options, self._cli)
        verbose_flag = util.verbose_flag(options)
        if self._playbook != self._config.provisioner.playbooks.converge:
            if options.get("become"):
                del options["become"]

        # We do not pass user-specified Ansible arguments to the create and
        # destroy invocations because playbooks involved in those two
        # operations are not always provided by end users. And in those cases,
        # custom Ansible arguments can break the creation and destruction
        # processes.
        #
        # If users need to modify the creation of deletion, they can supply
        # custom playbooks and specify them in the scenario configuration.
        if self._config.action not in ["create", "destroy"]:
            ansible_args = list(self._config.provisioner.ansible_args) + list(
                self._config.ansible_args)
        else:
            ansible_args = []

        self._ansible_command = util.BakedCommand(
            cmd=[
                "ansible-playbook",
                *util.dict2args(options),
                *util.bool2args(verbose_flag),
                *ansible_args,
                self._playbook,  # must always go last
            ],
            cwd=self._config.scenario.directory,
            env=self._env,
        )
示例#5
0
    def bake(self):
        """
        Bake an ``ansible-playbook`` command so it's ready to execute and \
        returns ``None``.

        :return: None
        """
        if not self._playbook:
            return

        # Pass a directory as inventory to let Ansible merge the multiple
        # inventory sources located under
        self.add_cli_arg("inventory",
                         self._config.provisioner.inventory_directory)
        options = util.merge_dicts(self._config.provisioner.options, self._cli)
        verbose_flag = util.verbose_flag(options)
        if self._playbook != self._config.provisioner.playbooks.converge:
            if options.get("become"):
                del options["become"]

        ansible_args = list(self._config.provisioner.ansible_args) + list(
            self._config.ansible_args)

        # if ansible_args:
        #     if self._config.action not in ["create", "destroy"]:
        #         # inserts ansible_args at index 1
        #         self._ansible_command.cmd.extend(ansible_args)

        self._ansible_command = util.BakedCommand(
            cmd=[
                "ansible-playbook",
                *util.dict2args(options),
                *util.bool2args(verbose_flag),
                *ansible_args,
                self._playbook,  # must always go last
            ],
            cwd=self._config.scenario.directory,
            env=self._env,
            stdout=self._out,
            stderr=self._err,
        )