From 9358a9781bdd1ca9683146882973badc0afe4289 Mon Sep 17 00:00:00 2001 From: Chirag Jog Date: Mon, 25 Jun 2012 18:42:54 +0530 Subject: [PATCH] Adding VM in stopped state tests --- test/integration/component/test_stopped_vm.py | 1876 +++++++++++++++++ test/integration/lib/base.py | 60 +- 2 files changed, 1935 insertions(+), 1 deletion(-) create mode 100644 test/integration/component/test_stopped_vm.py diff --git a/test/integration/component/test_stopped_vm.py b/test/integration/component/test_stopped_vm.py new file mode 100644 index 00000000000..2ff2f811148 --- /dev/null +++ b/test/integration/component/test_stopped_vm.py @@ -0,0 +1,1876 @@ +# -*- encoding: utf-8 -*- +# Copyright 2012 Citrix Systems, Inc. Licensed under the +# Apache License, Version 2.0 (the "License"); you may not use this +# file except in compliance with the License. Citrix Systems, Inc. +# reserves all rights not expressly granted by the License. +# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Automatically generated by addcopyright.py at 04/03/2012 + +""" P1 for stopped Virtual Maschine life cycle +""" +#Import Local Modules +import marvin +from marvin.cloudstackTestCase import * +from marvin.cloudstackAPI import * +from marvin.remoteSSHClient import remoteSSHClient +from integration.lib.utils import * +from integration.lib.base import * +from integration.lib.common import * +#Import System modules +import time + +class Services: + """Test Stopped VM Life Cycle Services + """ + + def __init__(self): + self.services = { + "account": { + "email": "test@test.com", + "firstname": "Test", + "lastname": "User", + "username": "test", + # Random characters are appended in create account to + # ensure unique username generated each time + "password": "password", + }, + "virtual_machine": + { + "displayname": "testserver", + "username": "root", # VM creds for SSH + "password": "password", + "ssh_port": 22, + "hypervisor": 'XenServer', + "privateport": 22, + "publicport": 22, + "protocol": 'TCP', + }, + "service_offering": + { + "name": "Tiny Instance", + "displaytext": "Tiny Instance", + "cpunumber": 1, + "cpuspeed": 100, # in MHz + "memory": 128, # In MBs + }, + "disk_offering": { + "displaytext": "Small volume", + "name": "Small volume", + "disksize": 20 + }, + "volume": { + "diskname": "DataDisk", + "url": '', + "format": 'VHD' + }, + "iso": # ISO settings for Attach/Detach ISO tests + { + "displaytext": "Test ISO", + "name": "testISO", + "url": "http://nfs1.lab.vmops.com/isos_32bit/dsl-4.4.10.iso", + # Source URL where ISO is located + "ostypeid": '19e6a39f-92db-4d2c-b375-33e7f42d86be', + "mode": 'HTTP_DOWNLOAD', # Downloading existing ISO + }, + "template": { + "url": "http://download.cloud.com/releases/2.0.0/UbuntuServer-10-04-64bit.vhd.bz2", + "hypervisor": 'XenServer', + "format" : 'VHD', + "isfeatured": True, + "ispublic": True, + "isextractable": True, + "displaytext": "Cent OS Template", + "name": "Cent OS Template", + "ostypeid": '19e6a39f-92db-4d2c-b375-33e7f42d86be', + "templatefilter": 'self', + "passwordenabled": True, + }, + "sleep": 60, + "timeout": 10, + #Migrate VM to hostid + "ostypeid": '19e6a39f-92db-4d2c-b375-33e7f42d86be', + # CentOS 5.3 (64-bit) + } + + +class TestDeployVM(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + + cls.api_client = super( + TestDeployVM, + cls + ).getClsTestClient().getApiClient() + cls.services = Services().services + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.services) + + cls.template = get_template( + cls.api_client, + cls.zone.id, + cls.services["ostypeid"] + ) + + # Create service offerings, disk offerings etc + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) + cls.disk_offering = DiskOffering.create( + cls.api_client, + cls.services["disk_offering"] + ) + # Cleanup + cls._cleanup = [ + cls.service_offering, + cls.disk_offering, + ] + return + + @classmethod + def tearDownClass(cls): + try: + cleanup_resources(cls.api_client, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + + def setUp(self): + + self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.services = Services().services + self.services["virtual_machine"]["zoneid"] = self.zone.id + self.services["iso"]["zoneid"] = self.zone.id + self.services["virtual_machine"]["template"] = self.template.id + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id + ) + self.cleanup = [self.account] + return + + def tearDown(self): + try: + self.debug("Cleaning up the resources") + cleanup_resources(self.apiclient, self.cleanup) + self.debug("Cleanup complete!") + except Exception as e: + self.debug("Warning! Exception in tearDown: %s" % e) + + def test_01_deploy_vm_no_startvm(self): + """Test Deploy Virtual Machine with no startVM parameter + """ + + # Validate the following: + # 1. deploy Vm without specifying the startvm parameter + # 2. Should be able to login to the VM. + # 3. listVM command should return the deployed VM.State of this VM + # should be "Running". + + self.debug("Deploying instance in the account: %s" % + self.account.account.name) + self.virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.account.name, + domainid=self.account.account.domainid, + serviceofferingid=self.service_offering.id, + diskofferingid=self.disk_offering.id, + mode=self.zone.networktype + ) + + self.debug("Deployed instance in account: %s" % + self.account.account.name) + list_vm_response = list_virtual_machines( + self.apiclient, + id=self.virtual_machine.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % self.virtual_machine.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + + vm_response.state, + "Running", + "VM should be in Running state after deployment" + ) + try: + ssh = self.virtual_machine.get_ssh_client() + except Exception as e: + self.fail("SSH to VM instance failed!") + return + + def test_02_deploy_vm_startvm_true(self): + """Test Deploy Virtual Machine with startVM=true parameter + """ + + # Validate the following: + # 1. deploy Vm with the startvm=true + # 2. Should be able to login to the VM. + # 3. listVM command should return the deployed VM.State of this VM + # should be "Running". + + self.debug("Deploying instance in the account: %s" % + self.account.account.name) + self.virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.account.name, + domainid=self.account.account.domainid, + serviceofferingid=self.service_offering.id, + startvm=True, + diskofferingid=self.disk_offering.id, + mode=self.zone.networktype + ) + + self.debug("Deployed instance in account: %s" % + self.account.account.name) + list_vm_response = list_virtual_machines( + self.apiclient, + id=self.virtual_machine.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % self.virtual_machine.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + + vm_response.state, + "Running", + "VM should be in Running state after deployment" + ) + try: + ssh = self.virtual_machine.get_ssh_client() + except Exception as e: + self.fail("SSH to VM instance failed!") + return + + def test_03_deploy_vm_startvm_false(self): + """Test Deploy Virtual Machine with startVM=false parameter + """ + + # Validate the following: + # 1. deploy Vm with the startvm=false + # 2. Should not be able to login to the VM. + # 3. listVM command should return the deployed VM.State of this VM + # should be "Stopped". + # 4. Check listRouters call for that account. List routers should + # return empty response + + self.debug("Deploying instance in the account: %s" % + self.account.account.name) + self.virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.account.name, + domainid=self.account.account.domainid, + serviceofferingid=self.service_offering.id, + startvm=False, + diskofferingid=self.disk_offering.id, + ) + + self.debug("Deployed instance in account: %s" % + self.account.account.name) + list_vm_response = list_virtual_machines( + self.apiclient, + id=self.virtual_machine.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % self.virtual_machine.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Stopped", + "VM should be in Stopped state after deployment with startvm=false" + ) + routers = Router.list( + self.apiclient, + account=self.account.account.name, + domainid=self.account.account.domainid, + listall=True + ) + self.assertEqual( + routers, + None, + "List routers should return empty response" + ) + self.debug("Destroying instance: %s" % self.virtual_machine.name) + self.virtual_machine.delete(self.apiclient) + self.debug("Instance is destroyed!") + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % self.virtual_machine.id + ) + self.debug("Instance destroyed..waiting till expunge interval") + + interval = list_configurations( + self.apiclient, + name='expunge.interval' + ) + delay = list_configurations( + self.apiclient, + name='expunge.delay' + ) + # Sleep to ensure that all resources are deleted + time.sleep((int(interval[0].value) + int(delay[0].value))) + list_vm_response = list_virtual_machines( + self.apiclient, + id=self.virtual_machine.id + ) + + self.assertEqual( + list_vm_response, + None, + "Check list response returns a valid list" + ) + return + + def test_04_deploy_startvm_false_attach_volume(self): + """Test Deploy Virtual Machine with startVM=false and attach volume + """ + + # Validate the following: + # 1. deploy Vm with the startvm=false. Attach volume to the instance + # 2. listVM command should return the deployed VM.State of this VM + # should be "Stopped". + # 3. Attach volume should be successful + + self.debug("Deploying instance in the account: %s" % + self.account.account.name) + self.virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.account.name, + domainid=self.account.account.domainid, + serviceofferingid=self.service_offering.id, + startvm=False, + diskofferingid=self.disk_offering.id, + ) + + self.debug("Deployed instance in account: %s" % + self.account.account.name) + list_vm_response = list_virtual_machines( + self.apiclient, + id=self.virtual_machine.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % self.virtual_machine.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Stopped", + "VM should be in Stopped state after deployment with startvm=false" + ) + self.debug("Creating a volume in account: %s" % + self.account.account.name) + volume = Volume.create( + self.apiclient, + self.services["volume"], + zoneid=self.zone.id, + account=self.account.account.name, + domainid=self.account.account.domainid, + diskofferingid=self.disk_offering.id + ) + self.debug("Created volume in account: %s" % self.account.account.name) + self.debug("Attaching volume to instance: %s" % + self.virtual_machine.name) + try: + self.virtual_machine.attach_volume(self.apiclient, volume) + except Exception as e: + self.fail("Attach volume failed!") + return + + def test_05_deploy_startvm_false_change_so(self): + """Test Deploy Virtual Machine with startVM=false and + change service offering + """ + + # Validate the following: + # 1. deploy Vm with the startvm=false. Attach volume to the instance + # 2. listVM command should return the deployed VM.State of this VM + # should be "Stopped". + # 3. Attach volume should be successful + # 4. Change service offering + + self.debug("Deploying instance in the account: %s" % + self.account.account.name) + self.virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.account.name, + domainid=self.account.account.domainid, + serviceofferingid=self.service_offering.id, + startvm=False, + diskofferingid=self.disk_offering.id, + ) + + self.debug("Deployed instance in account: %s" % + self.account.account.name) + list_vm_response = list_virtual_machines( + self.apiclient, + id=self.virtual_machine.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % self.virtual_machine.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Stopped", + "VM should be in Stopped state after deployment with startvm=false" + ) + self.debug("Creating a volume in account: %s" % + self.account.account.name) + volume = Volume.create( + self.apiclient, + self.services["volume"], + zoneid=self.zone.id, + account=self.account.account.name, + domainid=self.account.account.domainid, + diskofferingid=self.disk_offering.id + ) + self.debug("Created volume in account: %s" % self.account.account.name) + self.debug("Attaching volume to instance: %s" % + self.virtual_machine.name) + try: + self.virtual_machine.attach_volume(self.apiclient, volume) + except Exception as e: + self.fail("Attach volume failed!") + self.debug("Fetching details of medium service offering") + medium_service_offs = ServiceOffering.list( + self.apiclient, + name="Medium Instance" + ) + if isinstance(medium_service_offs, list): + medium_service_off = medium_service_offs[0] + else: + self.debug("Service offering not found! Creating a new one..") + medium_service_off = ServiceOffering.create( + self.apiclient, + self.services["service_offering"] + ) + self.cleanup.append(medium_service_off) + + self.debug("Changing service offering for instance: %s" % + self.virtual_machine.name) + try: + self.virtual_machine.change_service_offering( + self.apiclient, + medium_service_off.id + ) + except Exception as e: + self.fail("Change service offering failed: %s" % e) + + self.debug("Starting the instance: %s" % self.virtual_machine.name) + self.virtual_machine.start(self.apiclient) + self.debug("Instance: %s started" % self.virtual_machine.name) + + self.debug("Detaching the disk: %s" % volume.name) + self.virtual_machine.detach_volume(self.apiclient, volume) + self.debug("Datadisk %s detached!" % volume.name) + + volumes = Volume.list( + self.apiclient, + virtualmachineid=self.virtual_machine.id, + type='DATADISK', + id=volume.id, + listall=True + ) + self.assertEqual( + volumes, + None, + "List Volumes should not list any volume for instance" + ) + return + + def test_06_deploy_startvm_attach_detach(self): + """Test Deploy Virtual Machine with startVM=false and + attach detach volumes + """ + + # Validate the following: + # 1. deploy Vm with the startvm=false. Attach volume to the instance + # 2. listVM command should return the deployed VM.State of this VM + # should be "Stopped". + # 3. Attach volume should be successful + # 4. Detach volume from instance. Detach should be successful + + self.debug("Deploying instance in the account: %s" % + self.account.account.name) + self.virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.account.name, + domainid=self.account.account.domainid, + serviceofferingid=self.service_offering.id, + startvm=False, + diskofferingid=self.disk_offering.id, + ) + + self.debug("Deployed instance in account: %s" % + self.account.account.name) + list_vm_response = list_virtual_machines( + self.apiclient, + id=self.virtual_machine.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % self.virtual_machine.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Stopped", + "VM should be in Stopped state after deployment with startvm=false" + ) + self.debug("Creating a volume in account: %s" % + self.account.account.name) + volume = Volume.create( + self.apiclient, + self.services["volume"], + zoneid=self.zone.id, + account=self.account.account.name, + domainid=self.account.account.domainid, + diskofferingid=self.disk_offering.id + ) + self.debug("Created volume in account: %s" % self.account.account.name) + self.debug("Attaching volume to instance: %s" % + self.virtual_machine.name) + try: + self.virtual_machine.attach_volume(self.apiclient, volume) + except Exception as e: + self.fail("Attach volume failed!") + + self.debug("Detaching the disk: %s" % volume.name) + self.virtual_machine.detach_volume(self.apiclient, volume) + self.debug("Datadisk %s detached!" % volume.name) + + volumes = Volume.list( + self.apiclient, + virtualmachineid=self.virtual_machine.id, + type='DATADISK', + id=volume.id, + listall=True + ) + self.assertEqual( + volumes, + None, + "List Volumes should not list any volume for instance" + ) + return + + def test_07_deploy_startvm_attach_iso(self): + """Test Deploy Virtual Machine with startVM=false and attach ISO + """ + + # Validate the following: + # 1. deploy Vm with the startvm=false. Attach volume to the instance + # 2. listVM command should return the deployed VM.State of this VM + # should be "Stopped". + # 3. Attach ISO to the instance. Attach ISO should be successful + + self.debug("Deploying instance in the account: %s" % + self.account.account.name) + self.virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.account.name, + domainid=self.account.account.domainid, + serviceofferingid=self.service_offering.id, + startvm=False, + diskofferingid=self.disk_offering.id, + ) + + self.debug("Deployed instance in account: %s" % + self.account.account.name) + list_vm_response = list_virtual_machines( + self.apiclient, + id=self.virtual_machine.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % self.virtual_machine.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Stopped", + "VM should be in Stopped state after deployment with startvm=false" + ) + self.debug("Registering a ISO in account: %s" % + self.account.account.name) + iso = Iso.create( + self.apiclient, + self.services["iso"], + account=self.account.account.name, + domainid=self.account.account.domainid + ) + + self.debug("Successfully created ISO with ID: %s" % iso.id) + try: + iso.download(self.apiclient) + self.cleanup.append(iso) + except Exception as e: + self.fail("Exception while downloading ISO %s: %s"\ + % (iso.id, e)) + + self.debug("Attach ISO with ID: %s to VM ID: %s" % ( + iso.id, + self.virtual_machine.id + )) + try: + self.virtual_machine.attach_iso(self.apiclient, iso) + except Exception as e: + self.fail("Attach ISO failed!") + + vms = VirtualMachine.list( + self.apiclient, + id=self.virtual_machine.id, + listall=True + ) + self.assertEqual( + isinstance(vms, list), + True, + "List vms should return a valid list" + ) + vm = vms[0] + self.assertEqual( + vm.isoid, + iso.id, + "The ISO status should be reflected in list Vm call" + ) + return + + def test_08_deploy_attach_volume(self): + """Test Deploy Virtual Machine with startVM=false and + attach volume already attached to different machine + """ + + # Validate the following: + # 1. deploy Vm with the startvm=false. Attach volume to the instance + # 2. listVM command should return the deployed VM.State of this VM + # should be "Stopped". + # 3. Create an instance with datadisk attached to it. Detach DATADISK + # 4. Attach the volume to first virtual machine. + + self.debug("Deploying instance in the account: %s" % + self.account.account.name) + self.virtual_machine_1 = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.account.name, + domainid=self.account.account.domainid, + serviceofferingid=self.service_offering.id, + startvm=False, + ) + + self.debug("Deployed instance in account: %s" % + self.account.account.name) + list_vm_response = list_virtual_machines( + self.apiclient, + id=self.virtual_machine_1.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % self.virtual_machine_1.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Stopped", + "VM should be in Stopped state after deployment with startvm=false" + ) + + self.debug("Deploying instance in the account: %s" % + self.account.account.name) + self.virtual_machine_2 = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.account.name, + domainid=self.account.account.domainid, + serviceofferingid=self.service_offering.id, + diskofferingid=self.disk_offering.id + ) + + self.debug("Deployed instance in account: %s" % + self.account.account.name) + list_vm_response = list_virtual_machines( + self.apiclient, + id=self.virtual_machine_2.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % self.virtual_machine_2.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Running", + "VM should be in Stopped state after deployment with startvm=false" + ) + + self.debug( + "Fetching DATADISK details for instance: %s" % + self.virtual_machine_2.name) + volumes = Volume.list( + self.apiclient, + type='DATADISK', + account=self.account.account.name, + domainid=self.account.account.domainid, + listall=True + ) + self.assertEqual( + isinstance(volumes, list), + True, + "List volumes should return a valid list" + ) + volume = volumes[0] + + self.debug("Detaching the disk: %s" % volume.name) + + try: + self.virtual_machine_2.detach_volume(self.apiclient, volume) + self.debug("Datadisk %s detached!" % volume.name) + except Exception as e: + self.fail("Detach volume failed!") + + self.debug("Attaching volume to instance: %s" % + self.virtual_machine_1.name) + try: + self.virtual_machine_1.attach_volume(self.apiclient, volume) + except Exception as e: + self.fail("Attach volume failed!") + + volumes = Volume.list( + self.apiclient, + virtualmachineid=self.virtual_machine_1.id, + type='DATADISK', + id=volume.id, + listall=True + ) + self.assertNotEqual( + volumes, + None, + "List Volumes should not list any volume for instance" + ) + return + + + +class TestDeployHaEnabledVM(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + + cls.api_client = super( + TestDeployHaEnabledVM, + cls + ).getClsTestClient().getApiClient() + cls.services = Services().services + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.services) + + cls.template = get_template( + cls.api_client, + cls.zone.id, + cls.services["ostypeid"] + ) + + # Create service, disk offerings etc + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"], + offerha=True + ) + cls.disk_offering = DiskOffering.create( + cls.api_client, + cls.services["disk_offering"] + ) + # Cleanup + cls._cleanup = [ + cls.service_offering, + cls.disk_offering, + ] + return + + @classmethod + def tearDownClass(cls): + try: + cleanup_resources(cls.api_client, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + + def setUp(self): + + self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.services = Services().services + self.services["virtual_machine"]["zoneid"] = self.zone.id + self.services["virtual_machine"]["template"] = self.template.id + self.services["iso"]["zoneid"] = self.zone.id + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id + ) + self.cleanup = [self.account] + return + + def tearDown(self): + try: + self.debug("Cleaning up the resources") + cleanup_resources(self.apiclient, self.cleanup) + self.debug("Cleanup complete!") + except Exception as e: + self.debug("Warning! Exception in tearDown: %s" % e) + + def test_01_deploy_ha_vm_startvm_false(self): + """Test Deploy HA enabled Virtual Machine with startvm=false + """ + + # Validate the following: + # 1. deployHA enabled Vm with the startvm parameter = false + # 2. listVM command should return the deployed VM. State of this VM + # should be "Created". + + self.debug("Deploying instance in the account: %s" % + self.account.account.name) + self.virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.account.name, + domainid=self.account.account.domainid, + serviceofferingid=self.service_offering.id, + diskofferingid=self.disk_offering.id, + startvm=False + ) + + self.debug("Deployed instance in account: %s" % + self.account.account.name) + list_vm_response = list_virtual_machines( + self.apiclient, + id=self.virtual_machine.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % self.virtual_machine.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + + vm_response.state, + "Stopped", + "VM should be in Stopped state after deployment" + ) + return + + def test_02_deploy_ha_vm_from_iso(self): + """Test Deploy HA enabled Virtual Machine from ISO + """ + + # Validate the following: + # 1. deployHA enabled Vm using ISO with the startvm parameter=true + # 2. listVM command should return the deployed VM. State of this VM + # should be "Running". + + self.iso = Iso.create( + self.apiclient, + self.services["iso"], + account=self.account.account.name, + domainid=self.account.account.domainid + ) + try: + # Dowanload the ISO + self.iso.download(self.apiclient) + self.cleanup.append(self.iso) + except Exception as e: + raise Exception("Exception while downloading ISO %s: %s"\ + % (self.iso.id, e)) + + self.debug("Registered ISO: %s" % self.iso.name) + self.debug("Deploying instance in the account: %s" % + self.account.account.name) + self.virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.account.name, + domainid=self.account.account.domainid, + templateid=self.iso.id, + serviceofferingid=self.service_offering.id, + diskofferingid=self.disk_offering.id, + startvm=True + ) + + self.debug("Deployed instance in account: %s" % + self.account.account.name) + list_vm_response = list_virtual_machines( + self.apiclient, + id=self.virtual_machine.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % self.virtual_machine.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + + vm_response.state, + "Running", + "VM should be in Running state after deployment" + ) + return + + def test_03_deploy_ha_vm_iso_startvm_false(self): + """Test Deploy HA enabled Virtual Machine from ISO with startvm=false + """ + + # Validate the following: + # 1. deployHA enabled Vm using ISO with the startvm parameter=false + # 2. listVM command should return the deployed VM. State of this VM + # should be "Stopped". + + self.debug("Deploying instance in the account: %s" % + self.account.account.name) + self.virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.account.name, + domainid=self.account.account.domainid, + serviceofferingid=self.service_offering.id, + diskofferingid=self.disk_offering.id, + startvm=False + ) + + self.debug("Deployed instance in account: %s" % + self.account.account.name) + list_vm_response = list_virtual_machines( + self.apiclient, + id=self.virtual_machine.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % self.virtual_machine.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + + vm_response.state, + "Stopped", + "VM should be in Running state after deployment" + ) + return + + +class TestRouterStateAfterDeploy(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + + cls.api_client = super( + TestRouterStateAfterDeploy, + cls + ).getClsTestClient().getApiClient() + cls.services = Services().services + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.services) + + cls.template = get_template( + cls.api_client, + cls.zone.id, + cls.services["ostypeid"] + ) + + # Create service offerings, disk offerings etc + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) + cls.disk_offering = DiskOffering.create( + cls.api_client, + cls.services["disk_offering"] + ) + # Cleanup + cls._cleanup = [ + cls.service_offering, + cls.disk_offering, + ] + return + + @classmethod + def tearDownClass(cls): + try: + cleanup_resources(cls.api_client, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + + def setUp(self): + + self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.services = Services().services + self.services["virtual_machine"]["zoneid"] = self.zone.id + self.services["virtual_machine"]["template"] = self.template.id + self.services["iso"]["zoneid"] = self.zone.id + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id + ) + self.cleanup = [self.account] + return + + def tearDown(self): + try: + self.debug("Cleaning up the resources") + cleanup_resources(self.apiclient, self.cleanup) + self.debug("Cleanup complete!") + except Exception as e: + self.debug("Warning! Exception in tearDown: %s" % e) + + def test_01_deploy_vm_no_startvm(self): + """Test Deploy Virtual Machine with no startVM parameter + """ + + # Validate the following: + # 1. deploy Vm without specifying the startvm parameter + # 2. Should be able to login to the VM. + # 3. listVM command should return the deployed VM.State of this VM + # should be "Running". + + self.debug("Deploying instance in the account: %s" % + self.account.account.name) + self.virtual_machine_1 = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.account.name, + domainid=self.account.account.domainid, + serviceofferingid=self.service_offering.id, + diskofferingid=self.disk_offering.id, + startvm=False + ) + + self.debug("Deployed instance in account: %s" % + self.account.account.name) + list_vm_response = list_virtual_machines( + self.apiclient, + id=self.virtual_machine_1.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % self.virtual_machine_1.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + + vm_response.state, + "Stopped", + "VM should be in stopped state after deployment" + ) + self.debug("Checking the router state after VM deployment") + routers = Router.list( + self.apiclient, + account=self.account.account.name, + domainid=self.account.account.domainid, + listall=True + ) + self.assertEqual( + routers, + None, + "List routers should return empty response" + ) + self.debug( + "Deploying another instance (startvm=true) in the account: %s" % + self.account.account.name) + self.virtual_machine_2 = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.account.name, + domainid=self.account.account.domainid, + serviceofferingid=self.service_offering.id, + diskofferingid=self.disk_offering.id, + startvm=True + ) + + self.debug("Deployed instance in account: %s" % + self.account.account.name) + list_vm_response = list_virtual_machines( + self.apiclient, + id=self.virtual_machine_2.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % self.virtual_machine_2.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + + vm_response.state, + "Running", + "VM should be in Running state after deployment" + ) + self.debug("Checking the router state after VM deployment") + routers = Router.list( + self.apiclient, + account=self.account.account.name, + domainid=self.account.account.domainid, + listall=True + ) + self.assertEqual( + isinstance(routers, list), + True, + "List routers should not return empty response" + ) + for router in routers: + self.debug("Router state: %s" % router.state) + self.assertEqual( + router.state, + "Running", + "Router should be in running state when instance is running in the account" + ) + self.debug("Destroying the running VM:%s" % + self.virtual_machine_2.name) + self.virtual_machine_2.delete(self.apiclient) + self.debug("Instance destroyed..waiting till expunge interval") + + interval = list_configurations( + self.apiclient, + name='expunge.interval' + ) + delay = list_configurations( + self.apiclient, + name='expunge.delay' + ) + # Sleep to ensure that all resources are deleted + time.sleep((int(interval[0].value) + int(delay[0].value)) * 2) + + self.debug("Checking the router state after VM deployment") + routers = Router.list( + self.apiclient, + account=self.account.account.name, + domainid=self.account.account.domainid, + listall=True + ) + self.assertNotEqual( + routers, + None, + "Router should get deleted after expunge delay+wait" + ) + return + + +class TestDeployVMBasicZone(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + + cls.api_client = super( + TestDeployVMBasicZone, + cls + ).getClsTestClient().getApiClient() + cls.services = Services().services + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.services) + + cls.template = get_template( + cls.api_client, + cls.zone.id, + cls.services["ostypeid"] + ) + + # Create service offerings, disk offerings etc + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) + cls.disk_offering = DiskOffering.create( + cls.api_client, + cls.services["disk_offering"] + ) + # Cleanup + cls._cleanup = [ + cls.service_offering, + cls.disk_offering, + ] + return + + @classmethod + def tearDownClass(cls): + try: + cleanup_resources(cls.api_client, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + + def setUp(self): + + self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.services = Services().services + self.services["virtual_machine"]["zoneid"] = self.zone.id + self.services["iso"]["zoneid"] = self.zone.id + self.services["virtual_machine"]["template"] = self.template.id + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id + ) + self.cleanup = [self.account] + return + + def tearDown(self): + try: + self.debug("Cleaning up the resources") + cleanup_resources(self.apiclient, self.cleanup) + self.debug("Cleanup complete!") + except Exception as e: + self.debug("Warning! Exception in tearDown: %s" % e) + + def test_01_deploy_vm_startvm_true(self): + """Test Deploy Virtual Machine with startVM=true parameter + """ + + # Validate the following: + # 1. deploy Vm with the startvm=true + # 2. Should be able to login to the VM. + # 3. listVM command should return the deployed VM.State of this VM + # should be "Running". + + + self.debug("Checking the network type of the zone: %s" % + self.zone.networktype) + self.assertEqual( + self.zone.networktype, + 'Basic', + "Zone must be configured in basic networking mode" + ) + self.debug("Deploying instance in the account: %s" % + self.account.account.name) + self.virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.account.name, + domainid=self.account.account.domainid, + serviceofferingid=self.service_offering.id, + startvm=True, + diskofferingid=self.disk_offering.id, + mode=self.zone.networktype + ) + + self.debug("Deployed instance ion account: %s" % + self.account.account.name) + list_vm_response = list_virtual_machines( + self.apiclient, + id=self.virtual_machine.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % self.virtual_machine.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + + vm_response.state, + "Running", + "VM should be in Running state after deployment" + ) + return + + def test_02_deploy_vm_startvm_false(self): + """Test Deploy Virtual Machine with startVM=true parameter + """ + + # Validate the following: + # 1. deploy Vm with the startvm=true + # 2. Should be able to login to the VM. + # 3. listVM command should return the deployed VM.State of this VM + # should be "Running". + + + self.debug("Checking the network type of the zone: %s" % + self.zone.networktype) + self.assertEqual( + self.zone.networktype, + 'Basic', + "Zone must be configured in basic networking mode" + ) + self.debug("Deploying instance in the account: %s" % + self.account.account.name) + self.virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.account.name, + domainid=self.account.account.domainid, + serviceofferingid=self.service_offering.id, + startvm=False, + mode=self.zone.networktype + ) + + self.debug("Deployed instance in account: %s" % + self.account.account.name) + list_vm_response = list_virtual_machines( + self.apiclient, + id=self.virtual_machine.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % self.virtual_machine.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + + vm_response.state, + "Stopped", + "VM should be in stopped state after deployment" + ) + self.debug("Starting the instance: %s" % self.virtual_machine.name) + self.virtual_machine.start(self.apiclient) + self.debug("Started the instance: %s" % self.virtual_machine.name) + + list_vm_response = list_virtual_machines( + self.apiclient, + id=self.virtual_machine.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % self.virtual_machine.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + + vm_response.state, + "Running", + "VM should be in running state after deployment" + ) + return + + +class TestDeployVMFromTemplate(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + + cls.api_client = super( + TestDeployVMFromTemplate, + cls + ).getClsTestClient().getApiClient() + cls.services = Services().services + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.services) + + # Create service, disk offerings etc + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"], + offerha=True + ) + cls.disk_offering = DiskOffering.create( + cls.api_client, + cls.services["disk_offering"] + ) + # Cleanup + cls._cleanup = [ + cls.service_offering, + cls.disk_offering, + ] + return + + @classmethod + def tearDownClass(cls): + try: + cleanup_resources(cls.api_client, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + + def setUp(self): + + self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.services = Services().services + self.services["virtual_machine"]["zoneid"] = self.zone.id + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id + ) + self.template = Template.register( + self.apiclient, + self.services["template"], + zoneid=self.zone.id, + account=self.account.account.name, + domainid=self.account.account.domainid + ) + try: + self.template.download(self.apiclient) + except Exception as e: + raise Exception("Template download failed: %s" % e) + + self.cleanup = [self.account] + return + + def tearDown(self): + try: + self.debug("Cleaning up the resources") + cleanup_resources(self.apiclient, self.cleanup) + self.debug("Cleanup complete!") + except Exception as e: + self.debug("Warning! Exception in tearDown: %s" % e) + + def test_deploy_vm_password_enabled(self): + """Test Deploy Virtual Machine with startVM=false & enabledpassword in + template + """ + + # Validate the following: + # 1. Create the password enabled template + # 2. Deploy Vm with this template and passing startvm=false + # 3. Start VM. Deploy VM should be successful and it should be in Up + # and running state + + self.debug("Deploying instance in the account: %s" % + self.account.account.name) + self.virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.account.name, + domainid=self.account.account.domainid, + serviceofferingid=self.service_offering.id, + templateid=self.template.id, + startvm=False, + ) + + self.debug("Deployed instance in account: %s" % + self.account.account.name) + list_vm_response = list_virtual_machines( + self.apiclient, + id=self.virtual_machine.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % self.virtual_machine.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + + vm_response.state, + "Stopped", + "VM should be in stopped state after deployment" + ) + self.debug("Starting the instance: %s" % self.virtual_machine.name) + self.virtual_machine.start(self.apiclient) + self.debug("Started the instance: %s" % self.virtual_machine.name) + + list_vm_response = list_virtual_machines( + self.apiclient, + id=self.virtual_machine.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % self.virtual_machine.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Running", + "VM should be in running state after deployment" + ) + return + + +class TestVMAccountLimit(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + cls.api_client = super( + TestVMAccountLimit, + cls + ).getClsTestClient().getApiClient() + cls.services = Services().services + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.services) + + cls.template = get_template( + cls.api_client, + cls.zone.id, + cls.services["ostypeid"] + ) + cls.services["virtual_machine"]["zoneid"] = cls.zone.id + + # Create Account, VMs etc + cls.account = Account.create( + cls.api_client, + cls.services["account"], + domainid=cls.domain.id + ) + + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) + cls._cleanup = [ + cls.service_offering, + cls.account + ] + return + + @classmethod + def tearDownClass(cls): + try: + #Cleanup resources used + cleanup_resources(cls.api_client, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + def setUp(self): + self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.cleanup = [] + return + + def tearDown(self): + try: + #Clean up, terminate the created instance, volumes and snapshots + cleanup_resources(self.apiclient, self.cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + def test_vm_per_account(self): + """Test VM limit per account + """ + + # Validate the following + # 1. Set the resource limit for VM per account. + # 2. Deploy VMs more than limit in that account. + # 3. AIP should error out + + self.debug( + "Updating instance resource limit for account: %s" % + self.account.account.name) + # Set usage_vm=1 for Account 1 + update_resource_limit( + self.apiclient, + 0, # Instance + account=self.account.account.name, + domainid=self.account.account.domainid, + max=1 + ) + self.debug( + "Deploying VM instance in account: %s" % + self.account.account.name) + + virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + templateid=self.template.id, + accountid=self.account.account.name, + domainid=self.account.account.domainid, + serviceofferingid=self.service_offering.id, + startvm=False + ) + + # Verify VM state + self.assertEqual( + virtual_machine.state, + 'Stopped', + "Check VM state is Running or not" + ) + + # Exception should be raised for second instance (account_1) + with self.assertRaises(Exception): + VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + templateid=self.template.id, + accountid=self.account.account.name, + domainid=self.account.account.domainid, + serviceofferingid=self.service_offering.id, + startvm=False + ) + return + + +class TestUploadAttachVolume(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + cls.api_client = super( + TestUploadAttachVolume, + cls + ).getClsTestClient().getApiClient() + cls.services = Services().services + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.services) + + cls.template = get_template( + cls.api_client, + cls.zone.id, + cls.services["ostypeid"] + ) + cls.services["virtual_machine"]["zoneid"] = cls.zone.id + + # Create Account, VMs etc + cls.account = Account.create( + cls.api_client, + cls.services["account"], + domainid=cls.domain.id + ) + + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) + cls._cleanup = [ + cls.service_offering, + cls.account + ] + return + + @classmethod + def tearDownClass(cls): + try: + #Cleanup resources used + cleanup_resources(cls.api_client, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + def setUp(self): + self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.cleanup = [] + return + + def tearDown(self): + try: + #Clean up, terminate the created instance, volumes and snapshots + cleanup_resources(self.apiclient, self.cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + def test_upload_attach_volume(self): + """Test Upload volume and attach to VM in stopped state + """ + + # Validate the following + # 1. Upload the volume using uploadVolume API call + # 2. Deploy VM with startvm=false. + # 3. Attach the volume to the deployed VM in step 2 + + self.debug( + "Uploading the volume: %s" % + self.services["volume"]["diskname"]) + try: + volume = Volume.upload( + self.apiclient, + self.services["volume"], + zoneid=self.zone.id, + account=self.account.account.name, + domainid=self.account.account.domainid + ) + self.debug("Uploading the volume: %s" % volume.name) + volume.wait_for_upload(self.apiclient) + self.debug("Volume: %s uploaded successfully") + except Exception as e: + self.fail("Failed to upload the volume: %s" % e) + + self.debug( + "Deploying VM instance in account: %s" % + self.account.account.name) + + virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + templateid=self.template.id, + accountid=self.account.account.name, + domainid=self.account.account.domainid, + serviceofferingid=self.service_offering.id, + startvm=False + ) + # Verify VM state + self.assertEqual( + virtual_machine.state, + 'Stopped', + "Check VM state is Running or not" + ) + try: + virtual_machine.attach_volume(self.apiclient) + except Exception as e: + self.fail("Failed to attach the volume: %s" % e) + return diff --git a/test/integration/lib/base.py b/test/integration/lib/base.py index 336a453c546..69882bcb13d 100644 --- a/test/integration/lib/base.py +++ b/test/integration/lib/base.py @@ -326,6 +326,14 @@ class VirtualMachine: cmd.id = self.id apiclient.destroyVirtualMachine(cmd) + def migrate(self, apiclient, hostid=None): + """migrate an Instance""" + cmd = migrateVirtualMachine.migrateVirtualMachineCmd() + cmd.virtualmachineid = self.id + if hostid: + cmd.hostid = hostid + apiclient.migrateVirtualMachine(cmd) + def attach_volume(self, apiclient, volume): """Attach volume to instance""" cmd = attachVolume.attachVolumeCmd() @@ -472,6 +480,57 @@ class Volume: [setattr(cmd, k, v) for k, v in kwargs.items()] return(apiclient.listVolumes(cmd)) + @classmethod + def upload(cls, apiclient, services, zoneid=None, account=None, domainid=None): + """Uploads the volume to specified account""" + + cmd = uploadVolume.uploadVolumeCmd() + if zoneid: + cmd.zoneid = zoneid + if account: + cmd.account = account + if domainid: + cmd.domainid = domainid + cmd.format = services["format"] + cmd.name = services["diskname"] + cmd.url = services["url"] + return Volume(apiclient.uploadVolume(cmd).__dict__) + + def wait_for_upload(self, apiclient, timeout=5, interval=60): + """Wait for upload""" + #Sleep to ensure template is in proper state before download + time.sleep(interval) + + while True: + volume_response = Volume.list( + apiclient, + id=self.id, + zoneid=self.zoneid, + templatefilter='self' + ) + if isinstance(volume_response, list): + + volume = volume_response[0] + # If volume is ready, + # volume.state = Allocated + if volue.state == 'Allocated': + break + + elif 'Uploading' in volume.state: + time.sleep(interval) + + elif 'Installing' not in volume.state: + raise Exception( + "Error in uploading volume: status - %s" % + volume.state) + + elif timeout == 0: + break + + else: + time.sleep(interval) + timeout = timeout - 1 + return class Snapshot: """Manage Snapshot Lifecycle @@ -528,7 +587,6 @@ class Template: cmd.ispublic = services["ispublic"] if "ispublic" in services else False cmd.isextractable = services["isextractable"] if "isextractable" in services else False cmd.passwordenabled = services["passwordenabled"] if "passwordenabled" in services else False - cmd.passwordenabled = services["passwordenabled"] if "passwordenabled" in services else False if volumeid: cmd.volumeid = volumeid