Merge ~adam-collard/maas:less-testtools into maas:master
- Git
- lp:~adam-collard/maas
- less-testtools
- Merge into master
Proposed by
Adam Collard
Status: | Merged |
---|---|
Approved by: | Adam Collard |
Approved revision: | 4e7ad7e674ecf182a46a255f26dca354a87e0757 |
Merge reported by: | MAAS Lander |
Merged at revision: | not available |
Proposed branch: | ~adam-collard/maas:less-testtools |
Merge into: | maas:master |
Diff against target: |
998 lines (+170/-222) 10 files modified
src/provisioningserver/drivers/hardware/tests/test_seamicro.py (+21/-37) src/provisioningserver/drivers/hardware/tests/test_ucsm.py (+40/-68) src/provisioningserver/drivers/hardware/tests/test_virsh.py (+32/-37) src/provisioningserver/drivers/hardware/tests/test_vmware.py (+32/-29) src/provisioningserver/drivers/osystem/tests/test_centos.py (+1/-3) src/provisioningserver/drivers/osystem/tests/test_esxi.py (+1/-3) src/provisioningserver/drivers/osystem/tests/test_rhel.py (+1/-3) src/provisioningserver/tests/test_monkey.py (+39/-36) src/provisioningserver/utils/tests/test_events.py (+1/-3) src/provisioningserver/utils/tests/test_text.py (+2/-3) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
MAAS Lander | Approve | ||
Anton Troyanov | Approve | ||
Review via email: mp+457042@code.launchpad.net |
Commit message
refactor(pserv/*): replace testtools' expectThat with unittest
refactor(
Description of the change
To post a comment you must log in.
Revision history for this message
Anton Troyanov (troyanov) : | # |
review:
Approve
Revision history for this message
MAAS Lander (maas-lander) wrote : | # |
UNIT TESTS
-b less-testtools lp:~adam-collard/maas/+git/maas into -b master lp:~maas-committers/maas
STATUS: SUCCESS
COMMIT: 4e7ad7e674ecf18
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/src/provisioningserver/drivers/hardware/tests/test_seamicro.py b/src/provisioningserver/drivers/hardware/tests/test_seamicro.py | |||
2 | index f06111c..0907960 100644 | |||
3 | --- a/src/provisioningserver/drivers/hardware/tests/test_seamicro.py | |||
4 | +++ b/src/provisioningserver/drivers/hardware/tests/test_seamicro.py | |||
5 | @@ -14,11 +14,6 @@ from twisted.internet.threads import deferToThread | |||
6 | 14 | 14 | ||
7 | 15 | from maastesting import get_testing_timeout | 15 | from maastesting import get_testing_timeout |
8 | 16 | from maastesting.factory import factory | 16 | from maastesting.factory import factory |
9 | 17 | from maastesting.matchers import ( | ||
10 | 18 | MockCalledOnceWith, | ||
11 | 19 | MockCalledWith, | ||
12 | 20 | MockCallsMatch, | ||
13 | 21 | ) | ||
14 | 22 | from maastesting.testcase import MAASTestCase, MAASTwistedRunTest | 17 | from maastesting.testcase import MAASTestCase, MAASTwistedRunTest |
15 | 23 | from provisioningserver.drivers.hardware import seamicro | 18 | from provisioningserver.drivers.hardware import seamicro |
16 | 24 | from provisioningserver.drivers.hardware.seamicro import ( | 19 | from provisioningserver.drivers.hardware.seamicro import ( |
17 | @@ -39,9 +34,9 @@ from provisioningserver.utils.twisted import asynchronous | |||
18 | 39 | class FakeResponse: | 34 | class FakeResponse: |
19 | 40 | def __init__(self, response_code, response, is_json=False): | 35 | def __init__(self, response_code, response, is_json=False): |
20 | 41 | self.response_code = response_code | 36 | self.response_code = response_code |
21 | 42 | self.response = response | ||
22 | 43 | if is_json: | 37 | if is_json: |
24 | 44 | self.response = json.dumps(response) | 38 | response = json.dumps(response) |
25 | 39 | self.response = response | ||
26 | 45 | 40 | ||
27 | 46 | def getcode(self): | 41 | def getcode(self): |
28 | 47 | return self.response_code | 42 | return self.response_code |
29 | @@ -163,7 +158,7 @@ class TestSeaMicroAPIV09(MAASTestCase): | |||
30 | 163 | def assert_put_power_called(self, mock, idx, new_status, *params): | 158 | def assert_put_power_called(self, mock, idx, new_status, *params): |
31 | 164 | location = "servers/%d" % idx | 159 | location = "servers/%d" % idx |
32 | 165 | params = ["action=%s" % new_status] + list(params) | 160 | params = ["action=%s" % new_status] + list(params) |
34 | 166 | self.assertThat(mock, MockCalledOnceWith(location, params=params)) | 161 | mock.assert_called_once_with(location, params=params) |
35 | 167 | 162 | ||
36 | 168 | def test_put_server_power_on_using_pxe(self): | 163 | def test_put_server_power_on_using_pxe(self): |
37 | 169 | token = factory.make_string() | 164 | token = factory.make_string() |
38 | @@ -251,12 +246,11 @@ class TestSeaMicro(MAASTestCase): | |||
39 | 251 | password, | 246 | password, |
40 | 252 | "ipmi", | 247 | "ipmi", |
41 | 253 | ) | 248 | ) |
45 | 254 | self.assertThat( | 249 | mock.assert_has_calls( |
46 | 255 | mock, | 250 | [ |
44 | 256 | MockCallsMatch( | ||
47 | 257 | call("v2.0", ip, username, password), | 251 | call("v2.0", ip, username, password), |
48 | 258 | call("v0.9", ip, username, password), | 252 | call("v0.9", ip, username, password), |
50 | 259 | ), | 253 | ] |
51 | 260 | ) | 254 | ) |
52 | 261 | 255 | ||
53 | 262 | def test_find_seamicro15k_servers_restapi(self): | 256 | def test_find_seamicro15k_servers_restapi(self): |
54 | @@ -269,9 +263,7 @@ class TestSeaMicro(MAASTestCase): | |||
55 | 269 | password, | 263 | password, |
56 | 270 | "restapi", | 264 | "restapi", |
57 | 271 | ) | 265 | ) |
61 | 272 | self.assertThat( | 266 | mock.assert_called_once_with("v0.9", ip, username, password) |
59 | 273 | mock, MockCalledOnceWith("v0.9", ip, username, password) | ||
60 | 274 | ) | ||
62 | 275 | 267 | ||
63 | 276 | def test_find_seamicro15k_servers_restapi2(self): | 268 | def test_find_seamicro15k_servers_restapi2(self): |
64 | 277 | mock, ip, username, password = self.configure_get_seamicro15k_api() | 269 | mock, ip, username, password = self.configure_get_seamicro15k_api() |
65 | @@ -283,9 +275,7 @@ class TestSeaMicro(MAASTestCase): | |||
66 | 283 | password, | 275 | password, |
67 | 284 | "restapi2", | 276 | "restapi2", |
68 | 285 | ) | 277 | ) |
72 | 286 | self.assertThat( | 278 | mock.assert_called_once_with("v2.0", ip, username, password) |
70 | 287 | mock, MockCalledOnceWith("v2.0", ip, username, password) | ||
71 | 288 | ) | ||
73 | 289 | 279 | ||
74 | 290 | def configure_api_v09_login(self, token=None): | 280 | def configure_api_v09_login(self, token=None): |
75 | 291 | token = token or factory.make_string() | 281 | token = token or factory.make_string() |
76 | @@ -349,17 +339,14 @@ class TestSeaMicro(MAASTestCase): | |||
77 | 349 | "power_pass": password, | 339 | "power_pass": password, |
78 | 350 | "power_user": username, | 340 | "power_user": username, |
79 | 351 | } | 341 | } |
89 | 352 | self.expectThat( | 342 | mock_create_node.assert_called_with( |
90 | 353 | mock_create_node, | 343 | last["serverMacAddr"], |
91 | 354 | MockCalledWith( | 344 | "amd64", |
92 | 355 | last["serverMacAddr"], | 345 | "sm15k", |
93 | 356 | "amd64", | 346 | power_params, |
94 | 357 | "sm15k", | 347 | domain=domain, |
86 | 358 | power_params, | ||
87 | 359 | domain=domain, | ||
88 | 360 | ), | ||
95 | 361 | ) | 348 | ) |
97 | 362 | self.expectThat(mock_commission_node, MockCalledWith(system_id, user)) | 349 | mock_commission_node.assert_called_with(system_id, user) |
98 | 363 | 350 | ||
99 | 364 | def test_power_control_seamicro15k_v09(self): | 351 | def test_power_control_seamicro15k_v09(self): |
100 | 365 | self.configure_api_v09_login() | 352 | self.configure_api_v09_login() |
101 | @@ -369,9 +356,7 @@ class TestSeaMicro(MAASTestCase): | |||
102 | 369 | mock = self.patch(SeaMicroAPIV09, "power_server") | 356 | mock = self.patch(SeaMicroAPIV09, "power_server") |
103 | 370 | 357 | ||
104 | 371 | power_control_seamicro15k_v09(ip, username, password, "25", "on") | 358 | power_control_seamicro15k_v09(ip, username, password, "25", "on") |
108 | 372 | self.assertThat( | 359 | mock.assert_called_once_with("25/0", POWER_STATUS.ON, do_pxe=True) |
106 | 373 | mock, MockCalledOnceWith("25/0", POWER_STATUS.ON, do_pxe=True) | ||
107 | 374 | ) | ||
109 | 375 | 360 | ||
110 | 376 | def test_power_control_seamicro15k_v09_retry_failure(self): | 361 | def test_power_control_seamicro15k_v09_retry_failure(self): |
111 | 377 | self.configure_api_v09_login() | 362 | self.configure_api_v09_login() |
112 | @@ -439,9 +424,8 @@ class TestSeaMicro(MAASTestCase): | |||
113 | 439 | ) | 424 | ) |
114 | 440 | self.assertEqual(2, mock_create_node.call_count) | 425 | self.assertEqual(2, mock_create_node.call_count) |
115 | 441 | 426 | ||
119 | 442 | self.expectThat( | 427 | mock_create_node.assert_has_calls( |
120 | 443 | mock_create_node, | 428 | [ |
118 | 444 | MockCallsMatch( | ||
121 | 445 | call( | 429 | call( |
122 | 446 | fake_server_0.get_fake_macs(), | 430 | fake_server_0.get_fake_macs(), |
123 | 447 | "amd64", | 431 | "amd64", |
124 | @@ -468,9 +452,9 @@ class TestSeaMicro(MAASTestCase): | |||
125 | 468 | }, | 452 | }, |
126 | 469 | domain=None, | 453 | domain=None, |
127 | 470 | ), | 454 | ), |
129 | 471 | ), | 455 | ] |
130 | 472 | ) | 456 | ) |
132 | 473 | self.expectThat(mock_commission_node, MockCalledWith(system_id, user)) | 457 | mock_commission_node.assert_called_with(system_id, user) |
133 | 474 | 458 | ||
134 | 475 | def test_power_control_seamicro15k_v2(self): | 459 | def test_power_control_seamicro15k_v2(self): |
135 | 476 | ip = factory.make_ipv4_address() | 460 | ip = factory.make_ipv4_address() |
136 | @@ -487,7 +471,7 @@ class TestSeaMicro(MAASTestCase): | |||
137 | 487 | mock_get_api.return_value = fake_client | 471 | mock_get_api.return_value = fake_client |
138 | 488 | 472 | ||
139 | 489 | power_control_seamicro15k_v2(ip, username, password, "0", "on") | 473 | power_control_seamicro15k_v2(ip, username, password, "0", "on") |
141 | 490 | self.assertThat(mock_power_on, MockCalledOnceWith(using_pxe=True)) | 474 | mock_power_on.assert_called_once_with(using_pxe=True) |
142 | 491 | 475 | ||
143 | 492 | def test_power_control_seamicro15k_v2_raises_error_when_api_None(self): | 476 | def test_power_control_seamicro15k_v2_raises_error_when_api_None(self): |
144 | 493 | ip = factory.make_ipv4_address() | 477 | ip = factory.make_ipv4_address() |
145 | diff --git a/src/provisioningserver/drivers/hardware/tests/test_ucsm.py b/src/provisioningserver/drivers/hardware/tests/test_ucsm.py | |||
146 | index ebac33b..87f6a16 100644 | |||
147 | --- a/src/provisioningserver/drivers/hardware/tests/test_ucsm.py | |||
148 | +++ b/src/provisioningserver/drivers/hardware/tests/test_ucsm.py | |||
149 | @@ -10,17 +10,11 @@ import urllib.parse | |||
150 | 10 | import urllib.request | 10 | import urllib.request |
151 | 11 | 11 | ||
152 | 12 | from lxml.etree import Element, SubElement, XML | 12 | from lxml.etree import Element, SubElement, XML |
153 | 13 | from testtools.matchers import Equals | ||
154 | 14 | from twisted.internet.defer import inlineCallbacks | 13 | from twisted.internet.defer import inlineCallbacks |
155 | 15 | from twisted.internet.threads import deferToThread | 14 | from twisted.internet.threads import deferToThread |
156 | 16 | 15 | ||
157 | 17 | from maastesting import get_testing_timeout | 16 | from maastesting import get_testing_timeout |
158 | 18 | from maastesting.factory import factory | 17 | from maastesting.factory import factory |
159 | 19 | from maastesting.matchers import ( | ||
160 | 20 | MockCalledOnceWith, | ||
161 | 21 | MockCallsMatch, | ||
162 | 22 | MockNotCalled, | ||
163 | 23 | ) | ||
164 | 24 | from maastesting.testcase import MAASTestCase, MAASTwistedRunTest | 18 | from maastesting.testcase import MAASTestCase, MAASTwistedRunTest |
165 | 25 | from provisioningserver.drivers.hardware import ucsm | 19 | from provisioningserver.drivers.hardware import ucsm |
166 | 26 | from provisioningserver.drivers.hardware.ucsm import ( | 20 | from provisioningserver.drivers.hardware.ucsm import ( |
167 | @@ -142,7 +136,7 @@ class TestLogin(MAASTestCase): | |||
168 | 142 | api, mock = make_api_patch_call(self, user=user, password=password) | 136 | api, mock = make_api_patch_call(self, user=user, password=password) |
169 | 143 | api.login() | 137 | api.login() |
170 | 144 | fields = {"inName": user, "inPassword": password} | 138 | fields = {"inName": user, "inPassword": password} |
172 | 145 | self.assertThat(mock, MockCalledOnceWith("aaaLogin", fields)) | 139 | mock.assert_called_once_with("aaaLogin", fields) |
173 | 146 | 140 | ||
174 | 147 | 141 | ||
175 | 148 | class TestLogout(MAASTestCase): | 142 | class TestLogout(MAASTestCase): |
176 | @@ -157,7 +151,7 @@ class TestLogout(MAASTestCase): | |||
177 | 157 | cookie = api.cookie | 151 | cookie = api.cookie |
178 | 158 | api.logout() | 152 | api.logout() |
179 | 159 | fields = {"inCookie": cookie} | 153 | fields = {"inCookie": cookie} |
181 | 160 | self.assertThat(mock, MockCalledOnceWith("aaaLogout", fields)) | 154 | mock.assert_called_once_with("aaaLogout", fields) |
182 | 161 | 155 | ||
183 | 162 | 156 | ||
184 | 163 | class TestConfigResolveClass(MAASTestCase): | 157 | class TestConfigResolveClass(MAASTestCase): |
185 | @@ -166,9 +160,7 @@ class TestConfigResolveClass(MAASTestCase): | |||
186 | 166 | api, mock = make_api_patch_call(self) | 160 | api, mock = make_api_patch_call(self) |
187 | 167 | api.config_resolve_class(class_id) | 161 | api.config_resolve_class(class_id) |
188 | 168 | fields = {"cookie": api.cookie, "classId": class_id} | 162 | fields = {"cookie": api.cookie, "classId": class_id} |
192 | 169 | self.assertThat( | 163 | mock.assert_called_once_with("configResolveClass", fields, ANY) |
190 | 170 | mock, MockCalledOnceWith("configResolveClass", fields, ANY) | ||
191 | 171 | ) | ||
193 | 172 | 164 | ||
194 | 173 | def test_with_filters(self): | 165 | def test_with_filters(self): |
195 | 174 | class_id = make_class() | 166 | class_id = make_class() |
196 | @@ -192,18 +184,14 @@ class TestConfigResolveChildren(MAASTestCase): | |||
197 | 192 | api, mock = make_api_patch_call(self) | 184 | api, mock = make_api_patch_call(self) |
198 | 193 | api.config_resolve_children(dn, class_id) | 185 | api.config_resolve_children(dn, class_id) |
199 | 194 | fields = {"inDn": dn, "classId": class_id, "cookie": api.cookie} | 186 | fields = {"inDn": dn, "classId": class_id, "cookie": api.cookie} |
203 | 195 | self.assertThat( | 187 | mock.assert_called_once_with("configResolveChildren", fields) |
201 | 196 | mock, MockCalledOnceWith("configResolveChildren", fields) | ||
202 | 197 | ) | ||
204 | 198 | 188 | ||
205 | 199 | def test_no_class_id(self): | 189 | def test_no_class_id(self): |
206 | 200 | dn = make_dn() | 190 | dn = make_dn() |
207 | 201 | api, mock = make_api_patch_call(self) | 191 | api, mock = make_api_patch_call(self) |
208 | 202 | api.config_resolve_children(dn) | 192 | api.config_resolve_children(dn) |
209 | 203 | fields = {"inDn": dn, "cookie": api.cookie} | 193 | fields = {"inDn": dn, "cookie": api.cookie} |
213 | 204 | self.assertThat( | 194 | mock.assert_called_once_with("configResolveChildren", fields) |
211 | 205 | mock, MockCalledOnceWith("configResolveChildren", fields) | ||
212 | 206 | ) | ||
214 | 207 | 195 | ||
215 | 208 | def test_return_response(self): | 196 | def test_return_response(self): |
216 | 209 | api, mock = make_api_patch_call(self) | 197 | api, mock = make_api_patch_call(self) |
217 | @@ -219,7 +207,7 @@ class TestConfigConfMo(MAASTestCase): | |||
218 | 219 | api, mock = make_api_patch_call(self) | 207 | api, mock = make_api_patch_call(self) |
219 | 220 | api.config_conf_mo(dn, config_items) | 208 | api.config_conf_mo(dn, config_items) |
220 | 221 | fields = {"dn": dn, "cookie": api.cookie} | 209 | fields = {"dn": dn, "cookie": api.cookie} |
222 | 222 | self.assertThat(mock, MockCalledOnceWith("configConfMo", fields, ANY)) | 210 | mock.assert_called_once_with("configConfMo", fields, ANY) |
223 | 223 | in_configs = mock.call_args[0][2] | 211 | in_configs = mock.call_args[0][2] |
224 | 224 | self.assertEqual(config_items, in_configs[0][:]) | 212 | self.assertEqual(config_items, in_configs[0][:]) |
225 | 225 | 213 | ||
226 | @@ -240,10 +228,8 @@ class TestCall(MAASTestCase): | |||
227 | 240 | mock_send_request.return_value = response | 228 | mock_send_request.return_value = response |
228 | 241 | 229 | ||
229 | 242 | api._call(name, fields, children) | 230 | api._call(name, fields, children) |
234 | 243 | self.assertThat( | 231 | mock_make_request_data.assert_called_once_with(name, fields, children) |
235 | 244 | mock_make_request_data, MockCalledOnceWith(name, fields, children) | 232 | mock_send_request.assert_called_once_with(request) |
232 | 245 | ) | ||
233 | 246 | self.assertThat(mock_send_request, MockCalledOnceWith(request)) | ||
236 | 247 | 233 | ||
237 | 248 | 234 | ||
238 | 249 | class TestSendRequest(MAASTestCase): | 235 | class TestSendRequest(MAASTestCase): |
239 | @@ -266,7 +252,7 @@ class TestConfigResolveDn(MAASTestCase): | |||
240 | 266 | test_dn = make_dn() | 252 | test_dn = make_dn() |
241 | 267 | fields = {"cookie": api.cookie, "dn": test_dn} | 253 | fields = {"cookie": api.cookie, "dn": test_dn} |
242 | 268 | api.config_resolve_dn(test_dn) | 254 | api.config_resolve_dn(test_dn) |
244 | 269 | self.assertThat(mock, MockCalledOnceWith("configResolveDn", fields)) | 255 | mock.assert_called_once_with("configResolveDn", fields) |
245 | 270 | 256 | ||
246 | 271 | 257 | ||
247 | 272 | class TestGetServers(MAASTestCase): | 258 | class TestGetServers(MAASTestCase): |
248 | @@ -292,7 +278,7 @@ class TestGetServers(MAASTestCase): | |||
249 | 292 | api = make_api() | 278 | api = make_api() |
250 | 293 | mock = self.patch(api, "config_resolve_class") | 279 | mock = self.patch(api, "config_resolve_class") |
251 | 294 | get_servers(api, uuid) | 280 | get_servers(api, uuid) |
253 | 295 | self.assertThat(mock, MockCalledOnceWith("computeItem", ANY)) | 281 | mock.assert_called_once_with("computeItem", ANY) |
254 | 296 | 282 | ||
255 | 297 | 283 | ||
256 | 298 | class TestProbeLanBootOptions(MAASTestCase): | 284 | class TestProbeLanBootOptions(MAASTestCase): |
257 | @@ -309,16 +295,11 @@ class TestProbeLanBootOptions(MAASTestCase): | |||
258 | 309 | ) | 295 | ) |
259 | 310 | mock_config_resolve_children.return_value = fake_result | 296 | mock_config_resolve_children.return_value = fake_result |
260 | 311 | self.assertEqual(1, len(probe_lan_boot_options(api, server))) | 297 | self.assertEqual(1, len(probe_lan_boot_options(api, server))) |
270 | 312 | self.assertThat( | 298 | mock_config_resolve_children.assert_called_once_with( |
271 | 313 | mock_config_resolve_children, | 299 | sentinel.profile_get |
263 | 314 | MockCalledOnceWith(sentinel.profile_get), | ||
264 | 315 | ) | ||
265 | 316 | self.assertThat( | ||
266 | 317 | mock_service_profile.get, MockCalledOnceWith("operBootPolicyName") | ||
267 | 318 | ) | ||
268 | 319 | self.assertThat( | ||
269 | 320 | mock_get_service_profile, MockCalledOnceWith(api, server) | ||
272 | 321 | ) | 300 | ) |
273 | 301 | mock_service_profile.get.assert_called_once_with("operBootPolicyName") | ||
274 | 302 | mock_get_service_profile.assert_called_once_with(api, server) | ||
275 | 322 | 303 | ||
276 | 323 | 304 | ||
277 | 324 | class TestGetChildren(MAASTestCase): | 305 | class TestGetChildren(MAASTestCase): |
278 | @@ -340,7 +321,7 @@ class TestGetChildren(MAASTestCase): | |||
279 | 340 | in_element = Element("test", {"dn": parent_dn}) | 321 | in_element = Element("test", {"dn": parent_dn}) |
280 | 341 | class_id = search_class | 322 | class_id = search_class |
281 | 342 | get_children(api, in_element, class_id) | 323 | get_children(api, in_element, class_id) |
283 | 343 | self.assertThat(mock, MockCalledOnceWith(parent_dn, search_class)) | 324 | mock.assert_called_once_with(parent_dn, search_class) |
284 | 344 | 325 | ||
285 | 345 | 326 | ||
286 | 346 | class TestGetMacs(MAASTestCase): | 327 | class TestGetMacs(MAASTestCase): |
287 | @@ -359,12 +340,11 @@ class TestGetMacs(MAASTestCase): | |||
288 | 359 | 340 | ||
289 | 360 | mock.side_effect = fake_get_children | 341 | mock.side_effect = fake_get_children |
290 | 361 | macs = get_macs(api, server) | 342 | macs = get_macs(api, server) |
294 | 362 | self.assertThat( | 343 | mock.assert_has_calls( |
295 | 363 | mock, | 344 | [ |
293 | 364 | MockCallsMatch( | ||
296 | 365 | call(api, server, "adaptorUnit"), | 345 | call(api, server, "adaptorUnit"), |
297 | 366 | call(api, adaptor, "adaptorHostEthIf"), | 346 | call(api, adaptor, "adaptorHostEthIf"), |
299 | 367 | ), | 347 | ] |
300 | 368 | ) | 348 | ) |
301 | 369 | self.assertEqual([mac], macs) | 349 | self.assertEqual([mac], macs) |
302 | 370 | 350 | ||
303 | @@ -374,7 +354,7 @@ class TestProbeServers(MAASTestCase): | |||
304 | 374 | api = make_api() | 354 | api = make_api() |
305 | 375 | mock = self.patch(ucsm, "get_servers") | 355 | mock = self.patch(ucsm, "get_servers") |
306 | 376 | probe_servers(api) | 356 | probe_servers(api) |
308 | 377 | self.assertThat(mock, MockCalledOnceWith(api)) | 357 | mock.assert_called_once_with(api) |
309 | 378 | 358 | ||
310 | 379 | def test_returns_results(self): | 359 | def test_returns_results(self): |
311 | 380 | servers = [{"uuid": factory.make_UUID()}] | 360 | servers = [{"uuid": factory.make_UUID()}] |
312 | @@ -415,7 +395,7 @@ class TestGetServerPowerControl(MAASTestCase): | |||
313 | 415 | dn = make_dn() | 395 | dn = make_dn() |
314 | 416 | server = Element("computeItem", {"assignedToDn": dn}) | 396 | server = Element("computeItem", {"assignedToDn": dn}) |
315 | 417 | power_control = get_server_power_control(api, server) | 397 | power_control = get_server_power_control(api, server) |
317 | 418 | self.assertThat(mock, MockCalledOnceWith(dn, "lsPower")) | 398 | mock.assert_called_once_with(dn, "lsPower") |
318 | 419 | self.assertEqual("lsPower", power_control.tag) | 399 | self.assertEqual("lsPower", power_control.tag) |
319 | 420 | 400 | ||
320 | 421 | 401 | ||
321 | @@ -427,7 +407,7 @@ class TestSetServerPowerControl(MAASTestCase): | |||
322 | 427 | config_conf_mo_mock = self.patch(api, "config_conf_mo") | 407 | config_conf_mo_mock = self.patch(api, "config_conf_mo") |
323 | 428 | state = "state" | 408 | state = "state" |
324 | 429 | set_server_power_control(api, power_control, state) | 409 | set_server_power_control(api, power_control, state) |
326 | 430 | self.assertThat(config_conf_mo_mock, MockCalledOnceWith(power_dn, ANY)) | 410 | config_conf_mo_mock.assert_called_once_with(power_dn, ANY) |
327 | 431 | power_change = config_conf_mo_mock.call_args[0][1][0] | 411 | power_change = config_conf_mo_mock.call_args[0][1][0] |
328 | 432 | self.assertEqual(power_change.tag, "lsPower") | 412 | self.assertEqual(power_change.tag, "lsPower") |
329 | 433 | self.assertEqual({"state": state, "dn": power_dn}, power_change.attrib) | 413 | self.assertEqual({"state": state, "dn": power_dn}, power_change.attrib) |
330 | @@ -443,9 +423,9 @@ class TestLoggedIn(MAASTestCase): | |||
331 | 443 | 423 | ||
332 | 444 | with logged_in(url, username, password) as api: | 424 | with logged_in(url, username, password) as api: |
333 | 445 | self.assertEqual(mock.return_value, api) | 425 | self.assertEqual(mock.return_value, api) |
335 | 446 | self.assertThat(api.login, MockCalledOnceWith()) | 426 | api.login() |
336 | 447 | 427 | ||
338 | 448 | self.assertThat(mock.return_value.logout, MockCalledOnceWith()) | 428 | mock.return_value.logout.assert_called_once_with() |
339 | 449 | 429 | ||
340 | 450 | 430 | ||
341 | 451 | class TestValidGetPowerCommand(MAASTestCase): | 431 | class TestValidGetPowerCommand(MAASTestCase): |
342 | @@ -498,10 +478,9 @@ class TestPowerControlUCSM(MAASTestCase): | |||
343 | 498 | ucsm, "set_server_power_control" | 478 | ucsm, "set_server_power_control" |
344 | 499 | ) | 479 | ) |
345 | 500 | power_control_ucsm("url", "username", "password", uuid, "off") | 480 | power_control_ucsm("url", "username", "password", uuid, "off") |
350 | 501 | self.assertThat(get_servers_mock, MockCalledOnceWith(api, uuid)) | 481 | get_servers_mock.assert_called_once_with(api, uuid) |
351 | 502 | self.assertThat( | 482 | set_server_power_control_mock.assert_called_once_with( |
352 | 503 | set_server_power_control_mock, | 483 | api, power_control, state |
349 | 504 | MockCalledOnceWith(api, power_control, state), | ||
353 | 505 | ) | 484 | ) |
354 | 506 | 485 | ||
355 | 507 | 486 | ||
356 | @@ -517,8 +496,8 @@ class TestUCSMPowerState(MAASTestCase): | |||
357 | 517 | get_servers_mock.return_value = [make_server("off")] | 496 | get_servers_mock.return_value = [make_server("off")] |
358 | 518 | 497 | ||
359 | 519 | power_state = power_state_ucsm(url, username, password, uuid) | 498 | power_state = power_state_ucsm(url, username, password, uuid) |
362 | 520 | self.expectThat(get_servers_mock, MockCalledOnceWith(api, uuid)) | 499 | get_servers_mock.assert_called_once_with(api, uuid) |
363 | 521 | self.expectThat(power_state, Equals("off")) | 500 | self.assertEqual(power_state, "off") |
364 | 522 | 501 | ||
365 | 523 | def test_power_state_get_on(self): | 502 | def test_power_state_get_on(self): |
366 | 524 | url = factory.make_name("url") | 503 | url = factory.make_name("url") |
367 | @@ -531,8 +510,8 @@ class TestUCSMPowerState(MAASTestCase): | |||
368 | 531 | get_servers_mock.return_value = [make_server("on")] | 510 | get_servers_mock.return_value = [make_server("on")] |
369 | 532 | 511 | ||
370 | 533 | power_state = power_state_ucsm(url, username, password, uuid) | 512 | power_state = power_state_ucsm(url, username, password, uuid) |
373 | 534 | self.expectThat(get_servers_mock, MockCalledOnceWith(api, uuid)) | 513 | get_servers_mock.assert_called_once_with(api, uuid) |
374 | 535 | self.expectThat(power_state, Equals("on")) | 514 | self.assertEqual(power_state, "on") |
375 | 536 | 515 | ||
376 | 537 | def test_power_state_error_on_unknown_state(self): | 516 | def test_power_state_error_on_unknown_state(self): |
377 | 538 | url = factory.make_name("url") | 517 | url = factory.make_name("url") |
378 | @@ -576,23 +555,18 @@ class TestProbeAndEnlistUCSM(MAASTestCase): | |||
379 | 576 | yield deferToThread( | 555 | yield deferToThread( |
380 | 577 | probe_and_enlist_ucsm, user, url, username, password, True, domain | 556 | probe_and_enlist_ucsm, user, url, username, password, True, domain |
381 | 578 | ) | 557 | ) |
386 | 579 | self.expectThat( | 558 | set_lan_boot_default_mock.assert_called_once_with(api, server_element) |
387 | 580 | set_lan_boot_default_mock, MockCalledOnceWith(api, server_element) | 559 | probe_servers_mock.assert_called_once_with(api) |
384 | 581 | ) | ||
385 | 582 | self.expectThat(probe_servers_mock, MockCalledOnceWith(api)) | ||
388 | 583 | params = { | 560 | params = { |
389 | 584 | "power_address": url, | 561 | "power_address": url, |
390 | 585 | "power_user": username, | 562 | "power_user": username, |
391 | 586 | "power_pass": password, | 563 | "power_pass": password, |
392 | 587 | "uuid": server[0]["uuid"], | 564 | "uuid": server[0]["uuid"], |
393 | 588 | } | 565 | } |
400 | 589 | self.expectThat( | 566 | create_node_mock.assert_called_once_with( |
401 | 590 | create_node_mock, | 567 | server[1], "amd64", "ucsm", params, domain |
396 | 591 | MockCalledOnceWith(server[1], "amd64", "ucsm", params, domain), | ||
397 | 592 | ) | ||
398 | 593 | self.expectThat( | ||
399 | 594 | commission_node_mock, MockCalledOnceWith(system_id, user) | ||
402 | 595 | ) | 568 | ) |
403 | 569 | commission_node_mock.assert_called_once_with(system_id, user) | ||
404 | 596 | 570 | ||
405 | 597 | 571 | ||
406 | 598 | class TestGetServiceProfile(MAASTestCase): | 572 | class TestGetServiceProfile(MAASTestCase): |
407 | @@ -605,7 +579,7 @@ class TestGetServiceProfile(MAASTestCase): | |||
408 | 605 | "configResolveDn", "lsServer", "outConfig" | 579 | "configResolveDn", "lsServer", "outConfig" |
409 | 606 | ) | 580 | ) |
410 | 607 | service_profile = get_service_profile(api, server) | 581 | service_profile = get_service_profile(api, server) |
412 | 608 | self.assertThat(mock, MockCalledOnceWith(test_dn)) | 582 | mock.assert_called_once_with(test_dn) |
413 | 609 | self.assertEqual(mock.return_value[0], service_profile) | 583 | self.assertEqual(mock.return_value[0], service_profile) |
414 | 610 | 584 | ||
415 | 611 | 585 | ||
416 | @@ -646,7 +620,7 @@ class TestsForStripRoKeys(MAASTestCase): | |||
417 | 646 | attributes = {key: "DC" for key in RO_KEYS} | 620 | attributes = {key: "DC" for key in RO_KEYS} |
418 | 647 | 621 | ||
419 | 648 | elements = [ | 622 | elements = [ |
421 | 649 | Element("Element%d" % i, attributes) | 623 | Element(f"Element{i}", attributes) |
422 | 650 | for i in range(random.randint(0, 10)) | 624 | for i in range(random.randint(0, 10)) |
423 | 651 | ] | 625 | ] |
424 | 652 | 626 | ||
425 | @@ -667,7 +641,7 @@ class TestMakePolicyChange(MAASTestCase): | |||
426 | 667 | mock.return_value = boot_profile_response[0] | 641 | mock.return_value = boot_profile_response[0] |
427 | 668 | change = make_policy_change(boot_profile_response) | 642 | change = make_policy_change(boot_profile_response) |
428 | 669 | self.assertIsNone(change) | 643 | self.assertIsNone(change) |
430 | 670 | self.assertThat(mock, MockCalledOnceWith(boot_profile_response)) | 644 | mock.assert_called_once_with(boot_profile_response) |
431 | 671 | 645 | ||
432 | 672 | def test_change_lan_to_top_priority(self): | 646 | def test_change_lan_to_top_priority(self): |
433 | 673 | boot_profile_response = Element("outConfigs") | 647 | boot_profile_response = Element("outConfigs") |
434 | @@ -694,7 +668,7 @@ class TestSetLanBootDefault(MAASTestCase): | |||
435 | 694 | self.patch(ucsm, "make_policy_change").return_value = None | 668 | self.patch(ucsm, "make_policy_change").return_value = None |
436 | 695 | config_conf_mo = self.patch(api, "config_conf_mo") | 669 | config_conf_mo = self.patch(api, "config_conf_mo") |
437 | 696 | set_lan_boot_default(api, server) | 670 | set_lan_boot_default(api, server) |
439 | 697 | self.assertThat(config_conf_mo, MockNotCalled()) | 671 | config_conf_mo.assert_not_called() |
440 | 698 | 672 | ||
441 | 699 | def test_with_change(self): | 673 | def test_with_change(self): |
442 | 700 | api = make_api() | 674 | api = make_api() |
443 | @@ -707,6 +681,4 @@ class TestSetLanBootDefault(MAASTestCase): | |||
444 | 707 | self.patch(ucsm, "make_policy_change").return_value = test_change | 681 | self.patch(ucsm, "make_policy_change").return_value = test_change |
445 | 708 | config_conf_mo = self.patch(api, "config_conf_mo") | 682 | config_conf_mo = self.patch(api, "config_conf_mo") |
446 | 709 | set_lan_boot_default(api, server) | 683 | set_lan_boot_default(api, server) |
450 | 710 | self.assertThat( | 684 | config_conf_mo.assert_called_once_with(test_dn, [test_change]) |
448 | 711 | config_conf_mo, MockCalledOnceWith(test_dn, [test_change]) | ||
449 | 712 | ) | ||
451 | diff --git a/src/provisioningserver/drivers/hardware/tests/test_virsh.py b/src/provisioningserver/drivers/hardware/tests/test_virsh.py | |||
452 | index 0711efa..5c124a0 100644 | |||
453 | --- a/src/provisioningserver/drivers/hardware/tests/test_virsh.py | |||
454 | +++ b/src/provisioningserver/drivers/hardware/tests/test_virsh.py | |||
455 | @@ -11,13 +11,11 @@ from unittest.mock import call | |||
456 | 11 | 11 | ||
457 | 12 | from lxml import etree | 12 | from lxml import etree |
458 | 13 | import pexpect | 13 | import pexpect |
459 | 14 | from testtools.testcase import ExpectedException | ||
460 | 15 | from twisted.internet.defer import inlineCallbacks | 14 | from twisted.internet.defer import inlineCallbacks |
461 | 16 | from twisted.internet.threads import deferToThread | 15 | from twisted.internet.threads import deferToThread |
462 | 17 | 16 | ||
463 | 18 | from maastesting import get_testing_timeout | 17 | from maastesting import get_testing_timeout |
464 | 19 | from maastesting.factory import factory | 18 | from maastesting.factory import factory |
465 | 20 | from maastesting.matchers import MockCalledOnceWith, MockCallsMatch | ||
466 | 21 | from maastesting.testcase import MAASTestCase, MAASTwistedRunTest | 19 | from maastesting.testcase import MAASTestCase, MAASTwistedRunTest |
467 | 22 | from provisioningserver.drivers.hardware import virsh | 20 | from provisioningserver.drivers.hardware import virsh |
468 | 23 | from provisioningserver.utils.arch import KERNEL_TO_DEBIAN_ARCHITECTURES | 21 | from provisioningserver.utils.arch import KERNEL_TO_DEBIAN_ARCHITECTURES |
469 | @@ -130,7 +128,7 @@ class TestVirshSSH(MAASTestCase): | |||
470 | 130 | conn = self.configure_virshssh_pexpect(virsh_outputs) | 128 | conn = self.configure_virshssh_pexpect(virsh_outputs) |
471 | 131 | mock_sendline = self.patch(conn, "sendline") | 129 | mock_sendline = self.patch(conn, "sendline") |
472 | 132 | conn.login(poweraddr=None) | 130 | conn.login(poweraddr=None) |
474 | 133 | self.assertThat(mock_sendline, MockCalledOnceWith("yes")) | 131 | mock_sendline.assert_called_once_with("yes") |
475 | 134 | 132 | ||
476 | 135 | def test_login_with_password(self): | 133 | def test_login_with_password(self): |
477 | 136 | virsh_outputs = [ | 134 | virsh_outputs = [ |
478 | @@ -140,7 +138,7 @@ class TestVirshSSH(MAASTestCase): | |||
479 | 140 | fake_password = factory.make_name("password") | 138 | fake_password = factory.make_name("password") |
480 | 141 | mock_sendline = self.patch(conn, "sendline") | 139 | mock_sendline = self.patch(conn, "sendline") |
481 | 142 | conn.login(poweraddr=None, password=fake_password) | 140 | conn.login(poweraddr=None, password=fake_password) |
483 | 143 | self.assertThat(mock_sendline, MockCalledOnceWith(fake_password)) | 141 | mock_sendline.assert_called_once_with(fake_password) |
484 | 144 | 142 | ||
485 | 145 | def test_login_missing_password(self): | 143 | def test_login_missing_password(self): |
486 | 146 | virsh_outputs = [ | 144 | virsh_outputs = [ |
487 | @@ -149,22 +147,22 @@ class TestVirshSSH(MAASTestCase): | |||
488 | 149 | conn = self.configure_virshssh_pexpect(virsh_outputs) | 147 | conn = self.configure_virshssh_pexpect(virsh_outputs) |
489 | 150 | mock_close = self.patch(conn, "close") | 148 | mock_close = self.patch(conn, "close") |
490 | 151 | self.assertFalse(conn.login(poweraddr=None, password=None)) | 149 | self.assertFalse(conn.login(poweraddr=None, password=None)) |
492 | 152 | self.assertThat(mock_close, MockCalledOnceWith()) | 150 | mock_close.assert_called_once_with() |
493 | 153 | 151 | ||
494 | 154 | def test_login_invalid(self): | 152 | def test_login_invalid(self): |
495 | 155 | virsh_outputs = [factory.make_string()] | 153 | virsh_outputs = [factory.make_string()] |
496 | 156 | conn = self.configure_virshssh_pexpect(virsh_outputs) | 154 | conn = self.configure_virshssh_pexpect(virsh_outputs) |
497 | 157 | mock_close = self.patch(conn, "close") | 155 | mock_close = self.patch(conn, "close") |
498 | 158 | self.assertFalse(conn.login(poweraddr=None)) | 156 | self.assertFalse(conn.login(poweraddr=None)) |
500 | 159 | self.assertThat(mock_close, MockCalledOnceWith()) | 157 | mock_close.assert_called_once_with() |
501 | 160 | 158 | ||
502 | 161 | def test_logout(self): | 159 | def test_logout(self): |
503 | 162 | conn = self.configure_virshssh_pexpect() | 160 | conn = self.configure_virshssh_pexpect() |
504 | 163 | mock_sendline = self.patch(conn, "sendline") | 161 | mock_sendline = self.patch(conn, "sendline") |
505 | 164 | mock_close = self.patch(conn, "close") | 162 | mock_close = self.patch(conn, "close") |
506 | 165 | conn.logout() | 163 | conn.logout() |
509 | 166 | self.assertThat(mock_sendline, MockCalledOnceWith("quit")) | 164 | mock_sendline.assert_called_once_with("quit") |
510 | 167 | self.assertThat(mock_close, MockCalledOnceWith()) | 165 | mock_close.assert_called_once_with() |
511 | 168 | 166 | ||
512 | 169 | def test_prompt(self): | 167 | def test_prompt(self): |
513 | 170 | virsh_outputs = ["virsh # "] | 168 | virsh_outputs = ["virsh # "] |
514 | @@ -185,8 +183,8 @@ class TestVirshSSH(MAASTestCase): | |||
515 | 185 | mock_sendline = self.patch(conn, "sendline") | 183 | mock_sendline = self.patch(conn, "sendline") |
516 | 186 | mock_prompt = self.patch(conn, "prompt") | 184 | mock_prompt = self.patch(conn, "prompt") |
517 | 187 | output = conn.run(cmd) | 185 | output = conn.run(cmd) |
520 | 188 | self.assertThat(mock_sendline, MockCalledOnceWith(expected)) | 186 | mock_sendline.assert_called_once_with(expected) |
521 | 189 | self.assertThat(mock_prompt, MockCalledOnceWith()) | 187 | mock_prompt.assert_called_once_with() |
522 | 190 | self.assertEqual("\n".join(names), output) | 188 | self.assertEqual("\n".join(names), output) |
523 | 191 | 189 | ||
524 | 192 | def test_list(self): | 190 | def test_list(self): |
525 | @@ -242,11 +240,8 @@ class TestVirshSSH(MAASTestCase): | |||
526 | 242 | c_utf8_environment = get_env_with_locale() | 240 | c_utf8_environment = get_env_with_locale() |
527 | 243 | mock_spawn = self.patch(pexpect.spawn, "__init__") | 241 | mock_spawn = self.patch(pexpect.spawn, "__init__") |
528 | 244 | self.configure_virshssh("") | 242 | self.configure_virshssh("") |
534 | 245 | self.assertThat( | 243 | mock_spawn.assert_called_once_with( |
535 | 246 | mock_spawn, | 244 | None, timeout=30, maxread=2000, env=c_utf8_environment |
531 | 247 | MockCalledOnceWith( | ||
532 | 248 | None, timeout=30, maxread=2000, env=c_utf8_environment | ||
533 | 249 | ), | ||
536 | 250 | ) | 245 | ) |
537 | 251 | 246 | ||
538 | 252 | 247 | ||
539 | @@ -359,15 +354,12 @@ class TestVirsh(MAASTestCase): | |||
540 | 359 | 354 | ||
541 | 360 | # Check that login was called with the provided poweraddr and | 355 | # Check that login was called with the provided poweraddr and |
542 | 361 | # password. | 356 | # password. |
546 | 362 | self.expectThat( | 357 | mock_login.assert_called_once_with(poweraddr, fake_password) |
544 | 363 | mock_login, MockCalledOnceWith(poweraddr, fake_password) | ||
545 | 364 | ) | ||
547 | 365 | 358 | ||
548 | 366 | # Check that the create command had the correct parameters for | 359 | # Check that the create command had the correct parameters for |
549 | 367 | # each machine. | 360 | # each machine. |
553 | 368 | self.expectThat( | 361 | mock_create_node.assert_has_calls( |
554 | 369 | mock_create_node, | 362 | [ |
552 | 370 | MockCallsMatch( | ||
555 | 371 | call( | 363 | call( |
556 | 372 | fake_macs[0], | 364 | fake_macs[0], |
557 | 373 | fake_arch, | 365 | fake_arch, |
558 | @@ -408,24 +400,25 @@ class TestVirsh(MAASTestCase): | |||
559 | 408 | domain, | 400 | domain, |
560 | 409 | machines[4], | 401 | machines[4], |
561 | 410 | ), | 402 | ), |
563 | 411 | ), | 403 | ] |
564 | 412 | ) | 404 | ) |
565 | 413 | 405 | ||
566 | 414 | # The first and last machine should have poweroff called on it, as it | 406 | # The first and last machine should have poweroff called on it, as it |
567 | 415 | # was initial in the on state. | 407 | # was initial in the on state. |
571 | 416 | self.expectThat( | 408 | mock_poweroff.assert_has_calls([call(machines[0]), call(machines[3])]) |
569 | 417 | mock_poweroff, MockCallsMatch(call(machines[0]), call(machines[3])) | ||
570 | 418 | ) | ||
572 | 419 | 409 | ||
577 | 420 | self.assertThat(mock_logout, MockCalledOnceWith()) | 410 | mock_logout.assert_called_once_with() |
578 | 421 | self.expectThat( | 411 | mock_commission_node.assert_has_calls( |
579 | 422 | mock_commission_node, | 412 | [ |
576 | 423 | MockCallsMatch( | ||
580 | 424 | call(system_id, user), | 413 | call(system_id, user), |
581 | 414 | call().wait(30), | ||
582 | 425 | call(system_id, user), | 415 | call(system_id, user), |
583 | 416 | call().wait(30), | ||
584 | 426 | call(system_id, user), | 417 | call(system_id, user), |
585 | 418 | call().wait(30), | ||
586 | 427 | call(system_id, user), | 419 | call(system_id, user), |
588 | 428 | ), | 420 | call().wait(30), |
589 | 421 | ] | ||
590 | 429 | ) | 422 | ) |
591 | 430 | 423 | ||
592 | 431 | @inlineCallbacks | 424 | @inlineCallbacks |
593 | @@ -434,7 +427,9 @@ class TestVirsh(MAASTestCase): | |||
594 | 434 | poweraddr = factory.make_name("poweraddr") | 427 | poweraddr = factory.make_name("poweraddr") |
595 | 435 | mock_login = self.patch(virsh.VirshSSH, "login") | 428 | mock_login = self.patch(virsh.VirshSSH, "login") |
596 | 436 | mock_login.return_value = False | 429 | mock_login.return_value = False |
598 | 437 | with ExpectedException(virsh.VirshError): | 430 | with self.assertRaisesRegex( |
599 | 431 | virsh.VirshError, r"^Failed to login to virsh console\.$" | ||
600 | 432 | ): | ||
601 | 438 | yield deferToThread( | 433 | yield deferToThread( |
602 | 439 | virsh.probe_virsh_and_enlist, | 434 | virsh.probe_virsh_and_enlist, |
603 | 440 | user, | 435 | user, |
604 | @@ -469,9 +464,9 @@ class TestVirshPowerControl(MAASTestCase): | |||
605 | 469 | machine = factory.make_name("machine") | 464 | machine = factory.make_name("machine") |
606 | 470 | virsh.power_control_virsh(poweraddr, machine, "on") | 465 | virsh.power_control_virsh(poweraddr, machine, "on") |
607 | 471 | 466 | ||
611 | 472 | self.assertThat(mock_login, MockCalledOnceWith(poweraddr, None)) | 467 | mock_login.assert_called_once_with(poweraddr, None) |
612 | 473 | self.assertThat(mock_state, MockCalledOnceWith(machine)) | 468 | mock_state.assert_called_once_with(machine) |
613 | 474 | self.assertThat(mock_poweron, MockCalledOnceWith(machine)) | 469 | mock_poweron.assert_called_once_with(machine) |
614 | 475 | 470 | ||
615 | 476 | def test_power_control_off(self): | 471 | def test_power_control_off(self): |
616 | 477 | mock_login = self.patch(virsh.VirshSSH, "login") | 472 | mock_login = self.patch(virsh.VirshSSH, "login") |
617 | @@ -484,9 +479,9 @@ class TestVirshPowerControl(MAASTestCase): | |||
618 | 484 | machine = factory.make_name("machine") | 479 | machine = factory.make_name("machine") |
619 | 485 | virsh.power_control_virsh(poweraddr, machine, "off") | 480 | virsh.power_control_virsh(poweraddr, machine, "off") |
620 | 486 | 481 | ||
624 | 487 | self.assertThat(mock_login, MockCalledOnceWith(poweraddr, None)) | 482 | mock_login.assert_called_once_with(poweraddr, None) |
625 | 488 | self.assertThat(mock_state, MockCalledOnceWith(machine)) | 483 | mock_state.assert_called_once_with(machine) |
626 | 489 | self.assertThat(mock_poweroff, MockCalledOnceWith(machine)) | 484 | mock_poweroff.assert_called_once_with(machine) |
627 | 490 | 485 | ||
628 | 491 | def test_power_control_bad_domain(self): | 486 | def test_power_control_bad_domain(self): |
629 | 492 | mock_login = self.patch(virsh.VirshSSH, "login") | 487 | mock_login = self.patch(virsh.VirshSSH, "login") |
630 | diff --git a/src/provisioningserver/drivers/hardware/tests/test_vmware.py b/src/provisioningserver/drivers/hardware/tests/test_vmware.py | |||
631 | index 433b452..a52a93e 100644 | |||
632 | --- a/src/provisioningserver/drivers/hardware/tests/test_vmware.py | |||
633 | +++ b/src/provisioningserver/drivers/hardware/tests/test_vmware.py | |||
634 | @@ -7,8 +7,6 @@ | |||
635 | 7 | 7 | ||
636 | 8 | import random | 8 | import random |
637 | 9 | 9 | ||
638 | 10 | from testtools import ExpectedException | ||
639 | 11 | from testtools.matchers import Equals, Is, IsInstance, Not | ||
640 | 12 | from twisted.internet.defer import inlineCallbacks | 10 | from twisted.internet.defer import inlineCallbacks |
641 | 13 | from twisted.internet.threads import deferToThread | 11 | from twisted.internet.threads import deferToThread |
642 | 14 | 12 | ||
643 | @@ -16,10 +14,6 @@ from maastesting import get_testing_timeout | |||
644 | 16 | from maastesting.factory import factory | 14 | from maastesting.factory import factory |
645 | 17 | from maastesting.testcase import MAASTestCase, MAASTwistedRunTest | 15 | from maastesting.testcase import MAASTestCase, MAASTwistedRunTest |
646 | 18 | from provisioningserver.drivers.hardware import vmware | 16 | from provisioningserver.drivers.hardware import vmware |
647 | 19 | from provisioningserver.drivers.hardware.vmware import ( | ||
648 | 20 | VMwarePyvmomiAPI, | ||
649 | 21 | VMwareVMNotFound, | ||
650 | 22 | ) | ||
651 | 23 | from provisioningserver.utils.twisted import asynchronous | 17 | from provisioningserver.utils.twisted import asynchronous |
652 | 24 | 18 | ||
653 | 25 | 19 | ||
654 | @@ -53,8 +47,7 @@ class FakeVmomiVMRuntime: | |||
655 | 53 | 47 | ||
656 | 54 | 48 | ||
657 | 55 | class FakeVmomiVMConfigHardwareDevice: | 49 | class FakeVmomiVMConfigHardwareDevice: |
660 | 56 | def __init__(self): | 50 | pass |
659 | 57 | pass | ||
661 | 58 | 51 | ||
662 | 59 | 52 | ||
663 | 60 | class FakeVmomiNic(FakeVmomiVMConfigHardwareDevice): | 53 | class FakeVmomiNic(FakeVmomiVMConfigHardwareDevice): |
664 | @@ -246,35 +239,36 @@ class TestVMwarePyvmomi(MAASTestCase): | |||
665 | 246 | 239 | ||
666 | 247 | def test_api_connection(self): | 240 | def test_api_connection(self): |
667 | 248 | mock_vmomi_api = self.configure_vmomi_api(servers=0) | 241 | mock_vmomi_api = self.configure_vmomi_api(servers=0) |
669 | 249 | api = VMwarePyvmomiAPI( | 242 | api = vmware.VMwarePyvmomiAPI( |
670 | 250 | factory.make_hostname(), | 243 | factory.make_hostname(), |
671 | 251 | factory.make_username(), | 244 | factory.make_username(), |
672 | 252 | factory.make_username(), | 245 | factory.make_username(), |
673 | 253 | ) | 246 | ) |
674 | 254 | api.connect() | 247 | api.connect() |
679 | 255 | self.expectThat( | 248 | self.assertIsInstance(api.service_instance, FakeVmomiServiceInstance) |
680 | 256 | api.service_instance, IsInstance(FakeVmomiServiceInstance) | 249 | self.assertTrue(api.is_connected()) |
677 | 257 | ) | ||
678 | 258 | self.expectThat(api.is_connected(), Equals(True)) | ||
681 | 259 | api.disconnect() | 250 | api.disconnect() |
684 | 260 | self.expectThat(mock_vmomi_api.SmartConnect.called, Equals(True)) | 251 | self.assertTrue(mock_vmomi_api.SmartConnect.called) |
685 | 261 | self.expectThat(mock_vmomi_api.Disconnect.called, Equals(True)) | 252 | self.assertTrue(mock_vmomi_api.Disconnect.called) |
686 | 262 | 253 | ||
687 | 263 | def test_api_failed_connection(self): | 254 | def test_api_failed_connection(self): |
688 | 264 | mock_vmomi_api = self.patch(vmware, "vmomi_api") | 255 | mock_vmomi_api = self.patch(vmware, "vmomi_api") |
689 | 265 | mock_vmomi_api.SmartConnect.return_value = None | 256 | mock_vmomi_api.SmartConnect.return_value = None |
691 | 266 | api = VMwarePyvmomiAPI( | 257 | api = vmware.VMwarePyvmomiAPI( |
692 | 267 | factory.make_hostname(), | 258 | factory.make_hostname(), |
693 | 268 | factory.make_username(), | 259 | factory.make_username(), |
694 | 269 | factory.make_username(), | 260 | factory.make_username(), |
695 | 270 | ) | 261 | ) |
697 | 271 | with ExpectedException(vmware.VMwareAPIConnectionFailed): | 262 | with self.assertRaisesRegex( |
698 | 263 | vmware.VMwareAPIConnectionFailed, | ||
699 | 264 | "^Could not connect to VMware service API$", | ||
700 | 265 | ): | ||
701 | 272 | api.connect() | 266 | api.connect() |
704 | 273 | self.expectThat(api.service_instance, Is(None)) | 267 | self.assertIsNone(api.service_instance) |
705 | 274 | self.expectThat(api.is_connected(), Equals(False)) | 268 | self.assertFalse(api.is_connected()) |
706 | 275 | api.disconnect() | 269 | api.disconnect() |
709 | 276 | self.expectThat(mock_vmomi_api.SmartConnect.called, Equals(True)) | 270 | self.assertTrue(mock_vmomi_api.SmartConnect.called) |
710 | 277 | self.expectThat(mock_vmomi_api.Disconnect.called, Equals(True)) | 271 | self.assertTrue(mock_vmomi_api.Disconnect.called) |
711 | 278 | 272 | ||
712 | 279 | def test_get_vmware_servers_empty(self): | 273 | def test_get_vmware_servers_empty(self): |
713 | 280 | self.configure_vmomi_api(servers=0) | 274 | self.configure_vmomi_api(servers=0) |
714 | @@ -285,7 +279,7 @@ class TestVMwarePyvmomi(MAASTestCase): | |||
715 | 285 | port=8443, | 279 | port=8443, |
716 | 286 | protocol="https", | 280 | protocol="https", |
717 | 287 | ) | 281 | ) |
719 | 288 | self.expectThat(servers, Equals({})) | 282 | self.assertEqual(servers, {}) |
720 | 289 | 283 | ||
721 | 290 | def test_get_vmware_servers(self): | 284 | def test_get_vmware_servers(self): |
722 | 291 | self.configure_vmomi_api(servers=10) | 285 | self.configure_vmomi_api(servers=10) |
723 | @@ -294,7 +288,7 @@ class TestVMwarePyvmomi(MAASTestCase): | |||
724 | 294 | factory.make_username(), | 288 | factory.make_username(), |
725 | 295 | factory.make_username(), | 289 | factory.make_username(), |
726 | 296 | ) | 290 | ) |
728 | 297 | self.expectThat(servers, Not(Equals({}))) | 291 | self.assertNotEqual(servers, {}) |
729 | 298 | 292 | ||
730 | 299 | def test_get_server_by_instance_uuid(self): | 293 | def test_get_server_by_instance_uuid(self): |
731 | 300 | mock_vmomi_api = self.configure_vmomi_api( | 294 | mock_vmomi_api = self.configure_vmomi_api( |
732 | @@ -336,7 +330,10 @@ class TestVMwarePyvmomi(MAASTestCase): | |||
733 | 336 | mock_vmomi_api = self.configure_vmomi_api( | 330 | mock_vmomi_api = self.configure_vmomi_api( |
734 | 337 | servers=1, has_instance_uuid=True, has_uuid=True | 331 | servers=1, has_instance_uuid=True, has_uuid=True |
735 | 338 | ) | 332 | ) |
737 | 339 | with ExpectedException(VMwareVMNotFound): | 333 | with self.assertRaisesRegex( |
738 | 334 | vmware.VMwareVMNotFound, | ||
739 | 335 | "^Failed to find VM; need a UUID or a VM name for power control$", | ||
740 | 336 | ): | ||
741 | 340 | vmware._find_vm_by_uuid_or_name(mock_vmomi_api, None, None) | 337 | vmware._find_vm_by_uuid_or_name(mock_vmomi_api, None, None) |
742 | 341 | 338 | ||
743 | 342 | def test_power_control_missing_server_raises_VMwareVMNotFound(self): | 339 | def test_power_control_missing_server_raises_VMwareVMNotFound(self): |
744 | @@ -346,7 +343,10 @@ class TestVMwarePyvmomi(MAASTestCase): | |||
745 | 346 | host = factory.make_hostname() | 343 | host = factory.make_hostname() |
746 | 347 | username = factory.make_username() | 344 | username = factory.make_username() |
747 | 348 | password = factory.make_username() | 345 | password = factory.make_username() |
749 | 349 | with ExpectedException(VMwareVMNotFound): | 346 | with self.assertRaisesRegex( |
750 | 347 | vmware.VMwareVMNotFound, | ||
751 | 348 | "^Failed to find VM; need a UUID or a VM name for power control$", | ||
752 | 349 | ): | ||
753 | 350 | vmware.power_control_vmware( | 350 | vmware.power_control_vmware( |
754 | 351 | host, username, password, None, None, "on" | 351 | host, username, password, None, None, "on" |
755 | 352 | ) | 352 | ) |
756 | @@ -358,7 +358,10 @@ class TestVMwarePyvmomi(MAASTestCase): | |||
757 | 358 | host = factory.make_hostname() | 358 | host = factory.make_hostname() |
758 | 359 | username = factory.make_username() | 359 | username = factory.make_username() |
759 | 360 | password = factory.make_username() | 360 | password = factory.make_username() |
761 | 361 | with ExpectedException(VMwareVMNotFound): | 361 | with self.assertRaisesRegex( |
762 | 362 | vmware.VMwareVMNotFound, | ||
763 | 363 | "^Failed to find VM; need a UUID or a VM name for power control$", | ||
764 | 364 | ): | ||
765 | 362 | vmware.power_query_vmware(host, username, password, None, None) | 365 | vmware.power_query_vmware(host, username, password, None, None) |
766 | 363 | 366 | ||
767 | 364 | def test_power_control(self): | 367 | def test_power_control(self): |
768 | @@ -399,7 +402,7 @@ class TestVMwarePyvmomi(MAASTestCase): | |||
769 | 399 | state = vmware.power_query_vmware( | 402 | state = vmware.power_query_vmware( |
770 | 400 | host, username, password, vm_name, uuid | 403 | host, username, password, vm_name, uuid |
771 | 401 | ) | 404 | ) |
773 | 402 | self.expectThat(state, Equals("on")) | 405 | self.assertEqual(state, "on") |
774 | 403 | 406 | ||
775 | 404 | # turn off a set of VMs, then verify they are off | 407 | # turn off a set of VMs, then verify they are off |
776 | 405 | for uuid in instance_uuids: | 408 | for uuid in instance_uuids: |
777 | @@ -410,9 +413,9 @@ class TestVMwarePyvmomi(MAASTestCase): | |||
778 | 410 | state = vmware.power_query_vmware( | 413 | state = vmware.power_query_vmware( |
779 | 411 | host, username, password, vm_name, uuid | 414 | host, username, password, vm_name, uuid |
780 | 412 | ) | 415 | ) |
782 | 413 | self.expectThat(state, Equals("off")) | 416 | self.assertEqual(state, "off") |
783 | 414 | 417 | ||
785 | 415 | self.expectThat(servers, Not(Equals({}))) | 418 | self.assertNotEqual(servers, {}) |
786 | 416 | 419 | ||
787 | 417 | @inlineCallbacks | 420 | @inlineCallbacks |
788 | 418 | def test_probe_and_enlist(self): | 421 | def test_probe_and_enlist(self): |
789 | diff --git a/src/provisioningserver/drivers/osystem/tests/test_centos.py b/src/provisioningserver/drivers/osystem/tests/test_centos.py | |||
790 | index aabc7f9..ccc1b4d 100644 | |||
791 | --- a/src/provisioningserver/drivers/osystem/tests/test_centos.py | |||
792 | +++ b/src/provisioningserver/drivers/osystem/tests/test_centos.py | |||
793 | @@ -6,8 +6,6 @@ | |||
794 | 6 | 6 | ||
795 | 7 | from itertools import product | 7 | from itertools import product |
796 | 8 | 8 | ||
797 | 9 | from testtools.matchers import Equals | ||
798 | 10 | |||
799 | 11 | from maastesting.factory import factory | 9 | from maastesting.factory import factory |
800 | 12 | from maastesting.testcase import MAASTestCase | 10 | from maastesting.testcase import MAASTestCase |
801 | 13 | from provisioningserver.drivers.osystem.centos import ( | 11 | from provisioningserver.drivers.osystem.centos import ( |
802 | @@ -53,4 +51,4 @@ class TestCentOS(MAASTestCase): | |||
803 | 53 | } | 51 | } |
804 | 54 | osystem = CentOS() | 52 | osystem = CentOS() |
805 | 55 | for name, title in name_titles.items(): | 53 | for name, title in name_titles.items(): |
807 | 56 | self.expectThat(osystem.get_release_title(name), Equals(title)) | 54 | self.assertEqual(osystem.get_release_title(name), title) |
808 | diff --git a/src/provisioningserver/drivers/osystem/tests/test_esxi.py b/src/provisioningserver/drivers/osystem/tests/test_esxi.py | |||
809 | index 8b60360..cea57d1 100644 | |||
810 | --- a/src/provisioningserver/drivers/osystem/tests/test_esxi.py | |||
811 | +++ b/src/provisioningserver/drivers/osystem/tests/test_esxi.py | |||
812 | @@ -6,8 +6,6 @@ | |||
813 | 6 | 6 | ||
814 | 7 | from itertools import product | 7 | from itertools import product |
815 | 8 | 8 | ||
816 | 9 | from testtools.matchers import Equals | ||
817 | 10 | |||
818 | 11 | from maastesting.factory import factory | 9 | from maastesting.factory import factory |
819 | 12 | from maastesting.testcase import MAASTestCase | 10 | from maastesting.testcase import MAASTestCase |
820 | 13 | from provisioningserver.drivers.osystem import BOOT_IMAGE_PURPOSE | 11 | from provisioningserver.drivers.osystem import BOOT_IMAGE_PURPOSE |
821 | @@ -47,4 +45,4 @@ class TestESXi(MAASTestCase): | |||
822 | 47 | } | 45 | } |
823 | 48 | osystem = ESXi() | 46 | osystem = ESXi() |
824 | 49 | for name, title in name_titles.items(): | 47 | for name, title in name_titles.items(): |
826 | 50 | self.expectThat(osystem.get_release_title(name), Equals(title)) | 48 | self.assertEqual(osystem.get_release_title(name), title) |
827 | diff --git a/src/provisioningserver/drivers/osystem/tests/test_rhel.py b/src/provisioningserver/drivers/osystem/tests/test_rhel.py | |||
828 | index 709aee9..fc2acd7 100644 | |||
829 | --- a/src/provisioningserver/drivers/osystem/tests/test_rhel.py | |||
830 | +++ b/src/provisioningserver/drivers/osystem/tests/test_rhel.py | |||
831 | @@ -6,8 +6,6 @@ | |||
832 | 6 | 6 | ||
833 | 7 | from itertools import product | 7 | from itertools import product |
834 | 8 | 8 | ||
835 | 9 | from testtools.matchers import Equals | ||
836 | 10 | |||
837 | 11 | from maastesting.factory import factory | 9 | from maastesting.factory import factory |
838 | 12 | from maastesting.testcase import MAASTestCase | 10 | from maastesting.testcase import MAASTestCase |
839 | 13 | from provisioningserver.drivers.osystem.rhel import ( | 11 | from provisioningserver.drivers.osystem.rhel import ( |
840 | @@ -51,4 +49,4 @@ class TestRHEL(MAASTestCase): | |||
841 | 51 | } | 49 | } |
842 | 52 | osystem = RHELOS() | 50 | osystem = RHELOS() |
843 | 53 | for name, title in name_titles.items(): | 51 | for name, title in name_titles.items(): |
845 | 54 | self.expectThat(osystem.get_release_title(name), Equals(title)) | 52 | self.assertEqual(osystem.get_release_title(name), title) |
846 | diff --git a/src/provisioningserver/tests/test_monkey.py b/src/provisioningserver/tests/test_monkey.py | |||
847 | index 3c38d49..7ddc0ff 100644 | |||
848 | --- a/src/provisioningserver/tests/test_monkey.py | |||
849 | +++ b/src/provisioningserver/tests/test_monkey.py | |||
850 | @@ -5,7 +5,6 @@ | |||
851 | 5 | 5 | ||
852 | 6 | 6 | ||
853 | 7 | from testtools.deferredruntest import assert_fails_with | 7 | from testtools.deferredruntest import assert_fails_with |
854 | 8 | from testtools.matchers import Equals | ||
855 | 9 | from twisted.internet.defer import Deferred | 8 | from twisted.internet.defer import Deferred |
856 | 10 | from twisted.internet.threads import deferToThread | 9 | from twisted.internet.threads import deferToThread |
857 | 11 | 10 | ||
858 | @@ -38,58 +37,62 @@ class TestAugmentDeferToThreadPool(MAASTestCase): | |||
859 | 38 | 37 | ||
860 | 39 | class TestPatchedURI(MAASTestCase): | 38 | class TestPatchedURI(MAASTestCase): |
861 | 40 | def test_parses_URL_with_hostname(self): | 39 | def test_parses_URL_with_hostname(self): |
868 | 41 | hostname = factory.make_name("host").encode("ascii") | 40 | hostname = factory.make_name("host") |
869 | 42 | path = factory.make_name("path").encode("ascii") | 41 | path = factory.make_name("path") |
870 | 43 | uri = get_patched_URI().fromBytes(b"http://%s/%s" % (hostname, path)) | 42 | uri = get_patched_URI().fromBytes( |
871 | 44 | self.expectThat(uri.host, Equals(hostname)) | 43 | f"http://{hostname}/{path}".encode("utf-8") |
872 | 45 | self.expectThat(uri.path, Equals(b"/%s" % path)) | 44 | ) |
873 | 46 | self.expectThat(uri.port, Equals(80)) | 45 | self.assertEqual(uri.host, hostname.encode("utf-8")) |
874 | 46 | self.assertEqual(uri.path, f"/{path}".encode("utf-8")) | ||
875 | 47 | self.assertEqual(uri.port, 80) | ||
876 | 47 | 48 | ||
877 | 48 | def test_parses_URL_with_hostname_and_port(self): | 49 | def test_parses_URL_with_hostname_and_port(self): |
879 | 49 | hostname = factory.make_name("host").encode("ascii") | 50 | hostname = factory.make_name("host") |
880 | 50 | port = factory.pick_port() | 51 | port = factory.pick_port() |
882 | 51 | path = factory.make_name("path").encode("ascii") | 52 | path = factory.make_name("path") |
883 | 52 | uri = get_patched_URI().fromBytes( | 53 | uri = get_patched_URI().fromBytes( |
885 | 53 | b"http://%s:%d/%s" % (hostname, port, path) | 54 | f"http://{hostname}:{port}/{path}".encode("utf-8") |
886 | 54 | ) | 55 | ) |
890 | 55 | self.expectThat(uri.host, Equals(hostname)) | 56 | self.assertEqual(uri.host, hostname.encode("utf-8")) |
891 | 56 | self.expectThat(uri.path, Equals(b"/%s" % path)) | 57 | self.assertEqual(uri.path, f"/{path}".encode("utf-8")) |
892 | 57 | self.expectThat(uri.port, Equals(port)) | 58 | self.assertEqual(uri.port, port) |
893 | 58 | 59 | ||
894 | 59 | def test_parses_URL_with_IPv4_address(self): | 60 | def test_parses_URL_with_IPv4_address(self): |
896 | 60 | ip = factory.make_ipv4_address().encode("ascii") | 61 | ip = factory.make_ipv4_address() |
897 | 61 | path = factory.make_name("path").encode("ascii") | 62 | path = factory.make_name("path").encode("ascii") |
902 | 62 | uri = get_patched_URI().fromBytes(b"http://%s/%s" % (ip, path)) | 63 | uri = get_patched_URI().fromBytes( |
903 | 63 | self.expectThat(uri.host, Equals(ip)) | 64 | f"http://{ip}/{path}".encode("utf-8") |
904 | 64 | self.expectThat(uri.path, Equals(b"/%s" % path)) | 65 | ) |
905 | 65 | self.expectThat(uri.port, Equals(80)) | 66 | self.assertEqual(uri.host, ip.encode("utf-8")) |
906 | 67 | self.assertEqual(uri.path, f"/{path}".encode("utf-8")) | ||
907 | 68 | self.assertEqual(uri.port, 80) | ||
908 | 66 | 69 | ||
909 | 67 | def test_parses_URL_with_IPv4_address_and_port(self): | 70 | def test_parses_URL_with_IPv4_address_and_port(self): |
911 | 68 | ip = factory.make_ipv4_address().encode("ascii") | 71 | ip = factory.make_ipv4_address() |
912 | 69 | port = factory.pick_port() | 72 | port = factory.pick_port() |
914 | 70 | path = factory.make_name("path").encode("ascii") | 73 | path = factory.make_name("path") |
915 | 71 | uri = get_patched_URI().fromBytes( | 74 | uri = get_patched_URI().fromBytes( |
917 | 72 | b"http://%s:%d/%s" % (ip, port, path) | 75 | f"http://{ip}:{port}/{path}".encode("utf-8") |
918 | 73 | ) | 76 | ) |
922 | 74 | self.expectThat(uri.host, Equals(ip)) | 77 | self.assertEqual(uri.host, ip.encode("utf-8")) |
923 | 75 | self.expectThat(uri.path, Equals(b"/%s" % path)) | 78 | self.assertEqual(uri.path, f"/{path}".encode("utf-8")) |
924 | 76 | self.expectThat(uri.port, Equals(port)) | 79 | self.assertEqual(uri.port, port) |
925 | 77 | 80 | ||
926 | 78 | def test_parses_URL_with_IPv6_address(self): | 81 | def test_parses_URL_with_IPv6_address(self): |
933 | 79 | ip = factory.make_ipv6_address().encode("ascii") | 82 | ip = factory.make_ipv6_address() |
934 | 80 | path = factory.make_name("path").encode("ascii") | 83 | path = factory.make_name("path") |
935 | 81 | uri = get_patched_URI().fromBytes(b"http://[%s]/%s" % (ip, path)) | 84 | uri = get_patched_URI().fromBytes(f"http://[{ip}]/{path}".encode()) |
936 | 82 | self.expectThat(uri.host, Equals(b"%s" % ip)) | 85 | self.assertEqual(uri.host, ip.encode("utf-8")) |
937 | 83 | self.expectThat(uri.path, Equals(b"/%s" % path)) | 86 | self.assertEqual(uri.path, f"/{path}".encode("utf-8")) |
938 | 84 | self.expectThat(uri.port, Equals(80)) | 87 | self.assertEqual(uri.port, 80) |
939 | 85 | 88 | ||
940 | 86 | def test_parses_URL_with_IPv6_address_and_port(self): | 89 | def test_parses_URL_with_IPv6_address_and_port(self): |
942 | 87 | ip = factory.make_ipv6_address().encode("ascii") | 90 | ip = factory.make_ipv6_address() |
943 | 88 | port = factory.pick_port() | 91 | port = factory.pick_port() |
945 | 89 | path = factory.make_name("path").encode("ascii") | 92 | path = factory.make_name("path") |
946 | 90 | uri = get_patched_URI().fromBytes( | 93 | uri = get_patched_URI().fromBytes( |
948 | 91 | b"http://[%s]:%d/%s" % (ip, port, path) | 94 | f"http://[{ip}]:{port}/{path}".encode() |
949 | 92 | ) | 95 | ) |
953 | 93 | self.expectThat(uri.host, Equals(b"%s" % ip)) | 96 | self.assertEqual(uri.host, ip.encode("utf-8")) |
954 | 94 | self.expectThat(uri.path, Equals(b"/%s" % path)) | 97 | self.assertEqual(uri.path, f"/{path}".encode("utf-8")) |
955 | 95 | self.expectThat(uri.port, Equals(port)) | 98 | self.assertEqual(uri.port, port) |
956 | diff --git a/src/provisioningserver/utils/tests/test_events.py b/src/provisioningserver/utils/tests/test_events.py | |||
957 | index c9a677f..c3c64bb 100644 | |||
958 | --- a/src/provisioningserver/utils/tests/test_events.py | |||
959 | +++ b/src/provisioningserver/utils/tests/test_events.py | |||
960 | @@ -6,8 +6,6 @@ | |||
961 | 6 | 6 | ||
962 | 7 | from unittest.mock import MagicMock, sentinel | 7 | from unittest.mock import MagicMock, sentinel |
963 | 8 | 8 | ||
964 | 9 | from testtools.matchers import IsInstance | ||
965 | 10 | |||
966 | 11 | from maastesting.factory import factory | 9 | from maastesting.factory import factory |
967 | 12 | from maastesting.testcase import MAASTestCase | 10 | from maastesting.testcase import MAASTestCase |
968 | 13 | from provisioningserver.utils.events import Event, EventGroup | 11 | from provisioningserver.utils.events import Event, EventGroup |
969 | @@ -64,4 +62,4 @@ class TestEventGroup(MAASTestCase): | |||
970 | 64 | events = [factory.make_name("event") for _ in range(3)] | 62 | events = [factory.make_name("event") for _ in range(3)] |
971 | 65 | group = EventGroup(*events) | 63 | group = EventGroup(*events) |
972 | 66 | for event in events: | 64 | for event in events: |
974 | 67 | self.expectThat(getattr(group, event), IsInstance(Event)) | 65 | self.assertIsInstance(getattr(group, event), Event) |
975 | diff --git a/src/provisioningserver/utils/tests/test_text.py b/src/provisioningserver/utils/tests/test_text.py | |||
976 | index 5e6f949..c585619 100644 | |||
977 | --- a/src/provisioningserver/utils/tests/test_text.py | |||
978 | +++ b/src/provisioningserver/utils/tests/test_text.py | |||
979 | @@ -8,7 +8,6 @@ from itertools import repeat | |||
980 | 8 | import string | 8 | import string |
981 | 9 | 9 | ||
982 | 10 | import hypothesis.strategies | 10 | import hypothesis.strategies |
983 | 11 | from testtools.matchers import Equals | ||
984 | 12 | 11 | ||
985 | 13 | from maastesting.factory import factory | 12 | from maastesting.factory import factory |
986 | 14 | from maastesting.testcase import MAASTestCase | 13 | from maastesting.testcase import MAASTestCase |
987 | @@ -111,9 +110,9 @@ class TestNormalizeToCommaListScenarios(MAASTestCase): | |||
988 | 111 | 110 | ||
989 | 112 | def test_scenarios(self): | 111 | def test_scenarios(self): |
990 | 113 | unquoted = normalise_to_comma_list(self.test_input) | 112 | unquoted = normalise_to_comma_list(self.test_input) |
992 | 114 | self.expectThat(unquoted, Equals(self.unquoted)) | 113 | self.assertEqual(unquoted, self.unquoted) |
993 | 115 | quoted = normalise_to_comma_list(self.test_input, quoted=True) | 114 | quoted = normalise_to_comma_list(self.test_input, quoted=True) |
995 | 116 | self.expectThat(quoted, Equals(self.quoted)) | 115 | self.assertEqual(quoted, self.quoted) |
996 | 117 | 116 | ||
997 | 118 | 117 | ||
998 | 119 | class TestSplitStringList(MAASTestCase): | 118 | class TestSplitStringList(MAASTestCase): |
UNIT TESTS
-b less-testtools lp:~adam-collard/maas/+git/maas into -b master lp:~maas-committers/maas
STATUS: FAILED maas-ci. internal: 8080/job/ maas-tester/ 4199/console 590eb5ba1dc8704 6584d1a02e
LOG: http://
COMMIT: ceddd187e1b20f2