From 223b9428f14b466c1c723dc02e4fb39b7f152caa Mon Sep 17 00:00:00 2001
From: Janki Chhatbar <jchhatba@redhat.com>
Date: Thu, 14 Jun 2018 17:31:46 +0530
Subject: [PATCH] Store ODL logs to file

ODL is configured to log to console and then access the logs
via docker logs. Older logs are being deleted too fast. So
moving back to logging to file which is default setting in ODL
THT.
https://github.com/openstack/tripleo-heat-templates/blob/
master/puppet/services/opendaylight-api.yaml#L60

Change-Id: I29724cfb23e13c8293d1b7b4341cbd409ae1b7a6
Closes-Bug: 1779629
---
 .../logging/files/opendaylight-api.yaml       | 32 +++++++++++++++
 docker/services/opendaylight-api.yaml         | 40 +++++++++----------
 .../neutron-opendaylight.yaml                 |  1 -
 .../services/neutron-opendaylight.yaml        |  1 -
 overcloud-resource-registry-puppet.j2.yaml    |  1 +
 ...and_alone_log_config-5358ec26f7e7a970.yaml |  9 +++++
 6 files changed, 61 insertions(+), 23 deletions(-)
 create mode 100644 docker/services/logging/files/opendaylight-api.yaml
 create mode 100644 releasenotes/notes/odl_stand_alone_log_config-5358ec26f7e7a970.yaml

diff --git a/docker/services/logging/files/opendaylight-api.yaml b/docker/services/logging/files/opendaylight-api.yaml
new file mode 100644
index 0000000000..a035ebb2e6
--- /dev/null
+++ b/docker/services/logging/files/opendaylight-api.yaml
@@ -0,0 +1,32 @@
+heat_template_version: rocky
+
+description: >
+  Logging configuration for containerized OpenDaylight API service
+outputs:
+  config_settings:
+    description: Extra hieradata needed to log to files in the host.
+    value: null
+  docker_config:
+    description: Extra containers needed for logging to files in the host.
+    value:
+      step_1: {}
+  volumes:
+    description: The volumes needed to log to files in the host.
+    value:
+      - /var/log/containers/opendaylight:/opt/opendaylight/data/log
+  host_prep_tasks:
+    description: Extra ansible tasks needed for logging to files in the host.
+    value:
+      - name: create persistent logs directory
+        file:
+          path: "{{ item }}"
+          state: directory
+        with_items:
+          - /var/log/containers/opendaylight
+          - /var/log/opendaylight
+      - name: opendaylight logs readme
+        copy:
+          dest: /var/log/opendaylight/readme.txt
+          content: |
+            Logs from OpenDaylight container can be found at /var/log/containers/opendaylight/karaf.log
+        ignore_errors: true
\ No newline at end of file
diff --git a/docker/services/opendaylight-api.yaml b/docker/services/opendaylight-api.yaml
index 06b30e0bde..28777fe163 100644
--- a/docker/services/opendaylight-api.yaml
+++ b/docker/services/opendaylight-api.yaml
@@ -72,6 +72,9 @@ resources:
       RoleName: {get_param: RoleName}
       RoleParameters: {get_param: RoleParameters}
 
+  OpenDaylightApiLogging:
+    type: OS::TripleO::Services::Logging::OpenDaylightApi
+
 outputs:
   role_data:
     description: Role data for the OpenDaylight API role.
@@ -133,38 +136,33 @@ outputs:
             volumes:
               list_concat:
                 - {get_attr: [ContainersCommon, volumes]}
+                - {get_attr: [OpenDaylightApiLogging, volumes]}
                 -
                   - /var/lib/kolla/config_files/opendaylight_api.json:/var/lib/kolla/config_files/config.json:ro
                   - /var/lib/config-data/puppet-generated/opendaylight/:/var/lib/kolla/config_files/src:ro
                   - /var/lib/opendaylight/journal:/opt/opendaylight/journal
                   - /var/lib/opendaylight/snapshots:/opt/opendaylight/snapshots
                   - /var/lib/opendaylight/data:/opt/opendaylight/data
-                  - /var/log/containers/opendaylight:/opt/opendaylight/data/log
             environment:
               - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
       metadata_settings:
         get_attr: [OpenDaylightBase, role_data, metadata_settings]
       host_prep_tasks:
