Migrating networks_info from AnsibleModule to OpenStackModule

Migrated networks_info module to OpenStackModule and updated playbook to test the module in CI jobs. Added deprecated_names tyo module.
Removed "ansible-deprecated-no-collection-name" exception for networks_info for ansible 2.10 and 2.11. Reverted 'False' to 'false' and updated filters (case sensitive) to check for 'False' instead

Change-Id: I85e19f0db8b4ee549137249477d0b7f5d82e9865
This commit is contained in:
frenzy_friday 2020-11-23 18:37:14 +01:00 committed by Shnaidman Sagi
parent 15675ce23f
commit d36ac1f125
4 changed files with 34 additions and 25 deletions

View File

@ -7,6 +7,21 @@
shared: "{{ network_shared }}"
external: "{{ network_external }}"
- name: Gather networks info
openstack.cloud.networks_info:
cloud: "{{ cloud }}"
name: "{{ network_name }}"
filters:
shared: "{{ network_shared|string|capitalize }}"
register: result
- name: Verify networks info
assert:
that:
- "result.openstack_networks.0.name == network_name"
- "(result.openstack_networks.0.shared|lower) == (network_shared|lower)"
- "result.openstack_networks[0]['router:external'] == {{ network_external }}"
- name: Delete network
openstack.cloud.network:
cloud: "{{ cloud }}"

View File

@ -113,37 +113,33 @@ openstack_networks:
type: bool
'''
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import (
openstack_full_argument_spec,
openstack_cloud_from_module,
)
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
def main():
class NetworkInfoModule(OpenStackModule):
argument_spec = openstack_full_argument_spec(
deprecated_names = ('networks_facts', 'openstack.cloud.networks_facts')
argument_spec = dict(
name=dict(required=False, default=None),
filters=dict(required=False, type='dict', default=None)
)
module = AnsibleModule(argument_spec)
is_old_facts = module._name == 'openstack.cloud.networks_facts'
if is_old_facts:
module.deprecate("The 'openstack.cloud.networks_facts' module has been renamed to 'openstack.cloud.networks_info', "
"and the renamed one no longer returns ansible_facts", version='2.13')
sdk, cloud = openstack_cloud_from_module(module)
try:
networks = cloud.search_networks(module.params['name'],
module.params['filters'])
if is_old_facts:
module.exit_json(changed=False, ansible_facts=dict(
openstack_networks=networks))
else:
module.exit_json(changed=False, openstack_networks=networks)
def run(self):
except sdk.exceptions.OpenStackCloudException as e:
module.fail_json(msg=str(e))
kwargs = self.check_versioned(
filters=self.params['filters']
)
if self.params['name']:
kwargs['name_or_id'] = self.params['name']
networks = self.conn.search_networks(**kwargs)
self.exit(changed=False, openstack_networks=networks)
def main():
module = NetworkInfoModule()
module()
if __name__ == '__main__':

View File

@ -2,7 +2,6 @@ plugins/modules/compute_flavor_info.py pylint:ansible-deprecated-no-collection-n
plugins/modules/identity_domain_info.py pylint:ansible-deprecated-no-collection-name
plugins/modules/identity_user_info.py pylint:ansible-deprecated-no-collection-name
plugins/modules/image_info.py pylint:ansible-deprecated-no-collection-name
plugins/modules/networks_info.py pylint:ansible-deprecated-no-collection-name
plugins/modules/port_info.py pylint:ansible-deprecated-no-collection-name
plugins/modules/project_info.py pylint:ansible-deprecated-no-collection-name
plugins/modules/subnets_info.py pylint:ansible-deprecated-no-collection-name

View File

@ -2,7 +2,6 @@ plugins/modules/compute_flavor_info.py pylint:ansible-deprecated-no-collection-n
plugins/modules/identity_domain_info.py pylint:ansible-deprecated-no-collection-name
plugins/modules/identity_user_info.py pylint:ansible-deprecated-no-collection-name
plugins/modules/image_info.py pylint:ansible-deprecated-no-collection-name
plugins/modules/networks_info.py pylint:ansible-deprecated-no-collection-name
plugins/modules/port_info.py pylint:ansible-deprecated-no-collection-name
plugins/modules/project_info.py pylint:ansible-deprecated-no-collection-name
plugins/modules/subnets_info.py pylint:ansible-deprecated-no-collection-name