support pep8 check
[doctor.git] / doctor_tests / main.py
index 0ea9d36..3f34635 100644 (file)
@@ -33,10 +33,9 @@ from doctor_tests.scenario.network_failure import NetworkFault
 from doctor_tests.user import User
 
 
-LOG = doctor_log.Logger('doctor').getLogger()
-
-# TODO (r-mibu): fix doctor logger or consider logfile option
-LOG_FILE = LOG.handlers[0].baseFilename
+Logger = doctor_log.Logger('doctor')
+LOG = Logger.getLogger()
+LogFile = Logger.getLogFilename()
 
 
 class DoctorTest(object):
@@ -96,7 +95,8 @@ class DoctorTest(object):
             self.setup()
 
             # wait for aodh alarms are updated in caches for event evaluator,
-            # sleep time should be larger than event_alarm_cache_ttl(default 60)
+            # sleep time should be larger than event_alarm_cache_ttl
+            # (default 60)
             time.sleep(60)
 
             # injecting host failure...
@@ -109,11 +109,13 @@ class DoctorTest(object):
             # NOTE (umar) copy remote monitor.log file when monitor=collectd
             self.check_host_status(self.down_host.name, 'down')
 
-            notification_time = calculate_notification_time(LOG_FILE)
+            notification_time = calculate_notification_time(LogFile)
             if notification_time < 1 and notification_time > 0:
-                LOG.info('doctor test successfully, notification_time=%s' % notification_time)
+                LOG.info('doctor test successfully, notification_time=%s'
+                         % notification_time)
             else:
-                LOG.error('doctor test failed, notification_time=%s' % notification_time)
+                LOG.error('doctor test failed, notification_time=%s'
+                          % notification_time)
                 sys.exit(1)
 
             if self.conf.profiler_type:
@@ -145,13 +147,15 @@ class DoctorTest(object):
         return Host(host_name, host_ip)
 
     def check_host_status(self, hostname, state):
-        service = self.nova.services.list(host=hostname, binary='nova-compute')
+        service = self.nova.services.list(host=hostname,
+                                          binary='nova-compute')
         host_state = service[0].__dict__.get('state')
         assert host_state == state
 
     def unset_forced_down_hosts(self):
         if self.down_host:
-            self.nova.services.force_down(self.down_host.name, 'nova-compute', False)
+            self.nova.services.force_down(self.down_host.name,
+                                          'nova-compute', False)
             time.sleep(2)
             self.check_host_status(self.down_host.name, 'up')
 
@@ -159,31 +163,36 @@ class DoctorTest(object):
         self.fault.get_disable_network_log()
 
     def run_profiler(self):
-        test_dir = os.path.split(os.path.realpath(__file__))[0]
 
+        net_down_log_file = self.fault.get_disable_network_log()
         reg = '(?<=doctor set link down at )\d+.\d+'
-        linkdown = float(match_rep_in_file(reg, LOG_FILE).group(0))
+        linkdown = float(match_rep_in_file(reg, net_down_log_file).group(0))
 
         reg = '(.* doctor mark vm.* error at )(\d+.\d+)'
-        vmdown = float(match_rep_in_file(reg, LOG_FILE).group(2))
+        vmdown = float(match_rep_in_file(reg, LogFile).group(2))
 
         reg = '(.* doctor mark host.* down at )(\d+.\d+)'
-        hostdown = float(match_rep_in_file(reg, LOG_FILE).group(2))
+        hostdown = float(match_rep_in_file(reg, LogFile).group(2))
 
         reg = '(?<=doctor monitor detected at )\d+.\d+'
-        detected = float(match_rep_in_file(reg, LOG_FILE).group(0))
+        detected = float(match_rep_in_file(reg, LogFile).group(0))
 
         reg = '(?<=doctor consumer notified at )\d+.\d+'
-        notified = float(match_rep_in_file(reg, LOG_FILE).group(0))
+        notified = float(match_rep_in_file(reg, LogFile).group(0))
 
         # TODO(yujunz) check the actual delay to verify time sync status
         # expected ~1s delay from $trigger to $linkdown
         relative_start = linkdown
-        os.environ['DOCTOR_PROFILER_T00'] = str(int((linkdown - relative_start)*1000))
-        os.environ['DOCTOR_PROFILER_T01'] = str(int((detected - relative_start) * 1000))
-        os.environ['DOCTOR_PROFILER_T03'] = str(int((vmdown - relative_start) * 1000))
-        os.environ['DOCTOR_PROFILER_T04'] = str(int((hostdown - relative_start) * 1000))
-        os.environ['DOCTOR_PROFILER_T09'] = str(int((notified - relative_start) * 1000))
+        os.environ['DOCTOR_PROFILER_T00'] = \
+            str(int((linkdown - relative_start) * 1000))
+        os.environ['DOCTOR_PROFILER_T01'] = \
+            str(int((detected - relative_start) * 1000))
+        os.environ['DOCTOR_PROFILER_T03'] = \
+            str(int((vmdown - relative_start) * 1000))
+        os.environ['DOCTOR_PROFILER_T04'] = \
+            str(int((hostdown - relative_start) * 1000))
+        os.environ['DOCTOR_PROFILER_T09'] = \
+            str(int((notified - relative_start) * 1000))
 
         profiler_main(log=LOG)
 
@@ -207,7 +216,8 @@ def main():
     doctor_root_dir = os.path.dirname(test_dir)
 
     config_file_dir = '{0}/{1}'.format(doctor_root_dir, 'etc/')
-    config_files = [join(config_file_dir, f) for f in os.listdir(config_file_dir)
+    config_files = [join(config_file_dir, f)
+                    for f in os.listdir(config_file_dir)
                     if isfile(join(config_file_dir, f))]
 
     conf = config.prepare_conf(args=sys.argv[1:],