]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Use built-in print() instead of print statement
authorChang Bo Guo <guochbo@cn.ibm.com>
Wed, 18 Sep 2013 09:35:53 +0000 (02:35 -0700)
committerChang Bo Guo <guochbo@cn.ibm.com>
Sat, 21 Sep 2013 14:30:33 +0000 (07:30 -0700)
In python 3 print statement is not supported, so we should use
only print() functions.

This patch also removes print in unit test, left by accident

Fixes bug 1226943

Change-Id: I5ace50cb9e149682344b4c986ef9318f8dc50f72

17 files changed:
bin/neutron-rootwrap-xen-dom0
bin/quantum-rootwrap-xen-dom0
neutron/plugins/bigswitch/tests/test_server.py
neutron/plugins/bigswitch/version.py
neutron/plugins/brocade/tests/noscli.py
neutron/plugins/brocade/tests/nostest.py
neutron/plugins/nicira/check_nvp_config.py
neutron/plugins/nicira/vshield/tasks/tasks.py
neutron/tests/unit/database_stubs.py
neutron/tests/unit/nec/test_nec_agent.py
neutron/tests/unit/nec/test_pfc_driver.py
neutron/tests/unit/nec/test_trema_driver.py
neutron/tests/unit/nicira/test_vcns_driver.py
neutron/tests/unit/test_extension_allowedaddresspairs.py
neutron/wsgi.py
tools/check_i18n.py
tools/install_venv.py

index fd0b0c9895c6f3e0ad655a82a18c1ab50fd6f91e..2f7dc872496d49621bf3e4d40cf3b11bd212b832 100755 (executable)
@@ -21,6 +21,7 @@ Executes networking commands in dom0.  The XenAPI plugin is
 responsible determining whether a command is safe to execute.
 
 """
+from __future__ import print_function
 
 import ConfigParser
 import json
@@ -42,7 +43,7 @@ def parse_args():
     exec_name = sys.argv.pop(0)
     # argv[0] required; path to conf file
     if len(sys.argv) < 2:
-        print "%s: No command specified" % exec_name
+        print("%s: No command specified" % exec_name)
         sys.exit(RC_NOCOMMAND)
 
     config_file = sys.argv.pop(0)
@@ -56,7 +57,7 @@ def _xenapi_section_name(config):
     if len(sections) == 1:
         return sections[0]
 
-    print "Multiple [xenapi] sections or no [xenapi] section found!"
+    print("Multiple [xenapi] sections or no [xenapi] section found!")
     sys.exit(RC_BADCONFIG)
 
 
@@ -71,13 +72,13 @@ def load_configuration(exec_name, config_file):
         username = config.get(section, "xenapi_connection_username")
         password = config.get(section, "xenapi_connection_password")
     except ConfigParser.Error:
-        print "%s: Incorrect configuration file: %s" % (exec_name, config_file)
+        print("%s: Incorrect configuration file: %s" % (exec_name, config_file))
         sys.exit(RC_BADCONFIG)
     if not url or not password:
         msg = ("%s: Must specify xenapi_connection_url, "
                "xenapi_connection_username (optionally), and "
                "xenapi_connection_password in %s") % (exec_name, config_file)
-        print msg
+        print(msg)
         sys.exit(RC_BADCONFIG)
     return dict(
         filters_path=filters_path,
@@ -102,7 +103,7 @@ def filter_command(exec_name, filters_path, user_args, exec_dirs):
     filter_match = wrapper.match_filter(
         filters, user_args, exec_dirs=exec_dirs)
     if not filter_match:
-        print "Unauthorized command: %s" % ' '.join(user_args)
+        print("Unauthorized command: %s" % ' '.join(user_args))
         sys.exit(RC_UNAUTHORIZED)
 
 
@@ -128,4 +129,4 @@ def main():
 
 
 if __name__ == '__main__':
-    print main()
+    print(main())
index fd0b0c9895c6f3e0ad655a82a18c1ab50fd6f91e..2f7dc872496d49621bf3e4d40cf3b11bd212b832 100755 (executable)
@@ -21,6 +21,7 @@ Executes networking commands in dom0.  The XenAPI plugin is
 responsible determining whether a command is safe to execute.
 
 """
