summaryrefslogtreecommitdiff
path: root/tests/unittests
diff options
context:
space:
mode:
authorAndrew Jorgensen <ajorgens@amazon.com>2017-08-14 17:08:37 +0000
committerScott Moser <smoser@ubuntu.com>2017-08-25 14:46:19 -0700
commit20ca23cab0bdfdffa567f8fb4b49f3727bac6444 (patch)
tree50df8ca6773a7088357c1c7061dd728acd789320 /tests/unittests
parent89579a68d9f51e51b24f96b933da656afd83edfb (diff)
downloadvyos-cloud-init-20ca23cab0bdfdffa567f8fb4b49f3727bac6444.tar.gz
vyos-cloud-init-20ca23cab0bdfdffa567f8fb4b49f3727bac6444.zip
Log a helpful message if a user script does not include shebang.
A patch to allow scripts missing a #! to run by using shell=True was proposed but rejected. Instead we emit a log message to help the user understand what went wrong.
Diffstat (limited to 'tests/unittests')
-rw-r--r--tests/unittests/test_util.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py
index f38a664c..5f11c88f 100644
--- a/tests/unittests/test_util.py
+++ b/tests/unittests/test_util.py
@@ -568,7 +568,8 @@ class TestReadSeeded(helpers.TestCase):
self.assertEqual(found_ud, ud)
-class TestSubp(helpers.TestCase):
+class TestSubp(helpers.CiTestCase):
+ with_logs = True
stdin2err = [BASH, '-c', 'cat >&2']
stdin2out = ['cat']
@@ -650,6 +651,16 @@ class TestSubp(helpers.TestCase):
self.assertEqual(
['FOO=BAR', 'HOME=/myhome', 'K1=V1', 'K2=V2'], out.splitlines())
+ def test_subp_warn_missing_shebang(self):
+ """Warn on no #! in script"""
+ noshebang = self.tmp_path('noshebang')
+ util.write_file(noshebang, 'true\n')
+
+ os.chmod(noshebang, os.stat(noshebang).st_mode | stat.S_IEXEC)
+ self.assertRaisesRegexp(util.ProcessExecutionError,
+ 'Missing #! in script\?',
+ util.subp, (noshebang,))
+
def test_returns_none_if_no_capture(self):
(out, err) = util.subp(self.stdin2out, data=b'', capture=False)
self.assertIsNone(err)