コード例 #1
0
def run(config, status):
    manager = RemoteJobManager("localhost", 5000)
    pip_cmd = config.get(KEYS.PIP_CMD, None) if config.get(KEYS.PIP_CMD, None) is not None else config.get(KEYS.LOCAL_PATH, None)

    if pip_cmd is None:
        status.update(
            {"succeeded": False, "errors": ["No local path specified"]})
        return
    ret, stdout = install_package_with_pip(pip_cmd)
    if ret:
        status.update(
            {"succeeded": False, "stdout": stdout, "errors": ["Pip returned a non-zero error code"]})
        return
    manager.reload_site_packages()
    status.update({"succeeded": True, "stdout": stdout})
コード例 #2
0
class TestRemoteDaemonManager(unittest2.TestCase):
    def setUp(self):
        self.proc = start_hoplite_server(5001)
        self.manager = RemoteJobManager("localhost", 5001)

    def tearDown(self):
        tear_down_hoplite(self.proc)

    def test_create_job(self):
        job = None
        job = self.manager.create_job(DOWNLOAD_NETWORK_FOLDER_JOB_NAME, {})
        self.assertIsNotNone(job)
        self.assertEquals(job.name, DOWNLOAD_NETWORK_FOLDER_JOB_NAME)
        self.assertEquals(job.running(), False)

    def test_get_job(self):
        job = self.manager.create_job(DOWNLOAD_NETWORK_FOLDER_JOB_NAME, {})
        r_job = self.manager.get_job(job.uuid)
        self.assertEquals(r_job.uuid, job.uuid)
        self.assertEquals(r_job.name, job.name)

    def test_get_job_raises(self):
        self.assertRaises(JobDoesNotExistError, self.manager.get_job, 393939)

    def test_get_job_plugins(self):
        job_plugins = self.manager.get_job_plugins()
        self.assertEquals(len(job_plugins), 7)
        actual = job_plugins
        self.assertIn(DOWNLOAD_FOLDER_FROM_FTP_JOB_NAME, actual)
        self.assertIn(DOWNLOAD_NETWORK_FOLDER_JOB_NAME, actual)

    def test_get_job_plugins_raises(self):
        with HTTMock(response_500):
            self.assertRaises(InternalServerError,
                              self.manager.get_job_plugins)

    def test_get_running_jobs(self):
        jobs = self.manager.get_running_jobs()
        self.assertEqual(len(jobs), 0)
        with HTTMock(get_running_jobs):
            jobs = self.manager.get_running_jobs()
            self.assertEqual(len(jobs), 1)

    def test_reload_site_packages(self):
        done = self.manager.reload_site_packages()
        self.assertTrue(done)

    def test_is_manager_available(self):
        time.sleep(1)  # Give some time for job manager to connect to start
        self.assertTrue(self.manager.is_available())
        invalid_manager = RemoteJobManager("localhost", 48423)
        self.assertFalse(invalid_manager.is_available())
コード例 #3
0
ファイル: test_remote_job_manager.py プロジェクト: ni/hoplite
class TestRemoteDaemonManager(unittest2.TestCase):
    def setUp(self):
        self.proc = start_hoplite_server(5001)
        self.manager = RemoteJobManager("localhost", 5001)

    def tearDown(self):
        tear_down_hoplite(self.proc)

    def test_create_job(self):
        job = None
        job = self.manager.create_job(DOWNLOAD_NETWORK_FOLDER_JOB_NAME, {})
        self.assertIsNotNone(job)
        self.assertEquals(job.name, DOWNLOAD_NETWORK_FOLDER_JOB_NAME)
        self.assertEquals(job.running(), False)

    def test_get_job(self):
        job = self.manager.create_job(DOWNLOAD_NETWORK_FOLDER_JOB_NAME, {})
        r_job = self.manager.get_job(job.uuid)
        self.assertEquals(r_job.uuid, job.uuid)
        self.assertEquals(r_job.name, job.name)

    def test_get_job_raises(self):
        self.assertRaises(JobDoesNotExistError, self.manager.get_job, 393939)

    def test_get_job_plugins(self):
        job_plugins = self.manager.get_job_plugins()
        self.assertEquals(len(job_plugins), 7)
        actual = job_plugins
        self.assertIn(DOWNLOAD_FOLDER_FROM_FTP_JOB_NAME, actual)
        self.assertIn(DOWNLOAD_NETWORK_FOLDER_JOB_NAME, actual)

    def test_get_job_plugins_raises(self):
        with HTTMock(response_500):
            self.assertRaises(InternalServerError, self.manager.get_job_plugins)

    def test_get_running_jobs(self):
        jobs = self.manager.get_running_jobs()
        self.assertEqual(len(jobs), 0)
        with HTTMock(get_running_jobs):
            jobs = self.manager.get_running_jobs()
            self.assertEqual(len(jobs), 1)

    def test_reload_site_packages(self):
        done = self.manager.reload_site_packages()
        self.assertTrue(done)

    def test_is_manager_available(self):
        time.sleep(1)  # Give some time for job manager to connect to start
        self.assertTrue(self.manager.is_available())
        invalid_manager = RemoteJobManager("localhost", 48423)
        self.assertFalse(invalid_manager.is_available())