Merge "Integrate yardstick on daisy master branch"
[releng.git] / modules / opnfv / utils / ovs_logger.py
index 3159609..2107bdc 100644 (file)
@@ -7,7 +7,7 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
 
-import opnfv.utils.OPNFVLogger as OPNFVLogger
+import opnfv.utils.opnfv_logger as OPNFVLogger
 import os
 import time
 import shutil
@@ -16,6 +16,7 @@ logger = OPNFVLogger.Logger('ovs_logger').getLogger()
 
 
 class OVSLogger(object):
+
     def __init__(self, basedir, ft_resdir):
         self.ovs_dir = basedir
         self.ft_resdir = ft_resdir
@@ -26,13 +27,12 @@ class OVSLogger(object):
         if not os.path.exists(dirpath):
             os.makedirs(dirpath)
 
-    def __ssh_host(self, ssh_conn, host_prefix='10.20.0'):
+    def __ssh_host(self, ssh_conn):
         try:
-            _, stdout, _ = ssh_conn.exec_command('hostname -I')
-            hosts = stdout.readline().strip().split(' ')
-            found_host = [h for h in hosts if h.startswith(host_prefix)][0]
+            _, stdout, _ = ssh_conn.exec_command('hostname')
+            found_host = stdout.readline()
             return found_host
-        except Exception, e:
+        except Exception as e:
             logger.error(e)
 
     def __dump_to_file(self, operation, host, text, timestamp=None):
@@ -55,7 +55,7 @@ class OVSLogger(object):
                                 .format(cmd, host))
             output = ''.join(stdout.readlines())
             return output
-        except Exception, e:
+        except Exception as e:
             logger.error('[__remote_command(ssh_client, {0})]: {1}'
                          .format(cmd, e))
             return None
@@ -70,7 +70,7 @@ class OVSLogger(object):
     def ofctl_dump_flows(self, ssh_conn, br='br-int',
                          choose_table=None, timestamp=None):
         try:
-            cmd = 'ovs-ofctl -OOpenFlow13 dump-flows {0}'.format(br)
+            cmd = 'sudo ovs-ofctl -OOpenFlow13 dump-flows {0}'.format(br)
             if choose_table is not None:
                 cmd = '{0} table={1}'.format(cmd, choose_table)
             output = self.__remote_cmd(ssh_conn, cmd)
@@ -78,41 +78,43 @@ class OVSLogger(object):
             host = self.__ssh_host(ssh_conn)
             self.__dump_to_file(operation, host, output, timestamp=timestamp)
             return output
-        except Exception, e:
+        except Exception as e:
             logger.error('[ofctl_dump_flows(ssh_client, {0}, {1})]: {2}'
                          .format(br, choose_table, e))
             return None
 
     def vsctl_show(self, ssh_conn, timestamp=None):
         try:
-            cmd = 'ovs-vsctl show'
+            cmd = 'sudo ovs-vsctl show'
             output = self.__remote_cmd(ssh_conn, cmd)
             operation = 'vsctl_show'
             host = self.__ssh_host(ssh_conn)
             self.__dump_to_file(operation, host, output, timestamp=timestamp)
             return output
-        except Exception, e:
+        except Exception as e:
             logger.error('[vsctl_show(ssh_client)]: {0}'.format(e))
             return None
 
     def dump_ovs_logs(self, controller_clients, compute_clients,
                       related_error=None, timestamp=None):
+        """
+        delete controller_clients argument because
+        that was producing an error in XCI installer.
+
+        For more information see:
+        TODO: https://jira.opnfv.org/browse/RELENG-314
+        """
+        del controller_clients
         if timestamp is None:
             timestamp = time.strftime("%Y%m%d-%H%M%S")
-
-        for controller_client in controller_clients:
-            self.ofctl_dump_flows(controller_client,
-                                  timestamp=timestamp)
-            self.vsctl_show(controller_client,
-                            timestamp=timestamp)
-
-        for compute_client in compute_clients:
-            self.ofctl_dump_flows(compute_client,
-                                  timestamp=timestamp)
-            self.vsctl_show(compute_client,
-                            timestamp=timestamp)
+        # clients = controller_clients + compute_clients
+        clients = compute_clients
+        for client in clients:
+            self.ofctl_dump_flows(client, timestamp=timestamp)
+            self.vsctl_show(client, timestamp=timestamp)
 
         if related_error is not None:
             dumpdir = os.path.join(self.ovs_dir, timestamp)
+            self.__mkdir_p(dumpdir)
             with open(os.path.join(dumpdir, 'error'), 'w') as f:
                 f.write(related_error)