summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHongjiang Zhang <honzhan@microsoft.com>2017-06-07 13:58:51 +0800
committerScott Moser <smoser@brickies.net>2017-06-15 15:21:22 -0400
commit8a06a1244c8ee20902db050e142c5a0b2fd777a9 (patch)
tree2df7f8f0f5870f76c52c39a9997babd9addddae7
parent977c4cf42e795e35cf4ac31b5f000736c674502e (diff)
downloadvyos-cloud-init-8a06a1244c8ee20902db050e142c5a0b2fd777a9.tar.gz
vyos-cloud-init-8a06a1244c8ee20902db050e142c5a0b2fd777a9.zip
FreeBSD: fix cdrom mounting failure if /mnt/cdrom/secure did not exist.
The current method is to attempt to mount the cdrom (/dev/cd0), if it is successful, /dev/cd0 is configured, otherwise, it is not configured. The problem is it forgets to check whether the mounting destination folder is created or not. As a result, mounting attempt failed even if cdrom is ready. LP: #1696295
-rw-r--r--cloudinit/sources/DataSourceAzure.py15
-rw-r--r--tests/unittests/test_datasource/test_azure.py12
2 files changed, 18 insertions, 9 deletions
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
index a0b9eaef..a8bad90b 100644
--- a/cloudinit/sources/DataSourceAzure.py
+++ b/cloudinit/sources/DataSourceAzure.py
@@ -799,18 +799,17 @@ def encrypt_pass(password, salt_id="$6$"):
def list_possible_azure_ds_devs():
- # return a sorted list of devices that might have a azure datasource
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:
- util.subp(["mount", "-o", "ro", "-t", "udf", cdrom_dev,
- "/mnt/cdrom/secure"])
- except util.ProcessExecutionError:
- LOG.debug("Fail to mount cd")
- return devlist
- util.subp(["umount", "/mnt/cdrom/secure"])
- devlist.append(cdrom_dev)
+ with open(cdrom_dev) as fp:
+ fp.read(1024)
+ devlist.append(cdrom_dev)
+ except IOError:
+ LOG.debug("cdrom (%s) is not configured", cdrom_dev)
else:
for fstype in ("iso9660", "udf"):
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 b17f389c..114b1a5d 100644
--- a/tests/unittests/test_datasource/test_azure.py
+++ b/tests/unittests/test_datasource/test_azure.py
@@ -7,7 +7,8 @@ from cloudinit.util import find_freebsd_part
from cloudinit.util import get_path_dev_freebsd
from ..helpers import (CiTestCase, TestCase, populate_dir, mock,
- ExitStack, PY26, SkipTest)
+ ExitStack, PY26, PY3, SkipTest)
+from mock import patch, mock_open
import crypt
import os
@@ -543,6 +544,15 @@ fdescfs /dev/fd fdescfs rw 0 0
ds.get_data()
self.assertEqual(self.instance_id, ds.metadata['instance-id'])
+ def test_list_possible_azure_ds_devs(self):
+ devlist = []
+ with patch('platform.platform',
+ mock.MagicMock(return_value="FreeBSD")):
+ name = 'builtins.open' if PY3 else '__builtin__.open'
+ with patch(name, mock_open(read_data="data")):
+ devlist.extend(dsaz.list_possible_azure_ds_devs())
+ self.assertEqual(devlist, ['/dev/cd0'])
+
class TestAzureBounce(TestCase):