def test_10_attachAndDetach_iso(self): """Test for attach and detach ISO to virtual machine""" # Validate the following # 1. Create ISO # 2. Attach ISO to VM # 3. Log in to the VM. # 4. The device should be available for use # 5. Detach ISO # 6. Check the device is properly detached by logging into VM iso = Iso.create(self.apiclient, self.services["iso1"], account=self.account.name, domainid=self.account.domainid) self.debug("Successfully created ISO with ID: %s" % iso.id) try: iso.download(self.apiclient) 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)) #Attach ISO to virtual machine cmd = attachIso.attachIsoCmd() cmd.id = iso.id cmd.virtualmachineid = self.virtual_machine.id self.apiclient.attachIso(cmd) try: ssh_client = self.virtual_machine.get_ssh_client() except Exception as e: self.fail("SSH failed for virtual machine: %s - %s" % (self.virtual_machine.ipaddress, e)) mount_dir = "/mnt/tmp" cmds = "mkdir -p %s" % mount_dir self.assert_( ssh_client.execute(cmds) == [], "mkdir failed within guest") for diskdevice in self.services["diskdevice"]: res = ssh_client.execute("mount -rt iso9660 {} {}".format( diskdevice, mount_dir)) if res == []: self.services["mount"] = diskdevice break else: self.fail("No mount points matched. Mount was unsuccessful") c = "mount |grep %s|head -1" % self.services["mount"] res = ssh_client.execute(c) size = ssh_client.execute("du %s | tail -1" % self.services["mount"]) self.debug("Found a mount point at %s with size %s" % (res, size)) # Get ISO size iso_response = Iso.list(self.apiclient, id=iso.id) self.assertEqual(isinstance(iso_response, list), True, "Check list response returns a valid list") try: #Unmount ISO command = "umount %s" % mount_dir ssh_client.execute(command) except Exception as e: self.fail("SSH failed for virtual machine: %s - %s" % (self.virtual_machine.ipaddress, e)) #Detach from VM cmd = detachIso.detachIsoCmd() cmd.virtualmachineid = self.virtual_machine.id self.apiclient.detachIso(cmd) try: res = ssh_client.execute(c) except Exception as e: self.fail("SSH failed for virtual machine: %s - %s" % (self.virtual_machine.ipaddress, e)) # Check if ISO is properly detached from VM (using fdisk) result = self.services["mount"] in str(res) self.assertEqual(result, False, "Check if ISO is detached from virtual machine") return
def test_10_attachAndDetach_iso(self): """Test for attach and detach ISO to virtual machine""" # Validate the following # 1. Create ISO # 2. Attach ISO to VM # 3. Log in to the VM. # 4. The device should be available for use # 5. Detach ISO # 6. Check the device is properly detached by logging into VM iso = Iso.create( self.apiclient, self.services["iso1"], account=self.account.name, domainid=self.account.domainid ) self.debug("Successfully created ISO with ID: %s" % iso.id) try: iso.download(self.apiclient) 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 )) #Attach ISO to virtual machine cmd = attachIso.attachIsoCmd() cmd.id = iso.id cmd.virtualmachineid = self.virtual_machine.id self.apiclient.attachIso(cmd) try: ssh_client = self.virtual_machine.get_ssh_client() except Exception as e: self.fail("SSH failed for virtual machine: %s - %s" % (self.virtual_machine.ipaddress, e)) mount_dir = "/mnt/tmp" cmds = "mkdir -p %s" % mount_dir self.assert_(ssh_client.execute(cmds) == [], "mkdir failed within guest") for diskdevice in self.services["diskdevice"]: res = ssh_client.execute("mount -rt iso9660 {} {}".format(diskdevice, mount_dir)) if res == []: self.services["mount"] = diskdevice break else: self.fail("No mount points matched. Mount was unsuccessful") c = "mount |grep %s|head -1" % self.services["mount"] res = ssh_client.execute(c) size = ssh_client.execute("du %s | tail -1" % self.services["mount"]) self.debug("Found a mount point at %s with size %s" % (res, size)) # Get ISO size iso_response = Iso.list( self.apiclient, id=iso.id ) self.assertEqual( isinstance(iso_response, list), True, "Check list response returns a valid list" ) try: #Unmount ISO command = "umount %s" % mount_dir ssh_client.execute(command) except Exception as e: self.fail("SSH failed for virtual machine: %s - %s" % (self.virtual_machine.ipaddress, e)) #Detach from VM cmd = detachIso.detachIsoCmd() cmd.virtualmachineid = self.virtual_machine.id self.apiclient.detachIso(cmd) try: res = ssh_client.execute(c) except Exception as e: self.fail("SSH failed for virtual machine: %s - %s" % (self.virtual_machine.ipaddress, e)) # Check if ISO is properly detached from VM (using fdisk) result = self.services["mount"] in str(res) self.assertEqual( result, False, "Check if ISO is detached from virtual machine" ) return
def test_01_volume_iso_attach(self): """Test Volumes and ISO attach """ # Validate the following # 1. Create and attach 5 data volumes to VM # 2. Create an ISO. Attach it to VM instance # 3. Verify that attach ISO is successful # Create 5 volumes and attach to VM for i in range(self.max_data_volumes): volume = Volume.create( self.apiclient, self.services["volume"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, diskofferingid=self.disk_offering.id ) self.debug("Created volume: %s for account: %s" % ( volume.id, self.account.name )) # Check List Volume response for newly created volume list_volume_response = Volume.list( self.apiclient, id=volume.id ) self.assertNotEqual( list_volume_response, None, "Check if volume exists in ListVolumes" ) self.assertEqual( isinstance(list_volume_response, list), True, "Check list volumes response for valid list" ) # Attach volume to VM self.virtual_machine.attach_volume( self.apiclient, volume ) # Check all volumes attached to same VM list_volume_response = Volume.list( self.apiclient, virtualmachineid=self.virtual_machine.id, type='DATADISK', listall=True ) self.assertNotEqual( list_volume_response, None, "Check if volume exists in ListVolumes" ) self.assertEqual( isinstance(list_volume_response, list), True, "Check list volumes response for valid list" ) self.assertEqual( len(list_volume_response), self.max_data_volumes, "Volumes attached to the VM %s. Expected %s" % (len(list_volume_response), self.max_data_volumes)) # Create an ISO and attach it to VM iso = Iso.create( self.apiclient, self.services["iso"], account=self.account.name, domainid=self.account.domainid, ) self.debug("Created ISO with ID: %s for account: %s" % ( iso.id, self.account.name )) try: self.debug("Downloading ISO with ID: %s" % iso.id) iso.download(self.apiclient) except Exception as e: self.fail("Exception while downloading ISO %s: %s" % (iso.id, e)) # Attach ISO to virtual machine self.debug("Attach ISO ID: %s to VM: %s" % ( iso.id, self.virtual_machine.id )) cmd = attachIso.attachIsoCmd() cmd.id = iso.id cmd.virtualmachineid = self.virtual_machine.id self.apiclient.attachIso(cmd) # Verify ISO is attached to VM vm_response = VirtualMachine.list( self.apiclient, id=self.virtual_machine.id, ) # Verify VM response to check whether VM deployment was successful self.assertEqual( isinstance(vm_response, list), True, "Check list VM response for valid list" ) self.assertNotEqual( len(vm_response), 0, "Check VMs available in List VMs response" ) vm = vm_response[0] self.assertEqual( vm.isoid, iso.id, "Check ISO is attached to VM or not" ) return
def test_01_volume_iso_attach(self): """Test Volumes and ISO attach """ # Validate the following # 1. Create and attach 5 data volumes to VM # 2. Create an ISO. Attach it to VM instance # 3. Verify that attach ISO is successful # Create 5 volumes and attach to VM if self.hypervisor.lower() in ["lxc"]: self.skipTest("attach ISO is not supported on LXC") for i in range(self.max_data_volumes): volume = Volume.create( self.apiclient, self.services["volume"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, diskofferingid=self.disk_offering.id ) self.debug("Created volume: %s for account: %s" % ( volume.id, self.account.name )) # Check List Volume response for newly created volume list_volume_response = Volume.list( self.apiclient, id=volume.id ) self.assertNotEqual( list_volume_response, None, "Check if volume exists in ListVolumes" ) self.assertEqual( isinstance(list_volume_response, list), True, "Check list volumes response for valid list" ) # Attach volume to VM self.virtual_machine.attach_volume( self.apiclient, volume ) # Check all volumes attached to same VM list_volume_response = Volume.list( self.apiclient, virtualmachineid=self.virtual_machine.id, type='DATADISK', listall=True ) self.assertNotEqual( list_volume_response, None, "Check if volume exists in ListVolumes" ) self.assertEqual( isinstance(list_volume_response, list), True, "Check list volumes response for valid list" ) self.assertEqual( len(list_volume_response), self.max_data_volumes, "Volumes attached to the VM %s. Expected %s" % (len(list_volume_response), self.max_data_volumes)) # Create an ISO and attach it to VM iso = Iso.create( self.apiclient, self.services["iso"], account=self.account.name, domainid=self.account.domainid, ) self.debug("Created ISO with ID: %s for account: %s" % ( iso.id, self.account.name )) try: self.debug("Downloading ISO with ID: %s" % iso.id) iso.download(self.apiclient) except Exception as e: self.fail("Exception while downloading ISO %s: %s" % (iso.id, e)) # Attach ISO to virtual machine self.debug("Attach ISO ID: %s to VM: %s" % ( iso.id, self.virtual_machine.id )) cmd = attachIso.attachIsoCmd() cmd.id = iso.id cmd.virtualmachineid = self.virtual_machine.id self.apiclient.attachIso(cmd) # Verify ISO is attached to VM vm_response = VirtualMachine.list( self.apiclient, id=self.virtual_machine.id, ) # Verify VM response to check whether VM deployment was successful self.assertEqual( isinstance(vm_response, list), True, "Check list VM response for valid list" ) self.assertNotEqual( len(vm_response), 0, "Check VMs available in List VMs response" ) vm = vm_response[0] self.assertEqual( vm.isoid, iso.id, "Check ISO is attached to VM or not" ) return