snap-config-keys is now a map

It maps the name of the config values that we use in our templates to
the name of the key in the snap config. This allows us to stick a
bunch of stuff in the questions namespace in the snap config, and to
use dashes, with minimal changes to our templates.

Drop Python 2 support, to fix tests.

Change-Id: I48b86b5e557e30f81e9cc415e7fa3a9133aa9f39
This commit is contained in:
Pete Vander Giessen 2019-10-04 10:59:01 -04:00
parent f612dd2e61
commit 322514211b
3 changed files with 17 additions and 7 deletions

View File

@ -165,7 +165,7 @@ class OpenStackSnap(object):
snap environment, we'll clobber the keys in the environment.
'''
snap_config = utils.snap_config(
keys=setup.get('snap-config-keys', []))
keys=setup.get('snap-config-keys', {}))
for key in snap_config.keys():
utils.snap_env[key] = snap_config[key]

View File

@ -361,7 +361,17 @@ class TestSnapUtils(test_base.TestCase):
@patch.object(utils, 'os')
def test_snap_config(self, mock_os, mock_subprocess):
'''snap_config fetch snapctl vals from the environment.'''
faux_config = {'foo': 'bar', 'baz': 'qux', 'quux': ''}
faux_config = {
'foo': 'questions.foo',
'baz': 'questions.baz',
'quux': 'questions.quux',
}
faux_snap_config = {
'questions.foo': 'bar',
'questions.baz': 'qux',
'questions.quux': '',
}
def faux_check_output(commands):
'''Replacement for check output.
@ -369,11 +379,11 @@ class TestSnapUtils(test_base.TestCase):
We expect this to be called with a list of commands,
the last of which is the key that we're looking for.
'''
return faux_config[commands[-1]].encode('utf-8')
return faux_snap_config[commands[-1]].encode('utf-8')
mock_subprocess.check_output = faux_check_output
keys = faux_config.keys()
keys = faux_config
snap_utils = utils.SnapUtils()
snap_config = snap_utils.snap_config(keys)

View File

@ -69,7 +69,7 @@ class SnapUtils(object):
'''
snap_config = {}
for key in keys:
for our_key, snap_key in keys.items():
# Iterating through the keys is a little slow, as we make
# a lot of snapctl calls. OTOH, I'm not sure that we want
# to take responsibilty for parsing the return of "snap
@ -77,8 +77,8 @@ class SnapUtils(object):
# option, or any other way of ensuring a consistently
# formatted return.
ret = subprocess.check_output(
['snapctl', 'get', key]).decode('utf-8').strip()
snap_config[key] = ret or None
['snapctl', 'get', snap_key]).decode('utf-8').strip()
snap_config[our_key] = ret or None
return snap_config