Browse Source

Rename "LOGGER" to "LOG"

Align with OpenStack projects

Change-Id: Ie30b2819bce754650f3afa293935c2a0b551c217
Changbin Liu 5 years ago
parent
commit
02b6284ec2
5 changed files with 37 additions and 38 deletions
  1. 2
    2
      bin/orchestrator
  2. 26
    27
      inception/orchestrator.py
  3. 3
    3
      inception/utils/cmd.py
  4. 4
    4
      inception/utils/log.py
  5. 2
    2
      inception/utils/wrapper.py

+ 2
- 2
bin/orchestrator View File

@@ -10,7 +10,7 @@ from inception import __version__
10 10
 from inception.orchestrator import Orchestrator
11 11
 from inception.utils import log
12 12
 
13
-LOGGER = logging.getLogger(__name__)
13
+LOG = logging.getLogger(__name__)
14 14
 
15 15
 CONF = cfg.CONF
16 16
 
@@ -20,7 +20,7 @@ def main():
20 20
     try:
21 21
         CONF(args=sys.argv[1:], version="Inception: version %s" % __version__)
22 22
     except Exception as e:
23
-        LOGGER.error(e)
23
+        LOG.error(e)
24 24
         sys.exit(1)
25 25
     # start orchestator
26 26
     log.setup('inception')

+ 26
- 27
inception/orchestrator.py View File

@@ -48,7 +48,7 @@ from oslo.config import cfg
48 48
 from inception.utils import cmd
49 49
 from inception.utils import wrapper
50 50
 
51
-LOGGER = logging.getLogger(__name__)
51
+LOG = logging.getLogger(__name__)
52 52
 
53 53
 orchestrator_opts = [
54 54
     cfg.StrOpt('prefix',
@@ -259,19 +259,18 @@ class Orchestrator(object):
259 259
             self._deploy_dnsmasq()
260 260
             self._setup_controller()
261 261
             self._setup_workers()
262
-            LOGGER.info("Your inception cloud '%s' is ready!!!", self.prefix)
263
-            LOGGER.info("Gateway IP is %s", self._gateway_floating_ip.ip)
264
-            LOGGER.info("Chef server WebUI is http://%s:4040",
265
-                        self._chefserver_ip)
266
-            LOGGER.info("OpenStack dashboard is https://%s",
267
-                        self._controller_ip)
262
+            LOG.info("Your inception cloud '%s' is ready!!!", self.prefix)
263
+            LOG.info("Gateway IP is %s", self._gateway_floating_ip.ip)
264
+            LOG.info("Chef server WebUI is http://%s:4040",
265
+                     self._chefserver_ip)
266
+            LOG.info("OpenStack dashboard is https://%s", self._controller_ip)
268 267
         except Exception:
269
-            LOGGER.exception("Error in launching inception cloud")
268
+            LOG.exception("Error in launching inception cloud")
270 269
             if self.atomic:
271 270
                 self.cleanup()
272
-                LOGGER.info("Although there was error in creating your "
273
-                            "inception cloud '%s', resources have been "
274
-                            "successfully cleaned up", self.prefix)
271
+                LOG.info("Although there was error in creating your "
272
+                         "inception cloud '%s', resources have been "
273
+                         "successfully cleaned up", self.prefix)
275 274
             if re_raise:
276 275
                 raise
277 276
 
@@ -324,7 +323,7 @@ class Orchestrator(object):
324 323
             security_groups=self.security_groups,
325 324
             userdata=self.userdata)
326 325
         self._gateway_id = gateway.id
327
-        LOGGER.info("Creating %s", gateway)
326
+        LOG.info("Creating %s", gateway)
328 327
 
329 328
         # launch chefserver
330 329
         chefserver = self.client.servers.create(
@@ -336,7 +335,7 @@ class Orchestrator(object):
336 335
             userdata=self.userdata,
337 336
             files=self.chefserver_files)
338 337
         self._chefserver_id = chefserver.id
339
-        LOGGER.info("Creating %s", chefserver)
338
+        LOG.info("Creating %s", chefserver)
340 339
 
341 340
         # launch controller
342 341
         controller = self.client.servers.create(
@@ -347,7 +346,7 @@ class Orchestrator(object):
347 346
             security_groups=self.security_groups,
348 347
             userdata=self.userdata)
349 348
         self._controller_id = controller.id
350
-        LOGGER.info("Creating %s", controller)
349
+        LOG.info("Creating %s", controller)
351 350
 
352 351
         # launch workers
353 352
         for i in xrange(self.num_workers):
@@ -359,10 +358,10 @@ class Orchestrator(object):
359 358
                 security_groups=self.security_groups,
360 359
                 userdata=self.userdata)
