diff --git a/changelogs/fragments/5563-rax-scaling-group-sanity.yml b/changelogs/fragments/5563-rax-scaling-group-sanity.yml new file mode 100644 index 0000000000..310257f293 --- /dev/null +++ b/changelogs/fragments/5563-rax-scaling-group-sanity.yml @@ -0,0 +1,2 @@ +minor_changes: + - rax_scaling_group - refactored out code to the ``rax`` module utils to clear the sanity check (https://github.com/ansible-collections/community.general/pull/5563). diff --git a/plugins/module_utils/rax.py b/plugins/module_utils/rax.py index 2372088033..6331c0d1be 100644 --- a/plugins/module_utils/rax.py +++ b/plugins/module_utils/rax.py @@ -314,3 +314,21 @@ def setup_rax_module(module, rax_module, region_required=True): (region, ','.join(rax_module.regions))) return rax_module + + +def rax_scaling_group_personality_file(module, files): + if not files: + return [] + + results = [] + for rpath, lpath in files.items(): + lpath = os.path.expanduser(lpath) + try: + with open(lpath, 'r') as f: + results.append({ + 'path': rpath, + 'contents': f.read(), + }) + except Exception as e: + module.fail_json(msg='Failed to load %s: %s' % (lpath, str(e))) + return results diff --git a/plugins/modules/rax_scaling_group.py b/plugins/modules/rax_scaling_group.py index ef31cbb031..ed974ef0f9 100644 --- a/plugins/modules/rax_scaling_group.py +++ b/plugins/modules/rax_scaling_group.py @@ -161,8 +161,11 @@ except ImportError: HAS_PYRAX = False from ansible.module_utils.basic import AnsibleModule -from ansible_collections.community.general.plugins.module_utils.rax import (rax_argument_spec, rax_find_image, rax_find_network, - rax_required_together, rax_to_dict, setup_rax_module) +from ansible_collections.community.general.plugins.module_utils.rax import ( + rax_argument_spec, rax_find_image, rax_find_network, + rax_required_together, rax_to_dict, setup_rax_module, + rax_scaling_group_personality_file, +) from ansible.module_utils.six import string_types @@ -223,19 +226,7 @@ def rax_asg(module, cooldown=300, disk_config=None, files=None, flavor=None, del nic['net-id'] # Handle the file contents - personality = [] - if files: - for rpath in files.keys(): - lpath = os.path.expanduser(files[rpath]) - try: - f = open(lpath, 'r') - personality.append({ - 'path': rpath, - 'contents': f.read() - }) - f.close() - except Exception as e: - module.fail_json(msg='Failed to load %s' % lpath) + personality = rax_scaling_group_personality_file(module, files) lbs = [] if loadbalancers: diff --git a/tests/sanity/ignore-2.11.txt b/tests/sanity/ignore-2.11.txt index 2f6bf480c0..8ca3e163da 100644 --- a/tests/sanity/ignore-2.11.txt +++ b/tests/sanity/ignore-2.11.txt @@ -24,7 +24,6 @@ plugins/modules/puppet.py validate-modules:parameter-invalid # invalid alias - plugins/modules/rax_files_objects.py use-argspec-type-path plugins/modules/rax_files.py validate-modules:parameter-state-invalid-choice plugins/modules/rax.py use-argspec-type-path # fix needed -plugins/modules/rax_scaling_group.py use-argspec-type-path # fix needed, expanduser() applied to dict values plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice plugins/modules/scaleway_organization_info.py validate-modules:return-syntax-error plugins/modules/ssh_config.py use-argspec-type-path # Required since module uses other methods to specify path diff --git a/tests/sanity/ignore-2.12.txt b/tests/sanity/ignore-2.12.txt index 6499478916..9c1ccbf433 100644 --- a/tests/sanity/ignore-2.12.txt +++ b/tests/sanity/ignore-2.12.txt @@ -19,7 +19,6 @@ plugins/modules/puppet.py validate-modules:parameter-invalid # invalid alias - plugins/modules/rax_files_objects.py use-argspec-type-path plugins/modules/rax_files.py validate-modules:parameter-state-invalid-choice plugins/modules/rax.py use-argspec-type-path # fix needed -plugins/modules/rax_scaling_group.py use-argspec-type-path # fix needed, expanduser() applied to dict values plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice plugins/modules/scaleway_organization_info.py validate-modules:return-syntax-error plugins/modules/ssh_config.py use-argspec-type-path # Required since module uses other methods to specify path diff --git a/tests/sanity/ignore-2.13.txt b/tests/sanity/ignore-2.13.txt index 6499478916..9c1ccbf433 100644 --- a/tests/sanity/ignore-2.13.txt +++ b/tests/sanity/ignore-2.13.txt @@ -19,7 +19,6 @@ plugins/modules/puppet.py validate-modules:parameter-invalid # invalid alias - plugins/modules/rax_files_objects.py use-argspec-type-path plugins/modules/rax_files.py validate-modules:parameter-state-invalid-choice plugins/modules/rax.py use-argspec-type-path # fix needed -plugins/modules/rax_scaling_group.py use-argspec-type-path # fix needed, expanduser() applied to dict values plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice plugins/modules/scaleway_organization_info.py validate-modules:return-syntax-error plugins/modules/ssh_config.py use-argspec-type-path # Required since module uses other methods to specify path diff --git a/tests/sanity/ignore-2.14.txt b/tests/sanity/ignore-2.14.txt index ce92542bd1..edf15c5cfc 100644 --- a/tests/sanity/ignore-2.14.txt +++ b/tests/sanity/ignore-2.14.txt @@ -20,7 +20,6 @@ plugins/modules/puppet.py validate-modules:parameter-invalid # invalid alias - plugins/modules/rax_files_objects.py use-argspec-type-path plugins/modules/rax_files.py validate-modules:parameter-state-invalid-choice plugins/modules/rax.py use-argspec-type-path # fix needed -plugins/modules/rax_scaling_group.py use-argspec-type-path # fix needed, expanduser() applied to dict values plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice plugins/modules/scaleway_organization_info.py validate-modules:return-syntax-error plugins/modules/ssh_config.py use-argspec-type-path # Required since module uses other methods to specify path diff --git a/tests/sanity/ignore-2.15.txt b/tests/sanity/ignore-2.15.txt index ce92542bd1..edf15c5cfc 100644 --- a/tests/sanity/ignore-2.15.txt +++ b/tests/sanity/ignore-2.15.txt @@ -20,7 +20,6 @@ plugins/modules/puppet.py validate-modules:parameter-invalid # invalid alias - plugins/modules/rax_files_objects.py use-argspec-type-path plugins/modules/rax_files.py validate-modules:parameter-state-invalid-choice plugins/modules/rax.py use-argspec-type-path # fix needed -plugins/modules/rax_scaling_group.py use-argspec-type-path # fix needed, expanduser() applied to dict values plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice plugins/modules/scaleway_organization_info.py validate-modules:return-syntax-error plugins/modules/ssh_config.py use-argspec-type-path # Required since module uses other methods to specify path