[EDGEPOD-152] Modification in Fabric events steps to use fabric per site

Change-Id: I9e19e1f6d8548dcbbeb88f4c7a1333ff6cc9e765
diff --git a/VERSION b/VERSION
index 7364556..b502146 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-3.0.2-dev
+3.0.2
diff --git a/xos/synchronizer/event_steps/kubernetes_event.py b/xos/synchronizer/event_steps/kubernetes_event.py
index 9f02171..223247c 100644
--- a/xos/synchronizer/event_steps/kubernetes_event.py
+++ b/xos/synchronizer/event_steps/kubernetes_event.py
@@ -1,4 +1,3 @@
-
 # Copyright 2017-present Open Networking Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -33,17 +32,43 @@
         super(KubernetesPodDetailsEventStep, self).__init__(*args, **kwargs)
 
     @staticmethod
-    def get_fabric_onos(service):
-        service = Service.objects.get(id=service.id)
+    def get_fabric_onos(fabric):
+        service = Service.objects.get(id=fabric.id)
         # get the onos_fabric service
-        fabric_onos = [s.leaf_model for s in service.provider_services if "onos" in s.name.lower()]
+        fabric_onos = service.provider_services[0].leaf_model
+        if not fabric_onos:
+            log.error("ONOS Service is not found in provider_services of Fabric %s" % service.name)
+            raise Exception('Configuration error. Fabric without ONOS is not possible.')
 
-        if len(fabric_onos) == 0:
-            raise Exception('Cannot find ONOS service in provider_services of Fabric')
+        return fabric_onos
 
-        return fabric_onos[0]
+    @staticmethod
+    def dirty_switch(fabric_switches=None):
+        switches = None
+        if fabric_switches:
+            switches = fabric_switches
+        else:
+            switches = Switch.objects.all()
+
+        for switch in switches:
+            log.info("Dirtying Switch", switch=switch)
+            switch.backend_code = 0
+            switch.backend_status = "resynchronize due to kubernetes event"
+            switch.save(update_fields=["updated", "backend_code", "backend_status"], always_update_timestamp=True)
+
+            for port in switch.ports.all():
+                log.info("Dirtying SwitchPort", port=port)
+                port.backend_code = 0
+                port.backend_status = "resynchronize due to kubernetes event"
+                port.save(
+                    update_fields=[
+                        "updated",
+                        "backend_code",
+                        "backend_status"],
+                    always_update_timestamp=True)
 
     def process_event(self, event):
+        log.info("processing event")
         value = json.loads(event.value)
 
         if (value.get("status") != "created"):
@@ -61,19 +86,9 @@
             if (onos_service.name.lower() != xos_service.lower()):
                 continue
 
-            for switch in Switch.objects.all():
-                log.info("Dirtying Switch", switch=switch)
-                switch.backend_code = 0
-                switch.backend_status = "resynchronize due to kubernetes event"
-                switch.save(update_fields=["updated", "backend_code", "backend_status"], always_update_timestamp=True)
-
-                for port in switch.ports.all():
-                    log.info("Dirtying SwitchPort", port=port)
-                    port.backend_code = 0
-                    port.backend_status = "resynchronize due to kubernetes event"
-                    port.save(
-                        update_fields=[
-                            "updated",
-                            "backend_code",
-                            "backend_status"],
-                        always_update_timestamp=True)
+            if(len(FabricService.objects.all()) == 1):
+                log.info("Dirtying all switches.")
+                KubernetesPodDetailsEventStep.dirty_switch()
+            else:
+                fabric_switches = fabric_service.switch.all()
+                KubernetesPodDetailsEventStep.dirty_switch(fabric_switches)