示例#1
0
 def access_delete_stress(self):
     
     if not self.new_jobids or not self.old_jobids:
         self.create_lots_of_ids(how_many,self.new_jobids,"old")
         self.create_lots_of_ids(how_many,self.old_jobids,"new")
         self.enter_some_data(self.new_jobids)
     jobthing.purge_old_jobs()
     print "Old ids were removed succesfully "
示例#2
0
    def access_delete_stress(self):

        if not self.new_jobids or not self.old_jobids:
            self.create_lots_of_ids(how_many, self.new_jobids, "old")
            self.create_lots_of_ids(how_many, self.old_jobids, "new")
            self.enter_some_data(self.new_jobids)
        jobthing.purge_old_jobs()
        print "Old ids were removed succesfully "
示例#3
0
    def test_old_new_upgrade(self):
        #that will do some control if some users has old_ids and
        #upgrade to new ones so they shouldnt have some weird errors
        old_type_new = []
        old_type_old = []
        #create 5 old type job ids with current time
        for n in xrange(5):
            job_id = pprint.pformat(time.time())
            tmp_hash = {}
            tmp_hash[job_id] = (self.status_opt[randint(
                0,
                len(self.status_opt) - 1)], {
                    "some_old_type_new.com": self.test_result
                })
            old_type_new.append(tmp_hash)

        #create 5 old type job ids with older  time
        base_time = self.an_old_time
        for n in xrange(5):
            job_id = str(base_time)
            tmp_hash = {}
            tmp_hash[job_id] = (self.status_opt[randint(
                0,
                len(self.status_opt) - 1)], {
                    "some_old_type.com": self.test_result
                })
            old_type_old.append(tmp_hash)
            base_time = base_time + 10

        #print "The old type pack is : ",old_type_new
        #print "The old type pack is : ",old_type_old
        #enter also that ids into database
        self.enter_some_data(old_type_new)
        self.enter_some_data(old_type_old)
        #db_results = jobthing.get_open_ids()
        #print "The current db results are : ",db_results

        self.enter_some_data(self.new_jobids)
        self.enter_some_data(self.old_jobids)

        #db_results = jobthing.get_open_ids()
        #print "The current db results are : ",db_results

        #now check for errors or failures
        jobthing.purge_old_jobs()
        db_results = jobthing.get_open_ids()
        #print "The current db results are : ",db_results
        assert len(db_results.keys()) == len(self.new_jobids)
        for job in self.new_jobids:
            for job_id, job_pack in job.iteritems():
                assert db_results.has_key(job_id) == True
                assert db_results[job_id] == job_pack[0]
示例#4
0
    def test_purge_old_jobs(self):
        #purge_old_jobs()
        self.enter_some_data(self.new_jobids)
        self.enter_some_data(self.old_jobids)
        #delete the olders
        jobthing.purge_old_jobs()
        db_results = jobthing.get_open_ids()
        #print "The lenght of the db result is : ",len(db_results.keys())
        assert len(db_results.keys()) == len(self.new_jobids)

        for job in self.new_jobids:
            for job_id,job_pack in job.iteritems():
                assert db_results.has_key(job_id) == True
                assert db_results[job_id] == job_pack[0]
        self.enter_some_data(self.old_jobids)
        jobthing.purge_old_jobs()
        assert len(db_results.keys()) == len(self.new_jobids)
示例#5
0
    def test_purge_old_jobs(self):
        #purge_old_jobs()
        self.enter_some_data(self.new_jobids)
        self.enter_some_data(self.old_jobids)
        #delete the olders
        jobthing.purge_old_jobs()
        db_results = jobthing.get_open_ids()
        #print "The lenght of the db result is : ",len(db_results.keys())
        assert len(db_results.keys()) == len(self.new_jobids)

        for job in self.new_jobids:
            for job_id, job_pack in job.iteritems():
                assert db_results.has_key(job_id) == True
                assert db_results[job_id] == job_pack[0]
        self.enter_some_data(self.old_jobids)
        jobthing.purge_old_jobs()
        assert len(db_results.keys()) == len(self.new_jobids)
