Beispiel #1
0
    def testCreateDeleteUnit(self):

        # self.assertTrue(vmLB.containedUnits)
        # self.assertFalse(len(haproxy.containedUnits) > 0)

        commands.getoutput("rm /tmp/A.sql")
        databasePath = "/tmp/A.sql"
        db = DatabaseManagement(dbPath=databasePath)

        vmLB = Unit(name="VM.LoadBalancer", type=UnitType.VirtualMachine)
        haproxy = Unit(name="HAProxy", type=UnitType.Process)
        proxyConfigService = Unit(name="ConfigService", type=UnitType.Process)

        vmLB.hosts(proxyConfigService, haproxy)

        mqtt = Unit(name="LoadBalancer",
                    type=UnitType.Composite,
                    containedUnits=[vmLB, haproxy, proxyConfigService])

        vmEP = Unit(name="VM.EventProcessing", type=UnitType.VirtualMachine)
        dassWS = Unit(name="EventProcessingService", type=UnitType.Process)

        vmEP.hosts(dassWS)
        eventProcessing = Unit(name="EventProcessing",
                               type=UnitType.Composite,
                               containedUnits=[vmEP, dassWS])

        eventProcessing.connectsTo(haproxy)

        service = Unit(name="System",
                       type=UnitType.Composite,
                       containedUnits=[mqtt, eventProcessing])

        system_dao = SystemDAO(name=service.name,
                               description=pickle.dumps(service))

        db.add(system_dao)

        system_dao = SystemDAO(name=service.name,
                               description=pickle.dumps(service))

        system = db.getSystem(system_dao)

        db.add(UnitDAO.toDAO(vmLB, system.id))

        unit = db.getUnit(UnitDAO.toDAO(vmLB, system.id), system)

        print unit.name
Beispiel #2
0
    def addSystemUnit(self, user, system, unit):
        static_system_unit = SystemDAO(name=system.name)
        #1 update system structure
        if self.db.existsSystem(static_system_unit):
            lock = threading.Lock()
            lock.acquire()
            try:
                # self.db.add(UnitDAO.toDAO(unit))
                # unit = self.db.getUnit(unit)
                static_system = self.db.getSystem(static_system_unit)
                #check if type allready inserted, and if yes, do not add it again
                unitTypeDAO = UnitTypeDAO.toDAO(unit.type)
                if self.db.existsUnitType(unitTypeDAO):
                    unitTypeDAO = self.db.getUnitTypeByID(unitTypeDAO.type)
                unitDAO = UnitDAO.toDAO(unit, static_system.id, unitTypeDAO)
                if not self.db.existsUnit(unitDAO, static_system):
                    self.db.add(unitDAO)
            finally:
                lock.release()
        else:
            logging.warn("System with ID " + str(system.name) + " and UUID " +
                         str(system.uuid) + " does not exist")
        #2. now we need to start listening to the queue of test results for the added unit

        queueResultsListeningArgs = self.queue.listenToMessages(
            self.queueIP,
            system.name,
            binding_keys=[system.name + "." + unit.uuid + ".results"],
            username=user.username,
            password=user.password,
            exchange=unit.name,
            queueName=unit.uuid + "-Results",
            callback=self.testManagementEngine.handleReceivedTestResults)
Beispiel #3
0
    def removeSystem(self, user, system):

        static_system_dao = SystemDAO(
            name=system.name)  #static description has no UUID

        system_units = self.db.getSystemUnits(static_system_dao)
        events = self.db.deleteAllEventsForSystem(system)
        events = self.db.deleteAllTestSessionsForSystem(system)
        result = self.db.deleteAllTestExecutionsForSystem(system)
        result = self.db.deleteAllTestResultsForSystem(system)

        for unit in system_units:
            self.removeSystemUnit(user, unit)
        self.db.removeSystem(static_system_dao)

        self.queue.removeQueue(self.queueIP,
                               system.name,
                               username=user.username,
                               password=user.password,
                               queueName="alive")
        self.queue.removeQueue(self.queueIP,
                               system.name,
                               username=user.username,
                               password=user.password,
                               queueName="dead")
        self.queue.removeQueue(self.queueIP,
                               system.name,
                               username=user.username,
                               password=user.password,
                               queueName="events")

        QueueUtil.removeUserAccessToSystem(self.queueIP, self.queueCredentials,
                                           user, system)
        QueueUtil.removeSystemQueueHost(self.queueIP, self.queueCredentials,
                                        system)
