Fixes IOS L3 intermittent zuul failure (#61682)

* fix ios l3 intermittent failure

* fix self

* dict to ordered dict

* fix diff_again fn

Signed-off-by: Sumit Jaiswal <sjaiswal@redhat.com>

* remove orderdict as its expensive

Signed-off-by: Sumit Jaiswal <sjaiswal@redhat.com>

* update verify fn

Signed-off-by: Sumit Jaiswal <sjaiswal@redhat.com>
This commit is contained in:
Sumit Jaiswal 2019-09-04 15:51:05 +05:30 committed by GitHub
parent 01f4081b66
commit 2672dc9694
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 79 additions and 47 deletions

View file

@ -204,6 +204,42 @@ class L3_Interfaces(ConfigBase):
return commands 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): def _set_config(self, want, have, module):
# Set the interface config based on the want and have config # Set the interface config based on the want and have config
commands = [] commands = []
@ -225,6 +261,8 @@ class L3_Interfaces(ConfigBase):
# Get the diff b/w want and have IPV4 # Get the diff b/w want and have IPV4
if have.get('ipv4'): if have.get('ipv4'):
ipv4 = tuple(set(dict(want_dict).get('ipv4')) - set(dict(have_dict).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: else:
diff = want_dict - have_dict diff = want_dict - have_dict
ipv4 = dict(diff).get('ipv4') ipv4 = dict(diff).get('ipv4')

View file

@ -30,7 +30,7 @@ def add_command_to_config_list(interface, cmd, commands):
def dict_to_set(sample_dict): def dict_to_set(sample_dict):
# Generate a set with passed dictionary for comparison # Generate a set with passed dictionary for comparison
test_dict = {} test_dict = dict()
if isinstance(sample_dict, dict): if isinstance(sample_dict, dict):
for k, v in iteritems(sample_dict): for k, v in iteritems(sample_dict):
if v is not None: if v is not None:

View file

@ -5,8 +5,8 @@
vars: vars:
lines: | lines: |
interface GigabitEthernet 0/1 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 interface GigabitEthernet 0/2
ip address 192.168.2.1 255.255.255.0 secondary ip address 192.0.2.1 255.255.255.0 secondary
ip address 192.168.2.2 255.255.255.0 ip address 192.0.2.2 255.255.255.0
ipv6 address fd5d:12c9:2201:1::1/64 ipv6 address 2001:db8:0:3::/64

View file

@ -15,11 +15,11 @@
dhcp_hostname: test.com dhcp_hostname: test.com
- name: GigabitEthernet0/2 - name: GigabitEthernet0/2
ipv4: ipv4:
- address: 192.168.3.1/24 - address: 198.51.100.1/24
secondary: True secondary: True
- address: 192.168.3.2/24 - address: 198.51.100.2/24
ipv6: ipv6:
- address: fd5d:12c9:2201:1::1/64 - address: 2001:db8:0:3::/64
state: merged state: merged
register: result register: result

View file

@ -15,8 +15,8 @@
- address: dhcp - address: dhcp
- name: GigabitEthernet0/2 - name: GigabitEthernet0/2
ipv4: ipv4:
- address: 192.168.4.1/24 - address: 198.51.100.1/24
- address: 192.168.4.2/24 - address: 198.51.100.2/24
secondary: True secondary: True
state: overridden state: overridden
register: result register: result

View file

@ -12,12 +12,12 @@
config: config:
- name: GigabitEthernet0/1 - name: GigabitEthernet0/1
ipv4: ipv4:
- address: 192.168.3.1/24 - address: 203.0.114.1/24
- name: GigabitEthernet0/2 - name: GigabitEthernet0/2
ipv4: ipv4:
- address: 192.168.4.1/24 - address: 198.51.100.1/24
secondary: True secondary: True
- address: 192.168.4.2/24 - address: 198.51.100.2/24
state: replaced state: replaced
register: result register: result

View file

@ -13,9 +13,9 @@ merged:
- "interface GigabitEthernet0/1" - "interface GigabitEthernet0/1"
- "ip address dhcp client-id GigabitEthernet 0/0 hostname test.com" - "ip address dhcp client-id GigabitEthernet 0/0 hostname test.com"
- "interface GigabitEthernet0/2" - "interface GigabitEthernet0/2"
- "ip address 192.168.3.1 255.255.255.0 secondary" - "ip address 198.51.100.1 255.255.255.0 secondary"
- "ip address 192.168.3.2 255.255.255.0" - "ip address 198.51.100.2 255.255.255.0"
- "ipv6 address fd5d:12c9:2201:1::1/64" - "ipv6 address 2001:db8:0:3::/64"
after: after:
- name: loopback888 - name: loopback888
@ -29,11 +29,11 @@ merged:
dhcp_hostname: test.com dhcp_hostname: test.com
name: GigabitEthernet0/1 name: GigabitEthernet0/1
- ipv4: - ipv4:
- address: 192.168.3.1 255.255.255.0 - address: 198.51.100.1 255.255.255.0
secondary: true secondary: true
- address: 192.168.3.2 255.255.255.0 - address: 198.51.100.2 255.255.255.0
ipv6: ipv6:
- address: fd5d:12c9:2201:1::1/64 - address: 2001:db8:0:3::/64
name: GigabitEthernet0/2 name: GigabitEthernet0/2
@ -45,26 +45,24 @@ replaced:
- address: dhcp - address: dhcp
name: GigabitEthernet0/0 name: GigabitEthernet0/0
- ipv4: - ipv4:
- address: dhcp - address: 203.0.113.27 255.255.255.0
dhcp_client: 0
dhcp_hostname: test.com
name: GigabitEthernet0/1 name: GigabitEthernet0/1
- ipv4: - ipv4:
- address: 192.168.2.1 255.255.255.0 - address: 192.0.2.1 255.255.255.0
secondary: true secondary: true
- address: 192.168.2.2 255.255.255.0 - address: 192.0.2.2 255.255.255.0
ipv6: ipv6:
- address: fd5d:12c9:2201:1::1/64 - address: 2001:db8:0:3::/64
name: GigabitEthernet0/2 name: GigabitEthernet0/2
commands: commands:
- "interface GigabitEthernet0/1" - "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" - "interface GigabitEthernet0/2"
- "no ip address" - "no ip address"
- "no ipv6 address" - "no ipv6 address"
- "ip address 192.168.4.1 255.255.255.0 secondary" - "ip address 198.51.100.1 255.255.255.0 secondary"
- "ip address 192.168.4.2 255.255.255.0" - "ip address 198.51.100.2 255.255.255.0"
after: after:
- name: loopback888 - name: loopback888
@ -73,12 +71,12 @@ replaced:
- address: dhcp - address: dhcp
name: GigabitEthernet0/0 name: GigabitEthernet0/0
- ipv4: - ipv4:
- address: 192.168.3.1 255.255.255.0 - address: 203.0.114.1 255.255.255.0
name: GigabitEthernet0/1 name: GigabitEthernet0/1
- ipv4: - ipv4:
- address: 192.168.4.1 255.255.255.0 - address: 198.51.100.1 255.255.255.0
secondary: true secondary: true
- address: 192.168.4.2 255.255.255.0 - address: 198.51.100.2 255.255.255.0
name: GigabitEthernet0/2 name: GigabitEthernet0/2
overridden: overridden:
@ -89,16 +87,14 @@ overridden:
- address: dhcp - address: dhcp
name: GigabitEthernet0/0 name: GigabitEthernet0/0
- ipv4: - ipv4:
- address: dhcp - address: 203.0.113.27 255.255.255.0
dhcp_client: 0
dhcp_hostname: test.com
name: GigabitEthernet0/1 name: GigabitEthernet0/1
- ipv4: - ipv4:
- address: 192.168.2.1 255.255.255.0 - address: 192.0.2.1 255.255.255.0
secondary: true secondary: true
- address: 192.168.2.2 255.255.255.0 - address: 192.0.2.2 255.255.255.0
ipv6: ipv6:
- address: fd5d:12c9:2201:1::1/64 - address: 2001:db8:0:3::/64
name: GigabitEthernet0/2 name: GigabitEthernet0/2
commands: commands:
@ -107,8 +103,8 @@ overridden:
- "interface GigabitEthernet0/2" - "interface GigabitEthernet0/2"
- "no ip address" - "no ip address"
- "no ipv6 address" - "no ipv6 address"
- "ip address 192.168.4.1 255.255.255.0" - "ip address 198.51.100.1 255.255.255.0"
- "ip address 192.168.4.2 255.255.255.0 secondary" - "ip address 198.51.100.2 255.255.255.0 secondary"
after: after:
- name: loopback888 - name: loopback888
@ -118,9 +114,9 @@ overridden:
name: GigabitEthernet0/0 name: GigabitEthernet0/0
- name: GigabitEthernet0/1 - name: GigabitEthernet0/1
- ipv4: - ipv4:
- address: 192.168.4.2 255.255.255.0 - address: 198.51.100.2 255.255.255.0
secondary: true secondary: true
- address: 192.168.4.1 255.255.255.0 - address: 198.51.100.1 255.255.255.0
name: GigabitEthernet0/2 name: GigabitEthernet0/2
deleted: deleted:
@ -131,16 +127,14 @@ deleted:
- address: dhcp - address: dhcp
name: GigabitEthernet0/0 name: GigabitEthernet0/0
- ipv4: - ipv4:
- address: dhcp - address: 203.0.113.27 255.255.255.0
dhcp_client: 0
dhcp_hostname: test.com
name: GigabitEthernet0/1 name: GigabitEthernet0/1
- ipv4: - ipv4:
- address: 192.168.2.1 255.255.255.0 - address: 192.0.2.1 255.255.255.0
secondary: true secondary: true
- address: 192.168.2.2 255.255.255.0 - address: 192.0.2.2 255.255.255.0
ipv6: ipv6:
- address: fd5d:12c9:2201:1::1/64 - address: 2001:db8:0:3::/64
name: GigabitEthernet0/2 name: GigabitEthernet0/2
commands: commands: