Merge ~goneri/cloud-init:freebsd_nocloud into cloud-init:master

Proposed by Gonéri Le Bouder
Status: Merged
Approved by: Chad Smith
Approved revision: df7f3963cc86811a7d166243e913fc1c4833ad8f
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~goneri/cloud-init:freebsd_nocloud
Merge into: cloud-init:master
Diff against target: 108 lines (+43/-19)
3 files modified
cloudinit/sources/DataSourceNoCloud.py (+23/-17)
config/cloud.cfg.tmpl (+2/-2)
tests/unittests/test_datasource/test_nocloud.py (+18/-0)
Reviewer Review Type Date Requested Status
Chad Smith Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+365630@code.launchpad.net

Commit message

freebsd: NoCloud data source support

blkid is a Linux-only command. With this patch, cloud-init uses another
approach to find the data source on FreeBSD.

LP: #1645824

To post a comment you must log in.
Revision history for this message
do3meli (d-info-e) wrote :

it might be useful to have some test cases that cover the linux way using blkid and having a case that covers the FreeBSD way so future addition/changes to the data source don't break things up again without noticing.

apart from that - looking at the code diff without really testing it - the change looks reasonable to me.

Revision history for this message
Gonéri Le Bouder (goneri) wrote :

Done.

Revision history for this message
do3meli (d-info-e) wrote :

added 2 comments - don't understand that in detail yet...

Revision history for this message
Gonéri Le Bouder (goneri) :
Revision history for this message
Chad Smith (chad.smith) wrote :

Thanks for this branch Gonéri. Minor nits from me, but otherwise looks good.

Please reset 'Needs review' status when you get a chance to address or resolve comments.

Revision history for this message
Gonéri Le Bouder (goneri) wrote :

Done.

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

PASSED: Continuous integration, rev:df7f3963cc86811a7d166243e913fc1c4833ad8f
https://jenkins.ubuntu.com/server/job/cloud-init-ci/729/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/729/rebuild

