コード例 #1
0
def _extract_partition(image, partno, tarfile):
    """Mount a partition and produce a tarball of it

    :param image: The image to mount
    :param partno: The index of the partition in the image
    :param tarfile: path and filename of the tgz to output
    """
    with image_partition_mounted(image, partno) as mntdir:
        mk_targz(tarfile, mntdir, asroot=True)
コード例 #2
0
    def retrieve_results(self, result_disk):
        self.target_device.power_off(self.proc)

        td = self.target_device
        tar = os.path.join(td.scratch_dir, 'lava_results.tgz')
        result_dir = self.context.config.lava_result_dir
        with td.file_system(td.config.root_part, result_dir) as mnt:
            mk_targz(tar, mnt)
        return tar
コード例 #3
0
def _extract_partition(image, partno, tarfile):
    """Mount a partition and produce a tarball of it

    :param image: The image to mount
    :param partno: The index of the partition in the image
    :param tarfile: path and filename of the tgz to output
    """
    with image_partition_mounted(image, partno) as mntdir:
        mk_targz(tarfile, mntdir, asroot=True)
コード例 #4
0
    def retrieve_results(self, result_disk):
        self.target_device.power_off(self.proc)

        td = self.target_device
        tar = os.path.join(td.scratch_dir, 'lava_results.tgz')
        result_dir = self.context.config.lava_result_dir
        with td.file_system(td.config.root_part, result_dir) as mnt:
            mk_targz(tar, mnt)
        return tar
コード例 #5
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')
コード例 #6
0
ファイル: target.py プロジェクト: dl9pf/lava-dispatcher
    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')
コード例 #7
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')
コード例 #8
0
ファイル: target.py プロジェクト: dl9pf/lava-dispatcher
    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')