Skip to content

Commit 6d76e7d

Browse files
authored
Merge pull request #5280 from stephenchengCloud/private/stephenche/qemu
CP-45981: Update xenopsd from python2 to python3
2 parents c3dc055 + a418e99 commit 6d76e7d

File tree

6 files changed

+30
-31
lines changed

6 files changed

+30
-31
lines changed

ocaml/xenopsd/scripts/common.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python3
22
#
33
# Copyright (c) 2011-2013 Citrix Systems, Inc.
44
#
@@ -38,7 +38,8 @@ def send_to_syslog(msg):
3838
def doexec(args):
3939
"""Execute a subprocess, then return its return code, stdout and stderr"""
4040
send_to_syslog(args)
41-
proc = subprocess.Popen([ "/usr/bin/env", "PATH=%s" % path ] + args,stdin=None,stdout=subprocess.PIPE,stderr=subprocess.PIPE,close_fds=True)
41+
proc = subprocess.Popen([ "/usr/bin/env", "PATH=%s" % path ] + args, stdin=None, stdout=subprocess.PIPE,
42+
stderr=subprocess.PIPE, close_fds=True, universal_newlines=True)
4243
rc = proc.wait()
4344
stdout = proc.stdout
4445
stderr = proc.stderr
@@ -101,7 +102,7 @@ def add_to_bridge(mode, dev, bridge, address, external_ids):
101102
cmd = ["ovs-vsctl", "--timeout=30", "--", "--if-exists", "del-port", dev, "--", "add-port", bridge, dev]
102103
for (key, value) in external_ids:
103104
cmd = cmd + ["--", "set", "interface", dev, 'external-ids:"%s"="%s"' % (key, value) ]
104-
run(ON_ERROR_LOG, cmd)
105+
run(ON_ERROR_LOG, cmd)
105106

106107
def remove_from_bridge(mode, dev, bridge):
107108
if mode == MODE_BRIDGE:
@@ -203,14 +204,13 @@ def get_words(value, separator):
203204
"ipv4_allowed": [],
204205
"ipv6_allowed": []
205206
}
206-
private = self.json["extra_private_keys"]
207207
if "locking_mode" in self.json:
208208
if type(self.json["locking_mode"]) is list:
209-
# Must be type=locked here
209+
# Must be type=locked here
210210
results["locking_mode"] = self.json["locking_mode"][0].lower()
211-
locked_params=self.json["locking_mode"][1]
212-
results["ipv4_allowed"] = locked_params["ipv4"]
213-
results["ipv6_allowed"] = locked_params["ipv6"]
211+
locked_params=self.json["locking_mode"][1]
212+
results["ipv4_allowed"] = locked_params["ipv4"]
213+
results["ipv6_allowed"] = locked_params["ipv6"]
214214
else:
215215
results["locking_mode"] = self.json["locking_mode"].lower()
216216
send_to_syslog("Got locking config: %s" % (repr(results)))

ocaml/xenopsd/scripts/igmp_query_injector.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
import argparse
33
import threading
44
import logging
@@ -106,7 +106,7 @@ def _inject_with_connection_state_check(self):
106106
t.join(self.vif_connected_timeout)
107107
if watcher.watches:
108108
log.warning('Wait vif state change timeout')
109-
for vif in watcher.watches.itervalues():
109+
for vif in watcher.watches.values():
110110
log.warning("Vif:%s state did not change to '%s', don't inject IGMP query to mac: %s" %
111111
(vif, VIF_CONNECTED_STATE, get_vif_mac(vif)))
112112

@@ -142,11 +142,11 @@ def get_vif_state_path(vif):
142142

143143

144144
def get_parent_bridge(bridge):
145-
return subprocess.check_output(['/usr/bin/ovs-vsctl', 'br-to-parent', bridge]).strip()
145+
return subprocess.check_output(['/usr/bin/ovs-vsctl', 'br-to-parent', bridge], universal_newlines=True).strip()
146146

147147

148148
def network_backend_is_openvswitch():
149-
bridge_type = subprocess.check_output(['/opt/xensource/bin/xe-get-network-backend']).strip()
149+
bridge_type = subprocess.check_output(['/opt/xensource/bin/xe-get-network-backend'], universal_newlines=True).strip()
150150
return bridge_type == 'openvswitch'
151151

152152

@@ -161,7 +161,7 @@ def __missing__(self, key):
161161

162162
@memodict
163163
def igmp_snooping_is_enabled_on_bridge(bridge):
164-
vlan = subprocess.check_output(['/usr/bin/ovs-vsctl', 'br-to-vlan', bridge]).strip()
164+
vlan = subprocess.check_output(['/usr/bin/ovs-vsctl', 'br-to-vlan', bridge], universal_newlines=True).strip()
165165
if vlan != '0':
166166
# this br is a fake br, should get its parent
167167
bridge = get_parent_bridge(bridge)
@@ -170,12 +170,12 @@ def igmp_snooping_is_enabled_on_bridge(bridge):
170170

