def _get_instance_config(self, instance_name): instance_config_dict = util.safe_load_file( self._config.driver.instance_config) return next(item for item in instance_config_dict if item['instance'] == instance_name)
def test_reset_persists(state_instance): assert not state_instance.converged state_instance.change_state('converged', True) assert state_instance.converged state_instance.reset() assert not state_instance.converged d = util.safe_load_file(state_instance.state_file) assert not d.get('converged')
def test_safe_load_file(temp_dir): path = os.path.join(temp_dir.strpath, 'foo') util.write_file(path, 'foo: bar') assert {'foo': 'bar'} == util.safe_load_file(path)
def _get_instance_config(self, instance_name): instance_config_dict = util.safe_load_file(self._config.driver.instance_config) return next( item for item in instance_config_dict if item['instance'] == instance_name )
def test_write_inventory(temp_dir, ansible_instance): ansible_instance._write_inventory() assert os.path.isfile(ansible_instance.inventory_file) data = util.safe_load_file(ansible_instance.inventory_file) x = { 'ungrouped': { 'vars': {}, }, 'all': { 'hosts': { 'instance-1': { 'ansible_connection': 'docker', 'foo': 'bar', }, 'instance-2': { 'ansible_connection': 'docker', 'foo': 'bar', }, } }, 'bar': { 'hosts': { 'instance-1': { 'ansible_connection': 'docker', 'foo': 'bar', } }, 'children': { 'child1': { 'hosts': { 'instance-1': { 'ansible_connection': 'docker', 'foo': 'bar' }, } } } }, 'foo': { 'hosts': { 'instance-1': { 'ansible_connection': 'docker', 'foo': 'bar', }, 'instance-2': { 'ansible_connection': 'docker', 'foo': 'bar', }, }, 'children': { 'child1': { 'hosts': { 'instance-1': { 'ansible_connection': 'docker', 'foo': 'bar' }, } }, 'child2': { 'hosts': { 'instance-2': { 'ansible_connection': 'docker', 'foo': 'bar' }, } }, } }, 'baz': { 'hosts': { 'instance-2': { 'ansible_connection': 'docker', 'foo': 'bar', }, }, 'children': { 'child2': { 'hosts': { 'instance-2': { 'ansible_connection': 'docker', 'foo': 'bar' }, } }, } } } assert x == data
def _load_file(self): return util.safe_load_file(self.state_file)
def _get_instance_config(instance_name): instance_config_dict = safe_load_file( os.environ['MOLECULE_INSTANCE_CONFIG']) return next(item for item in instance_config_dict if item['instance'] == instance_name)
def test_write_inventory(temp_dir, _instance): _instance._write_inventory() assert os.path.isfile(_instance.inventory_file) data = util.safe_load_file(_instance.inventory_file) x = { 'ungrouped': { 'vars': {} }, 'bar': { 'hosts': { 'instance-1': { 'foo': 'bar', 'ansible_connection': 'docker' } }, 'children': { 'child1': { 'hosts': { 'instance-1': { 'foo': 'bar', 'ansible_connection': 'docker' } } } }, 'vars': { 'molecule_file': "{{ lookup('env', 'MOLECULE_FILE') }}", 'molecule_ephemeral_directory': "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}", 'molecule_scenario_directory': "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}", 'molecule_yml': "{{ lookup('file', molecule_file) | molecule_from_yaml }}", 'molecule_instance_config': "{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}", 'molecule_no_log': "{{ lookup('env', 'MOLECULE_NO_LOG') or not " "molecule_yml.provisioner.log|default(False) | bool }}", }, }, 'all': { 'hosts': { 'instance-1': { 'foo': 'bar', 'ansible_connection': 'docker' }, 'instance-2': { 'foo': 'bar', 'ansible_connection': 'docker' }, }, 'vars': { 'molecule_file': "{{ lookup('env', 'MOLECULE_FILE') }}", 'molecule_ephemeral_directory': "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}", 'molecule_scenario_directory': "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}", 'molecule_yml': "{{ lookup('file', molecule_file) | molecule_from_yaml }}", 'molecule_instance_config': "{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}", 'molecule_no_log': "{{ lookup('env', 'MOLECULE_NO_LOG') or not " "molecule_yml.provisioner.log|default(False) | bool }}", }, }, 'foo': { 'hosts': { 'instance-1': { 'foo': 'bar', 'ansible_connection': 'docker' }, 'instance-2': { 'foo': 'bar', 'ansible_connection': 'docker' }, }, 'children': { 'child1': { 'hosts': { 'instance-1': { 'foo': 'bar', 'ansible_connection': 'docker' } } }, 'child2': { 'hosts': { 'instance-2': { 'foo': 'bar', 'ansible_connection': 'docker' } } }, }, 'vars': { 'molecule_file': "{{ lookup('env', 'MOLECULE_FILE') }}", 'molecule_ephemeral_directory': "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}", 'molecule_scenario_directory': "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}", 'molecule_yml': "{{ lookup('file', molecule_file) | molecule_from_yaml }}", 'molecule_instance_config': "{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}", 'molecule_no_log': "{{ lookup('env', 'MOLECULE_NO_LOG') or not " "molecule_yml.provisioner.log|default(False) | bool }}", }, }, 'baz': { 'hosts': { 'instance-2': { 'foo': 'bar', 'ansible_connection': 'docker' } }, 'children': { 'child2': { 'hosts': { 'instance-2': { 'foo': 'bar', 'ansible_connection': 'docker' } } } }, 'vars': { 'molecule_file': "{{ lookup('env', 'MOLECULE_FILE') }}", 'molecule_ephemeral_directory': "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}", 'molecule_scenario_directory': "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}", 'molecule_yml': "{{ lookup('file', molecule_file) | molecule_from_yaml }}", 'molecule_instance_config': "{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}", 'molecule_no_log': "{{ lookup('env', 'MOLECULE_NO_LOG') or not " "molecule_yml.provisioner.log|default(False) | bool }}", }, }, } assert x == data
def test_safe_load_file(temp_dir): path = os.path.join(temp_dir.strpath, "foo") util.write_file(path, "foo: bar") assert {"foo": "bar"} == util.safe_load_file(path)
def test_write_inventory(temp_dir, _instance): _instance._write_inventory() assert os.path.isfile(_instance.inventory_file) data = util.safe_load_file(_instance.inventory_file) x = { "ungrouped": { "vars": {} }, "bar": { "hosts": { "instance-1": { "foo": "bar", "ansible_connection": "docker" } }, "children": { "child1": { "hosts": { "instance-1": { "foo": "bar", "ansible_connection": "docker" } } } }, "vars": { "molecule_file": "{{ lookup('env', 'MOLECULE_FILE') }}", "molecule_ephemeral_directory": "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}", "molecule_scenario_directory": "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}", "molecule_yml": "{{ lookup('file', molecule_file) | molecule_from_yaml }}", "molecule_instance_config": "{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}", "molecule_no_log": "{{ lookup('env', 'MOLECULE_NO_LOG') or not " "molecule_yml.provisioner.log|default(False) | bool }}", }, }, "all": { "hosts": { "instance-1": { "foo": "bar", "ansible_connection": "docker" }, "instance-2": { "foo": "bar", "ansible_connection": "docker" }, }, "vars": { "molecule_file": "{{ lookup('env', 'MOLECULE_FILE') }}", "molecule_ephemeral_directory": "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}", "molecule_scenario_directory": "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}", "molecule_yml": "{{ lookup('file', molecule_file) | molecule_from_yaml }}", "molecule_instance_config": "{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}", "molecule_no_log": "{{ lookup('env', 'MOLECULE_NO_LOG') or not " "molecule_yml.provisioner.log|default(False) | bool }}", }, }, "foo": { "hosts": { "instance-1": { "foo": "bar", "ansible_connection": "docker" }, "instance-2": { "foo": "bar", "ansible_connection": "docker" }, }, "children": { "child1": { "hosts": { "instance-1": { "foo": "bar", "ansible_connection": "docker" } } }, "child2": { "hosts": { "instance-2": { "foo": "bar", "ansible_connection": "docker" } } }, }, "vars": { "molecule_file": "{{ lookup('env', 'MOLECULE_FILE') }}", "molecule_ephemeral_directory": "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}", "molecule_scenario_directory": "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}", "molecule_yml": "{{ lookup('file', molecule_file) | molecule_from_yaml }}", "molecule_instance_config": "{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}", "molecule_no_log": "{{ lookup('env', 'MOLECULE_NO_LOG') or not " "molecule_yml.provisioner.log|default(False) | bool }}", }, }, "baz": { "hosts": { "instance-2": { "foo": "bar", "ansible_connection": "docker" } }, "children": { "child2": { "hosts": { "instance-2": { "foo": "bar", "ansible_connection": "docker" } } } }, "vars": { "molecule_file": "{{ lookup('env', 'MOLECULE_FILE') }}", "molecule_ephemeral_directory": "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}", "molecule_scenario_directory": "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}", "molecule_yml": "{{ lookup('file', molecule_file) | molecule_from_yaml }}", "molecule_instance_config": "{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}", "molecule_no_log": "{{ lookup('env', 'MOLECULE_NO_LOG') or not " "molecule_yml.provisioner.log|default(False) | bool }}", }, }, } assert is_subset(x, data)
msg = ("parsing config file '{}'.\n\n" '{}\n{}'.format(self.molecule_file, e.place, e.string)) util.sysexit_with_message(msg) <<<<<<< HEAD >>>>>>> 0fa82e7a3daa84ebd03d8af67403c6551113d3e4:molecule/config.py ======= ======= return base >>>>>>> b1eb06d375fd544a849fcf5c39f51dc334b87338:Rake/molecule/__GEMS_.py/__GEMS_.py/apt-py.git/commandinit.yaml/init.yml/config.py >>>>>>> e91355cf081d9dcd78efe38cdcc6f0353a1aa3ac def _set_env(self, env): env_file = self.args.get('env_file') if env_file and os.path.exists(env_file): env = env.copy() d = util.safe_load_file(env_file) for k, v in d.items(): env[k] = v return env return env def _get_defaults(self): return { 'dependency': { 'name': 'galaxy', 'enabled': True, 'options': {}, 'env': {}, },
def _parallelize_config(data): state = util.safe_load_file(os.environ['MOLECULE_STATE_FILE']) if state['is_parallel']: data['platforms'] = util._parallelize_platforms( data, state['run_uuid']) return data