Exemplo n.º 1
0
def test_execute(patched_ansible_galaxy, molecule_instance):
    molecule_instance.config.config['dependencies']['requirements_file'] = True

    d = dependency.Dependency({}, {}, molecule_instance)
    d.execute()

    patched_ansible_galaxy.assert_called_once()
    assert molecule_instance.state.installed_deps
Exemplo n.º 2
0
def test_execute_does_not_install_when_installed(patched_ansible_galaxy,
                                                 molecule_instance):
    molecule_instance.config.config['dependency']['requirements_file'] = True
    molecule_instance.state.change_state('installed_deps', True)

    d = dependency.Dependency({}, {}, molecule_instance)
    d.execute()

    assert not patched_ansible_galaxy.called
Exemplo n.º 3
0
def test_execute_shell(patched_shell, molecule_instance):
    molecule_instance.dependencies = 'shell'
    molecule_instance.config.config['dependencies']['command'] = True

    d = dependency.Dependency({}, {}, molecule_instance)
    d.execute()

    patched_shell.assert_called_once()
    assert molecule_instance.state.installed_deps
Exemplo n.º 4
0
def test_execute_shell_does_not_install_when_installed(patched_shell,
                                                       molecule_instance):
    molecule_instance.dependency = 'shell'
    molecule_instance.config.config['dependency']['command'] = True
    molecule_instance.state.change_state('installed_deps', True)

    d = dependency.Dependency({}, {}, molecule_instance)
    d.execute()

    assert not patched_shell.called
Exemplo n.º 5
0
def test_execute_shell(patched_shell, patched_print_info, molecule_instance):
    molecule_instance.dependency = 'shell'
    molecule_instance.config.config['dependency']['command'] = True

    d = dependency.Dependency({}, {}, molecule_instance)
    d.execute()

    msg = "Downloading dependencies with 'shell'..."
    patched_print_info.assert_called_once_with(msg)

    patched_shell.assert_called_once_with()
    assert molecule_instance.state.installed_deps
Exemplo n.º 6
0
def test_execute(patched_ansible_galaxy, patched_print_info,
                 molecule_instance):
    molecule_instance.config.config['dependency']['requirements_file'] = True

    d = dependency.Dependency({}, {}, molecule_instance)
    d.execute()

    msg = "Downloading dependencies with 'galaxy'..."
    patched_print_info.assert_called_once_with(msg)

    patched_ansible_galaxy.assert_called_once()
    assert molecule_instance.state.installed_deps
Exemplo n.º 7
0
def test_execute(mocker, patched_logger_info, patched_ansible_galaxy,
                 config_instance):
    d = dependency.Dependency(config_instance)
    d.execute()
    x = [
        mocker.call('Scenario: [default]'),
        mocker.call('Dependency: [galaxy]')
    ]

    assert x == patched_logger_info.mock_calls

    patched_ansible_galaxy.assert_called_once_with()
Exemplo n.º 8
0
def test_execute(mocker, patched_logger_info, patched_ansible_galaxy,
                 patched_config_validate, config_instance):
    d = dependency.Dependency(config_instance)
    d.execute()

    x = [
        mocker.call("Scenario: 'default'"),
        mocker.call("Action: 'dependency'"),
    ]
    assert x == patched_logger_info.mock_calls

    patched_ansible_galaxy.assert_called_once_with()
Exemplo n.º 9
0
def test_execute(
    mocker,
    patched_logger_info,
    patched_ansible_galaxy,
    patched_config_validate,
    config_instance,
):
    d = dependency.Dependency(config_instance)
    d.execute()

    patched_ansible_galaxy.assert_called_once_with()

    assert len(patched_logger_info.mock_calls) == 1
    name, args, kwargs = patched_logger_info.mock_calls[0]
    assert "default" in args
    assert "dependency" in args
Exemplo n.º 10
0
    def execute(self, exit=True):
        """
        Execute the actions necessary to perform a `molecule syntax` and
        return a tuple.

        :param exit: (Unused) Provided to complete method signature.
        :return: Return a tuple provided by :meth:`.AnsiblePlaybook.execute`.
        """
        debug = self.args.get('debug')
        self.molecule.create_templates()
        d = dependency.Dependency(self.args, self.command_args, self.molecule)
        d.execute()

        ansible = ansible_playbook.AnsiblePlaybook(
            self.molecule.config.config['ansible'], {}, debug=debug)
        ansible.add_cli_arg('syntax-check', True)
        ansible.add_cli_arg('inventory_file', 'localhost,')
        util.print_info("Checking playbook's syntax...")

        return ansible.execute(hide_errors=True)
Exemplo n.º 11
0
    def execute(self,
                idempotent=False,
                create_instances=True,
                create_inventory=True,
                exit=True,
                hide_errors=True):
        """
        Execute the actions necessary to perform a `molecule converge` and
        return a tuple.

        :param idempotent: An optional flag to perform the converge again, and
         parse the output for idempotence.
        :param create_inventory: An optional flag to toggle inventory creation.
        :param create_instances: An optional flag to toggle instance creation.
        :return: Return a tuple of (`exit status`, `command output`), otherwise
         sys.exit on command failure.
        """
        debug = self.args.get('debug')

        if self.molecule.state.created:
            create_instances = False

        if self.molecule.state.converged:
            create_inventory = False

        if self.molecule.state.multiple_platforms:
            self.command_args['platform'] = 'all'
        else:
            if ((self.command_args.get('platform') == 'all')
                    and self.molecule.state.created):
                create_instances = True
                create_inventory = True

        if create_instances and not idempotent:
            c = create.Create(self.args, self.command_args, self.molecule)
            c.execute()

        if create_inventory:
            self.molecule.create_inventory_file()

        d = dependency.Dependency(self.args, self.command_args, self.molecule)
        d.execute()

        ansible = ansible_playbook.AnsiblePlaybook(
            self.molecule.config.config['ansible'],
            self.molecule.driver.ansible_connection_params,
            raw_ansible_args=self.command_args.get('ansible_args'),
            debug=debug)

        if idempotent:
            # Don't log stdout/err
            ansible.remove_cli_arg('_out')
            ansible.remove_cli_arg('_err')
            # Idempotence task regexp cannot handle diff
            ansible.remove_cli_arg('diff')
            # Disable color for regexp
            ansible.add_env_arg('ANSIBLE_NOCOLOR', 'true')
            ansible.add_env_arg('ANSIBLE_FORCE_COLOR', 'false')

        if debug:
            ansible_env = {
                k: v
                for (k, v) in ansible.env.items() if 'ANSIBLE' in k
            }
            util.print_debug(
                'ANSIBLE ENVIRONMENT',
                yaml.dump(ansible_env, default_flow_style=False, indent=2))

        util.print_info('Starting Ansible Run ...')
        status, output = ansible.execute(hide_errors=hide_errors)
        if status is not None:
            if exit:
                util.sysexit(status)
            return status, None

        if not self.molecule.state.converged:
            self.molecule.state.change_state('converged', True)

        return None, output