def test_create(self):
     try:
         cloud_adapter = Cloud_Attributes()
         test_image = Image_Adapter(image_name='test_image', image_path='/home/openstack/Downloads/precise-server-cloudimg-amd64-disk1.img')
         image_list = cloud_adapter.get_os_specific_image_list('test_image')
         image_details = image_list.get('test_image')           
         image_id = image_details.get('Image_ID')
         
         prev_vm_list = cloud_adapter.get_vm_list()
         assert('testvm' not in prev_vm_list)
         
         vm_instance = VM_Adapter('testvm', image_id, 2048, 20, 1)
         count = 0
         while count <= 4:  
             time.sleep(pow(2,count))
             count+=1
         
         cur_vm_list = cloud_adapter.get_vm_list()
         assert('testvm' in cur_vm_list)
         print 'Virtual Machine successfully created.'
  
         vm_instance.destroy()
         test_image.delete()
     except:
         print 'Virtual Machine creation failed.'               
         test_image.delete()
         raise   
 def test_get_flavor(self):
     try:
         cloud_adapter = Cloud_Attributes()
         test_image = Image_Adapter(image_name='test_image', image_path='/home/openstack/Downloads/precise-server-cloudimg-amd64-disk1.img')
         image_list = cloud_adapter.get_os_specific_image_list('test_image')
         image_details = image_list.get('test_image')           
         image_id = image_details.get('Image_ID')
         
         vm_instance = VM_Adapter('testvm', image_id, 2048, 20, 1)
         count = 0
         while count <= 4:  
             time.sleep(pow(2,count))
             count+=1
     except:
         print 'Connection not establised.'   
         raise               
     try:
         vm_flavor = vm_instance.get_flavor()
         print '\n\nVirtual Machine Flavor Size :\n',vm_flavor
         vm_instance.destroy()
         test_image.delete()
     except:
         print 'Virtual Machine not found.'   
         vm_instance.destroy()
         test_image.delete()
         raise
