samba python tests: convert print func to be py2/py3 compatible
authorNoel Power <noel.power@suse.com>
Fri, 9 Mar 2018 13:38:42 +0000 (13:38 +0000)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 23 Mar 2018 06:28:23 +0000 (07:28 +0100)
Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/tests/auth_log.py
python/samba/tests/auth_log_base.py
python/samba/tests/auth_log_pass_change.py
python/samba/tests/blackbox/ndrdump.py
python/samba/tests/dcerpc/dnsserver.py
python/samba/tests/dcerpc/testrpc.py
python/samba/tests/dns.py
python/samba/tests/dns_base.py
python/samba/tests/dns_forwarder.py
python/samba/tests/dns_forwarder_helpers/server.py
python/samba/tests/samba3sam.py

index 6b032a80edc38b95fed32df29d550ab112182388..9e68c4fa38ea3704d68aa6b03b3c5bac1b3c43a9 100644 (file)
@@ -15,9 +15,9 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+from __future__ import print_function
 """Tests for the Auth and AuthZ logging.
 """
-
 from samba import auth
 import samba.tests
 from samba.messaging import Messaging
@@ -140,7 +140,7 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
         msg = messages[2]
         self.assertEquals("Authorization", msg["type"])
         serviceDescription = "SMB"
-        print "binding %s" % binding
+        print("binding %s" % binding)
         if binding == "[smb2]":
             serviceDescription = "SMB2"
 
index aefd57e551615325ea6b68f95408d7957f1ad9e4..6c1baea9df7ba16244ba07520229839bfe0c4193 100644 (file)
@@ -15,6 +15,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+from __future__ import print_function
 """Tests for the Auth and AuthZ logging.
 """
 
@@ -40,7 +41,7 @@ class AuthLogTestBase(samba.tests.TestCase):
         def messageHandler( context, msgType, src, message):
             # This does not look like sub unit output and it
             # makes these tests much easier to debug.
-            print message
+            print(message)
             jsonMsg = json.loads(message)
             context["messages"].append( jsonMsg)
 
index 77758a4430a2ef5d673a6cea749e6c08d4f3d3c9..9782389b97efb5ea261bb726c8265697f7e61c79 100644 (file)
@@ -15,6 +15,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+from __future__ import print_function
 """Tests for the Auth and AuthZ logging of password changes.
 """
 
@@ -50,10 +51,10 @@ class AuthLogPassChangeTests(samba.tests.auth_log_base.AuthLogTestBase):
                          credentials=self.get_credentials(),
                          lp=self.get_loadparm())
 
-        print "ldb %s" % type(self.ldb)
+        print("ldb %s" % type(self.ldb))
         # Gets back the basedn
         base_dn = self.ldb.domain_dn()
-        print "base_dn %s" % base_dn
+        print("base_dn %s" % base_dn)
 
         # Gets back the configuration basedn
         configuration_dn = self.ldb.get_config_basedn().get_linearized()
@@ -116,7 +117,7 @@ class AuthLogPassChangeTests(samba.tests.auth_log_base.AuthLogTestBase):
 
 
         messages = self.waitForMessages(isLastExpectedMessage)
-        print "Received %d messages" % len(messages)
+        print("Received %d messages" % len(messages))
         self.assertEquals(8,
                           len(messages),
                           "Did not receive the expected number of messages")
@@ -263,7 +264,7 @@ class AuthLogPassChangeTests(samba.tests.auth_log_base.AuthLogTestBase):
         )
 
         messages = self.waitForMessages(isLastExpectedMessage)
-        print "Received %d messages" % len(messages)
+        print("Received %d messages" % len(messages))
         self.assertEquals(4,
                           len(messages),
                           "Did not receive the expected number of messages")
@@ -295,7 +296,7 @@ class AuthLogPassChangeTests(samba.tests.auth_log_base.AuthLogTestBase):
             pass
 
         messages = self.waitForMessages(isLastExpectedMessage)
-        print "Received %d messages" % len(messages)
+        print("Received %d messages" % len(messages))
         self.assertEquals(3,
                           len(messages),
                           "Did not receive the expected number of messages")
@@ -326,7 +327,7 @@ class AuthLogPassChangeTests(samba.tests.auth_log_base.AuthLogTestBase):
             pass
 
         messages = self.waitForMessages(isLastExpectedMessage)
-        print "Received %d messages" % len(messages)
+        print("Received %d messages" % len(messages))
         self.assertEquals(4,
                           len(messages),
                           "Did not receive the expected number of messages")
index f0cd5f750ec72eb80aadfe540764f76aca53666a..86f958d63c3bdceb9f65967fb96ebe8c691a7de7 100644 (file)
@@ -18,6 +18,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+from __future__ import print_function
 """Blackbox tests for ndrdump."""
 
 import os
@@ -25,7 +26,7 @@ from samba.tests import BlackboxTestCase
 
 for p in [ "../../../../../source4/librpc/tests", "../../../../../librpc/tests"]:
     data_path_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), p))
-    print data_path_dir
+    print(data_path_dir)
     if os.path.exists(data_path_dir):
         break
 
index 349349428cb00819313507219b81f3dbf324c678..93d4478997c4fac60eca6cd91662b53a7a66e332 100644 (file)
@@ -15,6 +15,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+from __future__ import print_function
 """Tests for samba.dcerpc.dnsserver"""
 
 import os
@@ -337,7 +338,7 @@ class DnsserverTests(RpcInterfaceTestCase):
                     self.assert_num_records(self.custom_zone, "testrecord", record_type_str, expected_num=0)
                     self.delete_record(self.custom_zone, "testrecord", record_type_str, record_str, assertion=False)
                 except AssertionError as e:
-                    print e
+                    print(e)
                     num_failures = num_failures + 1
 
         # Also try to update valid records to invalid ones, making sure this fails
@@ -348,7 +349,7 @@ class DnsserverTests(RpcInterfaceTestCase):
                 try:
                     self.add_record(self.custom_zone, "testrecord", record_type_str, record_str, assertion=False)
                 except AssertionError as e:
-                    print e
+                    print(e)
                     num_failures = num_failures + 1
                 self.delete_record(self.custom_zone, "testrecord", record_type_str, good_record_str)
 
index fc3abf93395361783227724401ecc2c0eee11940..5aadcf48eedeb5a51bc6e9028be9c08ec12a0c2f 100644 (file)
@@ -14,6 +14,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
+from __future__ import print_function
 import sys
 
 sys.path.insert(0, "bin/python")
@@ -35,10 +36,10 @@ class RpcTests(object):
             nblocks -= self.initial_blocks
         leaked_blocks = (nblocks - num_expected)
         if leaked_blocks != 0:
-            print "Leaked %d blocks" % leaked_blocks
+            print("Leaked %d blocks" % leaked_blocks)
 
     def check_type(self, interface, typename, type):
-        print "Checking type %s" % typename
+        print("Checking type %s" % typename)
         v = type()
         for n in dir(v):
             if n[0] == '_':
@@ -47,43 +48,43 @@ class RpcTests(object):
                 value = getattr(v, n)
             except TypeError as errstr:
                 if str(errstr) == "unknown union level":
-                    print "ERROR: Unknown union level in %s.%s" % (typename, n)
+                    print("ERROR: Unknown union level in %s.%s" % (typename, n))
                     self.errcount += 1
                     continue
-                print str(errstr)[1:21]
+                print(str(errstr)[1:21])
                 if str(errstr)[0:21] == "Can not convert C Type":
-                    print "ERROR: Unknown C type for %s.%s" % (typename, n)
+                    print("ERROR: Unknown C type for %s.%s" % (typename, n))
                     self.errcount += 1
                     continue
                 else:
-                    print "ERROR: Failed to instantiate %s.%s" % (typename, n)
+                    print("ERROR: Failed to instantiate %s.%s" % (typename, n))
                     self.errcount += 1
                     continue
             except Exception:
-                print "ERROR: Failed to instantiate %s.%s" % (typename, n)
+                print("ERROR: Failed to instantiate %s.%s" % (typename, n))
                 self.errcount += 1
                 continue
 
             # now try setting the value back
             try:
-                print "Setting %s.%s" % (typename, n)
+                print("Setting %s.%s" % (typename, n))
                 setattr(v, n, value)
             except Exception as e:
                 if isinstance(e, AttributeError) and str(e).endswith("is read-only"):
                     # readonly, ignore
                     continue
                 else:
-                    print "ERROR: Failed to set %s.%s: %r: %s" % (typename, n, e.__class__, e)
+                    print("ERROR: Failed to set %s.%s: %r: %s" % (typename, n, e.__class__, e))
                     self.errcount += 1
                     continue
 
             # and try a comparison
             try:
                 if value != getattr(v, n):
-                    print "ERROR: Comparison failed for %s.%s: %r != %r" % (typename, n, value, getattr(v, n))
+                    print("ERROR: Comparison failed for %s.%s: %r != %r" % (typename, n, value, getattr(v, n)))
                     continue
             except Exception as e:
-                print "ERROR: compare exception for %s.%s: %r: %s" % (typename, n, e.__class__, e)
+                print("ERROR: compare exception for %s.%s: %r: %s" % (typename, n, e.__class__, e))
                 continue
 
     def check_interface(self, interface, iname):
@@ -105,14 +106,14 @@ class RpcTests(object):
                     self.check_type(interface, n, value)
                     self.check_blocks(None, initial_blocks)
                 except Exception as e:
-                    print "ERROR: Failed to check_type %s.%s: %r: %s" % (iname, n, e.__class__, e)
+                    print("ERROR: Failed to check_type %s.%s: %r: %s" % (iname, n, e.__class__, e))
                     self.errcount += 1
             elif callable(value):
                 pass # Method
             else:
-                print "UNKNOWN: %s=%s" % (n, value)
+                print("UNKNOWN: %s=%s" % (n, value))
         if self.errcount - errcount != 0:
-            print "Found %d errors in %s" % (self.errcount - errcount, iname)
+            print("Found %d errors in %s" % (self.errcount - errcount, iname))
 
     def check_all_interfaces(self):
         for iname in dir(samba.dcerpc):
@@ -120,7 +121,7 @@ class RpcTests(object):
                 continue
             if iname == 'ClientConnection' or iname == 'base':
                 continue
-            print "Checking interface %s" % iname
+            print("Checking interface %s" % iname)
             iface = getattr(samba.dcerpc, iname)
             initial_blocks = talloc.total_blocks(None)
             self.check_interface(iface, iname)
@@ -137,5 +138,5 @@ errcount = tests.run()
 if errcount == 0:
     sys.exit(0)
 else:
-    print "%d failures" % errcount
+    print("%d failures" % errcount)
     sys.exit(1)
index 8aecfe3be59ff36c4cb62ec2aba4337cff85c52f..4082b5375d1a1348af49f3e846a60d2fecea5741 100644 (file)
@@ -15,6 +15,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+from __future__ import print_function
 import os
 import sys
 import struct
@@ -77,7 +78,7 @@ class TestSimpleQueries(DNSTest):
 
         name = "%s.%s" % (self.server, self.get_dns_domain())
         q = self.make_name_question(name, dns.DNS_QTYPE_A, dns.DNS_QCLASS_IN)
-        print "asking for ", q.name
+        print("asking for ", q.name)
         questions.append(q)
 
         self.finish_name_packet(p, questions)
@@ -95,7 +96,7 @@ class TestSimpleQueries(DNSTest):
 
         name = "%s" % (self.get_dns_domain())
         q = self.make_name_question(name, dns.DNS_QTYPE_SOA, dns.DNS_QCLASS_IN)
-        print "asking for ", q.name
+        print("asking for ", q.name)
         questions.append(q)
 
         self.finish_name_packet(p, questions)
@@ -113,7 +114,7 @@ class TestSimpleQueries(DNSTest):
 
         name = "%s.%s" % (self.server, self.get_dns_domain())
         q = self.make_name_question(name, dns.DNS_QTYPE_A, dns.DNS_QCLASS_IN)
-        print "asking for ", q.name
+        print("asking for ", q.name)
         questions.append(q)
 
         self.finish_name_packet(p, questions)
@@ -131,7 +132,7 @@ class TestSimpleQueries(DNSTest):
 
         name = "%s.%s" % (self.server, self.get_dns_domain())
         q = self.make_name_question(name, dns.DNS_QTYPE_MX, dns.DNS_QCLASS_IN)
-        print "asking for ", q.name
+        print("asking for ", q.name)
         questions.append(q)
 
         self.finish_name_packet(p, questions)
@@ -145,7 +146,7 @@ class TestSimpleQueries(DNSTest):
 
         name = "invalid-%s.%s" % (self.server, self.get_dns_domain())
         q = self.make_name_question(name, dns.DNS_QTYPE_MX, dns.DNS_QCLASS_IN)
-        print "asking for ", q.name
+        print("asking for ", q.name)
         questions.append(q)
 
         self.finish_name_packet(p, questions)
@@ -185,7 +186,7 @@ class TestSimpleQueries(DNSTest):
 
         name = "%s.%s" % (self.server, self.get_dns_domain())
         q = self.make_name_question(name, dns.DNS_QTYPE_ALL, dns.DNS_QCLASS_IN)
-        print "asking for ", q.name
+        print("asking for ", q.name)
         questions.append(q)
 
         self.finish_name_packet(p, questions)
@@ -685,7 +686,7 @@ class TestComplexQueries(DNSTest):
             # Check the record
             name = "cname_test.%s" % self.get_dns_domain()
             q = self.make_name_question(name, dns.DNS_QTYPE_A, dns.DNS_QCLASS_IN)
-            print "asking for ", q.name
+            print("asking for ", q.name)
             questions.append(q)
 
             self.finish_name_packet(p, questions)
@@ -825,7 +826,7 @@ class TestInvalidQueries(DNSTest):
 
         name = "%s.%s" % (self.server, self.get_dns_domain())
         q = self.make_name_question(name, dns.DNS_QTYPE_A, dns.DNS_QCLASS_IN)
-        print "asking for ", q.name
+        print("asking for ", q.name)
         questions.append(q)
 
         self.finish_name_packet(p, questions)
@@ -845,7 +846,7 @@ class TestInvalidQueries(DNSTest):
 
         name = "%s.%s" % ('fakefakefake', self.get_dns_domain())
         q = self.make_name_question(name, dns.DNS_QTYPE_A, dns.DNS_QCLASS_IN)
-        print "asking for ", q.name
+        print("asking for ", q.name)
         questions.append(q)
 
         self.finish_name_packet(p, questions)
index 2a40d999c36f4b01a0172789799d9314fbef472d..10c7a0a6af5b6631d8a9f7454ddbd5628b7175a0 100644 (file)
@@ -16,6 +16,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+from __future__ import print_function
 from samba.tests import TestCaseInTempDir
 from samba.dcerpc import dns, dnsp
 from samba import gensec, tests
@@ -119,14 +120,14 @@ class DNSTest(TestCaseInTempDir):
         try:
             send_packet = ndr.ndr_pack(packet)
             if dump:
-                print self.hexdump(send_packet)
+                print(self.hexdump(send_packet))
             s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
             s.settimeout(timeout)
             s.connect((host, 53))
             s.sendall(send_packet, 0)
             recv_packet = s.recv(2048, 0)
             if dump:
-                print self.hexdump(recv_packet)
+                print(self.hexdump(recv_packet))
             response = ndr.ndr_unpack(dns.name_packet, recv_packet)
             return (response, recv_packet)
         finally:
@@ -142,7 +143,7 @@ class DNSTest(TestCaseInTempDir):
         try:
             send_packet = ndr.ndr_pack(packet)
             if dump:
-                print self.hexdump(send_packet)
+                print(self.hexdump(send_packet))
             s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
             s.settimeout(timeout)
             s.connect((host, 53))
@@ -152,7 +153,7 @@ class DNSTest(TestCaseInTempDir):
 
             recv_packet = s.recv(0xffff + 2, 0)
             if dump:
-                print self.hexdump(recv_packet)
+                print(self.hexdump(recv_packet))
             response = ndr.ndr_unpack(dns.name_packet, recv_packet[2:])
 
         finally:
index cf9f537e461d82c1336a6cf857bd1d22e994bdb2..028c308239f0b805399be23f2e04fc35bea21400 100644 (file)
@@ -15,6 +15,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+from __future__ import print_function
 import os
 import sys
 import struct
@@ -123,14 +124,14 @@ class DNSTest(TestCase):
         try:
             send_packet = ndr.ndr_pack(packet)
             if dump:
-                print self.hexdump(send_packet)
+                print(self.hexdump(send_packet))
             s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
             s.settimeout(timeout)
             s.connect((host, 53))
             s.send(send_packet, 0)
             recv_packet = s.recv(2048, 0)
             if dump:
-                print self.hexdump(recv_packet)
+                print(self.hexdump(recv_packet))
             return ndr.ndr_unpack(dns.name_packet, recv_packet)
         finally:
             if s is not None:
@@ -358,7 +359,7 @@ class TestDnsForwarding(DNSTest):
 
     def test_double_forwarder_first_frozen(self):
         if len(dns_servers) < 2:
-            print "Ignoring test_double_forwarder_first_frozen"
+            print("Ignoring test_double_forwarder_first_frozen")
             return
         s1 = self.start_toy_server(dns_servers[0], 53, 'forwarder1')
         s2 = self.start_toy_server(dns_servers[1], 53, 'forwarder2')
@@ -388,7 +389,7 @@ class TestDnsForwarding(DNSTest):
 
     def test_double_forwarder_first_down(self):
         if len(dns_servers) < 2:
-            print "Ignoring test_double_forwarder_first_down"
+            print("Ignoring test_double_forwarder_first_down")
             return
         s2 = self.start_toy_server(dns_servers[1], 53, 'forwarder2')
         ad = contact_real_server(server_ip, 53)
@@ -416,7 +417,7 @@ class TestDnsForwarding(DNSTest):
 
     def test_double_forwarder_both_slow(self):
         if len(dns_servers) < 2:
-            print "Ignoring test_double_forwarder_both_slow"
+            print("Ignoring test_double_forwarder_both_slow")
             return
         s1 = self.start_toy_server(dns_servers[0], 53, 'forwarder1')
         s2 = self.start_toy_server(dns_servers[1], 53, 'forwarder2')
@@ -502,7 +503,7 @@ class TestDnsForwarding(DNSTest):
 
     def test_cname_forwarding_with_slow_server(self):
         if len(dns_servers) < 2:
-            print "Ignoring test_cname_forwarding_with_slow_server"
+            print("Ignoring test_cname_forwarding_with_slow_server")
             return
         s1 = self.start_toy_server(dns_servers[0], 53, 'forwarder1')
         s2 = self.start_toy_server(dns_servers[1], 53, 'forwarder2')
@@ -535,7 +536,7 @@ class TestDnsForwarding(DNSTest):
 
     def test_cname_forwarding_with_server_down(self):
         if len(dns_servers) < 2:
-            print "Ignoring test_cname_forwarding_with_server_down"
+            print("Ignoring test_cname_forwarding_with_server_down")
             return
         s2 = self.start_toy_server(dns_servers[1], 53, 'forwarder2')
 
index e302485ea1be7fd5effcd6c2b47b8613007ac3b1..7bd27e53b503475d28a43cae6b38bfd8a7c280e2 100644 (file)
@@ -17,6 +17,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 # Based on the EchoServer example from python docs
+from __future__ import print_function
 import SocketServer
 import time
 import sys
@@ -31,7 +32,7 @@ VERBOSE = False
 def debug(msg):
     if VERBOSE:
         sys.stdout.flush()
-        print "\033[00;36m%s\033[00m" % msg
+        print("\033[00;36m%s\033[00m" % msg)
         sys.stdout.flush()
 
 timeout = 0
index bfc7932689f05832249faf80271a85ecfe30eccb..2fb4f13cfa69ac60dae3939db4e174997253ac91 100644 (file)
@@ -18,6 +18,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+from __future__ import print_function
 """Tests for the samba3sam LDB module, which maps Samba3 LDAP to AD LDAP."""
 
 import os
@@ -41,7 +42,7 @@ def read_datafile(filename):
     return open(os.path.join(datadir, filename), 'r').read()
 
 def ldb_debug(l, text):
-    print text
+    print(text)
 
 
 class MapBaseTestCase(TestCaseInTempDir):