From e5f7930bd9e89b4bb24494fd96d141fd11558f33 Mon Sep 17 00:00:00 2001 From: Daniel STAN Date: Tue, 9 Dec 2014 21:22:21 +0100 Subject: [PATCH] switchs2.py: don't crash si chbre inexistante --- gestion/annuaires_pg.py | 6 +++++- gestion/gen_confs/switchs2.py | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/gestion/annuaires_pg.py b/gestion/annuaires_pg.py index 4babb487..3f167df1 100644 --- a/gestion/annuaires_pg.py +++ b/gestion/annuaires_pg.py @@ -44,6 +44,10 @@ def _need_conn(f): bat_switchs = ["a", "b", "c", "g", "h", "i", "j", "m", "o", "p"] +class ChbreNotFound(ValueError): + """Lorsqu'une chambre n'existe pas""" + pass + @_need_conn def chbre_prises(batiment, chambre = None): """Correspondance chambre -> prise""" @@ -55,7 +59,7 @@ def chbre_prises(batiment, chambre = None): try: return "%03d" % cur.fetchone()[0] except TypeError: - raise ValueError("Chambre inexistante bat %r, chbre %r" % (batiment, chambre)) + raise ChbreNotFound("Chambre inexistante bat %r, chbre %r" % (batiment, chambre)) else: cur = conn.cursor() cur.execute("SELECT chambre, prise_crans FROM prises WHERE batiment = %s", batiment) diff --git a/gestion/gen_confs/switchs2.py b/gestion/gen_confs/switchs2.py index 4da31ace..7f673351 100755 --- a/gestion/gen_confs/switchs2.py +++ b/gestion/gen_confs/switchs2.py @@ -321,7 +321,11 @@ def check_conf_ldap(hostname): continue chbre = unicode(res[0].proprio().get('chbre', ['EXT'])[0]) th_prise = chbre[0].lower() - th_prise += annuaire.chbre_prises(chbre[0], chbre[1:]) + try: + th_prise += annuaire.chbre_prises(chbre[0], chbre[1:]) + except annuaire.ChbreNotFound: + # La chambre est inconnue -> drop + continue th_prises_set.add(th_prise) pr_prise = bat.lower() + '%d%02d' % (sw_num, port.num)