diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/Server/Plugins/DBStats.py | 21 | ||||
-rwxr-xr-x | src/lib/Server/Reports/importscript.py | 23 |
2 files changed, 26 insertions, 18 deletions
diff --git a/src/lib/Server/Plugins/DBStats.py b/src/lib/Server/Plugins/DBStats.py index fe357fc40..2712cd45f 100644 --- a/src/lib/Server/Plugins/DBStats.py +++ b/src/lib/Server/Plugins/DBStats.py @@ -5,6 +5,11 @@ import lxml.etree import platform import time +try: + from django.core.exceptions import MultipleObjectsReturned +except ImportError: + pass + import Bcfg2.Server.Plugin import Bcfg2.Server.Reports.importscript from Bcfg2.Server.Reports.reports.models import Client @@ -53,15 +58,19 @@ class DBStats(Bcfg2.Server.Plugin.Plugin, logger, True, platform.node()) + logger.info("Imported data for %s in %s seconds" \ + % (metadata.hostname, time.time() - start)) + return + except MultipleObjectsReturned, e: + logger.error("DBStats: MultipleObjectsReturned while handling %s: %s" % \ + (metadata.hostname, e)) + logger.error("DBStats: Data is inconsistent") break except: logger.error("DBStats: Failed to write to db (lock); retrying", exc_info=1) - if i == 3: - logger.error("DBStats: Retry limit failed; aborting operation") - return - logger.info("Imported data in the reason fast path in %s second" \ - % (time.time() - start)) + logger.error("DBStats: Retry limit failed for %s; aborting operation" \ + % metadata.hostname) def GetExtra(self, client): c_inst = Client.objects.filter(name=client)[0] @@ -95,7 +104,7 @@ class DBStats(Bcfg2.Server.Plugin.Plugin, entry.reason.current_diff.split('\n'), 1))) elif entry.reason.is_binary: # If len is zero the object was too large to store - raise Bcfg2.Server.Plugin.PluginExecutionError + raise Bcfg2.Server.Plugin.PluginExecutionError else: ret.append(None) return ret diff --git a/src/lib/Server/Reports/importscript.py b/src/lib/Server/Reports/importscript.py index 016098cc8..cdfd8079c 100755 --- a/src/lib/Server/Reports/importscript.py +++ b/src/lib/Server/Reports/importscript.py @@ -63,12 +63,9 @@ def build_reason_kwargs(r_ent): def load_stats(cdata, sdata, vlevel, logger, quick=False, location=''): - cursor = connection.cursor() clients = {} [clients.__setitem__(c.name, c) \ for c in Client.objects.all()] - #[clients.__setitem__(c['name'], c['id']) \ - # for c in Client.objects.values('name', 'id')] pingability = {} [pingability.__setitem__(n.get('name'), n.get('pingable', default='N')) \ @@ -169,16 +166,18 @@ def load_stats(cdata, sdata, vlevel, logger, quick=False, location=''): for key in pingability.keys(): if key not in clients: - #print "Ping Save Problem with client %s" % name continue - pmatch = Ping.objects.filter(client=clients[key]).order_by('-endtime') - if pmatch and pmatch[0].status == pingability[key]: - pmatch[0].endtime = datetime.now() - pmatch[0].save() - else: - Ping(client=clients[key], status=pingability[key], - starttime=datetime.now(), - endtime=datetime.now()).save() + try: + pmatch = Ping.objects.filter(client=clients[key]).order_by('-endtime')[0] + if pmatch.status == pingability[key]: + pmatch.endtime = datetime.now() + pmatch.save() + continue + except IndexError: + pass + Ping(client=clients[key], status=pingability[key], + starttime=datetime.now(), + endtime=datetime.now()).save() if vlevel > 1: logger.info("---------------PINGDATA SYNCED---------------------") |