Support for Python 3
Fix up various things to support Python 3. This also included removing the pretty lines in README.rst, because tox with Python 3 just could not cope. Change-Id: I8e8a40ebc54ab781ccf0961a88fd1f8526aaeba0
This commit is contained in:
parent
3685add131
commit
117e7c0f77
10
README.rst
10
README.rst
@ -64,11 +64,11 @@ example::
|
||||
|
||||
~/my_templates$ tree
|
||||
.
|
||||
└── etc
|
||||
├── keystone
|
||||
│ └── keystone.conf
|
||||
└── mysql
|
||||
└── mysql.conf
|
||||
+-- etc
|
||||
+-- keystone
|
||||
| +-- keystone.conf
|
||||
+-- mysql
|
||||
+-- mysql.conf
|
||||
|
||||
An example tree can be found `here <http://git.openstack.org/cgit/openstack/tripleo-image-elements/tree/elements/keystone/os-apply-config>`_.
|
||||
|
||||
|
@ -103,6 +103,8 @@ def write_file(path, contents):
|
||||
d = os.path.dirname(path)
|
||||
os.path.exists(d) or os.makedirs(d)
|
||||
with tempfile.NamedTemporaryFile(dir=d, delete=False) as newfile:
|
||||
if type(contents) == str:
|
||||
contents = contents.encode('utf-8')
|
||||
newfile.write(contents)
|
||||
os.chmod(newfile.name, mode)
|
||||
os.chown(newfile.name, uid, gid)
|
||||
@ -148,13 +150,13 @@ def render_executable(path, config):
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
stdout, stderr = p.communicate(json.dumps(config))
|
||||
stdout, stderr = p.communicate(json.dumps(config).encode('utf-8'))
|
||||
p.wait()
|
||||
if p.returncode != 0:
|
||||
raise exc.ConfigException(
|
||||
"config script failed: %s\n\nwith output:\n\n%s" %
|
||||
(path, stdout + stderr))
|
||||
return stdout
|
||||
return stdout.decode('utf-8')
|
||||
|
||||
|
||||
def template_paths(root):
|
||||
|
@ -1,7 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
from __future__ import print_function
|
||||
import json
|
||||
import sys
|
||||
params = json.loads(sys.stdin.read())
|
||||
x = params["x"]
|
||||
if x is None: raise Exception("undefined: x")
|
||||
print x
|
||||
print(x)
|
||||
|
@ -132,9 +132,10 @@ class TestRunOSConfigApplier(testtools.TestCase):
|
||||
def test_os_config_files(self):
|
||||
with tempfile.NamedTemporaryFile() as fake_os_config_files:
|
||||
with tempfile.NamedTemporaryFile() as fake_config:
|
||||
fake_config.write(json.dumps(CONFIG))
|
||||
fake_config.write(json.dumps(CONFIG).encode('utf-8'))
|
||||
fake_config.flush()
|
||||
fake_os_config_files.write(json.dumps([fake_config.name]))
|
||||
fake_os_config_files.write(
|
||||
json.dumps([fake_config.name]).encode('utf-8'))
|
||||
fake_os_config_files.flush()
|
||||
apply_config.main(['os-apply-config',
|
||||
'--key', 'database.url',
|
||||
@ -242,7 +243,7 @@ class OSConfigApplierTestCase(testtools.TestCase):
|
||||
template("/etc/glance/script.conf"), {})
|
||||
|
||||
def test_template_paths(self):
|
||||
expected = map(lambda p: (template(p), p), TEMPLATE_PATHS)
|
||||
expected = list(map(lambda p: (template(p), p), TEMPLATE_PATHS))
|
||||
actual = apply_config.template_paths(TEMPLATES)
|
||||
expected.sort(key=lambda tup: tup[1])
|
||||
actual.sort(key=lambda tup: tup[1])
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
import re
|
||||
|
||||
from config_exception import ConfigException
|
||||
from os_apply_config import config_exception
|
||||
|
||||
TYPES = {
|
||||
"int": "^[0-9]+$",
|
||||
@ -38,6 +38,7 @@ def ensure_type(string_value, type_name='default'):
|
||||
raise ValueError(
|
||||
"requested validation of unknown type: %s" % type_name)
|
||||
if not re.match(TYPES[type_name], string_value):
|
||||
raise ConfigException("cannot interpret value '%s' as type %s" % (
|
||||
exception = config_exception.ConfigException
|
||||
raise exception("cannot interpret value '%s' as type %s" % (
|
||||
string_value, type_name))
|
||||
return string_value
|
||||
|
Loading…
Reference in New Issue
Block a user