Exemplo n.º 1
0
 def start_testcase(self, test_case_id):
     case_dir = os.path.join(self.result_dir, test_case_id)
     utils.ensure_directory(case_dir)
     case_data = {'case_dir': case_dir}
     case_data['start_testcase_output'] = self._invoke_hook(
         'start_testcase', case_dir)
     return case_data
 def start_testcase(self, test_case_id):
     case_dir = os.path.join(self.result_dir, test_case_id)
     utils.ensure_directory(case_dir)
     case_data = {'case_dir': case_dir}
     case_data['start_testcase_output'] = self._invoke_hook(
         'start_testcase', case_dir)
     return case_data
Exemplo n.º 3
0
def create_config(name, data):
    filename = os.path.join(tmp_config_dir, name)
    if not os.path.exists(os.path.dirname(filename)):
        utils.ensure_directory(os.path.dirname(filename))
    with open(filename, 'w') as f:
        for key in data.keys():
            f.write("%s = %s\n" % (key, data[key]))
Exemplo n.º 4
0
 def file_system(self, partition, directory):
     # whaley
     # partition = 5
     # directory = None
     if self._is_bootloader() and self._reset_boot:
         self._reset_boot = False
         if self._in_test_shell:
             self._in_test_shell = False
             raise Exception("Operation timed out, resetting platform!")
     # bootloader and not booted
     if self._is_bootloader() and not self._booted:
         # self.context.client.boot_linaro_image()
         # reboot the system to the test image
         # if we don't use boot_whaley_image in job, use lava_test_shell directly, then boot the image
         self.context.client.boot_whaley_image()
     # for deploy linaro kernel, pass here
     if self._is_bootloader() and self._lava_nfsrootfs:
         path = '%s/%s' % (self._lava_nfsrootfs, directory)
         ensure_directory(path)
         yield path
     # bootloader
     elif self._is_bootloader():
         # pat = 'TESTER_PS1': "shell@helios:/ # "
         # incrc = 'TESTER_PS1_INCLUDES_RC': False
         pat = self.tester_ps1_pattern
         incrc = self.tester_ps1_includes_rc
         runner = NetworkCommandRunner(self, pat, incrc)
         with self._busybox_file_system(runner, directory) as path:
             yield path
     else:
         with super(BootloaderTarget,
                    self).file_system(partition, directory) as path:
             yield path
Exemplo n.º 5
0
def create_config(name, data):
    filename = os.path.join(tmp_config_dir, name)
    if not os.path.exists(os.path.dirname(filename)):
        utils.ensure_directory(os.path.dirname(filename))
    with open(filename, 'w') as f:
        for key in data.keys():
            f.write("%s = %s\n" % (key, data[key]))
Exemplo n.º 6
0
    def _busybox_file_system(self, runner, directory, mounted=False):
        error_detected = False
        try:
            if mounted:
                targetdir = os.path.abspath(os.path.join('/mnt/%s' %
                                                         directory))
            else:
                targetdir = os.path.abspath(os.path.join('/', directory))

            runner.run('mkdir -p %s' % targetdir)

            parent_dir, target_name = os.path.split(targetdir)

            runner.run('/bin/tar -cmzf /tmp/fs.tgz -C %s %s' %
                       (parent_dir, target_name))
            runner.run('cd /tmp')  # need to be in same dir as fs.tgz

            try:
                ip = runner.get_target_ip()
            except NetworkError as e:
                error_detected = True
                raise CriticalError("Network error detected..aborting")

            url_base = self._start_busybox_http_server(runner, ip)

            url = url_base + '/fs.tgz'
            logging.info("Fetching url: %s", url)
            tf = download_image(url,
                                self.context,
                                self.scratch_dir,
                                decompress=False)

            tfdir = os.path.join(self.scratch_dir, str(time.time()))

            try:
                utils.ensure_directory(tfdir)
                self.context.run_command('/bin/tar -C %s -xzf %s' %
                                         (tfdir, tf))
                yield os.path.join(tfdir, target_name)
            finally:
                tf = os.path.join(self.scratch_dir, 'fs.tgz')
                utils.mk_targz(tf, tfdir)
                utils.rmtree(tfdir)

                # get the last 2 parts of tf, ie "scratchdir/tf.tgz"
                tf = '/'.join(tf.split('/')[-2:])
                runner.run('rm -rf %s' % targetdir)
                self._target_extract(runner, tf, parent_dir, busybox=True)
        finally:
            if not error_detected:
                self._stop_busybox_http_server(runner)
            if mounted:
                runner.run('umount /mnt')
