Skip to content

Commit

Permalink
Merge pull request #1647 from jikui/9.9-remove-extra-payload
Browse files Browse the repository at this point in the history
 use a new way to check if tls and customized properties are changed.
  • Loading branch information
jikui authored Feb 1, 2021
2 parents cca5fec + 9961f5a commit f132dbc
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions f5_openstack_agent/lbaasv2/drivers/bigip/resource_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ def _delete(self, bigip, payload, resource, service, **kwargs):
resource_helper.delete(bigip, name=payload['name'],
partition=payload['partition'])

def _check_update_needed(self, payload, old_resource, resource):
if not payload or len(payload.keys()) == 0:
return False
return True

@log_helpers.log_method_call
def create(self, resource, service, **kwargs):
if not service.get(self._key):
Expand Down Expand Up @@ -153,7 +158,7 @@ def update(self, old_resource, resource, service, **kwargs):
self._update_payload(old_resource, resource,
service))

if not payload or len(payload.keys()) == 0:
if self._check_update_needed(payload, old_resource, resource) is False:
LOG.debug("Do not need to update %s", self._resource)
return

Expand Down Expand Up @@ -507,6 +512,14 @@ def _update_payload(self, old_listener, listener, service, **kwargs):
if old_listener['default_pool_id'] != listener['default_pool_id']:
payload['persist'] = create_payload['persist']

return super(ListenerManager, self)._update_payload(
old_listener, listener, service,
payload=payload, create_payload=create_payload
)

def _check_tls_changed(self, old_listener, listener):
if not old_listener:
return False
if listener['protocol'] == "TERMINATED_HTTPS":
LOG.debug("Finding tls setting differences.")
old_sni = [n['tls_container_id']
Expand All @@ -515,8 +528,8 @@ def _update_payload(self, old_listener, listener, service, **kwargs):
for n in listener['sni_containers']]
if old_listener['default_tls_container_id'] != \
listener['default_tls_container_id'] or old_sni != sni:
payload['tls'] = "tls change"
LOG.debug("tls changes happen")
return True

# If client authentication setting changes,
# also need to update client ssl profile.
Expand All @@ -525,19 +538,27 @@ def _update_payload(self, old_listener, listener, service, **kwargs):
old_ca = old_listener.get('ca_container_id', "")
new_ca = listener.get('ca_container_id', "")
if old_mode != new_mode or old_ca != new_ca:
payload['tls'] = "tls change"
return True
return False

def _check_customized_changed(self, old_listener, listener):
if not old_listener:
return False
if listener['protocol'] == "HTTP" or \
listener['protocol'] == "TERMINATED_HTTPS":
old_customized = old_listener.get('customized', None)
new_customized = listener.get('customized', None)
if old_customized != new_customized:
payload['customized'] = 'customized change'
return True
return False

return super(ListenerManager, self)._update_payload(
old_listener, listener, service,
payload=payload, create_payload=create_payload
)
def _check_update_needed(self, payload, old_listener, listener):
if not payload or len(payload.keys()) == 0:
if self._check_customized_changed(old_listener, listener) \
is False and \
self._check_tls_changed(old_listener, listener) is False:
return False
return True

def _create_persist_profile(self, bigip, vs, persist):
persist_type = persist.get('type', "")
Expand Down Expand Up @@ -760,7 +781,7 @@ def __get_profiles_from_bigip(self, bigip, vs):
def _update(self, bigip, vs, old_listener, listener, service):
# Add conditions here for more update requests via vs['profiles']
orig_profiles = []
if 'tls' in vs:
if self._check_tls_changed(old_listener, listener) is True:
orig_profiles = self.__get_profiles_from_bigip(bigip, vs)
if 'profiles' not in vs:
vs['profiles'] = list()
Expand All @@ -782,7 +803,7 @@ def _update(self, bigip, vs, old_listener, listener, service):
profile = self._create_persist_profile(bigip, vs, persist)
vs['persist'] = [{"name": profile}]

if vs.get('customized', None):
if self._check_customized_changed(old_listener, listener) is True:
self._create_http_profile(bigip, listener, vs)
# load the porfiles from bigip if needed
if not orig_profiles:
Expand Down Expand Up @@ -825,7 +846,8 @@ def _update(self, bigip, vs, old_listener, listener, service):
super(ListenerManager, self)._update(bigip, vs, old_listener, listener,
service)

if 'tls' in vs and old_listener:
if old_listener and \
self._check_tls_changed(old_listener, listener) is True:
old_service = {"listener": old_listener}
self._delete_ssl_profiles(bigip, vs, old_service)

Expand Down

0 comments on commit f132dbc

Please sign in to comment.