def view_save_benchmark_definition(request, benchmark_definition_id):
    """ Save benchmark definition properties """
    if request.method != 'POST':
        return res.get_only_post_allowed({})

    (json_valid_value, post_info) = val.validate_json_string(request.body)
    if not json_valid_value:
        return res.get_json_parser_failed({})

    (obj_validated, val_resp_obj) = val.validate_obj_schema(
        post_info, BenchmarkDefinitionSchemas.SAVE_BENCHMARK_DEFINITION)

    if not obj_validated:
        return res.get_schema_failed(val_resp_obj)

    bench_entry = BenchmarkDefinitionController.save_benchmark_definition(
        benchmark_definition_id=benchmark_definition_id,
        name=val_resp_obj['name'],
        layout_id=val_resp_obj['layout_id'],
        project_id=val_resp_obj['project_id'],
        priority=val_resp_obj['priority'],
        active=val_resp_obj['active'],
        command_list=val_resp_obj['command_list'],
        max_fluctuation_percent=val_resp_obj['max_fluctuation_percent'],
        overrides=val_resp_obj['overrides'],
        max_weeks_old_notify=val_resp_obj['max_weeks_old_notify'],
        work_passes=val_resp_obj['work_passes'],
    )

    if bench_entry is None:
        return res.get_response(404, 'Benchmark Defintion save error', {})

    return res.get_response(200, 'Benchmark Definition saved', {})
Beispiel #2
0
    def test_save_benchmark_definition_delete_benchmarks_executions_if_layout_or_project_different(
            self):
        user1 = User.objects.create_user('*****@*****.**', '*****@*****.**',
                                         'pass')
        user1.save()

        git_project1 = GitProjectEntry.objects.create(url='http://test/')

        git_user1 = GitUserEntry.objects.create(project=git_project1,
                                                name='user1',
                                                email='*****@*****.**')

        commit1 = GitCommitEntry.objects.create(
            project=git_project1,
            commit_hash='0000100001000010000100001000010000100001',
            author=git_user1,
            author_date=timezone.now(),
            committer=git_user1,
            committer_date=timezone.now())

        command_group = CommandGroupEntry.objects.create()
        command_set = CommandSetEntry.objects.create(group=command_group)

        bluesteel_layout1 = BluesteelLayoutEntry.objects.create(
            name='Layout', active=True, project_index_path=0)
        bluesteel_project1 = BluesteelProjectEntry.objects.create(
            name='Project',
            order=0,
            layout=bluesteel_layout1,
            command_group=command_group,
            git_project=git_project1)

        bluesteel_layout2 = BluesteelLayoutEntry.objects.create(
            name='Layout', active=True, project_index_path=0)
        bluesteel_project2 = BluesteelProjectEntry.objects.create(
            name='Project',
            order=0,
            layout=bluesteel_layout2,
            command_group=command_group,
            git_project=git_project1)

        benchmark_definition1 = BenchmarkDefinitionEntry.objects.create(
            name='BenchmarkDefinition1',
            layout=bluesteel_layout1,
            project=bluesteel_project1,
            command_set=command_set,
            revision=28)

        worker1 = WorkerEntry.objects.create(name='worker-name-1',
                                             uuid='uuid-worker-1',
                                             operative_system='osx',
                                             description='long-description-1',
                                             user=user1,
                                             git_feeder=False)
        report1 = CommandSetEntry.objects.create(group=None)

        benchmark_execution1 = BenchmarkExecutionEntry.objects.create(
            definition=benchmark_definition1,
            commit=commit1,
            worker=worker1,
            report=report1,
            invalidated=False,
            revision_target=28,
            status=BenchmarkExecutionEntry.READY)

        commands = []
        commands.append('command-new-1')
        commands.append('command-new-2')
        commands.append('command-new-3')
        commands.append('command-new-4')
        commands.append('command-new-5')

        overrides = []
        overrides.append({
            'result_id': 'id1',
            'override_value': 28,
            'ignore_fluctuation': False
        })
        overrides.append({
            'result_id': 'id2',
            'override_value': 29,
            'ignore_fluctuation': False
        })

        self.assertEqual('BenchmarkDefinition1', benchmark_definition1.name)
        self.assertEqual(1, BenchmarkExecutionEntry.objects.all().count())
        self.assertEqual(benchmark_execution1,
                         BenchmarkExecutionEntry.objects.all().first())
        self.assertEqual(
            0,
            CommandEntry.objects.filter(
                command_set=benchmark_definition1.command_set).count())
        self.assertEqual(
            0,
            BenchmarkFluctuationOverrideEntry.objects.all().count())

        result = BenchmarkDefinitionController.save_benchmark_definition(
            'BenchmarkDefinition1-1', benchmark_definition1.id,
            bluesteel_layout2.id, bluesteel_project2.id,
            BenchmarkDefinitionEntry.NORMAL, True, commands, 28, overrides, 0,
            [])

        self.assertEqual('BenchmarkDefinition1-1', result.name)
        self.assertEqual(0, BenchmarkExecutionEntry.objects.all().count())
