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
reviewable/pr18780/r1
Tim Rupp 8 years ago committed by John R Barker
parent 1ade801f65
commit 372828de01

@ -367,6 +367,20 @@ class BigIpSelfIp(object):
else: else:
return list(services) 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): def update(self):
changed = False changed = False
svcs = [] svcs = []
@ -408,8 +422,11 @@ class BigIpSelfIp(object):
) )
if traffic_group is not None: if traffic_group is not None:
groups = self.api.tm.cm.traffic_groups.get_collection() traffic_group = "/%s/%s" % (partition, traffic_group)
params['trafficGroup'] = "/%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' in current:
if traffic_group != current['traffic_group']: if traffic_group != current['traffic_group']:
@ -417,11 +434,6 @@ class BigIpSelfIp(object):
else: else:
params['trafficGroup'] = traffic_group params['trafficGroup'] = traffic_group
if traffic_group not in groups:
raise F5ModuleError(
'The specified traffic group was not found'
)
if vlan is not None: if vlan is not None:
vlans = self.get_vlans() vlans = self.get_vlans()
vlan = "/%s/%s" % (partition, vlan) vlan = "/%s/%s" % (partition, vlan)
@ -527,9 +539,9 @@ class BigIpSelfIp(object):
if traffic_group is None: if traffic_group is None:
params['trafficGroup'] = "/%s/%s" % (partition, DEFAULT_TG) params['trafficGroup'] = "/%s/%s" % (partition, DEFAULT_TG)
else: else:
groups = self.api.tm.cm.traffic_groups.get_collection() traffic_group = "/%s/%s" % (partition, traffic_group)
if traffic_group in groups: if traffic_group in self.traffic_groups():
params['trafficGroup'] = "/%s/%s" % (partition, traffic_group) params['trafficGroup'] = traffic_group
else: else:
raise F5ModuleError( raise F5ModuleError(
'The specified traffic group was not found' 'The specified traffic group was not found'

Loading…
Cancel
Save