Skip to content

Commit

Permalink
Fixes IOS L3 intermittent zuul failure (ansible#61682)
Browse files Browse the repository at this point in the history
* fix ios l3 intermittent failure

* fix self

* dict to ordered dict

* fix diff_again fn

Signed-off-by: Sumit Jaiswal <[email protected]>

* remove orderdict as its expensive

Signed-off-by: Sumit Jaiswal <[email protected]>

* update verify fn

Signed-off-by: Sumit Jaiswal <[email protected]>
  • Loading branch information
justjais authored Sep 4, 2019
1 parent 01f4081 commit 2672dc9
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,42 @@ def _state_deleted(self, want, have):

return commands

def verify_diff_again(self, want, have):
"""
Verify the IPV4 difference again as sometimes due to
change in order of set, set difference may result into change,
when there's actually no difference between want and have
:param want: want_dict IPV4
:param have: have_dict IPV4
:return: diff
"""
diff = False
for each in want:
each_want = dict(each)
for every in have:
every_have = dict(every)
if each_want.get('address') != every_have.get('address') and \
each_want.get('secondary') != every_have.get('secondary') and \
len(each_want.keys()) == len(every_have.keys()):
diff = True
break
elif each_want.get('dhcp_client') != every_have.get('dhcp_client') and each_want.get(
'dhcp_client') is not None:
diff = True
break
elif each_want.get('dhcp_hostname') != every_have.get('dhcp_hostname') and each_want.get(
'dhcp_hostname') is not None:
diff = True
break
elif each_want.get('address') != every_have.get('address') and len(each_want.keys()) == len(
every_have.keys()):
diff = True
break
if diff:
break

return diff

def _set_config(self, want, have, module):
# Set the interface config based on the want and have config
commands = []
Expand All @@ -225,6 +261,8 @@ def _set_config(self, want, have, module):
# Get the diff b/w want and have IPV4
if have.get('ipv4'):
ipv4 = tuple(set(dict(want_dict).get('ipv4')) - set(dict(have_dict).get('ipv4')))
if ipv4:
ipv4 = ipv4 if self.verify_diff_again(dict(want_dict).get('ipv4'), dict(have_dict).get('ipv4')) else ()
else:
diff = want_dict - have_dict
ipv4 = dict(diff).get('ipv4')
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/module_utils/network/ios/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def add_command_to_config_list(interface, cmd, commands):

def dict_to_set(sample_dict):
# Generate a set with passed dictionary for comparison
test_dict = {}
test_dict = dict()
if isinstance(sample_dict, dict):
for k, v in iteritems(sample_dict):
if v is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
vars:
lines: |
interface GigabitEthernet 0/1
ip address dhcp client-id GigabitEthernet 0/0 hostname test.com
ip address 203.0.113.27 255.255.255.0
interface GigabitEthernet 0/2
ip address 192.168.2.1 255.255.255.0 secondary
ip address 192.168.2.2 255.255.255.0
ipv6 address fd5d:12c9:2201:1::1/64
ip address 192.0.2.1 255.255.255.0 secondary
ip address 192.0.2.2 255.255.255.0
ipv6 address 2001:db8:0:3::/64
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
dhcp_hostname: test.com
- name: GigabitEthernet0/2
ipv4:
- address: 192.168.3.1/24
- address: 198.51.100.1/24
secondary: True
- address: 192.168.3.2/24
- address: 198.51.100.2/24
ipv6:
- address: fd5d:12c9:2201:1::1/64
- address: 2001:db8:0:3::/64
state: merged
register: result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
- address: dhcp
- name: GigabitEthernet0/2
ipv4:
- address: 192.168.4.1/24
- address: 192.168.4.2/24
- address: 198.51.100.1/24
- address: 198.51.100.2/24
secondary: True
state: overridden
register: result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
config:
- name: GigabitEthernet0/1
ipv4:
- address: 192.168.3.1/24
- address: 203.0.114.1/24
- name: GigabitEthernet0/2
ipv4:
- address: 192.168.4.1/24
- address: 198.51.100.1/24
secondary: True
- address: 192.168.4.2/24
- address: 198.51.100.2/24
state: replaced
register: result

Expand Down
62 changes: 28 additions & 34 deletions test/integration/targets/ios_l3_interfaces/vars/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ merged:
- "interface GigabitEthernet0/1"
- "ip address dhcp client-id GigabitEthernet 0/0 hostname test.com"
- "interface GigabitEthernet0/2"
- "ip address 192.168.3.1 255.255.255.0 secondary"
- "ip address 192.168.3.2 255.255.255.0"
- "ipv6 address fd5d:12c9:2201:1::1/64"
- "ip address 198.51.100.1 255.255.255.0 secondary"
- "ip address 198.51.100.2 255.255.255.0"
- "ipv6 address 2001:db8:0:3::/64"

after:
- name: loopback888
Expand All @@ -29,11 +29,11 @@ merged:
dhcp_hostname: test.com
name: GigabitEthernet0/1
- ipv4:
- address: 192.168.3.1 255.255.255.0
- address: 198.51.100.1 255.255.255.0
secondary: true
- address: 192.168.3.2 255.255.255.0
- address: 198.51.100.2 255.255.255.0
ipv6:
- address: fd5d:12c9:2201:1::1/64
- address: 2001:db8:0:3::/64
name: GigabitEthernet0/2


Expand All @@ -45,26 +45,24 @@ replaced:
- address: dhcp
name: GigabitEthernet0/0
- ipv4:
- address: dhcp
dhcp_client: 0
dhcp_hostname: test.com
- address: 203.0.113.27 255.255.255.0
name: GigabitEthernet0/1
- ipv4:
- address: 192.168.2.1 255.255.255.0
- address: 192.0.2.1 255.255.255.0
secondary: true
- address: 192.168.2.2 255.255.255.0
- address: 192.0.2.2 255.255.255.0
ipv6:
- address: fd5d:12c9:2201:1::1/64
- address: 2001:db8:0:3::/64
name: GigabitEthernet0/2

commands:
- "interface GigabitEthernet0/1"
- "ip address 192.168.3.1 255.255.255.0"
- "ip address 203.0.114.1 255.255.255.0"
- "interface GigabitEthernet0/2"
- "no ip address"
- "no ipv6 address"
- "ip address 192.168.4.1 255.255.255.0 secondary"
- "ip address 192.168.4.2 255.255.255.0"
- "ip address 198.51.100.1 255.255.255.0 secondary"
- "ip address 198.51.100.2 255.255.255.0"

after:
- name: loopback888
Expand All @@ -73,12 +71,12 @@ replaced:
- address: dhcp
name: GigabitEthernet0/0
- ipv4:
- address: 192.168.3.1 255.255.255.0
- address: 203.0.114.1 255.255.255.0
name: GigabitEthernet0/1
- ipv4:
- address: 192.168.4.1 255.255.255.0
- address: 198.51.100.1 255.255.255.0
secondary: true
- address: 192.168.4.2 255.255.255.0
- address: 198.51.100.2 255.255.255.0
name: GigabitEthernet0/2

overridden:
Expand All @@ -89,16 +87,14 @@ overridden:
- address: dhcp
name: GigabitEthernet0/0
- ipv4:
- address: dhcp
dhcp_client: 0
dhcp_hostname: test.com
- address: 203.0.113.27 255.255.255.0
name: GigabitEthernet0/1
- ipv4:
- address: 192.168.2.1 255.255.255.0
- address: 192.0.2.1 255.255.255.0
secondary: true
- address: 192.168.2.2 255.255.255.0
- address: 192.0.2.2 255.255.255.0
ipv6:
- address: fd5d:12c9:2201:1::1/64
- address: 2001:db8:0:3::/64
name: GigabitEthernet0/2

commands:
Expand All @@ -107,8 +103,8 @@ overridden:
- "interface GigabitEthernet0/2"
- "no ip address"
- "no ipv6 address"
- "ip address 192.168.4.1 255.255.255.0"
- "ip address 192.168.4.2 255.255.255.0 secondary"
- "ip address 198.51.100.1 255.255.255.0"
- "ip address 198.51.100.2 255.255.255.0 secondary"

after:
- name: loopback888
Expand All @@ -118,9 +114,9 @@ overridden:
name: GigabitEthernet0/0
- name: GigabitEthernet0/1
- ipv4:
- address: 192.168.4.2 255.255.255.0
- address: 198.51.100.2 255.255.255.0
secondary: true
- address: 192.168.4.1 255.255.255.0
- address: 198.51.100.1 255.255.255.0
name: GigabitEthernet0/2

deleted:
Expand All @@ -131,16 +127,14 @@ deleted:
- address: dhcp
name: GigabitEthernet0/0
- ipv4:
- address: dhcp
dhcp_client: 0
dhcp_hostname: test.com
- address: 203.0.113.27 255.255.255.0
name: GigabitEthernet0/1
- ipv4:
- address: 192.168.2.1 255.255.255.0
- address: 192.0.2.1 255.255.255.0
secondary: true
- address: 192.168.2.2 255.255.255.0
- address: 192.0.2.2 255.255.255.0
ipv6:
- address: fd5d:12c9:2201:1::1/64
- address: 2001:db8:0:3::/64
name: GigabitEthernet0/2

commands:
Expand Down

0 comments on commit 2672dc9

Please sign in to comment.