Example #1
0
    def test_get_builders_with_bucket_filtering(self):
        # Add a second bucket with a different name.
        other_bucket = '''
      name: "luci.other.try"
      acls {
        role: SCHEDULER
        group: "all"
      }
      swarming {
        hostname: "swarming.example.com"
        builders {
          name: "a"
          swarming_host: "swarming.example.com"
        }
      }
    '''
        config.put_bucket('other', 'deadbeef',
                          test_util.parse_bucket_cfg(other_bucket))

        req = {
            'bucket': ['luci.chromium.try'],
        }
        resp = self.call_api('get_builders', req).json_body
        self.assertEqual(
            test_util.ununicode(resp),
            {
                'buckets': [{
                    'name':
                    'luci.chromium.try',
                    'swarming_hostname':
                    'swarming.example.com',
                    'builders': [
                        {
                            'name':
                            'linux',
                            'category':
                            'Chromium',
                            'properties_json':
                            json.dumps({
                                'foo': 'bar',
                                'baz': 1
                            }),
                            'swarming_hostname':
                            'swarming.example.com',
                            'swarming_dimensions': [
                                'baz:baz',
                                'builder:linux',
                                'foo:bar',
                            ],
                        },
                        {
                            'name': 'windows',
                            'category': 'Chromium',
                            'properties_json': json.dumps({}),
                            'swarming_hostname': 'swarming.example.com',
                        },
                    ],
                }],
            },
        )
Example #2
0
    def test_get_builders(self):
        secret_cfg = 'name: "secret"'
        config.put_bucket('secret', 'deadbeef',
                          test_util.parse_bucket_cfg(secret_cfg))

        resp = self.call_api('get_builders').json_body
        self.assertEqual(
            test_util.ununicode(resp),
            {
                'buckets': [{
                    'name':
                    'luci.chromium.try',
                    'swarming_hostname':
                    'swarming.example.com',
                    'builders': [
                        {
                            'name':
                            'linux',
                            'category':
                            'Chromium',
                            'properties_json':
                            json.dumps({
                                'foo': 'bar',
                                'baz': 1
                            }),
                            'swarming_hostname':
                            'swarming.example.com',
                            'swarming_dimensions':
                            ['baz:baz', 'builder:linux', 'foo:bar'],
                        },
                        {
                            'name': 'windows',
                            'category': 'Chromium',
                            'properties_json': json.dumps({}),
                            'swarming_hostname': 'swarming.example.com',
                        },
                    ],
                }],
            },
        )
Example #3
0
  def test_legacy_kitchen(self):
    build = self._test_build(
        builder=build_pb2.BuilderID(
            project='chromium', bucket='try', builder='linux_kitchen'
        ),
    )
    actual = self.compute_task_def(build)

    self.assertEqual([
        "kitchen${EXECUTABLE_SUFFIX}", 'cook', '-buildbucket-hostname',
        'cr-buildbucket.appspot.com', '-buildbucket-build-id',
        '9027773186396127232', '-call-update-build', '-build-url',
        'https://milo.example.com/b/9027773186396127232',
        '-luci-system-account', 'system', '-recipe', 'presubmit', '-cache-dir',
        'cache', '-checkout-dir', 'kitchen-checkout', '-temp-dir', 'tmp',
        '-properties',
        api_common.properties_to_json(
            swarming._compute_legacy_properties(build)
        ), '-logdog-annotation-url',
        'logdog://logdog.example.com/chromium/bb/+/annotations',
        '-known-gerrit-host', 'chromium-review.googlesource.com'
    ], test_util.ununicode(actual['task_slices'][0]['properties']['command']))
Example #4
0
    def test_properties(self):
        self.patch('components.auth.get_current_identity',
                   autospec=True,
                   return_value=auth.Identity('user', '*****@*****.**'))

        build = self._test_build(
            id=1,
            number=1,
            builder=build_pb2.BuilderID(project='chromium',
                                        bucket='try',
                                        builder='linux'),
            exe=dict(
                cipd_package='infra/recipe_bundle',
                cipd_version='refs/heads/master',
            ),
            input=dict(
                properties=bbutil.dict_to_struct({
                    'a': 'b',
                    'recipe': 'recipe',
                }),
                gerrit_changes=[
                    dict(
                        host='chromium-review.googlesource.com',
                        project='chromium/src',
                        change=1234,
                        patchset=5,
                    ),
                ],
            ),
            infra=dict(swarming=dict(
                task_service_account='*****@*****.**',
                priority=108,
                task_dimensions=[
                    dict(key='cores', value='8'),
                    dict(key='os', value='Ubuntu'),
                    dict(key='pool', value='Chrome'),
                ],
            ), ),
        )

        _, extra_task_template_params = swarming._setup_recipes(build)
        actual = json.loads(extra_task_template_params['properties_json'])

        expected = {
            'a': 'b',
            'buildbucket': {
                'hostname': 'cr-buildbucket.appspot.com',
                'build': {
                    'project':
                    'chromium',
                    'bucket':
                    'luci.chromium.try',
                    'created_by':
                    'anonymous:anonymous',
                    'created_ts':
                    1448841600000000,
                    'id':
                    '1',
                    'tags': [
                        'build_address:luci.chromium.try/linux/1',
                        'builder:linux',
                        'buildset:1',
                    ],
                },
            },
            'buildername': 'linux',
            'buildnumber': 1,
            'recipe': 'recipe',
            'repository': 'https://chromium.googlesource.com/chromium/src',
            '$recipe_engine/buildbucket': {
                'hostname': 'cr-buildbucket.appspot.com',
                'build': {
                    'id': '1',
                    'builder': {
                        'project': 'chromium',
                        'bucket': 'try',
                        'builder': 'linux',
                    },
                    'number': 1,
                    'tags': [{
                        'value': '1',
                        'key': 'buildset'
                    }],
                    'exe': {
                        'cipdPackage': 'infra/recipe_bundle',
                        'cipdVersion': 'refs/heads/master',
                    },
                    'input': {
                        'gerritChanges': [{
                            'host': 'chromium-review.googlesource.com',
                            'project': 'chromium/src',
                            'change': '1234',
                            'patchset': '5',
                        }],
                    },
                    'infra': {
                        'buildbucket': {},
                        'swarming': {
                            'hostname':
                            'swarming.example.com',
                            'taskId':
                            'deadbeef',
                            'taskServiceAccount':
                            '*****@*****.**',
                            'priority':
                            108,
                            'taskDimensions': [
                                {
                                    'key': 'cores',
                                    'value': '8'
                                },
                                {
                                    'key': 'os',
                                    'value': 'Ubuntu'
                                },
                                {
                                    'key': 'pool',
                                    'value': 'Chrome'
                                },
                            ],
                        },
                        'logdog': {
                            'hostname': 'logdog.example.com',
                            'project': 'chromium',
                            'prefix': 'bb',
                        },
                    },
                    'createdBy': 'anonymous:anonymous',
                    'createTime': '2015-11-30T00:00:00Z',
                },
            },
            '$recipe_engine/runtime': {
                'is_experimental': False,
                'is_luci': True,
            },
        }
        self.assertEqual(test_util.ununicode(actual), expected)
Example #5
0
                'wait_for_capacity': False,
            }],
            'pubsub_topic':
            'projects/testbed-test/topics/swarming',
            'pubsub_userdata':
            json.dumps(
                {
                    'created_ts': 1448841600000000,
                    'swarming_hostname': 'swarming.example.com',
                    'build_id': 1L,
                },
                sort_keys=True),
            'service_account':
            '*****@*****.**',
        }
        self.assertEqual(test_util.ununicode(actual), expected)

        self.assertEqual(build.url, 'https://milo.example.com/b/1')

        self.assertEqual(build.proto.infra.swarming.task_service_account,
                         '*****@*****.**')

        self.assertNotIn('buildbucket', build.proto.input.properties)
        self.assertNotIn('$recipe_engine/buildbucket',
                         build.proto.input.properties)

    def test_experimental(self):
        build = self._test_build(input=dict(experimental=True))
        actual = self.prepare_task_def(build)

        env = actual['task_slices'][0]['properties']['env']
