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
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
index ebb53d0..71e7c55 100644
--- a/cloudinit/sources/DataSourceAzure.py
+++ b/cloudinit/sources/DataSourceAzure.py
@@ -803,18 +803,23 @@ def encrypt_pass(password, salt_id="$6$"):
803 return crypt.crypt(password, salt_id + util.rand_str(strlen=16))803 return crypt.crypt(password, salt_id + util.rand_str(strlen=16))
804804
805805
806def _check_freebsd_cdrom(cdrom_dev):
807 """Return boolean indicating path to cdrom device has content."""
808 try:
809 with open(cdrom_dev) as fp:
810 fp.read(1024)
811 return True
812 except IOError:
813 LOG.debug("cdrom (%s) is not configured", cdrom_dev)
814 return False
815
816
806def list_possible_azure_ds_devs():817def list_possible_azure_ds_devs():
807 devlist = []818 devlist = []
808 if util.is_FreeBSD():819 if util.is_FreeBSD():
809 # add '/dev/cd0' to devlist if it is configured
810 # here wants to test whether '/dev/cd0' is available
811 cdrom_dev = "/dev/cd0"820 cdrom_dev = "/dev/cd0"
812 try:821 if _check_freebsd_cdrom(cdrom_dev):
813 with open(cdrom_dev) as fp:822 return [cdrom_dev]
814 fp.read(1024)
815 devlist.append(cdrom_dev)
816 except IOError:
817 LOG.debug("cdrom (%s) is not configured", cdrom_dev)
818 else:823 else:
819 for fstype in ("iso9660", "udf"):824 for fstype in ("iso9660", "udf"):
820 devlist.extend(util.find_devs_with("TYPE=%s" % fstype))825 devlist.extend(util.find_devs_with("TYPE=%s" % fstype))
diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py
index 114b1a5..7d33daf 100644
--- a/tests/unittests/test_datasource/test_azure.py
+++ b/tests/unittests/test_datasource/test_azure.py
@@ -7,8 +7,7 @@ from cloudinit.util import find_freebsd_part
7from cloudinit.util import get_path_dev_freebsd7from cloudinit.util import get_path_dev_freebsd
88
9from ..helpers import (CiTestCase, TestCase, populate_dir, mock,9from ..helpers import (CiTestCase, TestCase, populate_dir, mock,
10 ExitStack, PY26, PY3, SkipTest)10 ExitStack, PY26, SkipTest)
11from mock import patch, mock_open
1211
13import crypt12import crypt
14import os13import os
@@ -544,14 +543,16 @@ fdescfs /dev/fd fdescfs rw 0 0
544 ds.get_data()543 ds.get_data()
545 self.assertEqual(self.instance_id, ds.metadata['instance-id'])544 self.assertEqual(self.instance_id, ds.metadata['instance-id'])
546545
547 def test_list_possible_azure_ds_devs(self):546 @mock.patch("cloudinit.sources.DataSourceAzure.util.is_FreeBSD")
548 devlist = []547 @mock.patch("cloudinit.sources.DataSourceAzure._check_freebsd_cdrom")
549 with patch('platform.platform',548 def test_list_possible_azure_ds_devs(self, m_check_fbsd_cdrom,
550 mock.MagicMock(return_value="FreeBSD")):549 m_is_FreeBSD):
551 name = 'builtins.open' if PY3 else '__builtin__.open'550 """On FreeBSD, possible devs should show /dev/cd0."""
552 with patch(name, mock_open(read_data="data")):551 m_is_FreeBSD.return_value = True
553 devlist.extend(dsaz.list_possible_azure_ds_devs())552 m_check_fbsd_cdrom.return_value = True
554 self.assertEqual(devlist, ['/dev/cd0'])553 self.assertEqual(dsaz.list_possible_azure_ds_devs(), ['/dev/cd0'])
554 self.assertEqual(
555 [mock.call("/dev/cd0")], m_check_fbsd_cdrom.call_args_list)
555556
556557
557class TestAzureBounce(TestCase):558class TestAzureBounce(TestCase):

Subscribers

People subscribed via source and target branches