Merge "Introducing common functions"
authorRyota Mibu <r-mibu@cq.jp.nec.com>
Thu, 8 Dec 2016 20:30:07 +0000 (20:30 +0000)
committerGerrit Code Review <gerrit@opnfv.org>
Thu, 8 Dec 2016 20:30:07 +0000 (20:30 +0000)
UPSTREAM [new file with mode: 0644]
docs/requirements/02-use_cases.rst
docs/requirements/03-architecture.rst
docs/requirements/images/figure1.png [changed mode: 0755->0644]
docs/requirements/images/figure2.png [changed mode: 0755->0644]
tests/consumer.py
tests/inspector.py
tests/logger.py [new file with mode: 0644]
tests/monitor.py
tests/run.sh

diff --git a/UPSTREAM b/UPSTREAM
new file mode 100644 (file)
index 0000000..d881040
--- /dev/null
+++ b/UPSTREAM
@@ -0,0 +1,39 @@
+# Upstream contributions, bitergia will crawl this and extract the relevant information
+# system is one of Gerrit, Bugzilla, Launchpad (insert more)
+---
+-
+  url: https://blueprints.launchpad.net/ceilometer/+spec/event-alarm-evaluator
+  system: Launchpad
+-
+  url: https://blueprints.launchpad.net/nova/+spec/mark-host-down
+  system: Launchpad
+-
+  url: https://blueprints.launchpad.net/python-novaclient/+spec/support-force-down-service
+  system: Launchpad
+-
+  url: https://blueprints.launchpad.net/nova/+spec/get-valid-server-state
+  system: Launchpad
+-
+  url: https://blueprints.launchpad.net/nova/+spec/servers-by-host-status
+  system: Launchpad
+-
+  url: https://blueprints.launchpad.net/nova/+spec/maintenance-reason-to-server
+  system: Launchpad
+-
+  url: https://blueprints.launchpad.net/nova/+spec/service-status-notification
+  system: Launchpad
+-
+  url: https://blueprints.launchpad.net/congress/+spec/push-type-datasource-driver
+  system: Launchpad
+#-
+#  url: https://review.openstack.org/#/c/314915/
+#  system: Gerrit
+-
+  url: https://blueprints.launchpad.net/cinder/+spec/mark-services-down
+  system: Launchpad
+-
+  url: https://blueprints.launchpad.net/python-cinderclient/+spec/mark-service-down-cli
+  system: Launchpad
+#-
+#  url: https://bugs.launchpad.net/neutron/+bug/1513144
+#  system: Launchpad-bug
index 424a3c6..0a1f641 100644 (file)
@@ -136,7 +136,7 @@ the same as in the "Fault management using ACT-STBY configuration" use case,
 except in this case, the Consumer of a VM/VNF switches to STBY configuration
 based on a predicted fault, rather than an occurred fault.
 
-NVFI Maintenance
+NFVI Maintenance
 ----------------
 
 VM Retirement
index 8ff5dac..9f620e6 100644 (file)
@@ -217,7 +217,7 @@ restart of the VM, migration/evacuation of the VM, or no action.
 High level northbound interface specification
 ---------------------------------------------
 
-Fault management
+Fault Management
 ^^^^^^^^^^^^^^^^
 
 This interface allows the Consumer to subscribe to fault notification from the
@@ -321,7 +321,7 @@ An example of a high level message flow to cover the failed NFVI maintenance cas
 shown in :numref:`figure5c`.
 It consists of the following steps:
 
-5. The Consumer C3 switches to standby configuration (STDBY).
+5. The Consumer C3 switches to standby configuration (STBY).
 6. Instructions from Consumers C2/C3 are shared to VIM requesting certain actions to be performed (steps 6a, 6b).
    The VIM executes the requested actions and sends back a NACK to consumer C2 (step 6d) as the
    migration of the virtual resource(s) is not completed by the given timeout.
old mode 100755 (executable)
new mode 100644 (file)
index dacf0dd..267dddd
Binary files a/docs/requirements/images/figure1.png and b/docs/requirements/images/figure1.png differ
old mode 100755 (executable)
new mode 100644 (file)
index 3c8a2bf..9a3b166
Binary files a/docs/requirements/images/figure2.png and b/docs/requirements/images/figure2.png differ
index 9b3230f..3c012b4 100644 (file)
@@ -11,17 +11,20 @@ import argparse
 from flask import Flask
 from flask import request
 import json
+import logger as doctor_log
 import os
 import time
 
+LOG = doctor_log.Logger('doctor_consumer').getLogger()
+
 
 app = Flask(__name__)
 
 
 @app.route('/failure', methods=['POST'])
 def event_posted():
-    app.logger.debug('doctor consumer notified at %s' % time.time())
-    app.logger.debug('received data = %s' % request.data)
+    LOG.info('doctor consumer notified at %s' % time.time())
+    LOG.info('received data = %s' % request.data)
     d = json.loads(request.data)
     return "OK"
 
@@ -35,7 +38,7 @@ def get_args():
 
 def main():
     args = get_args()
-    app.run(host="0.0.0.0", port=args.port, debug=True)
+    app.run(host="0.0.0.0", port=args.port)
 
 
 if __name__ == '__main__':
index 6261415..129a386 100644 (file)
@@ -12,6 +12,7 @@ import collections
 from flask import Flask
 from flask import request
 import json
+import logger as doctor_log
 import os
 import time
 
@@ -19,6 +20,8 @@ import novaclient.client as novaclient
 
 import nova_force_down
 
