Beispiel #1
0
 def testVersion(self):
     # bugzilla.mozilla.org returns version values in YYYY-MM-DD
     # format, so just try to confirm that
     bz = Bugzilla("bugzilla.mozilla.org", use_creds=False)
     self.assertEquals(bz.__class__, Bugzilla)
     self.assertTrue(bz.bz_ver_major >= 2016)
     self.assertTrue(bz.bz_ver_minor in range(1, 13))
Beispiel #2
0
 def _testBZVersion(self):
     bz = Bugzilla(self.url, use_creds=False)
     assert bz.__class__ == self.bzclass
     if tests.CLICONFIG.REDHAT_URL:
         return
     assert bz.bz_ver_major == self.bzversion[0]
     assert bz.bz_ver_minor == self.bzversion[1]
 def testURLQuery(self):
     # This is a bugzilla 5.0 instance, which supports URL queries now
     query_url = ("https://bugs.gentoo.org/buglist.cgi?"
         "component=[CS]&product=Doc%20Translations"
         "&query_format=advanced&resolution=FIXED")
     bz = Bugzilla(url=self.url, use_creds=False)
     ret = bz.query(bz.url_to_query(query_url))
     assert len(ret) > 0
Beispiel #4
0
 def _testBZVersion(self):
     bz = Bugzilla(self.url, use_creds=False)
     self.assertEquals(bz.__class__, self.bzclass)
     if tests.REDHAT_URL:
         print("BZ version=%s.%s" % (bz.bz_ver_major, bz.bz_ver_minor))
     else:
         self.assertEquals(bz.bz_ver_major, self.bzversion[0])
         self.assertEquals(bz.bz_ver_minor, self.bzversion[1])
Beispiel #5
0
 def request(self, extra_fields={}):
     if not self._request:
         self._request = Bugzilla(url=None).url_to_query(self.url)
         self._request.update(extra_fields)
         self._request.update({
             'include_fields': Constants.INCLUDE_FIELDS,
         })
     return self._request
Beispiel #6
0
def _get_bugzilla_history(email, all_comments=False):
    """ Query the bugzilla for all bugs to which the provided email
    is either assigned or cc'ed. Then for each bug found, print the
    latest comment from this user (if any).

    :arg email, the email address used in the bugzilla and for which we
    are searching for activities.
    :arg all_comments, boolean to display all the comments made by this
    person on the bugzilla.
    """
    from bugzilla import Bugzilla
    bzclient = Bugzilla(url='https://bugzilla.redhat.com/xmlrpc.cgi')

    log.debug('Querying bugzilla for email: {0}'.format(email))

    print("Bugzilla activity")
    bugbz = bzclient.query({
        'emailtype1': 'substring',
        'emailcc1': True,
        'emailassigned_to1': True,
        'query_format': 'advanced',
        'order': 'Last Change',
        'bug_status': ['ASSIGNED', 'NEW', 'NEEDINFO'],
        'email1': email
    })
    print('   {0} bugs assigned, cc or on which {1} commented'.format(
        len(bugbz), email))
    # Retrieve the information about this user
    user = bzclient.getuser(email)
    bugbz.reverse()

    print('Last comment on the most recent ticket on bugzilla:')
    ids = [bug.bug_id for bug in bugbz]
    for bug in bzclient.getbugs(ids):
        log.debug(bug.bug_id)
        user_coms = [
            com
            for com in bug.longdescs
            if com['creator_id'] == user.userid
        ]

        if user_coms:
            last_com = user_coms[-1]
            converted = datetime.datetime.strptime(last_com['time'].value,
                                                   "%Y%m%dT%H:%M:%S")
            print(
                u'   #{0} {1} {2}'.format(
                    bug.bug_id,
                    converted.strftime('%Y-%m-%d'),
                    last_com['creator']
                )
            )

        else:
            continue

            if not all_comments:
                break
Beispiel #7
0
    def clicomm(self, argstr, expectexc=False, bz=None):
        comm = "bugzilla " + argstr

        if not bz:
            bz = Bugzilla(url=self.url, use_creds=False)
        if expectexc:
            self.assertRaises(Exception, tests.clicomm, comm, bz)
        else:
            return tests.clicomm(comm, bz)
