Skip to content

Commit

Permalink
Use exceptions to propagate error messages to fedmsg
Browse files Browse the repository at this point in the history
... instead of using log.error which just emails sysadmin-datanommer.
And we can't do anything about most of these errors.  We want the
community to see them and to actively garden the release-monitoring.org
content.
  • Loading branch information
ralphbean committed Mar 27, 2015
1 parent df8fddd commit 34dbb2e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 32 deletions.
42 changes: 18 additions & 24 deletions hotness/anitya.py
Expand Up @@ -228,16 +228,14 @@ def force_check(self, project):

def map_new_package(self, name, project):
if not self.is_logged_in:
log.error('Could not add new anitya project. Not logged in.')
return False
raise ValueError('Could not add anitya project. Not logged in.')

idx = project['id']
url = self.url + '/project/%i/map' % idx
response = self.__send_request(url, method='GET')
if not response.status_code == 200:
code = response.status_code
log.error("Couldn't get form page to get csrf token %r" % code)
return False
raise ValueError("Couldn't get form to get csrf token %r" % code)

This comment has been minimized.

Copy link
@pypingou

pypingou Mar 27, 2015

Member

This might be more an issue for us than fedmsg


soup = bs4.BeautifulSoup(response.text)
data = dict(
Expand All @@ -249,19 +247,17 @@ def map_new_package(self, name, project):

if not response.status_code == 200:
code = response.status_code
log.error('Failed to map in anitya, status %r: %r' % (code, data))
return False
raise ValueError('Failed to map in anitya, '
'status %r: %r' % (code, data))
elif 'Could not' in response.text:
log.error('Failed to map in anitya, validation failure: %r' % data)
return False
else:
log.info('Successfully mapped %r in anitya' % name)
return True
raise ValueError('Failed to map in anitya, '
'validation failure: %r' % data)

log.info('Successfully mapped %r in anitya' % name)

def add_new_project(self, name, homepage):
if not self.is_logged_in:
log.error('Could not add new anitya project. Not logged in.')
return False
raise ValueError('Could not add anitya project. Not logged in.')

data = dict(
name=name,
Expand All @@ -277,8 +273,7 @@ def add_new_project(self, name, homepage):
break

if 'backend' not in data:
log.error('Could not determine backend for %r' % homepage)
return False
raise ValueError('Could not determine backend for %r' % homepage)

# It's not always the case that these need removed, but often
# enough...
Expand All @@ -300,20 +295,19 @@ def add_new_project(self, name, homepage):

if not response.status_code == 200:
code = response.status_code
log.error("Couldn't get form page to get csrf token %r" % code)
return False
raise ValueError("Couldn't get form to get csrf token %r" % code)

soup = bs4.BeautifulSoup(response.text)
data['csrf_token'] = soup.form.find(id='csrf_token').attrs['value']

response = self.__send_request(url, method='POST', data=data)

# Hide this from stuff we republish to the bus
del data['csrf_token']

if not response.status_code == 200:
log.error('Failed to add to anitya: %r' % data)
return False
raise ValueError('Failed to add to anitya: %r' % data)
elif 'Could not' in response.text:
log.error('Failed to add to anitya: %r' % data)
return False
else:
log.info('Successfully added %r to anitya' % data['name'])
return True
raise ValueError('Failed to add to anitya: %r' % data)

log.info('Successfully added %r to anitya' % data['name'])
42 changes: 34 additions & 8 deletions hotness/consumers.py
Expand Up @@ -305,18 +305,31 @@ def handle_new_package(self, msg):
self.log.info("Found one match on Anitya.")
project = projects[0]
anitya.login(self.anitya_username, self.anitya_password)
success = anitya.map_new_package(name, project)
reason = None
try:
anitya.map_new_package(name, project)
except ValueError as e:
reason = str(e)
self.publish("project.map", msg=dict(
trigger=msg, project=project, success=success))
trigger=msg,
project=project,
success=not bool(reason),
reason=reason))
return

# ... else

self.log.info("Saw 0 matching projects on anitya. Attempting to add.")
anitya.login(self.anitya_username, self.anitya_password)
success = anitya.add_new_project(name, homepage)
reason = None
try:
anitya.add_new_project(name, homepage)
except ValueError as e:
reason = str(e)
self.publish("project.map", msg=dict(
trigger=msg, success=success))
trigger=msg,
success=not bool(reason),
reason=reason))

def handle_monitor_toggle(self, msg):
status = msg['msg']['status']
Expand All @@ -343,19 +356,32 @@ def handle_monitor_toggle(self, msg):
project = results['projects'][0]

if not any([p['distro'] == 'Fedora' for p in project['packages']]):
success = anitya.map_new_package(name, project)
reason = None
try:
anitya.map_new_package(name, project)
except ValueError as e:
reason = str(e)
self.publish("project.map", msg=dict(
trigger=msg, project=project, success=success))
trigger=msg,
project=project,
success=not bool(reason),
reason=reason))

# After mapping, force a check for new tarballs
anitya.force_check(project)
else:
# OTHERWISE, there is *nothing* on anitya about it, so add one.
self.log.info("Saw 0 matching projects on anitya. Adding.")
anitya.login(self.anitya_username, self.anitya_password)
success = anitya.add_new_project(name, homepage)
reason = None
try:
anitya.add_new_project(name, homepage)
except ValueError as e:
reason = str(e)
self.publish("project.map", msg=dict(
trigger=msg, success=success))
trigger=msg,
success=not bool(reason),
reason=reason))

def is_monitored(self, package):
""" Returns True if a package is marked as 'monitored' in pkgdb2. """
Expand Down

0 comments on commit 34dbb2e

Please sign in to comment.