From 372828de01bf487eea5b034409f501c7e7f6932e Mon Sep 17 00:00:00 2001 From: Tim Rupp Date: Thu, 22 Sep 2016 23:20:19 -0700 Subject: [PATCH] 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 --- network/f5/bigip_selfip.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/network/f5/bigip_selfip.py b/network/f5/bigip_selfip.py index 75ed6a09c0a..6cbf7badb58 100644 --- a/network/f5/bigip_selfip.py +++ b/network/f5/bigip_selfip.py @@ -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'