def molecule_instance(temp_files, state_path_without_data):
    c = temp_files(fixtures=['molecule_vagrant_config'])
    m = core.Molecule(dict())
    m.config = config.Config(configs=c)
    m.state = state.State(state_file=state_path_without_data)

    return m
Beispiel #2
0
def molecule_instance(temp_dir, temp_files, state_path_without_data):
    c = temp_files(fixtures=['molecule_docker_config'])
    m = core.Molecule({})
    m.config = config.Config(configs=c)
    m.state = state.State(state_file=state_path_without_data)

    return m
Beispiel #3
0
def test_get_data_loads_existing_state_file(temp_dir, molecule_data):
    molecule_directory = pytest.helpers.molecule_directory()
    scenario_directory = os.path.join(molecule_directory, 'default')
    molecule_file = pytest.helpers.get_molecule_file(scenario_directory)
    ephemeral_directory = pytest.helpers.molecule_ephemeral_directory()
    state_file = os.path.join(ephemeral_directory, 'state.yml')

    os.makedirs(ephemeral_directory)

    data = {
        'converged': False,
        'created': True,
        'driver': None,
        'prepared': None,
    }
    util.write_file(state_file, util.safe_dump(data))

    pytest.helpers.write_molecule_file(molecule_file, molecule_data)
    c = config.Config(molecule_file)
    s = state.State(c)

    assert not s.converged
    assert s.created
    assert not s.driver
    assert not s.prepared
Beispiel #4
0
def get_configs(args, command_args):
    """
    Glob the current directory for Molecule config files, instantiate config
    objects, and returns a list.

    :param args: A dict of options, arguments and commands from the CLI.
    :param command_args: A dict of options passed to the subcommand from
     the CLI.
    :return: list
    """
    configs = [
        config.Config(
            molecule_file=os.path.abspath(c),
            args=args,
            command_args=command_args) for c in glob.glob(MOLECULE_GLOB)
    ]

    scenario_name = command_args.get('scenario_name')
    if scenario_name:
        configs = _filter_configs_for_scenario(scenario_name, configs)
        _verify_scenario_name(configs, scenario_name)

    _verify_configs(configs)

    return configs
Beispiel #5
0
def config_instance(temp_files):
    # TODO(retr0h): Rework molecule config so we can pass a generic
    # config here.  Molecule currently expects to find a 'vagrant'
    # key in this dict.
    c = temp_files(fixtures=['molecule_vagrant_config'])

    return config.Config(configs=c)
Beispiel #6
0
    def test_merge_molecule_config_files(self):
        c = config.Config()
        c.load_defaults_file()
        c.merge_molecule_config_files(paths=[self.temp])

        self.assertEqual(c.config['molecule']['molecule_dir'],
                         '.test_molecule')
Beispiel #7
0
    def test_merge_molecule_file(self):
        c = config.Config()
        c.load_defaults_file()
        c.merge_molecule_file(molecule_file=self.temp)

        self.assertEqual(c.config['molecule']['molecule_dir'],
                         '.test_molecule')
Beispiel #8
0
def test_combine_local_config_overrides_default_and_project_config(temp_files):
    c = temp_files(fixtures=['default_config_data', 'project_config_data',
                             'local_config_data'])
    config_instance = config.Config(configs=c).config

    assert 'local-override' == config_instance['foo']
    assert 'local-override' == config_instance['baz']
Beispiel #9
0
def molecule_instance(temp_files, state_path):
    c = temp_files(fixtures=['molecule_openstack_config'])
    m = core.Molecule(dict())
    m.config = config.Config(configs=c)
    m._state = state.State(state_file=state_path)

    return m
Beispiel #10
0
def molecule_instance(temp_files, molecule_args):
    c = temp_files(fixtures=['molecule_vagrant_config'])
    m = core.Molecule(molecule_args)
    m.config = config.Config(configs=c)
    m.main()

    return m
Beispiel #11
0
    def test_populate_instance_names(self):
        c = config.Config()
        c.load_defaults_file()
        c.merge_molecule_file(molecule_file=self.temp)
        c.populate_instance_names('rhel-7')

        self.assertEqual(c.config['vagrant']['instances'][0]['vm_name'],
                         'aio-01-rhel-7')
Beispiel #12
0
    def test_update_ansible_defaults(self):
        c = config.Config()
        c.load_defaults_file()
        c.merge_molecule_file(molecule_file=self.temp)

        self.assertEqual(c.config['ansible']['inventory_file'],
                         'test_inventory')
        self.assertEqual(c.config['ansible']['config_file'], 'test_config')
Beispiel #13
0
def molecule_default_provider_instance(temp_files, state_path_without_data,
                                       molecule_args):
    c = temp_files(fixtures=['molecule_vagrant_config'])
    m = core.Molecule(molecule_args)
    m.config = config.Config(configs=c)
    m.state = state.State(state_file=state_path_without_data)
    m.main()

    return m
Beispiel #14
0
def config_instance(molecule_file_fixture, molecule_data, request):
    mdc = copy.deepcopy(molecule_data)
    if hasattr(request, 'param'):
        util.merge_dicts(mdc, request.getfuncargvalue(request.param))
    pytest.helpers.write_molecule_file(molecule_file_fixture, mdc)
    c = config.Config(molecule_file_fixture)
    c.command_args = {'subcommand': 'test'}

    return c
