Add support for MultiOpt parameters
Some drivers use MultiOpt parameters, which are parameters that can be present multiple times in a configuration file and which the parser joins together into a single list. This is not a supported feature of normal .INI file parsers, as the last configuration option overwrites the old value. This patch adds a "hack" to make it work, so we now support MultiOpt parameters that must be apssed to cinderlib as a list or a tuple.
This commit is contained in:
@@ -2,6 +2,14 @@
|
|||||||
History
|
History
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
0.3.5 (2019-01-XY)
|
||||||
|
------------------
|
||||||
|
|
||||||
|
- Bug fixes:
|
||||||
|
|
||||||
|
- Support MultiOpt configuration parameters
|
||||||
|
|
||||||
|
|
||||||
0.3.4 (2019-01-26)
|
0.3.4 (2019-01-26)
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class Backend(object):
|
|||||||
configuration=conf,
|
configuration=conf,
|
||||||
db=self.persistence.db,
|
db=self.persistence.db,
|
||||||
host='%s@%s' % (cfg.CONF.host, volume_backend_name),
|
host='%s@%s' % (cfg.CONF.host, volume_backend_name),
|
||||||
cluster_name=None, # We don't user cfg.CONF.cluster for now
|
cluster_name=None, # We don't use cfg.CONF.cluster for now
|
||||||
active_backend_id=None) # No failover for now
|
active_backend_id=None) # No failover for now
|
||||||
self.driver.do_setup(objects.CONTEXT)
|
self.driver.do_setup(objects.CONTEXT)
|
||||||
self.driver.check_for_setup_error()
|
self.driver.check_for_setup_error()
|
||||||
@@ -188,6 +188,14 @@ class Backend(object):
|
|||||||
"""Parse in-memory file to update OSLO configuration used by Cinder."""
|
"""Parse in-memory file to update OSLO configuration used by Cinder."""
|
||||||
cls._config_string_io.seek(0)
|
cls._config_string_io.seek(0)
|
||||||
cls._parser.write(cls._config_string_io)
|
cls._parser.write(cls._config_string_io)
|
||||||
|
|
||||||
|
# Check if we have any multiopt
|
||||||
|
cls._config_string_io.seek(0)
|
||||||
|
current_cfg = cls._config_string_io.read()
|
||||||
|
if '\n\t' in current_cfg:
|
||||||
|
cls._config_string_io.seek(0)
|
||||||
|
cls._config_string_io.write(current_cfg.replace('\n\t', '\n'))
|
||||||
|
|
||||||
cls._config_string_io.seek(0)
|
cls._config_string_io.seek(0)
|
||||||
cfg.CONF.reload_config_files()
|
cfg.CONF.reload_config_files()
|
||||||
|
|
||||||
@@ -211,10 +219,7 @@ class Backend(object):
|
|||||||
cls._parser.set('DEFAULT', 'host', host)
|
cls._parser.set('DEFAULT', 'host', host)
|
||||||
|
|
||||||
# All other configuration options go into the DEFAULT section
|
# All other configuration options go into the DEFAULT section
|
||||||
for key, value in cinder_config_params.items():
|
cls.__set_parser_kv(cinder_config_params, 'DEFAULT')
|
||||||
if not isinstance(value, six.string_types):
|
|
||||||
value = six.text_type(value)
|
|
||||||
cls._parser.set('DEFAULT', key, value)
|
|
||||||
|
|
||||||
# We replace the OSLO's default parser to read from a StringIO instead
|
# We replace the OSLO's default parser to read from a StringIO instead
|
||||||
# of reading from a file.
|
# of reading from a file.
|
||||||
@@ -230,13 +235,29 @@ class Backend(object):
|
|||||||
default_config_files=['in_memory_file'])
|
default_config_files=['in_memory_file'])
|
||||||
cls._update_cinder_config()
|
cls._update_cinder_config()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __set_parser_kv(cls, kvs, section):
|
||||||
|
for key, val in kvs.items():
|
||||||
|
# We receive list or tuple for multiopt and ConfigParser doesn't
|
||||||
|
# support repeating the same entry multiple times, so we hack our
|
||||||
|
# way around it
|
||||||
|
if isinstance(val, (list, tuple)):
|
||||||
|
if not val:
|
||||||
|
val = ''
|
||||||
|
elif len(val) == 1:
|
||||||
|
val = val[0]
|
||||||
|
else:
|
||||||
|
val = (('%s\n' % val[0]) +
|
||||||
|
'\n'.join('%s = %s' % (key, v) for v in val[1:]))
|
||||||
|
|
||||||
|
if not isinstance(val, six.string_types):
|
||||||
|
val = six.text_type(val)
|
||||||
|
cls._parser.set(section, key, val)
|
||||||
|
|
||||||
def _set_backend_config(self, driver_cfg):
|
def _set_backend_config(self, driver_cfg):
|
||||||
backend_name = driver_cfg['volume_backend_name']
|
backend_name = driver_cfg['volume_backend_name']
|
||||||
self._parser.add_section(backend_name)
|
self._parser.add_section(backend_name)
|
||||||
for key, value in driver_cfg.items():
|
self.__set_parser_kv(driver_cfg, backend_name)
|
||||||
if not isinstance(value, six.string_types):
|
|
||||||
value = six.text_type(value)
|
|
||||||
self._parser.set(backend_name, key, value)
|
|
||||||
self._parser.set('DEFAULT', 'enabled_backends',
|
self._parser.set('DEFAULT', 'enabled_backends',
|
||||||
','.join(self.backends.keys()))
|
','.join(self.backends.keys()))
|
||||||
self._update_cinder_config()
|
self._update_cinder_config()
|
||||||
|
|||||||
Reference in New Issue
Block a user