Beispiel #4
0
def deleteSystemEventHistoryAsCSV(system_name):
    user = authenticate_user()
    if not user:
        return Response("Not logged in", mimetype='text/json', status=403)
    controller.deleteEventsForSystem(user, SystemDAO(name=system_name))
    message = "Events successfully removed"
    return Response(message, mimetype='text/x-python', status=200)
Beispiel #5
0
def updateTestDescription():
    user =  authenticate_user()
    if not user:
        return render_template('login.html')

    system = controller.db.getSystem(SystemDAO(name=request.form['system_id']))
    system.genericTests = controller.getGenericTests(user)
    system.customTests = controller.getUserTests(user)

    if request.method == 'POST':
        testName = request.form['testName']

        if request.form['action'] == 'Add/Update':
           testDescriptionContent = request.form['testDescriptionContent']
           #check and remove for SUDO
           try:
             controller.addTestDescription(user,system
                                            , controller.db.getTest(TestDAO(name=testName))
                                           , testDescriptionContent)
           except Exception as e:
                   return render_template('testsmanagement.html', system=system, error=e)
        elif request.form['action'] == 'Reset':
           controller.deleteTestDescription(user,system
                                            , controller.db.getTest(TestDAO(name=testName)))

    return render_template('testsmanagement.html', system=system)
Beispiel #6
0
def getExecutorForubuntu1214Python2(system_id,unit_type, unit_id, unit_uuid):
    auth = request.authorization
    user = User(username=auth.username, password= auth.password)
    system = SystemDAO(name=system_id)
    if not controller.db.hasAccess(user, system):
        message = "User not authorized"
        return Response(message, mimetype='text/x-python', status=403)


    path = ".//resources/artifacts/ubuntu-12-14/python2/remote-executor/testsExecutor.py"
    with open (path, "r") as myfile:
       USERNAME=user.username
       PASSWORD =user.password
       SERVICE_NAME=system_id
       UNIT_ID=unit_id

       data=myfile.read()
       data = data.replace("HEALTH_CENTRAL_QUEUE_IP='localhost'", "HEALTH_CENTRAL_QUEUE_IP='" + str(queueIP)+"'")
       data = data.replace("USERNAME=''", "USERNAME='******'")
       data = data.replace("PASSWORD=''", "PASSWORD='******'")
       data = data.replace("SYSTEM_NAME=''", "SYSTEM_NAME='" + str(SERVICE_NAME)+"'")
       data = data.replace("UNIT_UUID=''", "UNIT_UUID='" + str(unit_uuid)+"'")
       data = data.replace("UNIT_ID=''", "UNIT_ID='" + str(UNIT_ID)+"'")
       data = data.replace("UNIT_TYPE=''", "UNIT_TYPE='" + str(unit_type)+"'")
    return Response(data, mimetype='text/x-python')
Beispiel #7
0
def getLastSystemTestsStatus(system_name):
    user = authenticate_user()
    systemDescription = controller.getLastTestsStatus(
        user, SystemDAO(name=system_name))

    message = json.dumps(
        JSONConverter.systemToJSONAfterHosted(systemDescription))
    return Response(message, mimetype='text/json', status=200)
Beispiel #8
0
def getStaticSystemStructure(system_name):
    user = authenticate_user()
    if not user:
        return Response("Not logged in", mimetype='text/json', status=403)
    systemDescription = controller.getStaticSystemStructure(
        user, SystemDAO(name=system_name))
    message = json.dumps(JSONConverter.systemToJSON(systemDescription))
    return Response(message, mimetype='text/json', status=200)
