Skip to content

Commit 741bb9f

Browse files
committed
bugzilla: Drop the hardcoded version to class mapping
This currently meant that all bugzilla 5.0 instances were detected as bugzilla 3, hence the previous gentoo hardcoding.
1 parent 0ab1279 commit 741bb9f

2 files changed

Lines changed: 28 additions & 60 deletions

File tree

bugzilla/__init__.py

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -37,68 +37,23 @@ def _getBugzillaClassForURL(url, sslverify):
3737
url = Bugzilla3.fix_url(url)
3838
log.debug("Detecting subclass for %s", url)
3939
s = ServerProxy(url, _RequestsTransport(url, sslverify=sslverify))
40-
rhbz = False
41-
bzversion = ''
42-
c = None
4340

4441
if "bugzilla.redhat.com" in url:
4542
log.info("Using RHBugzilla for URL containing bugzilla.redhat.com")
4643
return RHBugzilla
4744
if "bugzilla.novell.com" in url:
4845
log.info("Using NovellBugzilla for URL containing bugzilla.novell.com")
4946
return NovellBugzilla
50-
if "bugzilla.mozilla.org" in url:
51-
log.info("Using Bugzilla42 for URL containing bugzilla.mozilla.org")
52-
return Bugzilla42
53-
54-
# Gentoo uses Bugzilla 5.0.x so below is a placeholder until a new
55-
# Bugzilla50 class is created and includes changes in the 5.x API.
56-
if "bugs.gentoo.org" in url:
57-
log.info("Using Bugzilla44 for URL containing bugs.gentoo.org")
58-
return Bugzilla44
5947

6048
# Check for a Red Hat extension
6149
try:
6250
log.debug("Checking for Red Hat Bugzilla extension")
6351
extensions = s.Bugzilla.extensions()
6452
if extensions.get('extensions', {}).get('RedHat', False):
65-
rhbz = True
66-
except Fault:
67-
pass
68-
log.debug("rhbz=%s", str(rhbz))
69-
70-
# Try to get the bugzilla version string
71-
try:
72-
log.debug("Checking return value of Bugzilla.version()")
73-
r = s.Bugzilla.version()
74-
bzversion = r['version']
53+
log.debug("Found RedHat bugzilla extension")
54+
return RHBugzilla
7555
except Fault:
7656
pass
77-
log.debug("bzversion='%s'", str(bzversion))
78-
79-
# note preference order: RHBugzilla* wins if available
80-
if rhbz:
81-
c = RHBugzilla
82-
elif bzversion.startswith("4."):
83-
if bzversion.startswith("4.0"):
84-
c = Bugzilla4
85-
elif bzversion.startswith("4.2"):
86-
c = Bugzilla42
87-
else:
88-
log.debug("No explicit match for %s, using latest bz4", bzversion)
89-
c = Bugzilla44
90-
else:
91-
if bzversion.startswith('3.6'):
92-
c = Bugzilla36
93-
elif bzversion.startswith('3.4'):
94-
c = Bugzilla34
95-
elif bzversion.startswith('3.2'):
96-
c = Bugzilla32
97-
else:
98-
log.debug("No explicit match for %s, fall through", bzversion)
99-
c = Bugzilla3
100-
101-
return c
10257

10358

10459
class Bugzilla(_BugzillaBase):
@@ -112,8 +67,7 @@ def _init_class_from_url(self, url, sslverify):
11267

11368
c = _getBugzillaClassForURL(url, sslverify)
11469
if not c:
115-
raise ValueError("Couldn't determine Bugzilla version for %s" %
116-
url)
70+
return False
11771

11872
self.__class__ = c
11973
log.info("Chose subclass %s v%s", c.__name__, c.version)

tests/ro_functional.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,23 @@
2222
class BaseTest(unittest.TestCase):
2323
url = None
2424
bzclass = Bugzilla
25+
bzversion = (0, 0)
2526
closestatus = "CLOSED"
2627

