Ejemplo n.º 1
0
    def compare_job_attributes(self):
        Cargs.username = os.environ.get("OLWEB_USERNAME")
        Cargs.password = os.environ.get("OLWEB_PASSWORD")
        Cargs.url = os.environ.get("OLWEB_URL")
        # noinspection PyTypeChecker
        connection = OpenLavaConnection(Cargs)

        for local_job in Job.get_job_list():
            remote_ob = OLJob(connection, job_id=local_job.job_id, array_index=local_job.array_index)
            local_ob = Job(job_id=local_job.job_id, array_index=local_job.array_index)
            for attr in local_ob.json_attributes():

                local_attr_val = getattr(local_ob, attr)
                remote_attr_val = getattr(remote_ob, attr)

                if isinstance(local_attr_val, list):
                    self.assertEqual(len(local_attr_val), len(remote_attr_val))
                elif isinstance(local_attr_val, dict):
                    keys = local_attr_val.keys()
                    rkeys = getattr(remote_ob, attr).keys()
                    for key in keys:
                        self.assertIn(key, rkeys)
                    for key in rkeys:
                        self.assertIn(key, keys)
                else:
                    self.assertEqual(str(local_attr_val), str(remote_attr_val))
Ejemplo n.º 2
0
 def test_job_suspend(self):
     jobs = Job.submit(requested_slots=1, command="sleep 1000")
     job = jobs.pop()
     job.suspend()
     time.sleep(15)
     job = Job(job_id=job.job_id, array_index=job.array_index)
     self.assertTrue(job.is_suspended)
     job.kill()
Ejemplo n.º 3
0
    def test_job_kill(self):
        jobs = Job.submit(requested_slots=1, command="sleep 1000")
        job = jobs.pop()
        # kill the job
        job.kill()

        # Wait for the job to actually die
        time.sleep(15)

        job = Job(job_id=job.job_id, array_index=job.array_index)
        self.assertTrue(job.is_completed or job.is_failed or job.was_killed)
Ejemplo n.º 4
0
    def compare_job_attributes(self):
        Cargs.username = os.environ.get("OLWEB_USERNAME")
        Cargs.password = os.environ.get("OLWEB_PASSWORD")
        Cargs.url = os.environ.get("OLWEB_URL")
        # noinspection PyTypeChecker
        connection = OpenLavaConnection(Cargs)

        for local_job in Job.get_job_list():
            remote_job = OLJob(connection, job_id=local_job.job_id, array_index=local_job.array_index)
            local_job = Job(job_id=local_job.job_id, array_index=local_job.array_index)
            for attr in local_job.json_attributes():
                self.assertEqual(str(getattr(local_job, attr)), str(getattr(remote_job, attr)))
Ejemplo n.º 5
0
    def test_job_requeue_hold(self):
        jobs = Job.submit(requested_slots=1, command="sleep 1000")
        job = jobs.pop()
        while job.is_pending:
            time.sleep(1)
            job = Job(job_id=job.job_id, array_index=job.array_index)

        if not job.is_running:
            self.skipTest("Job no longer running")

        job.requeue(hold=True)
        time.sleep(45)  # Takes a while, first state is exit...
        job = Job(job_id=job.job_id, array_index=job.array_index)
        self.assertTrue(job.is_suspended)
        job.kill()
Ejemplo n.º 6
0
    def check_bjobs(self):
        jobs = Job.get_job_list()
        for mod in [[], ['-w']]:
            cmd = [
                os.path.join(os.environ.get("OLWCLIENT_PATH", None), 'bjobs.py'),
                '--username',
                os.environ.get("OLWEB_USERNAME", None),
                '--password',
                os.environ.get("OLWEB_PASSWORD", None),
            ]
            if mod:
                cmd.append(mod)

            cmd.append(
                os.environ.get("OLWEB_URL", None)
            )
            try:
                output = subprocess.check_output(cmd)
            except subprocess.CalledProcessError:
                    print " ".join(cmd)
                    raise

            if mod not in ['-l']:
                print " ".join(cmd)
                self.assertEqual(len(output.splitlines())-1, len(jobs))

            for job in jobs:
                job_str = str(job.job_id)
                if job.array_index > 0:
                    job_str += "[%s]" % job.array_index

                try:
                    output = subprocess.check_output(cmd + [job_str])
                except subprocess.CalledProcessError:
                    print " ".join(cmd + [job_str])
                    raise

                self.assertGreater(len(output), 0)
                if mod not in ['-l']:
                    self.assertEqual(len(output.splitlines()), 2)
                    if job.array_index == 0:
                        self.assertEqual(str(job.job_id), output.splitlines()[1].split()[0])