171171
@memodict
172172
def _igmp_snooping_is_enabled_on_bridge(bridge):
173-
enabled = subprocess.check_output(['/usr/bin/ovs-vsctl', 'get', 'bridge', bridge, 'mcast_snooping_enable']).strip()
173+
enabled = subprocess.check_output(['/usr/bin/ovs-vsctl', 'get', 'bridge', bridge, 'mcast_snooping_enable'], universal_newlines=True).strip()
174174
return enabled == 'true'
175175

176176

177177
def igmp_snooping_is_enabled_on_bridge_of_vif(vif):
178-
bridge = subprocess.check_output(['/usr/bin/ovs-vsctl', 'iface-to-br', vif]).strip()
178+
bridge = subprocess.check_output(['/usr/bin/ovs-vsctl', 'iface-to-br', vif], universal_newlines=True).strip()
179179
return igmp_snooping_is_enabled_on_bridge(bridge)
180180

181181

ocaml/xenopsd/scripts/pygrub-wrapper

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/bin/python
1+
#! /usr/bin/python3
22
#
33
# Copyright (C) 2023 Cloud Software Group
44
#
@@ -12,13 +12,13 @@
1212
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313
# GNU Lesser General Public License for more details.
1414

15-
from __future__ import print_function
15+
1616
import pwd, subprocess, sys
1717

1818
cmd = ["pygrub"]
1919

2020
# Get the usage string. We can't use check_output() because the exit status isn't 0
21-
pygrub_usage = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[1]
21+
pygrub_usage = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).communicate()[1]
2222

2323
for arg in sys.argv[1:]:
2424
# Catch the synthetic --domid argument and turn it into --runas

ocaml/xenopsd/scripts/qemu-vif-script

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
2+
23

3-
from __future__ import print_function
44
from common import *
5+
import sys
56

67
if __name__ == "__main__":
78
if len(sys.argv) != 2:

ocaml/xenopsd/scripts/qemu-wrapper

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/bin/python
1+
#! /usr/bin/python3
22
#
33
# Copyright (C) 2016 Citrix Systems R&D Ltd.
44
#
@@ -12,9 +12,7 @@
1212
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313
# GNU Lesser General Public License for more details.
1414

15-
from __future__ import print_function
1615
import os
17-
import re
1816
import sys
1917
import socket
2018
import tempfile
@@ -266,6 +264,7 @@ def main(argv):
266264
incoming_fd = os.open(loadvm_path, os.O_RDONLY)
267265
qemu_args[n] = "-incoming"
268266
qemu_args[n+1] = "fd:%d" % incoming_fd
267+
open_fds.append(incoming_fd)
269268

270269
n += 1
271270

@@ -310,7 +309,7 @@ def main(argv):
310309

311310
clipboardd = '/opt/xensource/libexec/xs-clipboardd'
312311
subprocess.call([clipboardd, "-d", str(domid), "-s", str(s2.fileno())],
313-
preexec_fn=close_fds)
312+
pass_fds=[s2.fileno()])
314313

315314
s2.close()
316315

@@ -327,7 +326,7 @@ def main(argv):
327326

328327
qemu = subprocess.Popen(qemu_args, executable=qemu_dm, env=qemu_env,
329328
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
330-
preexec_fn=prepare_exec)
329+
preexec_fn=prepare_exec, pass_fds=open_fds)
331330

332331
xenstore_write("/local/domain/%d/qemu-pid" % domid, "%d" % qemu.pid)
333332
xenstore_write("/local/domain/%d/image/device-model-pid" % domid, "%d" % qemu.pid)

ocaml/xenopsd/scripts/setup-vif-rules

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python3
22
#
33
# Copyright (c) 2011 Citrix Systems, Inc.
44
#
@@ -13,14 +13,11 @@
1313
# GNU Lesser General Public License for more details.
1414
#
1515

16-
from __future__ import print_function
16+
1717
import fcntl
1818
import os
1919
import os.path
20-
import string
21-
import subprocess
2220
import sys
23-
import syslog
2421
import time
2522
import common
2623
from common import ON_ERROR_FAIL, send_to_syslog, doexec, run
@@ -92,7 +89,9 @@ def remove_bridge_port(vif_name):
9289
def get_chain_name(vif_name):
9390
return ("FORWARD_%s" % vif_name)
9491

95-
def do_chain_action(executable, action, chain_name, args=[]):
92+
def do_chain_action(executable, action, chain_name, args=None):
93+
if args is None:
94+
args = []
9695
return doexec([executable, action, chain_name] + args)
9796

9897
def chain_exists(executable, chain_name):

0 commit comments

Comments
 (0)