コード例 #1
0
def ticket(deployment_id):
    deployment = Deployment.objects.get(id=deployment_id)
    issue_tracker = IssueTracker()
    if not deployment.issue_key:
        deployment.create_issue()
        # prevent other plugins to be executed until issue fires.
        return False
    if issue_tracker.deployment_accepted(deployment):
        deployment.set_status_and_sync(DeploymentStatus.in_progress.id)
        deployment.set_status_and_sync(DeploymentStatus.in_deployment.id)
        return True
    return False
コード例 #2
0
ファイル: ticket.py プロジェクト: pijany/ralph
def ticket(deployment_id):
    deployment = Deployment.objects.get(id=deployment_id)
    issue_tracker = IssueTracker()
    if not deployment.issue_key:
        deployment.create_issue()
        # prevent other plugins to be executed until issue fires.
        return False
    if issue_tracker.deployment_accepted(deployment):
        deployment.set_status_and_sync(DeploymentStatus.in_progress.id)
        deployment.set_status_and_sync(DeploymentStatus.in_deployment.id)
        return True
    return False
コード例 #3
0
ファイル: models_audits.py プロジェクト: szaydel/ralph
 def create_issue(self, params, default_assignee, retry_count=1):
     """
     We create 2 IssueTracker requests for IssueTracker here.
     1) Check if assignee exists in IssueTracker
     2) Create issue with back-link for acceptance
     """
     s = settings.ISSUETRACKERS['default']['OPA']
     template = s['TEMPLATE']
     issue_type = s['ISSUETYPE']
     tracker = IssueTracker()
     ci = None
     try:
         if params.get('ci_uid'):
             ci = CI.objects.get(uid=params.get('ci_uid'))
     except CI.DoesNotExist:
         pass
     if not tracker.user_exists(params.get('technical_assignee')):
         tuser = default_assignee
     else:
         tuser = params.get('technical_assignee')
     if not tracker.user_exists(params.get('business_assignee')):
         buser = default_assignee
     else:
         buser = params.get('business_assignee')
     issue = tracker.create_issue(
         issue_type=issue_type,
         description=params.get('description'),
         summary=params.get('summary'),
         ci=ci,
         assignee=default_assignee,
         technical_assignee=tuser,
         business_assignee=buser,
         start=self.created.isoformat(),
         end='',
         template=template,
     )
     self.issue_key = issue.get('key')
     self.save()
コード例 #4
0
ファイル: models_audits.py プロジェクト: 4i60r/ralph
 def create_issue(self, params, default_assignee, retry_count=1):
     """
     We create 2 IssueTracker requests for IssueTracker here.
     1) Check if assignee exists in IssueTracker
     2) Create issue with back-link for acceptance
     """
     s = settings.ISSUETRACKERS['default']['OPA']
     template = s['TEMPLATE']
     issue_type = s['ISSUETYPE']
     tracker = IssueTracker()
     ci = None
     try:
         if params.get('ci_uid'):
             ci = CI.objects.get(uid=params.get('ci_uid'))
     except CI.DoesNotExist:
         pass
     if not tracker.user_exists(params.get('technical_assignee')):
         tuser = default_assignee
     else:
         tuser = params.get('technical_assignee')
     if not tracker.user_exists(params.get('business_assignee')):
         buser = default_assignee
     else:
         buser = params.get('business_assignee')
     issue = tracker.create_issue(
         issue_type=issue_type,
         description=params.get('description'),
         summary=params.get('summary'),
         ci=ci,
         assignee=default_assignee,
         technical_assignee=tuser,
         business_assignee=buser,
         start=self.created.isoformat(),
         end='',
         template=template,
     )
     self.issue_key = issue.get('key')
     self.save()
