ansible / ansible-builder

An Ansible execution environment builder
Other
292 stars 97 forks source link

Systematically test that collection imports work #49

Open AlanCoding opened 4 years ago

AlanCoding commented 4 years ago

We need integration testing for this obviously, and we don't yet have a framework for that.

Throwing an idea out into the possibilities:

Introduce custom module which will attempt to import a variable or module, given in parameters.

Do the relatively simple task of cataloging the HAS_* variables in each collection, ex:

$ grep -r "HAS_.*=" theforeman/foreman/
theforeman/foreman//plugins/module_utils/foreman_helper.py:    HAS_APYPIE = True
theforeman/foreman//plugins/module_utils/foreman_helper.py:    HAS_APYPIE = False
theforeman/foreman//plugins/module_utils/foreman_helper.py:    HAS_PYYAML = True
theforeman/foreman//plugins/module_utils/foreman_helper.py:    HAS_PYYAML = False
theforeman/foreman//plugins/callback/foreman.py:    HAS_REQUESTS = True
theforeman/foreman//plugins/callback/foreman.py:    HAS_REQUESTS = False
theforeman/foreman//plugins/modules/subnet.py:    HAS_IPADDRESS = True
theforeman/foreman//plugins/modules/subnet.py:    HAS_IPADDRESS = False
theforeman/foreman//plugins/modules/content_upload.py:    HAS_DEBFILE = True
theforeman/foreman//plugins/modules/content_upload.py:    HAS_DEBFILE = False
theforeman/foreman//plugins/modules/content_upload.py:    HAS_RPM = True
theforeman/foreman//plugins/modules/content_upload.py:    HAS_RPM = False
$ grep -r "HAS_.*=" community/vmware/
community/vmware//plugins/connection/vmware_tools.py:    HAS_REQUESTS = True
community/vmware//plugins/connection/vmware_tools.py:    HAS_REQUESTS = False
community/vmware//plugins/connection/vmware_tools.py:    HAS_URLLIB3 = True
community/vmware//plugins/connection/vmware_tools.py:        HAS_URLLIB3 = True
community/vmware//plugins/connection/vmware_tools.py:        HAS_URLLIB3 = False
community/vmware//plugins/connection/vmware_tools.py:    HAS_PYVMOMI = True
community/vmware//plugins/connection/vmware_tools.py:    HAS_PYVMOMI = False
community/vmware//plugins/inventory/vmware_vm_inventory.py:    HAS_REQUESTS = True
community/vmware//plugins/inventory/vmware_vm_inventory.py:    HAS_REQUESTS = False
community/vmware//plugins/inventory/vmware_vm_inventory.py:    HAS_PYVMOMI = True
community/vmware//plugins/inventory/vmware_vm_inventory.py:    HAS_PYVMOMI = False
community/vmware//plugins/inventory/vmware_vm_inventory.py:    HAS_VSPHERE = True
community/vmware//plugins/inventory/vmware_vm_inventory.py:    HAS_VSPHERE = False
community/vmware//plugins/module_utils/vmware.py:    HAS_REQUESTS = True
community/vmware//plugins/module_utils/vmware.py:    HAS_REQUESTS = False
community/vmware//plugins/module_utils/vmware.py:    HAS_PYVMOMI = True
community/vmware//plugins/module_utils/vmware.py:    HAS_PYVMOMIJSON = hasattr(VmomiSupport, 'VmomiJSONEncoder')
community/vmware//plugins/module_utils/vmware.py:    HAS_PYVMOMI = False
community/vmware//plugins/module_utils/vmware.py:    HAS_PYVMOMIJSON = False
community/vmware//plugins/module_utils/vmware_rest_client.py:    HAS_REQUESTS = True
community/vmware//plugins/module_utils/vmware_rest_client.py:    HAS_REQUESTS = False
community/vmware//plugins/module_utils/vmware_rest_client.py:    HAS_PYVMOMI = True
community/vmware//plugins/module_utils/vmware_rest_client.py:    HAS_PYVMOMI = False
community/vmware//plugins/module_utils/vmware_rest_client.py:    HAS_VSPHERE = True
community/vmware//plugins/module_utils/vmware_rest_client.py:    HAS_VSPHERE = False
community/vmware//plugins/module_utils/vca.py:    HAS_PYVCLOUD = True
community/vmware//plugins/module_utils/vca.py:    HAS_PYVCLOUD = False
community/vmware//plugins/modules/vmware_content_deploy_template.py:HAS_VAUTOMATION_PYTHON_SDK = False
community/vmware//plugins/modules/vmware_content_deploy_template.py:    HAS_VAUTOMATION_PYTHON_SDK = True
community/vmware//plugins/modules/vmware_guest_facts.py:    HAS_VSPHERE = True
community/vmware//plugins/modules/vmware_guest_facts.py:    HAS_VSPHERE = False
community/vmware//plugins/modules/vmware_guest.py:HAS_PYVMOMI = False
community/vmware//plugins/modules/vmware_guest.py:    HAS_PYVMOMI = True
community/vmware//plugins/modules/vmware_vm_vss_dvs_migrate.py:    HAS_PYVMOMI = True
community/vmware//plugins/modules/vmware_vm_vss_dvs_migrate.py:    HAS_PYVMOMI = False
community/vmware//plugins/modules/vmware_content_library_manager.py:HAS_VAUTOMATION_PYTHON_SDK = False
community/vmware//plugins/modules/vmware_content_library_manager.py:    HAS_VAUTOMATION_PYTHON_SDK = True
community/vmware//plugins/modules/vmware_guest_info.py:    HAS_VSPHERE = True
community/vmware//plugins/modules/vmware_guest_info.py:    HAS_VSPHERE = False
community/vmware//plugins/modules/vmware_resource_pool.py:    HAS_PYVMOMI = True
community/vmware//plugins/modules/vmware_resource_pool.py:    HAS_PYVMOMI = False
community/vmware//plugins/modules/vmware_content_deploy_ovf_template.py:HAS_VAUTOMATION_PYTHON_SDK = False
community/vmware//plugins/modules/vmware_content_deploy_ovf_template.py:    HAS_VAUTOMATION_PYTHON_SDK = True
community/vmware//plugins/modules/vmware_vsan_cluster.py:    HAS_PYVMOMI = True
community/vmware//plugins/modules/vmware_vsan_cluster.py:    HAS_PYVMOMI = False
community/vmware//plugins/modules/vmware_migrate_vmk.py:    HAS_PYVMOMI = True
community/vmware//plugins/modules/vmware_migrate_vmk.py:    HAS_PYVMOMI = False
community/vmware//plugins/modules/vmware_dvs_host.py:    HAS_COLLECTIONS_COUNTER = True
community/vmware//plugins/modules/vmware_dvs_host.py:    HAS_COLLECTIONS_COUNTER = False
community/vmware//plugins/modules/vmware_dns_config.py:    HAS_PYVMOMI = True
community/vmware//plugins/modules/vmware_dns_config.py:    HAS_PYVMOMI = False
community/vmware//plugins/modules/vmware_vsan_health_info.py:    HAS_PYVMOMI = True
community/vmware//plugins/modules/vmware_vsan_health_info.py:    HAS_PYVMOMIJSON = hasattr(VmomiSupport, 'VmomiJSONEncoder')
community/vmware//plugins/modules/vmware_vsan_health_info.py:    HAS_PYVMOMI = False
community/vmware//plugins/modules/vmware_vsan_health_info.py:    HAS_PYVMOMIJSON = False
community/vmware//plugins/modules/vmware_vsan_health_info.py:    HAS_VSANPYTHONSDK = True
community/vmware//plugins/modules/vmware_vsan_health_info.py:    HAS_VSANPYTHONSDK = False
community/vmware//plugins/modules/vmware_vmkernel_ip_config.py:    HAS_PYVMOMI = True
community/vmware//plugins/modules/vmware_vmkernel_ip_config.py:    HAS_PYVMOMI = False

You can see that some of these may be easier than others. However, even between the two of these, there are only a tiny handful of unique HAS_ variables. While those are duplicated a lot, they tend to still have definitions in module_utils.

The re-definition in individual modules like:

https://github.com/ansible-collections/vmware/blob/main/plugins/modules/vmware_vsan_health_info.py#L105

seem to be completely unnecessary and could be removed. So that supports the argument that we could just focus on verifying that the HAS_ variables from module_utils are True.

AlanCoding commented 3 years ago

Put up a demo at:

https://github.com/AlanCoding/collection-dependencies-demo/tree/master/ee_imports

Still no clear plans for how something like this might be used. This is only an idea.