~smoser/ubuntu/quantal/cloud-init/sru

« back to all changes in this revision

Viewing changes to debian/patches/lp-1100545-allow-config-drive-from-cdrom.patch

  • Committer: Scott Moser
  • Date: 2013-01-18 15:28:08 UTC
  • Revision ID: smoser@ubuntu.com-20130118152808-jy5uq9pc79t82r85
Tags: 0.7.0-0ubuntu2.3~ppa0
debian/patches/lp-1100545-allow-config-drive-from-cdrom.patch:
in config-drive data to be provided from a CD-ROM (LP: #1100545)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Author: Scott Moser <smoser@brickies.net>
 
2
Bug: https://launchpad.net/bugs/1100545
 
3
Applied-Upstream: revno 760
 
4
Description: DataSourceConfigDrive: consider CD rom as valid config-drive source.
 
5
 previously, there was an attempt in the config drive source to limit
 
6
 the source device to a "full block device" rather than a partition.
 
7
 .
 
8
 This was done by a simplistic approach of checking that the last 
 
9
 character of the name was not a number.  That was filtering out
 
10
 CD-rom devices (sr0).
 
11
 .
 
12
 Now, we have a bit more sophisticated approach to that same problem.
 
13
 We filter out block devices that have a 'partition' entry in
 
14
 /sys/class/block/DEVICE_NAME/partition .
 
15
--- a/cloudinit/sources/DataSourceConfigDrive.py
 
16
+++ b/cloudinit/sources/DataSourceConfigDrive.py
 
17
@@ -200,7 +200,7 @@ def find_candidate_devs():
 
18
     combined = (by_label + [d for d in by_fstype if d not in by_label])
 
19
 
 
20
     # We are looking for block device (sda, not sda1), ignore partitions
 
21
-    combined = [d for d in combined if d[-1] not in "0123456789"]
 
22
+    combined = [d for d in combined if not util.is_partition(d)]
 
23
 
 
24
     return combined
 
25
 
 
26
--- a/cloudinit/util.py
 
27
+++ b/cloudinit/util.py
 
28
@@ -1533,3 +1533,10 @@ def keyval_str_to_dict(kvstring):
 
29
             val = True
 
30
         ret[key] = val
 
31
     return ret
 
32
+
 
33
+
 
34
+def is_partition(device):
 
35
+    if device.startswith("/dev/"):
 
36
+        device = device[5:]
 
37
+
 
38
+    return os.path.isfile("/sys/class/block/%s/partition" % device)
 
39
--- a/tests/unittests/test_datasource/test_configdrive.py
 
40
+++ b/tests/unittests/test_datasource/test_configdrive.py
 
41
@@ -136,19 +136,25 @@ class TestConfigDriveDataSource(TestCase
 
42
                           ds.read_config_drive_dir, my_d)
 
43
 
 
44
     def test_find_candidates(self):
 
45
-        devs_with_answers = {
 
46
-            "TYPE=vfat": [],
 
47
-            "TYPE=iso9660": ["/dev/vdb"],
 
48
-            "LABEL=config-2": ["/dev/vdb"],
 
49
-        }
 
50
+        devs_with_answers = {}
 
51
 
 
52
         def my_devs_with(criteria):
 
53
             return devs_with_answers[criteria]
 
54
 
 
55
+        def my_is_partition(dev):
 
56
+            return dev[-1] in "0123456789" and not dev.startswith("sr")
 
57
+
 
58
         try:
 
59
             orig_find_devs_with = util.find_devs_with
 
60
             util.find_devs_with = my_devs_with
 
61
 
 
62
+            orig_is_partition = util.is_partition
 
63
+            util.is_partition = my_is_partition
 
64
+
 
65
+            devs_with_answers = {"TYPE=vfat": [],
 
66
+                "TYPE=iso9660": ["/dev/vdb"],
 
67
+                "LABEL=config-2": ["/dev/vdb"],
 
68
+            }
 
69
             self.assertEqual(["/dev/vdb"], ds.find_candidate_devs())
 
70
 
 
71
             # add a vfat item
 
72
@@ -164,6 +170,7 @@ class TestConfigDriveDataSource(TestCase
 
73
 
 
74
         finally:
 
75
             util.find_devs_with = orig_find_devs_with
 
76
+            util.is_partition = orig_is_partition
 
77
 
 
78
     def test_pubkeys_v2(self):
 
79
         """Verify that public-keys work in config-drive-v2."""