From a254e1f31e5f34cc4944de922131688a692c0fd5 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 12 Oct 2011 17:12:22 +0200 Subject: [PATCH] return output of command execution as string instead of bytestring Signed-off-by: Steven Armstrong --- lib/cdist/exec/local.py | 4 ++-- lib/cdist/exec/remote.py | 4 ++-- lib/cdist/test/exec/test_local.py | 2 +- lib/cdist/test/exec/test_remote.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/cdist/exec/local.py b/lib/cdist/exec/local.py index b346bf7d..521d56c3 100644 --- a/lib/cdist/exec/local.py +++ b/lib/cdist/exec/local.py @@ -93,7 +93,7 @@ class Local(object): assert isinstance(command, (list, tuple)), "list or tuple argument expected, got: %s" % command self.log.debug("Local run: %s", command) try: - return subprocess.check_output(command, env=env) + return subprocess.check_output(command, env=env).decode() except subprocess.CalledProcessError: raise cdist.Error("Command failed: " + " ".join(command)) except OSError as error: @@ -112,7 +112,7 @@ class Local(object): self.log.debug("Local run script env: %s", env) try: - return subprocess.check_output(command, env=env) + return subprocess.check_output(command, env=env).decode() except subprocess.CalledProcessError as error: script_content = self.run(["cat", script]) self.log.error("Code that raised the error:\n%s", script_content) diff --git a/lib/cdist/exec/remote.py b/lib/cdist/exec/remote.py index 6ec9c46f..7821e993 100644 --- a/lib/cdist/exec/remote.py +++ b/lib/cdist/exec/remote.py @@ -104,7 +104,7 @@ class Remote(object): assert isinstance(command, (list, tuple)), "list or tuple argument expected, got: %s" % command self.log.debug("Remote run: %s", command) try: - return subprocess.check_output(command, env=env) + return subprocess.check_output(command, env=env).decode() except subprocess.CalledProcessError: raise cdist.Error("Command failed: " + " ".join(command)) except OSError as error: @@ -125,7 +125,7 @@ class Remote(object): self.log.debug("Remote run script env: %s", env) try: - return subprocess.check_output(command, env=env) + return subprocess.check_output(command, env=env).decode() except subprocess.CalledProcessError as error: script_content = self.run(["cat", script]) self.log.error("Code that raised the error:\n%s", script_content) diff --git a/lib/cdist/test/exec/test_local.py b/lib/cdist/test/exec/test_local.py index 40611a0b..b74f412e 100644 --- a/lib/cdist/test/exec/test_local.py +++ b/lib/cdist/test/exec/test_local.py @@ -81,7 +81,7 @@ class LocalTestCase(unittest.TestCase): fd = open(script, "w") fd.writelines(["#!/bin/sh\n", "echo foobar"]) fd.close() - self.assertEqual(self.local.run_script(script), b"foobar\n") + self.assertEqual(self.local.run_script(script), "foobar\n") def test_mkdir(self): temp_dir = self.mkdtemp(dir=self.temp_dir) diff --git a/lib/cdist/test/exec/test_remote.py b/lib/cdist/test/exec/test_remote.py index ae5e7aed..1fdb5833 100644 --- a/lib/cdist/test/exec/test_remote.py +++ b/lib/cdist/test/exec/test_remote.py @@ -76,7 +76,7 @@ class RemoteTestCase(unittest.TestCase): fd = open(script, "w") fd.writelines(["#!/bin/sh\n", "echo foobar"]) fd.close() - self.assertEqual(self.remote.run_script(script), b"foobar\n") + self.assertEqual(self.remote.run_script(script), "foobar\n") def test_mkdir(self): temp_dir = self.mkdtemp(dir=self.temp_dir)