Example #6
0
    def test_build_to_dict(self):
        params_json = json.dumps(
            {
                api_common.BUILDER_PARAMETER: 'linux',
                api_common.PROPERTIES_PARAMETER: {
                    'build-defined-property': 1.0,
                },
            },
            sort_keys=True,
        )
        tags = [
            'build_address:luci.chromium.try/linux/1',
            'builder:linux',
            'buildset:1',
            'swarming_hostname:swarming.example.com',
            ('swarming_tag:log_location:'
             'logdog://logdog.example.com/chromium/bb/+/annotations'),
            'swarming_tag:luci_project:chromium',
            'swarming_tag:os:Ubuntu',
            'swarming_tag:recipe_name:recipe',
            'swarming_tag:recipe_package:infra/recipe_bundle',
            'swarming_task_id:deadbeef',
        ]
        result_details = {
            'properties': {
                'a': 'b'
            },
            'swarming': {
                'bot_dimensions': {
                    'dim1': ['v1', 'v2'],
                    'os': ['Ubuntu'],
                },
            },
            'error': {
                'message': 'bad'
            },
            'ui': {
                'info': 'bad'
            },
        }
        expected = {
            'project': 'chromium',
            'bucket': 'luci.chromium.try',
            'created_by': 'anonymous:anonymous',
            'created_ts': '1483228800000000',
            'experimental': False,
            'completed_ts': '1483228800000000',
            'id': '8991715593768927232',
            'parameters_json': params_json,
            'result_details_json': json.dumps(result_details, sort_keys=True),
            'status': 'COMPLETED',
            'result': 'FAILURE',
            'failure_reason': 'INFRA_FAILURE',
            'status_changed_ts': '1483228800000000',
            'tags': tags,
            'utcnow_ts': '1483228800000000',
            'updated_ts': '1483228800000000',
            'canary_preference': 'PROD',
            'canary': False,
            'service_account': '*****@*****.**',
            'url': 'https://ci.example.com/8991715593768927232',
        }

        bundle = test_util.build_bundle(
            status=common_pb2.INFRA_FAILURE,
            summary_markdown='bad',
            input=dict(properties=bbutil.dict_to_struct({
                'recipe':
                'recipe',
                'build-defined-property':
                1,
                'builder-defined-property':
                2,
            }), ),
            output=dict(properties=bbutil.dict_to_struct({'a': 'b'}), ),
            infra=dict(
                swarming=dict(bot_dimensions=[
                    dict(key='dim1', value='v1'),
                    dict(key='dim1', value='v2'),
                    dict(key='os', value='Ubuntu'),
                ], ),
                buildbucket=dict(requested_properties=bbutil.dict_to_struct({
                    'build-defined-property':
                    1,
                }), ),
            ))

        self.assertEqual(expected,
                         test_util.ununicode(api_common.build_to_dict(bundle)))
