Beispiel #1
0
    def test_scale_post_steps_successful(self, mock_env_vars,
                                         mock_job_exe_manager):
        """Tests successfully executing scale_post_steps."""

        # Set up mocks
        def get_env_vars(name, *args, **kwargs):
            return str(self.job.id) if name == 'SCALE_JOB_ID' else str(
                self.job_exe.exe_num)

        mock_env_vars.side_effect = get_env_vars
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.job_type.get_job_interface.return_value.perform_post_steps.return_value = RESULTS
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.id = self.job_exe.id
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.job_id = self.job_exe.job_id
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.job_type_id = self.job_exe.job_type_id
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.exe_num = self.job_exe.exe_num

        # Call method to test
        cmd = PostCommand()
        cmd.run_from_argv(['manage.py', 'scale_post_steps'])

        # Check results
        job_exe_output = JobExecutionOutput.objects.get(
            job_exe_id=self.job_exe.id)
        self.assertDictEqual(job_exe_output.get_output().get_dict(),
                             JOB_RESULTS.get_dict())
Beispiel #2
0
    def test_scale_post_steps_io_error(self, mock_job_exe_manager, mock_sys_exit, mock_call):
        '''Tests executing scale_post_steps when an IO error occurs.'''

        # Set up mocks
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.get_job_interface.return_value.perform_post_steps.side_effect = IOError()

        # Call method to test
        cmd = PostCommand()
        cmd.run_from_argv(['manage.py', 'scale_post_steps', '-i', str(self.job_exe.id)])

        # Check results
        mock_sys_exit.assert_called_with(POST_IO_EXIT_CODE)
    def test_scale_post_steps_missing_manifest_output_error(self, mock_job_exe_manager, mock_sys_exit):
        """Tests executing scale_post_steps when a missing output manifest occurs."""

        # Set up mocks
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.get_job_interface.return_value.perform_post_steps.side_effect = MissingRequiredOutput()

        # Call method to test
        cmd = PostCommand()
        cmd.run_from_argv(['manage.py', 'scale_post_steps', '-i', str(self.job_exe.id)])

        # Check results
        mock_sys_exit.assert_called_with(POST_MI_OP_EXIT_CODE)
Beispiel #4
0
    def test_scale_post_steps_database_error(self, mock_db, mock_sys_exit, mock_call):
        '''Tests executing scale_post_steps when a database error occurs.'''

        # Set up mocks
        mock_db.side_effect = DatabaseError()

        # Call method to test
        cmd = PostCommand()
        cmd.run_from_argv(['manage.py', 'scale_post_steps', '-i', str(self.job_exe.id)])

        # Check results
        mock_sys_exit.assert_called_with(POST_DB_EXIT_CODE)
Beispiel #5
0
    def test_scale_post_steps_successful(self, mock_node_dir, mock_job_exe_manager, mock_cleanup, mock_call):
        '''Tests successfully executing scale_post_steps.'''

        # Set up mocks
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.get_job_interface.return_value.perform_post_steps.return_value = RESULTS

        # Call method to test
        cmd = PostCommand()
        cmd.run_from_argv(['manage.py', 'scale_post_steps', '-i', str(self.job_exe.id)])

        # Check results
        mock_job_exe_manager.post_steps_results.assert_called_with(self.job_exe.id, JOB_RESULTS, RESULTS_MANIFEST)
Beispiel #6
0
    def test_scale_post_steps_database_error(self, mock_db, mock_sys_exit):
        """Tests executing scale_post_steps when a database error occurs."""

        # Set up mocks
        mock_db.side_effect = DatabaseError()

        # Call method to test
        cmd = PostCommand()
        cmd.run_from_argv(
            ['manage.py', 'scale_post_steps', '-i',
             str(self.job_exe.id)])

        # Check results
        mock_sys_exit.assert_called_with(POST_DB_EXIT_CODE)
    def test_scale_post_steps_database_operation_error(self, mock_db,
                                                       mock_sys_exit):
        """Tests executing scale_post_steps when a database operation error occurs."""

        # Set up mocks
        mock_db.side_effect = OperationalError()

        # Call method to test
        cmd = PostCommand()
        cmd.run_from_argv(
            ['manage.py', 'scale_post_steps', '-i',
             str(self.job_exe.id)])

        # Check results
        mock_sys_exit.assert_called_with(ScaleOperationalError().exit_code)
    def test_scale_post_steps_no_stderr(self, mock_job_exe_manager, mock_cleanup):
        """Tests successfully executing scale_post_steps."""

        # Set up mocks
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.stdout = 'something'
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.stderr = None
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.get_job_interface.return_value.perform_post_steps.return_value = RESULTS
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.id = self.job_exe.id

        # Call method to test
        cmd = PostCommand()
        cmd.run_from_argv(['manage.py', 'scale_post_steps', '-i', str(self.job_exe.id)])

        # Check results
        mock_job_exe_manager.post_steps_results.assert_called_with(self.job_exe.id, JOB_RESULTS, RESULTS_MANIFEST)
