Run pyupgrade to clean up Python 2 syntaxes
Update all .py source files by $ pyupgrade --py3-only $(git ls-files | grep ".py$") to modernize the code according to Python 3 syntaxes. pep8 errors are fixed by $ autopep8 --select=E127,E128,E501 --max-line-length 79 -r \ --in-place os_collect_config and a few manual adjustments. Change-Id: Idaa7c70cf341d2ad28106d03d06eee5341507733
This commit is contained in:
parent
1e70bac696
commit
6d4ca22394
@ -57,7 +57,7 @@ opts = [
|
||||
name = 'cfn'
|
||||
|
||||
|
||||
class Collector(object):
|
||||
class Collector:
|
||||
|
||||
def __init__(self, requests_impl=common.requests):
|
||||
self._requests_impl = requests_impl
|
||||
@ -128,15 +128,15 @@ class Collector(object):
|
||||
value = json.loads(sub_element.text)
|
||||
except ValueError as e:
|
||||
logger.warn(
|
||||
'Path %s failed to parse as json. (%s)' % (path, e))
|
||||
'Path {} failed to parse as json. ({})'.format(path, e))
|
||||
raise exc.CfnMetadataNotAvailable
|
||||
if sub_path:
|
||||
for subkey in sub_path.split('.'):
|
||||
try:
|
||||
value = value[subkey]
|
||||
except KeyError:
|
||||
logger.warn(
|
||||
'Sub-key %s does not exist. (%s)' % (subkey, path))
|
||||
logger.warn('Sub-key {} does not exist. ({})'.format(
|
||||
subkey, path))
|
||||
raise exc.CfnMetadataNotAvailable
|
||||
final_content.update(value)
|
||||
final_list = merger.merged_list_from_content(
|
||||
|
@ -234,7 +234,7 @@ def getfilehash(files):
|
||||
with open(filename) as fp:
|
||||
data = fp.read()
|
||||
m.update(data.encode('utf-8'))
|
||||
except IOError:
|
||||
except OSError:
|
||||
pass
|
||||
return m.hexdigest()
|
||||
|
||||
|
@ -26,7 +26,7 @@ logger = log.getLogger('os-collect-config')
|
||||
PROC_MOUNTS_PATH = '/proc/mounts'
|
||||
|
||||
|
||||
class BlockDevice(object):
|
||||
class BlockDevice:
|
||||
|
||||
devname = None
|
||||
|
||||
@ -75,7 +75,7 @@ class BlockDevice(object):
|
||||
'''Finds an existing mountpoint or mounts to a temp directory.'''
|
||||
self.unmount = False
|
||||
# check if already mounted, if so use that
|
||||
with open(PROC_MOUNTS_PATH, 'r') as f:
|
||||
with open(PROC_MOUNTS_PATH) as f:
|
||||
for line in f.read().splitlines():
|
||||
values = line.split()
|
||||
if values[0] == self.devname:
|
||||
@ -87,7 +87,8 @@ class BlockDevice(object):
|
||||
# otherwise mount readonly to a temp directory
|
||||
self.mountpoint = tempfile.mkdtemp(prefix='config-2-')
|
||||
cmd = ['mount', self.devname, self.mountpoint, '-o', 'ro']
|
||||
logger.debug('Mounting %s at : %s' % (self.devname, self.mountpoint))
|
||||
logger.debug('Mounting {} at : {}'.format(
|
||||
self.devname, self.mountpoint))
|
||||
try:
|
||||
subprocess.check_output(cmd)
|
||||
except subprocess.CalledProcessError as e:
|
||||
@ -129,7 +130,7 @@ class BlockDevice(object):
|
||||
if not os.path.isfile(md_path):
|
||||
logger.warn('No expected file at path: %s' % md_path)
|
||||
return {}
|
||||
with open(md_path, 'r') as f:
|
||||
with open(md_path) as f:
|
||||
return json.load(f)
|
||||
except Exception as e:
|
||||
logger.error('Problem getting metadata: %s', e)
|
||||
@ -138,9 +139,9 @@ class BlockDevice(object):
|
||||
self.cleanup()
|
||||
|
||||
def __repr__(self):
|
||||
return '%s: TYPE="%s" LABEL="%s"' % (self.devname,
|
||||
self.type,
|
||||
self.label)
|
||||
return '{}: TYPE="{}" LABEL="{}"'.format(self.devname,
|
||||
self.type,
|
||||
self.label)
|
||||
|
||||
|
||||
def all_block_devices():
|
||||
|
@ -38,7 +38,7 @@ opts = [
|
||||
name = 'ec2'
|
||||
|
||||
|
||||
class Collector(object):
|
||||
class Collector:
|
||||
def __init__(self, requests_impl=common.requests):
|
||||
self._requests_impl = requests_impl
|
||||
self.session = requests_impl.Session()
|
||||
|
@ -43,7 +43,7 @@ opts = [
|
||||
name = 'heat'
|
||||
|
||||
|
||||
class Collector(object):
|
||||
class Collector:
|
||||
def __init__(self,
|
||||
keystoneclient=keystoneclient,
|
||||
heatclient=heatclient,
|
||||
|
@ -33,7 +33,7 @@ name = 'heat_local'
|
||||
logger = log.getLogger(__name__)
|
||||
|
||||
|
||||
class Collector(object):
|
||||
class Collector:
|
||||
def __init__(self, requests_impl=None):
|
||||
pass
|
||||
|
||||
@ -45,7 +45,8 @@ class Collector(object):
|
||||
try:
|
||||
value = json.loads(metadata.read())
|
||||
except ValueError as e:
|
||||
logger.info('%s is not valid JSON (%s)' % (path, e))
|
||||
logger.info(
|
||||
'{} is not valid JSON ({})'.format(path, e))
|
||||
continue
|
||||
if final_content:
|
||||
final_content.update(value)
|
||||
|
@ -32,7 +32,7 @@ opts = [
|
||||
]
|
||||
|
||||
|
||||
class Keystone(object):
|
||||
class Keystone:
|
||||
'''A keystone wrapper class.
|
||||
|
||||
This wrapper is used to encapsulate any keystone related operations
|
||||
|
@ -51,7 +51,7 @@ def _dest_looks_insecure(local_path):
|
||||
return looks_insecure
|
||||
|
||||
|
||||
class Collector(object):
|
||||
class Collector:
|
||||
def __init__(self, requests_impl=None):
|
||||
pass
|
||||
|
||||
@ -84,7 +84,7 @@ class Collector(object):
|
||||
value = json.loads(metadata.read())
|
||||
except ValueError as e:
|
||||
logger.error(
|
||||
'%s is not valid JSON (%s)' % (data_file, e))
|
||||
'{} is not valid JSON ({})'.format(data_file, e))
|
||||
raise exc.LocalMetadataNotAvailable
|
||||
basename = os.path.basename(data_file)
|
||||
final_content.append((basename, value))
|
||||
|
@ -30,7 +30,7 @@ def merged_list_from_content(final_content, deployment_keys, collector_name):
|
||||
'list.' % (depkey,))
|
||||
continue
|
||||
logger.debug(
|
||||
'Deployment found for %s' % (depkey,))
|
||||
'Deployment found for {}'.format(depkey))
|
||||
for deployment in deployments:
|
||||
if 'name' not in deployment:
|
||||
logger.warn(
|
||||
|
@ -37,7 +37,7 @@ opts = [
|
||||
name = 'request'
|
||||
|
||||
|
||||
class Collector(object):
|
||||
class Collector:
|
||||
def __init__(self, requests_impl=common.requests):
|
||||
self._requests_impl = requests_impl
|
||||
self._session = requests_impl.Session()
|
||||
|
@ -23,9 +23,9 @@ from testtools import matchers
|
||||
from os_collect_config import cache
|
||||
|
||||
|
||||
class DummyConf(object):
|
||||
class DummyConf:
|
||||
def __init__(self, cachedir):
|
||||
class CONFobj(object):
|
||||
class CONFobj:
|
||||
def __init__(self, cachedir):
|
||||
self.cachedir = cachedir
|
||||
self.CONF = CONFobj(cachedir)
|
||||
@ -33,14 +33,14 @@ class DummyConf(object):
|
||||
|
||||
class TestCache(testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(TestCache, self).setUp()
|
||||
super().setUp()
|
||||
cache_root = self.useFixture(fixtures.TempDir())
|
||||
self.cache_dir = os.path.join(cache_root.path, 'cache')
|
||||
self.useFixture(fixtures.MonkeyPatch('os_collect_config.cache.cfg',
|
||||
DummyConf(self.cache_dir)))
|
||||
|
||||
def tearDown(self):
|
||||
super(TestCache, self).tearDown()
|
||||
super().tearDown()
|
||||
|
||||
def test_cache(self):
|
||||
# Never seen, so changed is expected.
|
||||
@ -85,8 +85,8 @@ class TestCache(testtools.TestCase):
|
||||
self.assertIn(path, list_list)
|
||||
|
||||
def test_cache_ignores_json_inequality(self):
|
||||
content1 = u'{"a": "value-a", "b": "value-b"}'
|
||||
content2 = u'{"b": "value-b", "a": "value-a"}'
|
||||
content1 = '{"a": "value-a", "b": "value-b"}'
|
||||
content2 = '{"b": "value-b", "a": "value-a"}'
|
||||
value1 = json.loads(content1)
|
||||
value2 = json.loads(content2)
|
||||
self.assertEqual(value1, value2)
|
||||
|
@ -30,80 +30,80 @@ from os_collect_config import collect
|
||||
from os_collect_config import exc
|
||||
|
||||
|
||||
META_DATA = {u'int1': 1,
|
||||
u'strfoo': u'foo',
|
||||
u'map_ab': {
|
||||
u'a': 'apple',
|
||||
u'b': 'banana',
|
||||
META_DATA = {'int1': 1,
|
||||
'strfoo': 'foo',
|
||||
'map_ab': {
|
||||
'a': 'apple',
|
||||
'b': 'banana',
|
||||
}}
|
||||
|
||||
|
||||
SOFTWARE_CONFIG_DATA = {
|
||||
u'old-style': u'value',
|
||||
u'deployments': [
|
||||
'old-style': 'value',
|
||||
'deployments': [
|
||||
{
|
||||
u'inputs': [
|
||||
'inputs': [
|
||||
{
|
||||
u'type': u'String',
|
||||
u'name': u'input1',
|
||||
u'value': u'value1'
|
||||
'type': 'String',
|
||||
'name': 'input1',
|
||||
'value': 'value1'
|
||||
}
|
||||
],
|
||||
u'group': 'Heat::Ungrouped',
|
||||
u'name': 'dep-name1',
|
||||
u'outputs': None,
|
||||
u'options': None,
|
||||
u'config': {
|
||||
u'config1': 'value1'
|
||||
'group': 'Heat::Ungrouped',
|
||||
'name': 'dep-name1',
|
||||
'outputs': None,
|
||||
'options': None,
|
||||
'config': {
|
||||
'config1': 'value1'
|
||||
}
|
||||
},
|
||||
{
|
||||
u'inputs': [
|
||||
'inputs': [
|
||||
{
|
||||
u'type': u'String',
|
||||
u'name': u'input1',
|
||||
u'value': u'value1'
|
||||
'type': 'String',
|
||||
'name': 'input1',
|
||||
'value': 'value1'
|
||||
}
|
||||
],
|
||||
u'group': 'os-apply-config',
|
||||
u'name': 'dep-name2',
|
||||
u'outputs': None,
|
||||
u'options': None,
|
||||
u'config': {
|
||||
u'config2': 'value2'
|
||||
'group': 'os-apply-config',
|
||||
'name': 'dep-name2',
|
||||
'outputs': None,
|
||||
'options': None,
|
||||
'config': {
|
||||
'config2': 'value2'
|
||||
}
|
||||
},
|
||||
{
|
||||
u'inputs': [
|
||||
'inputs': [
|
||||
{
|
||||
u'type': u'String',
|
||||
u'name': u'input1',
|
||||
u'value': u'value1'
|
||||
'type': 'String',
|
||||
'name': 'input1',
|
||||
'value': 'value1'
|
||||
}
|
||||
],
|
||||
u'name': 'dep-name3',
|
||||
u'outputs': None,
|
||||
u'options': None,
|
||||
u'config': {
|
||||
u'config3': 'value3'
|
||||
'name': 'dep-name3',
|
||||
'outputs': None,
|
||||
'options': None,
|
||||
'config': {
|
||||
'config3': 'value3'
|
||||
}
|
||||
},
|
||||
{
|
||||
u'inputs': [],
|
||||
u'group': 'ignore_me',
|
||||
u'name': 'ignore_me_name',
|
||||
u'outputs': None,
|
||||
u'options': None,
|
||||
u'config': 'ignore_me_config'
|
||||
'inputs': [],
|
||||
'group': 'ignore_me',
|
||||
'name': 'ignore_me_name',
|
||||
'outputs': None,
|
||||
'options': None,
|
||||
'config': 'ignore_me_config'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
SOFTWARE_CONFIG_IMPOSTER_DATA = {
|
||||
u'old-style': u'value',
|
||||
u'deployments': {
|
||||
u"not": u"a list"
|
||||
'old-style': 'value',
|
||||
'deployments': {
|
||||
"not": "a list"
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,7 +116,7 @@ class FakeResponse(dict):
|
||||
pass
|
||||
|
||||
|
||||
class FakeReqSession(object):
|
||||
class FakeReqSession:
|
||||
|
||||
SESSION_META_DATA = META_DATA
|
||||
|
||||
@ -151,7 +151,7 @@ class FakeReqSession(object):
|
||||
return FakeResponse(etree.tostring(root))
|
||||
|
||||
|
||||
class FakeRequests(object):
|
||||
class FakeRequests:
|
||||
exceptions = requests.exceptions
|
||||
|
||||
def __init__(self, testcase, expected_netloc='192.0.2.1:8000'):
|
||||
@ -186,21 +186,21 @@ class FakeRequestsConfigImposter(FakeRequestsSoftwareConfig):
|
||||
FAKE_SESSION = FakeReqSessionConfigImposter
|
||||
|
||||
|
||||
class FakeFailRequests(object):
|
||||
class FakeFailRequests:
|
||||
exceptions = requests.exceptions
|
||||
|
||||
class Session(object):
|
||||
class Session:
|
||||
def get(self, url, params, headers, verify=None, timeout=None):
|
||||
raise requests.exceptions.HTTPError(403, 'Forbidden')
|
||||
|
||||
|
||||
class TestCfnBase(testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(TestCfnBase, self).setUp()
|
||||
super().setUp()
|
||||
self.log = self.useFixture(fixtures.FakeLogger())
|
||||
self.useFixture(fixtures.NestedTempfile())
|
||||
self.hint_file = tempfile.NamedTemporaryFile()
|
||||
self.hint_file.write(u'http://192.0.2.1:8000'.encode('utf-8'))
|
||||
self.hint_file.write(b'http://192.0.2.1:8000')
|
||||
self.hint_file.flush()
|
||||
self.addCleanup(self.hint_file.close)
|
||||
collect.setup_conf()
|
||||
@ -266,8 +266,8 @@ class TestCfn(TestCfnBase):
|
||||
self.assertThat(content, matchers.IsInstance(list))
|
||||
self.assertEqual('cfn', content[0][0])
|
||||
content = content[0][1]
|
||||
self.assertIn(u'b', content)
|
||||
self.assertEqual(u'banana', content[u'b'])
|
||||
self.assertIn('b', content)
|
||||
self.assertEqual('banana', content['b'])
|
||||
|
||||
def test_collect_cfn_metadata_url_overrides_hint(self):
|
||||
cfg.CONF.cfn.metadata_url = 'http://127.0.1.1:8000/v1/'
|
||||
@ -285,7 +285,7 @@ class TestCfnSoftwareConfig(TestCfnBase):
|
||||
self.assertEqual('cfn', cfn_md[0][0])
|
||||
cfn_config = cfn_md[0][1]
|
||||
self.assertThat(cfn_config, matchers.IsInstance(dict))
|
||||
self.assertEqual(set(['old-style', 'deployments']),
|
||||
self.assertEqual({'old-style', 'deployments'},
|
||||
set(cfn_config.keys()))
|
||||
self.assertIn('deployments', cfn_config)
|
||||
self.assertThat(cfn_config['deployments'], matchers.IsInstance(list))
|
||||
|
@ -59,7 +59,7 @@ def _setup_local_metadata(test_case):
|
||||
class TestCollect(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCollect, self).setUp()
|
||||
super().setUp()
|
||||
self.useFixture(fixtures.FakeLogger())
|
||||
collect.setup_conf()
|
||||
self.addCleanup(cfg.CONF.reset)
|
||||
@ -357,7 +357,7 @@ class TestCollect(testtools.TestCase):
|
||||
class TestCollectAll(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCollectAll, self).setUp()
|
||||
super().setUp()
|
||||
self.log = self.useFixture(fixtures.FakeLogger())
|
||||
collect.setup_conf()
|
||||
self.cache_dir = self.useFixture(fixtures.TempDir())
|
||||
@ -422,8 +422,8 @@ class TestCollectAll(testtools.TestCase):
|
||||
(changed_keys, paths) = self._call_collect_all(
|
||||
store=True, collector_kwargs_map=collector_kwargs_map)
|
||||
if expected_changed is None:
|
||||
expected_changed = set(['heat_local', 'cfn', 'ec2',
|
||||
'heat', 'local', 'request', 'zaqar'])
|
||||
expected_changed = {'heat_local', 'cfn', 'ec2',
|
||||
'heat', 'local', 'request', 'zaqar'}
|
||||
self.assertEqual(expected_changed, changed_keys)
|
||||
self.assertThat(paths, matchers.IsInstance(list))
|
||||
for path in paths:
|
||||
@ -450,9 +450,9 @@ class TestCollectAll(testtools.TestCase):
|
||||
'discover_class': test_heat.FakeKeystoneDiscover
|
||||
},
|
||||
}
|
||||
expected_changed = set((
|
||||
expected_changed = {
|
||||
'heat_local', 'ec2', 'cfn', 'heat', 'local', 'request',
|
||||
'dep-name1', 'dep-name2', 'dep-name3', 'zaqar'))
|
||||
'dep-name1', 'dep-name2', 'dep-name3', 'zaqar'}
|
||||
self._test_collect_all_store(collector_kwargs_map=soft_config_map,
|
||||
expected_changed=expected_changed)
|
||||
|
||||
@ -563,7 +563,7 @@ class TestConf(testtools.TestCase):
|
||||
class TestHup(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestHup, self).setUp()
|
||||
super().setUp()
|
||||
self.log = self.useFixture(fixtures.FakeLogger())
|
||||
|
||||
def fake_closerange(low, high):
|
||||
@ -588,7 +588,7 @@ class TestHup(testtools.TestCase):
|
||||
|
||||
class TestFileHash(testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(TestFileHash, self).setUp()
|
||||
super().setUp()
|
||||
|
||||
# Deletes tempfiles during teardown
|
||||
self.useFixture(fixtures.NestedTempfile())
|
||||
|
@ -38,7 +38,7 @@ TYPE=xfs
|
||||
class TestConfigDrive(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestConfigDrive, self).setUp()
|
||||
super().setUp()
|
||||
self.log = self.useFixture(fixtures.FakeLogger())
|
||||
|
||||
@mock.patch.object(subprocess, 'check_output')
|
||||
@ -74,7 +74,7 @@ class TestConfigDrive(testtools.TestCase):
|
||||
self.assertEqual(('foo', 'bar'), psv('foo=bar'))
|
||||
self.assertEqual(('foo', 'bar=baz'), psv('foo=bar=baz'))
|
||||
self.assertEqual(('foo', 'bar baz'), psv('foo=bar baz'))
|
||||
self.assertEqual(('foo', 'bar baz'), psv('foo=bar\ baz'))
|
||||
self.assertEqual(('foo', 'bar baz'), psv(r'foo=bar\ baz'))
|
||||
self.assertEqual(('foo', ''), psv('foo='))
|
||||
self.assertEqual((None, None), psv('foo'))
|
||||
self.assertEqual((None, None), psv(None))
|
||||
@ -116,7 +116,7 @@ class TestConfigDrive(testtools.TestCase):
|
||||
mountpoint = self.useFixture(fixtures.TempDir()).path
|
||||
config_drive.PROC_MOUNTS_PATH = os.path.join(proc.path, 'mount')
|
||||
with open(config_drive.PROC_MOUNTS_PATH, 'w') as md:
|
||||
md.write('%s %s r 0 0\n' % (bd.devname, mountpoint))
|
||||
md.write('{} {} r 0 0\n'.format(bd.devname, mountpoint))
|
||||
|
||||
self.assertIsNone(bd.mountpoint)
|
||||
self.assertFalse(bd.unmount)
|
||||
|
@ -86,10 +86,10 @@ class FakeResponse(dict):
|
||||
pass
|
||||
|
||||
|
||||
class FakeRequests(object):
|
||||
class FakeRequests:
|
||||
exceptions = requests.exceptions
|
||||
|
||||
class Session(object):
|
||||
class Session:
|
||||
def get(self, url, timeout=None):
|
||||
url = urlparse.urlparse(url)
|
||||
|
||||
@ -104,17 +104,17 @@ class FakeRequests(object):
|
||||
return FakeResponse(META_DATA[path])
|
||||
|
||||
|
||||
class FakeFailRequests(object):
|
||||
class FakeFailRequests:
|
||||
exceptions = requests.exceptions
|
||||
|
||||
class Session(object):
|
||||
class Session:
|
||||
def get(self, url, timeout=None):
|
||||
raise requests.exceptions.HTTPError(403, 'Forbidden')
|
||||
|
||||
|
||||
class TestEc2(testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(TestEc2, self).setUp()
|
||||
super().setUp()
|
||||
self.log = self.useFixture(fixtures.FakeLogger())
|
||||
|
||||
@mock.patch.object(config_drive, 'config_drive')
|
||||
|
@ -23,31 +23,31 @@ from os_collect_config import exc
|
||||
from os_collect_config import heat
|
||||
|
||||
|
||||
META_DATA = {u'int1': 1,
|
||||
u'strfoo': u'foo',
|
||||
u'map_ab': {
|
||||
u'a': 'apple',
|
||||
u'b': 'banana',
|
||||
META_DATA = {'int1': 1,
|
||||
'strfoo': 'foo',
|
||||
'map_ab': {
|
||||
'a': 'apple',
|
||||
'b': 'banana',
|
||||
}}
|
||||
|
||||
|
||||
SOFTWARE_CONFIG_DATA = {
|
||||
u'old-style': u'value',
|
||||
u'deployments': [
|
||||
'old-style': 'value',
|
||||
'deployments': [
|
||||
{
|
||||
u'inputs': [
|
||||
'inputs': [
|
||||
{
|
||||
u'type': u'String',
|
||||
u'name': u'input1',
|
||||
u'value': u'value1'
|
||||
'type': 'String',
|
||||
'name': 'input1',
|
||||
'value': 'value1'
|
||||
}
|
||||
],
|
||||
u'group': 'Heat::Ungrouped',
|
||||
u'name': 'dep-name1',
|
||||
u'outputs': None,
|
||||
u'options': None,
|
||||
u'config': {
|
||||
u'config1': 'value1'
|
||||
'group': 'Heat::Ungrouped',
|
||||
'name': 'dep-name1',
|
||||
'outputs': None,
|
||||
'options': None,
|
||||
'config': {
|
||||
'config1': 'value1'
|
||||
}
|
||||
}
|
||||
]
|
||||
@ -55,14 +55,14 @@ SOFTWARE_CONFIG_DATA = {
|
||||
|
||||
|
||||
SOFTWARE_CONFIG_IMPOSTER_DATA = {
|
||||
u'old-style': u'value',
|
||||
u'deployments': {
|
||||
u"not": u"a list"
|
||||
'old-style': 'value',
|
||||
'deployments': {
|
||||
"not": "a list"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class FakeKeystoneDiscover(object):
|
||||
class FakeKeystoneDiscover:
|
||||
|
||||
def __init__(self, auth_url):
|
||||
pass
|
||||
@ -71,7 +71,7 @@ class FakeKeystoneDiscover(object):
|
||||
return 'http://192.0.2.1:5000/v3'
|
||||
|
||||
|
||||
class FakeKeystoneClient(object):
|
||||
class FakeKeystoneClient:
|
||||
|
||||
def __init__(self, testcase, configs=None):
|
||||
self._test = testcase
|
||||
@ -103,7 +103,7 @@ class FakeFailKeystoneClient(FakeKeystoneClient):
|
||||
raise ks_exc.AuthorizationFailure('Forbidden')
|
||||
|
||||
|
||||
class FakeHeatClient(object):
|
||||
class FakeHeatClient:
|
||||
def __init__(self, testcase):
|
||||
self._test = testcase
|
||||
self.resources = self
|
||||
@ -128,7 +128,7 @@ class FakeHeatClientSoftwareConfig(FakeHeatClient):
|
||||
|
||||
class TestHeatBase(testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(TestHeatBase, self).setUp()
|
||||
super().setUp()
|
||||
self.log = self.useFixture(fixtures.FakeLogger())
|
||||
self.useFixture(fixtures.NestedTempfile())
|
||||
collect.setup_conf()
|
||||
|
@ -27,17 +27,17 @@ from os_collect_config import exc
|
||||
from os_collect_config import heat_local
|
||||
|
||||
|
||||
META_DATA = {u'localstrA': u'A',
|
||||
u'localint9': 9,
|
||||
u'localmap_xy': {
|
||||
u'x': 42,
|
||||
u'y': 'foo',
|
||||
META_DATA = {'localstrA': 'A',
|
||||
'localint9': 9,
|
||||
'localmap_xy': {
|
||||
'x': 42,
|
||||
'y': 'foo',
|
||||
}}
|
||||
|
||||
|
||||
class TestHeatLocal(testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(TestHeatLocal, self).setUp()
|
||||
super().setUp()
|
||||
self.log = self.useFixture(fixtures.FakeLogger())
|
||||
collect.setup_conf()
|
||||
self.orig_cfg_CONF = cfg.CONF
|
||||
@ -45,7 +45,7 @@ class TestHeatLocal(testtools.TestCase):
|
||||
def tearDown(self):
|
||||
cfg.CONF = self.orig_cfg_CONF
|
||||
cfg.CONF.reset()
|
||||
super(TestHeatLocal, self).tearDown()
|
||||
super().tearDown()
|
||||
|
||||
def _call_collect(self, *temp_name):
|
||||
cfg.CONF.heat_local.path = list(temp_name)
|
||||
@ -83,7 +83,7 @@ class TestHeatLocal(testtools.TestCase):
|
||||
|
||||
def test_collect_heat_local_with_invalid_metadata(self):
|
||||
with tempfile.NamedTemporaryFile() as md:
|
||||
md.write("{'invalid' => 'INVALID'}".encode('utf-8'))
|
||||
md.write(b"{'invalid' => 'INVALID'}")
|
||||
md.flush()
|
||||
self.assertRaises(exc.HeatLocalMetadataNotAvailable,
|
||||
self._call_collect, md.name)
|
||||
|
@ -44,7 +44,7 @@ class FakeKeystoneDiscoverBase(test_heat.FakeKeystoneDiscover):
|
||||
|
||||
class KeystoneTest(testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(KeystoneTest, self).setUp()
|
||||
super().setUp()
|
||||
self.addCleanup(cfg.CONF.reset)
|
||||
collect.setup_conf()
|
||||
self.useFixture(fixtures.NestedTempfile())
|
||||
@ -73,7 +73,7 @@ class KeystoneTest(testtools.TestCase):
|
||||
self.assertIsNotNone(ks.cache)
|
||||
|
||||
def _make_ks(self, client):
|
||||
class Configs(object):
|
||||
class Configs:
|
||||
auth_url = 'http://192.0.2.1:5000/'
|
||||
user_id = 'auser'
|
||||
password = 'apassword'
|
||||
|
@ -28,19 +28,19 @@ from os_collect_config import exc
|
||||
from os_collect_config import local
|
||||
|
||||
|
||||
META_DATA = {u'localstrA': u'A',
|
||||
u'localint9': 9,
|
||||
u'localmap_xy': {
|
||||
u'x': 42,
|
||||
u'y': 'foo',
|
||||
META_DATA = {'localstrA': 'A',
|
||||
'localint9': 9,
|
||||
'localmap_xy': {
|
||||
'x': 42,
|
||||
'y': 'foo',
|
||||
}}
|
||||
META_DATA2 = {u'localstrA': u'Z',
|
||||
u'localint9': 9}
|
||||
META_DATA2 = {'localstrA': 'Z',
|
||||
'localint9': 9}
|
||||
|
||||
|
||||
class TestLocal(testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(TestLocal, self).setUp()
|
||||
super().setUp()
|
||||
self.log = self.useFixture(fixtures.FakeLogger())
|
||||
self.useFixture(fixtures.NestedTempfile())
|
||||
self.tdir = tempfile.mkdtemp()
|
||||
|
@ -18,74 +18,74 @@ import testtools
|
||||
from os_collect_config import merger
|
||||
|
||||
|
||||
META_DATA = {u'int1': 1,
|
||||
u'strfoo': u'foo',
|
||||
u'map_ab': {
|
||||
u'a': 'apple',
|
||||
u'b': 'banana',
|
||||
META_DATA = {'int1': 1,
|
||||
'strfoo': 'foo',
|
||||
'map_ab': {
|
||||
'a': 'apple',
|
||||
'b': 'banana',
|
||||
}}
|
||||
|
||||
|
||||
SOFTWARE_CONFIG_DATA = {
|
||||
u'old-style': u'value',
|
||||
u'deployments': [
|
||||
'old-style': 'value',
|
||||
'deployments': [
|
||||
{
|
||||
u'inputs': [
|
||||
'inputs': [
|
||||
{
|
||||
u'type': u'String',
|
||||
u'name': u'input1',
|
||||
u'value': u'value1'
|
||||
'type': 'String',
|
||||
'name': 'input1',
|
||||
'value': 'value1'
|
||||
}
|
||||
],
|
||||
u'group': 'Heat::Ungrouped',
|
||||
u'name': 'dep-name1',
|
||||
u'outputs': None,
|
||||
u'options': None,
|
||||
u'config': {
|
||||
u'config1': 'value1'
|
||||
'group': 'Heat::Ungrouped',
|
||||
'name': 'dep-name1',
|
||||
'outputs': None,
|
||||
'options': None,
|
||||
'config': {
|
||||
'config1': 'value1'
|
||||
}
|
||||
},
|
||||
{
|
||||
u'inputs': [
|
||||
'inputs': [
|
||||
{
|
||||
u'type': u'String',
|
||||
u'name': u'input1',
|
||||
u'value': u'value1'
|
||||
'type': 'String',
|
||||
'name': 'input1',
|
||||
'value': 'value1'
|
||||
}
|
||||
],
|
||||
u'group': 'os-apply-config',
|
||||
u'name': 'dep-name2',
|
||||
u'outputs': None,
|
||||
u'options': None,
|
||||
u'config': {
|
||||
u'config2': 'value2'
|
||||
'group': 'os-apply-config',
|
||||
'name': 'dep-name2',
|
||||
'outputs': None,
|
||||
'options': None,
|
||||
'config': {
|
||||
'config2': 'value2'
|
||||
}
|
||||
},
|
||||
{
|
||||
u'inputs': [
|
||||
'inputs': [
|
||||
{
|
||||
u'type': u'String',
|
||||
u'name': u'input1',
|
||||
u'value': u'value1'
|
||||
'type': 'String',
|
||||
'name': 'input1',
|
||||
'value': 'value1'
|
||||
}
|
||||
],
|
||||
u'name': 'dep-name3',
|
||||
u'outputs': None,
|
||||
u'options': None,
|
||||
u'config': {
|
||||
u'config3': 'value3'
|
||||
'name': 'dep-name3',
|
||||
'outputs': None,
|
||||
'options': None,
|
||||
'config': {
|
||||
'config3': 'value3'
|
||||
}
|
||||
},
|
||||
{
|
||||
u'inputs': [],
|
||||
u'group': 'ignore_me',
|
||||
u'name': 'ignore_me_name',
|
||||
u'outputs': None,
|
||||
u'options': None,
|
||||
u'config': 'ignore_me_config'
|
||||
'inputs': [],
|
||||
'group': 'ignore_me',
|
||||
'name': 'ignore_me_name',
|
||||
'outputs': None,
|
||||
'options': None,
|
||||
'config': 'ignore_me_config'
|
||||
},
|
||||
{
|
||||
u'inputs': [], # to test missing name
|
||||
'inputs': [], # to test missing name
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -28,71 +28,71 @@ from os_collect_config import exc
|
||||
from os_collect_config import request
|
||||
|
||||
|
||||
META_DATA = {u'int1': 1,
|
||||
u'strfoo': u'foo',
|
||||
u'map_ab': {
|
||||
u'a': 'apple',
|
||||
u'b': 'banana',
|
||||
META_DATA = {'int1': 1,
|
||||
'strfoo': 'foo',
|
||||
'map_ab': {
|
||||
'a': 'apple',
|
||||
'b': 'banana',
|
||||
}}
|
||||
|
||||
|
||||
SOFTWARE_CONFIG_DATA = {
|
||||
u'old-style': u'value',
|
||||
u'deployments': [
|
||||
'old-style': 'value',
|
||||
'deployments': [
|
||||
{
|
||||
u'inputs': [
|
||||
'inputs': [
|
||||
{
|
||||
u'type': u'String',
|
||||
u'name': u'input1',
|
||||
u'value': u'value1'
|
||||
'type': 'String',
|
||||
'name': 'input1',
|
||||
'value': 'value1'
|
||||
}
|
||||
],
|
||||
u'group': 'Heat::Ungrouped',
|
||||
u'name': 'dep-name1',
|
||||
u'outputs': None,
|
||||
u'options': None,
|
||||
u'config': {
|
||||
u'config1': 'value1'
|
||||
'group': 'Heat::Ungrouped',
|
||||
'name': 'dep-name1',
|
||||
'outputs': None,
|
||||
'options': None,
|
||||
'config': {
|
||||
'config1': 'value1'
|
||||
}
|
||||
},
|
||||
{
|
||||
u'inputs': [
|
||||
'inputs': [
|
||||
{
|
||||
u'type': u'String',
|
||||
u'name': u'input1',
|
||||
u'value': u'value1'
|
||||
'type': 'String',
|
||||
'name': 'input1',
|
||||
'value': 'value1'
|
||||
}
|
||||
],
|
||||
u'group': 'os-apply-config',
|
||||
u'name': 'dep-name2',
|
||||
u'outputs': None,
|
||||
u'options': None,
|
||||
u'config': {
|
||||
u'config2': 'value2'
|
||||
'group': 'os-apply-config',
|
||||
'name': 'dep-name2',
|
||||
'outputs': None,
|
||||
'options': None,
|
||||
'config': {
|
||||
'config2': 'value2'
|
||||
}
|
||||
},
|
||||
{
|
||||
u'inputs': [
|
||||
'inputs': [
|
||||
{
|
||||
u'type': u'String',
|
||||
u'name': u'input1',
|
||||
u'value': u'value1'
|
||||
'type': 'String',
|
||||
'name': 'input1',
|
||||
'value': 'value1'
|
||||
}
|
||||
],
|
||||
u'name': 'dep-name3',
|
||||
u'outputs': None,
|
||||
u'options': None,
|
||||
u'config': {
|
||||
u'config3': 'value3'
|
||||
'name': 'dep-name3',
|
||||
'outputs': None,
|
||||
'options': None,
|
||||
'config': {
|
||||
'config3': 'value3'
|
||||
}
|
||||
},
|
||||
{
|
||||
u'inputs': [],
|
||||
u'group': 'ignore_me',
|
||||
u'name': 'ignore_me_name',
|
||||
u'outputs': None,
|
||||
u'options': None,
|
||||
u'config': 'ignore_me_config'
|
||||
'inputs': [],
|
||||
'group': 'ignore_me',
|
||||
'name': 'ignore_me_name',
|
||||
'outputs': None,
|
||||
'options': None,
|
||||
'config': 'ignore_me_config'
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -107,10 +107,10 @@ class FakeResponse(dict):
|
||||
pass
|
||||
|
||||
|
||||
class FakeRequests(object):
|
||||
class FakeRequests:
|
||||
exceptions = requests.exceptions
|
||||
|
||||
class Session(object):
|
||||
class Session:
|
||||
def get(self, url, timeout=None):
|
||||
return FakeResponse(json.dumps(META_DATA))
|
||||
|
||||
@ -120,10 +120,10 @@ class FakeRequests(object):
|
||||
"%a, %d %b %Y %H:%M:%S %Z", time.gmtime())})
|
||||
|
||||
|
||||
class FakeFailRequests(object):
|
||||
class FakeFailRequests:
|
||||
exceptions = requests.exceptions
|
||||
|
||||
class Session(object):
|
||||
class Session:
|
||||
def get(self, url, timeout=None):
|
||||
raise requests.exceptions.HTTPError(403, 'Forbidden')
|
||||
|
||||
@ -131,9 +131,9 @@ class FakeFailRequests(object):
|
||||
raise requests.exceptions.HTTPError(403, 'Forbidden')
|
||||
|
||||
|
||||
class FakeRequestsSoftwareConfig(object):
|
||||
class FakeRequestsSoftwareConfig:
|
||||
|
||||
class Session(object):
|
||||
class Session:
|
||||
def get(self, url, timeout=None):
|
||||
return FakeResponse(json.dumps(SOFTWARE_CONFIG_DATA))
|
||||
|
||||
@ -145,7 +145,7 @@ class FakeRequestsSoftwareConfig(object):
|
||||
|
||||
class TestRequestBase(testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(TestRequestBase, self).setUp()
|
||||
super().setUp()
|
||||
self.log = self.useFixture(fixtures.FakeLogger())
|
||||
collect.setup_conf()
|
||||
cfg.CONF.request.metadata_url = 'http://192.0.2.1:8000/my_metadata'
|
||||
|
@ -47,7 +47,7 @@ class FakeKeystoneClientWebsocket(test_heat.FakeKeystoneClient):
|
||||
return 'ws://127.0.0.1:9000/'
|
||||
|
||||
|
||||
class FakeZaqarClient(object):
|
||||
class FakeZaqarClient:
|
||||
|
||||
def __init__(self, testcase):
|
||||
self._test = testcase
|
||||
@ -63,7 +63,7 @@ class FakeZaqarClient(object):
|
||||
return FakeQueue()
|
||||
|
||||
|
||||
class FakeZaqarWebsocketClient(object):
|
||||
class FakeZaqarWebsocketClient:
|
||||
|
||||
def __init__(self, options, messages=None, testcase=None):
|
||||
self._messages = messages
|
||||
@ -88,14 +88,14 @@ class FakeZaqarWebsocketClient(object):
|
||||
pass
|
||||
|
||||
|
||||
class FakeQueue(object):
|
||||
class FakeQueue:
|
||||
|
||||
def pop(self):
|
||||
return iter([message.Message(
|
||||
queue=self, ttl=10, age=10, body=test_heat.META_DATA, href='')])
|
||||
|
||||
|
||||
class FakeZaqarClientSoftwareConfig(object):
|
||||
class FakeZaqarClientSoftwareConfig:
|
||||
|
||||
def __init__(self, testcase):
|
||||
self._test = testcase
|
||||
@ -111,7 +111,7 @@ class FakeZaqarClientSoftwareConfig(object):
|
||||
return FakeQueueSoftwareConfig()
|
||||
|
||||
|
||||
class FakeQueueSoftwareConfig(object):
|
||||
class FakeQueueSoftwareConfig:
|
||||
|
||||
def pop(self):
|
||||
return iter([message.Message(
|
||||
@ -121,7 +121,7 @@ class FakeQueueSoftwareConfig(object):
|
||||
|
||||
class TestZaqar(testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(TestZaqar, self).setUp()
|
||||
super().setUp()
|
||||
self.log = self.useFixture(fixtures.FakeLogger())
|
||||
self.useFixture(fixtures.NestedTempfile())
|
||||
collect.setup_conf()
|
||||
|
@ -53,7 +53,7 @@ opts = [
|
||||
name = 'zaqar'
|
||||
|
||||
|
||||
class Collector(object):
|
||||
class Collector:
|
||||
def __init__(self,
|
||||
keystoneclient=keystoneclient,
|
||||
zaqarclient=zaqarclient,
|
||||
|
Loading…
Reference in New Issue
Block a user