From 8b2abfe446007a2527cc05c1e215fec575b1312f Mon Sep 17 00:00:00 2001 From: Deepak Agrawal Date: Fri, 10 Aug 2018 10:31:03 +0530 Subject: [PATCH] openvswitch_db : Handle column value conversion and idempotency in no_key case (#43869) * change column value to string. handle idempotency in no key case * fix unit test failures in baseline (cherry picked from commit 8eaebf86b623c42c8e5a03ff63cd4fd4553f8c95) --- lib/ansible/modules/network/ovs/openvswitch_db.py | 13 ++++++------- .../targets/openvswitch_db/tests/basic.yaml | 7 +++++-- .../modules/network/ovs/test_openvswitch_db.py | 4 ++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/ansible/modules/network/ovs/openvswitch_db.py b/lib/ansible/modules/network/ovs/openvswitch_db.py index a13486126a..bbb8f58242 100644 --- a/lib/ansible/modules/network/ovs/openvswitch_db.py +++ b/lib/ansible/modules/network/ovs/openvswitch_db.py @@ -120,15 +120,14 @@ def map_obj_to_commands(want, have, module): "%(col)s" commands.append(templatized_command % module.params) else: + if want == have: + # Nothing to commit + return commands if module.params['key'] is None: templatized_command = "%(ovs-vsctl)s -t %(timeout)s set %(table)s %(record)s " \ "%(col)s=%(value)s" commands.append(templatized_command % module.params) - elif 'key' not in have.keys(): - templatized_command = "%(ovs-vsctl)s -t %(timeout)s add %(table)s %(record)s " \ - "%(col)s %(key)s=%(value)s" - commands.append(templatized_command % module.params) - elif want['value'] != have['value']: + else: templatized_command = "%(ovs-vsctl)s -t %(timeout)s set %(table)s %(record)s " \ "%(col)s:%(key)s=%(value)s" commands.append(templatized_command % module.params) @@ -171,7 +170,7 @@ def map_config_to_obj(module): obj['key'] = module.params['key'] obj['value'] = col_value_to_dict[module.params['key']] else: - obj['value'] = col_value.strip() + obj['value'] = str(col_value.strip()) return obj @@ -199,7 +198,7 @@ def main(): 'record': {'required': True}, 'col': {'required': True}, 'key': {'required': False}, - 'value': {'required': True}, + 'value': {'required': True, 'type': 'str'}, 'timeout': {'default': 5, 'type': 'int'}, } diff --git a/test/integration/targets/openvswitch_db/tests/basic.yaml b/test/integration/targets/openvswitch_db/tests/basic.yaml index 9447715c7c..97bec654b8 100644 --- a/test/integration/targets/openvswitch_db/tests/basic.yaml +++ b/test/integration/targets/openvswitch_db/tests/basic.yaml @@ -64,7 +64,8 @@ table: Bridge record: br-test col: stp_enable - value: true + value: 'true' + become: yes register: result - assert: @@ -76,7 +77,8 @@ table: Bridge record: br-test col: stp_enable - value: true + value: 'true' + become: yes register: result - assert: @@ -90,6 +92,7 @@ record: br-test col: other_config value: true + become: yes register: result - assert: diff --git a/test/units/modules/network/ovs/test_openvswitch_db.py b/test/units/modules/network/ovs/test_openvswitch_db.py index 88efe1e7a3..87a883b89e 100644 --- a/test/units/modules/network/ovs/test_openvswitch_db.py +++ b/test/units/modules/network/ovs/test_openvswitch_db.py @@ -114,8 +114,8 @@ class TestOpenVSwitchDBModule(TestOpenVSwitchModule): value='True')) self.execute_module( changed=True, - commands=['/usr/bin/ovs-vsctl -t 5 add Bridge test-br other_config' - ' disable-in-band=True'], + commands=['/usr/bin/ovs-vsctl -t 5 set Bridge test-br other_config' + ':disable-in-band=True'], test_name='test_openvswitch_db_present_adds_key') def test_openvswitch_db_present_updates_key(self):