Merge lp:~ltrager/maas/virt_detect into lp:~maas-committers/maas/trunk
- virt_detect
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Lee Trager |
Approved revision: | no longer in the source branch. |
Merged at revision: | 5105 |
Proposed branch: | lp:~ltrager/maas/virt_detect |
Merge into: | lp:~maas-committers/maas/trunk |
Diff against target: |
166 lines (+29/-30) 5 files modified
src/metadataserver/models/commissioningscript.py (+8/-8) src/metadataserver/models/tests/test_commissioningscript.py (+8/-10) src/metadataserver/tests/test_api.py (+4/-4) src/metadataserver/tests/test_api_status.py (+1/-1) src/provisioningserver/refresh/node_info_scripts.py (+8/-7) |
To merge this branch: | bzr merge lp:~ltrager/maas/virt_detect |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Mike Pontillo (community) | Approve | ||
Review via email: mp+297020@code.launchpad.net |
Commit message
If available use systemd-detect-virt to determine if the commissioning node is virtualized
Description of the change
This modifies the virtuality script to use systemd-detect-virt if available. When systemd-detect-virt is not available(i.e commissioning with trusty) it falls back on the old method which only detects qemu. systemd-detect-virt outputs the detected virtualization which is now stored so users can review it and possibly create virt type tags later on.
Lee Trager (ltrager) wrote : | # |
Thanks for the review, I've updated up the shell script as you suggested.
Mike Pontillo (mpontillo) wrote : | # |
Looks better now.
You could still probably lose the shell redirection on the fallback grep and just use "grep -q". But I won't block you on that.
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~ltrager/maas/virt_detect into lp:maas failed. Below is the output from the failed tests.
Hit:1 http://
Get:2 http://
Get:3 http://
Hit:4 http://
Fetched 189 kB in 0s (443 kB/s)
Reading package lists...
sudo DEBIAN_
--no-
Reading package lists...
Building dependency tree...
Reading state information...
apache2 is already the newest version (2.4.18-2ubuntu3).
archdetect-deb is already the newest version (1.117ubuntu2).
authbind is already the newest version (2.1.1+nmu1).
bash is already the newest version (4.3-14ubuntu1).
build-essential is already the newest version (12.1ubuntu2).
bzr is already the newest version (2.7.0-2ubuntu1).
curl is already the newest version (7.47.0-1ubuntu2).
debhelper is already the newest version (9.20160115ubun
distro-info is already the newest version (0.14build1).
freeipmi-tools is already the newest version (1.4.11-1ubuntu1).
git is already the newest version (1:2.7.4-0ubuntu1).
isc-dhcp-common is already the newest version (4.3.3-5ubuntu12).
libjs-angularjs is already the newest version (1.2.28-1ubuntu2).
libjs-jquery is already the newest version (1.11.3+dfsg-4).
libjs-yui3-full is already the newest version (3.5.1-1ubuntu3).
libjs-yui3-min is already the newest version (3.5.1-1ubuntu3).
make is already the newest version (4.1-6).
postgresql is already the newest version (9.5+173).
pxelinux is already the newest version (3:6.03+
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~ltrager/maas/virt_detect into lp:maas failed. Below is the output from the failed tests.
Hit:1 http://
Get:2 http://
Get:3 http://
Hit:4 http://
Fetched 189 kB in 0s (433 kB/s)
Reading package lists...
sudo DEBIAN_
--no-
Reading package lists...
Building dependency tree...
Reading state information...
apache2 is already the newest version (2.4.18-2ubuntu3).
archdetect-deb is already the newest version (1.117ubuntu2).
authbind is already the newest version (2.1.1+nmu1).
bash is already the newest version (4.3-14ubuntu1).
build-essential is already the newest version (12.1ubuntu2).
bzr is already the newest version (2.7.0-2ubuntu1).
curl is already the newest version (7.47.0-1ubuntu2).
debhelper is already the newest version (9.20160115ubun
distro-info is already the newest version (0.14build1).
freeipmi-tools is already the newest version (1.4.11-1ubuntu1).
git is already the newest version (1:2.7.4-0ubuntu1).
isc-dhcp-common is already the newest version (4.3.3-5ubuntu12).
libjs-angularjs is already the newest version (1.2.28-1ubuntu2).
libjs-jquery is already the newest version (1.11.3+dfsg-4).
libjs-yui3-full is already the newest version (3.5.1-1ubuntu3).
libjs-yui3-min is already the newest version (3.5.1-1ubuntu3).
make is already the newest version (4.1-6).
postgresql is already the newest version (9.5+173).
pxelinux is already the newest version (3:6.03+
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~ltrager/maas/virt_detect into lp:maas failed. Below is the output from the failed tests.
Hit:1 http://
Get:2 http://
Hit:3 http://
Get:4 http://
Get:5 http://
Get:6 http://
Fetched 494 kB in 0s (1,166 kB/s)
Reading package lists...
sudo DEBIAN_
--no-
Reading package lists...
Building dependency tree...
Reading state information...
apache2 is already the newest version (2.4.18-2ubuntu3).
archdetect-deb is already the newest version (1.117ubuntu2).
authbind is already the newest version (2.1.1+nmu1).
bash is already the newest version (4.3-14ubuntu1).
build-essential is already the newest version (12.1ubuntu2).
bzr is already the newest version (2.7.0-2ubuntu1).
curl is already the newest version (7.47.0-1ubuntu2).
debhelper is already the newest version (9.20160115ubun
distro-info is already the newest version (0.14build1).
freeipmi-tools is already the newest version (1.4.11-1ubuntu1).
git is already the newest version (1:2.7.4-0ubuntu1).
isc-dhcp-common is already the newest version (4.3.3-5ubuntu12).
libjs-angularjs is already the newest version (1.2.28-1ubuntu2).
libjs-jquery is already the newest version (1.11.3+dfsg-4).
libjs-yui3-full is already the newest version (3.5.1-1ubuntu...
Preview Diff
1 | === modified file 'src/metadataserver/models/commissioningscript.py' | |||
2 | --- src/metadataserver/models/commissioningscript.py 2016-06-02 12:06:46 +0000 | |||
3 | +++ src/metadataserver/models/commissioningscript.py 2016-06-11 23:59:05 +0000 | |||
4 | @@ -231,7 +231,7 @@ | |||
5 | 231 | """Process the results of `VIRTUALITY_SCRIPT`. | 231 | """Process the results of `VIRTUALITY_SCRIPT`. |
6 | 232 | 232 | ||
7 | 233 | This adds or removes the *virtual* tag from the node, depending on | 233 | This adds or removes the *virtual* tag from the node, depending on |
9 | 234 | the presence of the terms "notvirtual" or "virtual" in `output`. | 234 | whether a virtualization type is listed. |
10 | 235 | 235 | ||
11 | 236 | If `exit_status` is non-zero, this function returns without doing | 236 | If `exit_status` is non-zero, this function returns without doing |
12 | 237 | anything. | 237 | anything. |
13 | @@ -239,16 +239,16 @@ | |||
14 | 239 | assert isinstance(output, bytes) | 239 | assert isinstance(output, bytes) |
15 | 240 | if exit_status != 0: | 240 | if exit_status != 0: |
16 | 241 | return | 241 | return |
17 | 242 | decoded_output = output.decode('ascii').strip() | ||
18 | 242 | tag, _ = Tag.objects.get_or_create(name='virtual') | 243 | tag, _ = Tag.objects.get_or_create(name='virtual') |
20 | 243 | if b'notvirtual' in output: | 244 | if 'none' in decoded_output: |
21 | 244 | node.tags.remove(tag) | 245 | node.tags.remove(tag) |
23 | 245 | elif b'virtual' in output: | 246 | elif decoded_output == '': |
24 | 247 | logger.warn( | ||
25 | 248 | "No virtual type reported in VIRTUALITY_SCRIPT output for node " | ||
26 | 249 | "%s", node.system_id) | ||
27 | 250 | else: | ||
28 | 246 | node.tags.add(tag) | 251 | node.tags.add(tag) |
29 | 247 | else: | ||
30 | 248 | logger.warn( | ||
31 | 249 | "Neither 'virtual' nor 'notvirtual' appeared in the " | ||
32 | 250 | "captured VIRTUALITY_SCRIPT output for node %s.", | ||
33 | 251 | node.system_id) | ||
34 | 252 | 252 | ||
35 | 253 | 253 | ||
36 | 254 | _xpath_routers = "/lldp//id[@type='mac']/text()" | 254 | _xpath_routers = "/lldp//id[@type='mac']/text()" |
37 | 255 | 255 | ||
38 | === modified file 'src/metadataserver/models/tests/test_commissioningscript.py' | |||
39 | --- src/metadataserver/models/tests/test_commissioningscript.py 2016-06-02 12:06:46 +0000 | |||
40 | +++ src/metadataserver/models/tests/test_commissioningscript.py 2016-06-11 23:59:05 +0000 | |||
41 | @@ -266,38 +266,36 @@ | |||
42 | 266 | def test_sets_virtual_tag(self): | 266 | def test_sets_virtual_tag(self): |
43 | 267 | node = factory.make_Node() | 267 | node = factory.make_Node() |
44 | 268 | self.assertTagsEqual(node, []) | 268 | self.assertTagsEqual(node, []) |
46 | 269 | set_virtual_tag(node, b"virtual", 0) | 269 | set_virtual_tag(node, b"qemu", 0) |
47 | 270 | self.assertTagsEqual(node, ["virtual"]) | 270 | self.assertTagsEqual(node, ["virtual"]) |
48 | 271 | 271 | ||
49 | 272 | def test_removes_virtual_tag(self): | 272 | def test_removes_virtual_tag(self): |
50 | 273 | node = factory.make_Node() | 273 | node = factory.make_Node() |
51 | 274 | node.tags.add(self.getVirtualTag()) | 274 | node.tags.add(self.getVirtualTag()) |
52 | 275 | self.assertTagsEqual(node, ["virtual"]) | 275 | self.assertTagsEqual(node, ["virtual"]) |
54 | 276 | set_virtual_tag(node, b"notvirtual", 0) | 276 | set_virtual_tag(node, b"none", 0) |
55 | 277 | self.assertTagsEqual(node, []) | 277 | self.assertTagsEqual(node, []) |
56 | 278 | 278 | ||
57 | 279 | def test_output_not_containing_virtual_does_not_set_tag(self): | 279 | def test_output_not_containing_virtual_does_not_set_tag(self): |
58 | 280 | logger = self.useFixture(FakeLogger()) | 280 | logger = self.useFixture(FakeLogger()) |
59 | 281 | node = factory.make_Node() | 281 | node = factory.make_Node() |
60 | 282 | self.assertTagsEqual(node, []) | 282 | self.assertTagsEqual(node, []) |
62 | 283 | set_virtual_tag(node, b"wibble", 0) | 283 | set_virtual_tag(node, b"", 0) |
63 | 284 | self.assertTagsEqual(node, []) | 284 | self.assertTagsEqual(node, []) |
64 | 285 | self.assertIn( | 285 | self.assertIn( |
68 | 286 | "Neither 'virtual' nor 'notvirtual' appeared in the captured " | 286 | "No virtual type reported in VIRTUALITY_SCRIPT output for node " |
69 | 287 | "VIRTUALITY_SCRIPT output for node %s.\n" % node.system_id, | 287 | "%s" % node.system_id, logger.output) |
67 | 288 | logger.output) | ||
70 | 289 | 288 | ||
71 | 290 | def test_output_not_containing_virtual_does_not_remove_tag(self): | 289 | def test_output_not_containing_virtual_does_not_remove_tag(self): |
72 | 291 | logger = self.useFixture(FakeLogger()) | 290 | logger = self.useFixture(FakeLogger()) |
73 | 292 | node = factory.make_Node() | 291 | node = factory.make_Node() |
74 | 293 | node.tags.add(self.getVirtualTag()) | 292 | node.tags.add(self.getVirtualTag()) |
75 | 294 | self.assertTagsEqual(node, ["virtual"]) | 293 | self.assertTagsEqual(node, ["virtual"]) |
77 | 295 | set_virtual_tag(node, b"wibble", 0) | 294 | set_virtual_tag(node, b"", 0) |
78 | 296 | self.assertTagsEqual(node, ["virtual"]) | 295 | self.assertTagsEqual(node, ["virtual"]) |
79 | 297 | self.assertIn( | 296 | self.assertIn( |
83 | 298 | "Neither 'virtual' nor 'notvirtual' appeared in the captured " | 297 | "No virtual type reported in VIRTUALITY_SCRIPT output for node " |
84 | 299 | "VIRTUALITY_SCRIPT output for node %s.\n" % node.system_id, | 298 | "%s" % node.system_id, logger.output) |
82 | 300 | logger.output) | ||
85 | 301 | 299 | ||
86 | 302 | 300 | ||
87 | 303 | class TestUpdateHardwareDetails(MAASServerTestCase): | 301 | class TestUpdateHardwareDetails(MAASServerTestCase): |
88 | 304 | 302 | ||
89 | === modified file 'src/metadataserver/tests/test_api.py' | |||
90 | --- src/metadataserver/tests/test_api.py 2016-05-24 14:53:56 +0000 | |||
91 | +++ src/metadataserver/tests/test_api.py 2016-06-11 23:59:05 +0000 | |||
92 | @@ -934,21 +934,21 @@ | |||
93 | 934 | def test_signal_stores_virtual_tag_on_node_if_virtual(self): | 934 | def test_signal_stores_virtual_tag_on_node_if_virtual(self): |
94 | 935 | node = factory.make_Node(status=NODE_STATUS.COMMISSIONING) | 935 | node = factory.make_Node(status=NODE_STATUS.COMMISSIONING) |
95 | 936 | client = make_node_client(node=node) | 936 | client = make_node_client(node=node) |
97 | 937 | content = 'virtual'.encode('utf-8') | 937 | content = 'qemu'.encode('utf-8') |
98 | 938 | response = call_signal( | 938 | response = call_signal( |
99 | 939 | client, script_result=0, | 939 | client, script_result=0, |
100 | 940 | files={'00-maas-02-virtuality.out': content}) | 940 | files={'00-maas-02-virtuality.out': content}) |
101 | 941 | self.assertEqual(http.client.OK, response.status_code) | 941 | self.assertEqual(http.client.OK, response.status_code) |
102 | 942 | node = reload_object(node) | 942 | node = reload_object(node) |
103 | 943 | self.assertEqual( | 943 | self.assertEqual( |
105 | 944 | ["virtual"], [each_tag.name for each_tag in node.tags.all()]) | 944 | ['virtual'], [each_tag.name for each_tag in node.tags.all()]) |
106 | 945 | 945 | ||
107 | 946 | def test_signal_removes_virtual_tag_on_node_if_not_virtual(self): | 946 | def test_signal_removes_virtual_tag_on_node_if_not_virtual(self): |
108 | 947 | node = factory.make_Node(status=NODE_STATUS.COMMISSIONING) | 947 | node = factory.make_Node(status=NODE_STATUS.COMMISSIONING) |
109 | 948 | tag, _ = Tag.objects.get_or_create(name='virtual') | 948 | tag, _ = Tag.objects.get_or_create(name='virtual') |
110 | 949 | node.tags.add(tag) | 949 | node.tags.add(tag) |
111 | 950 | client = make_node_client(node=node) | 950 | client = make_node_client(node=node) |
113 | 951 | content = 'notvirtual'.encode('utf-8') | 951 | content = 'none'.encode('utf-8') |
114 | 952 | response = call_signal( | 952 | response = call_signal( |
115 | 953 | client, script_result=0, | 953 | client, script_result=0, |
116 | 954 | files={'00-maas-02-virtuality.out': content}) | 954 | files={'00-maas-02-virtuality.out': content}) |
117 | @@ -960,7 +960,7 @@ | |||
118 | 960 | def test_signal_leaves_untagged_physical_node_unaltered(self): | 960 | def test_signal_leaves_untagged_physical_node_unaltered(self): |
119 | 961 | node = factory.make_Node(status=NODE_STATUS.COMMISSIONING) | 961 | node = factory.make_Node(status=NODE_STATUS.COMMISSIONING) |
120 | 962 | client = make_node_client(node=node) | 962 | client = make_node_client(node=node) |
122 | 963 | content = 'notvirtual'.encode('utf-8') | 963 | content = 'none'.encode('utf-8') |
123 | 964 | response = call_signal( | 964 | response = call_signal( |
124 | 965 | client, script_result=0, | 965 | client, script_result=0, |
125 | 966 | files={'00-maas-02-virtuality.out': content}) | 966 | files={'00-maas-02-virtuality.out': content}) |
126 | 967 | 967 | ||
127 | === modified file 'src/metadataserver/tests/test_api_status.py' | |||
128 | --- src/metadataserver/tests/test_api_status.py 2016-05-24 14:53:56 +0000 | |||
129 | +++ src/metadataserver/tests/test_api_status.py 2016-06-11 23:59:05 +0000 | |||
130 | @@ -616,7 +616,7 @@ | |||
131 | 616 | tag, _ = Tag.objects.get_or_create(name='virtual') | 616 | tag, _ = Tag.objects.get_or_create(name='virtual') |
132 | 617 | node.tags.add(tag) | 617 | node.tags.add(tag) |
133 | 618 | client = make_node_client(node=node) | 618 | client = make_node_client(node=node) |
135 | 619 | content = 'notvirtual'.encode('utf-8') | 619 | content = 'none'.encode('utf-8') |
136 | 620 | payload = { | 620 | payload = { |
137 | 621 | 'event_type': 'finish', | 621 | 'event_type': 'finish', |
138 | 622 | 'result': 'SUCCESS', | 622 | 'result': 'SUCCESS', |
139 | 623 | 623 | ||
140 | === modified file 'src/provisioningserver/refresh/node_info_scripts.py' | |||
141 | --- src/provisioningserver/refresh/node_info_scripts.py 2016-06-01 19:30:03 +0000 | |||
142 | +++ src/provisioningserver/refresh/node_info_scripts.py 2016-06-11 23:59:05 +0000 | |||
143 | @@ -70,16 +70,17 @@ | |||
144 | 70 | ip addr | 70 | ip addr |
145 | 71 | """) | 71 | """) |
146 | 72 | 72 | ||
150 | 73 | # Built-in script to detect virtual instances. It will only detect QEMU | 73 | # Built-in script to detect virtual instances. |
148 | 74 | # for now and may need expanding/generalising at some point. | ||
149 | 75 | # XXX ltrager 2016-01-14 - Replace with virt-what | ||
151 | 76 | VIRTUALITY_SCRIPT = dedent("""\ | 74 | VIRTUALITY_SCRIPT = dedent("""\ |
152 | 77 | #!/bin/sh | 75 | #!/bin/sh |
156 | 78 | grep '^model name.*QEMU.*' /proc/cpuinfo >/dev/null 2>&1 | 76 | if type systemd-detect-virt 2>&1 > /dev/null; then |
157 | 79 | if [ $? -eq 0 ]; then | 77 | systemd-detect-virt |
158 | 80 | echo "virtual" | 78 | elif grep -q '^model name.*QEMU.*' /proc/cpuinfo; then |
159 | 79 | # Fall back if systemd-detect-virt isn't available. This method only | ||
160 | 80 | # detects QEMU virtualization not including KVM. | ||
161 | 81 | echo "qemu" | ||
162 | 81 | else | 82 | else |
164 | 82 | echo "notvirtual" | 83 | echo "none" |
165 | 83 | fi | 84 | fi |
166 | 84 | """) | 85 | """) |
167 | 85 | 86 |
The python code looks okay to me, but the shell script where you detect the binary looks odd to me. I think I caught a small issue below, though I'm not certain what the behavior would be.