Fixes the bigip_selfip module to respect traffic groups (#3009)

The code for traffic groups was not being tested and therefore
had errors associated with it. It is now covered in coverage tests
and bugs that were found in it have been fixed.

See this issue for details
https://github.com/F5Networks/f5-ansible/issues/28
This commit is contained in:
Tim Rupp 2016-09-22 23:20:19 -07:00 committed by John R Barker
parent 1ade801f65
commit 372828de01

View file

@ -367,6 +367,20 @@ class BigIpSelfIp(object):
else:
return list(services)
def traffic_groups(self):
result = []
groups = self.api.tm.cm.traffic_groups.get_collection()
for group in groups:
# Just checking for the addition of the partition here for
# different versions of BIG-IP
if '/' + self.params['partition'] + '/' in group.name:
result.append(group.name)
else:
full_name = '/%s/%s' % (self.params['partition'], group.name)
result.append(str(full_name))
return result
def update(self):
changed = False
svcs = []
@ -408,8 +422,11 @@ class BigIpSelfIp(object):
)
if traffic_group is not None:
groups = self.api.tm.cm.traffic_groups.get_collection()
params['trafficGroup'] = "/%s/%s" % (partition, traffic_group)
traffic_group = "/%s/%s" % (partition, traffic_group)
if traffic_group not in self.traffic_groups():
raise F5ModuleError(
'The specified traffic group was not found'
)
if 'traffic_group' in current:
if traffic_group != current['traffic_group']:
@ -417,11 +434,6 @@ class BigIpSelfIp(object):
else:
params['trafficGroup'] = traffic_group
if traffic_group not in groups:
raise F5ModuleError(
'The specified traffic group was not found'
)
if vlan is not None:
vlans = self.get_vlans()
vlan = "/%s/%s" % (partition, vlan)
@ -527,9 +539,9 @@ class BigIpSelfIp(object):
if traffic_group is None:
params['trafficGroup'] = "/%s/%s" % (partition, DEFAULT_TG)
else:
groups = self.api.tm.cm.traffic_groups.get_collection()
if traffic_group in groups:
params['trafficGroup'] = "/%s/%s" % (partition, traffic_group)
traffic_group = "/%s/%s" % (partition, traffic_group)
if traffic_group in self.traffic_groups():
params['trafficGroup'] = traffic_group
else:
raise F5ModuleError(
'The specified traffic group was not found'