コード例 #5
0
ファイル: models_signals.py プロジェクト: ReJeCtAll/ralph
def create_issue(change_id, retry_count=1):
    ch = chdb.CIChange.objects.get(id=change_id)
    if ch.registration_type == chdb.CI_CHANGE_REGISTRATION_TYPES.OP.id:
        logger.warning('Already registered change id=%d' % change_id)
        return

    user = ''
    summary = ch.message.split('\n')[0]
    if ch.type == chdb.CI_CHANGE_TYPES.CONF_GIT.id:
        user = get_login_from_user(ch.content_object.author)
        summary = 'Config Change: %s' % summary
        description = '''
        Changeset id: %(changeset)s
        Source: GIT
        Description: %(summary)s
        CMDB link: %(change_link)s
        Author: %(author)s

        ''' % (dict(
            changeset=ch.content_object.changeset,
            summary=ch.message,
            change_link=CHANGE_LINK % (ch.id),
            author=ch.content_object.author,
        ))

    elif ch.type == chdb.CI_CHANGE_TYPES.DEVICE.id:
        user = unicode(ch.content_object.user)
        summary = 'Asset attribute change: %s' % summary
        description = '''
        Attribute: %(attribute)s
        Old value: %(old_value)s
        New value: %(new_value)s
        Description: %(description)s
        CMDB link: %(cmdb_link)s
        Author: %(author)s

        ''' % (dict(
            attribute=ch.content_object.field_name,
            old_value=ch.content_object.old_value,
            new_value=ch.content_object.new_value,
            description=ch.content_object.comment,
            author=unicode(ch.content_object.user),
            cmdb_link=CHANGE_LINK % (ch.id),
        ))

    elif ch.type == chdb.CI_CHANGE_TYPES.CI.id:
        user = unicode(ch.content_object.user)
        summary = 'CMDB attribute change: %s' % summary
        description = '''
        Attribute: %(attribute)s
        Old value: %(old_value)s
        New value: %(new_value)s
        Description: %(description)s
        CMDB link: %(cmdb_link)s
        Author: %(author)s

        ''' % (dict(
            attribute=ch.content_object.field_name,
            old_value=ch.content_object.old_value,
            new_value=ch.content_object.new_value,
            description=ch.content_object.comment,
            author=unicode(ch.content_object.user),
            cmdb_link=CHANGE_LINK % (ch.id),
        ))
    if len(ch.message.split('\n')) > 1:
        description = '%s\n\n%s' % (ch.message, description)
    try:
        j = IssueTracker()
        if ch.ci:
            ci = ch.ci
        else:
            ci = None
        if not j.user_exists(user):
            user = DEFAULT_ASSIGNEE

        issue = j.create_issue(
            summary=summary,
            description=description,
            issue_type=OP_ISSUE_TYPE,
            ci=ci,
            assignee=user,
            template=OP_TEMPLATE,
            start=ch.created.isoformat(),
            end='',
            profile=OP_PROFILE,
        )
        ch = chdb.CIChange.objects.get(id=ch.id)
        # before save, check one more time
        if ch.registration_type == chdb.CI_CHANGE_REGISTRATION_TYPES.OP.id:
            logger.warning('Already registered change id=%d' % change_id)
            return
        ch.registration_type = chdb.CI_CHANGE_REGISTRATION_TYPES.OP.id
        ch.external_key = issue.get('key')
        ch.save()
    except IssueTrackerException as e:
        logger.warning(
            'Issue tracker exception for change: %d (%s)' % (change_id, e)
        )
コード例 #6
0
ファイル: models_audits.py プロジェクト: szaydel/ralph
 def transition_issue(self, transition_id, retry_count=1):
     tracker = IssueTracker()
     tracker.transition_issue(
         issue_key=self.issue_key,
         transition_id=transition_id,
     )