Beispiel #8
0
def get_bugzilla(parse):
    print "INFO - Connecting to bugzilla"
    try:
        bzusername = parse.get("bugzilla", "username")
        bzpassword = parse.get("bugzilla", "password")
        bzrpcurl = parse.get("bugzilla", "rpcurl")
        return Bugzilla(url=bzrpcurl, user=bzusername, password=bzpassword)
    except Exception as details:
        print "Error - get bugzilla connection failed: %s" % details
 def testURLQuery(self):
     # This instance is old and doesn't support URL queries, we are
     # just verifying our extra error message report
     query_url = ("https://bugzilla.gnome.org/buglist.cgi?"
         "bug_status=RESOLVED&order=Importance&product=accerciser"
         "&query_format=advanced&resolution=NOTABUG")
     bz = Bugzilla(url=self.url, use_creds=False)
     try:
         bz.query(bz.url_to_query(query_url))
     except BugzillaError as e:
         assert "derived from bugzilla" in str(e)
Beispiel #10
0
def get_security_bugs():
    bz = Bugzilla(url='https://bugzilla.redhat.com/xmlrpc.cgi')
    query_data = {
        'keywords': 'SecurityTracking',
        'keywords_type': 'allwords',
        # 'component': 'cacti',
        # 'severity': 'high',
        'status': VALID_STATUSES,
    }
    bugs = bz.query(query_data)
    return bugs
Beispiel #11
0
 def __init__(self, email, widget_id=None):
     self.widget_id = widget_id
     bugzilla = Bugzilla(url='https://bugzilla.redhat.com/xmlrpc.cgi')
     # pylint: disable-msg=E1101
     # :E1101: Bugzilla class monkey patches itself with methods like
     # query.
     self.bugs = bugzilla.query({
         'product': 'Fedora',
         'email1': email,
         'emailassigned_to1': True
     })[:5]
 def testVersion(self):
     # bugzilla.mozilla.org returns version values in YYYY-MM-DD
     # format, so just try to confirm that
     try:
         bz = Bugzilla("bugzilla.mozilla.org", use_creds=False)
         assert bz.__class__ == Bugzilla
         assert bz.bz_ver_major >= 2016
         assert bz.bz_ver_minor in range(1, 13)
     except Exception as e:
         # travis environment throws SSL errors here
         # https://travis-ci.org/python-bugzilla/python-bugzilla/builds/304713566
         if "EOF occurred" not in str(e):
             raise
         self.skipTest("travis environment SSL error hit: %s" % str(e))
Beispiel #13
0
def check_bugzilla(url):
	global bz

	if not url.startswith("https://bugzilla.novell.com"):
		return
	try:
		if bz == None:
			bz = Bugzilla(url="https://bugzilla.novell.com/xmlrpc.cgi", cookiefile=None)
		bug_id = url[url.find("id=")+3::]
		bug = bz._getbug(int(bug_id))
		bug_desc = bug['short_desc']
	except Exception as e:
		bug_desc = e
	print_item(4*" ", "(%s)" % bug_desc)
Beispiel #14
0
def get_bugs(package_name):
    bugzilla_client = Bugzilla(url=URL, cookiefile=None, tokenfile=None)

    bugs = _open_bugs(bugzilla_client, package_name)
    blocker_bugs_results = blocker_bugs(bugs)
    results = {
        'bugs': [],
        'open_bugs': len(bugs),
        'blocker_bugs': len(blocker_bugs_results),
    }
    # Generate the URL for the blocker bugs
    url_args = [
        ('classification', 'Fedora'),
        ('query_format', 'advanced'),
        ('component', package_name),
    ]
    for product in PRODUCTS:
        url_args.append(('product', product))
    for status in OPEN_BUG_STATUS:
        url_args.append(('bug_status', status))

    results['open_bugs_url'] = "https://bugzilla.redhat.com/buglist.cgi?" + \
                               urllib.parse.urlencode(url_args)
    url_args += [
        ('f1', 'blocked'),
        ('o1', 'anywordssubstr'),
        ('v1', ' '.join(map(str, blocker_bugs_results))),
    ]
    results['blocker_bugs_url'] = \
        "https://bugzilla.redhat.com/buglist.cgi?" + \
        urllib.parse.urlencode(url_args)
    for fb in bugs:
        bug_version = fb.version
        if isinstance(bug_version, (list, tuple)):
            bug_version = bug_version[0]
        results['bugs'].append({
            'id':
            fb.bug_id,
            'status':
            fb.bug_status.title(),
            'summary':
            fb.summary,
            'release':
            '{} {}'.format(fb.product, bug_version),
            'version_sort':
            _version_to_int(fb.version),
            'status_sort':
            _status_to_index(fb.bug_status),
        })
    return results
