def disconnectFromClusterServer(self): """ Closes the connection with the cluster server and drops the databases. Args: haltVMServers: if True, the virtual machine servers will be halted immediately. If false, they will be halted until all their virtual machines have been shut down. Returns: Nothing @attention: DO NOT call this method inside a network thread (i.e. inside the web callback). If you do so, your application will hang. """ # Send a halt packet to the cluster server p = self.__pHandler.createHaltPacket(self.__haltVMServers) self.__manager.sendPacket(self.__clusterServerIP, self.__clusterServerPort, p) # Stop the update request thread self.__updateRequestThread.stop() # Close the database connections self.__commandsDBConnector.disconnect() self.__writer.disconnect() # Stop the network service self.__manager.stopNetworkService() # Delete the status database dbConfigurator = DBConfigurator(self.__rootsPassword) dbConfigurator.dropDatabase(self.__statusDatabaseName) dbConfigurator.dropDatabase(self.__commandsDatabaseName)
def tearDown(self): ''' This method will be ran after EVERY unit test. ''' self.__connector.disconnect() dbConfigurator = DBConfigurator("") dbConfigurator.dropDatabase("ClusterServerDBTest")
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 setUp(self): # Create the database self.__dbConfigurator = DBConfigurator("") self.__dbConfigurator.runSQLScript("CommandsDBTest", "./CommandsDBTest.sql") # Add a user to it self.__dbConfigurator.addUser("cygnuscloud", "cygnuscloud", "CommandsDBTest") self.__connector = CommandsDatabaseConnector("cygnuscloud", "cygnuscloud", "CommandsDBTest", 1) self.__connector.connect()
def setUp(self): ''' This method will be ran before EVERY unit test. ''' # Create the database dbConfigurator = DBConfigurator("") dbConfigurator.runSQLScript("ClusterServerDBTest", "./ClusterServerDBTest.sql") # Add a user to it dbConfigurator.addUser("cygnuscloud", "cygnuscloud", "ClusterServerDBTest") self.__connector = ClusterServerDatabaseConnector( "cygnuscloud", "cygnuscloud", "ClusterServerDBTest")
def disconnectFromMainServer(self): # Discard all the incoming packets and the scheduled updates self.__stopped = True # Stop the update request thread self.__updateRequestThread.stop() # Close the database connections self.__reader.disconnect() self.__writer.disconnect() # Stop the network service self.__manager.stopNetworkService() # Delete the status database dbConfigurator = DBConfigurator(self.__rootsPassword) dbConfigurator.dropDatabase(self.__databaseName)
def closeNetworkAndDBConnections(self): """ Cierra las conexiones con las bases de datos Argumentos: Ninguno Devuelve: Nada """ # Detener el servicio de red self.__manager.stopNetworkService() # Borrar las bases de datos de comandos y de estado dbConfigurator = DBConfigurator(self.__rootsPassword) dbConfigurator.dropDatabase(self.__commandsDatabaseName)
def setUp(self): dbConfigurator = DBConfigurator("") dbConfigurator.runSQLScript("SystemStatusDBTest", "./SystemStatusDBTest.sql") dbConfigurator.addUser("website", "cygnuscloud", "SystemStatusDBTest", False) dbConfigurator.addUser("statusDBUpdater", "cygnuscloud", "SystemStatusDBTest", True) self.__reader = SystemStatusDatabaseReader("website", "cygnuscloud", "SystemStatusDBTest") self.__reader.connect() self.__writer = SystemStatusDatabaseWriter("statusDBUpdater", "cygnuscloud", "SystemStatusDBTest") self.__writer.connect()
def setUp(self): ''' This method will be ran before EVERY unit test. ''' # Create the database dbConfigurator = DBConfigurator("") dbConfigurator.runSQLScript("ImageRepositoryDBTest", "./ImageRepositoryDBTest.sql") # Add a user to it dbConfigurator.addUser("cygnuscloud", "cygnuscloud", "ImageRepositoryDBTest") self.__connector = ImageRepositoryDBConnector("cygnuscloud", "cygnuscloud", "ImageRepositoryDBTest") self.__connector.connect()
def connectToDatabase(self, mysqlRootsPassword, dbName, dbUser, dbPassword, scriptPath): """ Establishes a connection with the cluster server database. Args: mysqlRootsPassword: MySQL root's password dbName: the cluster server database's name dbUser: the cluster server database's user name dbPassword: the cluster server database's user password scriptPath: the cluster server database's initialization script path """ configurator = DBConfigurator(mysqlRootsPassword) configurator.runSQLScript(dbName, scriptPath) configurator.addUser(dbUser, dbPassword, dbName, True) self.__dbConnector = ClusterServerDatabaseConnector( dbUser, dbPassword, dbName) self.__dbConnector.connect() self.__dbConnector.resetVMServersStatus()
def connectToDatabases(self, mysqlRootsPassword, statusDBName, commandsDBName, statusdbSQLFilePath, commandsDBSQLFilePath, websiteUser, websiteUserPassword, endpointUser, endpointUserPassword): """ Establishes a connection with the system status database. Args: mysqlRootsPassword: MySQL root's password statusDBName: the status database name statusdbSQLFilePath: the database schema definition SQL file path websiteUser: the website user's name. websiteUserPassword: the website user's password endpointUser: the update user's name. This user will have ALL privileges on the status database. endpointUserPassword: the update user's password. """ # Create the status database self.__rootsPassword = mysqlRootsPassword self.__statusDatabaseName = statusDBName self.__commandsDatabaseName = commandsDBName configurator = DBConfigurator(mysqlRootsPassword) configurator.runSQLScript(statusDBName, statusdbSQLFilePath) configurator.runSQLScript(commandsDBName, commandsDBSQLFilePath) # Register the website and the endpoint users configurator.addUser(websiteUser, websiteUserPassword, statusDBName, False) configurator.addUser(endpointUser, endpointUserPassword, statusDBName, True) configurator.addUser(websiteUser, websiteUserPassword, commandsDBName, True) configurator.addUser(endpointUser, endpointUserPassword, commandsDBName, True) # Create the database connectors self.__commandsDBConnector = CommandsDatabaseConnector( endpointUser, endpointUserPassword, commandsDBName, 1) self.__writer = SystemStatusDatabaseWriter(endpointUser, endpointUserPassword, statusDBName) # Connect to the database self.__writer.connect() self.__commandsDBConnector.connect()
def connectToDatabases(self, mysqlRootsPassword, statusDBName, commandsDBName, statusdbSQLFilePath, commandsDBSQLFilePath, websiteUser, websiteUserPassword, endpointUser, endpointUserPassword, minCommandInterval): """ Establece la conexión con la base de datos de estado y con la base de datos de comandos. Argumentos: mysqlRootsPassword: la contraseña de root de MySQL statusDBName: el nombre de la base de datos de estado statusdbSQLFilePath: la ruta del script que crea la base de datos de estado websiteUser: nombre de usuario que usará la web para manipular las bases de datos websiteUserPassword: contraseña del usuario de la web endpointUser: usuario que utilizará en eldpoint para manipular las bases de datos de estado. Será el único que puede escribir en la base de datos de estado. endpointUserPassword: contraseña del usuario del endpoint """ # Crear las bases de datos self.__rootsPassword = mysqlRootsPassword self.__statusDatabaseName = statusDBName self.__commandsDatabaseName = commandsDBName configurator = DBConfigurator(mysqlRootsPassword) configurator.runSQLScript(statusDBName, statusdbSQLFilePath) configurator.runSQLScript(commandsDBName, commandsDBSQLFilePath) # Registrar en ellas los usuarios configurator.addUser(websiteUser, websiteUserPassword, statusDBName, False) configurator.addUser(endpointUser, endpointUserPassword, statusDBName, True) configurator.addUser(websiteUser, websiteUserPassword, commandsDBName, True) configurator.addUser(endpointUser, endpointUserPassword, commandsDBName, True) # Crear los conectores self.__commandsDBConnector = CommandsDatabaseConnector( endpointUser, endpointUserPassword, commandsDBName, minCommandInterval) self.__endpointDBConnector = ClusterEndpointDBConnector( endpointUser, endpointUserPassword, statusDBName)
def connectToDatabase(self, rootsPassword, databaseName, websiteUser, websiteUserPassword, updateUser, updateUserPassword): # Create the status database self.__rootsPassword = rootsPassword self.__databaseName = databaseName configurator = DBConfigurator(rootsPassword) configurator.runSQLScript(databaseName, "../../database/SystemStatusDB.sql") # Register the website and the update users configurator.addUser(websiteUser, websiteUserPassword, databaseName, False) configurator.addUser(updateUser, updateUserPassword, databaseName, True) # Create the database connectors self.__reader = SystemStatusDatabaseReader(websiteUser, websiteUserPassword, databaseName) self.__writer = SystemStatusDatabaseWriter(updateUser, updateUserPassword, databaseName) # Connect to the database self.__reader.connect() self.__writer.connect()
def tearDown(self): self.__reader.disconnect() self.__writer.disconnect() dbConfigurator = DBConfigurator("") dbConfigurator.dropDatabase("SystemStatusDBTest")
typeId = userM.createType("TypeTest") self.assertTrue(userM.isTypeExists(typeId), "type not created") def test_deleteType(self): userM = UserManagement("CygnusCloud", "cygnuscloud2012", "WebServerDBTest", 1) userM.deleteType(4) self.assertFalse(userM.isTypeExists(4), "type not deleted") def test_groupIds(self): userM = UserManagement("CygnusCloud", "cygnuscloud2012", "WebServerDBTest", 1) l1 = userM.getGroupId("VMName1") l2 = [1] self.assertEquals(l1, l2, "Not Same groups") def test_userIds(self): userM = UserManagement("CygnusCloud", "cygnuscloud2012", "WebServerDBTest", 1) l1 = userM.getUsersId(1) l2 = [2, 3, 5] self.assertEquals(l1, l2, "Not Same users") if __name__ == "__main__": #Cargamos el script de prueba dbUtils = DBConfigurator("") dbUtils.runSQLScript("WebServerDBTest", "./WebServerDBTest.sql") dbUtils.addUser("CygnusCloud", "cygnuscloud2012", "WebServerDBTest") unittest.main()