Repository: ansible/ansible

Issue:
(P2)nxos_bgp - event_history properties and suppress_fib_pending are not idempotent
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
- nxos_bgp

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.4.0 (devel e8072ee616) last updated 2017/06/21 14:40:23 (GMT -400)
  config file = None
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /root/agents-ci/ansible/lib/ansible
  executable location = /root/agents-ci/ansible/bin/ansible
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
```

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
- Ansible Server : Ubuntu 14.04
- Device: Nexus9000 C9508  running 7.0(3)I6(1)

##### SUMMARY
The properties event_history_cli, event_history_detail, event_history_events, event_history_periodic, suppress_fib_pending are not idempotent. The same playbook applied twice shows the result as 'changed'.

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
---
cli:
  host: "{{ inventory_hostname }}"
  username: "{{ nxos_cli_user | default('admin') }}"
  password: "{{ nxos_cli_pass | default('admin') }}"

nxapi:
  host: "{{ inventory_hostname }}"
  username: "{{ nxos_nxapi_user | default('admin') }}"
  password: "{{ nxos_nxapi_pass | default('admin') }}"
  transport: nxapi
  user_ssl: no

---
- name: NXOS Sample Playbook
  hosts: nxos
  connection: local
  gather_facts: no

  tasks:

  - name: Ensure BGP Is Enabled
    nxos_feature:
      feature: bgp
      state: enabled
      provider: "{{ cli }}"

  - name: "Configure BGP non defaults"
    nxos_bgp: &configure_non_default
      asn: 65535
      router_id: 1.1.1.1
      bestpath_always_compare_med: true
      bestpath_aspath_multipath_relax: true
      bestpath_compare_routerid: true
      bestpath_cost_community_ignore: true
      bestpath_med_confed: true
      bestpath_med_missing_as_worst: true
      bestpath_med_non_deterministic: true
      cluster_id: 10.0.0.1
      confederation_id: 99
      disable_policy_batching: true
      enforce_first_as: false
      fast_external_fallover: false
      flush_routes: true
      graceful_restart_helper: true
      graceful_restart_timers_restart: 130
      graceful_restart_timers_stalepath_time: 310
      isolate: false
      log_neighbor_changes: true
      maxas_limit: 50
      neighbor_down_fib_accelerate: true
      reconnect_interval: 55
      router_id: 192.168.0.66
      shutdown: true
      timer_bestpath_limit: 255
      timer_bgp_hold: 110
      timer_bgp_keepalive: 45
      event_history_cli: size_medium
      event_history_detail: size_large
      event_history_events: size_medium
      event_history_periodic: size_small
      suppress_fib_pending: true
      state: present
      provider: "{{ cli }}"
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
When the above playbook is run a second time the result should be

PLAY RECAP ************************************************************************************************************************************************
nxxxx-x-xxx.example.com          : ok=2    changed=0    unreachable=0    failed=0 

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
PLAY RECAP ************************************************************************************************************************************************
nxxxx-x-xxx.example.com          : ok=2    changed=1    unreachable=0    failed=0
```



Discussion:
cc @jedelman8 @GGabriele @privateip @rcarrillocruz @mikewiebe @trishnaguha
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
#27329 fixes `event-history`, but I'm not seeing any idempotence issues with `suppress_fib_pending`. Can you get me some detailed output of this happening?

Resolving patch:
diff --git a/lib/ansible/modules/network/nxos/nxos_bgp.py b/lib/ansible/modules/network/nxos/nxos_bgp.py
--- a/lib/ansible/modules/network/nxos/nxos_bgp.py
+++ b/lib/ansible/modules/network/nxos/nxos_bgp.py
@@ -412,7 +412,6 @@ def get_value(arg, config):
     command = PARAM_TO_COMMAND_KEYMAP.get(arg)
 
     if command.split()[0] == 'event-history':
-        command_re = re.compile(r'\s+{0}\s*'.format(command), re.M)
         has_size = re.search(r'^\s+{0} size\s(?P<value>.*)$'.format(command), config, re.M)
 
         if command == 'event-history detail':
@@ -420,11 +419,8 @@ def get_value(arg, config):
         else:
             value = 'size_small'
 
-        if command_re.search(config):
-            if has_size:
-                value = 'size_%s' % has_size.group('value')
-            else:
-                value = True
+        if has_size:
+            value = 'size_%s' % has_size.group('value')
 
     elif arg in ['enforce_first_as', 'fast_external_fallover']:
         no_command_re = re.compile(r'no\s+{0}\s*'.format(command), re.M)
@@ -687,7 +683,7 @@ def main():
 
     if candidate:
         candidate = candidate.items_text()
-        load_config(module, candidate)
+        warnings.extend(load_config(module, candidate))
         result['changed'] = True
         result['commands'] = candidate
     else:


Test patch:
diff --git a/test/units/modules/network/nxos/fixtures/nxos_bgp_config.cfg b/test/units/modules/network/nxos/fixtures/nxos_bgp_config.cfg
deleted file mode 100644
--- a/test/units/modules/network/nxos/fixtures/nxos_bgp_config.cfg
+++ /dev/null
@@ -1,11 +0,0 @@
-feature bgp
-
-router bgp 65535
-  router-id 192.168.1.1
-  event-history cli size medium
-  event-history detail
-  vrf test2
-    address-family ipv4 unicast
-    timers bgp 1 10
-  neighbor 3.3.3.5
-    address-family ipv4 unicast
diff --git a/test/units/modules/network/nxos/test_nxos_bgp.py b/test/units/modules/network/nxos/test_nxos_bgp.py
--- a/test/units/modules/network/nxos/test_nxos_bgp.py
+++ b/test/units/modules/network/nxos/test_nxos_bgp.py
@@ -42,8 +42,8 @@ def tearDown(self):
         self.mock_get_config.stop()
 
     def load_fixtures(self, commands=None, device=''):
-        self.get_config.return_value = load_fixture('', 'nxos_bgp_config.cfg')
-        self.load_config.return_value = None
+        self.get_config.return_value = load_fixture('nxos_bgp', 'config.cfg')
+        self.load_config.return_value = []
 
     def test_nxos_bgp(self):
         set_module_args(dict(asn=65535, router_id='1.1.1.1'))