mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-10-07 17:40:30 +00:00
Check runlevel in order to terminate reading from the console
This commit is contained in:
parent
ed98ab30fd
commit
27950af66e
2 changed files with 12 additions and 5 deletions
|
@ -50,24 +50,33 @@ class VirtualBoxInstance(Instance):
|
||||||
|
|
||||||
def boot(self):
|
def boot(self):
|
||||||
self.machine.launch_vm_process(self.session, 'headless').wait_for_completion(-1)
|
self.machine.launch_vm_process(self.session, 'headless').wait_for_completion(-1)
|
||||||
|
self.console_output = self._read_console_output()
|
||||||
|
|
||||||
def get_console_output(self):
|
def _read_console_output(self):
|
||||||
import socket
|
import socket
|
||||||
import select
|
import select
|
||||||
import errno
|
import errno
|
||||||
import sys
|
import sys
|
||||||
console = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
console = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
console.connect(self.serial_port_path)
|
console.connect(self.serial_port_path)
|
||||||
|
|
||||||
console.setblocking(0)
|
console.setblocking(0)
|
||||||
|
|
||||||
|
runlvl_check = 'INIT: Entering runlevel: 2'
|
||||||
output = ''
|
output = ''
|
||||||
|
ptr = 0
|
||||||
continue_select = True
|
continue_select = True
|
||||||
while continue_select:
|
while continue_select:
|
||||||
read_ready, _, _ = select.select([console], [], [])
|
read_ready, _, _ = select.select([console], [], [])
|
||||||
if console in read_ready:
|
if console in read_ready:
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
sys.stdout.write(console.recv(1024))
|
read = console.recv(1024)
|
||||||
|
output += read
|
||||||
|
sys.stdout.write(read)
|
||||||
|
if runlvl_check in output[ptr:]:
|
||||||
|
continue_select = False
|
||||||
|
else:
|
||||||
|
ptr = len(output) - len(runlvl_check)
|
||||||
break
|
break
|
||||||
except socket.error, e:
|
except socket.error, e:
|
||||||
if e.errno != errno.EWOULDBLOCK:
|
if e.errno != errno.EWOULDBLOCK:
|
||||||
|
|
|
@ -45,14 +45,12 @@ volume:
|
||||||
image_path = '/Users/anders/Workspace/cloud/images/debian-wheezy-amd64-141130.vmdk'
|
image_path = '/Users/anders/Workspace/cloud/images/debian-wheezy-amd64-141130.vmdk'
|
||||||
|
|
||||||
image = VirtualBoxImage(manifest, image_path)
|
image = VirtualBoxImage(manifest, image_path)
|
||||||
output = None
|
|
||||||
try:
|
try:
|
||||||
instance = VirtualBoxInstance('unpartitioned_extlinux', image)
|
instance = VirtualBoxInstance('unpartitioned_extlinux', image)
|
||||||
try:
|
try:
|
||||||
instance.create()
|
instance.create()
|
||||||
try:
|
try:
|
||||||
instance.boot()
|
instance.boot()
|
||||||
output = instance.get_console_output()
|
|
||||||
# tools.reachable_with_ssh(instance)
|
# tools.reachable_with_ssh(instance)
|
||||||
finally:
|
finally:
|
||||||
instance.shutdown()
|
instance.shutdown()
|
||||||
|
|
Loading…
Add table
Reference in a new issue