Skip to content

Commit 455dddb

Browse files
authored
Merge pull request #130 from matyasselmeci/wip/py3
Fix obvious Python 3 incompatibilities
2 parents e9948a0 + 7c3d678 commit 455dddb

28 files changed

+95
-93
lines changed

osg-test

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/python
22

3+
from __future__ import print_function
34
from distutils.sysconfig import get_python_lib
45
from optparse import OptionParser
56
import ConfigParser
@@ -55,7 +56,7 @@ def parse_command_line():
5556
config_file = ConfigParser.RawConfigParser()
5657
try:
5758
config_file.read(opts.config)
58-
except ConfigParser.ParsingError, exc:
59+
except ConfigParser.ParsingError as exc:
5960
sys.stderr.write("Error while parsing: %s\n%s\n" % (opts.config, exc))
6061
sys.stderr.write("Lines with options should not start with a space\n")
6162
sys.exit(1)
@@ -168,7 +169,7 @@ def get_password():
168169
if core.options.securepass:
169170
# If the user also specifies password on the command line, we complain
170171
if core.options.password != 'vdttest':
171-
print 'Only specify one of --password and --securepass'
172+
print('Only specify one of --password and --securepass')
172173
sys.exit(1)
173174
core.options.password = getpass()
174175

@@ -252,6 +253,6 @@ if __name__ == '__main__':
252253
signal.alarm(0)
253254
signal.signal(signal.SIGALRM, signal.SIG_DFL)
254255
else:
255-
print 'No tests to run.'
256+
print('No tests to run.')
256257
wrap_up()
257258
sys.exit(EXIT_CODE)

osgtest/library/core.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Support and convenience functions for tests."""
2+
from __future__ import print_function
23

34
import errno
45
import os
@@ -127,9 +128,9 @@ def end_log():
127128
def dump_log(outfile=None):
128129
if outfile is None:
129130
logfile = open(_log_filename, 'r')
130-
print '\n'
131+
print('\n')
131132
for line in logfile:
132-
print line.rstrip('\n')
133+
print(line.rstrip('\n'))
133134
logfile.close()
134135
else:
135136
shutil.copy(_log_filename, outfile)
@@ -143,7 +144,7 @@ def get_stat(filename):
143144
'''Return stat for 'filename', None if the file does not exist'''
144145
try:
145146
return os.stat(filename)
146-
except OSError, exc:
147+
except OSError as exc:
147148
if exc.errno == errno.ENOENT:
148149
return None
149150
raise
@@ -493,7 +494,7 @@ def __run_command(command, use_test_user, a_input, a_stdout, a_stderr, log_outpu
493494
try:
494495
repr(command)
495496
except TypeError:
496-
print 'Need list or tuple, got %s' % type(command)
497+
print('Need list or tuple, got %s' % type(command))
497498
if use_test_user:
498499
command = ['runuser', options.username, '-c', ' '.join(map(__prepare_shell_argument, command))]
499500

@@ -603,7 +604,7 @@ def el_release():
603604
release_file.close()
604605
match = re.search(r"release (\d)", release_text)
605606
_el_release = int(match.group(1))
606-
except (EnvironmentError, TypeError, ValueError), e:
607+
except (EnvironmentError, TypeError, ValueError) as e:
607608
_log.write("Couldn't determine redhat release: " + str(e) + "\n")
608609
sys.exit(1)
609610
return _el_release
@@ -642,7 +643,7 @@ def check_file_and_perms(file_path, owner_name, permissions):
642643
try:
643644
file_stat = os.stat(file_path)
644645
return (file_stat.st_uid == owner_uid and
645-
file_stat.st_mode & 07777 == permissions and
646+
file_stat.st_mode & 0o7777 == permissions and
646647
stat.S_ISREG(file_stat.st_mode))
647648
except OSError: # file does not exist
648649
return False
@@ -684,7 +685,7 @@ def install_cert(target_key, source_key, owner_name, permissions):
684685
os.makedirs(target_dir)
685686
state[target_key + '-dir'] = target_dir
686687
os.chown(target_dir, user.pw_uid, user.pw_gid)
687-
os.chmod(target_dir, 0755)
688+
os.chmod(target_dir, 0o755)
688689

689690
shutil.copy(source_path, target_path)
690691
state[target_key] = target_path
@@ -697,12 +698,12 @@ def remove_cert(target_key):
697698
paths associated with the key, as created by the install_cert()
698699
function.
699700
"""
700-
if state.has_key(target_key):
701+
if target_key in state:
701702
os.remove(state[target_key])
702-
if state.has_key(target_key + '-backup'):
703+
if target_key + '-backup' in state:
703704
shutil.move(state[target_key + '-backup'],
704705
state[target_key])
705-
if state.has_key(target_key + '-dir'):
706+
if target_key + '-dir' in state:
706707
target_dir = state[target_key + '-dir']
707708
if len(os.listdir(target_dir)) == 0:
708709
os.rmdir(target_dir)