Beispiel #9
0
def dispatchTests(system_name):
    systemDescription = SystemDAO(name=system_name)
    reason = request.data
    user = authenticate_user()
    if not user:
        return Response("Not logged in", mimetype='text/json', status=403)
    controller.dispatchTests(user, systemDescription, reason)
    message = "Tests dispatched"
    return Response(message, mimetype='text/x-python', status=200)
Beispiel #10
0
def getSuccessRateAnalysisByUUID(system_name):
    user = authenticate_user()
    if not user:
        return Response("Not logged in", mimetype='text/json', status=403)
    systemDescription = controller.getSuccessRateAnalysisByUUID(
        user, SystemDAO(name=system_name))
    message = json.dumps(
        JSONConverter.testSuccessRateToJSON(systemDescription))
    return Response(message, mimetype='text/json', status=200)
Beispiel #11
0
def manageTestsConfigurations():
    user = authenticate_user()
    if not user :
        return render_template('login.html')
    if request.form['action'] == 'ManageTests':
        system = controller.db.getSystem(SystemDAO(name=request.form['system_id']))
        # system.complexTestConfig= controller.getComplexTestsConfiguration(user,system)
        # system.simpleTestConfig= controller.getSimpleTestsConfiguration(user,system)
        system.genericTests = controller.getGenericTests(user)
        system.customTests = controller.getUserTests(user)
        return render_template('testsmanagement.html', system=system)
Beispiel #12
0
def downloadTestConfig(system_name):
    user = authenticate_user()
    if not user:
        return Response("Not logged in", mimetype='text/json', status=403)
    contents = controller.getTestsForSystemAsPickledObject(
        user, SystemDAO(name=system_name))
    response = Response(contents, mimetype='text/other', status=200)
    response.headers._list.append(
        ('Content-Disposition',
         'attachment;filename="' + system_name + '_tests_config.cfg"'))
    response.content_disposition = 'attachment; filename="' + system_name + '_tests_config.cfg"'
    return response
Beispiel #13
0
    def addSystem(self, user, system):

        user_dao = UserDAO.toDAO(user)
        system_dao = SystemDAO(name=system.name,
                               description=pickle.dumps(system))
        if not self.db.existsUser(user):
            return "Credentials for " + user.username + " not correct, or user does not exist"
        self.db.add(system_dao)

        user_dao = self.db.getUser(
            user_dao
        )  #retrieve the suer form the database to add to it the new managed service

        # managedSystemRelationship = UserSystemsDAO(user_id=user_dao.id,system_id=system_dao.id)
        # self.db.add(managedSystemRelationship)

        user_dao.managedSystems.append(system_dao)
        self.db.update(user_dao)

        QueueUtil.addSystemQueueHost(self.queueIP, self.queueCredentials,
                                     system)
        QueueUtil.addUserAccessToSystem(self.queueIP, self.queueCredentials,
                                        user, system)

        self.queue.listenToMessages(
            self.queueIP,
            system.name,
            binding_keys=[system.name + ".lifecycle.alive"],
            username=user.username,
            password=user.password,
            exchange=system.name,
            queueName="alive",
            callback=self.handleReceivedAliveMessage)
        self.queue.listenToMessages(
            self.queueIP,
            system.name,
            binding_keys=[system.name + ".lifecycle.dead"],
            username=user.username,
            password=user.password,
            exchange=system.name,
            queueName="dead",
            callback=self.handleReceivedDeadMessage)
        self.queue.listenToMessages(self.queueIP,
                                    system.name,
                                    binding_keys=[system.name + ".events"],
                                    username=user.username,
                                    password=user.password,
                                    exchange=system.name,
                                    queueName="events",
                                    callback=self.handleReceivedEventMessage)

        return system_dao
Beispiel #14
0
def deleteSystemFromUI():

    user = authenticate_user()
    if not user :
        return render_template('login.html')

    system = controller.db.getSystem(SystemDAO(name=request.form['system_id']))
    controller.removeSystem(user, system)
    systems = []
    user = controller.db.getUser(user)
    for system in user.managedSystems:
        systems.append(system)
    return render_template('systemmanagement.html', systems=systems)
