Example #1
0
 def testGetWithDir(self):
     tmpdir = utils.get_tmp_dir()
     origpath = os.path.join(tmpdir, 'testGetWithDir')
     os.mkdir(origpath)
     dstpath = utils.get(origpath)
     self.assertTrue(dstpath.endswith('/'))
     self.assertTrue(os.path.isdir(dstpath))
Example #2
0
    def _prepare_test_assets(self):
        """Create a local test bundle and send it to the client.

        @raise ValueError if the HTTP server does not start.
        """
        # Create a directory to unpack archives.
        temp_bundle_dir = utils.get_tmp_dir()

        for static_content in self.STATIC_CONTENT:
            archive_path = os.path.join(self.bindir, 'files', static_content)

            with tarfile.open(archive_path, 'r') as tar:
                tar.extractall(temp_bundle_dir)

        # Send bundle to client. The extra slash is to send directory contents.
        self._host.run('mkdir -p {}'.format(self.CLIENT_TEST_ROOT))
        self._host.send_file(temp_bundle_dir + '/',
                             self.CLIENT_TEST_ROOT,
                             delete_dest=True)

        # Start the HTTP server
        res = self._browser_facade.set_http_server_directories(
            self.CLIENT_TEST_ROOT)
        if not res:
            raise ValueError('HTTP server failed to start.')
Example #3
0
 def testGetWithDir(self):
     tmpdir = utils.get_tmp_dir()
     origpath = os.path.join(tmpdir, 'testGetWithDir')
     os.mkdir(origpath)
     dstpath = utils.get(origpath)
     self.assertTrue(dstpath.endswith('/'))
     self.assertTrue(os.path.isdir(dstpath))
Example #4
0
    def testInstallFromDir(self):
        class MockInstallHost:
            def __init__(self):
                self.commands = []
                self.hostname = 'autotest-client.foo.com'

            def run(self, command, ignore_status=False):
                self.commands.append(command)

            def send_file(self, src, dst, delete_dest=False):
                self.commands.append("send_file: %s %s" % (src, dst))

            def wait_up(self, timeout):
                pass

            def get_autodir(self):
                pass

            def set_autodir(self, autodir):
                pass

            def setup(self):
                pass

        host = MockInstallHost()
        tmpdir = utils.get_tmp_dir()
        self.autotest.get(tmpdir)
        self.autotest.install(host)
        self.assertEqual(host.commands[0],
                         'test -x %s/bin/autotest' % _TOP_PATH)
        self.assertEqual(host.commands[1], 'test -w %s' % _TOP_PATH)
        self.assertEqual(host.commands[2], 'mkdir -p %s' % _TOP_PATH)
        self.assertTrue(host.commands[4].startswith('send_file: []'))
        self.assertTrue(host.commands[4].endswith(_TOP_PATH))
Example #5
0
    def testInstallFromDir(self):
        class MockInstallHost:
            def __init__(self):
                self.commands = []

            def run(self, command):
                if command == "grep autodir= /etc/autotest.conf":
                    result= hosts.CmdResult()
                    result.stdout = "autodir=/usr/local/autotest\n"
                    return result
                else:
                    self.commands.append(command)

            def send_file(self, src, dst):
                self.commands.append("send_file: %s %s" % (src,
                                                           dst))

        host = MockInstallHost()
        tmpdir = utils.get_tmp_dir()
        self.autotest.get(tmpdir)
        self.autotest.install(host)
        self.assertEqual(host.commands[0],
                         'mkdir -p /usr/local/autotest')
        self.assertTrue(host.commands[1].startswith('send_file: /tmp/'))
        self.assertTrue(host.commands[1].endswith(
                '/ /usr/local/autotest'))
Example #6
0
    def testInstallFromDir(self):
        class MockInstallHost:
            def __init__(self):
                self.commands = []

            def run(self, command):
                if command == "grep autodir= /etc/autotest.conf":
                    result= hosts.CmdResult()
                    result.stdout = "autodir=%s\n" % _TOP_PATH
                    return result
                else:
                    self.commands.append(command)

            def send_file(self, src, dst):
                self.commands.append("send_file: %s %s" % (src,
                                                           dst))

        host = MockInstallHost()
        tmpdir = utils.get_tmp_dir()
        self.autotest.get(tmpdir)
        self.autotest.install(host)
        self.assertEqual(host.commands[0], 'mkdir -p %s' % _TOP_PATH)
        self.assertTrue(host.commands[1].startswith('send_file: /tmp/'))
        self.assertTrue(host.commands[1].endswith(
        '/ %s' % _GLOBAL_CONFIG.get_config_value('COMMON', 'autotest_top_path')))
Example #7
0
 def testGetWithOpenFile(self):
     tmpdir = utils.get_tmp_dir()
     tmppath = os.path.join(tmpdir, 'testfile')
     tmpfile = file(tmppath, 'w')
     print >> tmpfile, 'Test string'
     tmpfile.close()
     tmpfile = file(tmppath)
     newtmppath = utils.get(tmpfile)
     self.assertEqual(file(newtmppath).read(), 'Test string\n')
Example #8
0
 def testGetWithOpenFile(self):
     tmpdir = utils.get_tmp_dir()
     tmppath = os.path.join(tmpdir, 'testfile')
     tmpfile = file(tmppath, 'w')
     print >> tmpfile, 'Test string'
     tmpfile.close()
     tmpfile = file(tmppath)
     newtmppath = utils.get(tmpfile)
     self.assertEqual(file(newtmppath).read(), 'Test string\n')
Example #9
0
    def testInstallFromDir(self):
        class MockInstallHost:
            def __init__(self):
                self.commands = []

            def run(self, command):
                if command == "grep autodir= /etc/autotest.conf":
                    result = hosts.CmdResult()
                    result.stdout = "autodir=/usr/local/autotest\n"
                    return result
                else:
                    self.commands.append(command)

            def send_file(self, src, dst):
                self.commands.append("send_file: %s %s" % (src, dst))

        host = MockInstallHost()
        tmpdir = utils.get_tmp_dir()
        self.autotest.get(tmpdir)
        self.autotest.install(host)
        self.assertEqual(host.commands[0], 'mkdir -p /usr/local/autotest')
        self.assertTrue(host.commands[1].startswith('send_file: /tmp/'))
        self.assertTrue(host.commands[1].endswith('/ /usr/local/autotest'))