From 326ca99184b896d75266737466516846df29b447 Mon Sep 17 00:00:00 2001 From: Ross Brattain Date: Sun, 11 Feb 2018 19:24:16 -0800 Subject: Heatstack create: fix str/bytes error in NamedTemporaryFile.write() we need to use jsonutils.dump_as_bytes for NamedTemporaryFile.write() 2018-02-11 19:15:01,366 [INFO] yardstick.orchestrator.heat heat.py:563 Creating stack 'yardstick-4359f33e' START 2018-02-11 19:15:01,935 [ERROR] yardstick.benchmark.contexts.heat heat.py:317 stack failed Traceback (most recent call last): File "/home/rbbratta/yardstick-upstream/yardstick/yardstick/benchmark/contexts/heat.py", line 313, in deploy timeout=self.heat_timeout) File "/home/rbbratta/yardstick-upstream/yardstick/yardstick/orchestrator/heat.py", line 567, in create stack.create(self._template, self.heat_parameters, block, timeout) File "/home/rbbratta/yardstick-upstream/yardstick/yardstick/orchestrator/heat.py", line 56, in create template_file.write(jsonutils.dumps(template)) File "/home/rbbratta/yardstick_venv3/lib/python3.5/tempfile.py", line 622, in func_wrapper return func(*args, **kwargs) TypeError: a bytes-like object is required, not 'str' JIRA: YARDSTICK-1005 Change-Id: I504f23b86119b62f3aea5b83a445b97bf810220c Signed-off-by: Ross Brattain --- yardstick/orchestrator/heat.py | 2 +- yardstick/tests/unit/orchestrator/test_heat.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/yardstick/orchestrator/heat.py b/yardstick/orchestrator/heat.py index 1a8beaeb6..754482e4f 100644 --- a/yardstick/orchestrator/heat.py +++ b/yardstick/orchestrator/heat.py @@ -53,7 +53,7 @@ class HeatStack(object): def create(self, template, heat_parameters, wait, timeout): """Creates an OpenStack stack from a template""" with tempfile.NamedTemporaryFile('wb', delete=False) as template_file: - template_file.write(jsonutils.dumps(template)) + template_file.write(jsonutils.dump_as_bytes(template)) template_file.close() self._stack = self._cloud.create_stack( self.name, template_file=template_file.name, wait=wait, diff --git a/yardstick/tests/unit/orchestrator/test_heat.py b/yardstick/tests/unit/orchestrator/test_heat.py index 9164197b8..f53c9b78c 100644 --- a/yardstick/tests/unit/orchestrator/test_heat.py +++ b/yardstick/tests/unit/orchestrator/test_heat.py @@ -59,7 +59,7 @@ class HeatStackTestCase(unittest.TestCase): with mock.patch.object(tempfile._TemporaryFileWrapper, '__enter__', return_value=mock_tfile): self.heatstack.create(template, heat_parameters, True, 100) - mock_tfile.write.assert_called_once_with(jsonutils.dumps(template)) + mock_tfile.write.assert_called_once_with(jsonutils.dump_as_bytes(template)) mock_tfile.close.assert_called_once() self.mock_stack_create.assert_called_once_with( -- cgit 1.2.3-korg