Revision 4ca1b175
b/lib/utils.py | ||
---|---|---|
32 | 32 |
import socket |
33 | 33 |
import tempfile |
34 | 34 |
import shutil |
35 |
from errno import ENOENT, ENOTDIR, EISDIR, EEXIST, EADDRNOTAVAIL, ECONNREFUSED
|
|
35 |
import errno
|
|
36 | 36 |
|
37 | 37 |
from ganeti import logger |
38 | 38 |
from ganeti import errors |
... | ... | |
115 | 115 |
fd = os.open(lockfile, os.O_CREAT | os.O_EXCL | os.O_RDWR | os.O_SYNC) |
116 | 116 |
break |
117 | 117 |
except OSError, creat_err: |
118 |
if creat_err.errno != EEXIST: |
|
118 |
if creat_err.errno != errno.EEXIST:
|
|
119 | 119 |
raise errors.LockError("Can't create the lock file. Error '%s'." % |
120 | 120 |
str(creat_err)) |
121 | 121 |
|
... | ... | |
266 | 266 |
try: |
267 | 267 |
os.unlink(filename) |
268 | 268 |
except OSError, err: |
269 |
if err.errno not in (ENOENT, EISDIR):
|
|
269 |
if err.errno not in (errno.ENOENT, errno.EISDIR):
|
|
270 | 270 |
raise |
271 | 271 |
|
272 | 272 |
|
... | ... | |
355 | 355 |
try: |
356 | 356 |
f = open("/proc/%d/status" % pid) |
357 | 357 |
except IOError, err: |
358 |
if err.errno in (ENOENT, ENOTDIR):
|
|
358 |
if err.errno in (errno.ENOENT, errno.ENOTDIR):
|
|
359 | 359 |
return False |
360 | 360 |
|
361 | 361 |
alive = True |
... | ... | |
804 | 804 |
try: |
805 | 805 |
sock.bind((source, 0)) |
806 | 806 |
except socket.error, (errcode, errstring): |
807 |
if errcode == EADDRNOTAVAIL: |
|
807 |
if errcode == errno.EADDRNOTAVAIL:
|
|
808 | 808 |
success = False |
809 | 809 |
|
810 | 810 |
sock.settimeout(timeout) |
... | ... | |
816 | 816 |
except socket.timeout: |
817 | 817 |
success = False |
818 | 818 |
except socket.error, (errcode, errstring): |
819 |
success = (not live_port_needed) and (errcode == ECONNREFUSED) |
|
819 |
success = (not live_port_needed) and (errcode == errno.ECONNREFUSED)
|
|
820 | 820 |
|
821 | 821 |
return success |
b/test/ganeti.utils_unittest.py | ||
---|---|---|
28 | 28 |
import os.path |
29 | 29 |
import md5 |
30 | 30 |
import socket |
31 |
from errno import EADDRNOTAVAIL |
|
31 |
|
|
32 | 32 |
|
33 | 33 |
import ganeti |
34 | 34 |
from ganeti.utils import IsProcessAlive, Lock, Unlock, RunCmd, \ |
Also available in: Unified diff