server: Delegate association signal logic

Avoid emitting org.freedesktop.DBus.Properties.Properties
changed signals on association objects prior to an
org.freedesktop.DBus.ObjectManager.Interfaces removed signal.

Do this by dropping the Association append, remove, and emit_signal
methods and move their logic to the mapper.

Change-Id: Ibff3d7e0eb47de3ea992394e2122d39407aaf64e
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/obmc/mapper/server.py b/obmc/mapper/server.py
index 03400d6..6e46fc0 100644
--- a/obmc/mapper/server.py
+++ b/obmc/mapper/server.py
@@ -188,22 +188,6 @@
         super(Association, self).__init__(conn=bus, object_path=path)
         self.properties = {self.iface: {'endpoints': endpoints}}
 
-    def emit_signal(self, old):
-        new = self.properties[self.iface]['endpoints']
-        if old != new:
-            self.PropertiesChanged(
-                self.iface, self.properties[self.iface], ['endpoints'])
-
-    def append(self, endpoints):
-        old = self.endpoints
-        self.endpoints = list(set(endpoints).union(self.endpoints))
-        self.emit_signal(old)
-
-    def remove(self, endpoints):
-        old = self.endpoints
-        self.endpoints = list(set(self.endpoints).difference(endpoints))
-        self.emit_signal(old)
-
     @dbus.service.method(dbus.PROPERTIES_IFACE, 'ss', 'as')
     def Get(self, interface_name, property_name):
         if property_name != 'endpoints':
@@ -680,23 +664,26 @@
     def update_association(self, path, removed, added):
         iface = obmc.dbuslib.enums.OBMC_ASSOC_IFACE
         assoc = self.manager.get(path, None)
-        create = [] if assoc else [iface]
 
-        if added and create:
+        old_endpoints = assoc.properties[iface]['endpoints'] if assoc else []
+        new_endpoints = list(
+            set(old_endpoints).union(added).difference(removed))
+
+        if old_endpoints == new_endpoints:
+            return
+
+        create = [] if old_endpoints else [iface]
+        delete = [] if new_endpoints else [iface]
+
+        if create:
             self.manager.add(
-                path, Association(self.bus, path, added))
-            assoc = self.manager.get(path)
-        elif added:
-            assoc.append(added)
-
-        if assoc and removed:
-            assoc.remove(removed)
-
-        delete = []
-        endpoints = assoc.properties[iface]['endpoints']
-        if assoc and not endpoints:
+                path, Association(self.bus, path, new_endpoints))
+        elif delete:
             self.manager.remove(path)
-            delete = [iface]
+        else:
+            assoc.properties[iface]['endpoints'] = new_endpoints
+            assoc.PropertiesChanged(
+                iface, {'endpoints': new_endpoints}, ['endpoints'])
 
         if create != delete:
             self.update_interfaces(