Skip to content

Commit 82bc862

Browse files
Avoid patching profile failure, if profile is not created
(cherry picked from commit dde140e)
1 parent b58f889 commit 82bc862

1 file changed

Lines changed: 62 additions & 7 deletions

File tree

f5_openstack_agent/lbaasv2/drivers/bigip/resource_manager.py

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -632,17 +632,42 @@ def _update_extended_profiles(self, bigip, old_listener, listener, vs):
632632
# properties defined in json file.
633633
old_profile = {}
634634
profile = {}
635+
whole_profile = self.extended_profiles.get(profile_type, {})
635636
customize = self.profile_map[profile_type].get("customize")
636637
if callable(customize):
637638
customize(profile_type, old_profile, old_listener)
638639
customize(profile_type, profile, listener)
639-
if profile != old_profile:
640-
profile['partition'] = vs['partition']
641-
profile['name'] = profile_type + "_" + vs['name']
642-
helper = self.profile_map[profile_type]['helper']
643-
super(ListenerManager, self)._update(
644-
bigip, profile, None, None, None, type=profile_type,
645-
helper=helper)
640+
customize(profile_type, whole_profile, listener)
641+
changed = profile != old_profile
642+
profile['partition'] = vs['partition']
643+
profile['name'] = profile_type + "_" + vs['name']
644+
whole_profile['partition'] = vs['partition']
645+
whole_profile['name'] = profile_type + "_" + vs['name']
646+
helper = self.profile_map[profile_type]['helper']
647+
if changed:
648+
try:
649+
super(ListenerManager,
650+
self)._update(bigip, profile, None, None, None,
651+
type=profile_type, helper=helper)
652+
except HTTPError as ex:
653+
# If profile is not there, create it. That happens
654+
# in Agent migration case.
655+
if ex.response.status_code == 404:
656+
super(ListenerManager, self)._create(
657+
bigip, whole_profile, None, None,
658+
type=profile_type, helper=helper)
659+
self._attach_profile(bigip, vs, whole_profile)
660+
else:
661+
raise ex
662+
else:
663+
# In Agent migration case, profile might not be attached.
664+
# Attempt to create profile, even if no change. Nothing
665+
# will happen if profile is already there.
666+
super(ListenerManager,
667+
self)._create(bigip, whole_profile, None, None,
668+
type=profile_type, helper=helper,
669+
overwrite=False)
670+
self._attach_profile(bigip, vs, whole_profile)
646671
elif old_cond != new_cond and new_cond:
647672
# Need to create and attach profile
648673
profile = self.extended_profiles.get(profile_type, {})
@@ -677,6 +702,9 @@ def _delete_extended_profiles(self, bigip, listener, vs):
677702
bigip, profile, None, None, type=profile_type, helper=helper)
678703

679704
def _attach_profile(self, bigip, vs, profile):
705+
if profile['name'].startswith("http_profile_"):
706+
return self._attach_http_profile(bigip, vs, profile)
707+
680708
v = self.resource_helper.load(bigip, name=vs['name'],
681709
partition=vs['partition'])
682710
if v.profiles_s.profiles.exists(name=profile['name'],
@@ -687,6 +715,33 @@ def _attach_profile(self, bigip, vs, profile):
687715
v.profiles_s.profiles.create(name=profile['name'],
688716
partition=profile['partition'])
689717

718+
def _attach_http_profile(self, bigip, vs, profile):
719+
# If VS is created by legacy Agent instead of Agent Lite, we have to
720+
# patch VS profiles property, because /Common/http cannot be dettached.
721+
loc = "/" + profile["partition"] + "/" + profile["name"]
722+
attached = False
723+
payload = {
724+
"name": vs['name'],
725+
"partition": vs['partition'],
726+
"profiles": []
727+
}
728+
v = self.resource_helper.load(bigip, name=vs['name'],
729+
partition=vs['partition'])
730+
profiles = v.profiles_s.get_collection()
731+
for p in profiles:
732+
if p.fullPath == loc:
733+
attached = True
734+
break
735+
if p.fullPath == "/Common/http":
736+
payload['profiles'].append(loc)
737+
else:
738+
payload['profiles'].append(p.fullPath)
739+
if not attached:
740+
self._update(bigip, payload, None, None, None)
741+
else:
742+
LOG.debug("Profile %s has already been attached to vs %s",
743+
profile['name'], vs['name'])
744+
690745
def _detach_profile(self, bigip, vs, profile):
691746
v = self.resource_helper.load(bigip, name=vs['name'],
692747
partition=vs['partition'])

0 commit comments

Comments
 (0)