osgtest/library/files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def preserve(path, owner):
7474
else:
7575
_backups[backup_id] = None
7676

77-
def write(path, contents, owner=None, backup=True, chown=(0,0), chmod=0600):
77+
def write(path, contents, owner=None, backup=True, chown=(0,0), chmod=0o600):
7878
"""Write the contents to a file at the path.
7979
8080
The 'owner' argument (default: None) is a string that identifies the owner

osgtest/library/osgunittest.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,41 +75,41 @@ def __init__(self, methodName='runTest'):
7575

7676
def skip_ok(self, message=None):
7777
"Skip (ok) unconditionally"
78-
raise OkSkipException, message
78+
raise OkSkipException(message)
7979

8080
def skip_ok_if(self, expr, message=None):
8181
"Skip (ok) if the expression is true"
8282
if expr:
83-
raise OkSkipException, message
83+
raise OkSkipException(message)
8484

8585
def skip_ok_unless(self, expr, message=None):
8686
"Skip (ok) if the expression is false"
8787
if not expr:
88-
raise OkSkipException, message
88+
raise OkSkipException(message)
8989

9090
def skip_bad(self, message=None):
9191
"Skip (bad) unconditionally"
92-
raise BadSkipException, message
92+
raise BadSkipException(message)
9393

9494
def skip_bad_if(self, expr, message=None):
9595
"Skip (bad) if the expression is true"
9696
if expr:
97-
raise BadSkipException, message
97+
raise BadSkipException(message)
9898

9999
def skip_bad_unless(self, expr, message=None):
100100
"Skip (bad) if the expression is false"
101101
if not expr:
102-
raise BadSkipException, message
102+
raise BadSkipException(message)
103103

104104
def assertSubsetOf(self, a, b, message=None):
105105
"Ensure that a is a subset of b "
106106
if not set(a).issubset(set(b)):
107-
raise AssertionError, message
107+
raise AssertionError(message)
108108

109109
def failIfSubsetOf(self, a, b, message=None):
110110
"Ensure that a is not a subset of b"
111111
if set(a).issubset(set(b)):
112-
raise AssertionError, message
112+
raise AssertionError(message)
113113

114114
# This is mostly a copy of the method from unittest in python 2.4.
115115
# There is some code here to test if the 'result' object accepts 'skips',

osgtest/library/voms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def advertise_lsc(vo, hostcert='/etc/grid-security/hostcert.pem'):
7474
if not os.path.isdir(lsc_dir):
7575
os.makedirs(lsc_dir)
7676
vo_lsc_path = os.path.join(lsc_dir, hostname + '.lsc')
77-
files.write(vo_lsc_path, (host_dn + '\n', host_issuer + '\n'), backup=False, chmod=0644)
77+
files.write(vo_lsc_path, (host_dn + '\n', host_issuer + '\n'), backup=False, chmod=0o644)
7878

7979

8080
def advertise_vomses(vo, hostcert='/etc/grid-security/hostcert.pem'):
@@ -86,7 +86,7 @@ def advertise_vomses(vo, hostcert='/etc/grid-security/hostcert.pem'):
8686
vomses_path = '/etc/vomses'
8787
contents = ('"%s" "%s" "%d" "%s" "%s"\n' %
8888
(vo, hostname, 15151, host_dn, vo))
89-
files.write(vomses_path, contents, backup=False, chmod=0644)
89+
files.write(vomses_path, contents, backup=False, chmod=0o644)
9090

9191

9292
def add_user(vo, usercert, use_voms_admin=False):

osgtest/tests/special_cleanup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def test_06_cleanup_test_certs(self):
134134
dest = os.readlink(abs_link_path)
135135
if re.match(r'OSG-Test-CA\.', dest):
136136
files.remove(abs_link_path)
137-
except OSError, e:
137+
except OSError as e:
138138
if e.errno == errno.EINVAL:
139139
continue
140140

osgtest/tests/special_user.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_01_add_user(self):
6363
# Set up directories
6464
user = pwd.getpwnam(core.options.username)
6565
os.chown(user.pw_dir, user.pw_uid, user.pw_gid)
66-
os.chmod(user.pw_dir, 0755)
66+
os.chmod(user.pw_dir, 0o755)
6767

6868
# Set up certificate
6969
globus_dir = os.path.join(user.pw_dir, '.globus')
@@ -80,7 +80,7 @@ def test_02_user(self):
8080
return
8181
try:
8282
password_entry = pwd.getpwnam(core.options.username)
83-
except KeyError, e:
83+
except KeyError as e:
8484
self.fail("User '%s' should exist but does not" % core.options.username)
8585
self.assert_(password_entry.pw_dir != '/', "User '%s' has home directory at '/'" % (core.options.username))
8686
self.assert_(os.path.isdir(password_entry.pw_dir),
@@ -93,4 +93,4 @@ def test_02_user(self):
9393
(core.config['user.cert_subject'], password_entry.pw_name),
9494
owner='user')
9595
core.state['system.wrote_mapfile'] = True
96-
os.chmod(core.config['system.mapfile'], 0644)
96+
os.chmod(core.config['system.mapfile'], 0o644)

osgtest/tests/test_05_mysqld.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_01_backup_mysql(self):
2828
self.assert_(not os.path.exists(backup), 'mysql-backup already exists')
2929
try:
3030
shutil.move(core.config['mysql.datadir'], backup)
31-
except IOError, e:
31+
except IOError as e:
3232
if e.errno == 2:
3333
# Folder doesn't exist so we don't have to worry about backups
3434
pass

osgtest/tests/test_09_jobs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ def test_01_set_job_env(self):
2020
osg_libdir = os.path.join('/var', 'lib', 'osg')
2121
try:
2222
os.makedirs(osg_libdir)
23-
except OSError, exc:
23+
except OSError as exc:
2424
if exc.errno != errno.EEXIST:
2525
raise
2626
core.config['osg.job-environment'] = os.path.join(osg_libdir, 'osg-job-environment.conf')
2727
core.config['osg.local-job-environment'] = os.path.join(osg_libdir, 'osg-local-job-environment.conf')
2828

2929
files.write(core.config['osg.job-environment'],
3030
"#!/bin/sh\nJOB_ENV='vdt'\nexport JOB_ENV",
31-
owner='pbs', chmod=0644)
31+
owner='pbs', chmod=0o644)
3232
files.write(core.config['osg.local-job-environment'],
3333
"#!/bin/sh\nLOCAL_JOB_ENV='osg'\nexport LOCAL_JOB_ENV",
34-
owner='pbs', chmod=0644)
34+
owner='pbs', chmod=0o644)
3535

3636
core.state['jobs.env-set'] = True
3737

osgtest/tests/test_15_xrootd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def test_01_start_xrootd(self):
4242
user = pwd.getpwnam("xrootd")
4343
if core.config['xrootd.gsi'] == "ON":
4444
core.skip_ok_unless_installed('globus-proxy-utils')
45-
core.install_cert('certs.xrootdcert', 'certs.hostcert', 'xrootd', 0644)
46-
core.install_cert('certs.xrootdkey', 'certs.hostkey', 'xrootd', 0400)
45+
core.install_cert('certs.xrootdcert', 'certs.hostcert', 'xrootd', 0o644)
46+
core.install_cert('certs.xrootdkey', 'certs.hostkey', 'xrootd', 0o400)
4747

4848
lcmaps_packages = ('lcmaps', 'lcmaps-db-templates', 'xrootd-lcmaps', 'vo-client', 'vo-client-lcmaps-voms')
4949
if all([core.rpm_is_installed(x) for x in lcmaps_packages]):

0 commit comments

Comments
 (0)