@attr(tags=['advanced', 'eip', 'advancedns', 'basic', 'sg'])
def test_08_deploy_attached_volume(self):
    'Test Deploy Virtual Machine with startVM=false and attach volume already attached to different machine\n        '
    self.debug(('Deploying instance in the account: %s' % self.account.name))
    self.virtual_machine_1 = VirtualMachine.create(self.apiclient, self.services['virtual_machine'], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, startvm=False)
    self.debug(('Deployed instance in account: %s' % self.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.name))
    self.virtual_machine_2 = VirtualMachine.create(self.apiclient, self.services['virtual_machine'], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, diskofferingid=self.disk_offering.id)
    self.debug(('Deployed instance in account: %s' % self.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.name, domainid=self.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 with %s!' % e))
    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
Test Deploy Virtual Machine with startVM=false and attach volume already attached to different machine
@attr(tags=['advanced', 'eip', 'advancedns', 'basic', 'sg'])
def test_08_deploy_attached_volume(self):
    '\n        '
    self.debug(('Deploying instance in the account: %s' % self.account.name))
    self.virtual_machine_1 = VirtualMachine.create(self.apiclient, self.services['virtual_machine'], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, startvm=False)
    self.debug(('Deployed instance in account: %s' % self.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.name))
    self.virtual_machine_2 = VirtualMachine.create(self.apiclient, self.services['virtual_machine'], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, diskofferingid=self.disk_offering.id)
    self.debug(('Deployed instance in account: %s' % self.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.name, domainid=self.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 with %s!' % e))
    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