|
22 | 22 | from libcloud.test.secrets import OVH_PARAMS |
23 | 23 | from libcloud.common.exceptions import BaseHTTPError |
24 | 24 | from libcloud.test.file_fixtures import ComputeFileFixtures |
| 25 | +from libcloud.compute.types import NodeState |
25 | 26 | from libcloud.compute.drivers.ovh import OvhNodeDriver |
26 | 27 | from libcloud.test.common.test_ovh import BaseOvhMockHttp |
27 | 28 |
|
@@ -155,6 +156,36 @@ def _json_1_0_cloud_project_project_id_instance_get_invalid_app_key_error( |
155 | 156 | body = '{"message":"Invalid application key"}' |
156 | 157 | return (httplib.UNAUTHORIZED, body, {}, httplib.responses[httplib.OK]) |
157 | 158 |
|
| 159 | + # VPS mock handlers |
| 160 | + |
| 161 | + def _json_1_0_vps_get(self, method, url, body, headers): |
| 162 | + body = self.fixtures.load("vps_get.json") |
| 163 | + return (httplib.OK, body, {}, httplib.responses[httplib.OK]) |
| 164 | + |
| 165 | + def _json_1_0_vps_testvps_get(self, method, url, body, headers): |
| 166 | + body = self.fixtures.load("vps_get_detail.json") |
| 167 | + return (httplib.OK, body, {}, httplib.responses[httplib.OK]) |
| 168 | + |
| 169 | + def _json_1_0_vps_testvps_reboot_post(self, method, url, body, headers): |
| 170 | + body = self.fixtures.load("vps_reboot_post.json") |
| 171 | + return (httplib.OK, body, {}, httplib.responses[httplib.OK]) |
| 172 | + |
| 173 | + def _json_1_0_vps_testvps_start_post(self, method, url, body, headers): |
| 174 | + body = self.fixtures.load("vps_start_post.json") |
| 175 | + return (httplib.OK, body, {}, httplib.responses[httplib.OK]) |
| 176 | + |
| 177 | + def _json_1_0_vps_testvps_stop_post(self, method, url, body, headers): |
| 178 | + body = self.fixtures.load("vps_stop_post.json") |
| 179 | + return (httplib.OK, body, {}, httplib.responses[httplib.OK]) |
| 180 | + |
| 181 | + def _json_1_0_vps_testvps_rebuild_post(self, method, url, body, headers): |
| 182 | + body = self.fixtures.load("vps_rebuild_post.json") |
| 183 | + return (httplib.OK, body, {}, httplib.responses[httplib.OK]) |
| 184 | + |
| 185 | + def _json_1_0_vps_testvps_images_available_get(self, method, url, body, headers): |
| 186 | + body = self.fixtures.load("vps_images_available_get.json") |
| 187 | + return (httplib.OK, body, {}, httplib.responses[httplib.OK]) |
| 188 | + |
158 | 189 |
|
159 | 190 | @patch("libcloud.common.ovh.OvhConnection._timedelta", 42) |
160 | 191 | class OvhTests(unittest.TestCase): |
@@ -305,6 +336,62 @@ def test_destroy_volume_snapshot(self): |
305 | 336 | def test_get_pricing(self): |
306 | 337 | self.driver.ex_get_pricing("foo-id") |
307 | 338 |
|
| 339 | + # VPS tests |
| 340 | + |
| 341 | + def test_ex_list_vps(self): |
| 342 | + names = self.driver.ex_list_vps() |
| 343 | + self.assertEqual(len(names), 2) |
| 344 | + self.assertEqual(names[0], "testvps") |
| 345 | + self.assertEqual(names[1], "testvps2") |
| 346 | + |
| 347 | + def test_ex_get_vps(self): |
| 348 | + node = self.driver.ex_get_vps("testvps") |
| 349 | + self.assertEqual(node.id, "testvps") |
| 350 | + self.assertEqual(node.name, "my-vps") |
| 351 | + self.assertEqual(node.state, NodeState.RUNNING) |
| 352 | + self.assertEqual(len(node.public_ips), 2) |
| 353 | + self.assertIn("198.51.100.42", node.public_ips) |
| 354 | + self.assertEqual(node.extra["vcore"], 1) |
| 355 | + self.assertEqual(node.extra["memory"], 2048) |
| 356 | + self.assertEqual(node.extra["disk"], 40) |
| 357 | + self.assertEqual(node.extra["zone"], "eu-west-rbx") |
| 358 | + |
| 359 | + def test_ex_reboot_vps(self): |
| 360 | + result = self.driver.ex_reboot_vps("testvps") |
| 361 | + self.assertTrue(result) |
| 362 | + |
| 363 | + def test_ex_start_vps(self): |
| 364 | + result = self.driver.ex_start_vps("testvps") |
| 365 | + self.assertTrue(result) |
| 366 | + |
| 367 | + def test_ex_stop_vps(self): |
| 368 | + result = self.driver.ex_stop_vps("testvps") |
| 369 | + self.assertTrue(result) |
| 370 | + |
| 371 | + def test_ex_rebuild_vps(self): |
| 372 | + result = self.driver.ex_rebuild_vps("testvps", "img-debian-12") |
| 373 | + self.assertTrue(result) |
| 374 | + |
| 375 | + def test_ex_rebuild_vps_with_ssh_key(self): |
| 376 | + result = self.driver.ex_rebuild_vps( |
| 377 | + "testvps", "img-debian-12", ssh_key=["ssh-rsa AAAA..."] |
| 378 | + ) |
| 379 | + self.assertTrue(result) |
| 380 | + |
| 381 | + def test_ex_list_vps_images(self): |
| 382 | + images = self.driver.ex_list_vps_images("testvps") |
| 383 | + self.assertEqual(len(images), 3) |
| 384 | + self.assertEqual(images[0].id, "img-debian-12") |
| 385 | + self.assertEqual(images[0].name, "Debian 12") |
| 386 | + self.assertEqual(images[1].id, "img-ubuntu-2404") |
| 387 | + self.assertEqual(images[1].name, "Ubuntu 24.04") |
| 388 | + |
| 389 | + def test_vps_state_map(self): |
| 390 | + self.assertEqual(self.driver.VPS_STATE_MAP["running"], NodeState.RUNNING) |
| 391 | + self.assertEqual(self.driver.VPS_STATE_MAP["stopped"], NodeState.STOPPED) |
| 392 | + self.assertEqual(self.driver.VPS_STATE_MAP["rebooting"], NodeState.REBOOTING) |
| 393 | + self.assertEqual(self.driver.VPS_STATE_MAP["installing"], NodeState.PENDING) |
| 394 | + |
308 | 395 |
|
309 | 396 | if __name__ == "__main__": |
310 | 397 | sys.exit(unittest.main()) |
0 commit comments