+LOG = doctor_log.Logger('doctor_inspector').getLogger()
+
 
 class DoctorInspectorSample(object):
 
@@ -44,9 +47,9 @@ class DoctorInspectorSample(object):
             try:
                 host=server.__dict__.get('OS-EXT-SRV-ATTR:host')
                 self.servers[host].append(server)
-                app.logger.debug('get hostname=%s from server=%s' % (host, server))
+                LOG.debug('get hostname=%s from server=%s' % (host, server))
             except Exception as e:
-                app.logger.debug('can not get hostname from server=%s' % server)
+                LOG.error('can not get hostname from server=%s' % server)
 
     def disable_compute_host(self, hostname):
         for server in self.servers[hostname]:
@@ -63,15 +66,14 @@ class DoctorInspectorSample(object):
 
 
 app = Flask(__name__)
-app.debug = True
 inspector = DoctorInspectorSample()
 
 
 @app.route('/events', methods=['POST'])
 def event_posted():
-    app.logger.debug('event posted at %s' % time.time())
-    app.logger.debug('inspector = %s' % inspector)
-    app.logger.debug('received data = %s' % request.data)
+    LOG.info('event posted at %s' % time.time())
+    LOG.info('inspector = %s' % inspector)
+    LOG.info('received data = %s' % request.data)
     d = json.loads(request.data)
     hostname = d['hostname']
     event_type = d['type']
@@ -91,5 +93,6 @@ def main():
     args = get_args()
     app.run(port=args.port)
 
+
 if __name__ == '__main__':
     main()
diff --git a/tests/logger.py b/tests/logger.py
new file mode 100644 (file)
index 0000000..a4f3323
--- /dev/null
@@ -0,0 +1,47 @@
+##############################################################################
+# Copyright (c) 2016 ZTE Corporation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+# Usage:
+#  import doctor_logger
+#  logger = doctor_logger.Logger("script_name").getLogger()
+#  logger.info("message to be shown with - INFO - ")
+#  logger.debug("message to be shown with - DEBUG -")
+
+import logging
+import os
+
+
+class Logger:
+    def __init__(self, logger_name):
+
+        CI_DEBUG = os.getenv('CI_DEBUG')
+
+        self.logger = logging.getLogger(logger_name)
+        self.logger.propagate = 0
+        self.logger.setLevel(logging.DEBUG)
+
+        formatter = logging.Formatter('%(asctime)s %(filename)s %(lineno)d '
+                                      '%(levelname)-6s %(message)s')
+
+        ch = logging.StreamHandler()
+        ch.setFormatter(formatter)
+        if CI_DEBUG is not None and CI_DEBUG.lower() == "true":
+            ch.setLevel(logging.DEBUG)
+        else:
+            ch.setLevel(logging.INFO)
+        self.logger.addHandler(ch)
+
+        file_handler = logging.FileHandler('%s.log' % logger_name)
+        file_handler.setFormatter(formatter)
+        file_handler.setLevel(logging.DEBUG)
+        self.logger.addHandler(file_handler)
+
+
+    def getLogger(self):
+        return self.logger
+
index caf4c32..26c911d 100644 (file)
@@ -10,6 +10,7 @@
 import argparse
 from datetime import datetime
 import json
+import logger as doctor_log
 import os
 import requests
 import socket
@@ -26,6 +27,8 @@ ICMP_ECHO_MESSAGE = '\x08\x00\xf7\xff\x00\x00\x00\x00'
 
 SUPPORTED_INSPECTOR_TYPES = ['sample', 'congress']
 
+LOG = doctor_log.Logger('doctor_monitor').getLogger()
+
 class DoctorMonitorSample(object):
 
     interval = 0.1  # second
@@ -58,8 +61,8 @@ class DoctorMonitorSample(object):
                                   (congress_endpoint, doctor_ds['id']))
 
     def start_loop(self):
-        print "start ping to host %(h)s (ip=%(i)s)" % {'h': self.hostname,
-                                                       'i': self.ip_addr}
+        LOG.debug("start ping to host %(h)s (ip=%(i)s)" % {'h': self.hostname,
+                                                       'i': self.ip_addr})
         sock = socket.socket(socket.AF_INET, socket.SOCK_RAW,
                              socket.IPPROTO_ICMP)
         sock.settimeout(self.timeout)
@@ -68,9 +71,9 @@ class DoctorMonitorSample(object):
                 sock.sendto(ICMP_ECHO_MESSAGE, (self.ip_addr, 0))
                 data = sock.recv(4096)
             except socket.timeout:
-                print "doctor monitor detected at %s" % time.time()
+                LOG.info("doctor monitor detected at %s" % time.time())
                 self.report_error()
-                print "ping timeout, quit monitoring..."
+                LOG.info("ping timeout, quit monitoring...")
                 return
             time.sleep(self.interval)
 
index 3c4afc1..ea7ded5 100755 (executable)
@@ -475,8 +475,8 @@ END_TXT
 }
 
 calculate_notification_time() {
-    detected=$(grep "doctor monitor detected at" monitor.log | awk '{print $5}')
-    notified=$(grep "doctor consumer notified at" consumer.log | awk '{print $5}')
+    detected=$(grep "doctor monitor detected at" monitor.log | awk '{print $10}')
+    notified=$(grep "doctor consumer notified at" consumer.log | awk '{print $10}')
     if ! grep -q "doctor consumer notified at" consumer.log ; then
         die $LINENO "Consumer hasn't received fault notification."
     fi