Merge "Fixed to setOnosLogLevels keyword and use in the pipeline"
diff --git a/jjb/pipeline/voltha/master/physical-build.groovy b/jjb/pipeline/voltha/master/physical-build.groovy
index 24d1880..28241f8 100644
--- a/jjb/pipeline/voltha/master/physical-build.groovy
+++ b/jjb/pipeline/voltha/master/physical-build.groovy
@@ -264,16 +264,18 @@
               """
             }
             timeout(1) {
-              // setOnosLogLevels()
+              setOnosLogLevels([
+                  onosNamespace: infraNamespace,
+                  apps: [
+                    'org.opencord.dhcpl2relay',
+                    'org.opencord.olt',
+                    'org.opencord.aaa',
+                    'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
+                    'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
+                  ]
+              ])
               waitUntil {
                 sr_active_out = sh returnStatus: true, script: """
-                sshpass -p karaf ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 30115 karaf@${deployment_config.nodes[0].ip} "log:set TRACE org.opencord.dhcpl2relay"
-                sshpass -p karaf ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 30115 karaf@${deployment_config.nodes[0].ip} "log:set TRACE org.opencord.aaa"
-                sshpass -p karaf ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 30115 karaf@${deployment_config.nodes[0].ip} "log:set TRACE org.opencord.olt"
-                #TRACE in the pipeliner is too chatty, moving to DEBUG
-                sshpass -p karaf ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 30115 karaf@${deployment_config.nodes[0].ip} "log:set DEBUG org.opencord.olt.driver"
-                sshpass -p karaf ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 30115 karaf@${deployment_config.nodes[0].ip} "log:set DEBUG org.onosproject.net.flowobjective.impl.FlowObjectiveManager"
-                sshpass -p karaf ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 30115 karaf@${deployment_config.nodes[0].ip} "log:set DEBUG org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager"
                 curl -sSL --user karaf:karaf -X GET http://${deployment_config.nodes[0].ip}:30120/onos/v1/applications/org.onosproject.segmentrouting | jq '.state' | grep ACTIVE
                 sshpass -p karaf ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 30115 karaf@${deployment_config.nodes[0].ip} "cfg set org.onosproject.provider.lldp.impl.LldpLinkProvider enabled false"
                 sshpass -p karaf ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 30115 karaf@${deployment_config.nodes[0].ip} "cfg set org.onosproject.net.flow.impl.FlowRuleManager purgeOnDisconnection false"
diff --git a/vars/setOnosLogLevels.groovy b/vars/setOnosLogLevels.groovy
index 7ff0c19..b3281b9 100644
--- a/vars/setOnosLogLevels.groovy
+++ b/vars/setOnosLogLevels.groovy
@@ -2,7 +2,7 @@
 
   def defaultConfig = [
       onosNamespace: "infra",
-      apps: ['org.opencord.dhcpl2relay', 'org.opencord.olt', 'org.opencord.olt'],
+      apps: ['org.opencord.dhcpl2relay', 'org.opencord.olt', 'org.opencord.aaa'],
       logLevel: "DEBUG",
   ]
 
@@ -12,28 +12,29 @@
 
   def cfg = defaultConfig + config
 
-  def onosInstances = sh """
-  kubectl get pods -n ${cfg.onosNamespace} -l app=onos-classic --no-headers | awk '{print $1}'
-  """
+  def onosInstances = sh (
+    script: "kubectl get pods -n ${cfg.onosNamespace} -l app=onos-classic --no-headers | awk '{print \$1}'",
+    returnStdout: true
+  ).trim()
 
   for(int i = 0;i<onosInstances.split( '\n' ).size();i++) {
     def instance = onosInstances.split('\n')[i]
-
+      println "Setting log levels on ${instance}"
       sh """
+      set +x
       _TAG="onos-pf" bash -c "while true; do kubectl port-forward -n ${cfg.onosNamespace} ${instance} 8101; done"&
       """
 
-      for (int j = 0; j < apps.size(); j++) {
-        def app = apps[i]
+      for (int j = 0; j < cfg.apps.size(); j++) {
+        def app = cfg.apps[j]
         sh """
+        set +x
         sshpass -p karaf ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 8101 karaf@localhost log:set ${cfg.logLevel} ${app}
         """
       }
-
-  })
-
-  sh """
-    set +x
-    ps -ef | grep _TAG="onos-pf" | grep -v grep | awk '{print \$2}' | xargs --no-run-if-empty kill -9
-  """
+      sh """
+        set +x
+        ps e -ww -A | grep _TAG="onos-pf" | grep -v grep | awk '{print \$1}' | xargs --no-run-if-empty kill -9
+      """
+  }
 }