Exemplo n.º 7
0
    def _bundle_results(self, target, signal_director, testdef_objs):
        """ Pulls the results from the target device and builds a bundle
        """
        results_part = target.deployment_data['lava_test_results_part_attr']
        results_part = getattr(target.config, results_part)
        rdir = self.context.host_result_dir
        parse_err_msg = None

        filesystem_access_failure = True

        try:
            with target.file_system(results_part, target.lava_test_results_dir) as d:
                filesystem_access_failure = False
                err_log = os.path.join(d, 'parse_err.log')
                results_dir = os.path.join(d, 'results')
                bundle = lava_test_shell.get_bundle(results_dir, testdef_objs, err_log)
                parse_err_msg = read_content(err_log, ignore_missing=True)
                if os.path.isfile(err_log):
                    os.unlink(err_log)
                # lava/results must be empty, but we keep a copy named
                # lava/results-XXXXXXXXXX for post-mortem analysis
                timestamp = datetime.now().strftime("%s")
                os.rename(results_dir, results_dir + '-' + timestamp)
                utils.ensure_directory(results_dir)
        except Exception as e:
            if filesystem_access_failure:
                # a failure when accessing the filesystem means the device
                # probably crashed. We use the backup bundle then.
                bundle = self._backup_bundle
                logging.warning(
                    """Error extracting test results from device: %s""" % e)
                logging.warning(
                    """This may mean that the device under test crashed. """
                    """We will use test results parsed from the serial """
                    """output as a backup, but note that some test """
                    """artifacts (such as attachments and """
                    """hardware/software contexts) will not be available""")
            else:
                raise e

        signal_director.postprocess_bundle(bundle)

        (fd, name) = tempfile.mkstemp(
            prefix='lava-test-shell', suffix='.bundle', dir=rdir)
        with os.fdopen(fd, 'w') as f:
            DocumentIO.dump(f, bundle)

        printer = PrettyPrinter(self.context)
        printer.print_results(bundle)

        if parse_err_msg:
            raise GeneralError(parse_err_msg)
Exemplo n.º 8
0
    def _busybox_file_system(self, runner, directory, mounted=False):
        error_detected = False
        try:
            if mounted:
                targetdir = os.path.abspath(os.path.join('/mnt/%s' % directory))
            else:
                targetdir = os.path.abspath(os.path.join('/', directory))

            runner.run('mkdir -p %s' % targetdir)

            parent_dir, target_name = os.path.split(targetdir)

            runner.run('/bin/tar -cmzf /tmp/fs.tgz -C %s %s'
                       % (parent_dir, target_name))
            runner.run('cd /tmp')  # need to be in same dir as fs.tgz

            try:
                ip = runner.get_target_ip()
            except NetworkError as e:
                error_detected = True
                raise CriticalError("Network error detected..aborting")

            url_base = self._start_busybox_http_server(runner, ip)

            url = url_base + '/fs.tgz'
            logging.info("Fetching url: %s", url)
            tf = download_image(url, self.context, self.scratch_dir,
                                decompress=False)

            tfdir = os.path.join(self.scratch_dir, str(time.time()))

            try:
                utils.ensure_directory(tfdir)
                self.context.run_command('/bin/tar -C %s -xzf %s'
                                         % (tfdir, tf))
                yield os.path.join(tfdir, target_name)
            finally:
                tf = os.path.join(self.scratch_dir, 'fs.tgz')
                utils.mk_targz(tf, tfdir)
                utils.rmtree(tfdir)

                # get the last 2 parts of tf, ie "scratchdir/tf.tgz"
                tf = '/'.join(tf.split('/')[-2:])
                runner.run('rm -rf %s' % targetdir)
                self._target_extract(runner, tf, parent_dir, busybox=True)
        finally:
            if not error_detected:
                self._stop_busybox_http_server(runner)
            if mounted:
                runner.run('umount /mnt')
