Merge ~smoser/cloud-init:fix/freebsd-test-failure into cloud-init:master

Proposed by Scott Moser
Status: Merged
Merged at revision: 9ccb8f5e2ab262ee04bb9c103c1302479f7c81d3
Proposed branch: ~smoser/cloud-init:fix/freebsd-test-failure
Merge into: cloud-init:master
Diff against target: 75 lines (+24/-18)
2 files modified
cloudinit/sources/DataSourceAzure.py (+13/-8)
tests/unittests/test_datasource/test_azure.py (+11/-10)
Reviewer Review Type Date Requested Status
Chad Smith Approve
Joshua Powers (community) Approve
Ryan Harper Approve
Server Team CI bot continuous-integration Needs Fixing
Review via email: mp+325771@code.launchpad.net

Commit message

FreeBSD: fix test failure

The previous commit caused test failure.
This separates out _check_freebsd_cdrom and mocks it in a test
rather than patching open.

To post a comment you must log in.
Revision history for this message
Chad Smith (chad.smith) :
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ryan Harper (raharper) wrote :

Looks good.

review: Approve
Revision history for this message
Joshua Powers (powersj) wrote :

LGTM passes CI pipeline now.

review: Approve
Revision history for this message
Chad Smith (chad.smith) wrote :

minor nit and +1.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
2index ebb53d0..71e7c55 100644
3--- a/cloudinit/sources/DataSourceAzure.py
4+++ b/cloudinit/sources/DataSourceAzure.py
5@@ -803,18 +803,23 @@ def encrypt_pass(password, salt_id="$6$"):
6 return crypt.crypt(password, salt_id + util.rand_str(strlen=16))
7
8
9+def _check_freebsd_cdrom(cdrom_dev):
10+ """Return boolean indicating path to cdrom device has content."""
11+ try:
12+ with open(cdrom_dev) as fp:
13+ fp.read(1024)
14+ return True
15+ except IOError:
16+ LOG.debug("cdrom (%s) is not configured", cdrom_dev)
17+ return False
18+
19+
20 def list_possible_azure_ds_devs():
21 devlist = []
22 if util.is_FreeBSD():
23- # add '/dev/cd0' to devlist if it is configured
24- # here wants to test whether '/dev/cd0' is available
25 cdrom_dev = "/dev/cd0"
26- try:
27- with open(cdrom_dev) as fp:
28- fp.read(1024)
29- devlist.append(cdrom_dev)
30- except IOError:
31- LOG.debug("cdrom (%s) is not configured", cdrom_dev)
32+ if _check_freebsd_cdrom(cdrom_dev):
33+ return [cdrom_dev]
34 else:
35 for fstype in ("iso9660", "udf"):
36 devlist.extend(util.find_devs_with("TYPE=%s" % fstype))
37diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py
38index 114b1a5..7d33daf 100644
39--- a/tests/unittests/test_datasource/test_azure.py
40+++ b/tests/unittests/test_datasource/test_azure.py
41@@ -7,8 +7,7 @@ from cloudinit.util import find_freebsd_part
42 from cloudinit.util import get_path_dev_freebsd
43
44 from ..helpers import (CiTestCase, TestCase, populate_dir, mock,
45- ExitStack, PY26, PY3, SkipTest)
46-from mock import patch, mock_open
47+ ExitStack, PY26, SkipTest)
48
49 import crypt
50 import os
51@@ -544,14 +543,16 @@ fdescfs /dev/fd fdescfs rw 0 0
52 ds.get_data()
53 self.assertEqual(self.instance_id, ds.metadata['instance-id'])
54
55- def test_list_possible_azure_ds_devs(self):
56- devlist = []
57- with patch('platform.platform',
58- mock.MagicMock(return_value="FreeBSD")):
59- name = 'builtins.open' if PY3 else '__builtin__.open'
60- with patch(name, mock_open(read_data="data")):
61- devlist.extend(dsaz.list_possible_azure_ds_devs())
62- self.assertEqual(devlist, ['/dev/cd0'])
63+ @mock.patch("cloudinit.sources.DataSourceAzure.util.is_FreeBSD")
64+ @mock.patch("cloudinit.sources.DataSourceAzure._check_freebsd_cdrom")
65+ def test_list_possible_azure_ds_devs(self, m_check_fbsd_cdrom,
66+ m_is_FreeBSD):
67+ """On FreeBSD, possible devs should show /dev/cd0."""
68+ m_is_FreeBSD.return_value = True
69+ m_check_fbsd_cdrom.return_value = True
70+ self.assertEqual(dsaz.list_possible_azure_ds_devs(), ['/dev/cd0'])
71+ self.assertEqual(
72+ [mock.call("/dev/cd0")], m_check_fbsd_cdrom.call_args_list)
73
74
75 class TestAzureBounce(TestCase):

Subscribers

People subscribed via source and target branches