示例#1
0
 def setUp(self):
     self.__dbConfigurator = DBConfigurator("")
     self.__dbConfigurator.runSQLScript("VMServerDBTest",
                                        "./VMServerDBTest.sql")
     self.__dbConfigurator.addUser("CygnusCloud", "cygnuscloud2012",
                                   "VMServerDBTest", True)
     self.__dbConnector = VMServerDBConnector("CygnusCloud",
                                              "cygnuscloud2012",
                                              "VMServerDBTest")
示例#2
0
class DBWebServerTests(unittest.TestCase):
    '''
        Clase encargada de realizar los test unitarios asociados 
    '''
    def setUp(self):
        self.__dbConfigurator = DBConfigurator("")
        self.__dbConfigurator.runSQLScript("VMServerDBTest",
                                           "./VMServerDBTest.sql")
        self.__dbConfigurator.addUser("CygnusCloud", "cygnuscloud2012",
                                      "VMServerDBTest", True)
        self.__dbConnector = VMServerDBConnector("CygnusCloud",
                                                 "cygnuscloud2012",
                                                 "VMServerDBTest")

    def tearDown(self):
        self.__dbConnector.disconnect()
        self.__dbConfigurator.dropDatabase("VMServerDBTest")

    def test_getImages(self):
        # Instanciamos la clase
        l1 = self.__dbConnector.getImages()
        l2 = [1, 2, 3, 4]
        self.assertEquals(l1, l2, "The image ID lists do not match")

    def test_getName(self):
        # Instanciamos la clase
        n1 = self.__dbConnector.getName(1)
        n2 = "VMName1"
        self.assertEquals(n1, n2, "Not same image name")

    def test_getImagePath(self):
        # Instanciamos la clase
        n1 = self.__dbConnector.getImagePath(1)
        n2 = "./VMName1/"
        self.assertEquals(n1, n2, "Not same image path")

    def test_getFileConfigPath(self):
        # Instanciamos la clase
        n1 = self.__dbConnector.getFileConfigPath(1)
        n2 = "./VMName1/"
        self.assertEquals(n1, n2, "Not same image path")

    def test_setImageDataPath(self):
        # Instanciamos la clase
        self.__dbConnector.setImageDataPath(1, "./VMName1Test/")
        n1 = self.__dbConnector.getImagePath(1)
        n2 = "./VMName1Test/"
        self.assertEquals(n1, n2, "Not change image path")

    def test_createImage(self):
        # Instanciamos la clase
        imageId = self.__dbConnector.createImage(123, "VMNameTest",
                                                 "./VMNameTest/",
                                                 "./OSImagePath1",
                                                 "./VMNameTest/")
        self.assertTrue(self.__dbConnector.doesImageExist(imageId),
                        "Not image regist")
        self.__dbConnector.deleteImage(imageId)

    def test_getRunningPorts(self):
        # Instanciamos la clase
        l1 = self.__dbConnector.getRunningPorts()
        l2 = [1, 2, 3, 4]
        self.assertEquals(l1, l2, "Not same ports")

    def test_getUsers(self):
        # Instanciamos la clase
        l1 = self.__dbConnector.getUsers()
        l2 = [1, 2, 3]
        self.assertEquals(l1, l2, "Not same users")

    def test_getAssignedVM(self):
        # Instanciamos la clase
        n1 = self.__dbConnector.getAssignedVM(1)
        n2 = 1
        self.assertEquals(n1, n2, "Not same VM")

    def test_getAssignedVMNameInDomain(self):
        # Instanciamos la clase
        n1 = self.__dbConnector.getAssignedVMNameInDomain(2)
        n2 = "VMName1"
        self.assertEquals(n1, n2, "Not same VM Name")

    def test_getMachineDataPath(self):
        # Instanciamos la clase
        n1 = self.__dbConnector.getMachineDataPath(2)
        n2 = "./VMNameCopy1"
        self.assertEquals(n1, n2, "Not same VM path")

    def test_getMACAddressInDomain(self):
        # Instanciamos la clase
        n1 = self.__dbConnector.getMACAddress(3)
        n2 = "2C:00:00:00:00:02"
        self.assertEquals(n1, n2, "Not same VM MAC")

    def test_getPasswordInDomain(self):
        # Instanciamos la clase
        n1 = self.__dbConnector.getPassword(3)
        n2 = "1234567890Test"
        self.assertEquals(n1, n2, "Not same VM Pass")

    def test_registerVMResources(self):
        # Instanciamos la clase
        portId = self.__dbConnector.registerVMResources(
            "VMName123", 2, 23, "testPass", 3, 100, "./VMNameCopyTest",
            "./OSImagePath1", "testMac", "testUUID")
        self.assertTrue(self.__dbConnector.doesVMExist(portId),
                        "Not VM register")
        self.__dbConnector.unregisterVMResources("VMName123")
        self.assertFalse(self.__dbConnector.doesVMExist(23),
                         "Not VM unregisted")

    def test_extractFreeMACandUUID(self):
        # Instanciamos la clase
        (_uuid1, mac1) = self.__dbConnector.extractFreeMACAndUUID()
        (_uuid2, mac2) = ("9a47c734-5e5f-11e2-981b-001f16b99e1d",
                          "2C:00:00:00:00:00")
        self.assertEquals(mac1, mac2, "Not same MAC")

    def test_extractFreeVNCPort(self):
        # Instanciamos la clase
        vncPort1 = self.__dbConnector.extractFreeVNCPort()
        vncPort2 = (15000)
        self.assertEquals(vncPort1, vncPort2, "Not same VNCPort")

    def test_getVMsConnectionData(self):
        result = self.__dbConnector.getVMsConnectionData()
        expectedResult = [{
            "UserID": 1,
            "VMID": 1,
            "VMName": "VMName11",
            "VNCPort": 1,
            "VNCPass": "******"
        }, {
            "UserID": 1,
            "VMID": 1,
            "VMName": "VMName22",
            "VNCPort": 2,
            "VNCPass": "******"
        }, {
            "UserID": 2,
            "VMID": 1,
            "VMName": "VMName33",
            "VNCPort": 3,
            "VNCPass": "******"
        }, {
            "UserID": 3,
            "VMID": 1,
            "VMName": "VMName44",
            "VNCPort": 4,
            "VNCPass": "******"
        }]
        self.assertEquals(result, expectedResult,
                          "getVMsConnectionData does not work")

    def test_getVMBootCommand(self):
        result = self.__dbConnector.getVMBootCommand("VMName44")
        expectedResult = "123"
        self.assertEquals(result, expectedResult,
                          "getVMBootCommand does not work")
        result = self.__dbConnector.getVMBootCommand("VMName33")
        self.assertEquals(result, None, "getVMBootCommand does not work")

    def test_addVMBootCommand(self):
        self.__dbConnector.addVMBootCommand("VMName33", "1234")
        result = self.__dbConnector.getVMBootCommand("VMName33")
        self.assertEquals(result, "1234", "addVMBootCommand does not work")

    def test_getDomainImageDataPath(self):
        result = self.__dbConnector.getDomainImageDataPath("VMName33")
        expectedResult = "./VMNameCopy2"
        self.assertEquals(result, expectedResult,
                          "getDomainImageDataPath does not work")

    def test_getOSImagePath(self):
        result = self.__dbConnector.getOsImagePath(1)
        expectedResult = "./VMName1/"
        self.assertEquals(result, expectedResult,
                          "getOSImageDataPath does not work")

    def test_getRegisteredDomainNames(self):
        result = self.__dbConnector.getRegisteredDomainNames()
        expectedResult = ["VMName11", "VMName22", "VMName33", "VMName44"]
        self.assertEquals(result, expectedResult,
                          "getActiveDomainNames() does not work")