+from __future__ import print_function
 
 import ConfigParser
 import json
@@ -42,7 +43,7 @@ def parse_args():
     exec_name = sys.argv.pop(0)
     # argv[0] required; path to conf file
     if len(sys.argv) < 2:
-        print "%s: No command specified" % exec_name
+        print("%s: No command specified" % exec_name)
         sys.exit(RC_NOCOMMAND)
 
     config_file = sys.argv.pop(0)
@@ -56,7 +57,7 @@ def _xenapi_section_name(config):
     if len(sections) == 1:
         return sections[0]
 
-    print "Multiple [xenapi] sections or no [xenapi] section found!"
+    print("Multiple [xenapi] sections or no [xenapi] section found!")
     sys.exit(RC_BADCONFIG)
 
 
@@ -71,13 +72,13 @@ def load_configuration(exec_name, config_file):
         username = config.get(section, "xenapi_connection_username")
         password = config.get(section, "xenapi_connection_password")
     except ConfigParser.Error:
-        print "%s: Incorrect configuration file: %s" % (exec_name, config_file)
+        print("%s: Incorrect configuration file: %s" % (exec_name, config_file))
         sys.exit(RC_BADCONFIG)
     if not url or not password:
         msg = ("%s: Must specify xenapi_connection_url, "
                "xenapi_connection_username (optionally), and "
                "xenapi_connection_password in %s") % (exec_name, config_file)
-        print msg
+        print(msg)
         sys.exit(RC_BADCONFIG)
     return dict(
         filters_path=filters_path,
@@ -102,7 +103,7 @@ def filter_command(exec_name, filters_path, user_args, exec_dirs):
     filter_match = wrapper.match_filter(
         filters, user_args, exec_dirs=exec_dirs)
     if not filter_match:
-        print "Unauthorized command: %s" % ' '.join(user_args)
+        print("Unauthorized command: %s" % ' '.join(user_args))
         sys.exit(RC_UNAUTHORIZED)
 
 
@@ -128,4 +129,4 @@ def main():
 
 
 if __name__ == '__main__':
-    print main()
+    print(main())
index e37d6ea3dde890b78b74d7432dbb03535075c7aa..a3bfccdede279cecf6f538fb27d8afb2d5804afd 100755 (executable)
@@ -22,6 +22,7 @@
 
 Used for NeutronRestProxy tests
 """
+from __future__ import print_function
 
 import json
 import re
@@ -128,15 +129,15 @@ class TestNetworkCtrl(object):
                         pass
 
             if self.debug:
-                print '\n'
+                print('\n')
                 if self.debug_env:
-                    print '%s:' % 'environ:'
+                    print('environ:')
                     for (key, value) in sorted(environ.iteritems()):
-                        print '  %16s : %s' % (key, value)
+                        print('  %16s : %s' % (key, value))
 
-                print '%s %s' % (method, uri)
+                print('%s %s' % (method, uri))
                 if request_data:
-                    print '%s' % (
+                    print('%s' %
                           json.dumps(request_data, sort_keys=True, indent=4))
 
             status, body = self.request_handler(method, uri, None)
@@ -151,13 +152,13 @@ class TestNetworkCtrl(object):
             start_response(status, headers)
             if self.debug:
                 if self.debug_env:
-                    print '%s: %s' % ('Response',
-                          json.dumps(body_data, sort_keys=True, indent=4))
+                    print('%s: %s' % ('Response',
+                          json.dumps(body_data, sort_keys=True, indent=4)))
             return body
         return make_server(self.host, self.port, app)
 
     def run(self):
-        print "Serving on port %d ..." % self.port
+        print("Serving on port %d ..." % self.port)
         try:
             self.server().serve_forever()
         except KeyboardInterrupt:
index fa0ca26cc6ccbab406f867ba556858e19354a2e5..90c8229cb8cfa8c91895055ef888a029f317788b 100755 (executable)
@@ -20,6 +20,7 @@
 # @author: Mandeep Dhami, Big Switch Networks, Inc.
 
 """Determine version of NeutronRestProxy plugin"""
+from __future__ import print_function
 
 # if vcsversion exists, use it. Else, use LOCALBRANCH:LOCALREVISION
 try:
@@ -61,4 +62,4 @@ def version_string_with_vcs():
 
 
 if __name__ == "__main__":
-    print version_string_with_vcs()
+    print(version_string_with_vcs())
index a009e3c0a8928c5ae9f3bbc0d137b852d0b67656..81e988e3cc8b9357fd9ed882a860e3a29b89b245 100644 (file)
@@ -21,6 +21,7 @@
 
 
 """Brocade NOS Driver CLI."""
+from __future__ import print_function
 
 import argparse
 
@@ -50,7 +51,7 @@ class NOSCli(object):
         elif args.cmd == 'dissociate' and numargs == 2:
             self._dissociate(args.otherargs[0], args.otherargs[1])
         else:
-            print usage_desc
+            print(usage_desc)
             exit(0)
 
     def _create(self, net_id):
index 22dd1e2c0350502910cbf77b88b83b1413b75e74..72a21ae8ba78e46cb80a640625d628c8d85743ba 100644 (file)
@@ -19,6 +19,8 @@
 
 
 """Brocade NOS Driver Test."""
+from __future__ import print_function
+
 import sys
 
 from neutron.plugins.brocade.nos import nosdriver as nos
@@ -38,8 +40,8 @@ def nostest(host, username, password):
 
     # AMPP enumeration
     with driver.connect(host, username, password) as mgr:
-        print driver.get_port_profiles(mgr)
-        print driver.get_port_profile(mgr, 'default')
+        print(driver.get_port_profiles(mgr))
+        print(driver.get_port_profile(mgr, 'default'))
 
 
 if __name__ == '__main__':
index d65d47e05363db42a4ab2240fd71cf525e22e674..092dfba326028d65d9371e29e696db81db42a538 100644 (file)
@@ -18,6 +18,8 @@
 #
 # @author: Aaron Rosen, VMware
 
+from __future__ import print_function
+
 import sys
 
 from oslo.config import cfg
@@ -31,7 +33,7 @@ config.setup_logging(cfg.CONF)
 
 
 def help(name):
-    print "Usage: %s path/to/nvp.ini" % name
+    print("Usage: %s path/to/nvp.ini" % name)
     sys.exit(1)
 
 
@@ -55,33 +57,33 @@ def main(argv):
     args = ['--config-file']
     args.append(argv[1])
     config.parse(args)
-    print "------------------------ Database Options ------------------------"
-    print "\tconnection: %s" % cfg.CONF.database.connection
-    print "\tretry_interval: %d" % cfg.CONF.database.retry_interval
-    print "\tmax_retries: %d" % cfg.CONF.database.max_retries
-    print "------------------------    NVP Options   ------------------------"
-    print "\tNVP Generation Timeout %d" % cfg.CONF.NVP.nvp_gen_timeout
-    print ("\tNumber of concurrent connections to each controller %d" %
-           cfg.CONF.NVP.concurrent_connections)
-    print "\tmax_lp_per_bridged_ls: %s" % cfg.CONF.NVP.max_lp_per_bridged_ls
-    print "\tmax_lp_per_overlay_ls: %s" % cfg.CONF.NVP.max_lp_per_overlay_ls
-    print "------------------------  Cluster Options ------------------------"
-    print "\trequested_timeout: %s" % cfg.CONF.req_timeout
-    print "\tretries: %s" % cfg.CONF.retries
-    print "\tredirects: %s" % cfg.CONF.redirects
-    print "\thttp_timeout: %s" % cfg.CONF.http_timeout
+    print("----------------------- Database Options -----------------------")
+    print("\tconnection: %s" % cfg.CONF.database.connection)
+    print("\tretry_interval: %d" % cfg.CONF.database.retry_interval)
+    print("\tmax_retries: %d" % cfg.CONF.database.max_retries)
+    print("-----------------------    NVP Options   -----------------------")
+    print("\tNVP Generation Timeout %d" % cfg.CONF.NVP.nvp_gen_timeout)
+    print("\tNumber of concurrent connections to each controller %d" %
+          cfg.CONF.NVP.concurrent_connections)
+    print("\tmax_lp_per_bridged_ls: %s" % cfg.CONF.NVP.max_lp_per_bridged_ls)
+    print("\tmax_lp_per_overlay_ls: %s" % cfg.CONF.NVP.max_lp_per_overlay_ls)
+    print("-----------------------  Cluster Options -----------------------")
+    print("\trequested_timeout: %s" % cfg.CONF.req_timeout)
+    print("\tretries: %s" % cfg.CONF.retries)
+    print("\tredirects: %s" % cfg.CONF.redirects)
+    print("\thttp_timeout: %s" % cfg.CONF.http_timeout)
     cluster = NeutronPlugin.create_nvp_cluster(
         cfg.CONF,
         cfg.CONF.NVP.concurrent_connections,
         cfg.CONF.NVP.nvp_gen_timeout)
     num_controllers = len(cluster.nvp_controllers)
-    print "Number of controllers found: %s" % num_controllers
+    print("Number of controllers found: %s" % num_controllers)
     if num_controllers == 0:
-        print "You must specify at least one controller!"
+        print("You must specify at least one controller!")
         sys.exit(1)
 
     for controller in cluster.nvp_controllers:
-        print "\tController endpoint: %s" % controller
+        print("\tController endpoint: %s" % controller)
         nvplib.check_cluster_connectivity(cluster)
         gateway_services = get_gateway_services(cluster)
         default_gateways = {
@@ -90,24 +92,24 @@ def main(argv):
         errors = 0
         for svc_type in default_gateways.keys():
             for uuid in gateway_services[svc_type]:
-                print "\t\tGateway(%s) uuid: %s" % (svc_type, uuid)
+                print("\t\tGateway(%s) uuid: %s" % (svc_type, uuid))
             if (default_gateways[svc_type] and
                 default_gateways[svc_type] not in gateway_services):
-                print ("\t\t\tError: specified default %s gateway (%s) is "
-                       "missing from NVP Gateway Services!" % (svc_type,
-                       default_gateways[svc_type]))
+                print("\t\t\tError: specified default %s gateway (%s) is "
+                      "missing from NVP Gateway Services!" % (svc_type,
+                      default_gateways[svc_type]))
                 errors += 1
         transport_zones = get_transport_zones(cluster)
-        print "\tTransport zones: %s" % transport_zones
+        print("\tTransport zones: %s" % transport_zones)
         if cfg.CONF.default_tz_uuid not in transport_zones:
-            print ("\t\tError: specified default transport zone "
-                   "(%s) is missing from NVP transport zones!"
-                   % cfg.CONF.default_tz_uuid)
+            print("\t\tError: specified default transport zone "
+                  "(%s) is missing from NVP transport zones!"
+                  % cfg.CONF.default_tz_uuid)
             errors += 1
 
     if errors:
-        print ("\nThere are %d errors with your configuration. "
-               " Please, revise!" % errors)
+        print("\nThere are %d errors with your configuration. "
+              " Please, revise!" % errors)
         sys.exit(1)
     else:
-        print "Done."
+        print("Done.")
index a2c2809073a25bbf3f90ca92d26cda8c14b14d54..04dbfefd0f7e61826543f51a8c335600195fbae2 100755 (executable)
@@ -15,6 +15,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+from __future__ import print_function
+
 import collections
 import uuid
 
@@ -356,10 +358,10 @@ class TaskManager():
 
     def show_pending_tasks(self):
         for task in self._tasks_queue:
-            print str(task)
+            print(str(task))
         for resource, tasks in self._tasks.iteritems():
             for task in tasks:
-                print str(task)
+                print(str(task))
 
     def count(self):
         count = 0
index 0b2a3dc06b48ce29e15516d36d15091d3e86af16..5d388cfa27127a18b6ce05cae0bf3e4b7e4c11fc 100644 (file)
@@ -85,7 +85,6 @@ class NeutronDB(object):
     def update_network(self, tenant_id, net_id, param_data):
         """Rename a network."""
         try:
-            print param_data
             net = db.network_update(net_id, tenant_id, **param_data)
             LOG.debug("Updated network: %s", net.uuid)
             net_dict = {}
index 344047395789bf1deef76378575341b825d983b4..2314370b6950ca1da52fada8e386c73b38946a84 100644 (file)
@@ -172,9 +172,6 @@ class TestNecAgent(TestNecAgentBase):
         self._check_report_state([dummy_vif] * 5, 5, fail_mode)
         self._check_report_state([], 0, fail_mode)
 
-        print 'record_state', self.record_calls
-        print 'num_ports_hist', self.num_ports_hist
-
         # Since loopingcall start is mocked, call_count is same as
         # the call count of check_report_state.
         self.assertEqual(state_rpc.report_state.call_count, 4)
index 7f5883247fad005ccc01afd2e36cf3e088043d83..f45e0bf5c7fa16ce677fa9ca1ec0debfad3fd466 100644 (file)
@@ -427,7 +427,6 @@ class PFCIdConvertTest(base.BaseTestCase):
 
     def test_convert_tenant_id(self):
         ofc_t_id = self.generate_random_ids(1)
-        print ofc_t_id
         ret = self.driver.convert_ofc_tenant_id(self.ctx, ofc_t_id)
         self.assertEqual(ret, '/tenants/%s' % ofc_t_id)
 
index 7f8015ed7690ca0da391854a9d502cfd4b247c40..c6710ef1b41468809f8f50af13096675594fbd83 100644 (file)
@@ -241,7 +241,6 @@ class TremaFilterDriverTest(TremaDriverTestBase):
              'status': "ACTIVE"}
         if filter_dict:
             f.update(filter_dict)
-        print 'filter=%s' % f
 
         net_path = "/networks/%s" % n
 
@@ -462,8 +461,7 @@ class TremaIdConvertTestBase(base.BaseTestCase):
 
         ret = self.driver.convert_ofc_port_id(self.ctx, ofc_p_id, t_id, n_id)
         exp = port_path_template % {'network': ofc_n_id, 'port': ofc_p_id}
-        print 'exp=', exp
-        print 'ret=', ret
+
         self.assertEqual(ret, exp)
         self.mox.VerifyAll()
 
index e26e2a1318cba84e522ef7896ae62e27157a0deb..b0d69a460e3f5fd76f1215f66aad1ed34dd74890 100644 (file)
@@ -125,9 +125,6 @@ class VcnsDriverTaskManagerTestCase(base.BaseTestCase):
 
         task.wait(TaskState.RESULT)
 
-        if 'error' in userdata:
-            print userdata['error']
-
         self.assertTrue(userdata['result'])
 
     def test_task_manager_task_sync_exec_process_state(self):
@@ -173,11 +170,6 @@ class VcnsDriverTaskManagerTestCase(base.BaseTestCase):
 
         last_task.wait(TaskState.RESULT)
 
-        for task in tasks:
-            if 'error' in task.userdata:
-                print "Task %s failed: " % (
-                    tasks.name, tasks.userdata['error'])
-
         for task in tasks:
             self.assertTrue(task.userdata['result'])
 
index dcfc2b99e50722c1656aef2b4576f2222f2df420..3e928350c98e1621f2666204e5032dd2ce920764 100644 (file)
@@ -271,7 +271,6 @@ class TestAllowedAddressPairs(AllowedAddressPairDBTestCase):
                                         port_security_enabled=True,
                                         allowed_address_pairs=address_pairs)
                 port = self.deserialize(self.fmt, res)
-                print port
                 update_port = {'port': {psec.PORTSECURITY: False}}
                 # If plugin implements security groups we also need to remove
                 # the security group on port.
index bf48af9fa0f848042828baf40ce0e01a8b9bb4c7..972b3998c64d380c4d7d5ba98108d22bbdfc1b14 100644 (file)
@@ -18,6 +18,8 @@
 """
 Utility methods for working with WSGI servers
 """
+from __future__ import print_function
+
 import errno
 import os
 import socket
@@ -894,15 +896,15 @@ class Debug(Middleware):
 
     @webob.dec.wsgify
     def __call__(self, req):
-        print ("*" * 40) + " REQUEST ENVIRON"
+        print(("*" * 40) + " REQUEST ENVIRON")
         for key, value in req.environ.items():
-            print key, "=", value
+            print(key, "=", value)
         print
         resp = req.get_response(self.application)
 
-        print ("*" * 40) + " RESPONSE HEADERS"
+        print(("*" * 40) + " RESPONSE HEADERS")
         for (key, value) in resp.headers.iteritems():
-            print key, "=", value
+            print(key, "=", value)
         print
 
         resp.app_iter = self.print_generator(resp.app_iter)
@@ -912,7 +914,7 @@ class Debug(Middleware):
     @staticmethod
     def print_generator(app_iter):
         """Print contents of a wrapper string iterator when iterated."""
-        print ("*" * 40) + " BODY"
+        print(("*" * 40) + " BODY")
         for part in app_iter:
             sys.stdout.write(part)
             sys.stdout.flush()
index b33055172300111a16e1634dd5a43001407812b0..86207b80b4e7ecde69bcf2a0208d4cdcff282635 100644 (file)
@@ -13,6 +13,7 @@
 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 #    License for the specific language governing permissions and limitations
 #    under the License.
+from __future__ import print_function
 
 import compiler
 import imp
@@ -56,43 +57,41 @@ class Visitor(object):
         if is_localized(node):
             for (checker, msg) in self.msg_format_checkers:
                 if checker(node):
-                    print >> sys.stderr, (
-                        '%s:%d %s: %s' %
-                        (self.filename, node.lineno,
-                         self.lines[node.lineno - 1][:-1],
-                         "Error: %s" % msg))
+                    print('%s:%d %s: %s Error: %s' %
+                          (self.filename, node.lineno,
+                           self.lines[node.lineno - 1][:-1], msg),
+                           file=sys.stderr)
                     self.error = 1
                     return
             if debug:
-                print ('%s:%d %s: %s' %
-                       (self.filename, node.lineno,
-                        self.lines[node.lineno - 1][:-1],
-                        "Pass"))
+                print('%s:%d %s: %s' %
+                      (self.filename, node.lineno,
+                       self.lines[node.lineno - 1][:-1],
+                       "Pass"))
         else:
             for (predicate, action, msg) in self.i18n_msg_predicates:
                 if predicate(node):
                     if action == 'skip':
                         if debug:
-                            print ('%s:%d %s: %s' %
-                                   (self.filename, node.lineno,
-                                    self.lines[node.lineno - 1][:-1],
-                                    "Pass"))
+                            print('%s:%d %s: %s' %
+                                  (self.filename, node.lineno,
+                                  self.lines[node.lineno - 1][:-1],
+                                  "Pass"))
                         return
                     elif action == 'error':
-                        print >> sys.stderr, (
-                            '%s:%d %s: %s' %
-                            (self.filename, node.lineno,
-                             self.lines[node.lineno - 1][:-1],
-                             "Error: %s" % msg))
+                        print('%s:%d %s: %s Error: %s' %
+                              (self.filename, node.lineno,
+                               self.lines[node.lineno - 1][:-1], msg),
+                               file=sys.stderr)
                         self.error = 1
                         return
                     elif action == 'warn':
-                        print ('%s:%d %s: %s' %
-                               (self.filename, node.lineno,
-                                self.lines[node.lineno - 1][:-1],
-                                "Warn: %s" % msg))
+                        print('%s:%d %s: %s' %
+                              (self.filename, node.lineno,
+                              self.lines[node.lineno - 1][:-1],
+                              "Warn: %s" % msg))
                         return
-                    print >> sys.stderr, 'Predicate with wrong action!'
+                    print('Predicate with wrong action!', file=sys.stderr)
 
 
 def is_file_in_black_list(black_list, f):
@@ -120,7 +119,7 @@ if __name__ == '__main__':
     try:
         cfg_mod = imp.load_source('', cfg_path)
     except Exception:
-        print >> sys.stderr, "Load cfg module failed"
+        print("Load cfg module failed", file=sys.stderr)
         sys.exit(1)
 
     i18n_msg_predicates = cfg_mod.i18n_msg_predicates
index a51c29512e9dd353a76b3a29be2ff6e940eea9b7..0f189b4ca967f77790eb714fbc7344f5139fef30 100644 (file)
@@ -23,6 +23,7 @@
 """
 Installation script for Neutron's development virtualenv
 """
+from __future__ import print_function
 
 import os
 import subprocess
@@ -50,7 +51,7 @@ def print_help():
 
  Also, make test will automatically use the virtualenv.
     """
-    print help
+    print(help)
 
 
 def main(argv):