def promote_link(dlrn, hash_values, link): '''Promotes a set of hash values as a named link using DLRN API''' logger = logging.getLogger('promoter') current_hashes = fetch_hashes(dlrn, link) # Save current hash as previous-$link if current_hashes is not None: params = dlrnapi_client.Promotion() params.commit_hash = current_hashes['commit_hash'] params.distro_hash = current_hashes['distro_hash'] params.promote_name = "previous-" + link try: dlrn.api_promote_post(params) except ApiException: logger.error( 'Exception when calling api_promote_post: %s' ' to store current hashes as previous', ApiException) raise params = dlrnapi_client.Promotion() params.commit_hash = hash_values['commit_hash'] params.distro_hash = hash_values['distro_hash'] params.promote_name = link try: dlrn.api_promote_post(params) except ApiException: logger.error('Exception when calling api_promote_post: %s', ApiException) raise
def __init__(self, config): """ like all the the other inits around this code, the init will gather relevant information for this class and put them into local shortcuts :param config: The global promoter config or the reduced dlrnclient config """ self.config = config # TODO(gcerami): fix credentials gathering dlrnapi_client.configuration.password = self.config.dlrnauth_password dlrnapi_client.configuration.username = self.config.dlrnauth_username api_client = dlrnapi_client.ApiClient(host=self.config.api_url) self.api_instance = dlrnapi_client.DefaultApi(api_client=api_client) self.last_promotions = {} # Variable to detect changes on the hash while we are running a # promotion self.named_hashes_map = {} # This way of preparing parameters and configuration is copied # directly from dlrnapi CLI and ansible module self.hashes_params = dlrnapi_client.PromotionQuery() self.jobs_params = dlrnapi_client.Params2() self.jobs_params_aggregate = dlrnapi_client.Params3() self.report_params = dlrnapi_client.Params3() self.promote_params = dlrnapi_client.Promotion() self.log.debug("Promoter DLRN client: API URL: {}, user: {}" "".format(api_client.host, self.config.dlrnauth_username))
def test_api_promotions_get(self): """Test case for api_promotions_get """ default_api = DefaultApi(api_client=self.api_client) params = dlrnapi_client.Promotion() path, method = default_api.api_promotions_get(params) self.assertEqual(path, '/api/promotions') self.assertEqual(method, 'GET')
def repo_promote(api_instance, options): params = dlrnapi_client.Promotion() # Promotion | The JSON params to post params.commit_hash = options.commit_hash params.distro_hash = options.distro_hash params.promote_name = options.promote_name try: api_response = api_instance.api_promote_post(params) return api_response except ApiException as e: raise e