From 5d406cffca4fe84f139ba9714d00ffefe20ec984 Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Mon, 10 Feb 2020 23:23:38 +0000 Subject: [PATCH] Bump minimum openstacksdk version when using os_network/dns_domain (#66952) With the addition of [a], the minimum openstacksdk version needs to be bumped to include [b], or the os_network module will return the error: TypeError: create_network() got an unexpected keyword argument 'dns_domain' To handle this, we fail the module if the dns_domain argument is used and the minimum openstacksdk version for that argument is not met. [a] https://github.com/ansible/ansible/commit/6c74e29618a6872bc0da66e4992cfcd9cebf6acc [b] https://github.com/openstack/openstacksdk/commit/a3e846e2b9301f4ae725e97b21b4313bfcc81d10 Fixes: #64495 Fixes: #64841 --- .../64495-os_network-openstacksdk-min.yml | 3 +++ .../modules/cloud/openstack/os_network.py | 24 +++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 changelogs/fragments/64495-os_network-openstacksdk-min.yml diff --git a/changelogs/fragments/64495-os_network-openstacksdk-min.yml b/changelogs/fragments/64495-os_network-openstacksdk-min.yml new file mode 100644 index 00000000000..7fd35acb785 --- /dev/null +++ b/changelogs/fragments/64495-os_network-openstacksdk-min.yml @@ -0,0 +1,3 @@ +bugfixes: + - bump the minimum openstacksdk version when os_network + uses the dns_domain argument diff --git a/lib/ansible/modules/cloud/openstack/os_network.py b/lib/ansible/modules/cloud/openstack/os_network.py index 79f4b0f9e35..3e036b5eecc 100644 --- a/lib/ansible/modules/cloud/openstack/os_network.py +++ b/lib/ansible/modules/cloud/openstack/os_network.py @@ -129,7 +129,7 @@ network: type: int sample: 0 dns_domain: - description: The DNS domain of a network resource. + description: The DNS domain of a network resource. Requires openstacksdk>=0.29. type: str sample: "sample.openstack.org." admin_state_up: @@ -197,12 +197,18 @@ def main(): provider_physical_network = module.params['provider_physical_network'] provider_network_type = module.params['provider_network_type'] provider_segmentation_id = module.params['provider_segmentation_id'] - project = module.params.get('project') - port_security_enabled = module.params.get('port_security_enabled') - mtu = module.params.get('mtu') - dns_domain = module.params.get('dns_domain') + project = module.params['project'] - sdk, cloud = openstack_cloud_from_module(module) + net_create_kwargs = { + 'port_security_enabled': module.params['port_security_enabled'], + 'mtu_size': module.params['mtu'] + } + + if module.params['dns_domain'] is not None: + sdk, cloud = openstack_cloud_from_module(module, min_version='0.29.0') + net_create_kwargs['dns_domain'] = module.params['dns_domain'] + else: + sdk, cloud = openstack_cloud_from_module(module) try: if project is not None: proj = cloud.get_project(project) @@ -228,13 +234,11 @@ def main(): if project_id is not None: net = cloud.create_network(name, shared, admin_state_up, external, provider, project_id, - port_security_enabled=port_security_enabled, - mtu_size=mtu, dns_domain=dns_domain) + **net_create_kwargs) else: net = cloud.create_network(name, shared, admin_state_up, external, provider, - port_security_enabled=port_security_enabled, - mtu_size=mtu, dns_domain=dns_domain) + **net_create_kwargs) changed = True else: changed = False