361 360
             self._worker_ids.append(worker.id)
362
-            LOGGER.info("Creating %s", worker)
361
+            LOG.info("Creating %s", worker)
363 362
 
364
-        LOGGER.info('wait at most %s seconds for servers to be ready'
365
-                    ' (ssh-able + userdata done)', self.timeout)
363
+        LOG.info('wait at most %s seconds for servers to be ready'
364
+                 ' (ssh-able + userdata done)', self.timeout)
366 365
         servers_ready = False
367 366
         begin_time = time.time()
368 367
         while time.time() - begin_time <= self.timeout:
@@ -392,8 +391,8 @@ class Orchestrator(object):
392 391
                 servers_ready = True
393 392
                 break
394 393
             except (UnboundLocalError, subprocess.CalledProcessError) as error:
395
-                LOGGER.info('servers are not all ready, error=%s,'
396
-                            ' sleep %s seconds', error, self.poll_interval)
394
+                LOG.info('servers are not all ready, error=%s,'
395
+                         ' sleep %s seconds', error, self.poll_interval)
397 396
                 time.sleep(self.poll_interval)
398 397
                 continue
399 398
         if not servers_ready:
@@ -403,7 +402,7 @@ class Orchestrator(object):
403 402
         floating_ip = self.client.floating_ips.create(pool=self.pool)
404 403
         self.client.servers.add_floating_ip(self._gateway_id, floating_ip)
405 404
         self._gateway_floating_ip = floating_ip
406
-        LOGGER.info("Creating and associating %s", floating_ip)
405
+        LOG.info("Creating and associating %s", floating_ip)
407 406
 
408 407
     def _get_server_info(self, _id):
409 408
         """
@@ -549,7 +548,7 @@ class Orchestrator(object):
549 548
             got_exception = not exception_queue.empty()
550 549
             while not exception_queue.empty():
551 550
                 thread_name, func_info, exc = exception_queue.get()
552
-                LOGGER.error('%s %s %s', thread_name, func_info, exc)
551
+                LOG.error('%s %s %s', thread_name, func_info, exc)
553 552
             if got_exception:
554 553
                 raise RuntimeError("One or more subthreads got exception")
555 554
 
@@ -577,7 +576,7 @@ class Orchestrator(object):
577 576
         @param re_raise: whether re-raise caught exception, for the purpose of
578 577
             notifying external caller. Default: False
579 578
         """
580
-        LOGGER.info("Let's clean up inception cloud '%s'...", self.prefix)
579
+        LOG.info("Let's clean up inception cloud '%s'...", self.prefix)
581 580
         ## find out servers info
582 581
         servers = []
583 582
         gateway = None
@@ -596,22 +595,22 @@ class Orchestrator(object):
596 595
         try:
597 596
             for floating_ip in self.client.floating_ips.list():
598 597
                 if floating_ip.ip == gateway_ip:
599
-                    LOGGER.info("Disassociating and releasing %s", floating_ip)
598
+                    LOG.info("Disassociating and releasing %s", floating_ip)
600 599
                     self.client.servers.remove_floating_ip(gateway,
601 600
                                                            floating_ip)
602 601
                     self.client.floating_ips.delete(floating_ip)
603 602
         except Exception:
604
-            LOGGER.exception("Error in disassociating/releasing floating IP")
603
+            LOG.exception("Error in disassociating/releasing floating IP")
605 604
             if re_raise:
606 605
                 raise
607 606
         ## try deleting each server
608 607
         for server in servers:
