From 531369836c304678b8fad9c13e9583b44f4f3f2c Mon Sep 17 00:00:00 2001
From: Peter Penchev <openstack-dev@storpool.com>
Date: Tue, 10 Sep 2019 11:34:25 +0300
Subject: [PATCH 2/2] DNM: diagnostic messages while loading the driver.

Change-Id: I3e7ff44d4f0eeca384ae03405d47328483461ded
---
 cinderlib/cinderlib.py                   | 11 +++++++++++
 cinderlib/tests/functional/base_tests.py | 14 ++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/cinderlib/cinderlib.py b/cinderlib/cinderlib.py
index 9a4766e..258845b 100644
--- a/cinderlib/cinderlib.py
+++ b/cinderlib/cinderlib.py
@@ -19,6 +19,7 @@ import logging
 import multiprocessing
 import os
 import six
+import sys  # RDBG
 
 from cinder import coordination
 from cinder.db import api as db_api
@@ -71,12 +72,16 @@ class Backend(object):
     _volumes_inflight = {}
 
     def __init__(self, volume_backend_name, **driver_cfg):
+        print(f'RDBG cinderlib.Backend.__init__() name {repr(volume_backend_name)} cfg {repr(driver_cfg)}', file=sys.stderr)
         if not self.global_initialization:
+            print(f'RDBG - invoking global_setup()', file=sys.stderr)
             self.global_setup()
+            print(f'RDBG - back to cinderlib.Backend.__init__()', file=sys.stderr)
         driver_cfg['volume_backend_name'] = volume_backend_name
         Backend.backends[volume_backend_name] = self
 
         conf = self._set_backend_config(driver_cfg)
+        print(f'RDBG - cinderlib.Backend.__init__ got config {repr(conf)}', file=sys.stderr)
         self.driver = importutils.import_object(
             conf.volume_driver,
             configuration=conf,
@@ -84,6 +89,7 @@ class Backend(object):
             host='%s@%s' % (cfg.CONF.host, volume_backend_name),
             cluster_name=None,  # We don't use cfg.CONF.cluster for now
             active_backend_id=None)  # No failover for now
+        print(f'RDBG - cinderlib.Backend.__init__ got a driver: {repr(driver)}', file=sys.stderr)
         self.driver.do_setup(objects.CONTEXT)
         self.driver.check_for_setup_error()
 
@@ -270,14 +276,19 @@ class Backend(object):
             cls._parser.set(section, key, val)
 
     def _set_backend_config(self, driver_cfg):
+        print(f'RDBG cinderlib._set_backend_config() driver_cfg {repr(driver_cfg)}', file=sys.stderr)
         backend_name = driver_cfg['volume_backend_name']
+        print(f'RDBG - backend_name {backend_name}', file=sys.stderr)
         self._parser.add_section(backend_name)
         self.__set_parser_kv(driver_cfg, backend_name)
         self._parser.set('DEFAULT', 'enabled_backends',
                          ','.join(self.backends.keys()))
+        print(f'RDBG - invoking _update_cinder_config()', file=sys.stderr)
         self._update_cinder_config()
+        print(f'RDBG - about to create a config object, opts {repr(manager.volume_backend_opts)} config_group {repr(backend_name)}', file=sys.stderr)
         config = configuration.Configuration(manager.volume_backend_opts,
                                              config_group=backend_name)
+        print(f'RDBG - _set_backend_config() returning {repr(config)}', file=sys.stderr)
         return config
 
     @classmethod
diff --git a/cinderlib/tests/functional/base_tests.py b/cinderlib/tests/functional/base_tests.py
index 65c15a4..2f9bbcb 100644
--- a/cinderlib/tests/functional/base_tests.py
+++ b/cinderlib/tests/functional/base_tests.py
@@ -16,6 +16,7 @@
 import functools
 import os
 import subprocess
+import sys  # RDBG
 import tempfile
 
 from oslo_config import cfg
@@ -40,7 +41,9 @@ def set_backend(func, new_name, backend_name):
 
 def test_all_backends(cls):
     """Decorator to run tests in a class for all available backends."""
+    print(f'RDBG test_all_backends() invoked', file=sys.stderr)
     config = BaseFunctTestCase.ensure_config_loaded()
+    print(f'RDBG - test_all_backends() got config {repr(config)}', file=sys.stderr)
     for fname, func in cls.__dict__.items():
         if fname.startswith('test_'):
             for backend in config['backends']:
@@ -67,15 +70,20 @@ class BaseFunctTestCase(unittest2.TestCase):
 
     @classmethod
     def ensure_config_loaded(cls):
+        print(f'RDBG ensure_config_loaded({cls.__name__})', file=sys.stderr)
         if not cls.tests_config:
+            print(f'RDBG - no tests_config, config file {cls.CONFIG_FILE}', file=sys.stderr)
             # If it's a .conf type of configuration file convert it to dict
             if cls.CONFIG_FILE.endswith('.conf'):
                 cls.tests_config = cinder_to_yaml.convert(cls.CONFIG_FILE)
+                print(f'RDBG - endswith conf, got {repr(cls.tests_config)}', file=sys.stderr)
             else:
                 with open(cls.CONFIG_FILE, 'r') as f:
                     cls.tests_config = yaml.load(f)
+                    print(f'RDBG - assuming yaml, got {repr(cls.tests_config)}', file=sys.stderr)
             cls.tests_config.setdefault('logs', cls.LOGGING_ENABLED)
             cls.tests_config.setdefault('size_precision', cls.PRECISION)
+        print(f'RDBG - ensure_config_loaded returning {repr(cls.tests_config)}', file=sys.stderr)
         return cls.tests_config
 
     @staticmethod
@@ -90,9 +98,11 @@ class BaseFunctTestCase(unittest2.TestCase):
 
     @classmethod
     def setUpClass(cls):
+        print(f'RDBG setUpClass({cls.__name__})', file=sys.stderr)
         cls._replace_oslo_cli_parse()
         config = cls.ensure_config_loaded()
         # Use memory_db persistence instead of memory to ensure migrations work
+        print(f'RDBG - setUpClass() invoking cinderlib.setup()', file=sys.stderr)
         cinderlib.setup(root_helper=cls.ROOT_HELPER,
                         disable_logs=not config['logs'],
                         persistence_config={'storage': 'memory_db'})
@@ -107,16 +117,20 @@ class BaseFunctTestCase(unittest2.TestCase):
                             persistence_config={'storage': 'memory'})
 
         # Initialize backends
+        print(f'RDBG - setUpClass() creating backends: {repr(config["backends"])}', file=sys.stderr)
         cls.backends = [cinderlib.Backend(**cfg) for cfg in
                         config['backends']]
+        print(f'RDBG - setUpClass() created backends: {repr(cls.backends)}', file=sys.stderr)
         # Lazy load backend's _volumes variable using the volumes property so
         # new volumes are added to this list on successful creation.
         for backend in cls.backends:
+            print(f'RDBG - lazy-loading the volumes for {backend}', file=sys.stderr)
             backend.volumes
 
         # Set current backend, by default is the first
         cls.backend = cls.backends[0]
         cls.size_precision = config['size_precision']
+        print(f'RDBG - setUpClass() done, current backend {cls.backend}', file=sys.stderr)
 
     @classmethod
     def tearDownClass(cls):
-- 
2.23.0

