Switch print to logging.info 37/20337/1
authorCédric Ollivier <cedric.ollivier@orange.com>
Thu, 1 Sep 2016 11:52:28 +0000 (13:52 +0200)
committerMorgan Richomme <morgan.richomme@orange.com>
Mon, 5 Sep 2016 12:30:20 +0000 (12:30 +0000)
It follows the recommendations described in the next review [1].

[1] https://gerrit.opnfv.org/gerrit/#/c/19795/

Change-Id: Ie7ce28451122c554f135caad068844c0303deaeb
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
(cherry picked from commit 0ae5f5fc64868e8c68eb330fa5aa219abdbdfee0)

testcases/Controllers/ONOS/Teston/adapters/client.py
testcases/Controllers/ONOS/Teston/adapters/connection.py
testcases/Controllers/ONOS/Teston/adapters/environment.py
testcases/Controllers/ONOS/Teston/adapters/foundation.py
utils/openstack_clean.py

index 77de092..6b3285e 100644 (file)
@@ -10,15 +10,19 @@ Description:
 # http://www.apache.org/licenses/LICENSE-2.0
 #
 """
-from environment import environment
-import time
+import json
 import pexpect
 import requests
-import json
+import time
+
+from environment import environment
+import functest.utils.functest_logger as ft_logger
 
 
 class client(environment):
 
+    logger = ft_logger.Logger("client").getLogger()
+
     def __init__(self):
         environment.__init__(self)
         self.loginfo = environment()
@@ -50,7 +54,7 @@ class client(environment):
                                  [len(lastshowscreeninfo)::])
                 lastshowscreeninfo = curshowscreeninfo
             if Result == 0:
-                print "Done!"
+                self.logger.info("Done!")
                 return
             time.sleep(1)
             circletime += 1
@@ -61,7 +65,7 @@ class client(environment):
     def onosstart(self):
         # This is the compass run machine user&pass,you need to modify
 
-        print "Test Begin....."
+        self.logger.info("Test Begin.....")
         self.OnosConnectionSet()
         masterhandle = self.SSHlogin(self.localhost, self.masterusername,
                                      self.masterpassword)
index 16f2ef3..b2a2e3d 100644 (file)
@@ -16,11 +16,15 @@ Description:
 import os
 import pexpect
 import re
+
 from foundation import foundation
+import functest.utils.functest_logger as ft_logger
 
 
 class connection(foundation):
 
+    logger = ft_logger.Logger("connection").getLogger()
+
     def __init__(self):
         foundation.__init__(self)
         self.loginfo = foundation()
@@ -33,7 +37,7 @@ class connection(foundation):
         username: login user name
         password: login password
         """
-        print("Now Adding an user to known hosts " + ipaddr)
+        self.logger.info("Now Adding an user to known hosts " + ipaddr)
         login = handle
         login.sendline("ssh -l %s -p 8101 %s" % (username, ipaddr))
         index = 0
@@ -78,7 +82,7 @@ class connection(foundation):
         """
         Generate ssh keys, used for some server have no sshkey.
         """
-        print "Now Generating SSH keys..."
+        self.logger.info("Now Generating SSH keys...")
         # Here file name may be id_rsa or id_ecdsa or others
         # So here will have a judgement
         keysub = handle
@@ -112,7 +116,7 @@ class connection(foundation):
         parameters:
         password: root login password
         """
-        print("Now changing to user root")
+        self.logger.info("Now changing to user root")
         login = pexpect.spawn("su - root")
         index = 0
         while index != 2:
@@ -129,7 +133,7 @@ class connection(foundation):
         """
         Exit root user.
         """
-        print("Now Release user root")
+        self.logger.info("Now Release user root")
         login = pexpect.spawn("exit")
         index = login.expect(['logout', pexpect.EOF, pexpect.TIMEOUT])
         if index == 0:
@@ -145,7 +149,7 @@ class connection(foundation):
         parameters:
         envalue: environment value to add
         """
-        print "Now Adding bash environment"
+        self.logger.info("Now Adding bash environment")
         fileopen = open("/etc/profile", 'r')
         findContext = 1
         while findContext:
@@ -165,7 +169,7 @@ class connection(foundation):
         Change ONOS root path in file:bash_profile
         onospath: path of onos root
         """
-        print "Now Changing ONOS Root Path"
+        self.logger.info("Now Changing ONOS Root Path")
         filepath = onospath + 'onos/tools/dev/bash_profile'
         line = open(filepath, 'r').readlines()
         lenall = len(line) - 1
@@ -175,7 +179,7 @@ class connection(foundation):
         NewFile = open(filepath, 'w')
         NewFile.writelines(line)
         NewFile.close
-        print "Done!"
+        self.logger.info("Done!")
 
     def OnosConnectionSet(self):
         """
index 2316773..f2755b6 100644 (file)
@@ -15,17 +15,21 @@ Description:
 #
 """
 
-import os
-import time
 import pexpect
+import pxssh
 import re
+import os
 import sys
-import pxssh
+import time
+
 from connection import connection
+import functest.utils.functest_logger as ft_logger
 
 
 class environment(connection):
 
+    logger = ft_logger.Logger("environment").getLogger()
+
     def __init__(self):
         connection.__init__(self)
         self.loginfo = connection()
@@ -39,9 +43,9 @@ class environment(connection):
         handle:  current working handle
         codeurl: clone code url
         """