Beispiel #15
0
def manageSystemsConfigurations():
    user = authenticate_user()
    if not user :
        return render_template('login.html')
    if request.method == 'POST':
        if request.form['action'] == 'Delete':
            system = controller.db.getSystem(SystemDAO(name=request.form['system_id']))
            controller.removeSystem(user, system)
            systems = []
            user = controller.db.getUser(user)
            for system in user.managedSystems:
                systems.append(system)
            return render_template('systemmanagement.html', systems=systems)
        elif request.form['action'] == 'DispatchTests':
            system = controller.db.getSystem(SystemDAO(name=request.form['system_id']))
            controller.dispatchTests(user, system, request.form['reason'])
            systems = []
            user = controller.db.getUser(user)
            for system in user.managedSystems:
                systems.append(system)
            return render_template('systemmanagement.html', systems=systems)
        elif request.form['action'] == 'ManageTests':
            system = controller.db.getSystem(SystemDAO(name=request.form['system_id']))
            # system.complexTestConfig= controller.getComplexTestsConfiguration(user,system)
            # system.simpleTestConfig= controller.getSimpleTestsConfiguration(user,system)
            system.genericTests = controller.getGenericTests(user)
            system.customTests = controller.getUserTests(user)
            return render_template('testsmanagement.html', system=system)

        elif request.form['action'] == 'ViewEvents':
            systemID =request.form['system_id']
            system = controller.db.getSystem(SystemDAO( name=systemID))
            events = controller.getAllEventsForSystem(user, system)
            system.events = events
            return render_template('eventsManagement.html', system=system)

        elif request.form['action'] == 'DownloadInstaller':
            systemID =request.form['system_id']
            system = controller.db.getSystem(SystemDAO( name=systemID))
            units = controller.getStaticSystemStructure(user, SystemDAO( name=systemID)).toList()
            units.pop(0) #to unit list and remove self, as self is complex system

            urls = {}

            #traverse shit of system

            for unit in units:
                if unit.type == UnitType.Composite:
                    continue
                command = "wget -q --user="******" --password="******" --auth-no-challenge http://"+ centralPublicIP\
                  +":5001/artifacts/ubuntu12-14-python2/remote-executor/installer/"+systemID+"/" + unit.type + "/" + unit.id +" -O ./install.sh"
                # url = "http://"+ centralIP\
                #   +":5001/artifacts/ubuntu12-14-python2/remote-executor/installer/"+systemID+"/" + unit.type + "/" + unit.id
                urls[unit.id] = command

            system.installers = urls

            return render_template('installerManagement.html', system=system)
Beispiel #16
0
def updateTest():
    user =  authenticate_user()
    if not user :
        return render_template('login.html')
    system = controller.db.getSystem(SystemDAO(name=request.form['system_id']))

    if request.method == 'POST':
        if request.form['action'] == 'Add/Update':
           testName = request.form['testName']
           testContentNoPadded  = request.form['testContent']

           testContent = ""

           #add for each line in content one space on left, to ensure compatibility with
           #test dispatch mechanism which embeds tests in local python method
           lines = testContentNoPadded.splitlines()

           #if first line is padded do not pad (was allready padded), else pad
           if not lines[0].startswith(" "):
             for line in testContentNoPadded.splitlines():
                 testContent = testContent + " " + line + "\n"
           else:
             testContent = testContentNoPadded

           test = TestDAO(name = testName, content = testContent)
           if controller.db.existsTest(test):
               test = controller.db.getTest(test)
               test.content = testContent
               if test in user.managedTests:
                  controller.db.update(test)
           else:
               controller.db.add(test)
               user.managedTests.append(test)
               controller.db.update(user)
        if request.form['action'] == 'Delete':
           testName = request.form['testName']
           test = TestDAO(name = testName)
           if controller.db.existsTest(test):
               test = controller.db.getTest(test)
               #remove test description
               controller.deleteTestDescription(user,system, test)
               user.managedTests.remove(test)
               controller.db.update(user)
               controller.db.remove(test)

    system.genericTests = controller.getGenericTests(user)
    system.customTests = controller.getUserTests(user)

    return render_template('testsmanagement.html', system=system)