示例#3
0
class DBWebServerTests(unittest.TestCase):
    '''
        Clase encargada de realizar los test unitarios asociados 
    '''
    
    def setUp(self):
        self.__dbConfigurator = DBConfigurator("")
        self.__dbConfigurator.runSQLScript("VMServerDBTest", "./VMServerDBTest.sql")
        self.__dbConfigurator.addUser("CygnusCloud", "cygnuscloud2012", "VMServerDBTest", True)
        self.__dbConnector = VMServerDBConnector("CygnusCloud", "cygnuscloud2012", "VMServerDBTest")
    
    def tearDown(self):
        self.__dbConnector.disconnect()
        self.__dbConfigurator.dropDatabase("VMServerDBTest")
    
    def test_getImages(self):
        # Instanciamos la clase
        l1 = self.__dbConnector.getImages()
        l2 = [1, 2, 3, 4]
        self.assertEquals(l1, l2, "The image ID lists do not match")
        
    def test_getName(self):
        # Instanciamos la clase
        n1 = self.__dbConnector.getName(1)
        n2 = "VMName1"
        self.assertEquals(n1, n2, "Not same image name")
        
    def test_getImagePath(self):
        # Instanciamos la clase
        n1 = self.__dbConnector.getImagePath(1)
        n2 = "./VMName1/"
        self.assertEquals(n1, n2, "Not same image path")   
        
    def test_getFileConfigPath(self):
        # Instanciamos la clase
        n1 = self.__dbConnector.getFileConfigPath(1)
        n2 = "./VMName1/"
        self.assertEquals(n1, n2, "Not same image path")

    def test_setImageDataPath(self):
        # Instanciamos la clase
        self.__dbConnector.setImageDataPath(1, "./VMName1Test/")
        n1 = self.__dbConnector.getImagePath(1)
        n2 = "./VMName1Test/"
        self.assertEquals(n1, n2, "Not change image path")  
        
    def test_createImage(self):
        # Instanciamos la clase
        imageId = self.__dbConnector.createImage(123, "VMNameTest", "./VMNameTest/", "./OSImagePath1", "./VMNameTest/")
        self.assertTrue(self.__dbConnector.doesImageExist(imageId), "Not image regist")  
        self.__dbConnector.deleteImage(imageId)    
    
    def test_getRunningPorts(self):
        # Instanciamos la clase
        l1 = self.__dbConnector.getRunningPorts()
        l2 = [1, 2, 3, 4]
        self.assertEquals(l1, l2, "Not same ports") 
        
    def test_getUsers(self):
        # Instanciamos la clase
        l1 = self.__dbConnector.getUsers()
        l2 = [1, 2, 3]
        self.assertEquals(l1, l2, "Not same users")

    def test_getAssignedVM(self):
        # Instanciamos la clase
        n1 = self.__dbConnector.getAssignedVM(1)
        n2 = 1
        self.assertEquals(n1, n2, "Not same VM") 
        
    def test_getAssignedVMNameInDomain(self):
        # Instanciamos la clase
        n1 = self.__dbConnector.getAssignedVMNameInDomain(2)
        n2 = "VMName1"
        self.assertEquals(n1, n2, "Not same VM Name")   
        
    def test_getMachineDataPath(self):
        # Instanciamos la clase
        n1 = self.__dbConnector.getMachineDataPath(2)
        n2 = "./VMNameCopy1"
        self.assertEquals(n1, n2, "Not same VM path")
 
    def test_getMACAddressInDomain(self):
        # Instanciamos la clase
        n1 = self.__dbConnector.getMACAddress(3)
        n2 = "2C:00:00:00:00:02"
        self.assertEquals(n1, n2, "Not same VM MAC") 
        
    def test_getPasswordInDomain(self):
        # Instanciamos la clase
        n1 = self.__dbConnector.getPassword(3)
        n2 = "1234567890Test"
        self.assertEquals(n1, n2, "Not same VM Pass")
        
    def test_registerVMResources(self):
        # Instanciamos la clase
        portId = self.__dbConnector.registerVMResources("VMName123", 2,
            23, "testPass", 3, 100, "./VMNameCopyTest", "./OSImagePath1", "testMac", "testUUID")
        self.assertTrue(self.__dbConnector.doesVMExist(portId), "Not VM register") 
        self.__dbConnector.unregisterVMResources("VMName123")
        self.assertFalse(self.__dbConnector.doesVMExist(23), "Not VM unregisted")
        
    def test_extractFreeMACandUUID(self):
        # Instanciamos la clase
        (_uuid1, mac1) = self.__dbConnector.extractFreeMACAndUUID()
        (_uuid2, mac2) = ("9a47c734-5e5f-11e2-981b-001f16b99e1d", "2C:00:00:00:00:00")
        self.assertEquals(mac1, mac2, "Not same MAC")
    
    def test_extractFreeVNCPort(self):
        # Instanciamos la clase
        vncPort1 = self.__dbConnector.extractFreeVNCPort()
        vncPort2 = (15000)
        self.assertEquals(vncPort1, vncPort2, "Not same VNCPort")
             
    def test_getVMsConnectionData(self):
        result = self.__dbConnector.getVMsConnectionData()
        expectedResult = [
                          {"UserID": 1, "VMID": 1, "VMName" :"VMName11", "VNCPort" : 1, "VNCPass" : "1234567890"},
                          {"UserID": 1, "VMID": 1, "VMName" :"VMName22", "VNCPort" : 2, "VNCPass" : "1234567890"},
                          {"UserID": 2, "VMID": 1, "VMName" :"VMName33", "VNCPort" : 3, "VNCPass" : "1234567890Test"},
                          {"UserID": 3, "VMID": 1, "VMName" :"VMName44", "VNCPort" : 4, "VNCPass" : "1234567890"}
                          ]
        self.assertEquals(result, expectedResult, "getVMsConnectionData does not work")
        
    def test_getVMBootCommand(self):
        result = self.__dbConnector.getVMBootCommand("VMName44")
        expectedResult = "123"
        self.assertEquals(result, expectedResult, "getVMBootCommand does not work")
        result = self.__dbConnector.getVMBootCommand("VMName33")
        self.assertEquals(result, None, "getVMBootCommand does not work")
        
    def test_addVMBootCommand(self):
        self.__dbConnector.addVMBootCommand("VMName33", "1234")
        result = self.__dbConnector.getVMBootCommand("VMName33")
        self.assertEquals(result, "1234", "addVMBootCommand does not work")
        
    def test_getDomainImageDataPath(self):
        result = self.__dbConnector.getDomainImageDataPath("VMName33")
        expectedResult = "./VMNameCopy2"
        self.assertEquals(result, expectedResult, "getDomainImageDataPath does not work")
        
    def test_getOSImagePath(self):
        result = self.__dbConnector.getOsImagePath(1)
        expectedResult = "./VMName1/"
        self.assertEquals(result, expectedResult, "getOSImageDataPath does not work")  
        
    def test_getRegisteredDomainNames(self):
        result = self.__dbConnector.getRegisteredDomainNames()
        expectedResult = ["VMName11", "VMName22", "VMName33", "VMName44"]
        self.assertEquals(result, expectedResult, "getActiveDomainNames() does not work")      
