[CORD-3154] Adding support for host-learning config in fabric ports

Change-Id: Ic7f00d625ecd6fc6e0085a01bfccd3dd5fc64d7b
diff --git a/xos/synchronizer/models/fabric.xproto b/xos/synchronizer/models/fabric.xproto
index ac617be..71ad3ee 100644
--- a/xos/synchronizer/models/fabric.xproto
+++ b/xos/synchronizer/models/fabric.xproto
@@ -24,6 +24,7 @@
 
     required manytoone switch->Switch:ports = 1 [help_text = "The fabric switch the port belongs to", db_index = True, null = False, blank = False, tosca_key=True];
     required int32 portId = 2 [help_text = "The unique port OpenFlow port ID", null = False, db_index = False, blank = False, tosca_key=True];
+    required bool host_learning = 3 [help_text = "whether or not to enable autodiscovery", default = True, null = False, db_index = False, blank = False];
 }
 
 message PortInterface(XOSBase) {
diff --git a/xos/synchronizer/steps/sync_fabric_port.py b/xos/synchronizer/steps/sync_fabric_port.py
index 793bfd2..bfac5b9 100644
--- a/xos/synchronizer/steps/sync_fabric_port.py
+++ b/xos/synchronizer/steps/sync_fabric_port.py
@@ -43,13 +43,18 @@
 
         # Send port config to onos-fabric netcfg
         data = {
-          "ports": {
-            "%s/%s" % (model.switch.ofId, model.portId) : {
-              "interfaces" : interfaces
+            "ports": {
+                "%s/%s" % (model.switch.ofId, model.portId) : {
+                    "interfaces": interfaces,
+                    "hostLearning": {
+                        "enabled": model.host_learning
+                    }
+                }
             }
-          }
         }
 
+        log.debug("Port %s/%s data" % (model.switch.ofId, model.portId), data=data)
+
         onos = Helpers.get_onos_fabric_service()
 
         url = 'http://%s:%s/onos/v1/network/configuration/' % (onos.rest_hostname, onos.rest_port)
@@ -61,9 +66,9 @@
             raise Exception("Failed to add port %s into ONOS" % model.name)
         else:
             try:
-                print r.json()
+                log.info("Port %s/%s response" % (model.switch.ofId, model.portId), json=r.json())
             except Exception:
-                print r.text
+                log.info("Port %s/%s response" % (model.switch.ofId, model.portId), text=r.text)
 
     def delete_record(self, model):
         log.info("Removing port %s/%s from onos-fabric" % (model.switch.ofId, model.portId))
diff --git a/xos/synchronizer/steps/test_sync_fabric_port.py b/xos/synchronizer/steps/test_sync_fabric_port.py
index 00aded5..696a6a7 100644
--- a/xos/synchronizer/steps/test_sync_fabric_port.py
+++ b/xos/synchronizer/steps/test_sync_fabric_port.py
@@ -100,6 +100,7 @@
         self.o = Mock()
         self.o.id = 1
         self.o.tologdict.return_value = {}
+        self.o.host_learning = True
 
 
 
@@ -127,7 +128,10 @@
                             "name": intf1.name,
                             "ips": [ intf1.ips ]
                         }
-                    ]
+                    ],
+                    "hostLearning": {
+                        "enabled": self.o.host_learning
+                    }
                 }
             }
         }
@@ -153,6 +157,7 @@
         self.o.interfaces.all.return_value = [intf1]
         self.o.switch.ofId = "of:1234"
         self.o.portId = "1"
+        self.o.host_learning = False
 
         expected_conf = {
             "ports": {
@@ -163,7 +168,10 @@
                             "ips": [intf1.ips],
                             "vlan-untagged": intf1.vlanUntagged
                         }
-                    ]
+                    ],
+                    "hostLearning": {
+                        "enabled": self.o.host_learning
+                    }
                 }
             }
         }