def test_good_request(self): config.put_bucket( 'chromium', 'a' * 40, test_util.parse_bucket_cfg(''' name: "try" acls { role: SCHEDULER identity: "anonymous:anonymous" } '''), ) config.put_bucket( 'chromium', 'a' * 40, test_util.parse_bucket_cfg(''' name: "ci" acls { role: READER identity: "anonymous:anonymous" } '''), ) request = access_pb2.PermittedActionsRequest( resource_kind='bucket', resource_ids=['luci.chromium.try', 'luci.chromium.ci'], ) result = self.servicer.PermittedActions(request, None) self.assertEqual(len(result.permitted), 2) self.assertEqual( set(result.permitted.keys()), {'luci.chromium.try', 'luci.chromium.ci'}, ) try_perms = result.permitted['luci.chromium.try'] self.assertEqual(len(try_perms.actions), 5) # Sanity check. self.assertEqual( set(try_perms.actions), {action.name for action in user.ROLE_TO_ACTIONS[Acl.SCHEDULER]}, ) ci_perms = result.permitted['luci.chromium.ci'] self.assertEqual( set(ci_perms.actions), {action.name for action in user.ROLE_TO_ACTIONS[Acl.READER]}, )
def setUp(self): super(ToBucketIDTest, self).setUp() config.put_bucket( 'chromium', 'a' * 40, test_util.parse_bucket_cfg('name: "luci.chromium.try"'), )
def setUp(self): super(ConvertBucketTest, self).setUp() user.clear_request_cache() config.put_bucket( 'chromium', 'a' * 40, test_util.parse_bucket_cfg(''' name: "luci.chromium.try" acls { role: READER identity: "anonymous:anonymous" } '''), )
def test_retry_forbidden(self): config.put_bucket( 'chromium', 'a' * 40, test_util.parse_bucket_cfg(''' name: "readonly" acls { role: READER identity: "anonymous:anonymous" } '''), ) test_util.build(id=1, builder=dict(project='chromium', bucket='readonly')).put() self.call_api('retry', {'id': '1'}, status=403)
def test_update_global_metrics(self, set_build_count_metric_async, set_build_latency): set_build_count_metric_async.return_value = future(None) set_build_latency.return_value = future(None) model.Builder(id='chromium:luci.chromium.try:release').put() model.Builder(id='chromium:luci.chromium.try:debug').put() model.Builder(id='chromium:try:debug').put() config.put_bucket( 'chromium', 'a' * 40, test_util.parse_bucket_cfg(''' name: "luci.chromium.try" swarming { builders {} } '''), ) metrics.update_global_metrics() set_build_latency.assert_any_call('chromium/try', 'luci.chromium.try', 'release', True) set_build_latency.assert_any_call('chromium/try', 'luci.chromium.try', 'release', False) set_build_latency.assert_any_call('chromium/try', 'luci.chromium.try', 'debug', True) set_build_latency.assert_any_call('chromium/try', 'luci.chromium.try', 'debug', False) set_build_count_metric_async.assert_any_call( 'chromium/try', 'luci.chromium.try', 'release', model.BuildStatus.SCHEDULED, False) set_build_count_metric_async.assert_any_call( 'chromium/try', 'luci.chromium.try', 'release', model.BuildStatus.SCHEDULED, True) set_build_count_metric_async.assert_any_call( 'chromium/try', 'luci.chromium.try', 'debug', model.BuildStatus.SCHEDULED, False) set_build_count_metric_async.assert_any_call( 'chromium/try', 'luci.chromium.try', 'debug', model.BuildStatus.SCHEDULED, True)
def setUp(self): super(CreationTest, self).setUp() user.clear_request_cache() self.current_identity = auth.Identity('service', 'unittest') self.patch('components.auth.get_current_identity', side_effect=lambda: self.current_identity) self.patch('user.can_async', return_value=future(True)) self.now = datetime.datetime(2015, 1, 1) self.patch('components.utils.utcnow', side_effect=lambda: self.now) self.chromium_try = test_util.parse_bucket_cfg(''' name: "luci.chromium.try" swarming { builders { name: "linux" build_numbers: YES swarming_host: "chromium-swarm.appspot.com" recipe { name: "recipe" cipd_package: "infra/recipe_bundle" cipd_version: "refs/heads/master" } } builders { name: "mac" swarming_host: "chromium-swarm.appspot.com" recipe { name: "recipe" cipd_package: "infra/recipe_bundle" cipd_version: "refs/heads/master" } } builders { name: "win" swarming_host: "chromium-swarm.appspot.com" recipe { name: "recipe" cipd_package: "infra/recipe_bundle" cipd_version: "refs/heads/master" } } } ''') config.put_bucket('chromium', 'a' * 40, self.chromium_try) self.create_sync_task = self.patch( 'swarming.create_sync_task', autospec=True, return_value={'is_payload': True}, ) self.patch('swarming.cancel_task_async', return_value=future(None)) self.patch( 'google.appengine.api.app_identity.get_default_version_hostname', autospec=True, return_value='buildbucket.example.com') self.patch('tq.enqueue_async', autospec=True, return_value=future(None)) self.settings = service_config_pb2.SettingsCfg( swarming=dict(global_caches=[dict(path='git')]), logdog=dict(hostname='logs.example.com'), ) self.patch('config.get_settings_async', autospec=True, return_value=future(self.settings)) self.patch('creation._should_update_builder', side_effect=lambda p: p > 0.5) self.patch('creation._should_be_canary', side_effect=lambda p: p > 50) self.patch('search.TagIndex.random_shard_index', return_value=0)
def setUp(self): super(SwarmbucketApiTest, self).setUp() self.patch('components.utils.utcnow', autospec=True, return_value=datetime.datetime(2015, 11, 30)) self.patch( 'google.appengine.api.app_identity.get_default_version_hostname', return_value='cr-buildbucket.appspot.com') self.patch('creation._should_be_canary', side_effect=lambda p: p > 50) auth_testing.reset_local_state() auth.bootstrap_group('all', [auth.Anonymous]) user.clear_request_cache() chromium_cfg = test_util.parse_bucket_cfg(''' name: "luci.chromium.try" acls { role: SCHEDULER group: "all" } swarming { hostname: "swarming.example.com" builders { name: "linux" swarming_host: "swarming.example.com" category: "Chromium" build_numbers: YES recipe { cipd_package: "infra/recipe_bundle" cipd_version: "refs/heads/master" name: "presubmit" properties: "foo:bar" properties_j: "baz:1" } dimensions: "foo:bar" dimensions: "baz:baz" auto_builder_dimension: YES # Override builder cache without timeout to make tests # simpler. caches { path: "builder" name: "builder_cache_name" } } builders { name: "windows" category: "Chromium" swarming_host: "swarming.example.com" recipe { cipd_package: "infra/recipe_bundle" cipd_version: "refs/heads/master" name: "presubmit" } # Override builder cache without timeout to make tests # simpler. caches { path: "builder" name: "builder_cache_name" } } } ''') config.put_bucket('chromium', 'deadbeef', chromium_cfg) v8_cfg = test_util.parse_bucket_cfg(''' name: "luci.v8.try" acls { role: READER group: "all" } ''') config.put_bucket('v8', 'deadbeef', v8_cfg) self.settings = service_config_pb2.SettingsCfg( swarming=dict( milo_hostname='milo.example.com', bbagent_package=dict( package_name='infra/tools/bbagent', version='luci-runner-version', ), kitchen_package=dict( package_name='infra/tools/kitchen', version='kitchen-version', ), user_packages=[ dict( package_name='infra/tools/git', version='git-version', ), ], ), logdog=dict(hostname='logdog.example.com'), ) self.patch( 'config.get_settings_async', autospec=True, return_value=future(self.settings), )