示例#4
0
 def setUp(self):
     self.__dbConfigurator = DBConfigurator("")
     self.__dbConfigurator.runSQLScript("VMServerDBTest", "./VMServerDBTest.sql")
     self.__dbConfigurator.addUser("CygnusCloud", "cygnuscloud2012", "VMServerDBTest", True)
     self.__dbConnector = VMServerDBConnector("CygnusCloud", "cygnuscloud2012", "VMServerDBTest")
示例#5
0
class DBWebServerTests(unittest.TestCase):
    '''
        Clase con las pruebas unitarias de la base de datos del servidor de máquinas
        virtuales
    '''    
    def setUp(self):
        self.__dbConfigurator = DBConfigurator("")
        self.__dbConfigurator.runSQLScript("VMServerDBTest", "./VMServerDBTest.sql")
        self.__dbConfigurator.addUser("CygnusCloud", "cygnuscloud2012", "VMServerDBTest", True)
        self.__dbConnector = VMServerDBConnector("CygnusCloud", "cygnuscloud2012", "VMServerDBTest")
    
    def tearDown(self):
        self.__dbConnector.disconnect()
        self.__dbConfigurator.dropDatabase("VMServerDBTest")
     
    def test_getImages(self):
        result = self.__dbConnector.getImageIDs()
        expectedResult = [1, 2, 3, 4]
        self.assertEquals(result, expectedResult, "getImageIDs() error")
          
            
    def test_getDataImagePath(self):
        result = self.__dbConnector.getDataImagePath(1)
        expectedResult = "./VMName1/Data.qcow2"
        self.assertEquals(result, expectedResult, "getDataImagePath() error")   
          
    def test_getOSImagePath(self):
        result = self.__dbConnector.getOSImagePath(1)
        expectedResult = "./VMName1/OS.qcow2"
        self.assertEquals(result, expectedResult, "getOSImagePath() error")   
          
    def test_getDefinitionFilePath(self):
        result = self.__dbConnector.getDefinitionFilePath(1)
        expectedResult = "./VMName1/Definition.xml"
        self.assertEquals(result, expectedResult, "getDefinitionFilePath() error")   
           
    def test_createImage(self):
        self.__dbConnector.createImage(123, "Image/OS.qcow2", "Image/Data.qcow2", "Image/Definition.xml", 0)
        result = self.__dbConnector.getOSImagePath(123)
        expectedResult = "Image/OS.qcow2"
        self.assertEquals(result, expectedResult, "createImage() error")   
        result = self.__dbConnector.getDataImagePath(123)
        expectedResult = "Image/Data.qcow2"
        self.assertEquals(result, expectedResult, "createImage() error")  
        result = self.__dbConnector.getDefinitionFilePath(123)
        expectedResult = "Image/Definition.xml"
        self.assertEquals(result, expectedResult, "createImage() error")   
        result = self.__dbConnector.getBootableFlag(123)
        expectedResult = False
        self.assertEquals(result, expectedResult, "createImage() error")   
           
    def test_deleteImage(self):
        self.__dbConnector.deleteImage(1)
        result = self.__dbConnector.getOSImagePath(1)
        expectedResult = None
        self.assertEquals(result, expectedResult, "deleteImage() error")  
           
    def test_getDomainImageID(self):
        result = self.__dbConnector.getDomainImageID("1_1")
        expectedResult = 1
        self.assertEquals(result, expectedResult, "getDomainImageID() error") 
           
    def test_getDomainDataImagePath(self):
        result = self.__dbConnector.getDomainDataImagePath("1_1")
        expectedResult = "./DataImagePath1"
        self.assertEquals(result, expectedResult, "getDomainDataImagePath() error") 
       
    def test_getDomainOSImagePath(self):
        result = self.__dbConnector.getDomainOSImagePath("1_1")
        expectedResult = "./OSImagePath1"
        self.assertEquals(result, expectedResult, "getDomainOSImagePath() error") 
           
    def test_getDomainMACAddress(self):
        result = self.__dbConnector.getDomainMACAddress("1_1")
        expectedResult = "2C:00:00:00:00:00"
        self.assertEquals(result, expectedResult, "getDomainMACAddress() error") 
           
    def test_getDomainUUID(self):
        result = self.__dbConnector.getDomainUUID("1_1")
        expectedResult = "fce02cff-5d6d-11e2-a3f0-001f16b99e1d"
        self.assertEquals(result, expectedResult, "getDomainUUID() error") 
          
    def test_getDomainVNCPassword(self):
        result = self.__dbConnector.getDomainVNCPassword("1_1")
        expectedResult = "12134567890"
        self.assertEquals(result, expectedResult, "getDomainVNCPassword() error") 
          
    def test_getWebsockifyDaemonPID(self):
        result = self.__dbConnector.getWebsockifyDaemonPID("1_1")
        expectedResult = 1
        self.assertEquals(result, expectedResult, "getWebsockifyDaemonPID() error") 
   
    def test_getDomainNameFromVNCPort(self):
        result = self.__dbConnector.getDomainNameFromVNCPort(1)
        expectedResult = "1_1"
        self.assertEquals(result, expectedResult, "getDomainNameFromVNCPort() error") 
          
    def test_registerVMResources(self):
        self.__dbConnector.registerVMResources("1_20", 1, 2000, "aaa", 1, 2, "OS_20.qcow2", "Data_20.qcow2", "MAC_20", "UUID_20")
        result = self.__dbConnector.getDomainNameFromVNCPort(2000)
        expectedResult = "1_20"
        self.assertEquals(result, expectedResult, "registerVMSResources() error")
        result = self.__dbConnector.getDomainVNCPassword("1_20")
        expectedResult = "aaa"
        self.assertEquals(result, expectedResult, "registerVMSResources() error")
        result = self.__dbConnector.getDomainOwnerID("1_20")
        expectedResult = 1
        self.assertEquals(result, expectedResult, "registerVMSResources() error")
        result = self.__dbConnector.getWebsockifyDaemonPID("1_20")
        expectedResult = 2
        self.assertEquals(result, expectedResult, "registerVMSResources() error")
        result = self.__dbConnector.getDomainOSImagePath("1_20")
        expectedResult = "OS_20.qcow2"
        self.assertEquals(result, expectedResult, "registerVMSResources() error")
        result = self.__dbConnector.getDomainDataImagePath("1_20")
        expectedResult = "Data_20.qcow2"
        self.assertEquals(result, expectedResult, "registerVMSResources() error")
        result = self.__dbConnector.getDomainMACAddress("1_20")
        expectedResult = "MAC_20"
        self.assertEquals(result, expectedResult, "registerVMSResources() error")
        result = self.__dbConnector.getDomainUUID("1_20")
        expectedResult = "UUID_20"
        self.assertEquals(result, expectedResult, "registerVMSResources() error")
          
    def test_unregisterDomainResources(self):
        self.__dbConnector.unregisterDomainResources("1_1")
        result = self.__dbConnector.getDomainOSImagePath("1_1")
        expectedResult = None
        self.assertEquals(result, expectedResult, "unregisterDomainResources() error")
          
    def test_getOwnerID(self):
        result = self.__dbConnector.getDomainOwnerID("1_1")
        expectedResult = 1
        self.assertEquals(result, expectedResult, "getOwnerID() error")
         
    def test_getVMBootCommand(self):
        result = self.__dbConnector.getVMBootCommand("4_4")
        expectedResult = "Command4"
        self.assertEquals(result, expectedResult, "getVMBootCommand() error")
        result = self.__dbConnector.getVMBootCommand("3_3")
        self.assertEquals(result, "Command3", "getVMBootCommand() error")
  
         
    def test_addVMBootCommand(self):
        self.__dbConnector.registerVMResources("5_5", 1, 1, "123", 1, 1, "os", "data", "mac", "uuid")
        self.__dbConnector.addVMBootCommand("5_5", "1234")
        result = self.__dbConnector.getVMBootCommand("5_5")
        self.assertEquals(result, "1234", "addVMBootCommand() error")
  
    def test_getBootableFlag(self):
        result = self.__dbConnector.getBootableFlag(2)
        expectedResult = True
        self.assertEquals(result, expectedResult, "getBootableFlag() error")
          
    def test_getRegisteredDomainNames(self):
        result = self.__dbConnector.getRegisteredDomainNames()
        expectedResult = ["1_1", "2_2", "3_3", "4_4"]
        self.assertEquals(result, expectedResult, "getRegisteredDomainNames() error")    
         
    def test_transferQueue(self):
        expectedResult = dict()
        expectedResult["Transfer_Type"] = TRANSFER_T.STORE_IMAGE
        expectedResult["FTPTimeout"] = 100
        expectedResult["TargetImageID"] = 2
        expectedResult["RepositoryIP"] = "192.168.0.1"
        expectedResult["RepositoryPort"] = 3000
        expectedResult["CommandID"] = "1"
        expectedResult["SourceFilePath"] ="/tmp/foo.zip"
        self.__dbConnector.addToTransferQueue(expectedResult)
        result = self.__dbConnector.peekFromTransferQueue()
        self.assertEquals(result, expectedResult, "addToTransferQueue() error")
        self.__dbConnector.removeFirstElementFromTransferQueue()
        expectedResult = dict()
        expectedResult["Transfer_Type"] = TRANSFER_T.EDIT_IMAGE
        expectedResult["FTPTimeout"] = 100
        expectedResult["SourceImageID"] = 2
        expectedResult["RepositoryIP"] = "192.168.0.1"
        expectedResult["RepositoryPort"] = 3000
        expectedResult["CommandID"] = "1"
        expectedResult["UserID"] = 1
        self.__dbConnector.addToTransferQueue(expectedResult)
        result = self.__dbConnector.peekFromTransferQueue()
        self.assertEquals(result, expectedResult, "addToTransferQueue() error")
         
    def test_addToCompressionQueue(self):
        expectedResult = dict()
        expectedResult["Transfer_Type"] = TRANSFER_T.STORE_IMAGE
        expectedResult["CommandID"] = "1"
        expectedResult["TargetImageID"] = 1
        expectedResult["OSImagePath"] = "os.qcow"
        expectedResult["DataImagePath"] = "data.qcow2"
        expectedResult["DefinitionFilePath"] = "definition.xml"
        expectedResult["RepositoryIP"] = "192.198.0.2"
        expectedResult["RepositoryPort"] = 3000
        self.__dbConnector.addToCompressionQueue(expectedResult)
        result = self.__dbConnector.peekFromCompressionQueue()
        self.assertEquals(result, expectedResult, "addToCompressionQueue() error")
        self.__dbConnector.removeFirstElementFromCompressionQueue()
        expectedResult = dict()
        expectedResult["Transfer_Type"] = TRANSFER_T.EDIT_IMAGE
        expectedResult["CommandID"] = "1"
        expectedResult["TargetImageID"] = 1
        expectedResult["SourceImageID"] = 2
        expectedResult["UserID"] = 3
        self.__dbConnector.addToCompressionQueue(expectedResult)
        result = self.__dbConnector.peekFromCompressionQueue()
        self.assertEquals(result, expectedResult, "addToCompressionQueue() error")   
         
    def test_connectionDataDictionary(self):
        result = self.__dbConnector.getImageRepositoryConnectionData("1")
        expectedResult = None
        self.assertEquals(result, expectedResult, "getImageRepositoryConnectionData() error")
        expectedResult = dict()
        expectedResult["RepositoryIP"] = "192.168.0.5"
        expectedResult["RepositoryPort"] = 30000
        self.__dbConnector.addValueToConnectionDataDictionary("1", expectedResult)
        result = self.__dbConnector.getImageRepositoryConnectionData("1")
        self.assertEquals(result, expectedResult, "getImageRepositoryConnectionData() error")
        self.__dbConnector.removeImageRepositoryConnectionData("1")
        result = self.__dbConnector.getImageRepositoryConnectionData("1")
        expectedResult = None
        self.assertEquals(result, expectedResult, "removeImageRepositoryConnectionData() error")