Example #7
0
    def test_get_task_def(self):
        self.patch(
            'tokens.generate_build_token',
            autospec=True,
            return_value='beeff00d',
        )

        req = {
            'build_request': {
                'bucket':
                'luci.chromium.try',
                'parameters_json':
                json.dumps({
                    api_common.BUILDER_PARAMETER: 'linux',
                }),
            },
        }
        resp = self.call_api('get_task_def', req).json_body
        actual_task_def = json.loads(resp['task_definition'])
        props_def = {
            'env': [{
                'key': 'BUILDBUCKET_EXPERIMENTAL',
                'value': 'FALSE'
            }],
            'env_prefixes': [{
                'key':
                'PATH',
                'value': ['cipd_bin_packages', 'cipd_bin_packages/bin']
            }],
            # Concrete command line is not a concern of this test.
            'command':
            test_util.ununicode(
                actual_task_def['task_slices'][0]['properties']['command']),
            'execution_timeout_secs':
            '10800',
            'cipd_input': {
                'packages': [
                    {
                        'package_name': 'infra/tools/bbagent',
                        'path': '.',
                        'version': 'luci-runner-version',
                    },
                    {
                        'package_name': 'infra/tools/kitchen',
                        'path': '.',
                        'version': 'kitchen-version',
                    },
                    {
                        'package_name': 'infra/recipe_bundle',
                        'path': 'kitchen-checkout',
                        'version': 'refs/heads/master',
                    },
                    {
                        'package_name': 'infra/tools/git',
                        'path': swarming.USER_PACKAGE_DIR,
                        'version': 'git-version',
                    },
                ],
            },
            'dimensions': [
                {
                    'key': 'baz',
                    'value': 'baz'
                },
                {
                    'key': 'builder',
                    'value': 'linux'
                },
                {
                    'key': 'foo',
                    'value': 'bar'
                },
            ],
            'caches': [{
                'path': 'cache/builder',
                'name': 'builder_cache_name',
            }],
        }
        expected_task_def = {
            'name':
            'bb-1-chromium/try/linux-1',
            'tags': [
                'buildbucket_bucket:chromium/try',
                'buildbucket_build_id:1',
                'buildbucket_hostname:cr-buildbucket.appspot.com',
                'buildbucket_template_canary:0',
                'builder:linux',
                'luci_project:chromium',
            ],
            'priority':
            '30',
            'task_slices': [{
                'expiration_secs': '21600',
                'properties': props_def,
                'wait_for_capacity': False,
            }],
        }
        self.assertEqual(test_util.ununicode(actual_task_def),
                         expected_task_def)
        self.assertEqual(resp['swarming_host'], 'swarming.example.com')
Example #8
0
  def test_properties(self):
    self.patch(
        'components.auth.get_current_identity',
        autospec=True,
        return_value=auth.Identity('user', '*****@*****.**')
    )

    now_ts = timestamp_pb2.Timestamp()
    now_ts.FromDatetime(utils.utcnow())
    build = model.Build(
        tags=['t:1'],
        created_by=auth.Anonymous,
        proto=build_pb2.Build(
            id=1,
            builder=dict(project='chromium', bucket='try', builder='linux-rel'),
            number=1,
            status=common_pb2.SCHEDULED,
            created_by='anonymous:anonymous',
            create_time=now_ts,
            update_time=now_ts,
            input=dict(
                properties=bbutil.dict_to_struct({
                    'recipe': 'recipe',
                    'a': 'b',
                }),
                gerrit_changes=[
                    dict(
                        host='chromium-review.googlesource.com',
                        project='chromium/src',
                        change=1234,
                        patchset=5,
                    )
                ],
            ),
            output=dict(),
            infra=dict(
                buildbucket=dict(
                    requested_properties=bbutil.dict_to_struct({'a': 'b'}),
                ),
                recipe=dict(),
            ),
        ),
    )

    actual = bbutil.struct_to_dict(swarming._compute_legacy_properties(build))

    expected = {
        'a': 'b',
        'buildbucket': {
            'hostname': 'cr-buildbucket.appspot.com',
            'build': {
                'project': 'chromium',
                'bucket': 'luci.chromium.try',
                'created_by': 'anonymous:anonymous',
                'created_ts': 1448841600000000,
                'id': '1',
                'tags': ['t:1'],
            },
        },
        'buildername': 'linux-rel',
        'buildnumber': 1,
        'recipe': 'recipe',
        'repository': 'https://chromium.googlesource.com/chromium/src',
        '$recipe_engine/buildbucket': {
            'hostname': 'cr-buildbucket.appspot.com',
            'build': {
                'id': '1',
                'builder': {
                    'project': 'chromium',
                    'bucket': 'try',
                    'builder': 'linux-rel',
                },
                'number': 1,
                'tags': [{'key': 't', 'value': '1'}],
                'input': {
                    'gerritChanges': [{
                        'host': 'chromium-review.googlesource.com',
                        'project': 'chromium/src',
                        'change': '1234',
                        'patchset': '5',
                    }],
                },
                'infra': {'buildbucket': {},},
                'createdBy': 'anonymous:anonymous',
                'createTime': '2015-11-30T00:00:00Z',
            },
        },
        '$recipe_engine/runtime': {
            'is_experimental': False,
            'is_luci': True,
        },
    }
    self.assertEqual(test_util.ununicode(actual), expected)