Beispiel #1
0
def main():
    config_filename = os.environ.get("LANDO_CONFIG")
    if not config_filename:
        config_filename = CONFIG_FILE_NAME
    config = ServerConfig(config_filename)
    logging.basicConfig(stream=sys.stdout, level=config.log_level)
    lando = Lando(config)
    lando.listen_for_messages()
Beispiel #2
0
    def test_store_job_output_error(self, mock_requests, MockLandoWorkerClient,
                                    MockJobSettings):
        job_id = 4
        mock_settings, report = make_mock_settings_and_report(job_id)
        MockJobSettings.return_value = mock_settings
        lando = Lando(MagicMock())
        lando.store_job_output_error(
            MagicMock(job_id=1, vm_instance_name='worker_5', message='Oops3'))
        expected_report = """
Set job state to E.
Send progress notification. Job:1 State:E Step:EMPTY
        """
        self.assertMultiLineEqual(expected_report.strip(), report.text.strip())
Beispiel #3
0
    def test_stage_job_complete(self, mock_requests, MockLandoWorkerClient,
                                MockJobSettings):
        job_id = 3
        mock_settings, report = make_mock_settings_and_report(job_id)
        MockJobSettings.return_value = mock_settings
        lando = Lando(MagicMock())
        lando.stage_job_complete(
            MagicMock(job_id=1, vm_instance_name='worker_x'))
        expected_report = """
Set job step to R.
Send progress notification. Job:1 State:N Step:R
Put run_job message in queue for worker_x.
        """
        self.assertMultiLineEqual(expected_report.strip(), report.text.strip())
Beispiel #4
0
    def test_restart_record_output_project(self, mock_requests,
                                           MockJobSettings):
        job_id = 1
        mock_settings, report = make_mock_settings_and_report(job_id)
        MockJobSettings.return_value = mock_settings
        report.vm_instance_name = 'some_vm'
        report.vm_volume_name = 'volume_x'
        report.job_state = JobStates.ERRORED
        report.job_step = JobSteps.RECORD_OUTPUT_PROJECT
        lando = Lando(MagicMock())
        lando.restart_job(RestartJobPayload(job_id=1))
        expected_report = """
Set job state to E.
Send progress notification. Job:1 State:E Step:P
        """
        self.assertMultiLineEqual(expected_report.strip(), report.text.strip())
Beispiel #5
0
    def test_cancel_job(self, mock_requests, MockLandoWorkerClient,
                        MockJobSettings):
        job_id = 2
        mock_settings, report = make_mock_settings_and_report(job_id)
        MockJobSettings.return_value = mock_settings
        lando = Lando(MagicMock())
        lando.cancel_job(MagicMock(job_id=job_id))
        expected_report = """
Set job step to EMPTY.
Set job state to C.
Send progress notification. Job:1 State:C Step:EMPTY
Terminated vm worker_x.
Deleted volume volume_x.
Delete my worker's queue.
        """
        self.assertMultiLineEqual(expected_report.strip(), report.text.strip())
Beispiel #6
0
    def test_worker_started(self, mock_requests, MockLandoWorkerClient,
                            MockJobSettings, MockJobApi):
        MockJobApi.get_jobs_for_vm_instance_name.return_value = [
            MagicMock(state="R", step="V")
        ]
        job_id = 1
        mock_settings, report = make_mock_settings_and_report(job_id)
        MockJobSettings.return_value = mock_settings
        lando = Lando(MagicMock())
        lando.worker_started(MagicMock(worker_queue_name='stuff'))
        expected_report = """
Set job step to S.
Send progress notification. Job:1 State:N Step:S
Put stage message in queue for stuff.
        """
        self.assertMultiLineEqual(expected_report.strip(), report.text.strip())
Beispiel #7
0
    def test_restart_store_output_job(self, mock_requests,
                                      MockLandoWorkerClient, MockJobSettings):
        job_id = 1
        mock_settings, report = make_mock_settings_and_report(job_id)
        MockJobSettings.return_value = mock_settings
        report.vm_instance_name = 'some_vm'
        report.job_state = JobStates.ERRORED
        report.job_step = JobSteps.STORING_JOB_OUTPUT
        lando = Lando(MagicMock())
        lando.restart_job(RestartJobPayload(job_id=1))
        expected_report = """
Set job state to R.
Send progress notification. Job:1 State:R Step:O
Set job step to o.
Send progress notification. Job:1 State:R Step:o
"""
        self.assertMultiLineEqual(expected_report.strip(), report.text.strip())
