summaryrefslogtreecommitdiff
path: root/cloudinit/tests
diff options
context:
space:
mode:
authorRyan Harper <ryan.harper@canonical.com>2017-09-19 11:10:09 -0500
committerScott Moser <smoser@brickies.net>2017-09-22 14:37:52 -0400
commitda6562e21d0b17a0957adc0c5a2c9da076e0d219 (patch)
treeeab4e4f20adbdd695f39af4c4e2700ed1ce59a96 /cloudinit/tests
parent79ce0a234584a50b1c6e2b664b9ccf7a5d1fca58 (diff)
downloadvyos-cloud-init-da6562e21d0b17a0957adc0c5a2c9da076e0d219.tar.gz
vyos-cloud-init-da6562e21d0b17a0957adc0c5a2c9da076e0d219.zip
DataSourceOVF: use util.find_devs_with(TYPE=iso9660)
DataSourceOVF attempts to find iso files via walking os.listdir('/dev/') which is far too wide. This approach is too invasive and can sometimes race with systemd attempting to fsck and mount devices. Instead, utilize cloudinit.util.find_devs_with to filter devices by criteria (which uses blkid under the covers). This results in fewer attempts to mount block devices which do not contain iso filesystems. Unittest changes include: - cloudinit.tests.helpers; introduce add_patch() helper - Add unittest coverage for DataSourceOVF use of transport_iso9660 LP: #1718287
Diffstat (limited to 'cloudinit/tests')
-rw-r--r--cloudinit/tests/helpers.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/cloudinit/tests/helpers.py b/cloudinit/tests/helpers.py
index 28e26622..6f88a5b7 100644
--- a/cloudinit/tests/helpers.py
+++ b/cloudinit/tests/helpers.py
@@ -104,6 +104,16 @@ class TestCase(unittest2.TestCase):
super(TestCase, self).setUp()
self.reset_global_state()
+ def add_patch(self, target, attr, **kwargs):
+ """Patches specified target object and sets it as attr on test
+ instance also schedules cleanup"""
+ if 'autospec' not in kwargs:
+ kwargs['autospec'] = True
+ m = mock.patch(target, **kwargs)
+ p = m.start()
+ self.addCleanup(m.stop)
+ setattr(self, attr, p)
+
class CiTestCase(TestCase):
"""This is the preferred test case base class unless user