hobo agent: notify subservices on profile changes (#43553)
This commit is contained in:
parent
9aa26aca45
commit
a8c3eaf395
|
@ -27,6 +27,13 @@ class Command(hobo_deploy.Command):
|
|||
# want to create secondary services on every branches.
|
||||
if Hobo.objects.filter(secondary=False).count() == 0:
|
||||
return
|
||||
is_primary_hobo = True
|
||||
# on the primary hobo, notify other primary services, this will
|
||||
# get authentic to know about secondary services
|
||||
propagate_notify = True
|
||||
else:
|
||||
is_primary_hobo = False
|
||||
propagate_notify = False
|
||||
|
||||
for service_dict in services:
|
||||
if service_dict.get('secondary'):
|
||||
|
@ -47,7 +54,7 @@ class Command(hobo_deploy.Command):
|
|||
continue
|
||||
|
||||
slug_prefix = '_interco_'
|
||||
if me.get('secondary'):
|
||||
if is_primary_hobo:
|
||||
# this is the primary hobo, receiving a notification
|
||||
# because something changed in secondary hobo environment.
|
||||
# mark services with ou-label/ou-slug
|
||||
|
@ -70,7 +77,7 @@ class Command(hobo_deploy.Command):
|
|||
service.last_operational_success_timestamp = service.last_operational_check_timestamp
|
||||
service.save()
|
||||
|
||||
if me.get('secondary'):
|
||||
if is_primary_hobo:
|
||||
# add variables to mark the service as a different
|
||||
# organizational unit
|
||||
service_type = ContentType.objects.get_for_model(service_klass)
|
||||
|
@ -85,7 +92,7 @@ class Command(hobo_deploy.Command):
|
|||
variable.value = hobo_environment['variables']['ou-slug']
|
||||
variable.save()
|
||||
|
||||
if not me.get('secondary'):
|
||||
if not is_primary_hobo:
|
||||
# this is the secondary hobo, set service slug and label as
|
||||
# global variables so they can later be used to identify
|
||||
# this "organizational unit".
|
||||
|
@ -101,18 +108,28 @@ class Command(hobo_deploy.Command):
|
|||
# and reproduce profile settings from primary
|
||||
if 'profile' in hobo_environment:
|
||||
seen = []
|
||||
changes = False
|
||||
for i, field in enumerate(hobo_environment['profile']['fields']):
|
||||
attribute, created = AttributeDefinition.objects.get_or_create(
|
||||
name=field['name'],
|
||||
defaults={'label': field['label']})
|
||||
if created:
|
||||
changes = True
|
||||
for k, v in field.items():
|
||||
setattr(attribute, k, v)
|
||||
attribute.order = i + 1
|
||||
if getattr(attribute, k, None) != v:
|
||||
setattr(attribute, k, v)
|
||||
changes = True
|
||||
if attribute.order != (i + 1):
|
||||
changes = True
|
||||
attribute.order = i + 1
|
||||
attribute.save()
|
||||
seen.append(attribute.name)
|
||||
AttributeDefinition.objects.exclude(name__in=seen).delete()
|
||||
removed, details_ = AttributeDefinition.objects.exclude(name__in=seen).delete()
|
||||
if removed:
|
||||
changes = True
|
||||
if changes:
|
||||
# if there were changes to profile fields, propagate them.
|
||||
propagate_notify = True
|
||||
|
||||
if me.get('secondary'):
|
||||
# on the primary hobo, notify other primary services, this will
|
||||
# get authentic to know about secondary services
|
||||
if propagate_notify:
|
||||
notify_agents(None)
|
||||
|
|
Loading…
Reference in New Issue