Beispiel #15
0
def config_instance(molecule_file_fixture, molecule_data, request):
    mdc = copy.deepcopy(molecule_data)
    if hasattr(request, "param"):
        mdc = util.merge_dicts(mdc, request.getfixturevalue(request.param))
    pytest.helpers.write_molecule_file(molecule_file_fixture, mdc)
    c = config.Config(molecule_file_fixture)
    c.command_args = {"subcommand": "test"}

    return c
Beispiel #16
0
    def __init__(self, args):
        """
        Initialize a new molecule class, and returns None.

        :param args: A dict of options, arguments and commands from the CLI.
        :returns: None
        """
        self.env = os.environ.copy()
        self.args = args
        self.config = config.Config()
        self._verifier = self._get_verifier()
        self._verifier_options = self._get_verifier_options()
Beispiel #17
0
def config_instance(
    molecule_file_fixture: str, molecule_data, request
) -> Generator[config.Config, None, None]:
    mdc = copy.deepcopy(molecule_data)
    if hasattr(request, "param"):
        mdc = util.merge_dicts(mdc, request.getfixturevalue(request.param))
    write_molecule_file(molecule_file_fixture, mdc)

    _environ = dict(os.environ)
    c = config.Config(molecule_file_fixture)
    c.command_args = {"subcommand": "test"}
    yield c
    # restore environ which can be modified by Config()
    os.environ.clear()
    os.environ.update(_environ)
Beispiel #18
0
    def test_build_easy_paths(self):
        c = config.Config()
        c.load_defaults_file()
        c.build_easy_paths()

        self.assertEqual(c.config['molecule']['state_file'],
                         os.path.join('.molecule', 'state'))
        self.assertEqual(c.config['molecule']['vagrantfile_file'],
                         os.path.join('.molecule', 'vagrantfile'))
        self.assertEqual(c.config['molecule']['rakefile_file'],
                         os.path.join('.molecule', 'rakefile'))
        self.assertEqual(c.config['molecule']['config_file'],
                         os.path.join('.molecule', 'ansible.cfg'))
        self.assertEqual(c.config['molecule']['inventory_file'],
                         os.path.join('.molecule', 'ansible_inventory'))
Beispiel #19
0
def get_configs(args, command_args):
    """
    Glob the current directory for Molecule config files, instantiate config
    objects, and returns a list.

    :param args: A dict of options, arguments and commands from the CLI.
    :param command_args: A dict of options passed to the subcommand from
     the CLI.
    :return: list
    """
    configs = [
        config.Config(
            molecule_file=util.abs_path(c),
            args=args,
            command_args=command_args) for c in glob.glob(MOLECULE_GLOB)
    ]
    _verify_configs(configs)

    return configs
Beispiel #20
0
def get_configs(args, command_args, ansible_args=(), glob_str=MOLECULE_GLOB):
    """
    Glob the current directory for Molecule config files, instantiate config \
    objects, and returns a list.

    :param args: A dict of options, arguments and commands from the CLI.
    :param command_args: A dict of options passed to the subcommand from
     the CLI.
    :param ansible_args: An optional tuple of arguments provided to the
     `ansible-playbook` command.
    :return: list
    """
    configs = [
        config.Config(
            molecule_file=util.abs_path(c),
            args=args,
            command_args=command_args,
            ansible_args=ansible_args,
        ) for c in glob.glob(glob_str)
    ]
    _verify_configs(configs, glob_str)

    return configs
Beispiel #21
0
 def __init__(self, args):
     self._provisioned = False
     self._env = os.environ.copy()
     self._args = args
     self._config = config.Config()
     self._provisioner = None
Beispiel #22
0
def test_combine_default_config(temp_files):
    c = temp_files(fixtures=['default_config_data'])
    config_instance = config.Config(configs=c).config

    assert 'bar' == config_instance['foo']
    assert 'qux' == config_instance['baz']
Beispiel #23
0
def test_build_config_paths_preserves_full_path(temp_files):
    confs = temp_files(fixtures=['build_config_paths_molecule_data'])
    c = config.Config(configs=confs)

    assert '/full/path/vagrantfile_file' == c.config['molecule'][
        'vagrantfile_file']
Beispiel #24
0
    def test_load_defaults_external_file(self):
        c = config.Config()
        c.load_defaults_file(defaults_file=self.temp)

        self.assertEqual(c.config['molecule']['molecule_dir'],
                         '.test_molecule')
Beispiel #25
0
    def test_load_defaults_file(self):
        c = config.Config()
        c.load_defaults_file()

        self.assertEqual(c.config['molecule']['molecule_dir'], '.molecule')
Beispiel #26
0
def instance_with_scenario_name(molecule_file, instance_name):
    c = config.Config(molecule_file)

    return util.instance_with_scenario_name(instance_name, c.scenario.name)
Beispiel #27
0
 def __init__(self, args):
     self._env = os.environ.copy()
     self._args = args
     self._driver = None
     self.config = config.Config()
def ansible_galaxy_instance(temp_files):
    confs = temp_files(fixtures=['molecule_vagrant_config'])
    c = config.Config(configs=confs)
    c.config['ansible']['requirements_file'] = 'requirements.yml'

    return ansible_galaxy.AnsibleGalaxy(c.config)
Beispiel #29
0
def config_instance(molecule_file_fixture, molecule_data):
    pytest.helpers.write_molecule_file(molecule_file_fixture, molecule_data)

    return config.Config(molecule_file_fixture)
Beispiel #30
0
def molecule_instance(temp_files):
    c = temp_files(fixtures=['molecule_docker_config'])
    m = core.Molecule(dict())
    m.config = config.Config(configs=c)

    return m