Exemplo n.º 9
0
    def file_system(self, partition, directory):
        """
        This works in conjunction with the "mux_device" function to safely
        access a partition/directory on the sdmux filesystem
        """
        self.proc.sendline('sync')
        self.proc.expect(self.tester_ps1_pattern)
        logging.info('powering off')
        self.context.run_command(self.config.power_off_cmd)

        sdmux.dut_disconnect(self.config.sdmux_id)
        sdmux.host_usda(self.config.sdmux_id)

        mntdir = os.path.join(self.scratch_dir, 'sdmux_mnt')
        ensure_directory(mntdir)

        device = self.mux_device()
        device = '%s%s' % (device, partition)
        try:
            self.context.run_command(['mount', device, mntdir], failok=False)
            if directory[0] == '/':
                directory = directory[1:]
            path = os.path.join(mntdir, directory)
            ensure_directory(path)
            logging.info('sdmux(%s) mounted at: %s', device, path)
            yield path
        except CriticalError:
            raise
        except subprocess.CalledProcessError:
            raise CriticalError('Unable to access sdmux device')
        except KeyboardInterrupt:
            raise KeyboardInterrupt
        except:
            logging.exception('Error accessing sdmux filesystem')
            raise CriticalError('Error accessing sdmux filesystem')
        finally:
            logging.info('unmounting sdmux')
            try:
                _flush_files(mntdir)
                self.context.run_command(['umount', device], failok=False)
            except subprocess.CalledProcessError:
                logging.exception('umount failed, re-try in 10 seconds')
                time.sleep(10)
                if self.context.run_command(['umount', device]) != 0:
                    logging.error(
                        'Unable to unmount sdmux device %s', device)

        sdmux.host_disconnect(self.config.sdmux_id)
Exemplo n.º 10
0
    def file_system(self, partition, directory):

        # If we are using NFS
        if '{NFSROOTFS}' in self._boot_tags:
            path = self._boot_tags['{NFSROOTFS}'] + directory
            logging.info("NFSROOTFS=%s", path)
            ensure_directory(path)
            yield path
        else:
            if not self._booted:
                self.context.client.boot_linaro_image()
            pat = self.tester_ps1_pattern
            incrc = self.tester_ps1_includes_rc
            runner = NetworkCommandRunner(self, pat, incrc)
            with self._busybox_file_system(runner, directory) as path:
                yield path
    def file_system(self, partition, directory):

        # If we are using NFS
        if '{NFSROOTFS}' in self._boot_tags:
            path = self._boot_tags['{NFSROOTFS}'] + directory
            logging.info("NFSROOTFS=%s", path)
            ensure_directory(path)
            yield path
        else:
            if not self._booted:
                self.context.client.boot_linaro_image()
            pat = self.tester_ps1_pattern
            incrc = self.tester_ps1_includes_rc
            runner = NetworkCommandRunner(self, pat, incrc)
            with self._busybox_file_system(runner, directory) as path:
                yield path
 def file_system(self, partition, directory):
     if self._ramdisk_boot:
         if self._reset_boot:
             self._booted = False
             self._reset_boot = False
             raise Exception("Operation timed out, resetting platform!")
         elif not self._booted:
             self.context.client.boot_linaro_image()
         pat = self.tester_ps1_pattern
         incrc = self.tester_ps1_includes_rc
         runner = NetworkCommandRunner(self, pat, incrc)
         with self._busybox_file_system(runner, directory) as path:
             yield path
     else:
         with image_partition_mounted(self._sd_image, partition) as mntdir:
             path = '%s/%s' % (mntdir, directory)
             ensure_directory(path)
             yield path