609 608
             try:
610
-                LOGGER.info('Deleting %s', server)
609
+                LOG.info('Deleting %s', server)
611 610
                 server.delete()
612 611
             except Exception:
613
-                LOGGER.exception("Error in deleting server %s", server)
612
+                LOG.exception("Error in deleting server %s", server)
614 613
                 if re_raise:
615 614
                     raise
616 615
                 continue
617
-        LOGGER.info("Inception cloud '%s' has been cleaned up.", self.prefix)
616
+        LOG.info("Inception cloud '%s' has been cleaned up.", self.prefix)

+ 3
- 3
inception/utils/cmd.py View File

@@ -22,7 +22,7 @@
22 22
 import logging
23 23
 import subprocess
24 24
 
25
-LOGGER = logging.getLogger(__name__)
25
+LOG = logging.getLogger(__name__)
26 26
 
27 27
 
28 28
 def local(cmd, screen_output=False):
@@ -35,7 +35,7 @@ def local(cmd, screen_output=False):
35 35
     @return: (output, error)
36 36
       if screen_output is True, return ("", "")
37 37
     """
38
-    LOGGER.info('executing command=%s', cmd)
38
+    LOG.info('executing command=%s', cmd)
39 39
     stdout, stderr = ((None, None) if screen_output
40 40
                       else (subprocess.PIPE, subprocess.PIPE))
41 41
     proc = subprocess.Popen(cmd,
@@ -84,7 +84,7 @@ def ssh(uri, cmd, screen_output=False, silent=True, agent_forwarding=False):
84 84
     if agent_forwarding:
85 85
         flags.append('-A')
86 86
     cmd = 'ssh -p %s %s %s %s' % (port, ' '.join(flags), uri, cmd)
87
-    LOGGER.info('executing command=%s', cmd)
87
+    LOG.info('executing command=%s', cmd)
88 88
     stdout, stderr = ((None, None) if screen_output
89 89
                       else (subprocess.PIPE, subprocess.PIPE))
90 90
     proc = subprocess.Popen(cmd,

+ 4
- 4
inception/utils/log.py View File

@@ -55,14 +55,14 @@ LOG_LEVELS = {
55 55
 
56 56
 def setup(product_name):
57 57
     """setup logger and its handlers"""
58
-    LOGGER = logging.getLogger(product_name)
58
+    LOG = logging.getLogger(product_name)
59 59
     log_level = LOG_LEVELS[CONF.log_level]
60
-    LOGGER.setLevel(log_level)
60
+    LOG.setLevel(log_level)
61 61
     ## console logging
62 62
     console_handler = logging.StreamHandler()
63 63
     console_handler.setLevel(log_level)
64 64
     console_handler.setFormatter(CONF.log_formatter)
65
-    LOGGER.addHandler(console_handler)
65
+    LOG.addHandler(console_handler)
66 66
     ## file logging
67 67
     if CONF.log_dir is not None and CONF.log_file is not None:
68 68
         if not os.path.exists(CONF.log_dir):
@@ -71,4 +71,4 @@ def setup(product_name):
71 71
                                                         CONF.log_file))
72 72
         file_handler.setLevel(log_level)
73 73
         file_handler.setFormatter(CONF.log_formatter)
74
-        LOGGER.addHandler(file_handler)
74
+        LOG.addHandler(file_handler)

+ 2
- 2
inception/utils/wrapper.py View File

@@ -23,7 +23,7 @@ import logging
23 23
 import threading
24 24
 import traceback
25 25
 
26
-LOGGER = logging.getLogger(__name__)
26
+LOG = logging.getLogger(__name__)
27 27
 
28 28
 
29 29
 class FuncThread(threading.Thread):
@@ -46,5 +46,5 @@ class FuncThread(threading.Thread):
46 46
             func_info = (str(self._func.func) + " " + str(self._func.args) +
47 47
                          " " + str(self._func.keywords))
48 48
             info = (self.name, func_info, traceback.format_exc())
49
-            LOGGER.info(info)
49
+            LOG.info(info)
50 50
             self._exception_queue.put(info)

Loading…
Cancel
Save