예제 #1
0
    def test_get_bucket_async(self):
        config.Bucket(
            id='master.tryserver.chromium.linux',
            project_id='chromium',
            revision='deadbeef',
            config_content=MASTER_TRYSERVER_CHROMIUM_LINUX_CONFIG_TEXT,
            config_content_binary=text_to_binary(
                MASTER_TRYSERVER_CHROMIUM_LINUX_CONFIG_TEXT),
        ).put()
        project, cfg = config.get_bucket_async(
            'master.tryserver.chromium.linux').get_result()
        self.assertEqual(project, 'chromium')
        self.assertEqual(
            cfg,
            project_config_pb2.Bucket(
                name='master.tryserver.chromium.linux',
                acls=[
                    project_config_pb2.Acl(role=project_config_pb2.Acl.READER,
                                           group='all'),
                    project_config_pb2.Acl(
                        role=project_config_pb2.Acl.SCHEDULER,
                        group='tryjob-access'),
                ]),
        )

        self.assertIsNone(
            config.get_bucket_async('non.existing').get_result()[0])
예제 #2
0
 def test_get_buckets_async(self):
     config.Bucket(
         id='master.tryserver.chromium.linux',
         project_id='chromium',
         revision='deadbeef',
         config_content=MASTER_TRYSERVER_CHROMIUM_LINUX_CONFIG_TEXT).put()
     config.Bucket(
         id='master.tryserver.chromium.win',
         project_id='chromium',
         revision='deadbeef',
         config_content=MASTER_TRYSERVER_CHROMIUM_WIN_CONFIG_TEXT).put()
     actual = config.get_buckets_async().get_result()
     expected = [
         project_config_pb2.Bucket(
             name='master.tryserver.chromium.linux',
             acls=[
                 project_config_pb2.Acl(role=project_config_pb2.Acl.READER,
                                        group='all'),
                 project_config_pb2.Acl(
                     role=project_config_pb2.Acl.SCHEDULER,
                     group='tryjob-access'),
             ]),
         project_config_pb2.Bucket(
             name='master.tryserver.chromium.win',
             acls=[
                 project_config_pb2.Acl(role=project_config_pb2.Acl.READER,
                                        group='all'),
                 project_config_pb2.Acl(
                     role=project_config_pb2.Acl.SCHEDULER,
                     group='tryjob-access'),
             ]),
     ]
     self.assertEqual(actual, expected)
예제 #3
0
 def test_validate_buildbucket_cfg_fail(self):
     self.cfg_validation_test(
         project_config_pb2.BuildbucketCfg(buckets=[
             project_config_pb2.Bucket(
                 name='a',
                 acls=[
                     project_config_pb2.Acl(
                         group='writers',
                         identity='*****@*****.**',
                         role=project_config_pb2.Acl.READER),
                     project_config_pb2.Acl(
                         role=project_config_pb2.Acl.READER),
                 ]),
             project_config_pb2.Bucket(
                 name='b',
                 acls=[
                     project_config_pb2.Acl(
                         identity='ldap',
                         role=project_config_pb2.Acl.READER),
                     project_config_pb2.Acl(
                         group='*****@*****.**',
                         role=project_config_pb2.Acl.READER),
                 ]),
             project_config_pb2.Bucket(),
         ]), [
             errmsg(
                 'Bucket a: acl #1: either group or identity must be set, '
                 'not both'),
             errmsg('Bucket a: acl #2: group or identity must be set'),
             errmsg('Bucket b: acl #1: Identity has invalid format: ldap'),
             errmsg('Bucket b: acl #2: invalid group: [email protected]'),
             errmsg('Bucket #3: invalid name: Bucket not specified'),
         ])
예제 #4
0
 def test_validate_buildbucket_cfg_success(self):
     self.cfg_validation_test(
         project_config_pb2.BuildbucketCfg(buckets=[
             project_config_pb2.Bucket(
                 name='good.name',
                 acls=[
                     project_config_pb2.Acl(
                         group='writers',
                         role=project_config_pb2.Acl.WRITER)
                 ],
             ),
             project_config_pb2.Bucket(
                 name='good.name2',
                 acls=[
                     project_config_pb2.Acl(
                         identity='*****@*****.**',
                         role=project_config_pb2.Acl.READER),
                     project_config_pb2.Acl(
                         identity='user:[email protected]',
                         role=project_config_pb2.Acl.READER),
                 ],
             )
         ]), [])
예제 #5
0
    def test_cron_update_buckets_with_existing(self):
        config.Bucket(
            id='master.tryserver.chromium.linux',
            project_id='chromium',
            revision='deadbeef',
            config_content=MASTER_TRYSERVER_CHROMIUM_LINUX_CONFIG_TEXT,
        ).put()

        # Will not be updated.
        config.Bucket(
            id='master.tryserver.v8',
            project_id='v8',
            revision='deadbeef',
            config_content=MASTER_TRYSERVER_V8_CONFIG_TEXT,
        ).put()

        # Will be deleted.
        config.Bucket(
            id='master.tryserver.chromium.win',
            project_id='chromium',
            revision='deadbeef',
            config_content=MASTER_TRYSERVER_CHROMIUM_WIN_CONFIG_TEXT,
        ).put()

        chromium_buildbucket_cfg = project_config_pb2.BuildbucketCfg(buckets=[
            project_config_pb2.Bucket(
                name='master.tryserver.chromium.linux',
                acls=[
                    project_config_pb2.Acl(role=project_config_pb2.Acl.READER,
                                           group='all'),
                    project_config_pb2.Acl(
                        role=project_config_pb2.Acl.SCHEDULER,
                        group='tryjob-access'),
                ],
            ),
            # Will be added.
            project_config_pb2.Bucket(
                name='master.tryserver.chromium.mac',
                acls=[
                    project_config_pb2.Acl(role=project_config_pb2.Acl.READER,
                                           group='all'),
                    project_config_pb2.Acl(
                        role=project_config_pb2.Acl.SCHEDULER,
                        group='tryjob-access'),
                ],
            ),
        ])

        v8_buildbucket_cfg = project_config_pb2.BuildbucketCfg(
            buckets=[
                # Reservation will fail.
                project_config_pb2.Bucket(
                    name='master.tryserver.chromium.linux',
                    acls=[
                        project_config_pb2.Acl(
                            role=project_config_pb2.Acl.WRITER,
                            group='v8-team')
                    ],
                ),
                # Will not be updated.
                project_config_pb2.Bucket(
                    name='master.tryserver.v8',
                    acls=[
                        project_config_pb2.Acl(
                            role=project_config_pb2.Acl.WRITER,
                            group='v8-team')
                    ],
                ),
            ], )

        self.mock(config_component, 'get_project_configs', mock.Mock())
        config_component.get_project_configs.return_value = {
            'chromium': ('new!', chromium_buildbucket_cfg),
            'v8': ('deadbeef', v8_buildbucket_cfg),
        }

        config.cron_update_buckets()

        actual = config.Bucket.query().fetch()
        actual = sorted(actual, key=lambda b: b.key.id())
        expected = [
            config.Bucket(
                id='master.tryserver.chromium.linux',
                project_id='chromium',
                revision='new!',
                config_content=MASTER_TRYSERVER_CHROMIUM_LINUX_CONFIG_TEXT,
            ),
            config.Bucket(
                id='master.tryserver.chromium.mac',
                project_id='chromium',
                revision='new!',
                config_content=MASTER_TRYSERVER_CHROMIUM_MAC_CONFIG_TEXT,
            ),
            config.Bucket(
                id='master.tryserver.v8',
                project_id='v8',
                revision='deadbeef',
                config_content=MASTER_TRYSERVER_V8_CONFIG_TEXT,
            ),
        ]
        self.assertEqual(actual, expected)
예제 #6
0
    def test_cron_update_buckets(self):
        chromium_buildbucket_cfg = project_config_pb2.BuildbucketCfg(buckets=[
            project_config_pb2.Bucket(
                name='master.tryserver.chromium.linux',
                acls=[
                    project_config_pb2.Acl(role=project_config_pb2.Acl.READER,
                                           group='all'),
                    project_config_pb2.Acl(
                        role=project_config_pb2.Acl.SCHEDULER,
                        group='tryjob-access'),
                ],
            ),
            project_config_pb2.Bucket(
                name='master.tryserver.chromium.win',
                acls=[
                    project_config_pb2.Acl(role=project_config_pb2.Acl.READER,
                                           group='all'),
                    project_config_pb2.Acl(
                        role=project_config_pb2.Acl.SCHEDULER,
                        group='tryjob-access'),
                ],
            ),
        ])

        v8_buildbucket_cfg = project_config_pb2.BuildbucketCfg(buckets=[
            project_config_pb2.Bucket(
                name='master.tryserver.v8',
                acls=[
                    project_config_pb2.Acl(role=project_config_pb2.Acl.WRITER,
                                           group='v8-team')
                ],
            ),
        ])

        test_buildbucket_cfg = project_config_pb2.BuildbucketCfg(buckets=[
            project_config_pb2.Bucket(
                name='master.tryserver.test',
                acls=[
                    project_config_pb2.Acl(role=project_config_pb2.Acl.WRITER,
                                           identity='*****@*****.**')
                ],
            ),
        ])

        self.mock(config_component, 'get_project_configs', mock.Mock())
        config_component.get_project_configs.return_value = {
            'chromium': ('deadbeef', chromium_buildbucket_cfg),
            'v8': (None, v8_buildbucket_cfg),
            'test': ('babe', test_buildbucket_cfg),
        }

        config.cron_update_buckets()

        actual = config.Bucket.query().fetch()
        actual = sorted(actual, key=lambda b: b.key)
        expected = [
            config.Bucket(
                id='master.tryserver.chromium.linux',
                project_id='chromium',
                revision='deadbeef',
                config_content=MASTER_TRYSERVER_CHROMIUM_LINUX_CONFIG_TEXT,
            ),
            config.Bucket(
                id='master.tryserver.chromium.win',
                project_id='chromium',
                revision='deadbeef',
                config_content=MASTER_TRYSERVER_CHROMIUM_WIN_CONFIG_TEXT,
            ),
            config.Bucket(id='master.tryserver.test',
                          project_id='test',
                          revision='babe',
                          config_content=MASTER_TRYSERVER_TEST_CONFIG_TEXT),
            config.Bucket(
                id='master.tryserver.v8',
                project_id='v8',
                revision='sha1:cfc761d7a953a72ddea8f3d4c9a28e69777ca22c',
                config_content=MASTER_TRYSERVER_V8_CONFIG_TEXT,
            ),
        ]
        self.assertEqual(actual, expected)