Ejemplo n.º 7
0
    def test_job_urls(self):
        base_url = os.environ.get("OLWEB_URL", None)
        if not base_url:
            return
        base_url.rstrip("/")

        response = urllib.urlopen("%s/jobs/" % base_url)
        self.assertTrue(self.check_content_type(response, "text/html"))
        response = urllib.urlopen("%s/jobs/?json=1" % base_url)
        self.assertTrue(self.check_content_type(response, "application/json"))

        for job in Job.get_job_list():
            response = urllib.urlopen("%s/jobs/%d/" % (base_url, job.job_id))
            self.assertTrue(self.check_content_type(response, "text/html"))
            response = urllib.urlopen("%s/jobs/%d/?json=1" % (base_url, job.job_id))
            self.assertTrue(self.check_content_type(response, "application/json"))
            response = urllib.urlopen("%s/job/%d/%d" % (base_url, job.job_id, job.array_index))
            self.assertTrue(self.check_content_type(response, "text/html"))
            response = urllib.urlopen("%s/job/%d/%d?json=1" % (base_url, job.job_id, job.array_index))
            self.assertTrue(self.check_content_type(response, "application/json"))
Ejemplo n.º 8
0
    def compare_job_list(self):
        Cargs.username = os.environ.get("OLWEB_USERNAME")
        Cargs.password = os.environ.get("OLWEB_PASSWORD")
        Cargs.url = os.environ.get("OLWEB_URL")
        # noinspection PyTypeChecker
        connection = OpenLavaConnection(Cargs)

        remote_job_list = OLJob.get_job_list(connection)
        local_job_list = Job.get_job_list()
        local_jobs = set()
        remote_jobs = set()
        for job in local_job_list:
            local_jobs.add(str(job))

        for job in remote_job_list:
            remote_jobs.add(str(job))

        for job in local_jobs:
            self.assertIn(job, remote_jobs)

        for job in remote_jobs:
            self.assertIn(job, local_jobs)
Ejemplo n.º 9
0
    def test_job_requeue(self):
        jobs = Job.submit(requested_slots=1, command="sleep 1000")
        job = jobs.pop()
        while job.is_pending:
            time.sleep(1)
            job = Job(job_id=job.job_id, array_index=job.array_index)

        if not job.is_running:
            self.skipTest("Job no longer running")

        start_time = job.start_time
        job.requeue(hold=False)
        time.sleep(45)
        job = Job(job_id=job.job_id, array_index=job.array_index)
        if job.is_pending:
            # Passed
            job.kill()
            return None

        self.assertNotEqual(job.start_time, start_time)
        job.kill()
Ejemplo n.º 10
0
 def test_job_submit_array(self):
     jobs = Job.submit(job_name="JobTestSubmitArray[1-100]", requested_slots=1, command="hostname")
     self.assertIs(len(jobs), 100, msg="Submitting one job returns 1 item")
     for job in jobs[:5]:
         self.job_state_test(job)
Ejemplo n.º 11
0
 def test_job_submit(self):
     jobs = Job.submit(requested_slots=1, command="hostname")
     self.assertIs(len(jobs), 1, msg="Submitting one job returns 1 item")
     self.job_state_test(jobs[0])
Ejemplo n.º 12
0
 def test_job_list(self):
     job_list = Job.get_job_list()
     for job in job_list:
         self.assertIsInstance(job, Job)