bootstrap-vz/tests/integration/tools/__init__.py

89 lines
2.3 KiB
Python
Raw Normal View History

2014-11-30 14:09:21 +01:00
# Register deserialization handlers for objects
# that will pass between server and client
2014-11-30 14:13:43 +01:00
from bootstrapvz.remote import register_deserialization_handlers
2014-11-30 14:09:21 +01:00
register_deserialization_handlers()
# Snatched from here: http://stackoverflow.com/a/7205107
def merge_dicts(*args):
def merge(a, b, path=None):
if path is None:
path = []
for key in b:
if key in a:
if isinstance(a[key], dict) and isinstance(b[key], dict):
merge(a[key], b[key], path + [str(key)])
elif a[key] == b[key]:
pass
else:
raise Exception('Conflict at %s' % '.'.join(path + [str(key)]))
else:
a[key] = b[key]
return a
return reduce(merge, args, {})
2014-12-18 21:47:51 +01:00
def waituntil(predicate, timeout=5, interval=0.05):
import time
threshhold = time.time() + timeout
while time.time() < threshhold:
if predicate():
return True
time.sleep(interval)
return False
2014-12-20 16:07:00 +01:00
def read_from_socket(socket_path, termination_string, timeout):
import socket
import select
import errno
console = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
console.connect(socket_path)
console.setblocking(0)
output = ''
ptr = 0
continue_select = True
nooutput_for = 0
select_timeout = .5
while continue_select:
read_ready, _, _ = select.select([console], [], [], select_timeout)
if console in read_ready:
nooutput_for = 0
while True:
try:
output += console.recv(1024)
if termination_string in output[ptr:]:
continue_select = False
else:
ptr = len(output) - len(termination_string)
break
except socket.error, e:
if e.errno != errno.EWOULDBLOCK:
raise Exception(e)
continue_select = False
else:
nooutput_for += select_timeout
if nooutput_for > timeout:
from exceptions import SocketReadTimeout
msg = ('Reading from socket `{path}\' timed out after {seconds} seconds.'
.format(path=socket_path, timeout=nooutput_for))
raise SocketReadTimeout(msg)
console.close()
return output
2014-11-30 00:33:42 +01:00
def bootstrap(manifest, build_server):
2014-11-30 15:54:31 +01:00
from bootstrapvz.remote.build_servers import LocalBuildServer
2014-11-30 00:33:42 +01:00
if isinstance(build_server, LocalBuildServer):
from bootstrapvz.base.main import run
bootstrap_info = run(manifest)
else:
2014-11-30 14:13:43 +01:00
from bootstrapvz.remote.main import run
2014-11-30 15:42:38 +01:00
bootstrap_info = run(manifest, build_server)
2014-11-30 00:33:42 +01:00
return bootstrap_info
def test(instance):
2014-11-25 22:45:03 +01:00
pass