Beispiel #15
0
def _get_bz(url=pkgdb2client.BZ_URL, insecure=False):
    ''' Return a bugzilla object. '''
    global BZCLIENT
    if not BZCLIENT or BZCLIENT.url != url:
        BZCLIENT = Bugzilla(url=url)

    BZCLIENT._sslverify = not insecure

    try:
        BZCLIENT.logged_in
    except xmlrpclib.Error:
        bz_login()

    return BZCLIENT
Beispiel #16
0
def _get_bz(url=RH_BZ_API, insecure=False):
    ''' Return a bugzilla object. '''
    global BZCLIENT
    if not BZCLIENT:
        BZCLIENT = Bugzilla(url=url)
    elif BZCLIENT.url != url:
        BZCLIENT.url = url

    BZCLIENT._sslverify = not insecure

    try:
        BZCLIENT.logged_in
    except xmlrpclib.Error:
        bz_login()

    return BZCLIENT
    def testFaults(self):
        # Test special error wrappers in bugzilla/_cli.py
        bzinstance = Bugzilla(self.url, use_creds=False)
        out = tests.clicomm("bugzilla query --field=IDONTEXIST=FOO",
            bzinstance, expectfail=True)
        assert "Server error:" in out

        out = tests.clicomm("bugzilla "
            "--bugzilla https://example.com/xmlrpc.cgi "
            "query --field=IDONTEXIST=FOO", None, expectfail=True)
        assert "Connection lost/failed" in out

        out = tests.clicomm("bugzilla "
            "--bugzilla https://expired.badssl.com/ "
            "query --bug_id 1234", None, expectfail=True)
        assert "trust the remote server" in out
        assert "--nosslverify" in out
Beispiel #18
0
    def __init__(self, bug, user=None, password=None):
        """ Constructor.
        :arg bug, the bug number on bugzilla
        :kwarg user, the username with which to log in in bugzilla.
        :kwarg password, the password associated with this account.
        """
        AbstractBug.__init__(self)
        self.check_options()
        self.bug_num = bug
        bz_url = os.path.join(Settings.current_bz_url, 'xmlrpc.cgi')
        self.bugzilla = Bugzilla(url=bz_url)

        self.log.info("Trying bugzilla cookies for authentication")
        self.user = user
        self.bug = self.bugzilla.getbug(self.bug_num)
        if Settings.login:
            self.login(Settings.user)
        if Settings.assign:
            self.assign_bug()
Beispiel #19
0
def get_bz():  # pragma: no cover
    '''Retrieve a connection to bugzilla

    :raises xmlrpclib.ProtocolError: If we're unable to contact bugzilla
    '''
    global _BUGZILLA
    if _BUGZILLA:  # pragma: no cover
        return _BUGZILLA

    # Get a connection to bugzilla
    bz_server = pkgdb2.APP.config['PKGDB2_BUGZILLA_URL']
    if not bz_server:
        raise pkgdb2.lib.PkgdbException('No PKGDB2_BUGZILLA_URL configured')
    bz_url = bz_server + '/xmlrpc.cgi'
    bz_user = pkgdb2.APP.config['PKGDB2_BUGZILLA_USER']
    bz_pass = pkgdb2.APP.config['PKGDB2_BUGZILLA_PASSWORD']

    _BUGZILLA = Bugzilla(url=bz_url, user=bz_user, password=bz_pass,
                         cookiefile=None, tokenfile=None)
    return _BUGZILLA
