commit 4de71152472d3fafe1b4b8d76ea3369323d620fd Author: Steve Baker Date: Thu Sep 24 13:00:00 2020 +1200 Handle out-of-tree openstack module_utils ansible.module_utils.openstack will exist during ansible runtime due to ansible's runtime package renaming of module_utils. However with ansible-2.10 the openstack collection[1] is no longer in the ansible tree, so the unit tests will fail due to the missing package. This change works around this by handling import failure and adding a check in main() to fail if the openstack module_utils is not available. The unit tests deliberately don't test main() to avoid dealing with ansible internals. NOTE: Also explicitly enables the iscsi deployment interface as it has been deprecated and is no longer enabled by default. [1] https://opendev.org/openstack/ansible-collections-openstack Change-Id: I2d03696d673e74f0d4e6609532a8add1c0725f91 diff --git a/.zuul.yaml b/.zuul.yaml index 0c566dc..c0ecd45 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -147,6 +147,7 @@ vars: devstack_localrc: IRONIC_DEFAULT_DEPLOY_INTERFACE: iscsi + IRONIC_ENABLED_DEPLOY_INTERFACES: "iscsi,direct,fake" metalsmith_netboot: true metalsmith_precreate_port: true diff --git a/metalsmith_ansible/ansible_plugins/modules/metalsmith_instances.py b/metalsmith_ansible/ansible_plugins/modules/metalsmith_instances.py index a8d75f7..f1c3fca 100644 --- a/metalsmith_ansible/ansible_plugins/modules/metalsmith_instances.py +++ b/metalsmith_ansible/ansible_plugins/modules/metalsmith_instances.py @@ -18,9 +18,14 @@ import io import logging from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.openstack import openstack_cloud_from_module -from ansible.module_utils.openstack import openstack_full_argument_spec -from ansible.module_utils.openstack import openstack_module_kwargs +try: + from ansible.module_utils.openstack import openstack_cloud_from_module + from ansible.module_utils.openstack import openstack_full_argument_spec + from ansible.module_utils.openstack import openstack_module_kwargs +except ImportError: + openstack_cloud_from_module = None + openstack_full_argument_spec = None + openstack_module_kwargs = None import metalsmith from metalsmith import instance_config @@ -364,6 +369,10 @@ def _configure_logging(log_level): def main(): + if not openstack_full_argument_spec: + raise RuntimeError( + 'This module requires ansible-collections-openstack') + argument_spec = openstack_full_argument_spec( **yaml.safe_load(DOCUMENTATION)['options'] )