From d1d0cd540607408122af914ad97fdf98d74a5fe6 Mon Sep 17 00:00:00 2001 From: Ricardo Carrillo Cruz Date: Tue, 8 Aug 2017 20:23:45 +0200 Subject: [PATCH] Add delay and check configuration when interfaces is set on eos_vrf (#27884) * Add delay and check configuration is right when interfaces is set on eos_vrf Per the spec we put up for declarative intent modules, we need to check declarative intent params (in the case of eos_vrf it's 'interfaces') after a delay and non-declarative params have been set. If that doesn't meet desired state after delay, we fail the task. * Check declarative intent param only if config changed * Fix pep8 issue * Change default of delay param to 10 * Revert bogus change on eos_vlan --- lib/ansible/modules/network/eos/eos_vrf.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/ansible/modules/network/eos/eos_vrf.py b/lib/ansible/modules/network/eos/eos_vrf.py index 51ac40700d2..21e4bce6ddb 100644 --- a/lib/ansible/modules/network/eos/eos_vrf.py +++ b/lib/ansible/modules/network/eos/eos_vrf.py @@ -78,6 +78,7 @@ from ansible.module_utils.eos import eos_argument_spec, check_args from ansible.module_utils.six import iteritems import re +import time def map_obj_to_commands(updates, module): @@ -147,12 +148,24 @@ def map_params_to_obj(module): } +def check_declarative_intent_params(module): + if module.params['interfaces']: + time.sleep(module.params['delay']) + have = map_config_to_obj(module) + vrf = module.params['name'] + + for i in module.params['interfaces']: + if i not in have['interfaces']: + module.fail_json(msg="Interface %s not configured on vrf %s" % (i, vrf)) + + def main(): """ main entry point for module execution """ argument_spec = dict( name=dict(required=True), interfaces=dict(type='list'), + delay=dict(default=10, type='int'), rd=dict(), aggregate=dict(), purge=dict(default=False, type='bool'), @@ -186,6 +199,9 @@ def main(): result['session_name'] = response.get('session') result['changed'] = True + if result['changed']: + check_declarative_intent_params(module) + module.exit_json(**result) if __name__ == '__main__':