Projet

Général

Profil

0001-hobo-agent-notify-subservices-on-profile-changes-435.patch

Frédéric Péters, 03 juin 2020 09:23

Télécharger (4,55 ko)

Voir les différences:

Subject: [PATCH] hobo agent: notify subservices on profile changes (#43553)

 .../hobo/management/commands/hobo_deploy.py   | 37 ++++++++++++++-----
 1 file changed, 27 insertions(+), 10 deletions(-)
hobo/agent/hobo/management/commands/hobo_deploy.py
27 27
                # want to create secondary services on every branches.
28 28
                if Hobo.objects.filter(secondary=False).count() == 0:
29 29
                    return
30
                is_primary_hobo = True
31
                # on the primary hobo, notify other primary services, this will
32
                # get authentic to know about secondary services
33
                propagate_notify = True
34
            else:
35
                is_primary_hobo = False
36
                propagate_notify = False
30 37

  
31 38
            for service_dict in services:
32 39
                if service_dict.get('secondary'):
......
47 54
                    continue
48 55

  
49 56
                slug_prefix = '_interco_'
50
                if me.get('secondary'):
57
                if is_primary_hobo:
51 58
                    # this is the primary hobo, receiving a notification
52 59
                    # because something changed in secondary hobo environment.
53 60
                    # mark services with ou-label/ou-slug
......
70 77
                service.last_operational_success_timestamp = service.last_operational_check_timestamp
71 78
                service.save()
72 79

  
73
                if me.get('secondary'):
80
                if is_primary_hobo:
74 81
                    # add variables to mark the service as a different
75 82
                    # organizational unit
76 83
                    service_type = ContentType.objects.get_for_model(service_klass)
......
85 92
                    variable.value = hobo_environment['variables']['ou-slug']
86 93
                    variable.save()
87 94

  
88
                if not me.get('secondary'):
95
                if not is_primary_hobo:
89 96
                    # this is the secondary hobo, set service slug and label as
90 97
                    # global variables so they can later be used to identify
91 98
                    # this "organizational unit".
......
101 108
                    # and reproduce profile settings from primary
102 109
                    if 'profile' in hobo_environment:
103 110
                        seen = []
111
                        changes = False
104 112
                        for i, field in enumerate(hobo_environment['profile']['fields']):
105 113
                            attribute, created = AttributeDefinition.objects.get_or_create(
106 114
                                    name=field['name'],
107 115
                                    defaults={'label': field['label']})
116
                            if created:
117
                                changes = True
108 118
                            for k, v in field.items():
109
                                setattr(attribute, k, v)
110
                            attribute.order = i + 1
119
                                if getattr(attribute, k, None) != v:
120
                                    setattr(attribute, k, v)
121
                                    changes = True
122
                            if attribute.order != (i + 1):
123
                                changes = True
124
                                attribute.order = i + 1
111 125
                            attribute.save()
112 126
                            seen.append(attribute.name)
113
                        AttributeDefinition.objects.exclude(name__in=seen).delete()
114

  
115
            if me.get('secondary'):
116
                # on the primary hobo, notify other primary services, this will
117
                # get authentic to know about secondary services
127
                        removed, details_ = AttributeDefinition.objects.exclude(name__in=seen).delete()
128
                        if removed:
129
                            changes = True
130
                        if changes:
131
                            # if there were changes to profile fields, propagate them.
132
                            propagate_notify = True
133

  
134
            if propagate_notify:
118 135
                notify_agents(None)
119
-