-        - name: Delete cache folder
-          file:
-            path: /var/lib/opendaylight/data/cache
-            state: absent
-        - name: create persistent directories
-          file:
-            path: "{{ item }}"
-            state: directory
-          with_items:
-            - /var/lib/opendaylight/snapshots
-            - /var/lib/opendaylight/journal
-            - /var/lib/opendaylight/data
-            - /var/log/opendaylight
-            - /var/log/containers/opendaylight
-        - name: opendaylight logs readme
-          copy:
-            dest: /var/log/opendaylight/readme.txt
-            content: |
-              Logs from opendaylight container can be found by running "sudo docker logs opendaylight_api" and are also available in /var/log/containers/opendaylight/karaf.log
-          ignore_errors: true
+        list_concat:
+          - {get_attr: [OpenDaylightApiLogging, host_prep_tasks]}
+          -
+            - name: Delete cache folder
+              file:
+                path: /var/lib/opendaylight/data/cache
+                state: absent
+            - name: create persistent directories
+              file:
+                path: "{{ item }}"
+                state: directory
+              with_items:
+                - /var/lib/opendaylight/snapshots
+                - /var/lib/opendaylight/journal
+                - /var/lib/opendaylight/data
       upgrade_tasks:
         - when: step|int == 0
           tags: common
diff --git a/environments/services-baremetal/neutron-opendaylight.yaml b/environments/services-baremetal/neutron-opendaylight.yaml
index bc0f864f92..a828c36d4a 100644
--- a/environments/services-baremetal/neutron-opendaylight.yaml
+++ b/environments/services-baremetal/neutron-opendaylight.yaml
@@ -13,4 +13,3 @@ parameter_defaults:
   NeutronPluginExtensions: 'port_security'
   NeutronMechanismDrivers: 'opendaylight_v2'
   NeutronServicePlugins: 'odl-router_v2,trunk'
-  OpenDaylightLogMechanism: 'console'
diff --git a/environments/services/neutron-opendaylight.yaml b/environments/services/neutron-opendaylight.yaml
index 8ace95a97e..c2504d60f0 100644
--- a/environments/services/neutron-opendaylight.yaml
+++ b/environments/services/neutron-opendaylight.yaml
@@ -14,4 +14,3 @@ parameter_defaults:
   NeutronPluginExtensions: 'port_security'
   NeutronMechanismDrivers: 'opendaylight_v2'
   NeutronServicePlugins: 'odl-router_v2,trunk'
-  OpenDaylightLogMechanism: 'console'
diff --git a/overcloud-resource-registry-puppet.j2.yaml b/overcloud-resource-registry-puppet.j2.yaml
index 3bc2655bee..72685f9c08 100644
--- a/overcloud-resource-registry-puppet.j2.yaml
+++ b/overcloud-resource-registry-puppet.j2.yaml
@@ -336,6 +336,7 @@ resource_registry:
   OS::TripleO::Services::Logging::NovaCommon: docker/services/logging/files/nova-common.yaml
   OS::TripleO::Services::Logging::NovaLibvirt: OS::Heat::None
   OS::TripleO::Services::Logging::NovaPlacement: docker/services/logging/files/nova-placement.yaml
+  OS::TripleO::Services::Logging::OpenDaylightApi: docker/services/logging/files/opendaylight-api.yaml
   OS::TripleO::Services::Logging::PankoApi: docker/services/logging/files/panko-api.yaml
 
   # Tempest
diff --git a/releasenotes/notes/odl_stand_alone_log_config-5358ec26f7e7a970.yaml b/releasenotes/notes/odl_stand_alone_log_config-5358ec26f7e7a970.yaml
new file mode 100644
index 0000000000..019301ff16
--- /dev/null
+++ b/releasenotes/notes/odl_stand_alone_log_config-5358ec26f7e7a970.yaml
@@ -0,0 +1,9 @@
+---
+features:
+  - |
+    Configure ODL to log to file instead of console. Also ODL
+    log configuration has been moved out of general service
+    configurations to a stand-alone config file at
+    docker/services/logging/files/opendaylight-api.yaml. ODL
+    logs are now accessible at /var/log/containers/opendaylight/
+    karaf.log
\ No newline at end of file