python3: celery now handle text (#40288)
This commit is contained in:
parent
cf4d3d4a46
commit
59b3228dcb
|
@ -10,6 +10,7 @@ import tempfile
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
from django.core.management import call_command, get_commands
|
from django.core.management import call_command, get_commands
|
||||||
|
from django.utils.encoding import force_text
|
||||||
from django.utils.six.moves.urllib import parse as urlparse
|
from django.utils.six.moves.urllib import parse as urlparse
|
||||||
|
|
||||||
from tenant_schemas.utils import tenant_context
|
from tenant_schemas.utils import tenant_context
|
||||||
|
@ -26,7 +27,7 @@ def replace_file(path, content):
|
||||||
fd, temp = tempfile.mkstemp(dir=dirname,
|
fd, temp = tempfile.mkstemp(dir=dirname,
|
||||||
prefix='.tmp-'+os.path.basename(path)+'-')
|
prefix='.tmp-'+os.path.basename(path)+'-')
|
||||||
f = os.fdopen(fd, 'w')
|
f = os.fdopen(fd, 'w')
|
||||||
f.write(content)
|
f.write(force_text(content))
|
||||||
f.flush()
|
f.flush()
|
||||||
os.fsync(f.fileno())
|
os.fsync(f.fileno())
|
||||||
f.close()
|
f.close()
|
||||||
|
|
|
@ -23,6 +23,7 @@ import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from django.utils.encoding import force_bytes
|
||||||
from django.utils.six.moves.urllib import parse as urlparse
|
from django.utils.six.moves.urllib import parse as urlparse
|
||||||
|
|
||||||
from . import settings
|
from . import settings
|
||||||
|
@ -80,7 +81,7 @@ class BaseService(object):
|
||||||
cmd = self.service_manage_cmd + ' hobo_deploy ' + self.base_url + ' -'
|
cmd = self.service_manage_cmd + ' hobo_deploy ' + self.base_url + ' -'
|
||||||
cmd_process = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
|
cmd_process = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
stdout, stderr = cmd_process.communicate(input=json.dumps(environment))
|
stdout, stderr = cmd_process.communicate(input=force_bytes(json.dumps(environment)))
|
||||||
if cmd_process.returncode != 0:
|
if cmd_process.returncode != 0:
|
||||||
raise RuntimeError('command "%s" failed: %r %r' % (cmd, stdout, stderr))
|
raise RuntimeError('command "%s" failed: %r %r' % (cmd, stdout, stderr))
|
||||||
|
|
||||||
|
@ -103,7 +104,7 @@ class BaseService(object):
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
except OSError:
|
except OSError:
|
||||||
return
|
return
|
||||||
stdout, stderr = cmd_process.communicate(input=json.dumps(data))
|
stdout, stderr = cmd_process.communicate(input=force_bytes(json.dumps(data)))
|
||||||
if cmd_process.returncode != 0:
|
if cmd_process.returncode != 0:
|
||||||
raise RuntimeError('command "%s" failed: %r %r' % (cmd, stdout, stderr))
|
raise RuntimeError('command "%s" failed: %r %r' % (cmd, stdout, stderr))
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ import os
|
||||||
import pytest
|
import pytest
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
from django.utils.encoding import force_text
|
||||||
|
|
||||||
from hobo.agent.worker.services import deploy, notify
|
from hobo.agent.worker.services import deploy, notify
|
||||||
from hobo.agent.worker import settings
|
from hobo.agent.worker import settings
|
||||||
|
|
||||||
|
@ -102,7 +104,7 @@ def test_deploy(mocked_subprocess, mocked_exists):
|
||||||
mock_calls = mocked_communicate.mock_calls
|
mock_calls = mocked_communicate.mock_calls
|
||||||
assert len(mock_calls) == 4
|
assert len(mock_calls) == 4
|
||||||
for i in range(0, len(mock_calls)):
|
for i in range(0, len(mock_calls)):
|
||||||
assert json.loads(mock_calls[0][2]['input']) == ENVIRONMENT
|
assert json.loads(force_text(mock_calls[0][2]['input'])) == ENVIRONMENT
|
||||||
|
|
||||||
mocked_opened.returncode = 1
|
mocked_opened.returncode = 1
|
||||||
with pytest.raises(RuntimeError, match='failed: '):
|
with pytest.raises(RuntimeError, match='failed: '):
|
||||||
|
@ -147,7 +149,7 @@ def test_notify(mocked_subprocess, mocked_listdir, mocked_exists):
|
||||||
# notification sent
|
# notification sent
|
||||||
mock_calls = mocked_communicate.mock_calls
|
mock_calls = mocked_communicate.mock_calls
|
||||||
assert len(mock_calls) == 1
|
assert len(mock_calls) == 1
|
||||||
assert json.loads(mock_calls[0][2]['input'])['objects']['data'][0]['uuid'] == '12345'
|
assert json.loads(force_text(mock_calls[0][2]['input']))['objects']['data'][0]['uuid'] == '12345'
|
||||||
|
|
||||||
mocked_opened.returncode = 1
|
mocked_opened.returncode = 1
|
||||||
with pytest.raises(RuntimeError, match='failed: '):
|
with pytest.raises(RuntimeError, match='failed: '):
|
||||||
|
|
Loading…
Reference in New Issue