Add py3.5 support

Depends-On: Ibda89b467b461b8833515f50a0cf1cc3064cb917
Change-Id: I68ac61b7d1d0d180a7696ae2f0f75b1a4a969995
This commit is contained in:
Thomas Herve 2017-01-05 22:15:16 +01:00
parent cb2690a5fc
commit 25cd394bbe
28 changed files with 111 additions and 84 deletions

View File

@ -70,8 +70,8 @@ def main(argv=sys.argv):
vars_filename, os.O_CREAT | os.O_WRONLY, 0o600), 'w') as var_file:
json.dump(variables, var_file)
# Write the executable, 'config', to file
with os.fdopen(os.open(fn, os.O_CREAT | os.O_WRONLY, 0o600), 'w') as f:
f.write(c.get('config', '').encode('utf-8'))
with os.fdopen(os.open(fn, os.O_CREAT | os.O_WRONLY, 0o600), 'wb') as f:
f.write(c.get('config', '').encode('utf-8', 'replace'))
cmd = [
ANSIBLE_CMD,
@ -130,8 +130,8 @@ def main(argv=sys.argv):
pass
response.update({
'deploy_stdout': stdout,
'deploy_stderr': stderr,
'deploy_stdout': stdout.decode('utf-8', 'replace'),
'deploy_stderr': stderr.decode('utf-8', 'replace'),
'deploy_status_code': subproc.returncode,
})

View File

@ -46,8 +46,8 @@ def main(argv=sys.argv):
log.info('Completed apply-config.')
response = {
'deploy_stdout': stdout,
'deploy_stderr': stderr,
'deploy_stdout': stdout.decode('utf-8', 'replace'),
'deploy_stderr': stderr.decode('utf-8', 'replace'),
'deploy_status_code': subproc.returncode,
}

View File

@ -70,8 +70,8 @@ def main(argv=sys.argv, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr):
log.info('Completed %s' % CFN_INIT_CMD)
response = {
'deploy_stdout': cstdout,
'deploy_stderr': cstderr,
'deploy_stdout': cstdout.decode('utf-8', 'replace'),
'deploy_stderr': cstderr.decode('utf-8', 'replace'),
'deploy_status_code': subproc.returncode,
}

View File

@ -73,7 +73,7 @@ def main(argv=sys.argv):
labels = collections.OrderedDict()
labels['deploy_stack_id'] = input_values.get('deploy_stack_id')
labels['deploy_resource_name'] = input_values.get('deploy_resource_name')
(stdout, stderr, deploy_status_code) = paunch.apply(
stdout, stderr, deploy_status_code = paunch.apply(
cid,
config,
managed_by='docker-cmd',

View File

@ -39,13 +39,13 @@ def write_input_file(file_path, content):
prepare_dir(os.path.dirname(file_path))
with os.fdopen(os.open(
file_path, os.O_CREAT | os.O_WRONLY, 0o600), 'w') as f:
f.write(content.encode('utf-8'))
f.write(content)
def build_response(deploy_stdout, deploy_stderr, deploy_status_code):
return {
'deploy_stdout': deploy_stdout,
'deploy_stderr': deploy_stderr,
'deploy_stdout': deploy_stdout.decode('utf-8', 'replace'),
'deploy_stderr': deploy_stderr.decode('utf-8', 'replace'),
'deploy_status_code': deploy_status_code,
}

View File

@ -43,7 +43,6 @@ def main(argv=sys.argv):
if not os.path.exists(CONF_FILE):
log.error('No config file %s' % CONF_FILE)
return 1
if not os.path.isdir(DOCKER_COMPOSE_DIR):
os.makedirs(DOCKER_COMPOSE_DIR, 0o700)
@ -59,6 +58,7 @@ def main(argv=sys.argv):
write_compose_config(c)
except Exception as e:
log.exception(e)
return 1
def cleanup_stale_projects(configs):
@ -109,7 +109,7 @@ def write_compose_config(c):
fn = os.path.join(proj_dir, 'docker-compose.yml')
with os.fdopen(os.open(fn, os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o600),
'w') as f:
f.write(yaml_config.encode('utf-8'))
f.write(yaml_config)
if __name__ == '__main__':

View File

@ -49,7 +49,7 @@ def exit_legacy_hiera_detected():
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = subproc.communicate()
rs_stdout = stdout.rstrip()
rs_stdout = stdout.rstrip().decode('utf-8', 'replace')
if rs_stdout != 'empty':
err_msg = ('Legacy hieradata from os-apply-config has been '
'detected - %s. Please update all of your interfaces '
@ -96,7 +96,7 @@ def main(argv=sys.argv):
# write out the datafiles as YAML
if 'datafiles' in c:
for name, data in c['datafiles'].iteritems():
for name, data in c['datafiles'].items():
hiera_data = os.path.join(HIERA_DATADIR, '%s.json' % name)
with os.fdopen(os.open(hiera_data,
os.O_CREAT | os.O_TRUNC | os.O_WRONLY,

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import cStringIO
import io
import json
import logging
import os
@ -82,13 +82,13 @@ def configure_logging():
handler.setFormatter(formatter)
log.addHandler(handler)
deploy_stdout = cStringIO.StringIO()
deploy_stdout = io.StringIO()
handler = logging.StreamHandler(deploy_stdout)
handler.setFormatter(formatter)
handler.setLevel('DEBUG')
log.addHandler(handler)
deploy_stderr = cStringIO.StringIO()
deploy_stderr = io.StringIO()
handler = logging.StreamHandler(deploy_stderr)
handler.setFormatter(formatter)
handler.setLevel('WARN')

View File

@ -92,7 +92,7 @@ def main(argv=sys.argv):
with os.fdopen(os.open(hiera_data,
os.O_CREAT | os.O_TRUNC | os.O_WRONLY, 0o600),
'w') as hiera_file:
hiera_file.write(json.dumps(hiera).encode('utf8'))
hiera_file.write(json.dumps(hiera))
facts['FACTER_deploy_config_name'] = c['name']
fn = os.path.join(WORKING_DIR, '%s.pp' % c['id'])
@ -106,7 +106,7 @@ def main(argv=sys.argv):
with os.fdopen(os.open(fn, os.O_CREAT | os.O_TRUNC | os.O_WRONLY, 0o700),
'w') as f:
f.write(c.get('config', '').encode('utf-8'))
f.write(c.get('config', ''))
cmd = [PUPPET_CMD, 'apply', '--color', 'false', '--detailed-exitcodes', fn]
# This is the default log destination to print out to the console and

View File

@ -70,7 +70,7 @@ def main(argv=sys.argv):
fn = os.path.join(WORKING_DIR, state_file)
with os.fdopen(os.open(fn, os.O_CREAT | os.O_WRONLY, 0o700), 'w') as f:
f.write(yaml_config.encode('utf-8'))
f.write(yaml_config)
caller = salt.cli.caller.Caller.factory(opts)

View File

@ -59,7 +59,7 @@ def main(argv=sys.argv):
env['heat_outputs_path'] = heat_outputs_path
with os.fdopen(os.open(fn, os.O_CREAT | os.O_WRONLY, 0o700), 'w') as f:
f.write(c.get('config', '').encode('utf-8'))
f.write(c.get('config', ''))
log.debug('Running %s' % fn)
subproc = subprocess.Popen([fn], stdout=subprocess.PIPE,
@ -85,8 +85,8 @@ def main(argv=sys.argv):
pass
response.update({
'deploy_stdout': stdout,
'deploy_stderr': stderr,
'deploy_stdout': stdout.decode('utf-8', 'replace'),
'deploy_stderr': stderr.decode('utf-8', 'replace'),
'deploy_status_code': subproc.returncode,
})

View File

@ -58,7 +58,7 @@ def trim_response(response, trimmed_values=None):
"""
trimmed_values = trimmed_values or ('deploy_stdout', 'deploy_stderr')
str_response = json.dumps(response, ensure_ascii=True, encoding='utf-8')
str_response = json.dumps(response, ensure_ascii=True)
len_total = len(str_response)
offset = MAX_RESPONSE_SIZE - len_total
if offset >= 0:

View File

@ -20,8 +20,6 @@ import stat
import subprocess
import sys
import requests
HOOKS_DIR_PATHS = (
os.environ.get('HEAT_CONFIG_HOOKS'),
'/usr/libexec/heat-config/hooks',
@ -145,7 +143,8 @@ def invoke_hook(c, log):
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = subproc.communicate(input=json.dumps(c))
stdout, stderr = subproc.communicate(
input=json.dumps(c).encode('utf-8', 'replace'))
log.info(stdout)
log.debug(stderr)
@ -158,7 +157,7 @@ def invoke_hook(c, log):
try:
if stdout:
signal_data = json.loads(stdout)
signal_data = json.loads(stdout.decode('utf-8', 'replace'))
except ValueError:
signal_data = {
'deploy_stdout': stdout,

View File

@ -30,6 +30,8 @@ class RunScriptTest(testtools.TestCase):
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=env)
if input_str:
input_str = input_str.encode('utf-8')
stdout, stderr = subproc.communicate(input=input_str)
return subproc.returncode, stdout, stderr

View File

@ -48,8 +48,7 @@ def main(argv=sys.argv):
if isinstance(response, list):
response = response[suffix]
for k, v in response.get('files', {}).iteritems():
open(k, 'w')
for k, v in response.get('files', {}).items():
with open(k, 'w') as f:
f.write(v)

View File

@ -157,7 +157,7 @@ class HeatConfigTest(common.RunScriptTest):
self.env = os.environ.copy()
def write_config_file(self, data):
config_file = tempfile.NamedTemporaryFile()
config_file = tempfile.NamedTemporaryFile(mode='w')
config_file.write(json.dumps(data))
config_file.flush()
return config_file

View File

@ -90,7 +90,7 @@ class HeatConfigDockerComposeORCTest(common.RunScriptTest):
os.chmod(hook_name, 0o755)
def write_config_file(self, data):
config_file = tempfile.NamedTemporaryFile()
config_file = tempfile.NamedTemporaryFile(mode='w')
config_file.write(json.dumps(data))
config_file.flush()
return config_file

View File

@ -117,7 +117,7 @@ class HeatConfigKubeletORCTest(common.RunScriptTest):
os.chmod(hook_name, 0o755)
def write_config_file(self, data):
config_file = tempfile.NamedTemporaryFile()
config_file = tempfile.NamedTemporaryFile(mode='w')
config_file.write(json.dumps(data))
config_file.flush()
return config_file

View File

@ -11,12 +11,13 @@
# License for the specific language governing permissions and limitations
# under the License.
import cStringIO
import io
import json
import tempfile
import fixtures
import mock
import six
from tests import common
from tests import heat_config_notify as hcn
@ -76,9 +77,13 @@ class HeatConfigNotifyTest(common.RunScriptTest):
super(HeatConfigNotifyTest, self).setUp()
self.deployed_dir = self.useFixture(fixtures.TempDir())
hcn.init_logging = mock.MagicMock()
if six.PY2:
self.stdin = io.BytesIO()
else:
self.stdin = io.StringIO()
def write_config_file(self, data):
config_file = tempfile.NamedTemporaryFile()
config_file = tempfile.NamedTemporaryFile(mode='w')
config_file.write(json.dumps(data))
config_file.flush()
return config_file
@ -86,21 +91,23 @@ class HeatConfigNotifyTest(common.RunScriptTest):
def test_notify_missing_file(self):
signal_data = json.dumps({'foo': 'bar'})
stdin = cStringIO.StringIO(signal_data)
self.stdin.write(signal_data)
self.stdin.seek(0)
with self.write_config_file(self.data_signal_id) as config_file:
config_file_name = config_file.name
self.assertEqual(
1, hcn.main(['heat-config-notify', config_file_name], stdin))
1, hcn.main(['heat-config-notify', config_file_name], self.stdin))
def test_notify_missing_file_arg(self):
signal_data = json.dumps({'foo': 'bar'})
stdin = cStringIO.StringIO(signal_data)
self.stdin.write(signal_data)
self.stdin.seek(0)
self.assertEqual(
1, hcn.main(['heat-config-notify'], stdin))
1, hcn.main(['heat-config-notify'], self.stdin))
def test_notify_signal_id(self):
requests = mock.MagicMock()
@ -109,11 +116,13 @@ class HeatConfigNotifyTest(common.RunScriptTest):
requests.post.return_value = '[200]'
signal_data = json.dumps({'foo': 'bar'})
stdin = cStringIO.StringIO(signal_data)
self.stdin.write(signal_data)
self.stdin.seek(0)
with self.write_config_file(self.data_signal_id) as config_file:
self.assertEqual(
0, hcn.main(['heat-config-notify', config_file.name], stdin))
0,
hcn.main(['heat-config-notify', config_file.name], self.stdin))
requests.post.assert_called_once_with(
'mock://192.0.2.3/foo',
@ -127,11 +136,13 @@ class HeatConfigNotifyTest(common.RunScriptTest):
requests.post.return_value = '[200]'
signal_data = json.dumps({'foo': 'bar'})
stdin = cStringIO.StringIO(signal_data)
self.stdin.write(signal_data)
self.stdin.seek(0)
with self.write_config_file(self.data_signal_id_put) as config_file:
self.assertEqual(
0, hcn.main(['heat-config-notify', config_file.name], stdin))
0,
hcn.main(['heat-config-notify', config_file.name], self.stdin))
requests.put.assert_called_once_with(
'mock://192.0.2.3/foo',
@ -144,11 +155,10 @@ class HeatConfigNotifyTest(common.RunScriptTest):
requests.post.return_value = '[200]'
stdin = cStringIO.StringIO()
with self.write_config_file(self.data_signal_id) as config_file:
self.assertEqual(
0, hcn.main(['heat-config-notify', config_file.name], stdin))
0,
hcn.main(['heat-config-notify', config_file.name], self.stdin))
requests.post.assert_called_once_with(
'mock://192.0.2.3/foo',
@ -161,11 +171,15 @@ class HeatConfigNotifyTest(common.RunScriptTest):
requests.post.return_value = '[200]'
stdin = cStringIO.StringIO('{{{"hi')
signal_data = json.dumps({'foo': 'bar'})
self.stdin.write(signal_data)
self.stdin.write(signal_data[:-3])
self.stdin.seek(0)
with self.write_config_file(self.data_signal_id) as config_file:
self.assertEqual(
0, hcn.main(['heat-config-notify', config_file.name], stdin))
0,
hcn.main(['heat-config-notify', config_file.name], self.stdin))
requests.post.assert_called_once_with(
'mock://192.0.2.3/foo',
@ -184,14 +198,16 @@ class HeatConfigNotifyTest(common.RunScriptTest):
heatclient.Client.return_value = heat
signal_data = json.dumps({'foo': 'bar'})
stdin = cStringIO.StringIO(signal_data)
self.stdin.write(signal_data)
self.stdin.seek(0)
ks.service_catalog.url_for.return_value = 'mock://192.0.2.3/heat'
heat.resources.signal.return_value = 'all good'
with self.write_config_file(self.data_heat_signal) as config_file:
self.assertEqual(
0, hcn.main(['heat-config-notify', config_file.name], stdin))
0,
hcn.main(['heat-config-notify', config_file.name], self.stdin))
ksclient.Client.assert_called_once_with(
auth_url='mock://192.0.2.3/auth',

View File

@ -165,7 +165,7 @@ class HookAnsibleTest(common.RunScriptTest):
'deploy_stdout': 'ansible success',
'deploy_stderr': 'thing happened',
'deploy_status_code': 0,
}, json.loads(stdout))
}, json.loads(stdout.decode('utf-8')))
state = self.json_from_file(self.test_state_path)
ansible_playbook = self.working_dir.join('1234_playbook.yaml')
@ -214,7 +214,7 @@ class HookAnsibleTest(common.RunScriptTest):
'deploy_stdout': 'ansible success',
'deploy_stderr': 'thing happened',
'deploy_status_code': 0,
}, json.loads(stdout))
}, json.loads(stdout.decode('utf-8')))
state = self.json_from_file(self.test_state_path)
ansible_playbook = self.working_dir.join('1234_playbook.yaml')
@ -248,7 +248,7 @@ class HookAnsibleTest(common.RunScriptTest):
'deploy_stdout': 'ansible failed',
'deploy_stderr': 'bad thing happened',
'deploy_status_code': 4,
}, json.loads(stdout))
}, json.loads(stdout.decode('utf-8')))
state = self.json_from_file(self.test_state_path)
ansible_playbook = self.working_dir.join('1234_playbook.yaml')

View File

@ -64,7 +64,7 @@ class HookCfnInitTest(common.RunScriptTest):
'deploy_stdout': 'cfn-init success',
'deploy_stderr': 'thing happened',
'deploy_status_code': 0
}, json.loads(stdout))
}, json.loads(stdout.decode('utf-8')))
# assert last_metadata was written with cfn-init metadata
self.assertEqual(
@ -92,7 +92,7 @@ class HookCfnInitTest(common.RunScriptTest):
'deploy_stdout': '',
'deploy_stderr': 'bad thing happened',
'deploy_status_code': 1
}, json.loads(stdout))
}, json.loads(stdout.decode('utf-8')))
self.assertEqual(
{'AWS::CloudFormation::Init': {'foo': 'bar'}},

View File

@ -13,10 +13,11 @@
import copy
import imp
import io
import json
import logging
import mock
import StringIO
import six
import sys
from tests import common
@ -58,8 +59,12 @@ class HookChefTest(common.RunScriptTest):
__file__,
'..',
'heat-config-chef/install.d/hook-chef.py')
sys.stdin = StringIO.StringIO()
sys.stdout = StringIO.StringIO()
if six.PY2:
sys.stdin = io.BytesIO()
sys.stdout = io.BytesIO()
else:
sys.stdin = io.StringIO()
sys.stdout = io.StringIO()
def tearDown(self):
super(HookChefTest, self).tearDown()
@ -77,7 +82,7 @@ class HookChefTest(common.RunScriptTest):
data = copy.deepcopy(self.data)
data['config'] = '["recipe[apache]"]'
hook_chef = self.get_module()
sys.stdin.write(json.dumps(data))
json.dump(data, sys.stdin)
sys.stdin.seek(0)
mock_subproc = mock.Mock()
mock_popen.return_value = mock_subproc

View File

@ -172,7 +172,7 @@ class HookDockerCmdTest(common.RunScriptTest):
'Creating web...\n'
'one.txt\ntwo.txt\nthree.txt',
'deploy_status_code': 0
}, json.loads(stdout))
}, json.loads(stdout.decode('utf-8')))
state = list(self.json_from_files(self.test_state_path, 9))
self.assertEqual([
@ -308,7 +308,7 @@ class HookDockerCmdTest(common.RunScriptTest):
'deploy_stdout': '',
'deploy_stderr': 'Warning: custom exit code',
'deploy_status_code': 0
}, json.loads(stdout))
}, json.loads(stdout.decode('utf-8')))
state = list(self.json_from_files(self.test_state_path, 5))
self.assertEqual([
@ -398,7 +398,7 @@ class HookDockerCmdTest(common.RunScriptTest):
'Creating web...\n'
'No such file or directory',
'deploy_status_code': 2
}, json.loads(stdout))
}, json.loads(stdout.decode('utf-8')))
state = list(self.json_from_files(self.test_state_path, 9))
self.assertEqual([
@ -552,7 +552,7 @@ class HookDockerCmdTest(common.RunScriptTest):
'Creating web...\n'
'one.txt\ntwo.txt\nthree.txt',
'deploy_status_code': 0
}, json.loads(stdout))
}, json.loads(stdout.decode('utf-8')))
state = list(self.json_from_files(self.test_state_path, 11))
db_container_name = state[4]['args'][4]
@ -691,7 +691,8 @@ class HookDockerCmdTest(common.RunScriptTest):
}])
})
conf_dir = self.useFixture(fixtures.TempDir()).join()
with tempfile.NamedTemporaryFile(dir=conf_dir, delete=False) as f:
with tempfile.NamedTemporaryFile(dir=conf_dir, delete=False,
mode='w') as f:
f.write(json.dumps([self.data]))
f.flush()
self.env['HEAT_SHELL_CONFIG'] = f.name
@ -740,7 +741,8 @@ class HookDockerCmdTest(common.RunScriptTest):
})
# run again with empty config data
with tempfile.NamedTemporaryFile(dir=conf_dir, delete=False) as f:
with tempfile.NamedTemporaryFile(dir=conf_dir, delete=False,
mode='w') as f:
f.write(json.dumps([]))
f.flush()
self.env['HEAT_SHELL_CONFIG'] = f.name
@ -811,7 +813,8 @@ class HookDockerCmdTest(common.RunScriptTest):
}])
})
conf_dir = self.useFixture(fixtures.TempDir()).join()
with tempfile.NamedTemporaryFile(dir=conf_dir, delete=False) as f:
with tempfile.NamedTemporaryFile(dir=conf_dir, delete=False,
mode='w') as f:
f.write(json.dumps([self.data]))
f.flush()
self.env['HEAT_SHELL_CONFIG'] = f.name
@ -862,7 +865,8 @@ class HookDockerCmdTest(common.RunScriptTest):
new_data = copy.deepcopy(self.data)
new_data['config']['web']['image'] = 'yyy'
new_data['id'] = 'def456'
with tempfile.NamedTemporaryFile(dir=conf_dir, delete=False) as f:
with tempfile.NamedTemporaryFile(dir=conf_dir, delete=False,
mode='w') as f:
f.write(json.dumps([new_data]))
f.flush()
self.env['HEAT_SHELL_CONFIG'] = f.name
@ -933,7 +937,8 @@ class HookDockerCmdTest(common.RunScriptTest):
}])
})
conf_dir = self.useFixture(fixtures.TempDir()).join()
with tempfile.NamedTemporaryFile(dir=conf_dir, delete=False) as f:
with tempfile.NamedTemporaryFile(dir=conf_dir, delete=False,
mode='w') as f:
f.write(json.dumps([self.data]))
f.flush()
self.env['HEAT_SHELL_CONFIG'] = f.name

View File

@ -107,7 +107,7 @@ class HookDockerComposeTest(common.RunScriptTest):
'deploy_stdout': '',
'deploy_stderr': 'Creating abcdef001_db_1...',
'deploy_status_code': 0
}, json.loads(stdout))
}, json.loads(stdout.decode('utf-8')))
state = self.json_from_file(self.test_state_path)
self.assertEqual(
@ -135,7 +135,7 @@ class HookDockerComposeTest(common.RunScriptTest):
'deploy_stdout': '',
'deploy_stderr': 'env_file_not found...',
'deploy_status_code': 1
}, json.loads(stdout))
}, json.loads(stdout.decode('utf-8')))
state = self.json_from_file(self.test_state_path)
self.assertEqual(
@ -163,7 +163,7 @@ class HookDockerComposeTest(common.RunScriptTest):
'deploy_stdout': '',
'deploy_stderr': 'Error: image library/xxx:latest not found',
'deploy_status_code': 1
}, json.loads(stdout))
}, json.loads(stdout.decode('utf-8')))
state = self.json_from_file(self.test_state_path)
self.assertEqual(

View File

@ -93,7 +93,7 @@ class HookPuppetTest(common.RunScriptTest):
'deploy_status_code': 0,
'first_output': 'output 1',
'second_output': 'output 2',
}, json.loads(stdout))
}, json.loads(stdout.decode('utf-8')))
state = self.json_from_file(self.test_state_path)
puppet_script = self.working_dir.join('1234.pp')
@ -200,7 +200,7 @@ class HookPuppetTest(common.RunScriptTest):
'deploy_stdout': 'puppet failed',
'deploy_stderr': 'bad thing happened',
'deploy_status_code': 4,
}, json.loads(stdout))
}, json.loads(stdout.decode('utf-8')))
state = self.json_from_file(self.test_state_path)
puppet_script = self.working_dir.join('1234.pp')
@ -256,7 +256,7 @@ class HookPuppetTest(common.RunScriptTest):
'deploy_status_code': 0,
'first_output': 'output 1',
'second_output': 'output 2',
}, json.loads(stdout))
}, json.loads(stdout.decode('utf-8')))
state = self.json_from_file(self.test_state_path)
puppet_script = self.working_dir.join('1234.pp')

View File

@ -97,9 +97,9 @@ class HookSaltTest(common.RunScriptTest):
self.assertIsNone(ret['deploy_stderr'])
self.assertIsNotNone(ret['deploy_stdout'])
resp = yaml.safe_load(ret['deploy_stdout'])
self.assertTrue(resp.values()[0]['result'])
self.assertTrue(list(resp.values())[0]['result'])
self.assertEqual({'bar': 'foo', 'foo': 'bar'},
resp.values()[0]['changes'])
list(resp.values())[0]['changes'])
def test_hook_salt_failed(self):
@ -111,7 +111,7 @@ class HookSaltTest(common.RunScriptTest):
self.assertEqual(0, returncode)
self.assertIsNotNone(stderr)
self.assertIsNotNone(stdout)
jsonout = json.loads(stdout)
jsonout = json.loads(stdout.decode('utf-8'))
self.assertIsNone(jsonout.get("deploy_stdout"),
jsonout.get("deploy_stdout"))
self.assertEqual(2, jsonout.get("deploy_status_code"))
@ -128,8 +128,8 @@ class HookSaltTest(common.RunScriptTest):
self.assertEqual(0, returncode, stderr)
self.assertIsNotNone(stdout)
self.assertIsNotNone(stderr)
ret = json.loads(stdout)
ret = json.loads(stdout.decode('utf-8'))
self.assertIsNone(ret['deploy_stdout'])
self.assertIsNotNone(ret['deploy_stderr'])
resp = yaml.safe_load(ret['deploy_stderr']).values()[0]
resp = list(yaml.safe_load(ret['deploy_stderr']).values())[0]
self.assertFalse(resp['result'])

View File

@ -84,7 +84,7 @@ class HookScriptTest(common.RunScriptTest):
'deploy_status_code': 0,
'first_output': 'output 1',
'second_output': 'output 2',
}, json.loads(stdout))
}, json.loads(stdout.decode('utf-8')))
state = self.json_from_file(self.test_state_path)
script = self.working_dir.join('1234')
@ -116,7 +116,7 @@ class HookScriptTest(common.RunScriptTest):
'deploy_stdout': 'script failed',
'deploy_stderr': 'bad thing happened',
'deploy_status_code': 1,
}, json.loads(stdout))
}, json.loads(stdout.decode('utf-8')))
state = self.json_from_file(self.test_state_path)
script = self.working_dir.join('1234')

View File

@ -1,9 +1,10 @@
[tox]
envlist = py27,pep8
envlist = py27,py35,pep8
minversion = 1.6
skipsdist = True
[testenv]
whitelist_externals = bash
setenv = VIRTUAL_ENV={envdir}
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt