|
| 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 | + |
| 18 | +#Import Local Modules |
| 19 | +from marvin.cloudstackTestCase import cloudstackTestCase |
| 20 | +from marvin.lib.utils import (cleanup_resources, |
| 21 | + validateList, |
| 22 | + get_hypervisor_type) |
| 23 | +from marvin.lib.base import (Account, |
| 24 | + VirtualMachine, |
| 25 | + ServiceOffering, |
| 26 | + Volume, |
| 27 | + DiskOffering, |
| 28 | + Template, |
| 29 | + Configurations) |
| 30 | +from marvin.lib.common import (get_domain, |
| 31 | + get_zone, |
| 32 | + get_template) |
| 33 | +from nose.plugins.attrib import attr |
| 34 | +from marvin.codes import PASS |
| 35 | +from marvin.sshClient import SshClient |
| 36 | +import time |
| 37 | + |
| 38 | +class TestInstance(cloudstackTestCase): |
| 39 | + |
| 40 | + @classmethod |
| 41 | + def setUpClass(cls): |
| 42 | + try: |
| 43 | + cls._cleanup = [] |
| 44 | + cls.testClient = super(TestInstance, cls).getClsTestClient() |
| 45 | + cls.api_client = cls.testClient.getApiClient() |
| 46 | + cls.services = cls.testClient.getParsedTestDataConfig() |
| 47 | + # Get Domain, Zone, Template |
| 48 | + cls.domain = get_domain(cls.api_client) |
| 49 | + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) |
| 50 | + cls.template = get_template( |
| 51 | + cls.api_client, |
| 52 | + cls.zone.id, |
| 53 | + cls.services["ostype"] |
| 54 | + ) |
| 55 | + if cls.zone.localstorageenabled: |
| 56 | + cls.storagetype = 'local' |
| 57 | + cls.services["service_offerings"]["tiny"]["storagetype"] = 'local' |
| 58 | + cls.services["disk_offering"]["storagetype"] = 'local' |
| 59 | + else: |
| 60 | + cls.storagetype = 'shared' |
| 61 | + cls.services["service_offerings"]["tiny"]["storagetype"] = 'shared' |
| 62 | + cls.services["disk_offering"]["storagetype"] = 'shared' |
| 63 | + |
| 64 | + cls.services['mode'] = cls.zone.networktype |
| 65 | + cls.services["virtual_machine"]["hypervisor"] = cls.testClient.getHypervisorInfo() |
| 66 | + cls.services["virtual_machine"]["zoneid"] = cls.zone.id |
| 67 | + cls.services["virtual_machine"]["template"] = cls.template.id |
| 68 | + cls.services["custom_volume"]["zoneid"] = cls.zone.id |
| 69 | + # Creating Disk offering, Service Offering and Account |
| 70 | + cls.disk_offering = DiskOffering.create( |
| 71 | + cls.api_client, |
| 72 | + cls.services["disk_offering"] |
| 73 | + ) |
| 74 | + cls.service_offering = ServiceOffering.create( |
| 75 | + cls.api_client, |
| 76 | + cls.services["service_offerings"]["small"] |
| 77 | + ) |
| 78 | + cls.account = Account.create( |
| 79 | + cls.api_client, |
| 80 | + cls.services["account"], |
| 81 | + domainid=cls.domain.id |
| 82 | + ) |
| 83 | + # Getting authentication for user in newly created Account |
| 84 | + cls.user = cls.account.user[0] |
| 85 | + cls.userapiclient = cls.testClient.getUserApiClient(cls.user.username, cls.domain.name) |
| 86 | + cls._cleanup.append(cls.disk_offering) |
| 87 | + cls._cleanup.append(cls.service_offering) |
| 88 | + cls._cleanup.append(cls.account) |
| 89 | + cls.mgtSvrDetails = cls.config.__dict__["mgtSvr"][0].__dict__ |
| 90 | + except Exception as e: |
| 91 | + cls.tearDownClass() |
| 92 | + raise Exception("Warning: Exception in setup : %s" % e) |
| 93 | + return |
| 94 | + |
| 95 | + def setUp(self): |
| 96 | + |
| 97 | + self.apiClient = self.testClient.getApiClient() |
| 98 | + self.cleanup = [] |
| 99 | + |
| 100 | + def tearDown(self): |
| 101 | + #Clean up, terminate the created volumes |
| 102 | + cleanup_resources(self.apiClient, self.cleanup) |
| 103 | + return |
| 104 | + |
| 105 | + @classmethod |
| 106 | + def tearDownClass(cls): |
| 107 | + try: |
| 108 | + cleanup_resources(cls.api_client, cls._cleanup) |
| 109 | + except Exception as e: |
| 110 | + raise Exception("Warning: Exception during cleanup : %s" % e) |
| 111 | + |
| 112 | + def RestartServers(self): |
| 113 | + """ Restart management server and usage server """ |
| 114 | + |
| 115 | + sshClient = SshClient( |
| 116 | + self.mgtSvrDetails["mgtSvrIp"], |
| 117 | + 22, |
| 118 | + self.mgtSvrDetails["user"], |
| 119 | + self.mgtSvrDetails["passwd"] |
| 120 | + ) |
| 121 | + command = "service cloudstack-management restart" |
| 122 | + sshClient.execute(command) |
| 123 | + return |
| 124 | + |
| 125 | + def updateConfigurAndRestart(self,name, value): |
| 126 | + Configurations.update(self.apiClient, |
| 127 | + name,value ) |
| 128 | + self.RestartServers() |
| 129 | + time.sleep(self.services["sleep"]) |
| 130 | + |
| 131 | + @attr(tags=["advanced"], required_hardware="true") |
| 132 | + def test1_attach_volume(self): |
| 133 | + """ |
| 134 | + @desc: Unable to attach 7th Disk to windows server 2012R2 instance. Add a valid windows server 2012 URL to execute this test case |
| 135 | + Step1: Set global config vmware.root.disk.controller to 'osdefault' |
| 136 | + Step2: Deploy a Windows 2012 R2 instance. |
| 137 | + Step3: Attach 6 disks to the VM. |
| 138 | + Step4: Try attaching a 7th disk to the VM |
| 139 | + Verify that step4 succeeds without any exception |
| 140 | + """ |
| 141 | + self.hypervisor = str(get_hypervisor_type(self.api_client)).lower() |
| 142 | + if self.hypervisor != "vmware": |
| 143 | + self.skipTest("This test can be run only on vmware") |
| 144 | + self.updateConfigurAndRestart("vmware.root.disk.controller","osdefault") |
| 145 | + |
| 146 | + self.services["Windows Server 2012"]["url"]="http://10.147.28.7/templates/Windows2012/WindowsServer2012R2.ova.gz", |
| 147 | + template = Template.register( |
| 148 | + self.userapiclient, |
| 149 | + self.services["Windows Server 2012"], |
| 150 | + zoneid=self.zone.id, |
| 151 | + account=self.account.name, |
| 152 | + domainid=self.account.domainid |
| 153 | + ) |
| 154 | + self.assertIsNotNone(template,"Failed to register Windows server 2012 R2 template") |
| 155 | + self.debug( |
| 156 | + "Registered a template with format {} and id {}".format( |
| 157 | + self.services["Windows Server 2012"]["format"],template.id) |
| 158 | + ) |
| 159 | + template.download(self.userapiclient) |
| 160 | + self.cleanup.append(template) |
| 161 | + |
| 162 | + # Creating a big service offering for windows VM launch |
| 163 | + big_service_offering = ServiceOffering.create( |
| 164 | + self.apiClient, |
| 165 | + self.services["service_offerings"]["big"] |
| 166 | + ) |
| 167 | + self.cleanup.append(big_service_offering) |
| 168 | + vm = VirtualMachine.create( |
| 169 | + self.userapiclient, |
| 170 | + self.services["virtual_machine"], |
| 171 | + accountid=self.account.name, |
| 172 | + domainid=self.account.domainid, |
| 173 | + serviceofferingid=big_service_offering.id, |
| 174 | + templateid=template.id, |
| 175 | + zoneid=self.zone.id |
| 176 | + ) |
| 177 | + self.assertIsNotNone(vm,"Failed to deploy virtual machine") |
| 178 | + self.cleanup.append(vm) |
| 179 | + response = VirtualMachine.list(self.userapiclient,id=vm.id) |
| 180 | + status = validateList(response) |
| 181 | + self.assertEqual(status[0],PASS,"list vm response returned invalid list") |
| 182 | + |
| 183 | + for i in range(0,7): |
| 184 | + self.services["volume"]["diskname"]=i |
| 185 | + disk = Volume.create( |
| 186 | + self.userapiclient, |
| 187 | + self.services["volume"], |
| 188 | + zoneid=self.zone.id, |
| 189 | + diskofferingid=self.disk_offering.id |
| 190 | + ) |
| 191 | + self.assertIsNotNone(disk,"Failed to create custom volume") |
| 192 | + self.cleanup.append(disk) |
| 193 | + try: |
| 194 | + vm.attach_volume(self.userapiclient,disk) |
| 195 | + list_volumes = Volume.list( |
| 196 | + self.userapiclient, |
| 197 | + listall=self.services["listall"], |
| 198 | + id=disk.id |
| 199 | + ) |
| 200 | + |
| 201 | + attached_volume = list_volumes[0] |
| 202 | + self.assertEqual( |
| 203 | + disk.id, |
| 204 | + attached_volume.id, |
| 205 | + "list volume response does not match with the volume created and attached to vm" |
| 206 | + ) |
| 207 | + except Exception as e: |
| 208 | + self.fail("Failed to attach {} data disk to Windows server 2012 R2 vm ".format(i)) |
| 209 | + return |
| 210 | + @attr(tags=["advanced"], required_hardware="true") |
| 211 | + def test_Scale_VM(self): |
| 212 | + """ |
| 213 | + @desc: |
| 214 | + 1. Enable dynamic scaling in Global settings |
| 215 | + 2. Register an CentOS 7 tempplate(with tools) and tick dynamic scaling |
| 216 | + 3. Deploy VM with this template |
| 217 | + 4.Start the VM and try to change service offering |
| 218 | +
|
| 219 | + """ |
| 220 | + self.hypervisor = str(get_hypervisor_type(self.api_client)).lower() |
| 221 | + if self.hypervisor != "xenserver": |
| 222 | + self.skipTest("This test can be run only on xenserver") |
| 223 | + self.updateConfigurAndRestart("enable.dynamic.scale.vm","true") |
| 224 | + template = Template.register( |
| 225 | + self.userapiclient, |
| 226 | + self.services["CentOS7template"], |
| 227 | + zoneid=self.zone.id, |
| 228 | + account=self.account.name, |
| 229 | + domainid=self.account.domainid |
| 230 | + ) |
| 231 | + self.assertIsNotNone(template,"Failed to register CentOS 7 template") |
| 232 | + self.debug( |
| 233 | + "Registered a template with format {} and id {}".format( |
| 234 | + self.services["CentOS7template"]["format"],template.id) |
| 235 | + ) |
| 236 | + template.download(self.userapiclient) |
| 237 | + self.cleanup.append(template) |
| 238 | + vm = VirtualMachine.create( |
| 239 | + self.userapiclient, |
| 240 | + self.services["virtual_machine"], |
| 241 | + accountid=self.account.name, |
| 242 | + domainid=self.account.domainid, |
| 243 | + serviceofferingid=self.service_offering.id, |
| 244 | + templateid=template.id, |
| 245 | + zoneid=self.zone.id |
| 246 | + ) |
| 247 | + self.assertIsNotNone(vm,"Failed to deploy virtual machine") |
| 248 | + self.cleanup.append(vm) |
| 249 | + response = VirtualMachine.list(self.userapiclient,id=vm.id) |
| 250 | + status = validateList(response) |
| 251 | + self.assertEqual(status[0],PASS,"list vm response returned invalid list") |
| 252 | + self.assertEqual(status[1].state,"Running", "vm is not running") |
| 253 | + |
| 254 | + service_offering = ServiceOffering.create( |
| 255 | + self.apiClient, |
| 256 | + self.services["service_offerings"]["big"] |
| 257 | + ) |
| 258 | + time.sleep(self.services["sleep"]) |
| 259 | + vm.scale(self.userapiclient,service_offering.id) |
| 260 | + scaleresponse = VirtualMachine.list(self.userapiclient,id=vm.id) |
| 261 | + scalestatus = validateList(scaleresponse) |
| 262 | + self.assertEqual(scalestatus[0],PASS,"list vm response returned invalid list") |
| 263 | + self.assertEqual(scalestatus[1].serviceofferingname,service_offering.name, " service offering is not same") |
| 264 | + self.assertEqual(scalestatus[1].serviceofferingid,service_offering.id, " service offering ids are not same") |
| 265 | + |
| 266 | + |
| 267 | + return |
0 commit comments