コード例 #7
0
ファイル: models_signals.py プロジェクト: pijany/ralph
def create_issue(change_id, retry_count=1):
    ch = chdb.CIChange.objects.get(id=change_id)
    if ch.registration_type == chdb.CI_CHANGE_REGISTRATION_TYPES.CHANGE.id:
        raise Exception('Already registered')

    user=''
    if ch.type == chdb.CI_CHANGE_TYPES.CONF_GIT.id:
        user = get_login_from_user(ch.content_object.author)
        summary = 'Config Change: %s' % ch.message
        description = '''
        Changeset id: %(changeset)s
        Source: GIT
        Description: %(summary)s
        CMDB link: %(change_link)s
        Author: %(author)s

        ''' % (dict(
            changeset=ch.content_object.changeset,
            summary=ch.message,
            change_link=ralph_change_link % (ch.id),
            author=ch.content_object.author,
        ))

    elif ch.type == chdb.CI_CHANGE_TYPES.DEVICE.id:
        user = unicode(ch.content_object.user)
        summary = 'Asset attribute change: %s' % ch.message
        description = '''
        Old value: %(old_value)s
        New value: %(new_value)s
        Description: %(description)s
        CMDB link: %(cmdb_link)s
        Author: %(author)s

        ''' % (dict(
            old_value=ch.content_object.old_value,
            new_value=ch.content_object.new_value,
            description=ch.content_object.comment,
            author=unicode(ch.content_object.user),
            cmdb_link=ralph_change_link % (ch.id),
        ))

    elif ch.type == chdb.CI_CHANGE_TYPES.CI.id:
        user = unicode(ch.content_object.user)
        summary = 'CMDB attribute change: %s' % ch.message
        description = '''
        Old value: %(old_value)s
        New value: %(new_value)s
        Description: %(description)s
        CMDB link: %(cmdb_link)s
        Author: %(author)s
        ''' % (dict(
            old_value=ch.content_object.old_value,
            new_value=ch.content_object.new_value,
            description=ch.content_object.comment,
            author=unicode(ch.content_object.user),
            cmdb_link=ralph_change_link % (ch.id),
        ))
    try:
        j = IssueTracker()
        if ch.ci:
            ci = ch.ci
        else:
            ci = None
        if not j.user_exists(user):
            user = default_assignee

        issue = j.create_issue(
                description=description,
                summary=summary,
                ci=ci,
                assignee=user,
                start=ch.created.isoformat(),
                end='',
                template=op_template,
        )
        ch.registration_type = chdb.CI_CHANGE_REGISTRATION_TYPES.CHANGE.id
        ch.external_key = issue.get('key')
        ch.save()
    except IssueTrackerException as e:
        raise create_issue.retry(exc=e, args=[change_id,
            retry_count + 1], countdown=60 * (2 ** retry_count),
            max_retries=15) # 22 days
コード例 #8
0
def create_issue(change_id, retry_count=1):
    ch = chdb.CIChange.objects.get(id=change_id)
    if ch.registration_type == chdb.CI_CHANGE_REGISTRATION_TYPES.OP.id:
        logger.warning('Already registered change id=%d' % change_id)
        return

    user = ''
    summary = ch.message.split('\n')[0]
    if ch.type == chdb.CI_CHANGE_TYPES.CONF_GIT.id:
        user = get_login_from_user(ch.content_object.author)
        summary = 'Config Change: %s' % summary
        description = '''
        Changeset id: %(changeset)s
        Source: GIT
        Description: %(summary)s
        CMDB link: %(change_link)s
        Author: %(author)s

        ''' % (dict(
            changeset=ch.content_object.changeset,
            summary=ch.message,
            change_link=CHANGE_LINK % (ch.id),
            author=ch.content_object.author,
        ))

    elif ch.type == chdb.CI_CHANGE_TYPES.DEVICE.id:
        user = unicode(ch.content_object.user)
        summary = 'Asset attribute change: %s' % summary
        description = '''
        Attribute: %(attribute)s
        Old value: %(old_value)s
        New value: %(new_value)s
        Description: %(description)s
        CMDB link: %(cmdb_link)s
        Author: %(author)s

        ''' % (dict(
            attribute=ch.content_object.field_name,
            old_value=ch.content_object.old_value,
            new_value=ch.content_object.new_value,
            description=ch.content_object.comment,
            author=unicode(ch.content_object.user),
            cmdb_link=CHANGE_LINK % (ch.id),
        ))

    elif ch.type == chdb.CI_CHANGE_TYPES.CI.id:
        user = unicode(ch.content_object.user)
        summary = 'CMDB attribute change: %s' % summary
        description = '''
        Attribute: %(attribute)s
        Old value: %(old_value)s
        New value: %(new_value)s
        Description: %(description)s
        CMDB link: %(cmdb_link)s
        Author: %(author)s

        ''' % (dict(
            attribute=ch.content_object.field_name,
            old_value=ch.content_object.old_value,
            new_value=ch.content_object.new_value,
            description=ch.content_object.comment,
            author=unicode(ch.content_object.user),
            cmdb_link=CHANGE_LINK % (ch.id),
        ))
    if len(ch.message.split('\n')) > 1:
        description = '%s\n\n%s' % (ch.message, description)
    try:
        j = IssueTracker()
        if ch.ci:
            ci = ch.ci
        else:
            ci = None
        if not j.user_exists(user):
            user = DEFAULT_ASSIGNEE

        issue = j.create_issue(
            summary=summary,
            description=description,
            issue_type=OP_ISSUE_TYPE,
            ci=ci,
            assignee=user,
            template=OP_TEMPLATE,
            start=ch.created.isoformat(),
            end='',
            profile=OP_PROFILE,
        )
        ch = chdb.CIChange.objects.get(id=ch.id)
        # before save, check one more time
        if ch.registration_type == chdb.CI_CHANGE_REGISTRATION_TYPES.OP.id:
            logger.warning('Already registered change id=%d' % change_id)
            return
        ch.registration_type = chdb.CI_CHANGE_REGISTRATION_TYPES.OP.id
        ch.external_key = issue.get('key')
        ch.save()
    except IssueTrackerException as e:
        logger.warning(
            'Issue tracker exception for change: %d (%s)' % (change_id, e)
        )
