Merge ~raharper/curtin:fix/zfsroot-export-zpools-after-install into curtin:master

Proposed by Ryan Harper
Status: Merged
Approved by: Ryan Harper
Approved revision: 8c362d2e8dcfb26792c7978f6528c90e9845d48a
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~raharper/curtin:fix/zfsroot-export-zpools-after-install
Merge into: curtin:master
Diff against target: 112 lines (+55/-3)
4 files modified
curtin/block/zfs.py (+24/-0)
curtin/commands/install.py (+5/-1)
tests/unittests/test_block_zfs.py (+26/-0)
tests/vmtests/test_zfsroot.py (+0/-2)
Reviewer Review Type Date Requested Status
Chad Smith Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+372913@code.launchpad.net

Commit message

install: export zpools if present in the storage-config

Curtin needs to run zpool export on the any pool it created
before booting as zfs-initramfs 0.8 now requires a pool to
be exported before being imported.

LP: #1838278

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Scott Moser (smoser) wrote :

You should mention in commit message that you're putting /run into all chroots now.

Revision history for this message
Ryan Harper (raharper) wrote :

> You should mention in commit message that you're putting /run into all chroots
> now.

Fixed now; I didn't mean to include that in this merge. I'll put the /run one up separately.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ryan Harper (raharper) wrote :

vmtest shows that the fstype: zfsroot scenario needs a fix too.

Revision history for this message
Dan Watkins (oddbloke) :
Revision history for this message
Ryan Harper (raharper) wrote :

Thanks, I'll fix up the early return. And I need to add a fix for the zfsroot fstype case.

Revision history for this message
Dan Watkins (oddbloke) :
Revision history for this message
Ryan Harper (raharper) wrote :

Computer says "Yes!"

https://jenkins.ubuntu.com/server/job/curtin-vmtest-devel-debug/191/console

----------------------------------------------------------------------
Ran 182 tests in 1687.305s

OK (SKIP=28)
Wed, 18 Sep 2019 13:15:40 +0000: vmtest end [0] in 1690s

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Scott Moser (smoser) wrote :

The /run change got moved https://code.launchpad.net/~raharper/curtin/+git/curtin/+merge/372942

Thanks for separating.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Chad Smith (chad.smith) wrote :

Thanks for this, looks good Ryan, just one question about limiting where we need to do this to Eoan ++,

review: Needs Information
Revision history for this message
Ryan Harper (raharper) :
Revision history for this message
Chad Smith (chad.smith) wrote :

+1 on this. Thanks for the response.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/curtin/block/zfs.py b/curtin/block/zfs.py
2index dce15c3..25751d3 100644
3--- a/curtin/block/zfs.py
4+++ b/curtin/block/zfs.py
5@@ -281,4 +281,28 @@ def device_to_poolname(devname):
6 if vdev_type == 'zfs_member' and label:
7 return label
8
9+
10+def get_zpool_from_config(cfg):
11+ """Parse a curtin storage config and return a list
12+ of zpools that were created.
13+ """
14+ if not cfg:
15+ return []
16+
17+ if 'storage' not in cfg:
18+ return []
19+
20+ zpools = []
21+ sconfig = cfg['storage']['config']
22+ for item in sconfig:
23+ if item['type'] == 'zpool':
24+ zpools.append(item['pool'])
25+ elif item['type'] == 'format':
26+ if item['fstype'] == 'zfsroot':
27+ # curtin.commands.blockmeta sets pool='rpool' for zfsroot
28+ zpools.append('rpool')
29+
30+ return zpools
31+
32+
33 # vi: ts=4 expandtab syntax=python
34diff --git a/curtin/commands/install.py b/curtin/commands/install.py
35index ad17508..a3471f6 100644
36--- a/curtin/commands/install.py
37+++ b/curtin/commands/install.py
38@@ -11,7 +11,7 @@ import subprocess
39 import sys
40 import tempfile
41
42-from curtin.block import iscsi
43+from curtin.block import iscsi, zfs
44 from curtin import config
45 from curtin import distro
46 from curtin import util
47@@ -505,6 +505,10 @@ def cmd_install(args):
48 if iscsi.get_iscsi_disks_from_config(cfg):
49 iscsi.restart_iscsi_service()
50
51+ for pool in zfs.get_zpool_from_config(cfg):
52+ LOG.debug('Exporting ZFS zpool %s', pool)
53+ zfs.zpool_export(pool)
54+
55 shutil.rmtree(workingd.top)
56
57 apply_power_state(cfg.get('power_state'))
58diff --git a/tests/unittests/test_block_zfs.py b/tests/unittests/test_block_zfs.py
59index f45fde2..3508d4b 100644
60--- a/tests/unittests/test_block_zfs.py
61+++ b/tests/unittests/test_block_zfs.py
62@@ -538,4 +538,30 @@ class TestZfsSupported(CiTestCase):
63 self.assertEqual(1, m_assert_zfs.call_count)
64
65
66+class TestZfsGetPoolFromConfig(CiTestCase):
67+
68+ def test_get_zpool_from_config_returns_empty(self):
69+ """ get_zpool_from_config_returns_empty for invalid/empty configs."""
70+ configs = (None, {}, {'network': 'foobar'},
71+ {'storage': {'config': []}})
72+ for cfg in configs:
73+ self.assertEqual([],
74+ zfs.get_zpool_from_config(cfg))
75+
76+ def test_get_zpool_from_config(self):
77+ """ get_zpool_from_config_returns pool names for each zpool in cfg."""
78+ expected_zpools = ['rpool1', 'rpool2']
79+ zpool_cfg = [{'type': 'zpool', 'pool': pool}
80+ for pool in expected_zpools]
81+ sconfig = {'storage': {'config': zpool_cfg}}
82+ self.assertEqual(sorted(expected_zpools),
83+ sorted(zfs.get_zpool_from_config(sconfig)))
84+
85+ def test_get_zpool_from_config_zfsroot(self):
86+ """ get_zpool_from_config_returns injected pool name for zfsroot."""
87+ zpool_cfg = [{'type': 'format', 'fstype': 'zfsroot'}]
88+ sconfig = {'storage': {'config': zpool_cfg}}
89+ self.assertEqual(['rpool'], zfs.get_zpool_from_config(sconfig))
90+
91+
92 # vi: ts=4 expandtab syntax=python
93diff --git a/tests/vmtests/test_zfsroot.py b/tests/vmtests/test_zfsroot.py
94index a2fc316..a0e50e9 100644
95--- a/tests/vmtests/test_zfsroot.py
96+++ b/tests/vmtests/test_zfsroot.py
97@@ -99,7 +99,6 @@ class DiscoTestZfsRoot(relbase.disco, TestZfsRootAbs):
98 mem = 4096
99
100
101-@TestZfsRootAbs.skip_by_date("1838278", fixby="2019-10-01", install=False)
102 class EoanTestZfsRoot(relbase.eoan, TestZfsRootAbs):
103 __test__ = True
104 mem = 4096
105@@ -129,7 +128,6 @@ class DiscoTestZfsRootFsType(relbase.disco, TestZfsRootFsTypeAbs):
106 mem = 4096
107
108
109-@TestZfsRootAbs.skip_by_date("1838278", fixby="2019-10-01", install=False)
110 class EoanTestZfsRootFsType(relbase.eoan, TestZfsRootFsTypeAbs):
111 __test__ = True
112 mem = 4096

Subscribers

People subscribed via source and target branches