Use processutils to fix TypeError in subprocess
Calling processutils.execute() other than subprocess to fix bytes-like and str issue in python3. Closes-bug: #2029392 Change-Id: I16436aa19da2cf53951c9ad27bca14033194651a
This commit is contained in:
parent
d27fb63796
commit
e0937b1f09
@ -16,6 +16,7 @@ python-swiftclient>=3.10.1 # Apache-2.0
|
||||
WebOb>=1.7.1 # MIT
|
||||
stevedore>=3.2.2 # Apache-2.0
|
||||
oslo.cache>=1.26.0 # Apache-2.0
|
||||
oslo.concurrency>=5.0.1 # Apache-2.0
|
||||
oslo.config>=8.3.2 # Apache-2.0
|
||||
oslo.context>=2.19.2 # Apache-2.0
|
||||
oslo.db>=11.0.0 # Apache-2.0
|
||||
|
@ -15,9 +15,9 @@
|
||||
|
||||
from email.mime import text
|
||||
import smtplib
|
||||
import subprocess
|
||||
from urllib import parse as urllib_parse
|
||||
|
||||
from oslo_concurrency import processutils
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
@ -98,9 +98,8 @@ class MailtoTask(object):
|
||||
subject_opt = subscription['options'].get('subject', '')
|
||||
msg["subject"] = params.get('subject', subject_opt)
|
||||
if conf_n.smtp_mode == 'third_part':
|
||||
p = subprocess.Popen(conf_n.smtp_command.split(' '),
|
||||
stdin=subprocess.PIPE)
|
||||
p.communicate(msg.as_string())
|
||||
cmd = conf_n.smtp_command.split(' ')
|
||||
processutils.execute(*cmd, process_input=msg.as_string())
|
||||
elif conf_n.smtp_mode == 'self_local':
|
||||
sender = smtplib.SMTP_SSL(conf_n.smtp_host,
|
||||
conf_n.smtp_port)
|
||||
|
@ -19,6 +19,7 @@ import uuid
|
||||
import ddt
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import encodeutils
|
||||
|
||||
from zaqar.common import urls
|
||||
from zaqar.notification import notifier
|
||||
@ -228,11 +229,12 @@ class NotifierTest(testing.TestBase):
|
||||
'from': 'zaqar@example.com', 'subject': 'Hello',
|
||||
'body': jsonutils.dumps(self.notifications[1])}
|
||||
|
||||
def _communicate(msg):
|
||||
def _communicate(msg, timeout=None):
|
||||
called.add(msg)
|
||||
return ('', '')
|
||||
|
||||
mock_process = mock.Mock()
|
||||
attrs = {'communicate': _communicate}
|
||||
attrs = {'communicate': _communicate, 'returncode': 0}
|
||||
mock_process.configure_mock(**attrs)
|
||||
mock_popen.return_value = mock_process
|
||||
driver.post('fake_queue', self.messages, self.client_id, self.project)
|
||||
@ -252,7 +254,7 @@ class NotifierTest(testing.TestBase):
|
||||
called_options = []
|
||||
called_bodies = []
|
||||
for call in called:
|
||||
options, body = call.split('\n\n')
|
||||
options, body = encodeutils.safe_decode(call).split('\n\n')
|
||||
called_options.append(options)
|
||||
called_bodies.append(jsonutils.dumps(jsonutils.loads(body),
|
||||
sort_keys=True))
|
||||
@ -408,11 +410,12 @@ class NotifierTest(testing.TestBase):
|
||||
|
||||
called = set()
|
||||
|
||||
def _communicate(msg):
|
||||
def _communicate(msg, timeout=None):
|
||||
called.add(msg)
|
||||
return ('', '')
|
||||
|
||||
mock_process = mock.Mock()
|
||||
attrs = {'communicate': _communicate}
|
||||
attrs = {'communicate': _communicate, 'returncode': 0}
|
||||
mock_process.configure_mock(**attrs)
|
||||
mock_popen.return_value = mock_process
|
||||
mock_signed_url.return_value = message
|
||||
@ -429,7 +432,7 @@ class NotifierTest(testing.TestBase):
|
||||
called_options = []
|
||||
called_bodies = []
|
||||
for call in called:
|
||||
options, body = call.split('\n\n')
|
||||
options, body = encodeutils.safe_decode(call).split('\n\n')
|
||||
called_options.append(options)
|
||||
called_bodies.append(body)
|
||||
self.assertEqual(expec_options, called_options)
|
||||
|
Loading…
x
Reference in New Issue
Block a user