Exemplo n.º 13
0
    def copy_test(self, hostdir, targetdir):
        """Copy the files needed to run this test to the device.

        :param hostdir: The location on the device filesystem to copy too.
        :param targetdir: The location `hostdir` will have when the device
            boots.
        """
        utils.ensure_directory(hostdir)
        self._fetch_all_parameters()
        with open('%s/testdef.yaml' % hostdir, 'w') as f:
            f.write(yaml.dump(self.testdef, encoding='utf-8', allow_unicode=True))

        with open('%s/uuid' % hostdir, 'w', encoding='utf-8') as f:
            f.write(self.uuid)

        with open('%s/testdef_metadata' % hostdir, 'w', encoding='utf-8') as f:
            f.write(yaml.safe_dump(self.testdef_metadata))

        if self.skip_install != "all":
            if 'install' in self.testdef:
                if self.skip_install != 'repos':
                    self._create_repos(hostdir)
                self._create_target_install(hostdir, targetdir)

        with open('%s/run.sh' % hostdir, 'w', encoding='utf-8') as f:
            self._inject_testdef_parameters(f)
            f.write('set -e\n')
            f.write('export TESTRUN_ID=%s\n' % self.test_id)
            f.write('cd %s\n' % targetdir)
            f.write('UUID=`cat uuid`\n')
            f.write('echo "<LAVA_SIGNAL_STARTRUN $TESTRUN_ID $UUID>"\n')
            f.write('#wait for an ack from the dispatcher\n')
            f.write('read\n')
            steps = self.testdef['run'].get('steps', [])
            if steps:
                for cmd in steps:
                    if '--cmd' in cmd or '--shell' in cmd:
                        cmd = re.sub(r'\$(\d+)\b', r'\\$\1', cmd)
                    f.write('%s\n' % cmd)
            f.write('echo "<LAVA_SIGNAL_ENDRUN $TESTRUN_ID $UUID>"\n')
            f.write('#wait for an ack from the dispatcher\n')
            f.write('read\n')
Exemplo n.º 14
0
 def file_system(self, partition, directory):
     if self._ramdisk_boot:
         if self._reset_boot:
             self._reset_boot = False
             if self._in_test_shell:
                 self._in_test_shell = False
                 raise Exception("Operation timed out, resetting platform!")
         elif not self._booted:
             self.context.client.boot_linaro_image()
         pat = self.tester_ps1_pattern
         incrc = self.tester_ps1_includes_rc
         runner = NetworkCommandRunner(self, pat, incrc)
         with self._busybox_file_system(runner, directory) as path:
             yield path
     else:
         self._check_power_state()
         with image_partition_mounted(self._sd_image, partition) as mntdir:
             path = '%s/%s' % (mntdir, directory)
             ensure_directory(path)
             yield path
Exemplo n.º 15
0
 def file_system(self, partition, directory):
     if self._is_bootloader() and self._reset_boot:
         self._booted = False
         self._reset_boot = False
         raise Exception("Operation timed out, resetting platform!")
     if self._is_bootloader() and not self._booted:
         self.context.client.boot_linaro_image()
     if self._is_bootloader() and self._lava_nfsrootfs:
         path = '%s/%s' % (self._lava_nfsrootfs, directory)
         ensure_directory(path)
         yield path
     elif self._is_bootloader():
         pat = self.tester_ps1_pattern
         incrc = self.tester_ps1_includes_rc
         runner = NetworkCommandRunner(self, pat, incrc)
         with self._busybox_file_system(runner, directory) as path:
             yield path
     else:
         with super(BootloaderTarget, self).file_system(
                 partition, directory) as path:
             yield path
Exemplo n.º 16
0
 def file_system(self, partition, directory):
     if self._is_bootloader() and self._reset_boot:
         self._booted = False
         self._reset_boot = False
         raise Exception("Operation timed out, resetting platform!")
     if self._is_bootloader() and not self._booted:
         self.context.client.boot_linaro_image()
     if self._is_bootloader() and self._lava_nfsrootfs:
         path = '%s/%s' % (self._lava_nfsrootfs, directory)
         ensure_directory(path)
         yield path
     elif self._is_bootloader():
         pat = self.tester_ps1_pattern
         incrc = self.tester_ps1_includes_rc
         runner = NetworkCommandRunner(self, pat, incrc)
         with self._busybox_file_system(runner, directory) as path:
             yield path
     else:
         with super(BootloaderTarget,
                    self).file_system(partition, directory) as path:
             yield path
Exemplo n.º 17
0
    def copy_test(self, hostdir, targetdir):  # FIXME: needs a dedicated Action
        """Copy the files needed to run this test to the device.

        :param hostdir: The location on the device filesystem to copy too.
        :param targetdir: The location `hostdir` will have when the device
            boots.
        """
        utils.ensure_directory(hostdir)
        with open('%s/testdef.yaml' % hostdir, 'w') as f:
            f.write(yaml.dump(self.testdef))

        with open('%s/uuid' % hostdir, 'w') as f:
            f.write(self.uuid)

        with open('%s/testdef_metadata' % hostdir, 'w') as f:
            f.write(yaml.safe_dump(self.testdef_metadata))

        if self.skip_install != "all":
            if 'install' in self.testdef:
                if self.skip_install != 'repos':
                    self._create_repos(hostdir)
                self._create_target_install(hostdir, targetdir)

        with open('%s/run.sh' % hostdir, 'w') as f:
            self._inject_testdef_parameters(f)
            f.write('set -e\n')
            f.write('export TESTRUN_ID=%s\n' % self.test_id)
            f.write('cd %s\n' % targetdir)
            f.write('UUID=`cat uuid`\n')
            f.write('echo "<LAVA_SIGNAL_STARTRUN $TESTRUN_ID $UUID>"\n')
            f.write('#wait for an ack from the dispatcher\n')
            f.write('read\n')
            steps = self.testdef['run'].get('steps', [])
            if steps:
                for cmd in steps:
                    f.write('%s\n' % cmd)
            f.write('echo "<LAVA_SIGNAL_ENDRUN $TESTRUN_ID $UUID>"\n')
            f.write('#wait for an ack from the dispatcher\n')
            f.write('read\n')
Exemplo n.º 18
0
 def file_system(self, partition, directory):
     with self.backend_adapter.mount(partition) as mntdir:
         target = '%s/%s' % (mntdir, directory)
         ensure_directory(target)
         yield target
Exemplo n.º 19
0
def setup_config_dir():
    utils.ensure_directory(tmp_config_dir)
Exemplo n.º 20
0
 def file_system(self, partition, directory):
     self._check_power_state()
     with image_partition_mounted(self._sd_image, partition) as mntdir:
         path = '%s/%s' % (mntdir, directory)
         ensure_directory(path)
         yield path
Exemplo n.º 21
0
    def _python_file_system(self, runner, directory, prompt_pattern, mounted=False):
        connection = runner.get_connection()
        error_detected = False
        try:
            if mounted:
                targetdir = os.path.abspath(os.path.join('/mnt/%s' % directory))
            else:
                targetdir = os.path.abspath(os.path.join('/', directory))

            runner.run('mkdir -p %s' % targetdir)

            parent_dir, target_name = os.path.split(targetdir)

            runner.run('nice tar -czf /tmp/fs.tgz -C %s %s' %
                       (parent_dir, target_name))
            runner.run('cd /tmp')  # need to be in same dir as fs.tgz

            try:
                ip = runner.get_target_ip()
            except NetworkError as e:
                error_detected = True
                raise CriticalError("Network error detected..aborting")

            connection.sendline('python -m SimpleHTTPServer 0 2>/dev/null')
            match_id = connection.expect([
                'Serving HTTP on 0.0.0.0 port (\d+) \.\.',
                pexpect.EOF, pexpect.TIMEOUT])
            if match_id != 0:
                msg = "Unable to start HTTP server"
                logging.error(msg)
                raise CriticalError(msg)
            port = connection.match.groups()[match_id]

            url = "http://%s:%s/fs.tgz" % (ip, port)
            tf = download_image(url,
                                self.context, self.scratch_dir, decompress=False)

            tfdir = os.path.join(self.scratch_dir, str(time.time()))
            try:
                utils.ensure_directory(tfdir)
                self.context.run_command('nice tar --selinux -C %s -xzf %s' % (tfdir, tf))
                yield os.path.join(tfdir, target_name)

            finally:
                tf = os.path.join(self.scratch_dir, 'fs.tgz')
                utils.mk_targz(tf, tfdir)
                utils.rmtree(tfdir)

                connection.sendcontrol('c')  # kill SimpleHTTPServer
                self._wait_for_prompt(connection,
                                      prompt_pattern,
                                      timeout=30)

                # get the last 2 parts of tf, ie "scratchdir/tf.tgz"
                tf = '/'.join(tf.split('/')[-2:])
                runner.run('rm -rf %s' % targetdir)
                self._target_extract(runner, tf, parent_dir)

        finally:
            if not error_detected:
                # kill SimpleHTTPServer
                connection.sendcontrol('c')
                self._wait_for_prompt(connection,
                                      prompt_pattern,
                                      timeout=30)
            if mounted:
                runner.run('umount /mnt')
Exemplo n.º 22
0
def get_config():
    config = lava_dispatcher.config.get_config()
    config.lava_image_tmpdir = os.path.join(tmpdir, 'images')
    if not os.path.exists(config.lava_image_tmpdir):
        utils.ensure_directory(config.lava_image_tmpdir)
    return config
Exemplo n.º 23
0
 def file_system(self, partition, directory):
     root = '/var/lib/lxc/%s/rootfs' % self.name
     logging.debug("Accessing the file system at %s", root)
     dest = root + directory
     ensure_directory(dest)
     yield dest
Exemplo n.º 24
0
 def file_system(self, partition, directory):
     with self.backend_adapter.mount(partition) as mntdir:
         target = '%s/%s' % (mntdir, directory)
         ensure_directory(target)
         yield target
Exemplo n.º 25
0
 def file_system(self, partition, directory):
     self._check_power_state()
     with image_partition_mounted(self._sd_image, partition) as mntdir:
         path = '%s/%s' % (mntdir, directory)
         ensure_directory(path)
         yield path
Exemplo n.º 26
0
 def _mk_runner_dirs(self, mntdir):
     utils.ensure_directory('%s/bin' % mntdir)
     utils.ensure_directory_empty('%s/tests' % mntdir)
     utils.ensure_directory_empty('%s/results' % mntdir)
Exemplo n.º 27
0
def setup_config_dir():
    utils.ensure_directory(tmp_config_dir)
    def _python_file_system(self, runner, directory, prompt_pattern, mounted=False):
        connection = runner.get_connection()
        error_detected = False
        try:
            if mounted:
                targetdir = os.path.abspath(os.path.join('/mnt/%s' % directory))
            else:
                targetdir = os.path.abspath(os.path.join('/', directory))

            runner.run('mkdir -p %s' % targetdir)

            parent_dir, target_name = os.path.split(targetdir)

            runner.run('nice tar -czf /tmp/fs.tgz -C %s %s' %
                       (parent_dir, target_name))
            runner.run('cd /tmp')  # need to be in same dir as fs.tgz

            try:
                ip = runner.get_target_ip()
            except NetworkError as e:
                error_detected = True
                raise CriticalError("Network error detected..aborting")

            connection.sendline('python -m SimpleHTTPServer 0 2>/dev/null')
            match_id = connection.expect([
                'Serving HTTP on 0.0.0.0 port (\d+) \.\.',
                pexpect.EOF, pexpect.TIMEOUT])
            if match_id != 0:
                msg = "Unable to start HTTP server"
                logging.error(msg)
                raise CriticalError(msg)
            port = connection.match.groups()[match_id]

            url = "http://%s:%s/fs.tgz" % (ip, port)
            tf = download_image(url,
                                self.context, self.scratch_dir, decompress=False)

            tfdir = os.path.join(self.scratch_dir, str(time.time()))
            try:
                utils.ensure_directory(tfdir)
                self.context.run_command('nice tar --selinux -C %s -xzf %s' % (tfdir, tf))
                yield os.path.join(tfdir, target_name)

            finally:
                tf = os.path.join(self.scratch_dir, 'fs.tgz')
                utils.mk_targz(tf, tfdir)
                utils.rmtree(tfdir)

                connection.sendcontrol('c')  # kill SimpleHTTPServer
                self._wait_for_prompt(connection,
                                      prompt_pattern,
                                      timeout=30)

                # get the last 2 parts of tf, ie "scratchdir/tf.tgz"
                tf = '/'.join(tf.split('/')[-2:])
                runner.run('rm -rf %s' % targetdir)
                self._target_extract(runner, tf, parent_dir)

        finally:
            if not error_detected:
                # kill SimpleHTTPServer
                connection.sendcontrol('c')
                self._wait_for_prompt(connection,
                                      prompt_pattern,
                                      timeout=30)
            if mounted:
                runner.run('umount /mnt')
Exemplo n.º 29
0
 def file_system(self, partition, directory):
     root = '/var/lib/lxc/%s/rootfs' % self.name
     logging.debug("Accessing the file system at %s", root)
     dest = root + directory
     ensure_directory(dest)
     yield dest