Browse Source

Merge "lxc: make use of filter python3 compatible" into stable/stein

changes/19/679519/1
Zuul 3 weeks ago
parent
commit
a1157700dc
2 changed files with 28 additions and 5 deletions
  1. 25
    3
      nova/tests/unit/virt/disk/mount/test_nbd.py
  2. 3
    2
      nova/virt/disk/mount/nbd.py

+ 25
- 3
nova/tests/unit/virt/disk/mount/test_nbd.py View File

@@ -51,11 +51,11 @@ def _fake_exists_all_used(path):
51 51
     return ORIG_EXISTS(path)
52 52
 
53 53
 
54
-def _fake_detect_nbd_devices_none(self):
54
+def _fake_detect_nbd_devices_none():
55 55
     return []
56 56
 
57 57
 
58
-def _fake_detect_nbd_devices(self):
58
+def _fake_detect_nbd_devices():
59 59
     return ['nbd0', 'nbd1']
60 60
 
61 61
 
@@ -63,6 +63,28 @@ def _fake_noop(*args, **kwargs):
63 63
     return
64 64
 
65 65
 
66
+class NbdTestCaseNoStub(test.NoDBTestCase):
67
+
68
+    @mock.patch('os.listdir')
69
+    def test_detect_nbd_devices(self, list_dir_mock):
70
+        list_dir_mock.return_value = _fake_detect_nbd_devices()
71
+        result = nbd.NbdMount._detect_nbd_devices()
72
+        self.assertIsNotNone(result)
73
+        self.assertIsInstance(result, list)
74
+        self.assertEqual(len(list_dir_mock.return_value), len(result))
75
+        for path in list_dir_mock.return_value:
76
+            self.assertIn(path, result)
77
+
78
+    @mock.patch('os.listdir')
79
+    def test_detect_nbd_devices_empty(self, list_dir_mock):
80
+        list_dir_mock.return_value = [
81
+            "nbdz", "fake0", "not-nbd1"]
82
+        result = nbd.NbdMount._detect_nbd_devices()
83
+        self.assertIsNotNone(result)
84
+        self.assertIsInstance(result, list)
85
+        self.assertEqual(0, len(result))
86
+
87
+
66 88
 class NbdTestCase(test.NoDBTestCase):
67 89
     def setUp(self):
68 90
         super(NbdTestCase, self).setUp()
@@ -272,7 +294,7 @@ class NbdTestCase(test.NoDBTestCase):
272 294
         # they cannot choose the same nbd number (see bug 1207422)
273 295
 
274 296
         tempdir = self.useFixture(fixtures.TempDir()).path
275
-        free_devices = _fake_detect_nbd_devices(None)[:]
297
+        free_devices = _fake_detect_nbd_devices()[:]
276 298
         chosen_devices = []
277 299
 
278 300
         def fake_find_unused(self):

+ 3
- 2
nova/virt/disk/mount/nbd.py View File

@@ -39,9 +39,10 @@ class NbdMount(api.Mount):
39 39
     """qemu-nbd support disk images."""
40 40
     mode = 'nbd'
41 41
 
42
-    def _detect_nbd_devices(self):
42
+    @staticmethod
43
+    def _detect_nbd_devices():
43 44
         """Detect nbd device files."""
44
-        return filter(NBD_DEVICE_RE.match, os.listdir('/sys/block/'))
45
+        return list(filter(NBD_DEVICE_RE.match, os.listdir('/sys/block/')))
45 46
 
46 47
     def _find_unused(self, devices):
47 48
         for device in devices:

Loading…
Cancel
Save