Search all assigned ipv6 addresses instead of just the first (#40533)

* Search all assigned ipv6 addresses instead of just the first

* Add test for idempotency with multiple ipv6 addresses assigned
This commit is contained in:
Nathaniel Case 2018-05-22 12:00:16 -04:00 committed by GitHub
parent ed7d6d9c19
commit e8d02a3a0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 15 deletions

View file

@ -148,9 +148,18 @@ def validate_param_values(module, obj, param=None):
def parse_config_argument(configobj, name, arg=None):
cfg = configobj['interface %s' % name]
cfg = '\n'.join(cfg.children)
match = re.search(r'%s (.+)$' % arg, cfg, re.M)
if match:
return match.group(1).strip()
values = []
matches = re.finditer(r'%s (.+)$' % arg, cfg, re.M)
for match in matches:
match_str = match.group(1).strip()
if arg == 'ipv6 address':
values.append(match_str)
else:
values = match_str
break
return values or None
def search_obj_in_list(name, lst):
@ -198,7 +207,7 @@ def map_obj_to_commands(updates, module):
commands.append('ip address {}'.format(ipv4))
if ipv6:
if obj_in_have is None or obj_in_have.get('ipv6') is None or ipv6.lower() != obj_in_have['ipv6'].lower():
if obj_in_have is None or obj_in_have.get('ipv6') is None or ipv6.lower() not in [addr.lower() for addr in obj_in_have['ipv6']]:
commands.append('ipv6 address {}'.format(ipv6))
if commands[-1] == interface: