def verifyBuildbucketRequest(self, buildbucket_id, expected_bucket, expected_tags, expected_parameters): """Verify the contents of a push to the TEST buildbucket instance. Args: buildbucket_id: Id to verify. expected_bucket: Bucket the push was supposed to go to as a string. expected_tags: List of buildbucket tags as strings. expected_parameters: Python dict equivalent to json string in parameters_json. """ buildbucket_client = buildbucket_lib.BuildbucketClient( auth.GetAccessToken, buildbucket_lib.BUILDBUCKET_TEST_HOST, service_account_json=buildbucket_lib.GetServiceAccount( constants.CHROMEOS_SERVICE_ACCOUNT)) request = buildbucket_client.GetBuildRequest(buildbucket_id, False) self.assertEqual(request['build']['id'], buildbucket_id) self.assertEqual(request['build']['bucket'], expected_bucket) self.assertCountEqual(request['build']['tags'], expected_tags) request_parameters = json.loads(request['build']['parameters_json']) self.assertEqual(request_parameters, expected_parameters)
def getProdClient(self): """Create a buildbucket client which is safe for RO network tests.""" return buildbucket_lib.BuildbucketClient( auth.GetAccessToken, buildbucket_lib.BUILDBUCKET_HOST, service_account_json=buildbucket_lib.GetServiceAccount( constants.CHROMEOS_SERVICE_ACCOUNT))
def GetBuildbucketClient(self): """Build a buildbucket_client instance for Buildbucket related operations. Returns: An instance of buildbucket_lib.BuildbucketClient if the build is using Buildbucket as the scheduler; else, None. """ buildbucket_client = None if config_lib.UseBuildbucketScheduler(self._run.config): if buildbucket_lib.GetServiceAccount( constants.CHROMEOS_SERVICE_ACCOUNT): buildbucket_client = buildbucket_lib.BuildbucketClient( auth.GetAccessToken, None, service_account_json=constants.CHROMEOS_SERVICE_ACCOUNT) if buildbucket_client is None and self._run.InProduction(): # If the build using Buildbucket is running on buildbot and # is in production mode, buildbucket_client cannot be None. raise buildbucket_lib.NoBuildbucketClientException( 'Buildbucket_client is None. ' 'Please check if the buildbot has a valid service account file. ' 'Please find the service account json file at %s.' % constants.CHROMEOS_SERVICE_ACCOUNT) return buildbucket_client
def Submit(self, testjob=False, dryrun=False): """Submit the tryjob through Git. Args: testjob: Submit job to the test branch of the tryjob repo. The tryjob will be ignored by production master. dryrun: Setting to true will run everything except the final submit step. Returns: A ScheduledBuild instance. """ host = (buildbucket_lib.BUILDBUCKET_TEST_HOST if testjob else buildbucket_lib.BUILDBUCKET_HOST) buildbucket_client = buildbucket_lib.BuildbucketClient( auth.GetAccessToken, host, service_account_json=buildbucket_lib.GetServiceAccount( constants.CHROMEOS_SERVICE_ACCOUNT)) return self._PutConfigToBuildBucket(buildbucket_client, dryrun)
def RunAlertsDispatcher(self, db_credentials_dir, tree): """Submit alerts summary to Sheriff-o-Matic. Args: db_credentials_dir: Path to CIDB database credentials. tree: Sheriff-o-Matic tree to submit alerts to. """ dispatcher_cmd = [ os.path.join(self._build_root, 'chromite', 'scripts', 'som_alerts_dispatcher'), '--som_tree', tree ] if buildbucket_lib.GetServiceAccount( constants.CHROMEOS_SERVICE_ACCOUNT): # User the service account file if it exists. dispatcher_cmd.extend( ['--service_acct_json', constants.CHROMEOS_SERVICE_ACCOUNT]) if tree != constants.SOM_TREE: dispatcher_cmd.append('--allow_experimental') dispatcher_cmd.append(db_credentials_dir) cros_build_lib.RunCommand(dispatcher_cmd)