From e102d33a9d01f3e90351f4cd363478ae1b37b0e4 Mon Sep 17 00:00:00 2001 From: Guillaume Raffy Date: Wed, 19 Jun 2019 07:31:41 +0000 Subject: [PATCH] Bug 2672 - le power diagram contient des erreurs (certains serveurs affichent une consommation de 0 W) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - correction du bug (les machines physix.._.. n'étaient pas gérées, alors que les machines simpatix.._.. l'étaient; du coup, j'ai rendu le code plus générique pour qu'il reconnaisse les machines [a-z]+.._..) --- PowerDiagram.py | 10 ++++++---- SimpaDbUtil.py | 2 +- inventory.py | 5 ++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/PowerDiagram.py b/PowerDiagram.py index 6deca1b..9b19253 100644 --- a/PowerDiagram.py +++ b/PowerDiagram.py @@ -7,8 +7,8 @@ ''' import re -import pygraphviz -from inventory import Inventory +import pygraphviz # port install py-pygraphviz +from inventory import Inventory, MachineSpecIdNotFound from SimpaDbUtil import SqlFile, SqlDatabaseReader from Lib import SimpaDbUtil @@ -199,7 +199,9 @@ class PowerConfig(object): machine_name = machine.name - if re.match('simpatix.._..', machine_name): + if re.match('[a-z]+.._..', machine_name): + # machine_name is a group of machines such as physix80_83 + # in this case, we use a hack : the type and power consumption is based on the first machine of this group (in this example physix80) machine_name = '_'.join(machine_name.split('_')[0:-1]) # print(machine_name) @@ -210,7 +212,7 @@ class PowerConfig(object): machine_spec_id = inventory.machine_name_to_machine_spec_id(machine_name) if machine_spec_id == '': machine_spec_id = None # some simple 'machines' such as powerext003 have undefined machine_spec_id - except SimpaDbUtil.TableAttrNotFound: + except MachineSpecIdNotFound: pass if machine_spec_id is not None: diff --git a/SimpaDbUtil.py b/SimpaDbUtil.py index 118f1bc..98b7736 100644 --- a/SimpaDbUtil.py +++ b/SimpaDbUtil.py @@ -1,4 +1,4 @@ -import MySQLdb +import MySQLdb # sudo port install py-mysql import time import StringIO import re diff --git a/inventory.py b/inventory.py index c0fc408..0c96e5a 100644 --- a/inventory.py +++ b/inventory.py @@ -45,7 +45,10 @@ class Inventory(object): return machine_name def machine_name_to_machine_spec_id(self, machine_name): - machine_spec_id = self._sql_reader.get_table_attr('machines', 'name', machine_name, 'machine_spec_id') + try: + machine_spec_id = self._sql_reader.get_table_attr('machines', 'name', machine_name, 'machine_spec_id') + except SimpaDbUtil.TableAttrNotFound as e: # @UnusedVariable + raise MachineSpecIdNotFound(machine_name) return machine_spec_id # electricity related methods