[PMSH] Replace own logging implementation with pylog

Signed-off-by: ERIMROB <robertas.rimkus@est.tech>
Issue-ID: DCAEGEN2-2155
Change-Id: I670c4fff8029a73075b651c2afe6237c08cf907c
diff --git a/components/pm-subscription-handler/tests/log_config.yaml b/components/pm-subscription-handler/tests/log_config.yaml
new file mode 100755
index 0000000..5662070
--- /dev/null
+++ b/components/pm-subscription-handler/tests/log_config.yaml
@@ -0,0 +1,20 @@
+version: 1
+
+disable_existing_loggers: true
+
+loggers:
+  onap_logger:
+    level: INFO
+    handlers: [stdout_handler]
+    propagate: false
+handlers:
+  stdout_handler:
+    class: logging.StreamHandler
+    formatter: mdcFormatter
+formatters:
+  mdcFormatter:
+    format: '%(asctime)s | %(threadName)s | %(thread)d | %(levelname)s | %(module)s
+      | %(funcName)s | %(mdc)s | %(message)s'
+    mdcfmt: '{ServiceName} | {RequestID} | {InvocationID}'
+    datefmt: '%Y-%m-%dT%H:%M:%S%z'
+    (): onaplogging.mdcformatter.MDCFormatter
diff --git a/components/pm-subscription-handler/tests/test_aai_service.py b/components/pm-subscription-handler/tests/test_aai_service.py
index 1ee7155..9a3a1b6 100644
--- a/components/pm-subscription-handler/tests/test_aai_service.py
+++ b/components/pm-subscription-handler/tests/test_aai_service.py
@@ -25,18 +25,24 @@
 from requests import Session
 
 import mod.aai_client as aai_client
+from mod import create_app
 
 
 class AaiClientTestCase(TestCase):
 
-    def setUp(self):
+    @patch('mod.update_config')
+    @patch('mod.get_db_connection_url')
+    def setUp(self, mock_get_db_url, mock_update_config):
+        mock_get_db_url.return_value = 'sqlite://'
         self.env = EnvironmentVarGuard()
         self.env.set('AAI_SERVICE_HOST', '1.2.3.4')
         self.env.set('AAI_SERVICE_PORT', '8443')
+        self.env.set('LOGGER_CONFIG', os.path.join(os.path.dirname(__file__), 'log_config.yaml'))
         with open(os.path.join(os.path.dirname(__file__), 'data/cbs_data_1.json'), 'r') as data:
             self.cbs_data = json.load(data)
         with open(os.path.join(os.path.dirname(__file__), 'data/aai_xnfs.json'), 'r') as data:
             self.aai_response_data = data.read()
+        self.app = create_app()
 
     @patch.object(Session, 'put')
     def test_aai_client_get_pm_sub_data_success(self, mock_session):
diff --git a/components/pm-subscription-handler/tests/test_controller.py b/components/pm-subscription-handler/tests/test_controller.py
index 8ef3946..8ca208a 100755
--- a/components/pm-subscription-handler/tests/test_controller.py
+++ b/components/pm-subscription-handler/tests/test_controller.py
@@ -29,9 +29,10 @@
 
 
 class ControllerTestCase(unittest.TestCase):
+    @patch('mod.update_config')
     @patch('mod.get_db_connection_url')
     @patch.object(Session, 'put')
-    def setUp(self, mock_session, mock_get_db_url):
+    def setUp(self, mock_session, mock_get_db_url, mock_update_config):
         mock_get_db_url.return_value = 'sqlite://'
         with open(os.path.join(os.path.dirname(__file__), 'data/aai_xnfs.json'), 'r') as data:
             self.aai_response_data = data.read()
@@ -40,8 +41,7 @@
         self.env = EnvironmentVarGuard()
         self.env.set('AAI_SERVICE_HOST', '1.2.3.4')
         self.env.set('AAI_SERVICE_PORT', '8443')
