Пример #1
0
    def test_scale_pre_steps_nfs_error(self, mock_job_exe, mock_sys_exit):
        """Tests executing scale_pre_steps when an NFS error occurs."""

        # Set up mocks
        mock_job_exe.objects.get_job_exe_with_job_and_job_type.return_value.get_job_interface.return_value.perform_pre_steps.side_effect = NfsError()

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

        # Check results
        mock_sys_exit.assert_called_with(PRE_NFS_EXIT_CODE)
Пример #2
0
    def test_scale_pre_steps_database_operation_error(self, mock_db, mock_sys_exit):
        """Tests executing scale_pre_steps when a database operation error occurs."""

        # Set up mocks
        mock_db.side_effect = OperationalError()

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

        # Check results
        mock_sys_exit.assert_called_with(PRE_DB_OP_EXIT_CODE)
Пример #3
0
    def test_scale_pre_steps_database_error(self, mock_db, mock_sys_exit):
        """Tests executing scale_pre_steps when a database error occurs."""

        # Set up mocks
        mock_db.side_effect = DatabaseError()

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

        # Check results
        mock_sys_exit.assert_called_with(ScaleDatabaseError().exit_code)
Пример #4
0
    def test_scale_pre_steps_successful(self, mock_job_exe, mock_sysexit):
        """Tests successfully executing scale_pre_steps."""

        # Set up mocks
        mock_job_exe.objects.get_job_exe_with_job_and_job_type.return_value.get_job_interface.return_value.fully_populate_command_argument.return_value = FILLED_IN_CMD
        mock_job_exe.objects.get_job_exe_with_job_and_job_type.return_value.get_docker_image.return_value = None

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

        # Check results
        mock_job_exe.objects.pre_steps_command_arguments.assert_called_with(self.job_exe.id, FILLED_IN_CMD)
Пример #5
0
    def test_seed_pre_steps_no_workspace(self, mock_env_vars, mock_sysexit):

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

        mock_env_vars.side_effect = get_env_vars

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

        # Make sure we get an exit code of 1
        mock_sysexit.assert_called_with(1)
Пример #6
0
    def test_scale_pre_steps_successful(self, mock_env_vars, mock_sysexit):
        """Tests successfully executing scale_pre_steps."""

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

        mock_env_vars.side_effect = get_env_vars

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

        # Make sure sys.exit() was never called
        self.assertItemsEqual(mock_sysexit.call_args_list, [])
Пример #7
0
    def test_scale_pre_steps_database_operation_error(self, mock_env_vars,
                                                      mock_db, mock_sys_exit):
        """Tests executing scale_pre_steps when a database operation error occurs."""

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

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

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

        # Check results
        mock_sys_exit.assert_called_with(ScaleOperationalError().exit_code)
Пример #8
0
    def test_scale_pre_steps_io_error(self, mock_env_vars, mock_job_exe,
                                      mock_sys_exit, mock_JobData):
        """Tests executing scale_pre_steps when an IO error occurs."""

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

        mock_env_vars.side_effect = get_env_vars
        mock_job_exe.objects.get_job_exe_with_job_and_job_type.return_value.job_type.get_job_interface.return_value.perform_pre_steps.side_effect = IOError(
        )

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

        # Check results
        mock_sys_exit.assert_called_with(ScaleIOError().exit_code)
Пример #9
0
    def test_seed_pre_steps_no_workspace(self, mock_env_vars, mock_sysexit):

        seed_exe = job_utils.create_job_exe(job=self.seed_job,
                                            status='RUNNING',
                                            timeout=60,
                                            queued=now())

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

        mock_env_vars.side_effect = get_env_vars

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

        # Make sure we get an exit code of 1
        mock_sysexit.assert_called_with(1)
Пример #10
0
    def test_generate_input_metadata(self, mock_dump, mock_open, mock_mkdir):

        cmd = PreCommand()

        cmd._generate_input_metadata(self.seed_exe_meta)
        mock_dump.assert_called_once()
        args, kwargs = mock_dump.call_args
        metadata_dict = {'JOB': {}}
        metadata_dict['JOB']['input_1'] = 'my_val'
        metadata_dict['JOB']['input_2'] = [
            serialize(
                ScaleFile.objects.get_details(file_id=self.file_1.id)).data
        ]
        metadata_dict['JOB']['input_3'] = [
            serialize(
                ScaleFile.objects.get_details(file_id=self.file_2.id)).data,
            serialize(
                ScaleFile.objects.get_details(file_id=self.file_3.id)).data
        ]
        self.maxDiff = None
        self.assertDictEqual(args[0]['JOB']['input_2'][0],
                             metadata_dict['JOB']['input_2'][0])
        self.assertDictEqual(args[0], metadata_dict)