mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 07:26:29 +00:00
Refactor, logging, comments
This commit is contained in:
parent
08976ffe07
commit
0f4c08e51d
6 changed files with 78 additions and 37 deletions
|
@ -1,9 +1,6 @@
|
||||||
"""Main module containing all the setup necessary for running the bootstrapping process
|
"""Main module containing all the setup necessary for running the bootstrapping process
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
|
||||||
log = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main function for invoking the bootstrap process
|
"""Main function for invoking the bootstrap process
|
||||||
|
@ -12,6 +9,7 @@ def main():
|
||||||
"""
|
"""
|
||||||
# Get the commandline arguments
|
# Get the commandline arguments
|
||||||
opts = get_opts()
|
opts = get_opts()
|
||||||
|
|
||||||
# Require root privileges, except when doing a dry-run where they aren't needed
|
# Require root privileges, except when doing a dry-run where they aren't needed
|
||||||
import os
|
import os
|
||||||
if os.geteuid() != 0 and not opts['--dry-run']:
|
if os.geteuid() != 0 and not opts['--dry-run']:
|
||||||
|
@ -104,6 +102,8 @@ def run(manifest, debug=False, pause_on_error=False, dry_run=False):
|
||||||
from bootstrapinfo import BootstrapInformation
|
from bootstrapinfo import BootstrapInformation
|
||||||
bootstrap_info = BootstrapInformation(manifest=manifest, debug=debug)
|
bootstrap_info = BootstrapInformation(manifest=manifest, debug=debug)
|
||||||
|
|
||||||
|
import logging
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
try:
|
try:
|
||||||
# Run all the tasks the tasklist has gathered
|
# Run all the tasks the tasklist has gathered
|
||||||
tasklist.run(info=bootstrap_info, dry_run=dry_run)
|
tasklist.run(info=bootstrap_info, dry_run=dry_run)
|
||||||
|
|
|
@ -8,6 +8,12 @@ def register_deserialization_handlers():
|
||||||
SerializerBase.register_dict_to_class('bootstrapvz.base.bootstrapinfo.BootstrapInformation', deserialize_bootstrapinfo)
|
SerializerBase.register_dict_to_class('bootstrapvz.base.bootstrapinfo.BootstrapInformation', deserialize_bootstrapinfo)
|
||||||
|
|
||||||
|
|
||||||
|
def unregister_deserialization_handlers():
|
||||||
|
from Pyro4.util import SerializerBase
|
||||||
|
SerializerBase.unregister_dict_to_class('bootstrapvz.base.manifest.Manifest')
|
||||||
|
SerializerBase.unregister_dict_to_class('bootstrapvz.base.bootstrapinfo.BootstrapInformation')
|
||||||
|
|
||||||
|
|
||||||
def deserialize_manifest(classname, state):
|
def deserialize_manifest(classname, state):
|
||||||
from bootstrapvz.base.manifest import Manifest
|
from bootstrapvz.base.manifest import Manifest
|
||||||
return Manifest(path=state['path'], data=state['data'])
|
return Manifest(path=state['path'], data=state['data'])
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import logging
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CallbackServer(object):
|
class CallbackServer(object):
|
||||||
|
@ -17,6 +19,7 @@ class CallbackServer(object):
|
||||||
self.daemon.requestLoop()
|
self.daemon.requestLoop()
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
self.thread = Thread(target=serve)
|
self.thread = Thread(target=serve)
|
||||||
|
log.debug('Starting the callback server')
|
||||||
self.thread.start()
|
self.thread.start()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
|
"""Main module containing all the setup necessary for running the remote bootstrapping process
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main function for invoking the bootstrap process remotely
|
"""Main function for invoking the bootstrap process remotely
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# Get the commandline arguments
|
# Get the commandline arguments
|
||||||
opts = get_opts()
|
opts = get_opts()
|
||||||
|
@ -9,6 +14,7 @@ def main():
|
||||||
from bootstrapvz.base.manifest import Manifest
|
from bootstrapvz.base.manifest import Manifest
|
||||||
manifest = Manifest(path=opts['MANIFEST'])
|
manifest = Manifest(path=opts['MANIFEST'])
|
||||||
|
|
||||||
|
# Load the build servers
|
||||||
from bootstrapvz.common.tools import load_data
|
from bootstrapvz.common.tools import load_data
|
||||||
build_servers = load_data(opts['--servers'])
|
build_servers = load_data(opts['--servers'])
|
||||||
|
|
||||||
|
@ -16,35 +22,16 @@ def main():
|
||||||
from bootstrapvz.base.main import setup_loggers
|
from bootstrapvz.base.main import setup_loggers
|
||||||
setup_loggers(opts)
|
setup_loggers(opts)
|
||||||
|
|
||||||
|
# Register deserialization handlers for objects
|
||||||
|
# that will pass between server and client
|
||||||
from . import register_deserialization_handlers
|
from . import register_deserialization_handlers
|
||||||
register_deserialization_handlers()
|
register_deserialization_handlers()
|
||||||
|
|
||||||
bootstrap_info = None
|
# Everything has been set up, connect to the server and begin the bootstrapping process
|
||||||
|
run(manifest,
|
||||||
from ssh_rpc_manager import SSHRPCManager
|
build_servers[opts['SERVER']],
|
||||||
manager = SSHRPCManager(build_servers[opts['SERVER']])
|
debug=opts['--debug'],
|
||||||
try:
|
dry_run=opts['--dry-run'])
|
||||||
manager.start()
|
|
||||||
server = manager.rpc_server
|
|
||||||
from callback import CallbackServer
|
|
||||||
callback_server = CallbackServer(listen_port=manager.local_callback_port,
|
|
||||||
remote_port=manager.remote_callback_port)
|
|
||||||
from bootstrapvz.base.log import LogServer
|
|
||||||
log_server = LogServer()
|
|
||||||
try:
|
|
||||||
callback_server.start(log_server)
|
|
||||||
server.set_log_server(log_server)
|
|
||||||
|
|
||||||
# Everything has been set up, begin the bootstrapping process
|
|
||||||
bootstrap_info = server.run(manifest,
|
|
||||||
debug=opts['--debug'],
|
|
||||||
pause_on_error=False,
|
|
||||||
dry_run=opts['--dry-run'])
|
|
||||||
finally:
|
|
||||||
callback_server.stop()
|
|
||||||
finally:
|
|
||||||
manager.stop()
|
|
||||||
return bootstrap_info
|
|
||||||
|
|
||||||
|
|
||||||
def get_opts():
|
def get_opts():
|
||||||
|
@ -65,3 +52,42 @@ Options:
|
||||||
-h, --help show this help
|
-h, --help show this help
|
||||||
"""
|
"""
|
||||||
return docopt(usage)
|
return docopt(usage)
|
||||||
|
|
||||||
|
|
||||||
|
def run(manifest, server, debug=False, dry_run=False):
|
||||||
|
"""Connects to the remote build server, starts an RPC daemin
|
||||||
|
on the other side and initiates a remote bootstrapping procedure
|
||||||
|
"""
|
||||||
|
bootstrap_info = None
|
||||||
|
|
||||||
|
from ssh_rpc_manager import SSHRPCManager
|
||||||
|
manager = SSHRPCManager(server)
|
||||||
|
try:
|
||||||
|
# Connect to the build server and start the RPC daemon
|
||||||
|
manager.start()
|
||||||
|
server = manager.rpc_server
|
||||||
|
# Start a callback server on this side, so that we may receive log entries
|
||||||
|
from callback import CallbackServer
|
||||||
|
callback_server = CallbackServer(listen_port=manager.local_callback_port,
|
||||||
|
remote_port=manager.remote_callback_port)
|
||||||
|
from bootstrapvz.base.log import LogServer
|
||||||
|
log_server = LogServer()
|
||||||
|
try:
|
||||||
|
# Start the callback server (in a background thread)
|
||||||
|
callback_server.start(log_server)
|
||||||
|
# Tell the RPC daemon about the callback server
|
||||||
|
server.set_log_server(log_server)
|
||||||
|
|
||||||
|
# Everything has been set up, begin the bootstrapping process
|
||||||
|
bootstrap_info = server.run(manifest,
|
||||||
|
debug=debug,
|
||||||
|
# We can't pause the bootstrapping process remotely, yet...
|
||||||
|
pause_on_error=False,
|
||||||
|
dry_run=dry_run)
|
||||||
|
finally:
|
||||||
|
# Stop the callback server
|
||||||
|
callback_server.stop()
|
||||||
|
finally:
|
||||||
|
# Stop the RPC daemon and close the SSH connection
|
||||||
|
manager.stop()
|
||||||
|
return bootstrap_info
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import logging
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -10,7 +12,6 @@ def main():
|
||||||
|
|
||||||
|
|
||||||
def setup_logging():
|
def setup_logging():
|
||||||
import logging
|
|
||||||
from bootstrapvz.base.log import LogForwarder
|
from bootstrapvz.base.log import LogForwarder
|
||||||
log_forwarder = LogForwarder()
|
log_forwarder = LogForwarder()
|
||||||
root = logging.getLogger()
|
root = logging.getLogger()
|
||||||
|
@ -52,7 +53,8 @@ class Server(object):
|
||||||
return run(*args, **kwargs)
|
return run(*args, **kwargs)
|
||||||
|
|
||||||
def set_log_server(self, server):
|
def set_log_server(self, server):
|
||||||
return self.log_forwarder.set_server(server)
|
self.log_forwarder.set_server(server)
|
||||||
|
log.debug('Successfully set the log forwarding server')
|
||||||
|
|
||||||
def ping(self):
|
def ping(self):
|
||||||
return 'pong'
|
return 'pong'
|
||||||
|
|
|
@ -37,7 +37,7 @@ class SSHRPCManager(object):
|
||||||
'sudo', self.settings['server-bin'],
|
'sudo', self.settings['server-bin'],
|
||||||
'--listen', str(self.remote_server_port)]
|
'--listen', str(self.remote_server_port)]
|
||||||
import sys
|
import sys
|
||||||
self.process = subprocess.Popen(args=ssh_cmd, stdout=sys.stderr, stderr=sys.stderr)
|
self.ssh_process = subprocess.Popen(args=ssh_cmd, stdout=sys.stderr, stderr=sys.stderr)
|
||||||
|
|
||||||
# Check that we can connect to the server
|
# Check that we can connect to the server
|
||||||
try:
|
try:
|
||||||
|
@ -45,7 +45,7 @@ class SSHRPCManager(object):
|
||||||
server_uri = 'PYRO:server@localhost:{server_port}'.format(server_port=self.local_server_port)
|
server_uri = 'PYRO:server@localhost:{server_port}'.format(server_port=self.local_server_port)
|
||||||
self.rpc_server = Pyro4.Proxy(server_uri)
|
self.rpc_server = Pyro4.Proxy(server_uri)
|
||||||
|
|
||||||
log.debug('Connecting to PYRO')
|
log.debug('Connecting to the RPC daemon')
|
||||||
remaining_retries = 5
|
remaining_retries = 5
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
@ -59,10 +59,14 @@ class SSHRPCManager(object):
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
except (Exception, KeyboardInterrupt) as e:
|
except (Exception, KeyboardInterrupt) as e:
|
||||||
self.process.terminate()
|
self.ssh_process.terminate()
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.rpc_server.stop()
|
if hasattr(self, 'rpc_server'):
|
||||||
self.rpc_server._pyroRelease()
|
log.debug('Stopping the RPC daemon')
|
||||||
self.process.wait()
|
self.rpc_server.stop()
|
||||||
|
self.rpc_server._pyroRelease()
|
||||||
|
if hasattr(self, 'ssh_process'):
|
||||||
|
log.debug('Waiting for the SSH connection to terminate')
|
||||||
|
self.ssh_process.wait()
|
||||||
|
|
Loading…
Add table
Reference in a new issue