Ejemplo n.º 3
0
    def __init__(self, image_name, image_path, vm_name, vm_ram, vm_disk,
                 vm_vcpus):
        """
        Constructor to create a Connection, an Image Instance and a VM Instance
    
        :param image_name: The name of the image to be created.
        :param image_path: The path of the image for creation.
        :param vm_name: The name of the virtual machine to create
        :param vm_ram: The ram size of the virtual machine.
        :param vm_disk: The disk size of the virtual machine.
        :param vm_vcpus: Number of CPU's required by the virtual machine.
        """

        logging.basicConfig(
            filename='openstack.log',
            level=logging.DEBUG,
            format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
            datefmt='%m/%d/%Y %I:%M:%S %p')

        try:
            cloud_adapter = Cloud_Attributes()

            logging.info('Establishing Connection.')

            # Connections with keystoneClient(identity API) --------------------
            creds = get_keystone_creds()
            self.keystone = ksclient.Client(**creds)

            # Connections with novaClient(compute API) --------------------
            creds = get_nova_creds()
            self.nova = nvclient.Client(**creds)
        except:
            logging.error('Invalid Credentials.')
            logging.critical('Connection Aborted.')
            raise

        # Creating IMAGE instance --------------------
        try:
            logging.info('Creating Image Instance.')
            image = Image_Adapter(image_name, image_path)
        except:
            logging.error('Image not Created.')
            raise

        # Creating VM instance --------------------
        try:
            logging.info('Creating Virtual Machine.')

            image_list = cloud_adapter.get_os_specific_image_list(image_name)
            image_details = image_list.get(image_name)
            image_id = image_details.get('Image_ID')

            instance = VM_Adapter(vm_name, image_id, vm_ram, vm_disk, vm_vcpus)
        except:
            logging.error('Virtual Machine not Created.')
            raise
 def test_restart_suspend(self):
     try:
         cloud_adapter = Cloud_Attributes()
         test_image = Image_Adapter(image_name='test_image', image_path='/home/openstack/Downloads/precise-server-cloudimg-amd64-disk1.img')
         image_list = cloud_adapter.get_os_specific_image_list('test_image')
         image_details = image_list.get('test_image')           
         image_id = image_details.get('Image_ID')
         
         vm_instance_suspend = VM_Adapter('testvm_suspend', image_id, 2048, 20, 1)
         count = 0
         while count <= 4:  
             time.sleep(pow(2,count))
             count+=1
     except:
         print 'Connection not establised.'   
         raise               
     try:
         vm_instance_suspend.suspend()
         count = 0
         while count <= 4:  
             time.sleep(pow(2,count))
             count+=1
         
         prev_vm_list = cloud_adapter.get_running_vm_list()
         assert('testvm_suspend' not in prev_vm_list)
         
         vm_instance_suspend.restart()
         count = 0
         while count <= 4:  
             time.sleep(pow(2,count))
             count+=1
         
         cur_vm_list = cloud_adapter.get_running_vm_list()
         assert('testvm_suspend' not in cur_vm_list)
         
         vm_instance_suspend.destroy()
         test_image.delete()
         print 'Virtual Machine restart successfully checked.'   
     except:
         print 'Virtual Machine not found.'   
         vm_instance_suspend.destroy()
         test_image.delete()
         raise
    def test_change_flavor(self):
        try:
            cloud_adapter = Cloud_Attributes()
            test_image = Image_Adapter(image_name='test_image', image_path='/home/openstack/Downloads/precise-server-cloudimg-amd64-disk1.img')
            image_list = cloud_adapter.get_os_specific_image_list('test_image')
            image_details = image_list.get('test_image')           
            image_id = image_details.get('Image_ID')
            
            vm_instance = VM_Adapter('testvm', image_id, 2048, 20, 1)
            count = 0
            while count <= 4:  
                time.sleep(pow(2,count))
                count+=1
        except:
            print 'Connection not establised.'   
            raise        
        try:
            prev_flavor_details = vm_instance.get_flavor()
            prev_flavor = prev_flavor_details.get('Flavor_Name')
            
            prev_flavor_list = cloud_adapter.get_flavor_list()
            assert(prev_flavor in prev_flavor_list)
            
            vm_instance.change_flavor(4096, 30)
            count = 0
            while count <= 4:  
                time.sleep(pow(2,count))
                count+=1

            cur_flavor_details = vm_instance.get_flavor()
            cur_flavor = cur_flavor_details.get('Flavor_Name')
            
            cur_flavor_list = cloud_adapter.get_flavor_list()
            assert(cur_flavor in cur_flavor_list)
            
            print 'Flavor Size of the Virtual Machine changed successfully.'
            vm_instance.destroy()
            test_image.delete()
        except:
            print 'Virtual Machine not found.'   
            vm_instance.destroy()
            test_image.delete()
            raise
    def test_change_disk(self):
        try:
            cloud_adapter = Cloud_Attributes()
            test_image = Image_Adapter(image_name='test_image', image_path='/home/openstack/Downloads/precise-server-cloudimg-amd64-disk1.img')
            image_list = cloud_adapter.get_os_specific_image_list('test_image')
            image_details = image_list.get('test_image')           
            image_id = image_details.get('Image_ID')
            
            vm_instance = VM_Adapter('testvm', image_id, 2048, 20, 1)
            count = 0
            while count <= 4:  
                time.sleep(pow(2,count))
                count+=1
        except:
            print 'Connection not establised.'   
            raise        

        try:
            prev_disk = vm_instance.get_disk()
            print '\nPrevious DISK SIZE',prev_disk
            
            vm_instance.change_disk(40)
            count = 0
            while count <= 4:  
                time.sleep(pow(2,count))
                count+=1
            cur_disk = vm_instance.get_disk()
            print '\nCurrent DISK SIZE',cur_disk
        
            print 'Disk Size of the Virtual Machine changed successfully.'
            vm_instance.destroy()
            test_image.delete()
        except:
            print 'Virtual Machine not found.'   
            vm_instance.destroy()
            test_image.delete()
            raise