[PATCH] Add is_logged_in utility method.
by Arun Babu Neelicattu
From: Arun Babu Neelicattu <abn(a)redhat.com>
---
bugzilla/base.py | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/bugzilla/base.py b/bugzilla/base.py
index e06223f..7aba942 100644
--- a/bugzilla/base.py
+++ b/bugzilla/base.py
@@ -697,6 +697,26 @@ class BugzillaBase(object):
self.password = ''
self.logged_in = False
+ def is_logged_in(self):
+ """
+ Utility method to check if this instance has already been logged in.
+
+ If the instance has its logged_in attribute set to True, this method
+ returns true. Otherwise, to test if this session is authenticated, the
+ method calls the User.get() XMLRPC method with ids set. Logged-out users
+ cannot pass the 'ids' parameter and will result in a 505 error.
+ """
+ try:
+ if self.logged_in:
+ return True
+ self._proxy.User.get({'ids': self._listify([])})
+ return True
+ except Fault:
+ e = sys.exc_info()[1]
+ if e.faultCode == 505:
+ return False
+ raise e
+
#############################################
# Fetching info about the bugzilla instance #
--
1.9.3
9 years, 3 months
Problem with RHBugzilla and _add_field_alias
by Jason L Tibbitts III
I'm kind of stumped on this one. I have a bit of code in Fedora
infrastructure (so running on RHEL6, python 2.6, in case that's
relevant) which works with python-bugzilla 1.0 but fails with 1.1.
Unfortunately it doesn't fail at all for me on my F20 dev machine.
Here's the backtrace:
Traceback (most recent call last):
File "/usr/local/bin/review-stats.py", line 612, in <module>
bz = bugzilla.RHBugzilla(url=config['url'], cookiefile=None, user=config['username'], password=config['password'])
File "/usr/lib/python2.6/site-packages/bugzilla/rhbugzilla.py", line 59, in __init__
_add_both_alias('fixed_in', 'cf_fixed_in')
File "/usr/lib/python2.6/site-packages/bugzilla/rhbugzilla.py", line 56, in _add_both_alias
self._add_field_alias(newname, origname, is_api=False)
AttributeError: 'RHBugzilla' object has no attribute '_add_field_alias'
This looks like it's down in the bowels of python-bugzilla itself and
not some trivial issue with my code, so I'm at a loss. Just in case, if
I ask for a Bugzilla object instead of a RHBugzilla one, I get a
different backtrace:
Traceback (most recent call last):
File "./review-stats.py", line 614, in <module>
(bugs, bugdata, usermap) = run_query(bz)
File "./review-stats.py", line 199, in run_query
bugs = filter(lambda b: b.id not in trackers, bz.query(querydata))
File "/usr/lib/python2.6/site-packages/bugzilla/base.py", line 995, in query
return [_Bug(bugzilla=self, dict=b) for b in r['bugs']]
File "/usr/lib/python2.6/site-packages/bugzilla/bug.py", line 42, in __init__
self._update_dict(dict)
File "/usr/lib/python2.6/site-packages/bugzilla/bug.py", line 129, in _update_dict
aliases = self.bugzilla._get_bug_aliases()
AttributeError: 'Bugzilla' object has no attribute '_get_bug_aliases'
You can see the code at
https://git.fedorahosted.org/cgit/fedora-infrastructure.git/tree/scripts/...
if that would be useful.
Any ideas would be greatly appreciated, because I'm fresh out.
- J<
9 years, 4 months
About .logged_in
by Pierre-Yves Chibon
Hi,
I have found a small thing that annoys me a little, as an example might make it
easier to explain, here we go:
>>> from bugzilla import Bugzilla
>>> bz = Bugzilla('https://bugzilla.redhat.com/xmlrpc.cgi')
>>> bz.logged_in
False
>>> bug = bz.getbug(123)
>>> bz.logged_in
False
>>> set([com['author'] for com in bug.comments])
set(['steve@...', 'why_99@...', 'jbj@...'])
Basically, the client authenticates against bugzilla with the token stored on
the file system, but it means that the `.logged_in` method does not actually say
if the user is logged in or not unless we specifically call `.login()`.
I can imagine that we do not know at first is the token stored on the disk is
still valid or not, but maybe could we check after calling bugzilla the first
time if said the result returned allowed to determine is the user is logged in
or not.
For `.getbug()` maybe we could check for the presence of '@' in the `.creator`.
I guess there are other methods where we maybe be able to find out if the user
is logged in or not.
Basically, it would allow then things like:
>>> from bugzilla import Bugzilla
>>> bz = Bugzilla('https://bugzilla.redhat.com/xmlrpc.cgi')
>>> bug = bz.getbug(123)
>>> if not bz.logged_in:
... bz.login(...)
... bug = bgz.getbug(123)
I adjusted my code to do
>>> from bugzilla import Bugzilla
>>> bz = Bugzilla('https://bugzilla.redhat.com/xmlrpc.cgi')
>>> bug = bz.getbug(123)
>>> if not '@' in bug.creator:
... bz.login(...)
... bug = bgz.getbug(123)
but I thought it might be an idea to have something in python-bugzilla itself
for this.
Thoughts?
Pierre
9 years, 4 months
[BUG] Server error: buf must be a byte string
by Jani Nikula
The command-line client fails with python 2.7.8 as follows:
Traceback (most recent call last):
File "/usr/local/bin/bugzilla", line 1253, in <module>
main()
File "/usr/local/bin/bugzilla", line 1212, in main
_do_info(bz, opt)
File "/usr/local/bin/bugzilla", line 728, in _do_info
products = bz.getproducts(include_fields=include_fields)
File "/usr/local/lib/python2.7/dist-packages/bugzilla/base.py", line 757, in getproducts
self._products = self._getproducts(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/bugzilla/base.py", line 891, in _getproducts
product_ids = self._proxy.Product.get_accessible_products()
File "/usr/lib/python2.7/xmlrpclib.py", line 1224, in __call__
return self.__send(self.__name, args)
File "/usr/local/lib/python2.7/dist-packages/bugzilla/base.py", line 168, in _ServerProxy__request
ret = ServerProxy._ServerProxy__request(self, methodname, params)
File "/usr/lib/python2.7/xmlrpclib.py", line 1578, in __request
verbose=self.__verbose
File "/usr/local/lib/python2.7/dist-packages/bugzilla/base.py", line 263, in request
return self._request_helper(url, request_body)
File "/usr/local/lib/python2.7/dist-packages/bugzilla/base.py", line 250, in _request_helper
raise e
BugzillaError: buf must be a byte string
Server error: buf must be a byte string
I've bisected this to
commit e3f17d7db5907ea629f31fbc892576fdf9ccec4e
Author: Josef Stribny <jstribny(a)redhat.com>
Date: Tue Jun 3 15:27:08 2014 +0200
Convert request_body to string for Python 3
and confirmed that reverting the commit from current master fixes the
issue.
BR,
Jani.
--
Jani Nikula, Intel Open Source Technology Center
9 years, 4 months
bugzilla login and cookiefile problems
by Jani Nikula
I used to have a working setup where I'd do 'bugzilla login' first and
then various bug modifications using the cookiefile from the
login. Problem is, I can't replicate this on a new install and I no
longer have access to the old one...
According to --debug --verbose output
Logging in... [14:37:48] INFO (base:485) login successful - dropping password from memory
Authorization cookie received.
I can successfully login to two different bugzilla instances
(https://bugzilla.kernel.org/xmlrpc.cgi and
https://bugs.freedesktop.org/xmlrpc.cgi) but the resulting cookiefile
will only include the comment:
# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This is a generated file! Do not edit.
The actual coookies don't get saved in the file. Any ideas?
BR,
Jani.
--
Jani Nikula, Intel Open Source Technology Center
9 years, 4 months
[PATCH] Add limited support for ExternalBugs extension in RHBZ
by Arun Babu Neelicattu
From: Arun Babu Neelicattu <abn(a)redhat.com>
- RHBZ instances now support adding/removing external trackers as
documented at https://bugzilla.redhat.com/docs/en/html/api/extensions/ExternalBugs/lib/...
- Limitations: current implementation uses only ext_type_description and
ext_bz_bug_id and does not support any other external tracker fields
---
bugzilla/rhbugzilla.py | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++
tests/rw_functional.py | 33 +++++++++++++++++++++++
2 files changed, 106 insertions(+)
diff --git a/bugzilla/rhbugzilla.py b/bugzilla/rhbugzilla.py
index dd9f76a..e9918de 100644
--- a/bugzilla/rhbugzilla.py
+++ b/bugzilla/rhbugzilla.py
@@ -116,6 +116,53 @@ class RHBugzilla(_parent):
return vals
+ def add_external_tracker(self, bug_ids, type_desc, external_id):
+ """
+ Wrapper method to allow adding of external tracking bugs using the
+ ExternalBugs::WebService::add_external_bug method.
+
+ This is documented at
+ https://bugzilla.redhat.com/docs/en/html/api/extensions/ExternalBugs/lib/...
+
+ bug_ids: A single bug id or list if bug ids to add the tracker to.
+ type_desc: The external tracker description as used by Bugzilla. This
+ value maps to the ext_type_description parameter of the XMLRPC
+ method.
+ external_id: The id as used by the external tracker. This value maps to
+ the ext_bz_bug_id parameter of the XMLRPC method.
+ """
+ kwargs = {
+ 'bug_ids': self._listify(bug_ids),
+ 'external_bugs': [{
+ 'ext_type_description': type_desc,
+ 'ext_bz_bug_id': external_id,
+ }],
+ }
+ return self._proxy.ExternalBugs.add_external_bug(kwargs)
+
+ def remove_external_tracker(self, bug_ids, type_desc, external_ids):
+ """
+ Wrapper method to allow removal of external tracking bugs using the
+ ExternalBugs::WebService::remove_external_bug method.
+
+ This is documented at
+ https://bugzilla.redhat.com/docs/en/html/api/extensions/ExternalBugs/lib/...
+
+ bug_ids: A single bug id or list if bug ids to remove the tracker from.
+ type_desc: The external tracker description as used by Bugzilla. This
+ value maps to the ext_type_description parameter of the XMLRPC
+ method.
+ external_ids: The id or list of ids as used by the external tracker.
+ This value maps to the ext_bz_bug_id parameter of the XMLRPC
+ method.
+ """
+ kwargs = {
+ 'bug_ids': self._listify(bug_ids),
+ 'ext_type_description': type_desc,
+ 'ext_bz_bug_id': self._listify(external_ids),
+ }
+ return self._proxy.ExternalBugs.remove_external_bug(kwargs)
+
#################
# Query methods #
@@ -220,6 +267,32 @@ class RHBugzilla(_parent):
tmp.append(t)
bug['groups'] = tmp
+ def build_external_tracker_boolean_query(
+ self, type_desc=None, external_id=None):
+ """
+ Helper method to build a boolean query to find bugs that contain an
+ external tracker with the 'type_desc' and 'external_id' combination.
+
+ All parameters that are None will be ignored when building the query.
+
+ type_desc: The external tracker description as used by Bugzilla. This
+ value maps to the external_bugzilla.description field.
+ external_ids: The id as used by the external tracker. This value maps
+ to the ext_bz_bug_map.ext_bz_bug_id field.
+ """
+ parts = []
+
+ if type_desc is not None:
+ parts.append(
+ 'external_bugzilla.description-equals-{0:s}'.format(type_desc))
+
+ if external_id is not None:
+ id_str = str(external_id)
+ parts.append(
+ 'ext_bz_bug_map.ext_bz_bug_id-equals-{0:s}'.format(id_str))
+
+ return ' & '.join(parts)
+
def build_query(self, **kwargs):
query = {}
diff --git a/tests/rw_functional.py b/tests/rw_functional.py
index ed55794..98dd89b 100644
--- a/tests/rw_functional.py
+++ b/tests/rw_functional.py
@@ -752,3 +752,36 @@ class RHPartnerTest(BaseTest):
bz.update_bugs(bug.id, bz.build_update(sub_component={}))
bug.refresh()
self.assertEqual(bug.sub_components, {})
+
+ def _test14ExternalTrackersQuery(self, bz, ext_type_desc, ext_bug_id):
+ boolean_query = bz.build_external_tracker_boolean_query(
+ ext_type_desc, ext_bug_id)
+ query = bz.build_query(
+ boolean_query=boolean_query, include_fields=['id'])
+ return [bug.bug_id for bug in bz.query(query)]
+
+ def test14ExternalTrackersQuery(self):
+ bz = self.bzclass(url=self.url, cookiefile=cf, tokenfile=tf)
+ ext_type_desc = "Mozilla Foundation"
+ ext_bug_id = 913904
+
+ # Closed RH Bugzilla bug with external tracker
+ bugid = 1007135
+ assert bugid in \
+ self._test14ExternalTrackersQuery(bz, ext_type_desc, ext_bug_id)
+
+ def test14ExternalTrackersAddRemove(self):
+ bz = self.bzclass(url=self.url, cookiefile=cf, tokenfile=tf)
+ ext_type_desc = "Mozilla Foundation"
+ ext_bug_id = 380489
+ bugid = 461686
+
+ # test adding tracker
+ bz.add_external_tracker(bugid, ext_type_desc, ext_bug_id)
+ assert bugid in \
+ self._test14ExternalTrackersQuery(bz, ext_type_desc, ext_bug_id)
+
+ # test removing tracker
+ bz.remove_external_tracker(bugid, ext_type_desc, ext_bug_id)
+ assert bugid not in \
+ self._test14ExternalTrackersQuery(bz, ext_type_desc, ext_bug_id)
--
1.9.3
9 years, 4 months
[BUG] UserWarning: Unknown distribution option: 'install_requires'
by Jani Nikula
Building or installing the command-line client with python 2.7.8 leads
to the warning:
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'install_requires'
warnings.warn(msg)
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'tests_require'
warnings.warn(msg)
I've bisected this to
commit 768b529c4f20059946be297438404735bd3ff4c2
Author: Arun Babu Neelicattu <abn(a)redhat.com>
Date: Tue Sep 16 08:17:08 2014 +1000
Handle requirements in setup.py
and confirmed that reverting the commit from current master fixes the
issue.
BR,
Jani.
--
Jani Nikula, Intel Open Source Technology Center
9 years, 4 months
Fwd: Complex Query Support
by Mildred Clarke
All,
The python-bugzilla implementation is great but I have one issue that I
cannot seem to find resolution on. Was hoping that someone here could shed
some light on the situation. I have attempted a few different ways and upon
review of the source I don't think* what I am attempting to do is supported
in the version I am using (1.1.0)
When I attempt to build a complex query, the url_to_query method returns a
dictionary object that appears to contain the appropriate values. However,
when attempting to query the remote bugzilla instance an error message is
displayed and no results are returned. I believe this is due to the use of
the "advanced" query format. The error message is complaining about the use
of "v1" and sometimes "o2". Is it the use of Regex ? Is it my bugzilla
instance ?
Message and code snips below.
--- Error Message ---
Fault: <Fault 53: 'v1 is not a valid parameter for the Bugzilla::Bug::match
function.'>
--- Error Message ---
Fault: <Fault 53: 'o2 is not a valid parameter for the Bugzilla::Bug::match
function.'>
--- CODE SNIP ---
q_url="
https://bugzilla.local/query.cgi?bug_status=New&bug_status=Accepted&bug_s...
^%24&v2=410000&v3=-"
Returns the values in a dictionary with this command --
bz.url_to_query(q_url)
{'bug_status': ['New', 'Accepted', 'Reopened'],
'f1': 'cf_custom_field_here',
'f2': 'bug_id',
'f3': 'alias',
'o1': 'regexp',
'o2': 'greaterthan',
'o3': 'notsubstring',
'query_format': 'advanced',
'v1': '^$',
'v2': '410000',
'v3': '-'}
This is the actual code that will produce the error message. bz is my
bugzilla connection.
""" bz.query(bz.url_to_query(q_url)) """. As you can see, I am using the
"advanced" formatting. If I don't include the "f*, v*, o*" parameters
queries return a result set.
Let me know if you need more details to help figure out this issue.
Thanks
Mildred.
9 years, 4 months