review: Approve (continuous-integration)
Revision history for this message
Chad Smith (chad.smith) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/cloudinit/sources/DataSourceNoCloud.py b/cloudinit/sources/DataSourceNoCloud.py
index fcf5d58..8a9e5dd 100644
--- a/cloudinit/sources/DataSourceNoCloud.py
+++ b/cloudinit/sources/DataSourceNoCloud.py
@@ -35,6 +35,26 @@ class DataSourceNoCloud(sources.DataSource):
35 root = sources.DataSource.__str__(self)35 root = sources.DataSource.__str__(self)
36 return "%s [seed=%s][dsmode=%s]" % (root, self.seed, self.dsmode)36 return "%s [seed=%s][dsmode=%s]" % (root, self.seed, self.dsmode)
3737
38 def _get_devices(self, label):
39 if util.is_FreeBSD():
40 devlist = [
41 p for p in ['/dev/msdosfs/' + label, '/dev/iso9660/' + label]
42 if os.path.exists(p)]
43 else:
44 # Query optical drive to get it in blkid cache for 2.6 kernels
45 util.find_devs_with(path="/dev/sr0")
46 util.find_devs_with(path="/dev/sr1")
47
48 fslist = util.find_devs_with("TYPE=vfat")
49 fslist.extend(util.find_devs_with("TYPE=iso9660"))
50
51 label_list = util.find_devs_with("LABEL=%s" % label.upper())
52 label_list.extend(util.find_devs_with("LABEL=%s" % label.lower()))
53
54 devlist = list(set(fslist) & set(label_list))
55 devlist.sort(reverse=True)
56 return devlist
57
38 def _get_data(self):58 def _get_data(self):
39 defaults = {59 defaults = {
40 "instance-id": "nocloud",60 "instance-id": "nocloud",
@@ -99,20 +119,7 @@ class DataSourceNoCloud(sources.DataSource):
99119
100 label = self.ds_cfg.get('fs_label', "cidata")120 label = self.ds_cfg.get('fs_label', "cidata")
101 if label is not None:121 if label is not None:
102 # Query optical drive to get it in blkid cache for 2.6 kernels122 for dev in self._get_devices(label):
103 util.find_devs_with(path="/dev/sr0")
104 util.find_devs_with(path="/dev/sr1")
105
106 fslist = util.find_devs_with("TYPE=vfat")
107 fslist.extend(util.find_devs_with("TYPE=iso9660"))
108
109 label_list = util.find_devs_with("LABEL=%s" % label.upper())
110 label_list.extend(util.find_devs_with("LABEL=%s" % label.lower()))
111
112 devlist = list(set(fslist) & set(label_list))
113 devlist.sort(reverse=True)
114
115 for dev in devlist:
116 try:123 try:
117 LOG.debug("Attempting to use data from %s", dev)124 LOG.debug("Attempting to use data from %s", dev)
118125
@@ -120,9 +127,8 @@ class DataSourceNoCloud(sources.DataSource):
120 seeded = util.mount_cb(dev, _pp2d_callback,127 seeded = util.mount_cb(dev, _pp2d_callback,
121 pp2d_kwargs)128 pp2d_kwargs)
122 except ValueError:129 except ValueError:
123 if dev in label_list:130 LOG.warning("device %s with label=%s not a"
124 LOG.warning("device %s with label=%s not a"131 "valid seed.", dev, label)
125 "valid seed.", dev, label)
126 continue132 continue
127133
128 mydata = _merge_new_seed(mydata, seeded)134 mydata = _merge_new_seed(mydata, seeded)
diff --git a/config/cloud.cfg.tmpl b/config/cloud.cfg.tmpl
index 25db43e..684c747 100644
--- a/config/cloud.cfg.tmpl
+++ b/config/cloud.cfg.tmpl
@@ -32,8 +32,8 @@ preserve_hostname: false
3232
33{% if variant in ["freebsd"] %}33{% if variant in ["freebsd"] %}
34# This should not be required, but leave it in place until the real cause of34# This should not be required, but leave it in place until the real cause of
35# not beeing able to find -any- datasources is resolved.35# not finding -any- datasources is resolved.
36datasource_list: ['ConfigDrive', 'Azure', 'OpenStack', 'Ec2']36datasource_list: ['NoCloud', 'ConfigDrive', 'Azure', 'OpenStack', 'Ec2']
37{% endif %}37{% endif %}
38# Example datasource config38# Example datasource config
39# datasource:39# datasource:
diff --git a/tests/unittests/test_datasource/test_nocloud.py b/tests/unittests/test_datasource/test_nocloud.py
index b785362..18bea0b 100644
--- a/tests/unittests/test_datasource/test_nocloud.py
+++ b/tests/unittests/test_datasource/test_nocloud.py
@@ -278,6 +278,24 @@ class TestNoCloudDataSource(CiTestCase):
278 self.assertEqual(netconf, dsrc.network_config)278 self.assertEqual(netconf, dsrc.network_config)
279 self.assertNotIn(gateway, str(dsrc.network_config))279 self.assertNotIn(gateway, str(dsrc.network_config))
280280
281 @mock.patch("cloudinit.util.blkid")
282 def test_nocloud_get_devices_freebsd(self, m_is_lxd, fake_blkid):
283 populate_dir(os.path.join(self.paths.seed_dir, "nocloud"),
284 {'user-data': b"ud", 'meta-data': "instance-id: IID\n"})
285
286 sys_cfg = {'datasource': {'NoCloud': {'fs_label': None}}}
287
288 self.mocks.enter_context(
289 mock.patch.object(util, 'is_FreeBSD', return_value=True))
290
291 self.mocks.enter_context(
292 mock.patch.object(os.path, 'exists', return_value=True))
293
294 dsrc = dsNoCloud(sys_cfg=sys_cfg, distro=None, paths=self.paths)
295 ret = dsrc._get_devices('foo')
296 self.assertEqual(['/dev/msdosfs/foo', '/dev/iso9660/foo'], ret)
297 fake_blkid.assert_not_called()
298
281299
282class TestParseCommandLineData(CiTestCase):300class TestParseCommandLineData(CiTestCase):
283301

Subscribers

People subscribed via source and target branches