Beispiel #8
0
    def test_restart_workflow_running_job(self, mock_requests,
                                          MockLandoWorkerClient,
                                          MockJobSettings):
        job_id = 1
        mock_settings, report = make_mock_settings_and_report(job_id)
        MockJobSettings.return_value = mock_settings
        report.vm_instance_name = 'some_vm'
        report.job_state = JobStates.ERRORED
        report.job_step = JobSteps.RUNNING
        lando = Lando(MagicMock())
        lando.restart_job(RestartJobPayload(job_id=1))
        expected_report = """
Set job state to R.
Send progress notification. Job:1 State:R Step:R
Set job step to R.
Send progress notification. Job:1 State:R Step:R
Put run_job message in queue for some_vm.
        """
        self.assertMultiLineEqual(expected_report.strip(), report.text.strip())
Beispiel #9
0
    def test_start_job(self, mock_requests, MockLandoWorkerClient,
                       MockJobSettings):
        job_id = 1
        mock_settings, report = make_mock_settings_and_report(job_id)
        MockJobSettings.return_value = mock_settings
        lando = Lando(MagicMock())
        lando.start_job(MagicMock(job_id=job_id))
        expected_report = """
Set job state to R.
Send progress notification. Job:1 State:R Step:EMPTY
Created vm name for job 1.
Created volume name for job 1.
Set job step to V.
Send progress notification. Job:1 State:R Step:V
Created volume volume_x.
Launched vm worker_x.
Set vm instance name to worker_x.
        """
        self.assertMultiLineEqual(expected_report.strip(), report.text.strip())
Beispiel #10
0
    def test_create_failing_volume(self, mock_requests, MockLandoWorkerClient,
                                   MockJobSettings):
        job_id = 1
        mock_settings, report = make_mock_settings_and_report(job_id)
        report.create_volume_error = OpenStackCloudException(
            'unable to create volume')
        MockJobSettings.return_value = mock_settings
        lando = Lando(MagicMock())
        lando.start_job(MagicMock(job_id=job_id))
        expected_report = """
Set job state to R.
Send progress notification. Job:1 State:R Step:EMPTY
Created vm name for job 1.
Created volume name for job 1.
Set job step to V.
Send progress notification. Job:1 State:R Step:V
Set job state to E.
Send progress notification. Job:1 State:E Step:V
"""
        self.assertMultiLineEqual(expected_report.strip(), report.text.strip())
Beispiel #11
0
    def test_cancel_job_with_no_vm_name(self, mock_requests,
                                        MockLandoWorkerClient,
                                        MockJobSettings):
        """
        When canceling a job that doesn't have a VM yet just set the state to canceled.
        There is no need to try to delete a VM or queue that doesn't exist.
        """
        job_id = 2
        mock_settings, report = make_mock_settings_and_report(job_id)
        report.vm_instance_name = ''
        MockJobSettings.return_value = mock_settings
        lando = Lando(MagicMock())
        lando.cancel_job(MagicMock(job_id=job_id))
        expected_report = """
Set job step to EMPTY.
Set job state to C.
Send progress notification. Job:1 State:C Step:EMPTY

        """
        self.assertMultiLineEqual(expected_report.strip(), report.text.strip())
Beispiel #12
0
 def test_error_sending_error(self, mock_traceback, mock_logging,
                              mock_requests, MockLandoWorkerClient,
                              MockJobSettings):
     job_id = 1
     mock_settings, report = make_mock_settings_and_report(job_id)
     mock_traceback.format_exc.side_effect = ['StackTrace1', 'StackTrace2']
     failing_job_api = MagicMock()
     failing_job_api.get_job.side_effect = [
         ValueError("Error1"), ValueError("Error2")
     ]
     mock_settings.get_job_api.return_value = failing_job_api
     MockJobSettings.return_value = mock_settings
     lando = Lando(MagicMock())
     lando.start_job(MagicMock(job_id=job_id))
     mock_logging.error.assert_has_calls([
         call('Handling error that occurred during start_job for job 1.'),
         call('Error contents: StackTrace1'),
         call(
             'Additional error occurred while handling an error: StackTrace2'
         )
     ])
Beispiel #13
0
    def test_restart_terminate_vm_job(self, mock_requests,
                                      MockLandoWorkerClient, MockJobSettings):
        job_id = 1
        mock_settings, report = make_mock_settings_and_report(job_id)
        MockJobSettings.return_value = mock_settings
        report.vm_instance_name = 'some_vm'
        report.vm_volume_name = 'volume_x'
        report.job_state = JobStates.ERRORED
        report.job_step = JobSteps.TERMINATE_VM
        lando = Lando(MagicMock())
        lando.restart_job(RestartJobPayload(job_id=1))
        expected_report = """
Set job state to R.
Send progress notification. Job:1 State:R Step:T
Set job step to T.
Send progress notification. Job:1 State:R Step:T
Terminated vm some_vm.
Deleted volume volume_x.
Delete my worker's queue.
Set job step to EMPTY.
Set job state to F.
Send progress notification. Job:1 State:F Step:EMPTY"""
        self.assertMultiLineEqual(expected_report.strip(), report.text.strip())