Project

General

Profile

Tâche #12764

Distribution EOLE - Scénario #12978: Assistance aux utilisateurs (39-41)

Diagnose des conteneurs de fonctionne pas

Added by Philippe Caseiro over 5 years ago. Updated over 5 years ago.

Status:
Fermé
Priority:
Normal
Assigned To:
Start date:
09/01/2015
Due date:
% Done:

100%

Estimated time:
1.00 h
Spent time:
Remaining (hours):
0.0

Description

Sur un AmonEcole 2.5 les conteneurs sont toujours en erreur dans le diagnose même si tout vas bien.

Il semblerais que la commande lxc-info ai légèrement changé.

En 2.4 elle affiche

status: RUNNING

en 2.5 elle affiche

Status: RUNNING

Le code de pyeole diagnose cherche "status" et non "Status".


Related issues

Related to Distribution EOLE - Tâche #13120: Générer l’image ISO 2.5.1-β1 Fermé 09/22/2015
Related to Distribution EOLE - Tâche #23205: Problème au diagnose en mode conteneur Fermé 03/05/2018

Associated revisions

Revision 42b7d766 (diff)
Added by Daniel Dehennin over 5 years ago

Correction du diagnose « test_containers() »

Les variables « OK » et « NOK » ne doivent pas être évaluées dans un
contexte booléen.

De plus, la commande « lxc-info » a évolué et permet de n’interroger que
l’état d’un conteneur, évitant d’avoir à chercher parmis plusieurs
lignes.

  • pyeole/diagnose/diagnose.py (test_container): Nouvelle fonction
    testant si le status LXC d’un conteneur est « RUNNING » et si l’accès
    SSH est fonctionnel.
    (test_containers): Utilisation de la nouvelle fonction.

Ref: #12764

History

#1 Updated by Philippe Caseiro over 5 years ago

  • Project changed from eole-common to python-pyeole

#3 Updated by Daniel Dehennin over 5 years ago

En fait il s’agit d’une erreur basique de logique.

OK = 0
NOK = 1
NOT_AVAILABLE = 2

On ne peut pas utiliser ces valeurs en tant que booléen.

Je propose le diff suivant:

diff --git a/pyeole/diagnose/diagnose.py b/pyeole/diagnose/diagnose.py
index 93d957b..560f2a9 100644
--- a/pyeole/diagnose/diagnose.py
+++ b/pyeole/diagnose/diagnose.py
@@ -273,12 +273,11 @@ def test_containers():
                 state:   RUNNING
                 pid:     19301
             """ 
-            is_stated = NOK
+            ret[container] = False
             for line in out.split('\n'):
-                if line.startswith('state: ') and line.split()[-1] == 'RUNNING':
-                    is_stated = OK
+                if line.startswith('State: ') and line.split()[-1] == 'RUNNING':
+                    ret[container] = True
                     break
-            ret[container] = is_stated
     return ret

#4 Updated by Daniel Dehennin over 5 years ago

Il y a beaucoup mieux en fait:

diff --git a/pyeole/diagnose/diagnose.py b/pyeole/diagnose/diagnose.py
index 93d957b..a8eef36 100644
--- a/pyeole/diagnose/diagnose.py
+++ b/pyeole/diagnose/diagnose.py
@@ -26,7 +26,9 @@ import logging

 from creole.client import CreoleClient
 from creole.config import VIRTMASTER
-from pyeole.process import system_code, system_out
+from pyeole.process import system_code
+from pyeole.process import system_out
+from pyeole.process import tcpcheck

 log = logging.getLogger(__name__)

@@ -258,27 +260,50 @@ def test_clamd():
         return ''

+def test_container(name, ip=None):
+    """Test if a container is running and reachable
+
+    Check the state with the ``lxc-info`` command.
+
+    If :data:`ip` is provided and the state is OK, check if SSH port
+    is open.
+
+    :param name: name of the container
+    :type name: `str`
+    :return: if the container is running and reachable
+    :rtype: `bool`
+
+    """ 
+    is_running = False
+    code, out, err = system_out(['lxc-info', '--state', '-n', name])
+    if code == 0:
+        """ 
+        lxc-info --state returns something like:
+            State:   RUNNING
+        """ 
+        is_running = out.strip().endswith('RUNNING')
+
+    if is_running and ip is not None:
+        is_running = tcpcheck(ip, '22', '2')
+
+    return is_running
+
+
 def test_containers():
+    """Check if the containers are running
+
+    :return: The running state for each container
+    :rtype: `dict`
+
+    """ 
     client = CreoleClient()
     ret = {}
     for container in client.get_groups():
         if container in ['all', VIRTMASTER]:
             continue
-        code, out, err = system_out(['lxc-info', '-n', container])
-        if code != 0:
-            ret[container] = False
-        else:
-            """ 
-            lxc-info returns something like:
-                state:   RUNNING
-                pid:     19301
-            """ 
-            is_stated = NOK
-            for line in out.split('\n'):
-                if line.startswith('state: ') and line.split()[-1] == 'RUNNING':
-                    is_stated = OK
-                    break
-            ret[container] = is_stated
+        ip = client.get_creole('adresse_ip_{0}'.format(container))
+        ret[container] = test_container(container, ip)
+
     return ret

J’ai ça sur une branche, à voir si nous l’appliquons pour la 2.5.1.

#5 Updated by Daniel Dehennin over 5 years ago

  • Parent task set to #12978

#6 Updated by Daniel Dehennin over 5 years ago

  • Assigned To set to Daniel Dehennin
  • Remaining (hours) set to 1.0

#7 Updated by Daniel Dehennin over 5 years ago

  • Status changed from Nouveau to En cours
  • % Done changed from 0 to 100

Passage du patch en 2.5.1.

#8 Updated by Daniel Dehennin over 5 years ago

  • Remaining (hours) changed from 1.0 to 0.25

#9 Updated by Scrum Master over 5 years ago

  • Status changed from En cours to Résolu

#10 Updated by Joël Cuissinat over 5 years ago

  • Status changed from Résolu to Fermé
  • Remaining (hours) changed from 0.25 to 0.0

OK

#11 Updated by Joël Cuissinat about 3 years ago

  • Related to Tâche #23205: Problème au diagnose en mode conteneur added

Also available in: Atom PDF