Revision 53dbf14c test/import-export_unittest-helper
b/test/import-export_unittest-helper | ||
---|---|---|
24 | 24 |
import os |
25 | 25 |
import sys |
26 | 26 |
import errno |
27 |
import time |
|
27 | 28 |
|
28 | 29 |
from ganeti import constants |
29 | 30 |
from ganeti import utils |
... | ... | |
36 | 37 |
VALIDITY = int(os.getenv("VALIDITY", 1)) |
37 | 38 |
|
38 | 39 |
|
40 |
def Log(msg, *args): |
|
41 |
if args: |
|
42 |
line = msg % args |
|
43 |
else: |
|
44 |
line = msg |
|
45 |
|
|
46 |
sys.stderr.write("%0.6f, pid %s: %s\n" % (time.time(), os.getpid(), line)) |
|
47 |
sys.stderr.flush() |
|
48 |
|
|
49 |
|
|
39 | 50 |
def _GetImportExportData(filename): |
40 | 51 |
try: |
41 | 52 |
data = utils.ReadFile(filename) |
42 | 53 |
except EnvironmentError, err: |
54 |
Log("%s = %s", filename, err) |
|
43 | 55 |
if err.errno != errno.ENOENT: |
44 | 56 |
raise |
45 | 57 |
raise utils.RetryAgain() |
46 | 58 |
|
59 |
Log("%s = %s", filename, data.strip()) |
|
60 |
|
|
47 | 61 |
return objects.ImportExportStatus.FromDict(serializer.LoadJson(data)) |
48 | 62 |
|
49 | 63 |
|
50 | 64 |
def _CheckConnected(filename): |
51 | 65 |
if not _GetImportExportData(filename).connected: |
66 |
Log("Not connected") |
|
67 |
raise utils.RetryAgain() |
|
68 |
|
|
69 |
Log("Connected") |
|
70 |
|
|
71 |
|
|
72 |
def _CheckListenPort(filename): |
|
73 |
port = _GetImportExportData(filename).listen_port |
|
74 |
if not port: |
|
75 |
Log("No port") |
|
52 | 76 |
raise utils.RetryAgain() |
77 |
Log("Listening on %s", port) |
|
78 |
return port |
|
53 | 79 |
|
54 | 80 |
|
55 | 81 |
def WaitForListenPort(filename): |
56 |
return utils.Retry(lambda: _GetImportExportData(filename).listen_port,
|
|
57 |
RETRY_INTERVAL, TIMEOUT)
|
|
82 |
return utils.Retry(_CheckListenPort, RETRY_INTERVAL, TIMEOUT,
|
|
83 |
args=(filename, ))
|
|
58 | 84 |
|
59 | 85 |
|
60 | 86 |
def WaitForConnected(filename): |
Also available in: Unified diff