Permalink
Browse files

clean up code, remove useless log lines, etc

  • Loading branch information...
1 parent 02df61b commit bef541ba056ac1e81ef5b06b88af5c33171c9a6c Jordan Evans committed Sep 21, 2011
Showing with 14 additions and 19 deletions.
  1. +9 −13 python/nagcat/merlin.py
  2. +5 −6 python/nagcat/merlintest.py
View
@@ -1,4 +1,4 @@
-# Copyright 2008-2009 ITA Software, Inc.
+# Copyright 2008-2011 Google, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -18,7 +18,8 @@
import time
from coil.errors import CoilError
-from nagcat import errors, log, nagios_api, nagios_objects, scheduler, merlintest,nagios
+from nagcat import errors, log, nagios_api
+from nagcat import nagios_objects, scheduler, merlintest, nagios
class NagcatMerlin(nagios.NagcatNagios):
"""NagcatNagios scheduler that load balances using merlin."""
@@ -55,17 +56,18 @@ def _set_peer_id_and_timestamp(self):
num_rows = curs.execute(
"""select * from merlin_peers where state=3;""")
self._num_peers = num_rows
- log.debug("Setting self._num_peers = %s", num_rows)
+ log.debug("Setting self._num_peers = %s", self._num_peers)
for i in range(num_rows):
row = curs.fetchone()
if row[0] == "localhost":
self._peer_id = row[5]
self._peer_id_timestamp = time.time()
- log.debug(("Setting self._peer_id = %s", str(self._peer_id)) +
+ log.debug(("Setting self._peer_id = %s",
+ str(self._peer_id)) +
("and self._peer_id_timestamp = %s",
self._peer_id_timestamp))
except MySQLdb.Error, e:
- log.error("Error %d: %s" % (e.args[0], e.args[1]))
+ log.error("Error reading merlin db %d: %s" % (e.args[0], e.args[1]))
def _update_peer_id(self):
log.debug("Updating peer_id with _merlin_db_info=%s",
@@ -81,12 +83,6 @@ def _update_peer_id(self):
if self._merlin_db_info:
self._set_peer_id_and_timestamp()
- def get_peer_id(self):
+ def get_peer_id_num_peers(self):
self._update_peer_id()
- return self._peer_id
-
- def get_num_peers(self):
- self._update_peer_id()
- return self._num_peers
-
-
+ return self._peer_id, self._num_peers
@@ -1,4 +1,4 @@
-# Copyright 2008-2009 ITA Software, Inc.
+# Copyright 2008-2011 Google, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -33,17 +33,16 @@ def _should_run(self):
"""Decides whether or not a test should be run, based on its task
index and the schedulers peer_id. Returns True if it should run, False
if it should not."""
- peer_id = self._nagcat.get_peer_id()
- num_peers = self._nagcat.get_num_peers()
- log.debug("Running _should_run, test_index=%s, num_peers=%s, peer_id=%s", str(self._test_index), num_peers, peer_id)
+ peer_id, num_peers = self._nagcat.get_peer_id_num_peers()
+ log.debug("Running should_run, test_index=%s, num_peers=%s, peer_id=%s",
+ str(self._test_index), num_peers, peer_id)
if peer_id and num_peers:
- if not (self._test_index % num_peers == peer_id):
+ if self._test_index % num_peers != peer_id:
return False
return True
def start(self):
"""Decides whether or not to start the test, based on _should_run."""
- log.debug("Running MerlinTest.start")
if self._should_run():
log.debug("Running test %s", self)
return super(MerlinTest,self).start()

0 comments on commit bef541b

Please sign in to comment.