Esempio n. 1
0
    def get_job(self, uuid):
        """
        Get the job identified by the uuid

        :param str uuid: UUID of the job to get
        :return: the job that matches the uuid
        :rtype: :py:class:`hoplite.client.RemoteJob`
        """
        return RemoteJob(self.address, self.port, uuid=uuid)
Esempio n. 2
0
    def create_job(self, plugin_name, config):
        """
        Create a job

        :param str plugin_name: name of the plugin you want to run in the job
        :param dict config: the configuration dictionary for the job
        :return: a RemoteJob to access the created job with
        :rtype: :py:class:`hoplite.client.RemoteJob`
        """
        return RemoteJob(
            self.address, self.port, name=plugin_name, config=config)
Esempio n. 3
0
 def test_init_job_no_uuid_given_creates_job(self):
     with HTTMock(post_jobs, get_specific_job_named_something):
         self.job = RemoteJob("localhost", 5001, "something")
     self.assertEquals(self.job.uuid, "correctuuid")
     self.assertEquals(self.job.name, "something")
Esempio n. 4
0
 def setUp(self):
     with HTTMock(get_specific_job):
         self.job = RemoteJob("localhost", 5001,
                              "test_plugins.wait_10_seconds", "correctuuid",
                              "api_key")
Esempio n. 5
0
class TestRemoteJob(unittest2.TestCase):
    def setUp(self):
        with HTTMock(get_specific_job):
            self.job = RemoteJob("localhost", 5001,
                                 "test_plugins.wait_10_seconds", "correctuuid",
                                 "api_key")

    def test_init_addr_name_uuid_apikey(self):
        #TODO There is a testing hole here...Where's config?! Input and Return
        self.assertEquals(self.job.address, "localhost")
        self.assertEquals(self.job.name, "test_plugins.wait_10_seconds")
        self.assertEquals(self.job.uuid, "correctuuid")
        self.assertEquals(self.job._api_key, "api_key")

    def test_init_addr_does_not_exist_raises(self):
        self.assertRaises(ConnectionError, RemoteJob,
                          "localhost.not.the.right.url", 5001,
                          "test_plugins.wait_10_seconds", "uuid", "api_key")

    def test_init_job_name_does_not_exist_no_uuid_given_raises(self):
        with HTTMock(post_jobs_400):
            self.assertRaises(JobDoesNotExistError, RemoteJob, "localhost",
                              5001, "test_plugins.wait")

    def test_init_job_no_uuid_given_creates_job(self):
        with HTTMock(post_jobs, get_specific_job_named_something):
            self.job = RemoteJob("localhost", 5001, "something")
        self.assertEquals(self.job.uuid, "correctuuid")
        self.assertEquals(self.job.name, "something")

    def test_config(self):
        with HTTMock(get_specific_job):
            self.assertEquals(self.job.config(), job_dict['config'])

    def test_status(self):
        with HTTMock(get_specific_job):
            self.assertEquals(self.job.status(), job_dict['status'])

    def test_start(self):
        with HTTMock(get_specific_job, start_job):
            self.assertTrue(self.job.start())

    def test_kill(self):
        with HTTMock(get_specific_job, kill_job):
            self.assertTrue(self.job.kill())

    def test_running(self):
        with HTTMock(get_specific_job):
            self.assertTrue(self.job.running())
        with HTTMock(get_specific_job_running_false_finished_true):
            self.assertFalse(self.job.running(force=True))

    def test_finished(self):
        with HTTMock(get_specific_job):
            self.assertFalse(self.job.finished())
        with HTTMock(get_specific_job_running_false_finished_true):
            self.assertTrue(self.job.finished(force=True))

    def test_join(self):
        with HTTMock(get_specific_job_running_false_finished_true):
            self.assertTrue(self.job.join())

    def test_join_raises_timeouteror(self):
        with HTTMock(get_specific_job_named_something):
            self.assertRaises(TimeoutError, self.job.join, 0)

    def test_rate_limit(self):
        with HTTMock(get_specific_job):
            self.assertTrue(self.job.running())
        with HTTMock(get_specific_job_running_false_finished_true):
            self.assertTrue(self.job.running())

    def test_exception_thrown_from_status(self):
        with HTTMock(get_with_exception):
            self.assertRaises(JobFailedError, self.job.status, True)

    def test_exception_thrown_from_join(self):
        with HTTMock(get_with_exception):
            self.assertRaises(JobFailedError, self.job.join)

    def test_exception_thrown_from_status(self):
        with HTTMock(get_with_bubbled_up_exception):
            try:
                self.job.status()
            except JobFailedError as e:
                exception_info = exception_bubble_up_job["status"]["exception"]
                self.assertEqual(e.addr, exception_info["address"])
                self.assertEqual(e.uuid, exception_info["uuid"])
                self.assertEqual(e.type_string, exception_info["type"])
                self.assertEqual(e.msg, exception_info["message"])