-        print "Now loading test codes! Please wait in patient..."
+        self.logger.info("Now loading test codes! Please wait in patient...")
         originalfolder = sys.path[0]
-        print originalfolder
+        self.logger.info(originalfolder)
         gitclone = handle
         gitclone.sendline("git clone " + codeurl)
         index = 0
@@ -82,7 +86,7 @@ class environment(connection):
         parameters:
         handle(input): current working handle
         """
-        print "Now Cleaning test environment"
+        self.logger.info("Now Cleaning test environment")
         handle.sendline("sudo apt-get install -y mininet")
         handle.prompt()
         handle.sendline("sudo pip install configobj")
@@ -102,7 +106,7 @@ class environment(connection):
         cmd(input): onos-push-keys xxx(xxx is device)
         password(input): login in password
         """
-        print "Now Pushing Onos Keys:" + cmd
+        self.logger.info("Now Pushing Onos Keys:" + cmd)
         Pushkeys = handle
         Pushkeys.sendline(cmd)
         Result = 0
@@ -121,7 +125,7 @@ class environment(connection):
                 break
             time.sleep(2)
         Pushkeys.prompt()
-        print "Done!"
+        self.logger.info("Done!")
 
     def SetOnosEnvVar(self, handle, masterpass, agentpass):
         """
@@ -131,13 +135,14 @@ class environment(connection):
         masterpass: scripts running server's password
         agentpass: onos cluster&compute node password
         """
-        print "Now Setting test environment"
+        self.logger.info("Now Setting test environment")
         for host in self.hosts:
-            print "try to connect " + str(host)
+            self.logger.info("try to connect " + str(host))
             result = self.CheckSshNoPasswd(host)
             if not result:
-                print ("ssh login failed,try to copy master publickey" +
-                       "to agent " + str(host))
+                self.logger.info(
+                        "ssh login failed,try to copy master publickey" +
+                        "to agent " + str(host))
                 self.CopyPublicKey(host)
         self.OnosPushKeys(handle, "onos-push-keys " + self.OCT, masterpass)
         self.OnosPushKeys(handle, "onos-push-keys " + self.OC1, agentpass)
@@ -173,7 +178,7 @@ class environment(connection):
         user: onos&compute node user
         password: onos&compute node password
         """
-        print "Now Changing ONOS name&password"
+        self.logger.info("Now Changing ONOS name&password")
         filepath = self.home + '/onos/tools/build/envDefaults'
         line = open(filepath, 'r').readlines()
         lenall = len(line) - 1
@@ -187,7 +192,7 @@ class environment(connection):
         NewFile = open(filepath, 'w')
         NewFile.writelines(line)
         NewFile.close
-        print "Done!"
+        self.logger.info("Done!")
 
     def ChangeTestCasePara(self, testcase, user, password):
         """
@@ -196,7 +201,7 @@ class environment(connection):
         user: onos&compute node user
         password: onos&compute node password
         """
-        print "Now Changing " + testcase + " name&password"
+        self.logger.info("Now Changing " + testcase + " name&password")
         if self.masterusername == 'root':
             filepath = '/root/'
         else:
@@ -232,7 +237,7 @@ class environment(connection):
         login.sendline('ls -l')
         # match prompt
         login.prompt()
-        print("SSH login " + ipaddr + " success!")
+        self.logger.info("SSH login " + ipaddr + " success!")
         return login
 
     def SSHRelease(self, handle):
@@ -256,7 +261,7 @@ class environment(connection):
                            str(publickey) + ">>/root/.ssh/authorized_keys\'")
         tmphandle.prompt()
         self.SSHRelease(tmphandle)
-        print "Add OCT PublicKey to " + host + " success"
+        self.logger.info("Add OCT PublicKey to " + host + " success")
 
     def OnosEnvSetup(self, handle):
         """
index 70c84ac..3fae2a5 100644 (file)
@@ -16,8 +16,8 @@ import logging
 import os
 import re
 import time
-
 import yaml
+
 from functest.utils.functest_utils import FUNCTEST_REPO as FUNCTEST_REPO
 
 
@@ -49,7 +49,6 @@ class foundation:
                             filemode='w')
         filelog = logging.FileHandler(self.logfilepath)
         logging.getLogger('Functest').addHandler(filelog)
-        print loginfo
         logging.info(loginfo)
 
     def getdefaultpara(self):
index 3b937c9..ef26be1 100755 (executable)
@@ -233,7 +233,7 @@ def remove_ports(neutron_client, ports, network_ids):
             except:
                 logger.debug("  > WARNING: Port %s does not contain fixed_ips"
                              % port_id)
-                print port
+                logger.info(port)
             router_id = port['device_id']
             if len(port['fixed_ips']) == 0 and router_id == '':
                 logger.debug("Removing port %s ..." % port_id)