[SEBA-157]

Add log configuration to VOLTHA chart, configured to use kafkaloghandler
Resolve conflict between VOLTHA and ONOS logging fields

Change-Id: Ia218dedbd189a95d83b7e71887216f8de391ed91
diff --git a/onos/templates/log-agent-configmap.yaml b/onos/templates/log-agent-configmap.yaml
index 021ab63..44e2763 100644
--- a/onos/templates/log-agent-configmap.yaml
+++ b/onos/templates/log-agent-configmap.yaml
@@ -39,6 +39,11 @@
         multiline.negate: false
         multiline.match: after
 
+    # remove unneeded fields
+    processors:
+      - drop_fields:
+          fields: ["host", "prospector", "input"]
+
     output.kafka:
       hosts: {{ .Values.log_agent.kafka_brokers | toJson }}
       topic: 'onos.log'
diff --git a/voltha/templates/_helpers.tpl b/voltha/templates/_helpers.tpl
index bbe8aef..d2d876f 100644
--- a/voltha/templates/_helpers.tpl
+++ b/voltha/templates/_helpers.tpl
@@ -16,7 +16,6 @@
 
 {{- define "voltha-vcore.cmd" }}
 - "voltha/voltha/main.py"
-- "-v"
 - "--etcd=etcd-cluster.default.svc.cluster.local:2379"
 - "--kafka={{ .Values.kafkaReleaseName }}.default.svc.cluster.local"
 - "--rest-port=8880"
@@ -27,3 +26,35 @@
 - "--ponsim-comm=grpc"
 - "--core-number-extractor=^.*-([0-9]+)_.*$"
 {{- end }}
+
+{{- define "logconfig.yml" }}
+version: 1
+
+formatters:
+  default:
+    format: '%(asctime)s.%(msecs)03d %(levelname)-8s %(threadName)s %(module)s.%(funcName)s %(message)s'
+    datefmt: '%Y%m%dT%H%M%S'
+
+handlers:
+  console:
+    class : logging.StreamHandler
+    formatter: default
+    stream: ext://sys.stdout
+  localRotatingFile:
+    class: logging.handlers.RotatingFileHandler
+    filename: voltha.log
+    formatter: default
+    maxBytes: 2097152
+    backupCount: 10
+  kafka:
+    class: kafkaloghandler.KafkaLogHandler
+    bootstrap_servers:
+      - "cord-kafka.default:9092"
+    topic: "voltha.log.{{ .KafkaTopic }}"
+
+loggers:
+  '':
+    handlers: [console, localRotatingFile, kafka]
+    level: DEBUG
+    propagate: False
+{{- end }}
diff --git a/voltha/templates/logconfigmaps.yaml b/voltha/templates/logconfigmaps.yaml
new file mode 100644
index 0000000..b72db84
--- /dev/null
+++ b/voltha/templates/logconfigmaps.yaml
@@ -0,0 +1,48 @@
+---
+# Copyright 2018-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: vcore-logconfig
+  namespace: {{ .Values.global.namespace }}
+  serviceAccountName: {{ .Values.global.namespace }}-serviceaccount
+data:
+  logconfig: |
+{{- $data := dict "KafkaTopic" "vcore" }}
+{{ include "logconfig.yml" $data | indent 4 }}
+
+---
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: netconf-logconfig
+  namespace: {{ .Values.global.namespace }}
+  serviceAccountName: {{ .Values.global.namespace }}-serviceaccount
+data:
+  logconfig: |
+{{- $data := dict "KafkaTopic" "netconf" }}
+{{ include "logconfig.yml" $data | indent 4 }}
+
+---
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: ofagent-logconfig
+  namespace: {{ .Values.global.namespace }}
+  serviceAccountName: {{ .Values.global.namespace }}-serviceaccount
+data:
+  logconfig: |
+{{- $data := dict "KafkaTopic" "ofagent" }}
+{{ include "logconfig.yml" $data | indent 4 }}
diff --git a/voltha/templates/netconf.yaml b/voltha/templates/netconf.yaml
index 8ea1638..52989b8 100644
--- a/voltha/templates/netconf.yaml
+++ b/voltha/templates/netconf.yaml
@@ -1,3 +1,4 @@
+---
 # Copyright 2017-present Open Networking Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,8 +24,8 @@
     app: netconf
   clusterIP: None
   ports:
-  - port: 830
-    targetPort: 830
+    - port: 830
+      targetPort: 830
 ---
 apiVersion: apps/v1beta1
 kind: Deployment
