Exemple #1
0
def openstack_molecule_instance(temp_dir, temp_files, state_path_without_data):
    c = temp_files(fixtures=['molecule_openstack_v1_config'])
    m = core.Molecule(config.ConfigV1(configs=c), {})
    m.state = state.State(state_file=state_path_without_data)
    m.main()

    return m
Exemple #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
Exemple #3
0
    def main(self):
        if not os.path.exists(self.config.config['molecule']['molecule_dir']):
            os.makedirs(self.config.config['molecule']['molecule_dir'])

        self.state = state.State(
            state_file=self.config.config.get('molecule').get('state_file'))

        try:
            self.driver = self._get_driver()
        except basedriver.InvalidDriverSpecified:
            LOG.error("Invalid driver '{}'".format(self._get_driver_name()))
            # TODO(retr0h): Print valid drivers.
            util.sysexit()
        except basedriver.InvalidProviderSpecified:
            LOG.error("Invalid provider '{}'".format(self.args['provider']))
            self.args['provider'] = None
            self.args['platform'] = None
            self.driver = self._get_driver()
            self.print_valid_providers()
            util.sysexit()
        except basedriver.InvalidPlatformSpecified:
            LOG.error("Invalid platform '{}'".format(self.args['platform']))
            self.args['provider'] = None
            self.args['platform'] = None
            self.driver = self._get_driver()
            self.print_valid_platforms()
            util.sysexit()

        self.config.populate_instance_names(self.driver.platform)
        self._add_or_update_vars('group_vars')
        self._add_or_update_vars('host_vars')
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
Exemple #5
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
Exemple #6
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
Exemple #7
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
Exemple #8
0
def molecule_instance_with_env_expansion(temp_dir, temp_files,
                                         state_path_without_data):
    os.environ['MOLECULE_TEST_01'] = 'vagrant'
    os.environ['MOLECULE_TEST_02'] = 'ubuntu'
    os.environ['MOLECULE_TEST_03'] = 'trusty64'
    os.environ['MOLECULE_TEST_04'] = 'example1'
    os.environ['MOLECULE_TEST_05'] = 'append_platform_to_hostname'
    c = temp_files(fixtures=['molecule_vagrant_v1_config_using_env'])
    m = core.Molecule(config.ConfigV1(configs=c), {})
    m.state = state.State(state_file=state_path_without_data)
    m.main()

    return m
Exemple #9
0
def test_get_data_loads_existing_state_file(_instance, molecule_data,
                                            config_instance):
    data = {
        "converged": False,
        "created": True,
        "driver": None,
        "prepared": None
    }
    util.write_file(_instance._state_file, util.safe_dump(data))

    s = state.State(config_instance)

    assert not s.converged
    assert s.created
    assert not s.driver
    assert not s.prepared
Exemple #10
0
    def main(self):
        if not os.path.exists(self.config.config['molecule']['molecule_dir']):
            os.makedirs(self.config.config['molecule']['molecule_dir'])

        self.state = state.State(
            state_file=self.config.config.get('molecule').get('state_file'))

        try:
            self.driver = self._get_driver()
        except basedriver.InvalidDriverSpecified:
            LOG.error("Invalid driver '{}'".format(self._get_driver_name()))
            # TODO(retr0h): Print valid drivers.
            util.sysexit()
        except basedriver.InvalidProviderSpecified:
            LOG.error("Invalid provider '{}'".format(self.args['provider']))
            self.args['provider'] = None
            self.args['platform'] = None
            self.driver = self._get_driver()
            self.print_valid_providers()
            util.sysexit()
        except basedriver.InvalidPlatformSpecified:
            LOG.error("Invalid platform '{}'".format(self.args['platform']))
            self.args['provider'] = None
            self.args['platform'] = None
            self.driver = self._get_driver()
            self.print_valid_platforms()
            util.sysexit()

        # updates instances config with full machine names
        self.config.populate_instance_names(self.driver.platform)

        if self.args.get('debug'):
            util.print_debug(
                'RUNNING CONFIG',
                yaml.dump(self.config.config,
                          default_flow_style=False,
                          indent=2))

        self._add_or_update_vars('group_vars')
        self._add_or_update_vars('host_vars')
Exemple #11
0
 def state(self):
     return state.State(self)
Exemple #12
0
def _instance(config_instance):
    return state.State(config_instance)
Exemple #13
0
def state_instance_without_data(state_path_without_data):
    return state.State(state_file=state_path_without_data)
Exemple #14
0
def state_instance(state_path):
    return state.State(state_file=state_path)
Exemple #15
0
def test_get_data_loads_existing_state_file():
    d = os.path.dirname(os.path.abspath(__file__))
    f = os.path.join(d, 'support', 'state.yml')
    s = state.State(state_file=f)

    assert 'test' == s.created