Beispiel #9
0
    def test_scale_post_steps_io_error(self, mock_job_exe_manager,
                                       mock_sys_exit, mock_call):
        '''Tests executing scale_post_steps when an IO error occurs.'''

        # Set up mocks
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.get_job_interface.return_value.perform_post_steps.side_effect = IOError(
        )

        # Call method to test
        cmd = PostCommand()
        cmd.run_from_argv(
            ['manage.py', 'scale_post_steps', '-i',
             str(self.job_exe.id)])

        # Check results
        mock_sys_exit.assert_called_with(POST_IO_EXIT_CODE)
Beispiel #10
0
    def test_scale_post_steps_missing_manifest_output_error(
            self, mock_job_exe_manager, mock_sys_exit):
        """Tests executing scale_post_steps when a missing output manifest occurs."""

        # Set up mocks
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.get_job_interface.return_value.perform_post_steps.side_effect = MissingRequiredOutput(
        )

        # Call method to test
        cmd = PostCommand()
        cmd.run_from_argv(
            ['manage.py', 'scale_post_steps', '-i',
             str(self.job_exe.id)])

        # Check results
        mock_sys_exit.assert_called_with(POST_MI_OP_EXIT_CODE)
    def test_scale_post_steps_successful(self, mock_job_exe_manager):
        """Tests successfully executing scale_post_steps."""

        # Set up mocks
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.get_job_interface.return_value.perform_post_steps.return_value = RESULTS
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.id = self.job_exe.id

        # Call method to test
        cmd = PostCommand()
        cmd.run_from_argv(
            ['manage.py', 'scale_post_steps', '-i',
             str(self.job_exe.id)])

        # Check results
        mock_job_exe_manager.post_steps_results.assert_called_with(
            self.job_exe.id, JOB_RESULTS, RESULTS_MANIFEST)
    def test_scale_post_steps_invalid_manifest_error(self,
                                                     mock_job_exe_manager,
                                                     mock_sys_exit):
        """Tests executing scale_post_steps when an invalid manifest occurs."""

        # Set up mocks
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.get_job_interface.return_value.perform_post_steps.side_effect = InvalidResultsManifest(
            '')

        # Call method to test
        cmd = PostCommand()
        cmd.run_from_argv(
            ['manage.py', 'scale_post_steps', '-i',
             str(self.job_exe.id)])

        # Check results
        mock_sys_exit.assert_called_with(InvalidResultsManifest('').exit_code)
Beispiel #13
0
    def test_scale_post_steps_database_error(self, mock_env_vars, mock_db,
                                             mock_sys_exit):
        """Tests executing scale_post_steps when a database error occurs."""

        # Set up mocks
        def get_env_vars(name, *args, **kwargs):
            return str(self.job.id) if name == 'SCALE_JOB_ID' else str(
                self.job_exe.exe_num)

        mock_env_vars.side_effect = get_env_vars
        mock_db.side_effect = DatabaseError()

        # Call method to test
        cmd = PostCommand()
        cmd.run_from_argv(['manage.py', 'scale_post_steps'])

        # Check results
        mock_sys_exit.assert_called_with(ScaleDatabaseError().exit_code)
Beispiel #14
0
    def test_scale_post_steps_missing_manifest_output_error(
            self, mock_env_vars, mock_job_exe_manager, mock_sys_exit):
        """Tests executing scale_post_steps when a missing output manifest occurs."""

        # Set up mocks
        def get_env_vars(name, *args, **kwargs):
            return str(self.job.id) if name == 'SCALE_JOB_ID' else str(
                self.job_exe.exe_num)

        mock_env_vars.side_effect = get_env_vars
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.job_type.get_job_interface.return_value.perform_post_steps.side_effect = MissingRequiredOutput(
            '')

        # Call method to test
        cmd = PostCommand()
        cmd.run_from_argv(['manage.py', 'scale_post_steps'])

        # Check results
        mock_sys_exit.assert_called_with(MissingRequiredOutput('').exit_code)