Beispiel #20
0
 def __init__(self,
              bug,
              user=None,
              password=None,
              cache=False,
              nobuild=False):
     Helpers.__init__(self, cache, nobuild)
     self.bug_num = bug
     self.spec_url = None
     self.srpm_url = None
     self.spec_file = None
     self.srpm_file = None
     self.bugzilla = Bugzilla(url=BZ_URL)
     self.is_login = False
     if user and password:
         rc = self.bugzilla.login(user=user, password=password)
         if rc > 0:
             self.is_login = True
     self.user = user
     self.bug = self.bugzilla.getbug(self.bug_num)
     self.log = get_logger()
Beispiel #21
0
def selftest(data, user='', password=''):
    print "Using bugzilla at " + data['url']
    bz = Bugzilla(url=data['url'])
    print "Bugzilla class: %s" % bz.__class__
    if not bz.logged_in:
        if user and password:
            bz.login(user, password)
    if bz.logged_in:
        print "Logged in to bugzilla OK."
    else:
        print "Not logged in - create a .bugzillarc or provide user/password"
        # FIXME: only run some tests if .logged_in

    print "Reading product list"
    prod = bz.getproducts()
    prodlist = [p['name'] for p in prod]
    print "Products found: %s, %s, %s...(%i more)" % \
        (prodlist[0],prodlist[1],prodlist[2],len(prodlist)-3)

    p = data['query']['product']
    assert p in prodlist
    print "Getting component list for %s" % p
    comp = bz.getcomponents(p)
    print "%i components found" % len(comp)

    print "Reading public bug (#%i)" % data['public_bug']
    print bz.getbugsimple(data['public_bug'])
    print

    print "Reading private bug (#%i)" % data['private_bug']
    try:
        print bz.getbugsimple(data['private_bug'])
    except xmlrpclib.Fault, e:
        if 'NotPermitted' in e.faultString:
            print "Failed: Not authorized."
        else:
            print "Failed: Unknown XMLRPC error: %s" % e
Beispiel #22
0
def main():
    parser = argparse.ArgumentParser(description='pull all bugs from a '
                                     'bugzilla project')

    args = parser.parse_args()

    bz = Bugzilla(url=BZURL)

    counter = 0

    f = open('bugs-refresh.json', 'w')
    f.write('{"date": "%s", "bugs": [' % datetime.datetime.now())

    bzq = bz.build_query(product=LPPROJECT, status=BZSTATUS)
    bugs = bz.query(bzq)
    for task in bugs:
        try:
            if counter != 0:
                bug_data = ','
            else:
                bug_data = u""
            title = task.summary.replace('"', "'")
            title = title.replace("\n", "")
            title = title.replace("\t", "")
            bug_data += (
                '{"index": %d, "id": %d, "importance": "%s", '
                '"status": "%s", '
                '"owner": "%s", '
                '"title": "%s", '
                '"link": "%s", '
                '"component": "%s"' %
                (counter, task.id, getBugPriority(task), getBugStatus(task),
                 task.assigned_to, title.encode(
                     'ascii', 'ignore'), task.weburl, task.component))

        except (TypeError, UnicodeEncodeError):
            # TODO: fix this
            print 'Error on bug %d', task.id
            counter += 1
            continue

        age = delta(
            datetime.datetime.strptime("%s" % task.creation_time,
                                       "%Y%m%dT%H:%M:%S"))
        updated = delta(
            datetime.datetime.strptime("%s" % task.last_change_time,
                                       "%Y%m%dT%H:%M:%S"))
        stale = False
        if updated > 30 and age > 30:
            if task.status == 'ASSIGNED':
                stale = True
        bug_data += (',"age": %d, "update": %d, "stale": %d, '
                     '"never_touched": %d' %
                     (age, updated, 1 if stale else 0,
                      1 if len(task.comments) == 1 else 0))

        i = 0
        bug_data += (',"projects": [')
        bug_data += '{"target": "%s", "status": "%s"}' % (task.target_release,
                                                          task.status)
        bug_data += ('] ,"reviews": [')

        i = 0
        for review in get_reviews_from_bug(task):
            review_status = get_review_status(review)
            if i != 0:
                bug_data += (",")
            i += 1
            review_status = review_status.replace("\n", "")
            bug_data += ('{"review": '
                         '"%s/%s",'
                         '"status": "%s"}' %
                         (GERRIT_URL, review, review_status))
        bug_data += (']}')

        try:
            if counter == 0:
                json.loads(bug_data)
            else:
                json.loads(bug_data[1:])
            f.write(bug_data)
        except (ValueError, UnicodeEncodeError), e:
            print e, '[Bug: %s]' % task.id

        counter += 1
