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 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 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 setUp(self): self.mock_http = mock.MagicMock() self.PatchObject(auth, 'AuthorizedHttp', return_value=self.mock_http) self.success_response = {'status': 200} self.PatchObject(buildbucket_lib.BuildbucketClient, '_GetHost', return_value=buildbucket_lib.BUILDBUCKET_TEST_HOST) self.client = buildbucket_lib.BuildbucketClient(mock.Mock(), None)
def testCancelWithBuildbucketClient(self): """Test Buildbucket client cancels successfully during CancelBuilds.""" buildbucket_id_1 = '100' buildbucket_id_2 = '200' buildbucket_ids = [buildbucket_id_1, buildbucket_id_2] self.PatchObject(buildbucket_lib, 'GetServiceAccount', return_value=True) send_request_mock = self.PatchObject(buildbucket_lib.BuildbucketClient, 'SendBuildbucketRequest', return_value=dict()) buildbucket_client = buildbucket_lib.BuildbucketClient( mock.Mock(), mock.Mock()) builder_status_lib.CancelBuilds(buildbucket_ids, buildbucket_client) self.assertEqual(send_request_mock.call_count, 1)
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)