Merge ~dbungert/curtin:lp-1987236-chzdev into curtin:master

Proposed by Dan Bungert
Status: Merged
Approved by: Michael Hudson-Doyle
Approved revision: 360d590782987f2a68285e77aa81ead0076fd395
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~dbungert/curtin:lp-1987236-chzdev
Merge into: curtin:master
Diff against target: 62 lines (+23/-3)
2 files modified
curtin/commands/curthooks.py (+10/-2)
tests/unittests/test_curthooks.py (+13/-1)
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+428926@code.launchpad.net

Commit message

curthooks: make chzdev_export non-fatal on error

LP: #1987236

To post a comment you must log in.
Revision history for this message
Dan Bungert (dbungert) wrote :

still pending test

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Looks OKish to me. Are there other reasons why chzdev_export might fail? Swallowing failure like this is always a bit dodgy.

Revision history for this message
Dan Bungert (dbungert) wrote :

> Looks OKish to me. Are there other reasons why chzdev_export might fail?
> Swallowing failure like this is always a bit dodgy.

We could make this more specific and only swallow exit code 8:
       8 Empty selection
https://github.com/hreinecke/s390-tools-1/blob/39382ec5fdaa78c8b9e3534ff9537af7ce130607/zdev/man/chzdev.8#L634

~dbungert/curtin:lp-1987236-chzdev updated
360d590... by Dan Bungert

curthooks: narrow the chzdev_export error skip

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

I think you can make this simpler by using the rcs= argument to subp? util.subp(cmd, capture=True, rcs=[0, 8])

If this doesn't work for some reason, feel free to ignore me :)

Revision history for this message
Dan Bungert (dbungert) wrote :

Ah, a good reminder about the rcs arg. In this case though I don't think it's what we want. In the rc == 8 case, we do not want to continue on to the chzdev_prepare_for_import() step. We could add 8 to the rcs chzdev_export, but then we would need to convince ourselves that the later steps handle empty input or find some other way to not do the chzdev_prepare_for_import(). I propose that we stick to my current plan.

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Oh right, I see that subp doesn't tell you which of the acceptable rc values actually happened. Oh well. Have it your way :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/curtin/commands/curthooks.py b/curtin/commands/curthooks.py
2index 141eb76..4001166 100644
3--- a/curtin/commands/curthooks.py
4+++ b/curtin/commands/curthooks.py
5@@ -218,7 +218,11 @@ def chzdev_persist_active_online(cfg, target):
6
7 LOG.info('Persisting zdevice configuration in target')
8 target_etc = paths.target_path(target, 'etc')
9- (chzdev_conf, _) = chzdev_export(active=True, online=True)
10+ ERR_EMPTY_SELECTION = 8 # No settings found to export
11+ (chzdev_conf, _, ec) = chzdev_export(active=True, online=True)
12+ if ec == ERR_EMPTY_SELECTION:
13+ LOG.info('z specific devices not found')
14+ return
15 chzdev_persistent = chzdev_prepare_for_import(chzdev_conf)
16 chzdev_import(data=chzdev_persistent,
17 persistent=True, noroot=True, base={'/etc': target_etc})
18@@ -240,7 +244,11 @@ def chzdev_export(active=True, online=True, persistent=False,
19 cmd.extend(['--persistent'])
20 cmd.extend(['--export', export_file])
21
22- return util.subp(cmd, capture=True)
23+ try:
24+ out, err = util.subp(cmd, capture=True)
25+ return (out, err, 0)
26+ except util.ProcessExecutionError as proc_ex_err:
27+ return (None, None, proc_ex_err.exit_code)
28
29
30 def chzdev_import(data=None, persistent=True, noroot=True, base=None,
31diff --git a/tests/unittests/test_curthooks.py b/tests/unittests/test_curthooks.py
32index f87c17a..5ca0b8c 100644
33--- a/tests/unittests/test_curthooks.py
34+++ b/tests/unittests/test_curthooks.py
35@@ -1792,7 +1792,7 @@ class TestCurthooksChzdev(CiTestCase):
36 """chzdev_persist uses export, sends to prepare & import consumes."""
37 export_value = self.random_string()
38 import_value = self.random_string().encode()
39- m_chz_export.return_value = (export_value, '')
40+ m_chz_export.return_value = (export_value, '', 0)
41 m_chz_prepare.return_value = import_value
42 curthooks.chzdev_persist_active_online({}, self.target)
43 self.assertEqual(1, m_chz_export.call_count)
44@@ -1803,6 +1803,18 @@ class TestCurthooksChzdev(CiTestCase):
45 persistent=True, noroot=True,
46 base={'/etc': self.target + '/etc'})
47
48+ @patch('curtin.commands.curthooks.chzdev_export')
49+ @patch('curtin.commands.curthooks.chzdev_prepare_for_import')
50+ @patch('curtin.commands.curthooks.chzdev_import')
51+ def test_chzdev_skip_empty_selection(self, m_chz_import,
52+ m_chz_prepare, m_chz_export):
53+ """when chzdev_export returns an empty selection error, bail"""
54+ m_chz_export.return_value = (None, None, 8)
55+ curthooks.chzdev_persist_active_online({}, self.target)
56+ self.assertEqual(1, m_chz_export.call_count)
57+ self.assertEqual(0, m_chz_prepare.call_count)
58+ self.assertEqual(0, m_chz_import.call_count)
59+
60 def test_export_defaults_to_stdout(self):
61 """chzdev_export returns (stdout, stderr) from subp."""
62 self.m_subp.return_value = (self.chzdev_export, '')

Subscribers

People subscribed via source and target branches