Beispiel #23
0
 def _bugzilla(self):
     return Bugzilla(url=self._base_url, cookiefile=None, tokenfile=None)
Beispiel #24
0
parser = argparse.ArgumentParser(
    description='check that a candlepin PR references the correct BZ')
parser.add_argument('pr', help='the pr number to examine')
args = parser.parse_args()

# fetch pr
pr = requests.get(
    'https://api.github.com/repos/candlepin/candlepin/pulls/{pr}'.format(
        pr=args.pr),
    headers={
        'Authorization': 'token {}'.format(github_token)
    }).json()
target = pr['base']['ref']

bz = Bugzilla(bugzilla_url, user=bugzilla_user, password=bugzilla_password)

master_version = None


def fetch_master_version():
    global master_version
    if master_version:
        return master_version
    spec_file = requests.get(
        'https://raw.githubusercontent.com/candlepin/candlepin/master/candlepin.spec.tmpl'
    ).text
    for line in spec_file.split('\n'):
        if line.startswith('Version:'):
            match = re.search('^Version: (\d+\.\d+)\.\d+$', line)
            version = match.group(1)
    elif options.start_date and options.end_date:
        start = getDateTime(options.start_date)
        end = getDateTime(options.end_date)
        difference = end - start
        print "Report for ", difference.days, " days."

    url = "https://bugzilla.redhat.com/xmlrpc.cgi"
    query_dict = {
        "product": "Fedora",
        "component": "Package Review",
        "chfieldfrom": str(start),
        "field0-0-0": "flagtypes.name",
        "type0-0-0": "equals"
    }

    bz = Bugzilla(url=url, user=username, password=passwd)
    if verbose:
        print "Getting all package review bugs (be patient, this may take a while) ...."

    bug_list_query = {}
    flag = None

    if report == "new":
        flag = "new"
        bug_list_query = {"bug_status": "NEW"}
    elif report == "rev-com":
        flag = "fedora-review+"
        bug_list_query = {"value0-0-0": "fedora-review+"}
    elif report == "rev-incom":
        flag = "fedora-review?"
        bug_list_query = {"value0-0-0": "fedora-review?"}
Beispiel #26
0
 def test2(self):
     bz = Bugzilla(url=self.url, use_creds=False)
     assert bz.__class__ is self.bzclass
Beispiel #27
0
    # only keep the GlusterFS product BZs
    bzs = [b for b in bzs if b.product == 'GlusterFS']

    if not bzs:
        return list()

    # a tracker can be blocked by other trackers
    addBugs = list()
    addBugs.extend(bzs)
    for b in bzs:
        addBugs.extend(getByTracker(bz, '%d' % b.id))

    return addBugs


bz = Bugzilla(url=BZ_URL)
bzs = getOpenBugs(bz)
#bzs = [bz.getbug(765051)]
#bzs = [bz.getbug(841617)]
#bzs = getByTracker(bz, 'glusterfs-3.7.0')

bugs = list()

for bug in bzs:
    if 'Tracking' in bug.keywords:
        continue
    elif bug.component in BZ_COMPONENT_BLACKLIST:
        continue

    verbose(u'checking Bug %s' % bug)
    bs = BugStatus(bug)
