From e9a190e9c19cb4898c2f264be099f625f77a5f14 Mon Sep 17 00:00:00 2001 From: "Jesse Pretorius (odyssey4me)" Date: Wed, 19 Feb 2020 15:12:52 +0000 Subject: [PATCH] [backport 2.8] Bump min openstacksdk version for os_network/port_security_enabled To make use of the port_security_enabled [a] parameter, [b] needs to be present in the openstacksdk or the os_network module will return an error like: TypeError: create_network() got an unexpected keyword argument 'port_security_enabled' To handle this, we fail the module if one of the arguments are used and the minimum openstacksdk version for that argument is not met. [a] https://github.com/ansible/ansible/commit/eaf238b033a0504c48440cf85982a2b89851059d [b] https://github.com/openstack/openstacksdk/commit/8eb788af07ed88166db7b8a58ce1fecacd7a29b1 Backport-of: https://review.opendev.org/708119 Fixes: #62062 --- .../62062-os_network-openstacksdk-min.yml | 3 +++ lib/ansible/module_utils/openstack.py | 5 +++++ .../modules/cloud/openstack/os_network.py | 16 +++++++++++----- 3 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/62062-os_network-openstacksdk-min.yml diff --git a/changelogs/fragments/62062-os_network-openstacksdk-min.yml b/changelogs/fragments/62062-os_network-openstacksdk-min.yml new file mode 100644 index 00000000000..abefe32a763 --- /dev/null +++ b/changelogs/fragments/62062-os_network-openstacksdk-min.yml @@ -0,0 +1,3 @@ +bugfixes: + - Bump the minimum openstacksdk version to 0.18.0 when os_network + uses the port_security_enabled argument. diff --git a/lib/ansible/module_utils/openstack.py b/lib/ansible/module_utils/openstack.py index 9a74890ba59..1ac6c628e31 100644 --- a/lib/ansible/module_utils/openstack.py +++ b/lib/ansible/module_utils/openstack.py @@ -117,6 +117,11 @@ def openstack_cloud_from_module(module, min_version='0.12.0'): except ImportError: module.fail_json(msg='openstacksdk is required for this module') + if min_version: + min_version = max(StrictVersion('0.12.0'), StrictVersion(min_version)) + else: + min_version = StrictVersion('0.12.0') + if min_version: if StrictVersion(sdk.version.__version__) < StrictVersion(min_version): module.fail_json( diff --git a/lib/ansible/modules/cloud/openstack/os_network.py b/lib/ansible/modules/cloud/openstack/os_network.py index 9553e76498f..7fa11e872f7 100644 --- a/lib/ansible/modules/cloud/openstack/os_network.py +++ b/lib/ansible/modules/cloud/openstack/os_network.py @@ -73,7 +73,7 @@ options: description: - Whether port security is enabled on the network or not. Network will use OpenStack defaults if this option is - not utilised. + not utilised. Requires openstacksdk>=0.18. type: bool version_added: "2.8" requirements: @@ -179,9 +179,15 @@ def main(): 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') - sdk, cloud = openstack_cloud_from_module(module) + net_create_kwargs = {} + min_version = None + + if module.params['port_security_enabled'] is not None: + min_version = '0.18.0' + net_create_kwargs['port_security_enabled'] = module.params['port_security_enabled'] + + sdk, cloud = openstack_cloud_from_module(module, min_version) try: if project is not None: proj = cloud.get_project(project) @@ -207,11 +213,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) + **net_create_kwargs) else: net = cloud.create_network(name, shared, admin_state_up, external, provider, - port_security_enabled=port_security_enabled) + **net_create_kwargs) changed = True else: changed = False