Ejemplo n.º 1
0
    def test_unrelated_job_not_updated(self):
        """Ensure that we only update platform for the specified job's mappings."""
        fuzzer_1_mapping = data_types.FuzzerJob()
        fuzzer_1_mapping.fuzzer = 'fuzzer_1'
        fuzzer_1_mapping.job = 'test_job'
        fuzzer_1_mapping.platform = 'wrong_platform'
        fuzzer_1_mapping.put()

        fuzzer_2_mapping = data_types.FuzzerJob()
        fuzzer_2_mapping.fuzzer = 'fuzzer_2'
        fuzzer_2_mapping.job = 'unrelated_job'
        fuzzer_2_mapping.platform = 'unrelated_platform'
        fuzzer_2_mapping.put()

        fuzzer_selection.update_platform_for_job('test_job', 'right_platform')

        query = data_types.FuzzerJob.query()
        query = query.filter(data_types.FuzzerJob.fuzzer == 'fuzzer_2')
        fuzzer_2_mapping = query.get()

        self.assertEqual(fuzzer_2_mapping.platform, 'unrelated_platform')
Ejemplo n.º 2
0
    def test_jobs_updated(self):
        """Ensure that we properly update multiple jobs."""
        fuzzer_1_mapping = data_types.FuzzerJob()
        fuzzer_1_mapping.fuzzer = 'fuzzer_1'
        fuzzer_1_mapping.job = 'test_job'
        fuzzer_1_mapping.platform = 'wrong_platform'
        fuzzer_1_mapping.put()

        fuzzer_2_mapping = data_types.FuzzerJob()
        fuzzer_2_mapping.fuzzer = 'fuzzer_2'
        fuzzer_2_mapping.job = 'test_job'
        fuzzer_2_mapping.platform = 'wrong_platform'
        fuzzer_2_mapping.put()

        fuzzer_selection.update_platform_for_job('test_job', 'right_platform')

        platforms = [
            job.platform
            for job in ndb_utils.get_all_from_model(data_types.FuzzerJob)
        ]
        self.assertListEqual(platforms, ['right_platform', 'right_platform'])
Ejemplo n.º 3
0
    def post(self):
        """Handle a post request."""
        name = self.request.get('name')
        if not name:
            raise helpers.EarlyExitException('Please give this job a name!',
                                             400)

        if not data_types.Job.VALID_NAME_REGEX.match(name):
            raise helpers.EarlyExitException(
                'Job name can only contain letters, numbers, dashes and underscores.',
                400)

        fuzzers = self.request.get('fuzzers', []).split(',')
        templates = self.request.get('templates', '').splitlines()
        for template in templates:
            if not data_types.JobTemplate.query(
                    data_types.JobTemplate.name == template).get():
                raise helpers.EarlyExitException(
                    'Invalid template name(s) specified.', 400)

        new_platform = self.request.get('platform')
        if not new_platform or new_platform == 'undefined':
            raise helpers.EarlyExitException('No platform provided for job.',
                                             400)

        description = self.request.get('description', '')
        environment_string = self.request.get('environment_string', '')
        previous_custom_binary_revision = 0

        job = data_types.Job.query(data_types.Job.name == name).get()
        recreate_fuzzer_mappings = False
        if not job:
            job = data_types.Job()
        else:
            previous_custom_binary_revision = job.custom_binary_revision
            if previous_custom_binary_revision is None:
                previous_custom_binary_revision = 0
            if new_platform != job.platform:
                # The rare case of modifying a job's platform causes many problems with
                # task selection. If a job is leased from the old queue, the task will
                # be recreated in the correct queue at lease time. Fuzzer mappings must
                # be purged and recreated, since they depend on the job's platform.
                recreate_fuzzer_mappings = True

        job.name = name
        job.platform = new_platform
        job.description = description
        job.environment_string = environment_string
        job.templates = templates

        blob_info = self.get_upload()
        if blob_info:
            job.custom_binary_key = str(blob_info.key())
            job.custom_binary_filename = blob_info.filename
            job.custom_binary_revision = previous_custom_binary_revision + 1

        if job.custom_binary_key and 'CUSTOM_BINARY' not in job.environment_string:
            job.environment_string += '\nCUSTOM_BINARY = True'

        job.put()

        fuzzer_selection.update_mappings_for_job(job, fuzzers)
        if recreate_fuzzer_mappings:
            fuzzer_selection.update_platform_for_job(name, new_platform)

        # pylint: disable=unexpected-keyword-arg
        _ = data_handler.get_all_job_type_names(__memoize_force__=True)

        helpers.log('Job created %s' % name, helpers.MODIFY_OPERATION)
        template_values = {
            'title':
            'Success',
            'message': ('Job %s is successfully updated. '
                        'Redirecting back to jobs page...') % name,
            'redirect_url':
            '/jobs',
        }
        self.render('message.html', template_values)