Beispiel #3
0
    def test_save_same_benchmark_definition_does_not_increment_revision(self):
        self.assertEqual(0, CommandGroupEntry.objects.all().count())
        self.assertEqual(0, CommandSetEntry.objects.all().count())
        self.assertEqual(0, CommandEntry.objects.all().count())
        self.assertEqual(0, CommandResultEntry.objects.all().count())

        new_layout = BluesteelLayoutEntry.objects.create(name='default-name')
        project = BluesteelProjectController.create_default_project(
            new_layout, 'project', 0)
        definition = BenchmarkDefinitionController.create_default_benchmark_definition(
        )

        definition.priority = BenchmarkDefinitionEntry.HIGH

        self.assertEqual(1, BluesteelLayoutEntry.objects.all().count())
        self.assertEqual(1, BluesteelProjectEntry.objects.all().count())
        self.assertNotEqual(None, definition.command_set)
        self.assertEqual(
            1,
            CommandEntry.objects.filter(
                command_set=definition.command_set,
                command='git checkout {commit_hash}').count())
        self.assertEqual(
            1,
            CommandEntry.objects.filter(
                command_set=definition.command_set,
                command='git submodule update --init --recursive').count())
        self.assertEqual(
            1,
            CommandEntry.objects.filter(
                command_set=definition.command_set,
                command='<add_more_commands_here>').count())
        self.assertEqual(0, CommandResultEntry.objects.all().count())
        self.assertEqual(BenchmarkDefinitionEntry.HIGH, definition.priority)
        self.assertEqual(False, definition.active)
        self.assertEqual(0, definition.revision)
        self.assertEqual(0, definition.max_fluctuation_percent)
        self.assertEqual(1, definition.max_weeks_old_notify)
        self.assertEqual('default-name', definition.name)
        self.assertEqual(
            0,
            BenchmarkFluctuationOverrideEntry.objects.all().count())

        commands = self.get_default_commands()

        overrides = []
        overrides.append({
            'result_id': 'id1',
            'override_value': 28,
            'ignore_fluctuation': False
        })
        overrides.append({
            'result_id': 'id2',
            'override_value': 29,
            'ignore_fluctuation': False
        })

        result = BenchmarkDefinitionController.save_benchmark_definition(
            'default-name', definition.id, new_layout.id, project.id,
            BenchmarkDefinitionEntry.VERY_HIGH, True, commands, 0, overrides,
            8, [])
        definition = BenchmarkDefinitionEntry.objects.all().first()

        self.assertEqual(definition, result)
        self.assertEqual(
            1,
            CommandEntry.objects.filter(
                command_set=definition.command_set,
                command='git checkout {commit_hash}').count())
        self.assertEqual(
            1,
            CommandEntry.objects.filter(
                command_set=definition.command_set,
                command='git submodule update --init --recursive').count())
        self.assertEqual(
            1,
            CommandEntry.objects.filter(
                command_set=definition.command_set,
                command='<add_more_commands_here>').count())
        self.assertEqual(BenchmarkDefinitionEntry.VERY_HIGH,
                         definition.priority)
        self.assertEqual(True, definition.active)
        self.assertEqual(0, definition.revision)
        self.assertEqual(0, definition.max_fluctuation_percent)
        self.assertEqual(8, definition.max_weeks_old_notify)
        self.assertEqual('default-name', definition.name)
        self.assertEqual(
            2,
            BenchmarkFluctuationOverrideEntry.objects.all().count())
Beispiel #4
0
    def test_save_benchmark_definition(self):
        self.assertEqual(0, CommandGroupEntry.objects.all().count())
        self.assertEqual(0, CommandSetEntry.objects.all().count())
        self.assertEqual(0, CommandEntry.objects.all().count())
        self.assertEqual(0, CommandResultEntry.objects.all().count())

        new_layout = BluesteelLayoutEntry.objects.create(name='default-name')
        project = BluesteelProjectController.create_default_project(
            new_layout, 'project', 0)
        definition = BenchmarkDefinitionController.create_default_benchmark_definition(
        )

        self.assertEqual(1, BluesteelLayoutEntry.objects.all().count())
        self.assertEqual(1, BluesteelProjectEntry.objects.all().count())
        self.assertNotEqual(None, definition.command_set)
        self.assertEqual(
            3,
            CommandEntry.objects.filter(
                command_set=definition.command_set).count())
        self.assertEqual(0, CommandResultEntry.objects.all().count())
        self.assertEqual(BenchmarkDefinitionEntry.NORMAL, definition.priority)
        self.assertEqual(False, definition.active)
        self.assertEqual(0, definition.revision)
        self.assertEqual(0, definition.max_fluctuation_percent)
        self.assertEqual(1, definition.max_weeks_old_notify)
        self.assertEqual('default-name', definition.name)
        self.assertEqual(
            0,
            BenchmarkFluctuationOverrideEntry.objects.all().count())

        commands = []
        commands.append('command-28')
        commands.append('command-29')
        commands.append('command-30')

        overrides = []
        overrides.append({
            'result_id': 'id1',
            'override_value': 28,
            'ignore_fluctuation': False
        })
        overrides.append({
            'result_id': 'id2',
            'override_value': 29,
            'ignore_fluctuation': False
        })

        definition = BenchmarkDefinitionController.save_benchmark_definition(
            'new-name', definition.id, new_layout.id, project.id,
            BenchmarkDefinitionEntry.VERY_HIGH, True, commands, 28, overrides,
            8, [])

        self.assertEqual(
            1,
            CommandEntry.objects.filter(command_set=definition.command_set,
                                        command='command-28').count())
        self.assertEqual(
            1,
            CommandEntry.objects.filter(command_set=definition.command_set,
                                        command='command-29').count())
        self.assertEqual(
            1,
            CommandEntry.objects.filter(command_set=definition.command_set,
                                        command='command-30').count())
        self.assertEqual(BenchmarkDefinitionEntry.VERY_HIGH,
                         definition.priority)
        self.assertEqual(True, definition.active)
        self.assertEqual(1, definition.revision)
        self.assertEqual(28, definition.max_fluctuation_percent)
        self.assertEqual(8, definition.max_weeks_old_notify)
        self.assertEqual('new-name', definition.name)
        self.assertEqual(
            2,
            BenchmarkFluctuationOverrideEntry.objects.all().count())