Check mode support for 2 modules

Add check mode support for both tripleo_container_config_scripts and
tripleo_container_configs modules, and test them in check mode via
molecule.

Change-Id: I9667c581d9437ca6f210cb9ded9e189474d6641f
This commit is contained in:
Emilien Macchi 2020-09-25 01:12:56 -04:00
parent 4943feeec1
commit 18c880aac4
6 changed files with 27 additions and 13 deletions

View File

@ -72,14 +72,15 @@ def main():
config_data = args['config_data']
config_dir = args['config_dir']
for path, config in config_data.items():
# this is specific to how the files are written in config-download
mode = config.get('mode', '0600')
config_path = os.path.join(config_dir, path)
with open(config_path, "w") as config_file:
config_file.write(config['content'])
os.chmod(config_path, int(mode, 8))
results['changed'] = True
if not module.check_mode:
for path, config in config_data.items():
# this is specific to how the files are written in config-download
mode = config.get('mode', '0600')
config_path = os.path.join(config_dir, path)
with open(config_path, "w") as config_file:
config_file.write(config['content'])
os.chmod(config_path, int(mode, 8))
results['changed'] = True
module.exit_json(**results)

View File

@ -79,11 +79,12 @@ def main():
# Set parameters
config_data = args['config_data']
for path, config in config_data.items():
with open(path, "wb") as config_file:
config_file.write(json.dumps(config, indent=2).encode('utf-8'))
os.chmod(path, 0o600)
results['changed'] = True
if not module.check_mode:
for path, config in config_data.items():
with open(path, "wb") as config_file:
config_file.write(json.dumps(config, indent=2).encode('utf-8'))
os.chmod(path, 0o600)
results['changed'] = True
module.exit_json(**results)

View File

@ -14,6 +14,8 @@
content: "#!/bin/bash\npuppet apply"
mode: "0700"
config_dir: "{{ container_config_scripts_tmp_dir.path }}"
when:
- not ansible_check_mode|bool
- name: Check that container_puppet_apply.sh file was created with right permissions
stat:
path: "{{ container_config_scripts_tmp_dir.path }}/container_puppet_apply.sh"
@ -21,9 +23,13 @@
failed_when:
- not st_config.stat.exists
- not (st_config.stat.mode == '0700')
when:
- not ansible_check_mode|bool
- name: Check that container_puppet_apply.sh script is correct
slurp:
src: "{{ container_config_scripts_tmp_dir.path }}/container_puppet_apply.sh"
register: slurp_config
failed_when:
- ('puppet apply' not in slurp_config['content']|b64decode)
when:
- not ansible_check_mode|bool

View File

@ -45,6 +45,7 @@ scenario:
test_sequence:
- prepare
- converge
- check
verifier:
name: testinfra

View File

@ -25,9 +25,13 @@
register: st_config
failed_when:
- not st_config.stat.exists
when:
- not ansible_check_mode|bool
- name: Check that container_config1.json configuration is correct
slurp:
src: "/tmp/container_config1.json"
register: slurp_config
failed_when:
- ('ceilometer-polling' not in slurp_config['content']|b64decode)
when:
- not ansible_check_mode|bool

View File

@ -45,6 +45,7 @@ scenario:
test_sequence:
- prepare
- converge
- check
verifier:
name: testinfra