|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | +""" P1 tests for Scaling up Vm |
| 18 | +""" |
| 19 | +# Import Local Modules |
| 20 | +from marvin.cloudstackTestCase import cloudstackTestCase |
| 21 | +from marvin.lib.base import (VirtualMachine, Volume, ServiceOffering, Template) |
| 22 | +from marvin.lib.common import (get_zone, get_domain) |
| 23 | +from nose.plugins.attrib import attr |
| 24 | + |
| 25 | +_multiprocess_shared_ = True |
| 26 | + |
| 27 | + |
| 28 | +class TestRestoreVM(cloudstackTestCase): |
| 29 | + |
| 30 | + @classmethod |
| 31 | + def setUpClass(cls): |
| 32 | + testClient = super(TestRestoreVM, cls).getClsTestClient() |
| 33 | + cls.apiclient = testClient.getApiClient() |
| 34 | + cls.services = testClient.getParsedTestDataConfig() |
| 35 | + |
| 36 | + # Get Zone, Domain and templates |
| 37 | + cls.domain = get_domain(cls.apiclient) |
| 38 | + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) |
| 39 | + cls.hypervisor = testClient.getHypervisorInfo() |
| 40 | + cls.services['mode'] = cls.zone.networktype |
| 41 | + |
| 42 | + cls.services["virtual_machine"]["zoneid"] = cls.zone.id |
| 43 | + |
| 44 | + cls.service_offering = ServiceOffering.create(cls.apiclient, cls.services["service_offering"]) |
| 45 | + |
| 46 | + cls.template_t1 = Template.register(cls.apiclient, cls.services["test_templates"][ |
| 47 | + cls.hypervisor.lower() if cls.hypervisor.lower() != 'simulator' else 'xenserver'], |
| 48 | + zoneid=cls.zone.id, hypervisor=cls.hypervisor.lower()) |
| 49 | + |
| 50 | + cls.template_t2 = Template.register(cls.apiclient, cls.services["test_templates"][ |
| 51 | + cls.hypervisor.lower() if cls.hypervisor.lower() != 'simulator' else 'xenserver'], |
| 52 | + zoneid=cls.zone.id, hypervisor=cls.hypervisor.lower()) |
| 53 | + |
| 54 | + cls._cleanup = [cls.service_offering, cls.template_t1, cls.template_t2] |
| 55 | + |
| 56 | + @classmethod |
| 57 | + def tearDownClass(cls): |
| 58 | + super(TestRestoreVM, cls).tearDownClass() |
| 59 | + return |
| 60 | + |
| 61 | + @attr(tags=["advanced", "basic"], required_hardware="false") |
| 62 | + def test_01_restore_vm(self): |
| 63 | + """Test restore virtual machine |
| 64 | + """ |
| 65 | + # create a virtual machine |
| 66 | + virtual_machine = VirtualMachine.create(self.apiclient, self.services["virtual_machine"], zoneid=self.zone.id, |
| 67 | + templateid=self.template_t1.id, |
| 68 | + serviceofferingid=self.service_offering.id) |
| 69 | + self._cleanup.append(virtual_machine) |
| 70 | + |
| 71 | + root_vol = Volume.list(self.apiclient, virtualmachineid=virtual_machine.id)[0] |
| 72 | + self.assertEqual(root_vol.state, 'Ready', "Volume should be in Ready state") |
| 73 | + self.assertEqual(root_vol.size, self.template_t1.size, "Size of volume and template should match") |
| 74 | + |
| 75 | + virtual_machine.restore(self.apiclient, self.template_t2.id) |
| 76 | + restored_vm = VirtualMachine.list(self.apiclient, id=virtual_machine.id)[0] |
| 77 | + self.assertEqual(restored_vm.state, 'Running', "VM should be in a running state") |
| 78 | + self.assertEqual(restored_vm.templateid, self.template_t2.id, "VM's template after restore is incorrect") |
| 79 | + root_vol = Volume.list(self.apiclient, virtualmachineid=restored_vm.id)[0] |
| 80 | + self.assertEqual(root_vol.state, 'Ready', "Volume should be in Ready state") |
| 81 | + self.assertEqual(root_vol.size, self.template_t2.size, "Size of volume and template should match") |
| 82 | + |
| 83 | + @attr(tags=["advanced", "basic"], required_hardware="false") |
| 84 | + def test_02_restore_vm_allocated_root(self): |
| 85 | + """Test restore virtual machine with root disk in allocated state |
| 86 | + """ |
| 87 | + # create a virtual machine with allocated root disk by setting startvm=False |
| 88 | + virtual_machine = VirtualMachine.create(self.apiclient, self.services["virtual_machine"], zoneid=self.zone.id, |
| 89 | + templateid=self.template_t1.id, |
| 90 | + serviceofferingid=self.service_offering.id, |
| 91 | + startvm=False) |
| 92 | + self._cleanup.append(virtual_machine) |
| 93 | + root_vol = Volume.list(self.apiclient, virtualmachineid=virtual_machine.id)[0] |
| 94 | + self.assertEqual(root_vol.state, 'Allocated', "Volume should be in Allocated state") |
| 95 | + self.assertEqual(root_vol.size, self.template_t1.size, "Size of volume and template should match") |
| 96 | + |
| 97 | + virtual_machine.restore(self.apiclient, self.template_t2.id) |
| 98 | + restored_vm = VirtualMachine.list(self.apiclient, id=virtual_machine.id)[0] |
| 99 | + self.assertEqual(restored_vm.state, 'Stopped', "Check the state of VM") |
| 100 | + self.assertEqual(restored_vm.templateid, self.template_t2.id, "Check the template of VM") |
| 101 | + |
| 102 | + root_vol = Volume.list(self.apiclient, virtualmachineid=restored_vm.id)[0] |
| 103 | + self.assertEqual(root_vol.state, 'Allocated', "Volume should be in Allocated state") |
| 104 | + self.assertEqual(root_vol.size, self.template_t2.size, "Size of volume and template should match") |
| 105 | + |
| 106 | + virtual_machine.start(self.apiclient) |
| 107 | + root_vol = Volume.list(self.apiclient, virtualmachineid=restored_vm.id)[0] |
| 108 | + self.assertEqual(root_vol.state, 'Ready', "Volume should be in Ready state") |
0 commit comments