示例#6
0
class DBWebServerTests(unittest.TestCase):
    '''
        Clase con las pruebas unitarias de la base de datos del servidor de máquinas
        virtuales
    '''
    def setUp(self):
        self.__dbConfigurator = DBConfigurator("")
        self.__dbConfigurator.runSQLScript("VMServerDBTest",
                                           "./VMServerDBTest.sql")
        self.__dbConfigurator.addUser("CygnusCloud", "cygnuscloud2012",
                                      "VMServerDBTest", True)
        self.__dbConnector = VMServerDBConnector("CygnusCloud",
                                                 "cygnuscloud2012",
                                                 "VMServerDBTest")

    def tearDown(self):
        self.__dbConnector.disconnect()
        self.__dbConfigurator.dropDatabase("VMServerDBTest")

    def test_getImages(self):
        result = self.__dbConnector.getImageIDs()
        expectedResult = [1, 2, 3, 4]
        self.assertEquals(result, expectedResult, "getImageIDs() error")

    def test_getDataImagePath(self):
        result = self.__dbConnector.getDataImagePath(1)
        expectedResult = "./VMName1/Data.qcow2"
        self.assertEquals(result, expectedResult, "getDataImagePath() error")

    def test_getOSImagePath(self):
        result = self.__dbConnector.getOSImagePath(1)
        expectedResult = "./VMName1/OS.qcow2"
        self.assertEquals(result, expectedResult, "getOSImagePath() error")

    def test_getDefinitionFilePath(self):
        result = self.__dbConnector.getDefinitionFilePath(1)
        expectedResult = "./VMName1/Definition.xml"
        self.assertEquals(result, expectedResult,
                          "getDefinitionFilePath() error")

    def test_createImage(self):
        self.__dbConnector.createImage(123, "Image/OS.qcow2",
                                       "Image/Data.qcow2",
                                       "Image/Definition.xml", 0)
        result = self.__dbConnector.getOSImagePath(123)
        expectedResult = "Image/OS.qcow2"
        self.assertEquals(result, expectedResult, "createImage() error")
        result = self.__dbConnector.getDataImagePath(123)
        expectedResult = "Image/Data.qcow2"
        self.assertEquals(result, expectedResult, "createImage() error")
        result = self.__dbConnector.getDefinitionFilePath(123)
        expectedResult = "Image/Definition.xml"
        self.assertEquals(result, expectedResult, "createImage() error")
        result = self.__dbConnector.getBootableFlag(123)
        expectedResult = False
        self.assertEquals(result, expectedResult, "createImage() error")

    def test_deleteImage(self):
        self.__dbConnector.deleteImage(1)
        result = self.__dbConnector.getOSImagePath(1)
        expectedResult = None
        self.assertEquals(result, expectedResult, "deleteImage() error")

    def test_getDomainImageID(self):
        result = self.__dbConnector.getDomainImageID("1_1")
        expectedResult = 1
        self.assertEquals(result, expectedResult, "getDomainImageID() error")

    def test_getDomainDataImagePath(self):
        result = self.__dbConnector.getDomainDataImagePath("1_1")
        expectedResult = "./DataImagePath1"
        self.assertEquals(result, expectedResult,
                          "getDomainDataImagePath() error")

    def test_getDomainOSImagePath(self):
        result = self.__dbConnector.getDomainOSImagePath("1_1")
        expectedResult = "./OSImagePath1"
        self.assertEquals(result, expectedResult,
                          "getDomainOSImagePath() error")

    def test_getDomainMACAddress(self):
        result = self.__dbConnector.getDomainMACAddress("1_1")
        expectedResult = "2C:00:00:00:00:00"
        self.assertEquals(result, expectedResult,
                          "getDomainMACAddress() error")

    def test_getDomainUUID(self):
        result = self.__dbConnector.getDomainUUID("1_1")
        expectedResult = "fce02cff-5d6d-11e2-a3f0-001f16b99e1d"
        self.assertEquals(result, expectedResult, "getDomainUUID() error")

    def test_getDomainVNCPassword(self):
        result = self.__dbConnector.getDomainVNCPassword("1_1")
        expectedResult = "12134567890"
        self.assertEquals(result, expectedResult,
                          "getDomainVNCPassword() error")

    def test_getWebsockifyDaemonPID(self):
        result = self.__dbConnector.getWebsockifyDaemonPID("1_1")
        expectedResult = 1
        self.assertEquals(result, expectedResult,
                          "getWebsockifyDaemonPID() error")

    def test_getDomainNameFromVNCPort(self):
        result = self.__dbConnector.getDomainNameFromVNCPort(1)
        expectedResult = "1_1"
        self.assertEquals(result, expectedResult,
                          "getDomainNameFromVNCPort() error")

    def test_registerVMResources(self):
        self.__dbConnector.registerVMResources("1_20", 1, 2000, "aaa", 1, 2,
                                               "OS_20.qcow2", "Data_20.qcow2",
                                               "MAC_20", "UUID_20")
        result = self.__dbConnector.getDomainNameFromVNCPort(2000)
        expectedResult = "1_20"
        self.assertEquals(result, expectedResult,
                          "registerVMSResources() error")
        result = self.__dbConnector.getDomainVNCPassword("1_20")
        expectedResult = "aaa"
        self.assertEquals(result, expectedResult,
                          "registerVMSResources() error")
        result = self.__dbConnector.getDomainOwnerID("1_20")
        expectedResult = 1
        self.assertEquals(result, expectedResult,
                          "registerVMSResources() error")
        result = self.__dbConnector.getWebsockifyDaemonPID("1_20")
        expectedResult = 2
        self.assertEquals(result, expectedResult,
                          "registerVMSResources() error")
        result = self.__dbConnector.getDomainOSImagePath("1_20")
        expectedResult = "OS_20.qcow2"
        self.assertEquals(result, expectedResult,
                          "registerVMSResources() error")
        result = self.__dbConnector.getDomainDataImagePath("1_20")
        expectedResult = "Data_20.qcow2"
        self.assertEquals(result, expectedResult,
                          "registerVMSResources() error")
        result = self.__dbConnector.getDomainMACAddress("1_20")
        expectedResult = "MAC_20"
        self.assertEquals(result, expectedResult,
                          "registerVMSResources() error")
        result = self.__dbConnector.getDomainUUID("1_20")
        expectedResult = "UUID_20"
        self.assertEquals(result, expectedResult,
                          "registerVMSResources() error")

    def test_unregisterDomainResources(self):
        self.__dbConnector.unregisterDomainResources("1_1")
        result = self.__dbConnector.getDomainOSImagePath("1_1")
        expectedResult = None
        self.assertEquals(result, expectedResult,
                          "unregisterDomainResources() error")

    def test_getOwnerID(self):
        result = self.__dbConnector.getDomainOwnerID("1_1")
        expectedResult = 1
        self.assertEquals(result, expectedResult, "getOwnerID() error")

    def test_getVMBootCommand(self):
        result = self.__dbConnector.getVMBootCommand("4_4")
        expectedResult = "Command4"
        self.assertEquals(result, expectedResult, "getVMBootCommand() error")
        result = self.__dbConnector.getVMBootCommand("3_3")
        self.assertEquals(result, "Command3", "getVMBootCommand() error")

    def test_addVMBootCommand(self):
        self.__dbConnector.registerVMResources("5_5", 1, 1, "123", 1, 1, "os",
                                               "data", "mac", "uuid")
        self.__dbConnector.addVMBootCommand("5_5", "1234")
        result = self.__dbConnector.getVMBootCommand("5_5")
        self.assertEquals(result, "1234", "addVMBootCommand() error")

    def test_getBootableFlag(self):
        result = self.__dbConnector.getBootableFlag(2)
        expectedResult = True
        self.assertEquals(result, expectedResult, "getBootableFlag() error")

    def test_getRegisteredDomainNames(self):
        result = self.__dbConnector.getRegisteredDomainNames()
        expectedResult = ["1_1", "2_2", "3_3", "4_4"]
        self.assertEquals(result, expectedResult,
                          "getRegisteredDomainNames() error")

    def test_transferQueue(self):
        expectedResult = dict()
        expectedResult["Transfer_Type"] = TRANSFER_T.STORE_IMAGE
        expectedResult["FTPTimeout"] = 100
        expectedResult["TargetImageID"] = 2
        expectedResult["RepositoryIP"] = "192.168.0.1"
        expectedResult["RepositoryPort"] = 3000
        expectedResult["CommandID"] = "1"
        expectedResult["SourceFilePath"] = "/tmp/foo.zip"
        self.__dbConnector.addToTransferQueue(expectedResult)
        result = self.__dbConnector.peekFromTransferQueue()
        self.assertEquals(result, expectedResult, "addToTransferQueue() error")
        self.__dbConnector.removeFirstElementFromTransferQueue()
        expectedResult = dict()
        expectedResult["Transfer_Type"] = TRANSFER_T.EDIT_IMAGE
        expectedResult["FTPTimeout"] = 100
        expectedResult["SourceImageID"] = 2
        expectedResult["RepositoryIP"] = "192.168.0.1"
        expectedResult["RepositoryPort"] = 3000
        expectedResult["CommandID"] = "1"
        expectedResult["UserID"] = 1
        self.__dbConnector.addToTransferQueue(expectedResult)
        result = self.__dbConnector.peekFromTransferQueue()
        self.assertEquals(result, expectedResult, "addToTransferQueue() error")

    def test_addToCompressionQueue(self):
        expectedResult = dict()
        expectedResult["Transfer_Type"] = TRANSFER_T.STORE_IMAGE
        expectedResult["CommandID"] = "1"
        expectedResult["TargetImageID"] = 1
        expectedResult["OSImagePath"] = "os.qcow"
        expectedResult["DataImagePath"] = "data.qcow2"
        expectedResult["DefinitionFilePath"] = "definition.xml"
        expectedResult["RepositoryIP"] = "192.198.0.2"
        expectedResult["RepositoryPort"] = 3000
        self.__dbConnector.addToCompressionQueue(expectedResult)
        result = self.__dbConnector.peekFromCompressionQueue()
        self.assertEquals(result, expectedResult,
                          "addToCompressionQueue() error")
        self.__dbConnector.removeFirstElementFromCompressionQueue()
        expectedResult = dict()
        expectedResult["Transfer_Type"] = TRANSFER_T.EDIT_IMAGE
        expectedResult["CommandID"] = "1"
        expectedResult["TargetImageID"] = 1
        expectedResult["SourceImageID"] = 2
        expectedResult["UserID"] = 3
        self.__dbConnector.addToCompressionQueue(expectedResult)
        result = self.__dbConnector.peekFromCompressionQueue()
        self.assertEquals(result, expectedResult,
                          "addToCompressionQueue() error")

    def test_connectionDataDictionary(self):
        result = self.__dbConnector.getImageRepositoryConnectionData("1")
        expectedResult = None
        self.assertEquals(result, expectedResult,
                          "getImageRepositoryConnectionData() error")
        expectedResult = dict()
        expectedResult["RepositoryIP"] = "192.168.0.5"
        expectedResult["RepositoryPort"] = 30000
        self.__dbConnector.addValueToConnectionDataDictionary(
            "1", expectedResult)
        result = self.__dbConnector.getImageRepositoryConnectionData("1")
        self.assertEquals(result, expectedResult,
                          "getImageRepositoryConnectionData() error")
        self.__dbConnector.removeImageRepositoryConnectionData("1")
        result = self.__dbConnector.getImageRepositoryConnectionData("1")
        expectedResult = None
        self.assertEquals(result, expectedResult,
                          "removeImageRepositoryConnectionData() error")