Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
project_directory = trailing_instance._config.project_directory
for d in [
'.foo',
'.bar',
]:
os.mkdir(os.path.join(project_directory, d))
for f in [
'foo.yml',
'foo.yaml',
'foo.py',
'.foo/foo.yml',
'.bar/foo.yml',
]:
util.write_file(os.path.join(project_directory, f), '')
# NOTE(retr0h): Unit tests add a molecule.yml automatically.
assert 4 == len(trailing_instance._get_tests())
def test_execute(
mocker,
patched_logger_info,
_patched_ansible_prepare,
patched_config_validate,
config_instance,
):
pb = os.path.join(config_instance.scenario.directory, 'prepare.yml')
util.write_file(pb, '')
p = prepare.Prepare(config_instance)
p.execute()
x = [mocker.call("Scenario: 'default'"), mocker.call("Action: 'prepare'")]
assert x == patched_logger_info.mock_calls
_patched_ansible_prepare.assert_called_once_with()
assert config_instance.state.prepared
def test_execute_when_instances_already_prepared_but_force_provided(
mocker, patched_logger_warn, _patched_ansible_prepare, config_instance
):
pb = os.path.join(config_instance.scenario.directory, 'prepare.yml')
util.write_file(pb, '')
config_instance.state.change_state('prepared', True)
config_instance.command_args = {'force': True}
p = prepare.Prepare(config_instance)
p.execute()
_patched_ansible_prepare.assert_called_once_with()
def test_write_file(temp_dir):
dest_file = os.path.join(temp_dir.strpath, 'test_util_write_file.tmp')
contents = binascii.b2a_hex(os.urandom(15)).decode('utf-8')
util.write_file(dest_file, contents)
with util.open_file(dest_file) as stream:
data = stream.read()
x = '# Molecule managed\n\n{}'.format(contents)
assert x == data
def write_config(self):
"""
Writes the provisioner's config file to disk and returns None.
:return: None
"""
template = util.render_template(
self._get_config_template(), config_options=self.config_options
)
util.write_file(self.config_file, template)
if target in self.config.config['ansible']:
vars_target = self.config.config['ansible'][target]
else:
return
molecule_dir = self.config.config['molecule']['molecule_dir']
target_vars_path = os.path.join(molecule_dir, target)
if not os.path.exists(os.path.abspath(target_vars_path)):
os.mkdir(os.path.abspath(target_vars_path))
for target in vars_target.keys():
target_var_content = vars_target[target]
path = os.path.join(os.path.abspath(target_vars_path), target)
util.write_file(
path,
yaml.dump(
target_var_content,
default_flow_style=False,
explicit_start=True))
def write(self):
util.write_file(self.config_file, util.safe_dump(self.config))
if self.args.get('platform') == 'all':
self.driver.platform = 'all'
for group, subgroups in groups.iteritems():
inventory += '\n[{}]\n'.format(group)
for subgroup in subgroups:
instance_name = util.format_instance_name(
subgroup, self.driver.platform, self.driver.instances)
if instance_name:
inventory += '{}\n'.format(instance_name)
else:
inventory += '{}\n'.format(subgroup)
inventory_file = self.config.config['ansible']['inventory_file']
try:
util.write_file(inventory_file, inventory)
except IOError:
msg = 'WARNING: could not write inventory file {}.'.format(
inventory_file)
util.print_warn(msg)