Ejemplo n.º 1
0
def get_failing_jobs_html(dlrn_hashes, release_name):
    failing_jobs_html = ""

    # If any of the jobs is still in progress
    in_progress = False

    try:
        dlrn = get_dlrn_instance_for_release(release_name)
        if dlrn:
            params = dlrnapi_client.Params2()
            params.commit_hash = dlrn_hashes['commit_hash']
            params.distro_hash = dlrn_hashes['distro_hash']
            params.success = str(False)

            failing_jobs = dlrn.api_repo_status_get(params)
            for i, failing_job in enumerate(failing_jobs):
                if failing_job.in_progress:
                    in_progress = True
                failing_job_ln = "<a href='{}' target='_blank' >{}</a>".format(
                    failing_job.url, failing_job.job_id)

                if i > 0:
                    failing_job_ln += "<br>"
                failing_jobs_html += failing_job_ln

    except Exception as e:
        print(e)
        pass
    return (in_progress, failing_jobs_html)
Ejemplo n.º 2
0
def get_failing_jobs_html(dlrn_hashes, release_name):
    failing_jobs_html = ""

    # If any of the jobs is still in progress
    in_progress = False

    try:
        dlrn = get_dlrn_instance_for_release(release_name)
        if dlrn:
            params = dlrnapi_client.Params2()
            params.commit_hash = dlrn_hashes['commit_hash']
            params.distro_hash = dlrn_hashes['distro_hash']
            params.success = str(False)

            failing_jobs = dlrn.api_repo_status_get(params)
            if len(failing_jobs) > 0:
                for i, failing_job in enumerate(failing_jobs):
                    if failing_job.in_progress:
                        in_progress = True
                    failing_job_ln = html_link.format(failing_job.url,
                                                      failing_job.job_id)

                    if i > 0:
                        failing_job_ln += "<br>"
                    failing_jobs_html += failing_job_ln
            else:
                failing_jobs_html = ("<font color='red'>WARNING</font> "
                                     "expected perodic jobs have not run")

    except Exception as e:
        print(e)
        pass
    return (in_progress, failing_jobs_html)
Ejemplo n.º 3
0
    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))
Ejemplo n.º 4
0
 def test_api_repo_status_get(self):
     """Test case for api_repo_status_get """
     default_api = DefaultApi(api_client=self.api_client)
     params = dlrnapi_client.Params2()
     path, method = default_api.api_repo_status_get(params)
     self.assertEqual(path, '/api/repo_status')
     self.assertEqual(method, 'GET')
Ejemplo n.º 5
0
def check_trigger_condition(dlrn, promotion_name, wait_job_name,
                            launch_job_name):
    """
    Check if launch job has to run looking for the wait job at the latest
    DLRN promotion, the wait job has to be at success state.

    This just look at latest promotion and also don't retrigger if the
    launch_job state is not success.

    This uses to calls to the dlrnapi_client.DefaultApi:
        - api_promotions_get to get the newest  'Promotion'
        - api_repo_status_get to get the jobs from the 'Promotion'

    Parameters
    ----------
    dlrn : dlrnapi_client.DefaultApi
        The dlrn api impl to look for promotions and repo status
    promotion_name: str
        The promotion name to use, tripleo-ci-testing for example
    wait_job_name: str
        Name of the job that have to finish with success state to for
        the trigger condition to be True
    launch_job_name: str
        Name of the job that we want to trigger.

    Returns
    -------
    bool
        It will be True if the launch_job_name has to be triggered false
        otherwise
    """
    logger = logging.getLogger("dlrn-trigger")
    params = dlrnapi_client.PromotionQuery()
    params.promote_name = promotion_name
    api_response = dlrn.api_promotions_get(params)
    last_promotion = api_response[0]
    logger.debug("Selected promotion: {}".format(last_promotion))
    params = dlrnapi_client.Params2()
    params.distro_hash = last_promotion.distro_hash
    params.commit_hash = last_promotion.commit_hash
    api_response = dlrn.api_repo_status_get(params)
    logger.debug("CI status from promotion: {}".format(api_response))
    wait_job = None
    launch_job = None
    # Select the first ocurrence of wait and launch job
    for status in api_response:
        if wait_job is None and status.job_id == wait_job_name:
            wait_job = status
        elif launch_job is None and status.job_id == launch_job_name:
            launch_job = status
    logger.info("Selected wait job build: {}".format(wait_job))
    logger.info("Selected launch job build: {}".format(launch_job))
    # Trigger if job is not already trigger and wait job is fine
    return launch_job is None and wait_job is not None and wait_job.success
Ejemplo n.º 6
0
def repo_status(api_instance, options):
    params = dlrnapi_client.Params2()  # Params2 | The JSON params to post
    params.commit_hash = options.commit_hash
    params.distro_hash = options.distro_hash
    if options.success:
        params.success = str(options.success)

    try:
        api_response = api_instance.api_repo_status_get(params)
        return api_response
    except ApiException as e:
        raise e
Ejemplo n.º 7
0
def fetch_jobs(dlrn, hash_values):
    '''Fetch the successfully finished jobs for a specific DLRN hash'''
    logger = logging.getLogger('promoter')
    params = dlrnapi_client.Params2()
    params.commit_hash = hash_values['commit_hash']
    params.distro_hash = hash_values['distro_hash']
    params.success = str(True)

    try:
        api_response = dlrn.api_repo_status_get(params)
    except ApiException:
        logger.error('Exception when calling api_repo_status_get: %s',
                     ApiException)
        raise
    logger.debug('Successful jobs for %s:', hash_values)
    for result in api_response:
        logger.debug('%s at %s, logs at %s', result.job_id,
                     datetime.fromtimestamp(result.timestamp).isoformat(),
                     result.url)
    return [details.job_id for details in api_response]