-        self.env.set('TESTING', 'True')
-        self.env.set('LOGS_PATH', './unit_test_logs')
+        self.env.set('LOGGER_CONFIG', os.path.join(os.path.dirname(__file__), 'log_config.yaml'))
         with open(os.path.join(os.path.dirname(__file__), 'data/cbs_data_1.json'), 'r') as data:
             self.cbs_data_1 = json.load(data)
         self.sub_1, self.xnfs = aai_client.get_pmsh_subscription_data(self.cbs_data_1)
diff --git a/components/pm-subscription-handler/tests/test_network_function.py b/components/pm-subscription-handler/tests/test_network_function.py
index 138d99a..a5324bd 100755
--- a/components/pm-subscription-handler/tests/test_network_function.py
+++ b/components/pm-subscription-handler/tests/test_network_function.py
@@ -15,6 +15,7 @@
 #
 # SPDX-License-Identifier: Apache-2.0
 # ============LICENSE_END=====================================================
+import os
 from test.support import EnvironmentVarGuard
 from unittest import TestCase
 from unittest.mock import patch
@@ -26,13 +27,14 @@
 
 class NetworkFunctionTests(TestCase):
 
+    @patch('mod.update_config')
     @patch('mod.get_db_connection_url')
-    def setUp(self, mock_get_db_url):
+    def setUp(self, mock_get_db_url, mock_update_config):
         mock_get_db_url.return_value = 'sqlite://'
         self.nf_1 = NetworkFunction(nf_name='pnf_1', orchestration_status='Inventoried')
         self.nf_2 = NetworkFunction(nf_name='pnf_2', orchestration_status='Active')
         self.env = EnvironmentVarGuard()
-        self.env.set('LOGS_PATH', './unit_test_logs')
+        self.env.set('LOGGER_CONFIG', os.path.join(os.path.dirname(__file__), 'log_config.yaml'))
         self.app = create_app()
         self.app_context = self.app.app_context()
         self.app_context.push()
diff --git a/components/pm-subscription-handler/tests/test_pmsh_utils.py b/components/pm-subscription-handler/tests/test_pmsh_utils.py
index 236331b..0c3b2d2 100644
--- a/components/pm-subscription-handler/tests/test_pmsh_utils.py
+++ b/components/pm-subscription-handler/tests/test_pmsh_utils.py
@@ -31,16 +31,18 @@
 
 class PmshUtilsTestCase(TestCase):
 
+    @patch('mod.update_config')
     @patch('mod.create_app')
     @patch('mod.get_db_connection_url')
-    def setUp(self, mock_get_db_url, mock_app):
+    def setUp(self, mock_get_db_url, mock_app, mock_update_config):
         mock_get_db_url.return_value = 'sqlite://'
         with open(os.path.join(os.path.dirname(__file__), 'data/cbs_data_1.json'), 'r') as data:
             self.cbs_data = json.load(data)
         self.app_conf = AppConfig(**self.cbs_data['config'])
         self.sub = Subscription(**self.cbs_data['policy']['subscription'])
         self.env = EnvironmentVarGuard()
-        self.env.set('LOGS_PATH', './unit_test_logs')
+        self.env.set('TESTING', 'True')
+        self.env.set('LOGGER_CONFIG', os.path.join(os.path.dirname(__file__), 'log_config.yaml'))
         self.policy_mr_sub = self.app_conf.get_mr_sub('policy_pm_subscriber')
         self.mock_app = mock_app
         self.app = create_app()
diff --git a/components/pm-subscription-handler/tests/test_subscription.py b/components/pm-subscription-handler/tests/test_subscription.py
index dc549c9..b50d9aa 100755
--- a/components/pm-subscription-handler/tests/test_subscription.py
+++ b/components/pm-subscription-handler/tests/test_subscription.py
@@ -33,12 +33,14 @@
 
 
 class SubscriptionTest(TestCase):
+    @patch('mod.update_config')
     @patch('mod.pmsh_utils._MrPub')
     @patch('mod.pmsh_utils._MrSub')
     @patch('mod.get_db_connection_url')
     @patch.object(Session, 'put')
     @patch('pmsh_service_main.AppConfig')