Beispiel #17
0
def getSystemEventHistoryAsCSV(system_name):
    user = authenticate_user()
    if not user:
        return Response("Not logged in", mimetype='text/json', status=403)
    events = controller.getAllEventsForSystem(user,
                                              SystemDAO(name=system_name))
    message = ""
    for event in events:
        message = message + str(event.id) + "!" + str(
            event.eventType) + "!" + str(event.details) + "!" + str(
                event.timestamp) + "\n"
    response = Response(message, mimetype='text/csv', status=200)
    response.headers._list.append(
        ('Content-Disposition',
         'attachment;filename="' + system_name + '_events.csv"'))
    response.content_disposition = 'attachment; filename="' + system_name + '_events.csv"'
    return response\
Beispiel #18
0
def getInstallerForubuntu1214Python2Local(system_id, unit_ID, unit_type):

    auth = request.authorization
    user = User(username=auth.username, password= auth.password)
    system = SystemDAO(name=system_id)
    if not controller.db.hasAccess(user, system):
        message = "User not authorized"
        return Response(message, mimetype='text/x-python', status=403)

    path = ".//resources/artifacts/ubuntu-12-14/python2/local-executor/install.sh"
    with open (path, "r") as myfile:
       data=myfile.read()
       data = data.replace("HEALTH_CENTRAL_IP='localhost'", "HEALTH_CENTRAL_IP='" + str(centralPublicIP)+"'")
       data = data.replace("HEALTH_CENTRAL_PORT=*", "HEALTH_CENTRAL_PORT='" + str(centralPort)+"'")
       data = data.replace("USERNAME=''", "USERNAME='******'")
       data = data.replace("PASSWORD=''", "PASSWORD='******'")
       data = data.replace("UNIT_ID=''", "UNIT_ID='" + str(unit_ID)+"'")
       data = data.replace("UNIT_TYPE=''", "UNIT_TYPE='" + str(unit_type)+"'")
       data = data.replace("SYSTEM_NAME=''", "SYSTEM_NAME='" + str(system_id)+"'")
    return Response(data, mimetype='text/x-python')
Beispiel #19
0
    def removeSystemUnit(self, user, system, unit):
        static_system = SystemDAO(name=system.name)
        #1 update system structure
        if self.db.existsSystem(static_system):
            static_system = self.db.getSystem(static_system)

            unitDAO = UnitDAO.toDAO(unit, static_system.id,
                                    UnitTypeDAO.toDAO(unit.type))

            if self.db.existsUnit(unitDAO, static_system):
                lock = threading.Lock()
                lock.acquire()
                try:
                    #removing all execution history when unit dissapears to ensure we get fresh events
                    self.db.deleteAllTestExecutionsForUnit(
                        static_system, unitDAO)
                    self.db.deleteLastTestExecutionsForUnit(
                        static_system, unitDAO)
                    self.db.removeUnit(unitDAO, static_system)
                finally:
                    lock.release()

                self.queue.removeQueue(self.queueIP,
                                       system.name,
                                       username=user.username,
                                       password=user.password,
                                       queueName=unit.uuid + "-Tests")
                self.queue.removeQueue(self.queueIP,
                                       system.name,
                                       username=user.username,
                                       password=user.password,
                                       queueName=unit.uuid + "-Results")

            else:
                logging.warn("Unit with ID " + unitDAO.name + " and UUID " +
                             unitDAO.uuid + " does not exist")
        else:
            logging.warn("System with ID " + system.name + " and UUID " +
                         system.uuid + " does not exist")
Beispiel #20
0
def getTestDescription(system_name, test_name):
    user = authenticate_user()
    message = controller.getTestDescription(
        user, controller.db.getSystem(SystemDAO(name=system_name)),
        controller.db.getTest(TestDAO(name=test_name)))
    return Response(message, mimetype='text/json', status=200)