示例#6
0
    def test_old_new_upgrade(self):
        #that will do some control if some users has old_ids and
        #upgrade to new ones so they shouldnt have some weird errors
        old_type_new = []
        old_type_old = []
        #create 5 old type job ids with current time
        for n in xrange(5):
            job_id = pprint.pformat(time.time())
            tmp_hash = {}
            tmp_hash[job_id] = (self.status_opt[randint(0,len(self.status_opt)-1)],{"some_old_type_new.com":self.test_result})
            old_type_new.append(tmp_hash)
        
        #create 5 old type job ids with older  time
        base_time = self.an_old_time
        for n in xrange(5):
            job_id = str(base_time)
            tmp_hash = {}
            tmp_hash[job_id] = (self.status_opt[randint(0,len(self.status_opt)-1)],{"some_old_type.com":self.test_result})
            old_type_old.append(tmp_hash)
            base_time = base_time + 10
        
        #print "The old type pack is : ",old_type_new
        #print "The old type pack is : ",old_type_old
        #enter also that ids into database
        self.enter_some_data(old_type_new)
        self.enter_some_data(old_type_old)
        #db_results = jobthing.get_open_ids()
        #print "The current db results are : ",db_results

        self.enter_some_data(self.new_jobids)
        self.enter_some_data(self.old_jobids)
        
        #db_results = jobthing.get_open_ids()
        #print "The current db results are : ",db_results

        #now check for errors or failures
        jobthing.purge_old_jobs()
        db_results = jobthing.get_open_ids()
        #print "The current db results are : ",db_results
        assert len(db_results.keys()) == len(self.new_jobids)
        for job in self.new_jobids:
            for job_id,job_pack in job.iteritems():
                assert db_results.has_key(job_id) == True
                assert db_results[job_id] == job_pack[0]
示例#7
0
    def display_async_results(self):
        """
        Displaying the current db results that are in the memory
        """
        if not self.async_manager:
            # here should run the clean_old ids
            purge_old_jobs()
            self.async_manager = AsyncResultManager()
        else:
            # make a refresh of the memory copy
            self.async_manager.refresh_list()
        # get the actual db
        func_db = self.async_manager.current_db()

        for job_id, code_status_pack in func_db.iteritems():
            parsed_job_id = job_id.split("-")
            func_db[job_id].extend(parsed_job_id)

        # print func_db
        return dict(func_db=func_db)
示例#8
0
    def check_async(self, check_change=False):
        """
        That method is polled by js code to see if there is some
        interesting change in current db
        """
        changed = False

        if not check_change:
            msg = "Method invoked with False parameter which makes it useless"
            return dict(changed=False, changes=[], remote_error=msg)

        if not self.async_manager:
            # cleanup tha database firstly
            purge_old_jobs()
            self.async_manager = AsyncResultManager()
        changes = self.async_manager.check_for_changes()
        if changes:
            if not self.first_run:
                changed = True
            else:
                self.first_run = False

        return dict(changed=changed, changes=changes)
示例#9
0
    def post_form(self, **kw):
        """
        Data processing part for methods that accept some inputs.
        Method recieves the method arguments for minion method then
        orders them into their original order and sends the xmlrpc
        request to the minion !
        """
        if kw.has_key("minion") and kw.has_key("module") and kw.has_key("method"):
            # assign them because we need the rest so dont control everytime
            # and dont make lookup everytime ...
            # the del statements above are important dont remove them :)
            minion = kw["minion"]
            del kw["minion"]
            module = kw["module"]
            del kw["module"]
            method = kw["method"]
            del kw["method"]

            if self.func_cache["minion_name"] == minion:
                fc = self.func_cache["fc_object"]
            else:
                fc = Overlord(minion)
                self.func_cache["fc_object"] = fc
                self.func_cache["minion_name"] = minion
                # reset the children :)
                self.func_cache["module_name"] = module
                self.func_cache["modules"] = None
                self.func_cache["methods"] = None

            # get again the method args to get their order :
            arguments = getattr(fc, module).get_method_args()
            # so we know the order just allocate and put them there
            cmd_args = [""] * (len(kw.keys()))

            for arg in kw.keys():
                # wow what a lookup :)
                index_of_arg = arguments[minion][method]["args"][arg]["order"]
                cmd_args[index_of_arg] = kw[arg]

            # now execute the stuff
            # at the final execute it as a multiple if the glob suits for that
            # if not (actually there shouldnt be an option like that but who knows :))
            # it will run as a normal single command to clicked minion
            if self.func_cache["glob"]:
                fc_async = Overlord(self.func_cache["glob"], async=True)

            result_id = getattr(getattr(fc_async, module), method)(*cmd_args)
            result = "".join(
                [
                    "The id for current job is :",
                    str(result_id),
                    " You will be notified when there is some change about that command !",
                ]
            )

            # that part gives a chance for short methods to finish their jobs and display them
            # immediately so user will not wait for new notifications for that short thing
            import time

            time.sleep(4)
            tmp_as_res = fc_async.job_status(result_id)
            if tmp_as_res[0] == JOB_ID_FINISHED:
                result = tmp_as_res[1]

                if not self.async_manager:
                    # cleanup tha database firstly
                    purge_old_jobs()
                    self.async_manager = AsyncResultManager()
                self.async_manager.refresh_list()

            # TODO reformat that returning string to be more elegant to display :)
            return str(result)

        else:
            return "Missing arguments sorry can not proceess the form"