コード例 #9
0
def create_issue(change_id, retry_count=1):
    ch = chdb.CIChange.objects.get(id=change_id)
    if ch.registration_type == chdb.CI_CHANGE_REGISTRATION_TYPES.CHANGE.id:
        raise Exception('Already registered')

    user = ''
    if ch.type == chdb.CI_CHANGE_TYPES.CONF_GIT.id:
        user = get_login_from_user(ch.content_object.author)
        summary = 'Config Change: %s' % ch.message
        description = '''
        Changeset id: %(changeset)s
        Source: GIT
        Description: %(summary)s
        CMDB link: %(change_link)s
        Author: %(author)s

        ''' % (dict(
            changeset=ch.content_object.changeset,
            summary=ch.message,
            change_link=ralph_change_link % (ch.id),
            author=ch.content_object.author,
        ))

    elif ch.type == chdb.CI_CHANGE_TYPES.DEVICE.id:
        user = unicode(ch.content_object.user)
        summary = 'Asset attribute change: %s' % ch.message
        description = '''
        Old value: %(old_value)s
        New value: %(new_value)s
        Description: %(description)s
        CMDB link: %(cmdb_link)s
        Author: %(author)s

        ''' % (dict(
            old_value=ch.content_object.old_value,
            new_value=ch.content_object.new_value,
            description=ch.content_object.comment,
            author=unicode(ch.content_object.user),
            cmdb_link=ralph_change_link % (ch.id),
        ))

    elif ch.type == chdb.CI_CHANGE_TYPES.CI.id:
        user = unicode(ch.content_object.user)
        summary = 'CMDB attribute change: %s' % ch.message
        description = '''
        Old value: %(old_value)s
        New value: %(new_value)s
        Description: %(description)s
        CMDB link: %(cmdb_link)s
        Author: %(author)s
        ''' % (dict(
            old_value=ch.content_object.old_value,
            new_value=ch.content_object.new_value,
            description=ch.content_object.comment,
            author=unicode(ch.content_object.user),
            cmdb_link=ralph_change_link % (ch.id),
        ))
    try:
        j = IssueTracker()
        if ch.ci:
            ci = ch.ci
        else:
            ci = None
        if not j.user_exists(user):
            user = default_assignee

        issue = j.create_issue(
            summary=summary,
            description=description,
            issue_type=op_issue_type,
            ci=ci,
            assignee=user,
            template=op_template,
            start=ch.created.isoformat(),
            end='',
        )
        ch.registration_type = chdb.CI_CHANGE_REGISTRATION_TYPES.CHANGE.id
        ch.external_key = issue.get('key')
        ch.save()
    except IssueTrackerException as e:
        raise create_issue.retry(exc=e,
                                 args=[change_id, retry_count + 1],
                                 countdown=60 * (2**retry_count),
                                 max_retries=15)  # 22 days
コード例 #10
0
ファイル: models_audits.py プロジェクト: 4i60r/ralph
 def transition_issue(self, transition_id, retry_count=1):
     tracker = IssueTracker()
     tracker.transition_issue(
         issue_key=self.issue_key,
         transition_id=transition_id,
     )