From 536474bbb3bfb4bc29230af99dbed7bea8e7830d Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Thu, 20 Oct 2011 17:26:21 +1300 Subject: a start. only really committing so i can merge trunk... --- lava_dispatcher/connection.py | 98 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 lava_dispatcher/connection.py (limited to 'lava_dispatcher/connection.py') diff --git a/lava_dispatcher/connection.py b/lava_dispatcher/connection.py new file mode 100644 index 000000000..4e6782b1c --- /dev/null +++ b/lava_dispatcher/connection.py @@ -0,0 +1,98 @@ +# Copyright (C) 2011 Linaro Limited +# +# Author: Michael Hudson-Doyle +# +# This file is part of LAVA Dispatcher. +# +# LAVA Dispatcher is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# LAVA Dispatcher is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along +# with this program; if not, see . + +import logging +import time + +import pexpect + + +class LavaConmuxConnection(object): + + def __init__(self, device_config, sio): + self.device_config = device_config + cmd = "conmux-console %s" % self.device_option("hostname") + self.proc = pexpect.spawn(cmd, timeout=3600, logfile=sio) + #serial can be slow, races do funny things if you don't increase delay + self.proc.delaybeforesend=1 + + def device_option(self, option_name): + return self.device_config.get(option_name) + + def device_option_int(self, option_name): + return self.device_config.getint(option_name) + + + + def sendline(self, *args, **kw): + self.proc.sendline() + + def expect(self, *args, **kw): + self.proc.expect(*args, **kw) + + def sendcontrol(self, *args, **kw): + self.proc.sendcontrol(*args, **kw) + + @property + def match(self): + return self.proc.match + + + + def soft_reboot(self): + self.proc.sendline("reboot") + # set soft reboot timeout 120s, or do a hard reset + id = self.proc.expect( + ['Will now restart', pexpect.TIMEOUT], timeout=120) + if id != 0: + self.hard_reboot() + + def hard_reboot(self): + self.proc.send("~$") + self.proc.sendline("hardreset") + # XXX Workaround for snowball + if self.device_type == "snowball_sd": + time.sleep(10) + self.in_master_shell() + # Intentionally avoid self.soft_reboot() to prevent looping + self.proc.sendline("reboot") + self.enter_uboot() + + def enter_uboot(self): + self.proc.expect("Hit any key to stop autoboot") + self.proc.sendline("") + + def _boot(self, boot_cmds): + self.soft_reboot() + try: + self.enter_uboot() + except: + logging.exception("enter_uboot failed") + self.hard_reboot() + self.enter_uboot() + self.proc.sendline(boot_cmds[0]) + for line in range(1, len(boot_cmds)): + if self.device_type in ["mx51evk", "mx53loco"]: + self.proc.expect(">", timeout=300) + elif self.device_type == "snowball_sd": + self.proc.expect("\$", timeout=300) + else: + self.proc.expect("#", timeout=300) + self.proc.sendline(boot_cmds[line]) -- cgit v1.2.3 From c0c3d8788dc6761746728aa49ef17fb6b2dc1f3b Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Thu, 20 Oct 2011 17:50:04 +1300 Subject: finish replacing use of proc with connection --- lava_dispatcher/connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lava_dispatcher/connection.py') diff --git a/lava_dispatcher/connection.py b/lava_dispatcher/connection.py index df9eb96db..741d39550 100644 --- a/lava_dispatcher/connection.py +++ b/lava_dispatcher/connection.py @@ -69,7 +69,7 @@ class LavaConmuxConnection(object): self.proc.send("~$") self.proc.sendline("hardreset") # XXX Workaround for snowball - if self.device_type == "snowball_sd": + if self.device_option('device_type') == "snowball_sd": time.sleep(10) self.in_master_shell() # Intentionally avoid self.soft_reboot() to prevent looping -- cgit v1.2.3 From a0add65399eee69162af56cb8819e0fdb11015d2 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Thu, 20 Oct 2011 18:24:20 +1300 Subject: ah. that would be why nothing is working --- lava_dispatcher/connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lava_dispatcher/connection.py') diff --git a/lava_dispatcher/connection.py b/lava_dispatcher/connection.py index 741d39550..dc6b92c75 100644 --- a/lava_dispatcher/connection.py +++ b/lava_dispatcher/connection.py @@ -43,7 +43,7 @@ class LavaConmuxConnection(object): def sendline(self, *args, **kw): - self.proc.sendline() + self.proc.sendline(*args, **kw) def expect(self, *args, **kw): self.proc.expect(*args, **kw) -- cgit v1.2.3 From 080dfd67132a0a3230aafff78f2e72e84079c2e7 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Thu, 20 Oct 2011 18:28:58 +1300 Subject: embarrassing. please do not read :) --- lava_dispatcher/connection.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lava_dispatcher/connection.py') diff --git a/lava_dispatcher/connection.py b/lava_dispatcher/connection.py index dc6b92c75..62cfc6aaf 100644 --- a/lava_dispatcher/connection.py +++ b/lava_dispatcher/connection.py @@ -43,13 +43,13 @@ class LavaConmuxConnection(object): def sendline(self, *args, **kw): - self.proc.sendline(*args, **kw) + return self.proc.sendline(*args, **kw) def expect(self, *args, **kw): - self.proc.expect(*args, **kw) + return self.proc.expect(*args, **kw) def sendcontrol(self, *args, **kw): - self.proc.sendcontrol(*args, **kw) + return self.proc.sendcontrol(*args, **kw) @property def match(self): -- cgit v1.2.3 From 27897ae9409e0a5e857dd721629cbc06b8dd1bd7 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Wed, 26 Oct 2011 15:36:16 +1300 Subject: define the lava connection output a bit more --- lava_dispatcher/connection.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'lava_dispatcher/connection.py') diff --git a/lava_dispatcher/connection.py b/lava_dispatcher/connection.py index 62cfc6aaf..89c99d6d6 100644 --- a/lava_dispatcher/connection.py +++ b/lava_dispatcher/connection.py @@ -25,14 +25,14 @@ import time import pexpect -class LavaConmuxConnection(object): +class LavaConnection(object): def __init__(self, device_config, sio): self.device_config = device_config - cmd = "conmux-console %s" % self.device_option("hostname") - self.proc = pexpect.spawn(cmd, timeout=3600, logfile=sio) - #serial can be slow, races do funny things if you don't increase delay - self.proc.delaybeforesend=1 + self.proc = self._make_connection() + + def _make_connection(self): + raise NotImplementedError(self._make_connection) def device_option(self, option_name): return self.device_config.get(option_name) @@ -41,6 +41,7 @@ class LavaConmuxConnection(object): return self.device_config.getint(option_name) + # pexpect-like interface. def sendline(self, *args, **kw): return self.proc.sendline(*args, **kw) @@ -56,6 +57,7 @@ class LavaConmuxConnection(object): return self.proc.match + # Extra bits. def soft_reboot(self): self.proc.sendline("reboot") @@ -65,6 +67,18 @@ class LavaConmuxConnection(object): if id != 0: self.hard_reboot() + def hard_reboot(self): + raise NotImplementedError(self.hard_reboot) + + +class LavaConmuxConnection(object): + + def _make_connection(self, sio): + cmd = "conmux-console %s" % self.device_option("hostname") + self.proc = pexpect.spawn(cmd, timeout=3600, logfile=sio) + #serial can be slow, races do funny things if you don't increase delay + self.proc.delaybeforesend=1 + def hard_reboot(self): self.proc.send("~$") self.proc.sendline("hardreset") @@ -76,18 +90,18 @@ class LavaConmuxConnection(object): self.proc.sendline("reboot") self.enter_uboot() - def enter_uboot(self): + def _enter_uboot(self): self.proc.expect("Hit any key to stop autoboot") self.proc.sendline("") def _boot(self, boot_cmds): self.soft_reboot() try: - self.enter_uboot() + self._enter_uboot() except: - logging.exception("enter_uboot failed") + logging.exception("_enter_uboot failed") self.hard_reboot() - self.enter_uboot() + self._enter_uboot() self.proc.sendline(boot_cmds[0]) bootloader_prompt = re.escape(self.device_option('bootloader_prompt')) for line in range(1, len(boot_cmds)): -- cgit v1.2.3 From 65e9f82619ff1a43947d9c5b86f45f2dd6e28f1f Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Wed, 26 Oct 2011 15:41:41 +1300 Subject: small code motion --- lava_dispatcher/connection.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lava_dispatcher/connection.py') diff --git a/lava_dispatcher/connection.py b/lava_dispatcher/connection.py index 89c99d6d6..17c7f2c90 100644 --- a/lava_dispatcher/connection.py +++ b/lava_dispatcher/connection.py @@ -59,6 +59,10 @@ class LavaConnection(object): # Extra bits. + def _enter_uboot(self): + self.proc.expect("Hit any key to stop autoboot") + self.proc.sendline("") + def soft_reboot(self): self.proc.sendline("reboot") # set soft reboot timeout 120s, or do a hard reset @@ -90,10 +94,6 @@ class LavaConmuxConnection(object): self.proc.sendline("reboot") self.enter_uboot() - def _enter_uboot(self): - self.proc.expect("Hit any key to stop autoboot") - self.proc.sendline("") - def _boot(self, boot_cmds): self.soft_reboot() try: -- cgit v1.2.3 From 93467a3302c2145abf05a88624066aa5d013445c Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Wed, 26 Oct 2011 16:24:05 +1300 Subject: fix ridiculous bugs --- lava_dispatcher/connection.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lava_dispatcher/connection.py') diff --git a/lava_dispatcher/connection.py b/lava_dispatcher/connection.py index 976572643..749a61c41 100644 --- a/lava_dispatcher/connection.py +++ b/lava_dispatcher/connection.py @@ -29,9 +29,9 @@ class LavaConnection(object): def __init__(self, device_config, sio): self.device_config = device_config - self.proc = self._make_connection() + self.proc = self._make_connection(sio) - def _make_connection(self): + def _make_connection(self, sio): raise NotImplementedError(self._make_connection) def device_option(self, option_name): @@ -75,13 +75,14 @@ class LavaConnection(object): raise NotImplementedError(self.hard_reboot) -class LavaConmuxConnection(object): +class LavaConmuxConnection(LavaConnection): def _make_connection(self, sio): cmd = "conmux-console %s" % self.device_option("hostname") - self.proc = pexpect.spawn(cmd, timeout=3600, logfile=sio) + proc = pexpect.spawn(cmd, timeout=3600, logfile=sio) #serial can be slow, races do funny things if you don't increase delay - self.proc.delaybeforesend=1 + proc.delaybeforesend=1 + return proc def hard_reboot(self): self.proc.send("~$") -- cgit v1.2.3