~milo/lava-dispatcher/tar-repo

« back to all changes in this revision

Viewing changes to lava_dispatcher/device/target.py

UEFI support for Fastmodels. Add interactive bootloader support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
import contextlib
22
22
import os
 
23
import shutil
 
24
import re
23
25
 
24
26
from lava_dispatcher.client.lmc_utils import (
25
27
    image_partition_mounted,
67
69
    def __init__(self, context, device_config):
68
70
        self.context = context
69
71
        self.config = device_config
70
 
 
71
72
        self.boot_options = []
72
73
        self._scratch_dir = None
73
74
        self.deployment_data = {}
154
155
        """
155
156
        return 'unknown'
156
157
 
 
158
    def _find_and_copy(self, rootdir, odir, pattern, name=None):
 
159
        dest = None
 
160
        for root, dirs, files in os.walk(rootdir):
 
161
            for file in files:
 
162
                if re.match(pattern, file):
 
163
                    if name:
 
164
                        dest = os.path.join(odir, name)
 
165
                    else:
 
166
                        dest = os.path.join(odir, file)
 
167
                    if rootdir != odir:
 
168
                        src = os.path.join(rootdir, file)
 
169
                        shutil.copyfile(src, dest)
 
170
                        return dest
 
171
                    else:
 
172
                        return dest
 
173
        return dest
 
174
 
 
175
    def _customize_bootloader(self):
 
176
        self.proc.expect(self.config.bootloader_prompt, timeout=300)
 
177
        if isinstance(self.config.boot_cmds, basestring):
 
178
            boot_cmds = utils.string_to_list(self.config.boot_cmds.encode('ascii'))
 
179
        else:
 
180
            boot_cmds = self.config.boot_cmds
 
181
        for line in boot_cmds:
 
182
            parts = re.match('^(?P<action>sendline|expect)\s*(?P<command>.*)', line)
 
183
            if parts:
 
184
                try:
 
185
                    action = parts.group('action')
 
186
                    command = parts.group('command')
 
187
                except AttributeError as e:
 
188
                    raise Exception("Badly formatted command in boot_cmds %s" % e)
 
189
                if action == "sendline":
 
190
                    self.proc.send(command)
 
191
                    self.proc.sendline('')
 
192
                elif action == "expect":
 
193
                    command = re.escape(command)
 
194
                    self.proc.expect(command, timeout=300)
 
195
            else:
 
196
                self.proc.sendline(line)
 
197
 
157
198
    def _customize_ubuntu(self, rootdir):
158
199
        self.deployment_data = Target.ubuntu_deployment_data
159
200
        with open('%s/root/.bashrc' % rootdir, 'a') as f: