From patchwork Mon Dec 21 20:47:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Bryant X-Patchwork-Id: 559734 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (li376-54.members.linode.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 659F3140BB2 for ; Tue, 22 Dec 2015 07:55:43 +1100 (AEDT) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id B2B39108A6; Mon, 21 Dec 2015 12:48:44 -0800 (PST) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v3.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id 1595510775 for ; Mon, 21 Dec 2015 12:48:44 -0800 (PST) Received: from bar4.cudamail.com (localhost [127.0.0.1]) by mx3v3.cudamail.com (Postfix) with ESMTPS id A096B1610D6 for ; Mon, 21 Dec 2015 13:48:43 -0700 (MST) X-ASG-Debug-ID: 1450730923-03dc213ff0439680001-byXFYA Received: from mx3-pf1.cudamail.com ([192.168.14.2]) by bar4.cudamail.com with ESMTP id 4HonBVfT8lb5quKK (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 21 Dec 2015 13:48:43 -0700 (MST) X-Barracuda-Envelope-From: russell@ovn.org X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.2 Received: from unknown (HELO mx1.redhat.com) (209.132.183.28) by mx3-pf1.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 21 Dec 2015 20:48:43 -0000 Received-SPF: neutral (mx3-pf1.cudamail.com: 209.132.183.28 is neither permitted nor denied by SPF record at ovn.org) X-Barracuda-Apparent-Source-IP: 209.132.183.28 X-Barracuda-RBL-IP: 209.132.183.28 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 6D7F3693CD; Mon, 21 Dec 2015 20:48:42 +0000 (UTC) Received: from x1c.redhat.com ([10.3.112.11]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tBLKm0e0002018; Mon, 21 Dec 2015 15:48:41 -0500 X-CudaMail-Envelope-Sender: russell@ovn.org From: Russell Bryant To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-V1-1220054160 X-CudaMail-DTE: 122115 X-CudaMail-Originating-IP: 209.132.183.28 Date: Mon, 21 Dec 2015 15:47:37 -0500 X-ASG-Orig-Subj: [##CM-V1-1220054160##][PATCH 37/55] ovs-monitor-ipsec: Fix Python 3 compatibility. Message-Id: <1450730875-18083-38-git-send-email-russell@ovn.org> In-Reply-To: <1450730875-18083-1-git-send-email-russell@ovn.org> References: <1450730875-18083-1-git-send-email-russell@ovn.org> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Barracuda-Connect: UNKNOWN[192.168.14.2] X-Barracuda-Start-Time: 1450730923 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Subject: [ovs-dev] [PATCH 37/55] ovs-monitor-ipsec: Fix Python 3 compatibility. X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" Signed-off-by: Russell Bryant --- debian/ovs-monitor-ipsec | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/debian/ovs-monitor-ipsec b/debian/ovs-monitor-ipsec index d35ec46..1f1562d 100755 --- a/debian/ovs-monitor-ipsec +++ b/debian/ovs-monitor-ipsec @@ -40,6 +40,8 @@ import ovs.db.idl import ovs.unixctl import ovs.unixctl.server import ovs.vlog +import six +from six.moves import range vlog = ovs.vlog.Vlog("ovs-monitor-ipsec") root_prefix = '' # Prefix for absolute file names, for testing. @@ -152,7 +154,7 @@ path certificate "%s"; conf_file = open(root_prefix + self.conf_file, 'w') conf_file.write(Racoon.conf_header % (self.psk_file, self.cert_dir)) - for host, vals in self.cert_hosts.iteritems(): + for host, vals in six.iteritems(self.cert_hosts): conf_file.write(Racoon.cert_entry % (host, vals["certificate"], vals["private_key"], vals["peer_cert_file"])) @@ -163,13 +165,13 @@ path certificate "%s"; conf_file.close() # Rewrite the pre-shared keys file; it must only be readable by root. - orig_umask = os.umask(0077) + orig_umask = os.umask(0o077) psk_file = open(root_prefix + Racoon.psk_file, 'w') os.umask(orig_umask) psk_file.write("# Generated by Open vSwitch...do not modify by hand!") psk_file.write("\n\n") - for host, vals in self.psk_hosts.iteritems(): + for host, vals in six.iteritems(self.psk_hosts): psk_file.write("%s %s\n" % (host, vals["psk"])) psk_file.close() @@ -277,6 +279,8 @@ class IPsec: # xxx It is safer to pass the string into the communicate() # xxx method, but it didn't work for slightly longer commands. # xxx An alternative may need to be found. + if sys.version_info[0] >= 3 and not isinstance(cmds, six.binary_type): + cmds = six.binary_type(cmds, 'utf-8') p.stdin.write(cmds) return p.communicate()[0] @@ -354,11 +358,11 @@ class IPsec: def update_ipsec(ipsec, interfaces, new_interfaces): - for name, vals in interfaces.iteritems(): + for name, vals in six.iteritems(interfaces): if name not in new_interfaces: ipsec.del_entry(vals["local_ip"], vals["remote_ip"]) - for name, vals in new_interfaces.iteritems(): + for name, vals in six.iteritems(new_interfaces): orig_vals = interfaces.get(name) if orig_vals: # Configuration for this host already exists. Check if it's @@ -372,12 +376,12 @@ def update_ipsec(ipsec, interfaces, new_interfaces): try: ipsec.add_entry(vals["local_ip"], vals["remote_ip"], vals) - except error.Error, msg: + except error.Error as msg: vlog.warn("skipping ipsec config for %s: %s" % (name, msg)) def get_ssl_cert(data): - for ovs_rec in data["Open_vSwitch"].rows.itervalues(): + for ovs_rec in six.itervalues(data["Open_vSwitch"].rows): if ovs_rec.ssl: ssl = ovs_rec.ssl[0] if ssl.certificate and ssl.private_key: @@ -440,7 +444,7 @@ def main(): ssl_cert = get_ssl_cert(idl.tables) new_interfaces = {} - for rec in idl.tables["Interface"].rows.itervalues(): + for rec in six.itervalues(idl.tables["Interface"].rows): if rec.type == "ipsec_gre": name = rec.name options = rec.options