-    def setUp(self, mock_app_config, mock_session, mock_get_db_url, mock_mr_sub, mock_mr_pub):
+    def setUp(self, mock_app_config, mock_session, mock_get_db_url,
+              mock_mr_sub, mock_mr_pub, mock_update_config):
         mock_get_db_url.return_value = 'sqlite://'
         with open(os.path.join(os.path.dirname(__file__), 'data/aai_xnfs.json'), 'r') as data:
             self.aai_response_data = data.read()
@@ -47,8 +49,7 @@
         self.env = EnvironmentVarGuard()
         self.env.set('AAI_SERVICE_HOST', '1.2.3.4')
         self.env.set('AAI_SERVICE_PORT', '8443')
-        self.env.set('TESTING', 'True')
-        self.env.set('LOGS_PATH', './unit_test_logs')
+        self.env.set('LOGGER_CONFIG', os.path.join(os.path.dirname(__file__), 'log_config.yaml'))
         with open(os.path.join(os.path.dirname(__file__), 'data/cbs_data_1.json'), 'r') as data:
             self.cbs_data_1 = json.load(data)
         with open(os.path.join(os.path.dirname(__file__),
@@ -103,6 +104,13 @@
 
         self.assertEqual(2, len(subs))
 
+    def test_get_nf_names_per_sub(self):
+        self.sub_1.create()
+        self.sub_1.add_network_function_to_subscription(self.nf_1)
+        self.sub_1.add_network_function_to_subscription(self.nf_2)
+        nfs = Subscription.get_nf_names_per_sub(self.sub_1.subscriptionName)
+        self.assertEqual(2, len(nfs))
+
     def test_create_existing_subscription(self):
         sub1 = self.sub_1.create()
         same_sub1 = self.sub_1.create()
@@ -117,7 +125,6 @@
         new_nf = NetworkFunction(nf_name='vnf_3', orchestration_status='Inventoried')
         self.sub_1.add_network_function_to_subscription(new_nf)
         nf_subs = Subscription.get_all_nfs_subscription_relations()
-        print(nf_subs)
         self.assertEqual(3, len(nf_subs))
 
     def test_add_duplicate_network_functions_per_subscription(self):
@@ -201,7 +208,6 @@
             expected_sub_event = json.load(data)
         app_conf = AppConfig(**self.cbs_data_1['config'])
         actual_sub_event = self.sub_1.prepare_subscription_event(self.nf_1.nf_name, app_conf)
-        print(actual_sub_event)
         self.assertEqual(expected_sub_event, actual_sub_event)
 
     def test_get_nf_models(self):
diff --git a/components/pm-subscription-handler/tests/test_subscription_handler.py b/components/pm-subscription-handler/tests/test_subscription_handler.py
index d922b96..3eb12bc 100644
--- a/components/pm-subscription-handler/tests/test_subscription_handler.py
+++ b/components/pm-subscription-handler/tests/test_subscription_handler.py
@@ -45,7 +45,7 @@
         self.nf_2 = NetworkFunction(nf_name='pnf_2')
         self.nfs = [self.nf_1, self.nf_2]
 
-    @patch('mod.pmsh_logging.debug')
+    @patch('mod.logger.info')
     @patch('mod.aai_client.get_pmsh_subscription_data')
     def test_execute_no_change_of_state(self, mock_get_aai, mock_logger):
         mock_get_aai.return_value = self.mock_sub, self.nfs
@@ -88,7 +88,7 @@
                                                               self.mock_app_conf)
         self.mock_aai_event_thread.return_value.cancel.assert_called()
 
-    @patch('mod.pmsh_logging.debug')
+    @patch('mod.logger.error')
     @patch('mod.aai_client.get_pmsh_subscription_data')
     def test_execute_exception(self, mock_get_aai, mock_logger):
         mock_get_aai.return_value = self.mock_sub, self.nfs