@@ -44,13 +45,24 @@
       serviceAccountName: {{ .Values.global.namespace }}-serviceaccount
       terminationGracePeriodSeconds: 10
       containers:
-      - name: netconf
-        image: {{ .Values.netconfImage }}
-        imagePullPolicy: {{ .Values.imagePullPolicy }}
-        ports:
-        - containerPort: 830
-        env:
-        - name: NETCONF_PORT
-          value: "830"
-        args:
-{{ toYaml .Values.netconf_args | indent 8 }} 
+        - name: netconf
+          image: {{ .Values.netconfImage }}
+          imagePullPolicy: {{ .Values.imagePullPolicy }}
+          ports:
+            - containerPort: 830
+          env:
+            - name: NETCONF_PORT
+              value: "830"
+          args:
+{{ toYaml .Values.netconf_args | indent 12}}
+          volumeMounts:
+            - name: netconf-logconfig-vol
+              mountPath: /netconf/netconf/logconfig.yml
+              subPath: logconfig.yml
+      volumes:
+        - name: netconf-logconfig-vol
+          configMap:
+            name: netconf-logconfig
+            items:
+              - key: logconfig
+                path: logconfig.yml
diff --git a/voltha/templates/ofagent.yaml b/voltha/templates/ofagent.yaml
index 263223d..83d3848 100644
--- a/voltha/templates/ofagent.yaml
+++ b/voltha/templates/ofagent.yaml
@@ -1,3 +1,4 @@
+---
 # Copyright 2017-present Open Networking Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,13 +31,24 @@
       serviceAccountName: {{ .Values.global.namespace }}-serviceaccount
       terminationGracePeriodSeconds: 10
       containers:
-      - name: ofagent
-        image: {{ .Values.ofagentImage }}
-        imagePullPolicy: {{ .Values.imagePullPolicy }}
-        env:
-        - name: NAMESPACE
-          valueFrom:
-            fieldRef:
-              fieldPath: metadata.namespace
-        args:
-{{ toYaml .Values.ofagent_args | indent 8 }} 
+        - name: ofagent
+          image: {{ .Values.ofagentImage }}
+          imagePullPolicy: {{ .Values.imagePullPolicy }}
+          env:
+            - name: NAMESPACE
+              valueFrom:
+                fieldRef:
+                  fieldPath: metadata.namespace
+          args:
+{{ toYaml .Values.ofagent_args | indent 12 }}
+          volumeMounts:
+            - name: ofagent-logconfig-vol
+              mountPath: /ofagent/ofagent/logconfig.yml
+              subPath: logconfig.yml
+      volumes:
+        - name: ofagent-logconfig-vol
+          configMap:
+            name: ofagent-logconfig
+            items:
+              - key: logconfig
+                path: logconfig.yml
diff --git a/voltha/templates/vcore_for_etcd.yaml b/voltha/templates/vcore_for_etcd.yaml
index 206930c..4643d88 100644
--- a/voltha/templates/vcore_for_etcd.yaml
+++ b/voltha/templates/vcore_for_etcd.yaml
@@ -1,3 +1,4 @@
+---
 # Copyright 2017-present Open Networking Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -76,5 +77,14 @@
               name: mystery-port
             - containerPort: 50556
               name: grpc-port
-
-
+          volumeMounts:
+            - name: vcore-logconfig-vol
+              mountPath: /voltha/voltha/logconfig.yml
+              subPath: logconfig.yml
+      volumes:
+        - name: vcore-logconfig-vol
+          configMap:
+            name: vcore-logconfig
+            items:
+              - key: logconfig
+                path: logconfig.yml
diff --git a/voltha/values.yaml b/voltha/values.yaml
index 63b0c31..2dacb39 100644
--- a/voltha/values.yaml
+++ b/voltha/values.yaml
@@ -86,14 +86,12 @@
 
 ofagent_args:
 - "/ofagent/ofagent/main.py"
-- "-v"
 - "--consul=consul.$(NAMESPACE).svc.cluster.local:8500"
 - "--controller=onos-openflow.default.svc.cluster.local:6653"
 - "--grpc-endpoint=vcore.$(NAMESPACE).svc.cluster.local:50556"
 
 netconf_args:
 - "/netconf/netconf/main.py"
-- "-v"
 - "--consul=consul:8500"
 - "--grpc-endpoint=voltha:50555"