Added snapshot operations basic tests. Closes #658
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/99188f79 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/99188f79 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/99188f79 Branch: refs/heads/trunk Commit: 99188f79478f37ef817dd86d5d4f71943560bc09 Parents: 7bb4099 Author: Juan Font <juanfontalo...@gmail.com> Authored: Sun Feb 14 23:34:42 2016 +0100 Committer: anthony-shaw <anthony.p.s...@gmail.com> Committed: Mon Feb 15 09:44:54 2016 +1100 ---------------------------------------------------------------------- ...ask_2518935e_b315_4d8e_9e99_9275f751877c.xml | 32 +++++++++ ...ask_fab4b26f_4f2e_4d49_ad01_ae9324bbfe48.xml | 32 +++++++++ ...ask_fe75d3af_f5a3_44a5_b016_ae0bdadfc32b.xml | 32 +++++++++ ...b_48ca_8a78_3b70ee65ef6b_create_snapshot.xml | 32 +++++++++ ..._48ca_8a78_3b70ee65ef6b_remove_snapshots.xml | 32 +++++++++ ...b_48ca_8a78_3b70ee65ef6b_revert_snapshot.xml | 32 +++++++++ libcloud/test/compute/test_vcloud.py | 69 ++++++++++++++++++++ 7 files changed, 261 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/99188f79/libcloud/test/compute/fixtures/vcloud_1_5/api_task_2518935e_b315_4d8e_9e99_9275f751877c.xml ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/vcloud_1_5/api_task_2518935e_b315_4d8e_9e99_9275f751877c.xml b/libcloud/test/compute/fixtures/vcloud_1_5/api_task_2518935e_b315_4d8e_9e99_9275f751877c.xml new file mode 100644 index 0000000..e9fcc23 --- /dev/null +++ b/libcloud/test/compute/fixtures/vcloud_1_5/api_task_2518935e_b315_4d8e_9e99_9275f751877c.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?><Task + xmlns="http://www.vmware.com/vcloud/v1.5" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + cancelRequested="false" + expiryTime="2013-05-15T13:10:25.449+03:00" + href="https://vcloud.example.com/api/task/2518935e-b315-4d8e-9e99-9275f751877c" + id="urn:vcloud:task:2518935e-b315-4d8e-9e99-9275f751877c" + name="task" + operation="Removing Snapshot Virtual Machine (ec94079b-3071-4a72-b95c-4154acb12c38)" + operationName="vappRemoveAllSnapshots" + serviceNamespace="com.vmware.vcloud" + startTime="2013-02-14T13:10:25.449+02:00" + status="success" + type="application/vnd.vmware.vcloud.task+xml" + xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://https://vcloud.example.com/api/v1.5/schema/master.xsd"> + <Link + href="https://vcloud.example.com/api/task/2518935e-b315-4d8e-9e99-9275f751877c/action/cancel" + rel="task:cancel"/> + <Owner + href="https://vcloud.example.com/api/vApp/vm-ec94079b-3071-4a72-b95c-4154acb12c38" + name="" + type="application/vnd.vmware.vcloud.vm+xml"/> + <User + href="https://vcloud.example.com/api/admin/user/1260efee-6915-494c-8afa-84e7e6d8a310" + name="system" + type="application/vnd.vmware.admin.user+xml"/> + <Organization + href="https://vcloud.example.com/api/org/7b832bc5-3d65-45a2-8d35-da28388ab80a" + name="Default" + type="application/vnd.vmware.vcloud.org+xml"/> + <Details/> +</Task> http://git-wip-us.apache.org/repos/asf/libcloud/blob/99188f79/libcloud/test/compute/fixtures/vcloud_1_5/api_task_fab4b26f_4f2e_4d49_ad01_ae9324bbfe48.xml ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/vcloud_1_5/api_task_fab4b26f_4f2e_4d49_ad01_ae9324bbfe48.xml b/libcloud/test/compute/fixtures/vcloud_1_5/api_task_fab4b26f_4f2e_4d49_ad01_ae9324bbfe48.xml new file mode 100644 index 0000000..d16cb7b --- /dev/null +++ b/libcloud/test/compute/fixtures/vcloud_1_5/api_task_fab4b26f_4f2e_4d49_ad01_ae9324bbfe48.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?><Task + xmlns="http://www.vmware.com/vcloud/v1.5" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + cancelRequested="false" + expiryTime="2013-05-15T13:10:11.652+03:00" + href="https://vcloud.example.com/api/task/fab4b26f-4f2e-4d49-ad01-ae9324bbfe48" + id="urn:vcloud:task:fab4b26f-4f2e-4d49-ad01-ae9324bbfe48" + name="task" + operation="Creating Snapshot Virtual Machine (ec94079b-3071-4a72-b95c-4154acb12c38)" + operationName="vappCreateSnapshot" + serviceNamespace="com.vmware.vcloud" + startTime="2013-02-14T13:10:11.652+02:00" + status="success" + type="application/vnd.vmware.vcloud.task+xml" + xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://https://vcloud.example.com/api/v1.5/schema/master.xsd"> + <Link + href="https://vcloud.example.com/api/task/fab4b26f-4f2e-4d49-ad01-ae9324bbfe48/action/cancel" + rel="task:cancel"/> + <Owner + href="https://vcloud.example.com/api/vApp/vm-ec94079b-3071-4a72-b95c-4154acb12c38" + name="" + type="application/vnd.vmware.vcloud.vm+xml"/> + <User + href="https://vcloud.example.com/api/admin/user/1260efee-6915-494c-8afa-84e7e6d8a310" + name="system" + type="application/vnd.vmware.admin.user+xml"/> + <Organization + href="https://vcloud.example.com/api/org/7b832bc5-3d65-45a2-8d35-da28388ab80a" + name="Default" + type="application/vnd.vmware.vcloud.org+xml"/> + <Details/> +</Task> http://git-wip-us.apache.org/repos/asf/libcloud/blob/99188f79/libcloud/test/compute/fixtures/vcloud_1_5/api_task_fe75d3af_f5a3_44a5_b016_ae0bdadfc32b.xml ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/vcloud_1_5/api_task_fe75d3af_f5a3_44a5_b016_ae0bdadfc32b.xml b/libcloud/test/compute/fixtures/vcloud_1_5/api_task_fe75d3af_f5a3_44a5_b016_ae0bdadfc32b.xml new file mode 100644 index 0000000..f91c144 --- /dev/null +++ b/libcloud/test/compute/fixtures/vcloud_1_5/api_task_fe75d3af_f5a3_44a5_b016_ae0bdadfc32b.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?><Task + xmlns="http://www.vmware.com/vcloud/v1.5" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + cancelRequested="false" + expiryTime="2013-05-15T13:10:20.999+03:00" + href="https://vcloud.example.com/api/task/fe75d3af-f5a3-44a5-b016-ae0bdadfc32b" + id="urn:vcloud:task:fe75d3af-f5a3-44a5-b016-ae0bdadfc32b" + name="task" + operation="Reverting to Snapshot Virtual Machine (ec94079b-3071-4a72-b95c-4154acb12c38)" + operationName="vappRevertToCurrentSnapshot" + serviceNamespace="com.vmware.vcloud" + startTime="2013-02-14T13:10:20.999+02:00" + status="success" + type="application/vnd.vmware.vcloud.task+xml" + xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://https://vcloud.example.com/api/v1.5/schema/master.xsd"> + <Link + href="https://vcloud.example.com/api/task/fe75d3af-f5a3-44a5-b016-ae0bdadfc32b/action/cancel" + rel="task:cancel"/> + <Owner + href="https://vcloud.example.com/api/vApp/vm-ec94079b-3071-4a72-b95c-4154acb12c38" + name="" + type="application/vnd.vmware.vcloud.vm+xml"/> + <User + href="https://vcloud.example.com/api/admin/user/1260efee-6915-494c-8afa-84e7e6d8a310" + name="system" + type="application/vnd.vmware.admin.user+xml"/> + <Organization + href="https://vcloud.example.com/api/org/7b832bc5-3d65-45a2-8d35-da28388ab80a" + name="Default" + type="application/vnd.vmware.vcloud.org+xml"/> + <Details/> +</Task> http://git-wip-us.apache.org/repos/asf/libcloud/blob/99188f79/libcloud/test/compute/fixtures/vcloud_1_5/api_vApp_vapp_8c57a5b6_e61b_48ca_8a78_3b70ee65ef6b_create_snapshot.xml ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/vcloud_1_5/api_vApp_vapp_8c57a5b6_e61b_48ca_8a78_3b70ee65ef6b_create_snapshot.xml b/libcloud/test/compute/fixtures/vcloud_1_5/api_vApp_vapp_8c57a5b6_e61b_48ca_8a78_3b70ee65ef6b_create_snapshot.xml new file mode 100644 index 0000000..8aab54d --- /dev/null +++ b/libcloud/test/compute/fixtures/vcloud_1_5/api_vApp_vapp_8c57a5b6_e61b_48ca_8a78_3b70ee65ef6b_create_snapshot.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?><Task + xmlns="http://www.vmware.com/vcloud/v1.5" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + cancelRequested="false" + expiryTime="2013-05-15T13:10:11.652+03:00" + href="https://vcloud.example.com/api/task/fab4b26f-4f2e-4d49-ad01-ae9324bbfe48" + id="urn:vcloud:task:fab4b26f-4f2e-4d49-ad01-ae9324bbfe48" + name="task" + operation="Creating Snapshot Virtual Machine (ec94079b-3071-4a72-b95c-4154acb12c38)" + operationName="vappCreateSnapshot" + serviceNamespace="com.vmware.vcloud" + startTime="2013-02-14T13:10:11.652+02:00" + status="running" + type="application/vnd.vmware.vcloud.task+xml" + xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://https://vcloud.example.com/api/v1.5/schema/master.xsd"> + <Link + href="https://vcloud.example.com/api/task/fab4b26f-4f2e-4d49-ad01-ae9324bbfe48/action/cancel" + rel="task:cancel"/> + <Owner + href="https://vcloud.example.com/api/vApp/vm-ec94079b-3071-4a72-b95c-4154acb12c38" + name="" + type="application/vnd.vmware.vcloud.vm+xml"/> + <User + href="https://vcloud.example.com/api/admin/user/1260efee-6915-494c-8afa-84e7e6d8a310" + name="system" + type="application/vnd.vmware.admin.user+xml"/> + <Organization + href="https://vcloud.example.com/api/org/7b832bc5-3d65-45a2-8d35-da28388ab80a" + name="Default" + type="application/vnd.vmware.vcloud.org+xml"/> + <Details/> +</Task> http://git-wip-us.apache.org/repos/asf/libcloud/blob/99188f79/libcloud/test/compute/fixtures/vcloud_1_5/api_vApp_vapp_8c57a5b6_e61b_48ca_8a78_3b70ee65ef6b_remove_snapshots.xml ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/vcloud_1_5/api_vApp_vapp_8c57a5b6_e61b_48ca_8a78_3b70ee65ef6b_remove_snapshots.xml b/libcloud/test/compute/fixtures/vcloud_1_5/api_vApp_vapp_8c57a5b6_e61b_48ca_8a78_3b70ee65ef6b_remove_snapshots.xml new file mode 100644 index 0000000..3ff17de --- /dev/null +++ b/libcloud/test/compute/fixtures/vcloud_1_5/api_vApp_vapp_8c57a5b6_e61b_48ca_8a78_3b70ee65ef6b_remove_snapshots.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?><Task + xmlns="http://www.vmware.com/vcloud/v1.5" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + cancelRequested="false" + expiryTime="2013-05-15T13:10:25.449+03:00" + href="https://vcloud.example.com/api/task/2518935e-b315-4d8e-9e99-9275f751877c" + id="urn:vcloud:task:2518935e-b315-4d8e-9e99-9275f751877c" + name="task" + operation="Removing Snapshot Virtual Machine (ec94079b-3071-4a72-b95c-4154acb12c38)" + operationName="vappRemoveAllSnapshots" + serviceNamespace="com.vmware.vcloud" + startTime="2013-02-14T13:10:25.449+02:00" + status="running" + type="application/vnd.vmware.vcloud.task+xml" + xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://https://vcloud.example.com/api/v1.5/schema/master.xsd"> + <Link + href="https://vcloud.example.com/api/task/2518935e-b315-4d8e-9e99-9275f751877c/action/cancel" + rel="task:cancel"/> + <Owner + href="https://vcloud.example.com/api/vApp/vm-ec94079b-3071-4a72-b95c-4154acb12c38" + name="" + type="application/vnd.vmware.vcloud.vm+xml"/> + <User + href="https://vcloud.example.com/api/admin/user/1260efee-6915-494c-8afa-84e7e6d8a310" + name="system" + type="application/vnd.vmware.admin.user+xml"/> + <Organization + href="https://vcloud.example.com/api/org/7b832bc5-3d65-45a2-8d35-da28388ab80a" + name="Default" + type="application/vnd.vmware.vcloud.org+xml"/> + <Details/> +</Task> http://git-wip-us.apache.org/repos/asf/libcloud/blob/99188f79/libcloud/test/compute/fixtures/vcloud_1_5/api_vApp_vapp_8c57a5b6_e61b_48ca_8a78_3b70ee65ef6b_revert_snapshot.xml ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/vcloud_1_5/api_vApp_vapp_8c57a5b6_e61b_48ca_8a78_3b70ee65ef6b_revert_snapshot.xml b/libcloud/test/compute/fixtures/vcloud_1_5/api_vApp_vapp_8c57a5b6_e61b_48ca_8a78_3b70ee65ef6b_revert_snapshot.xml new file mode 100644 index 0000000..f91c144 --- /dev/null +++ b/libcloud/test/compute/fixtures/vcloud_1_5/api_vApp_vapp_8c57a5b6_e61b_48ca_8a78_3b70ee65ef6b_revert_snapshot.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?><Task + xmlns="http://www.vmware.com/vcloud/v1.5" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + cancelRequested="false" + expiryTime="2013-05-15T13:10:20.999+03:00" + href="https://vcloud.example.com/api/task/fe75d3af-f5a3-44a5-b016-ae0bdadfc32b" + id="urn:vcloud:task:fe75d3af-f5a3-44a5-b016-ae0bdadfc32b" + name="task" + operation="Reverting to Snapshot Virtual Machine (ec94079b-3071-4a72-b95c-4154acb12c38)" + operationName="vappRevertToCurrentSnapshot" + serviceNamespace="com.vmware.vcloud" + startTime="2013-02-14T13:10:20.999+02:00" + status="success" + type="application/vnd.vmware.vcloud.task+xml" + xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://https://vcloud.example.com/api/v1.5/schema/master.xsd"> + <Link + href="https://vcloud.example.com/api/task/fe75d3af-f5a3-44a5-b016-ae0bdadfc32b/action/cancel" + rel="task:cancel"/> + <Owner + href="https://vcloud.example.com/api/vApp/vm-ec94079b-3071-4a72-b95c-4154acb12c38" + name="" + type="application/vnd.vmware.vcloud.vm+xml"/> + <User + href="https://vcloud.example.com/api/admin/user/1260efee-6915-494c-8afa-84e7e6d8a310" + name="system" + type="application/vnd.vmware.admin.user+xml"/> + <Organization + href="https://vcloud.example.com/api/org/7b832bc5-3d65-45a2-8d35-da28388ab80a" + name="Default" + type="application/vnd.vmware.vcloud.org+xml"/> + <Details/> +</Task> http://git-wip-us.apache.org/repos/asf/libcloud/blob/99188f79/libcloud/test/compute/test_vcloud.py ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/test_vcloud.py b/libcloud/test/compute/test_vcloud.py index fc801be..6cbf700 100644 --- a/libcloud/test/compute/test_vcloud.py +++ b/libcloud/test/compute/test_vcloud.py @@ -26,6 +26,7 @@ from libcloud.utils.py3 import httplib, b from libcloud.compute.drivers.vcloud import TerremarkDriver, VCloudNodeDriver, Subject from libcloud.compute.drivers.vcloud import VCloud_1_5_NodeDriver, ControlAccess from libcloud.compute.drivers.vcloud import VCloud_5_1_NodeDriver +from libcloud.compute.drivers.vcloud import VCloud_5_5_NodeDriver from libcloud.compute.drivers.vcloud import Vdc from libcloud.compute.base import Node, NodeImage from libcloud.compute.types import NodeState @@ -392,6 +393,37 @@ class VCloud_5_1_Tests(unittest.TestCase, TestCaseMixin): 'https://vm-vcloud/api/vAppTemplate/vappTemplate-ac1bc027-bf8c-4050-8643-4971f691c158', ret[0].id) +class VCloud_5_5_Tests(unittest.TestCase, TestCaseMixin): + + def setUp(self): + VCloudNodeDriver.connectionCls.host = 'test' + VCloudNodeDriver.connectionCls.conn_classes = ( + None, VCloud_5_5_MockHttp) + VCloud_5_5_MockHttp.type = None + self.driver = VCloudNodeDriver( + *VCLOUD_PARAMS, **{'api_version': '5.5'}) + + self.assertTrue(isinstance(self.driver, VCloud_5_5_NodeDriver)) + + def test_ex_create_snapshot(self): + node = Node( + 'https://vm-vcloud/api/vApp/vapp-8c57a5b6-e61b-48ca-8a78-3b70ee65ef6b', + 'testNode', NodeState.RUNNING, [], [], self.driver) + self.driver.ex_create_snapshot(node) + + def test_ex_remove_snapshots(self): + node = Node( + 'https://vm-vcloud/api/vApp/vapp-8c57a5b6-e61b-48ca-8a78-3b70ee65ef6b', + 'testNode', NodeState.RUNNING, [], [], self.driver) + self.driver.ex_remove_snapshots(node) + + def test_ex_revert_to_snapshot(self): + node = Node( + 'https://vm-vcloud/api/vApp/vapp-8c57a5b6-e61b-48ca-8a78-3b70ee65ef6b', + 'testNode', NodeState.RUNNING, [], [], self.driver) + self.driver.ex_revert_to_snapshot(node) + + class TerremarkMockHttp(MockHttp): fixtures = ComputeFileFixtures('terremark') @@ -713,5 +745,42 @@ class VCloud_1_5_MockHttp(MockHttp, unittest.TestCase): return httplib.OK, body, headers, httplib.responses[httplib.OK] +class VCloud_5_5_MockHttp(VCloud_1_5_MockHttp): + # TODO: Move 5.5 fixtures to their own folder + + def _api_vApp_vapp_8c57a5b6_e61b_48ca_8a78_3b70ee65ef6b_action_createSnapshot(self, method, url, body, headers): + assert method == 'POST' + body = self.fixtures.load( + 'api_vApp_vapp_8c57a5b6_e61b_48ca_8a78_3b70ee65ef6b_create_snapshot.xml') + return httplib.OK, body, headers, httplib.responses[httplib.OK] + + def _api_task_fab4b26f_4f2e_4d49_ad01_ae9324bbfe48(self, method, url, body, headers): + body = self.fixtures.load( + 'api_task_b034df55_fe81_4798_bc81_1f0fd0ead450.xml') + return httplib.OK, body, headers, httplib.responses[httplib.OK] + + def _api_vApp_vapp_8c57a5b6_e61b_48ca_8a78_3b70ee65ef6b_action_removeAllSnapshots(self, method, url, body, headers): + assert method == 'POST' + body = self.fixtures.load( + 'api_vApp_vapp_8c57a5b6_e61b_48ca_8a78_3b70ee65ef6b_remove_snapshots.xml') + return httplib.OK, body, headers, httplib.responses[httplib.OK] + + def _api_task_2518935e_b315_4d8e_9e99_9275f751877c(self, method, url, body, headers): + body = self.fixtures.load( + 'api_task_2518935e_b315_4d8e_9e99_9275f751877c.xml') + return httplib.OK, body, headers, httplib.responses[httplib.OK] + + def _api_vApp_vapp_8c57a5b6_e61b_48ca_8a78_3b70ee65ef6b_action_revertToCurrentSnapshot(self, method, url, body, headers): + assert method == 'POST' + body = self.fixtures.load( + 'api_vApp_vapp_8c57a5b6_e61b_48ca_8a78_3b70ee65ef6b_revert_snapshot.xml') + return httplib.OK, body, headers, httplib.responses[httplib.OK] + + def _api_task_fe75d3af_f5a3_44a5_b016_ae0bdadfc32b(self, method, url, body, headers): + body = self.fixtures.load( + 'api_task_fe75d3af_f5a3_44a5_b016_ae0bdadfc32b.xml') + return httplib.OK, body, headers, httplib.responses[httplib.OK] + + if __name__ == '__main__': sys.exit(unittest.main())