Esempio n. 6
0
 def test_init_job_no_uuid_given_creates_job(self):
     with HTTMock(post_jobs, get_specific_job_named_something):
         self.job = RemoteJob("localhost", 5001, "something")
     self.assertEquals(self.job.uuid, "correctuuid")
     self.assertEquals(self.job.name, "something")
Esempio n. 7
0
 def setUp(self):
     with HTTMock(get_specific_job):
         self.job = RemoteJob("localhost", 5001, "test_plugins.wait_10_seconds", "correctuuid", "api_key")
Esempio n. 8
0
class TestRemoteJob(unittest2.TestCase):
    def setUp(self):
        with HTTMock(get_specific_job):
            self.job = RemoteJob("localhost", 5001, "test_plugins.wait_10_seconds", "correctuuid", "api_key")

    def test_init_addr_name_uuid_apikey(self):
        #TODO There is a testing hole here...Where's config?! Input and Return
        self.assertEquals(self.job.address, "localhost")
        self.assertEquals(self.job.name, "test_plugins.wait_10_seconds")
        self.assertEquals(self.job.uuid, "correctuuid")
        self.assertEquals(self.job._api_key, "api_key")

    def test_init_addr_does_not_exist_raises(self):
        self.assertRaises(
            ConnectionError,
            RemoteJob,
            "localhost.not.the.right.url",
            5001,
            "test_plugins.wait_10_seconds",
            "uuid",
            "api_key"
        )

    def test_init_job_name_does_not_exist_no_uuid_given_raises(self):
        with HTTMock(post_jobs_400):
            self.assertRaises(JobDoesNotExistError, RemoteJob, "localhost", 5001, "test_plugins.wait")

    def test_init_job_no_uuid_given_creates_job(self):
        with HTTMock(post_jobs, get_specific_job_named_something):
            self.job = RemoteJob("localhost", 5001, "something")
        self.assertEquals(self.job.uuid, "correctuuid")
        self.assertEquals(self.job.name, "something")

    def test_config(self):
        with HTTMock(get_specific_job):
            self.assertEquals(self.job.config(), job_dict['config'])

    def test_status(self):
        with HTTMock(get_specific_job):
            self.assertEquals(self.job.status(), job_dict['status'])

    def test_start(self):
        with HTTMock(get_specific_job, start_job):
            self.assertTrue(self.job.start())

    def test_kill(self):
        with HTTMock(get_specific_job, kill_job):
            self.assertTrue(self.job.kill())

    def test_running(self):
        with HTTMock(get_specific_job):
            self.assertTrue(self.job.running())
        with HTTMock(get_specific_job_running_false_finished_true):
            self.assertFalse(self.job.running(force=True))

    def test_finished(self):
        with HTTMock(get_specific_job):
            self.assertFalse(self.job.finished())
        with HTTMock(get_specific_job_running_false_finished_true):
            self.assertTrue(self.job.finished(force=True))

    def test_join(self):
        with HTTMock(get_specific_job_running_false_finished_true):
            self.assertTrue(self.job.join())

    def test_join_raises_timeouteror(self):
        with HTTMock(get_specific_job_named_something):
            self.assertRaises(TimeoutError, self.job.join, 0)

    def test_rate_limit(self):
        with HTTMock(get_specific_job):
            self.assertTrue(self.job.running())
        with HTTMock(get_specific_job_running_false_finished_true):
            self.assertTrue(self.job.running())

    def test_exception_thrown_from_status(self):
        with HTTMock(get_with_exception):
            self.assertRaises(JobFailedError, self.job.status, True)

    def test_exception_thrown_from_join(self):
        with HTTMock(get_with_exception):
            self.assertRaises(JobFailedError, self.job.join)

    def test_exception_thrown_from_status(self):
        with HTTMock(get_with_bubbled_up_exception):
            try:
                self.job.status()
            except JobFailedError as e:
                exception_info = exception_bubble_up_job["status"]["exception"]
                self.assertEqual(e.addr, exception_info["address"])
                self.assertEqual(e.uuid, exception_info["uuid"])
                self.assertEqual(e.type_string, exception_info["type"])
                self.assertEqual(e.msg, exception_info["message"])