From 9ccb8f5e2ab262ee04bb9c103c1302479f7c81d3 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 15 Jun 2017 16:39:50 -0400 Subject: 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. --- cloudinit/sources/DataSourceAzure.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'cloudinit/sources/DataSourceAzure.py') diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py index ebb53d0a..71e7c55c 100644 --- a/cloudinit/sources/DataSourceAzure.py +++ b/cloudinit/sources/DataSourceAzure.py @@ -803,18 +803,23 @@ def encrypt_pass(password, salt_id="$6$"): return crypt.crypt(password, salt_id + util.rand_str(strlen=16)) +def _check_freebsd_cdrom(cdrom_dev): + """Return boolean indicating path to cdrom device has content.""" + try: + with open(cdrom_dev) as fp: + fp.read(1024) + return True + except IOError: + LOG.debug("cdrom (%s) is not configured", cdrom_dev) + return False + + def list_possible_azure_ds_devs(): devlist = [] if util.is_FreeBSD(): - # add '/dev/cd0' to devlist if it is configured - # here wants to test whether '/dev/cd0' is available cdrom_dev = "/dev/cd0" - try: - with open(cdrom_dev) as fp: - fp.read(1024) - devlist.append(cdrom_dev) - except IOError: - LOG.debug("cdrom (%s) is not configured", cdrom_dev) + if _check_freebsd_cdrom(cdrom_dev): + return [cdrom_dev] else: for fstype in ("iso9660", "udf"): devlist.extend(util.find_devs_with("TYPE=%s" % fstype)) -- cgit v1.2.3