def _result_as_dir(self, test_result):
     scratch_dir = self.testdef_obj.context.client.target_device.scratch_dir
     rdir = tempfile.mkdtemp(dir=scratch_dir)
     try:
         tcid = test_result['test_case_id']
         _result_to_dir(test_result, rdir)
         yield rdir
         test_result.clear()
         test_result.update(_result_from_dir(rdir, tcid))
     finally:
         rmtree(rdir)
Ejemplo n.º 2
0
 def _result_as_dir(self, test_result):
     scratch_dir = self.testdef_obj.context.client.target_device.scratch_dir
     rdir = tempfile.mkdtemp(dir=scratch_dir)
     try:
         tcid = test_result['test_case_id']
         _result_to_dir(test_result, rdir)
         yield rdir
         test_result.clear()
         test_result.update(_result_from_dir(rdir, tcid))
     finally:
         rmtree(rdir)
Ejemplo n.º 3
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')
Ejemplo n.º 4
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')
    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')
Ejemplo n.º 6
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')