2728
def clicomm(self, argstr, expectexc=False):
2829
comm = "bugzilla " + argstr
2930

30-
bz = self.bzclass(url=self.url, cookiefile=None, tokenfile=None)
31+
bz = Bugzilla(url=self.url, cookiefile=None, tokenfile=None)
3132
if expectexc:
3233
self.assertRaises(Exception, tests.clicomm, comm, bz)
3334
else:
3435
return tests.clicomm(comm, bz)
3536

36-
def _testBZClass(self):
37+
def _testBZVersion(self):
3738
bz = Bugzilla(self.url, cookiefile=None, tokenfile=None)
38-
self.assertTrue(bz.__class__ is self.bzclass)
39+
self.assertEquals(bz.__class__, self.bzclass)
40+
self.assertEquals(bz.bz_ver_major, self.bzversion[0])
41+
self.assertEquals(bz.bz_ver_minor, self.bzversion[1])
3942

4043
# Since we are running these tests against bugzilla instances in
4144
# the wild, we can't depend on certain data like product lists
@@ -115,17 +118,27 @@ def _testQueryURL(self, url, count, expectstr):
115118

116119

117120
class BZMozilla(BaseTest):
118-
url = "https://bugzilla.mozilla.org"
119-
bzclass = bugzilla.Bugzilla42
120-
test0 = BaseTest._testBZClass
121+
def testVersion(self):
122+
# bugzilla.mozilla.org returns version values in YYYY-MM-DD
123+
# format, so just try to confirm that
124+
bz = Bugzilla("bugzilla.mozilla.org", cookiefile=None, tokenfile=None)
125+
self.assertEquals(bz.__class__, Bugzilla)
126+
self.assertTrue(bz.bz_ver_major >= 2016)
127+
self.assertTrue(bz.bz_ver_minor in range(1, 13))
128+
129+
130+
class BZGentoo(BaseTest):
131+
url = "bugs.gentoo.org"
132+
bzversion = (5, 0)
133+
test0 = BaseTest._testBZVersion
121134

122135

123136
class BZGnome(BaseTest):
124137
url = "https://bugzilla.gnome.org/xmlrpc.cgi"
125-
bzclass = bugzilla.Bugzilla44
138+
bzversion = (4, 4)
126139
closestatus = "RESOLVED"
127140

128-
test0 = BaseTest._testBZClass
141+
test0 = BaseTest._testBZVersion
129142
test1 = lambda s: BaseTest._testQuery(s,
130143
"--product dogtail --component sniff",
131144
9, "321654")
@@ -137,10 +150,10 @@ class BZGnome(BaseTest):
137150

138151
class BZFDO(BaseTest):
139152
url = "https://bugs.freedesktop.org/xmlrpc.cgi"
140-
bzclass = bugzilla.Bugzilla44
153+
bzversion = (5, 0)
141154
closestatus = "CLOSED,RESOLVED"
142155

143-
test0 = BaseTest._testBZClass
156+
test0 = BaseTest._testBZVersion
144157

145158
test1 = lambda s: BaseTest._testQuery(s, "--product avahi", 10, "3450")
146159
test2 = lambda s: BaseTest._testQueryFull(s, "3450", 10, "Blocked: \n")
@@ -158,8 +171,9 @@ class BZFDO(BaseTest):
158171
class RHTest(BaseTest):
159172
url = tests.REDHAT_URL or "https://bugzilla.redhat.com/xmlrpc.cgi"
160173
bzclass = bugzilla.RHBugzilla
174+
bzversion = (4, 4)
161175

162-
test0 = BaseTest._testBZClass
176+
test0 = BaseTest._testBZVersion
163177
test1 = lambda s: BaseTest._testInfoProducts(s, 125,
164178
"Virtualization Tools")
165179
test2 = lambda s: BaseTest._testInfoComps(s, "Virtualization Tools",

0 commit comments

Comments
 (0)