Merge ~raharper/curtin:bug/fix-curtin-exit-code into curtin:master

Proposed by Ryan Harper
Status: Merged
Approved by: Scott Moser
Approved revision: a6145f924398b06a2d5d5d18d4642505ecdc780d
Merged at revision: a6145f924398b06a2d5d5d18d4642505ecdc780d
Proposed branch: ~raharper/curtin:bug/fix-curtin-exit-code
Merge into: curtin:master
Diff against target: 68 lines (+5/-13)
2 files modified
curtin/commands/collect_logs.py (+1/-1)
tests/unittests/test_commands_collect_logs.py (+4/-12)
Reviewer Review Type Date Requested Status
Scott Moser (community) Approve
Review via email: mp+339411@code.launchpad.net

Description of the change

fix /usr/bin/curtin exit code in install failure

When curtin encounters an error during the 'install' stage, the default
configuration enables collecting of system logs. The collect_logs
function 'create_log_tarfall' included a sys.exit(0) which should only be
part of the 'collect_logs_main' method; this resulted in failed installs
exiting with a return code of 0. The fix is to move the sys.exit(0) up to
the main method.

LP: #1751176

To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/curtin/commands/collect_logs.py b/curtin/commands/collect_logs.py
2index a61d91e..a452e2e 100644
3--- a/curtin/commands/collect_logs.py
4+++ b/curtin/commands/collect_logs.py
5@@ -48,6 +48,7 @@ def collect_logs_main(args):
6 SAVE_INSTALL_CONFIG, CURTIN_PACK_CONFIG_DIR))
7 cfg = CONFIG_BUILTIN.copy()
8 create_log_tarfile(args.output, cfg)
9+ sys.exit(0)
10
11
12 def create_log_tarfile(tarfile, config):
13@@ -104,7 +105,6 @@ def create_log_tarfile(tarfile, config):
14 if os.path.exists(tmp_dir):
15 shutil.rmtree(tmp_dir)
16 sys.stderr.write('Wrote: %s\n' % tarfile)
17- sys.exit(0)
18
19
20 def _collect_system_info(target_dir, config):
21diff --git a/tests/unittests/test_commands_collect_logs.py b/tests/unittests/test_commands_collect_logs.py
22index d20cc54..bab36ae 100644
23--- a/tests/unittests/test_commands_collect_logs.py
24+++ b/tests/unittests/test_commands_collect_logs.py
25@@ -247,9 +247,7 @@ class TestCreateTar(CiTestCase):
26 self.add_patch('curtin.util.subp', 'mock_subp')
27 self.mock_subp.return_value = ('', '')
28 with mock.patch('sys.stderr'):
29- with self.assertRaises(SystemExit) as context_manager:
30- collect_logs.create_log_tarfile(tarfile, config={})
31- self.assertEqual('0', str(context_manager.exception))
32+ collect_logs.create_log_tarfile(tarfile, config={})
33 self.assertIn(
34 mock.call(['tar', '-cvf', tarfile, self.tardir],
35 capture=True),
36@@ -266,9 +264,7 @@ class TestCreateTar(CiTestCase):
37 self.add_patch('curtin.util.subp', 'mock_subp')
38 self.mock_subp.return_value = ('', '')
39 with mock.patch('sys.stderr'):
40- with self.assertRaises(SystemExit) as context_manager:
41- collect_logs.create_log_tarfile(tarfile, config={})
42- self.assertEqual('0', str(context_manager.exception))
43+ collect_logs.create_log_tarfile(tarfile, config={})
44 self.assertIn(
45 mock.call(['tar', '-cvf', tarfile, self.tardir],
46 capture=True),
47@@ -292,9 +288,7 @@ class TestCreateTar(CiTestCase):
48 'install': {'log_file': log1, 'post_files': [log2, absent_log]}}
49 self.add_patch('shutil.copy', 'm_copy')
50 with mock.patch('sys.stderr') as m_stderr:
51- with self.assertRaises(SystemExit) as context_manager:
52- collect_logs.create_log_tarfile(tarfile, config=config)
53- self.assertEqual('0', str(context_manager.exception))
54+ collect_logs.create_log_tarfile(tarfile, config=config)
55 self.assertIn(
56 mock.call(
57 'Skipping logfile %s: file does not exist\n' % absent_log),
58@@ -317,9 +311,7 @@ class TestCreateTar(CiTestCase):
59 'maas': {'consumer_key': 'ckey',
60 'token_key': 'tkey', 'token_secret': 'tsecret'}}}
61 with mock.patch('sys.stderr'):
62- with self.assertRaises(SystemExit) as context_manager:
63- collect_logs.create_log_tarfile(tarfile, config=config)
64- self.assertEqual('0', str(context_manager.exception))
65+ collect_logs.create_log_tarfile(tarfile, config=config)
66 self.assertEqual(
67 [mock.call(self.tardir, ['ckey', 'tkey', 'tsecret'])],
68 self.m_redact.call_args_list)

Subscribers

People subscribed via source and target branches