Beispiel #28
0
def createbug(filename,
              arch,
              mock=False,
              path='/etc/ksc.conf',
              releasename='7.0',
              module=None):
    """
    Opens a bug in the Bugzilla
    """

    if releasename.startswith('6.'):
        bughash = {'product': 'Red Hat Enterprise Linux 6'}
    elif releasename.startswith('7.'):
        bughash = {'product': 'Red Hat Enterprise Linux 7'}
    elif releasename.startswith('8.'):
        bughash = {'product': 'Red Hat Enterprise Linux 8'}
    elif releasename.startswith('9.'):
        bughash = {'product': 'Red Hat Enterprise Linux 9'}
    else:
        print("Invalid releasename: Bug not created")
        return
    bughash["component"] = 'kernel'
    bughash["summary"] = "kABI Symbol Usage"
    bughash["version"] = releasename
    bughash["platform"] = arch
    bughash["severity"] = "medium"
    bughash["priority"] = "medium"
    bughash["description"] = "Creating the bug to attach the symbol " + \
                             "usage details."
    bughash["qa_contact"] = "*****@*****.**"
    groups = []

    if module:
        bughash["summary"] += " ({})".format(str(module))

    # We change the path if only it is mock
    if mock:
        print("Using local config file data/ksc.conf")
        path = './data/ksc.conf'

    try:
        conf = getconfig(path, mock=mock)
    except Exception as err:
        print("Problem in parsing the configuration.")
        print(err)
        return

    if not conf:
        return
    if 'group' in conf:
        if conf['group'] != 'partner-group':
            groups.append(conf['group'])

    groups = list(filter(lambda x: len(x) > 0, groups))
    if not groups:
        print("Error: Please specify a non-empty partner-group config " +\
              "option in your ksc.conf config file or in the prompt above. " +\
              "Bug was not filed!")
        return

    bughash["groups"] = groups

    if 'api_key' in conf and conf['api_key'] != 'api_key':
        bughash["Bugzilla_api_key"] = conf["api_key"]
    else:
        bughash["Bugzilla_login"] = conf["user"]
        bughash["Bugzilla_password"] = conf["password"]
    bughash["cf_partner"] = [
        conf["partner"],
    ]
    bughash["keywords"] = ["Tracking"]

    try:
        if 'api_key' in conf and conf['api_key'] != 'api_key':
            bz = Bugzilla(url=conf['server'], api_key=conf["api_key"])
        else:
            bz = Bugzilla(url=conf['server'],
                          user=conf["user"],
                          password=conf["password"])
    except BugzillaError as err:
        print("Bug not submitted. %s" % err)
        if not mock:
            sys.exit(1)

    if not mock:  # pragma: no cover
        print("Creating a new bug")

    bughash["sub_component"] = 'kabi-stablelists'

    # As it is as yet unclear whether the new sub_component will be
    # set up at the time of deployment, attemp to file with the old
    # sub_component as well.
    # If kabi-stablelists does not exist, an attempt to createbug
    # will cause an xmlrpc.client.Fault exception.
    try:
        trycreatebug(filename, mock, bughash, conf, bz)
    except Exception as err:  # pragma: no cover
        try:
            bughash["sub_component"] = 'kabi-whitelists'
            trycreatebug(filename, mock, bughash, conf, bz)
        except Exception as err:  # pragma: no cover
            print("Could not create bug. %s" % err)
            if not mock:
                sys.exit(1)
Beispiel #29
0
def get_bzapi():
    """ Return a logged-in RHBZ API instance """
    bzapi = Bugzilla('bugzilla.redhat.com')
    if not bzapi.logged_in:
        raise SystemExit('Not logged into BZ')
    return bzapi
Beispiel #30
0
import requests
import fedora_cert

from bugzilla import Bugzilla
from fedora.client import AccountSystem, AuthError

import pkgdb2client

try:
    USERNAME = fedora_cert.read_user_cert()
except fedora_cert.fedora_cert_error:
    pkgdb2client.LOG.debug('Could not read Fedora cert, asking for username')
    USERNAME = None

RH_BZ_API = 'https://bugzilla.redhat.com/xmlrpc.cgi'
BZCLIENT = Bugzilla(url=RH_BZ_API)
FASCLIENT = AccountSystem(
    'https://admin.fedoraproject.org/accounts',
    username=USERNAME)


def bz_login():
    ''' Login on bugzilla. '''
    print 'To keep going, we need to authenticate against bugzilla' \
        ' at {0}'.format(RH_BZ_API)
    username = raw_input("Bugzilla user: "******"Bugzilla password: ")
    BZCLIENT.login(username, password)


def get_bugz(pkg_name):