Example #1
0
 def test_loadable(self):
     basedir = "test_client.Run.test_loadable"
     os.mkdir(basedir)
     dummy = "pb://[email protected]:58889/bogus"
     fileutil.write(os.path.join(basedir, "tahoe.cfg"), BASECONFIG_I % dummy)
     fileutil.write(os.path.join(basedir, client.Client.EXIT_TRIGGER_FILE), "")
     client.Client(basedir)
Example #2
0
    def test_reloadable(self):
        basedir = "test_client.Run.test_reloadable"
        os.mkdir(basedir)
        dummy = "pb://[email protected]:58889/bogus"
        fileutil.write(os.path.join(basedir, "tahoe.cfg"), BASECONFIG_I % dummy)
        c1 = client.Client(basedir)
        c1.setServiceParent(self.sparent)

        # delay to let the service start up completely. I'm not entirely sure
        # this is necessary.
        d = self.stall(delay=2.0)
        d.addCallback(lambda res: c1.disownServiceParent())
        # the cygwin buildslave seems to need more time to let the old
        # service completely shut down. When delay=0.1, I saw this test fail,
        # probably due to the logport trying to reclaim the old socket
        # number. This suggests that either we're dropping a Deferred
        # somewhere in the shutdown sequence, or that cygwin is just cranky.
        d.addCallback(self.stall, delay=2.0)
        def _restart(res):
            # TODO: pause for slightly over one second, to let
            # Client._check_exit_trigger poll the file once. That will exercise
            # another few lines. Then add another test in which we don't
            # update the file at all, and watch to see the node shutdown.
            # (To do this, use a modified node which overrides Node.shutdown(),
            # also change _check_exit_trigger to use it instead of a raw
            # reactor.stop, also instrument the shutdown event in an
            # attribute that we can check.)
            c2 = client.Client(basedir)
            c2.setServiceParent(self.sparent)
            return c2.disownServiceParent()
        d.addCallback(_restart)
        return d
Example #3
0
        def _cb3(res):
            out, err, rc_or_sig = res

            fileutil.write(exit_trigger_file, "")
            errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
            self.failUnlessEqual(rc_or_sig, 0, errstr)
            self.failUnlessEqual(out, "", errstr)
    def test_furl(self):
        basedir = "introducer.IntroducerNode.test_furl"
        os.mkdir(basedir)
        public_fn = os.path.join(basedir, "introducer.furl")
        private_fn = os.path.join(basedir, "private", "introducer.furl")

        q1 = IntroducerNode(basedir)
        del q1
        # new nodes create unguessable furls in private/introducer.furl
        ifurl = fileutil.read(private_fn)
        self.failUnless(ifurl)
        ifurl = ifurl.strip()
        self.failIf(ifurl.endswith("/introducer"), ifurl)

        # old nodes created guessable furls in BASEDIR/introducer.furl
        guessable = ifurl[:ifurl.rfind("/")] + "/introducer"
        fileutil.write(public_fn, guessable+"\n", mode="w") # text

        # if we see both files, throw an error
        self.failUnlessRaises(FurlFileConflictError,
                              IntroducerNode, basedir)

        # when we see only the public one, move it to private/ and use
        # the existing furl instead of creating a new one
        os.unlink(private_fn)

        q2 = IntroducerNode(basedir)
        del q2
        self.failIf(os.path.exists(public_fn))
        ifurl2 = fileutil.read(private_fn)
        self.failUnless(ifurl2)
        self.failUnlessEqual(ifurl2.strip(), guessable)
Example #5
0
 def _check(config, expected_furl):
     fileutil.write(os.path.join(basedir, "tahoe.cfg"),
                    BASECONFIG + config)
     c = client.Client(basedir)
     uploader = c.getServiceNamed("uploader")
     furl, connected = uploader.get_helper_info()
     self.failUnlessEqual(furl, expected_furl)
Example #6
0
    def test_immutable_from_file_unicode(self):
        # tahoe put "\u00E0 trier.txt" "\u00E0 trier.txt"

        try:
            a_trier_arg = u"\u00E0 trier.txt".encode(get_io_encoding())
        except UnicodeEncodeError:
            raise unittest.SkipTest("A non-ASCII command argument could not be encoded on this platform.")

        skip_if_cannot_represent_filename(u"\u00E0 trier.txt")

        self.basedir = "cli/Put/immutable_from_file_unicode"
        self.set_up_grid(oneshare=True)

        rel_fn = os.path.join(unicode(self.basedir), u"\u00E0 trier.txt")
        # we make the file small enough to fit in a LIT file, for speed
        DATA = "short file"
        fileutil.write(rel_fn, DATA)

        d = self.do_cli("create-alias", "tahoe")

        d.addCallback(lambda res:
                      self.do_cli("put", rel_fn.encode(get_io_encoding()), a_trier_arg))
        def _uploaded((rc, out, err)):
            readcap = out.strip()
            self.failUnless(readcap.startswith("URI:LIT:"), readcap)
            self.failUnlessIn("201 Created", err)
            self.readcap = readcap
        d.addCallback(_uploaded)

        d.addCallback(lambda res:
                      self.do_cli("get", "tahoe:" + a_trier_arg))
        d.addCallback(lambda (rc, out, err):
                      self.failUnlessReallyEqual(out, DATA))

        return d
Example #7
0
        def _cb3(res):
            out, err, rc_or_sig = res

            fileutil.write(HOTLINE_FILE, "")
            errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
            self.failUnlessEqual(rc_or_sig, 0, errstr)
            self.failUnlessEqual(out, "", errstr)
Example #8
0
    def test_error_on_old_config_files(self, mock_log_msg):
        basedir = "test_client.Basic.test_error_on_old_config_files"
        os.mkdir(basedir)
        fileutil.write(os.path.join(basedir, "tahoe.cfg"),
                       BASECONFIG +
                       "[storage]\n" +
                       "enabled = false\n" +
                       "reserved_space = bogus\n")
        fileutil.write(os.path.join(basedir, "introducer.furl"), "")
        fileutil.write(os.path.join(basedir, "no_storage"), "")
        fileutil.write(os.path.join(basedir, "readonly_storage"), "")
        fileutil.write(os.path.join(basedir, "debug_discard_storage"), "")

        e = self.failUnlessRaises(OldConfigError, client.Client, basedir)
        self.failUnlessIn(os.path.abspath(os.path.join(basedir, "introducer.furl")), e.args[0])
        self.failUnlessIn(os.path.abspath(os.path.join(basedir, "no_storage")), e.args[0])
        self.failUnlessIn(os.path.abspath(os.path.join(basedir, "readonly_storage")), e.args[0])
        self.failUnlessIn(os.path.abspath(os.path.join(basedir, "debug_discard_storage")), e.args[0])

        for oldfile in ['introducer.furl', 'no_storage', 'readonly_storage',
                        'debug_discard_storage']:
            logged = [ m for m in mock_log_msg.call_args_list if
                       ("Found pre-Tahoe-LAFS-v1.3 configuration file" in str(m[0][0]) and oldfile in str(m[0][0])) ]
            self.failUnless(logged, (oldfile, mock_log_msg.call_args_list))

        for oldfile in [
            'nickname', 'webport', 'keepalive_timeout', 'log_gatherer.furl',
            'disconnect_timeout', 'advertised_ip_addresses', 'helper.furl',
            'key_generator.furl', 'stats_gatherer.furl', 'sizelimit',
            'run_helper']:
            logged = [ m for m in mock_log_msg.call_args_list if
                       ("Found pre-Tahoe-LAFS-v1.3 configuration file" in str(m[0][0]) and oldfile in str(m[0][0])) ]
            self.failIf(logged, oldfile)
Example #9
0
 def _stop(res):
     fileutil.write(HOTLINE_FILE, "")
     self.failUnless(
         os.path.exists(TWISTD_PID_FILE),
         (TWISTD_PID_FILE, os.listdir(
             os.path.dirname(TWISTD_PID_FILE))))
     return self.run_bintahoe(["--quiet", "stop", c1])
    def test_cp_verbose(self):
        self.basedir = "cli/Cp/cp_verbose"
        self.set_up_grid()

        # Write two test files, which we'll copy to the grid.
        test1_path = os.path.join(self.basedir, "test1")
        test2_path = os.path.join(self.basedir, "test2")
        fileutil.write(test1_path, "test1")
        fileutil.write(test2_path, "test2")

        d = self.do_cli("create-alias", "tahoe")
        d.addCallback(lambda ign:
            self.do_cli("cp", "--verbose", test1_path, test2_path, "tahoe:"))
        def _check(res):
            (rc, out, err) = res
            self.failUnlessEqual(rc, 0, str(res))
            self.failUnlessIn("Success: files copied", out, str(res))
            self.failUnlessEqual(err, """\
attaching sources to targets, 2 files / 0 dirs in root
targets assigned, 1 dirs, 2 files
starting copy, 2 files, 1 directories
1/2 files, 0/1 directories
2/2 files, 0/1 directories
1/1 directories
""", str(res))
        d.addCallback(_check)
        return d
 def _remove_trailing_newline_and_create_alias(ign):
     # ticket #741 is about a manually-edited alias file (which
     # doesn't end in a newline) being corrupted by a subsequent
     # "tahoe create-alias"
     old = fileutil.read(aliasfile)
     fileutil.write(aliasfile, old.rstrip())
     return self.do_cli("create-alias", "un-corrupted1")
Example #12
0
def create_stats_gatherer(config):
    err = config.stderr
    basedir = config['basedir']
    # This should always be called with an absolute Unicode basedir.
    precondition(isinstance(basedir, unicode), basedir)

    if os.path.exists(basedir):
        if listdir_unicode(basedir):
            print("The base directory %s is not empty." % quote_output(basedir), file=err)
            print("To avoid clobbering anything, I am going to quit now.", file=err)
            print("Please use a different directory, or empty this one.", file=err)
            return -1
        # we're willing to use an empty directory
    else:
        os.mkdir(basedir)
    write_tac(basedir, "stats-gatherer")
    if config["hostname"]:
        portnum = iputil.allocate_tcp_port()
        location = "tcp:%s:%d" % (config["hostname"], portnum)
        port = "tcp:%d" % portnum
    else:
        location = config["location"]
        port = config["port"]
    fileutil.write(os.path.join(basedir, "location"), location+"\n")
    fileutil.write(os.path.join(basedir, "port"), port+"\n")
    return 0
    def test_cp_copies_dir(self):
        # This test ensures that a directory is copied using
        # tahoe cp -r. Refer to ticket #712:
        # https://tahoe-lafs.org/trac/tahoe-lafs/ticket/712

        self.basedir = "cli/Cp/cp_copies_dir"
        self.set_up_grid()
        subdir = os.path.join(self.basedir, "foo")
        os.mkdir(subdir)
        test1_path = os.path.join(subdir, "test1")
        fileutil.write(test1_path, "test1")

        d = self.do_cli("create-alias", "tahoe")
        d.addCallback(lambda ign:
            self.do_cli("cp", "-r", subdir, "tahoe:"))
        d.addCallback(lambda ign:
            self.do_cli("ls", "tahoe:"))
        def _check(res, item):
            (rc, out, err) = res
            self.failUnlessEqual(rc, 0)
            self.failUnlessEqual(err, "")
            self.failUnlessIn(item, out, str(res))
        d.addCallback(_check, "foo")
        d.addCallback(lambda ign:
            self.do_cli("ls", "tahoe:foo/"))
        d.addCallback(_check, "test1")

        d.addCallback(lambda ign: fileutil.rm_dir(subdir))
        d.addCallback(lambda ign: self.do_cli("cp", "-r", "tahoe:foo", self.basedir))
        def _check_local_fs(ign):
            self.failUnless(os.path.isdir(self.basedir))
            self.failUnless(os.path.isfile(test1_path))
        d.addCallback(_check_local_fs)
        return d
Example #14
0
 def test_nodekey_yes_storage(self):
     basedir = "test_client.Basic.test_nodekey_yes_storage"
     os.mkdir(basedir)
     fileutil.write(os.path.join(basedir, "tahoe.cfg"),
                    BASECONFIG)
     c = client.create_client(basedir)
     self.failUnless(c.get_long_nodeid().startswith("v0-"))
Example #15
0
    def get_or_create_private_config(self, name, default=_None):
        """Try to get the (string) contents of a private config file (which
        is a config file that resides within the subdirectory named
        'private'), and return it. Any leading or trailing whitespace will be
        stripped from the data.

        If the file does not exist, and default is not given, report an error.
        If the file does not exist and a default is specified, try to create
        it using that default, and then return the value that was written.
        If 'default' is a string, use it as a default value. If not, treat it
        as a zero-argument callable that is expected to return a string.
        """
        privname = os.path.join(self.basedir, "private", name)
        try:
            value = fileutil.read(privname)
        except EnvironmentError:
            if os.path.exists(privname):
                raise
            if default is _None:
                raise MissingConfigEntry("The required configuration file %s is missing."
                                         % (quote_output(privname),))
            if isinstance(default, basestring):
                value = default
            else:
                value = default()
            fileutil.write(privname, value)
        return value.strip()
Example #16
0
    def test_unlinked_immutable_from_file(self):
        # tahoe put file.txt
        # tahoe put ./file.txt
        # tahoe put /tmp/file.txt
        # tahoe put ~/file.txt
        self.basedir = "cli/Put/unlinked_immutable_from_file"
        self.set_up_grid(oneshare=True)

        rel_fn = os.path.join(self.basedir, "DATAFILE")
        abs_fn = unicode_to_argv(abspath_expanduser_unicode(unicode(rel_fn)))
        # we make the file small enough to fit in a LIT file, for speed
        fileutil.write(rel_fn, "short file")
        d = self.do_cli("put", rel_fn)
        def _uploaded((rc, out, err)):
            readcap = out
            self.failUnless(readcap.startswith("URI:LIT:"), readcap)
            self.readcap = readcap
        d.addCallback(_uploaded)
        d.addCallback(lambda res: self.do_cli("put", "./" + rel_fn))
        d.addCallback(lambda (rc,stdout,stderr):
                      self.failUnlessReallyEqual(stdout, self.readcap))
        d.addCallback(lambda res: self.do_cli("put", abs_fn))
        d.addCallback(lambda (rc,stdout,stderr):
                      self.failUnlessReallyEqual(stdout, self.readcap))
        # we just have to assume that ~ is handled properly
        return d
Example #17
0
 def test_put_to_sdmf_cap(self):
     self.basedir = "cli/Put/put_to_sdmf_cap"
     self.set_up_grid(oneshare=True)
     data = "data" * 100000
     fn1 = os.path.join(self.basedir, "data")
     fileutil.write(fn1, data)
     d = self.do_cli("put", "--format=SDMF", fn1)
     def _got_cap((rc, out, err)):
         self.failUnlessEqual(rc, 0)
         self.cap = out.strip()
     d.addCallback(_got_cap)
     # Now try to write something to the cap using put.
     data2 = "data2" * 100000
     fn2 = os.path.join(self.basedir, "data2")
     fileutil.write(fn2, data2)
     d.addCallback(lambda ignored:
         self.do_cli("put", fn2, self.cap))
     def _got_put((rc, out, err)):
         self.failUnlessEqual(rc, 0)
         self.failUnlessIn(self.cap, out)
     d.addCallback(_got_put)
     # Now get the cap. We should see the data we just put there.
     d.addCallback(lambda ignored:
         self.do_cli("get", self.cap))
     def _got_data((rc, out, err)):
         self.failUnlessEqual(rc, 0)
         self.failUnlessEqual(out, data2)
     d.addCallback(_got_data)
     return d
Example #18
0
 def test_nodekey_no_storage(self):
     basedir = "test_client.Basic.test_nodekey_no_storage"
     os.mkdir(basedir)
     fileutil.write(os.path.join(basedir, "tahoe.cfg"),
                    BASECONFIG + "[storage]\n" + "enabled = false\n")
     c = client.Client(basedir)
     self.failUnless(c.get_long_nodeid().startswith("v0-"))
Example #19
0
 def test_reserved_bad(self):
     basedir = "client.Basic.test_reserved_bad"
     os.mkdir(basedir)
     fileutil.write(
         os.path.join(basedir, "tahoe.cfg"),
         BASECONFIG + "[storage]\n" + "enabled = true\n" + "reserved_space = bogus\n",
     )
     self.failUnlessRaises(ValueError, client.Client, basedir)
Example #20
0
 def write_config(self, name, value, mode="w"):
     """Write a string to a config file."""
     fn = os.path.join(self.basedir, name)
     try:
         fileutil.write(fn, value, mode)
     except EnvironmentError, e:
         self.log("Unable to write config file '%s'" % fn)
         self.log(e)
Example #21
0
 def test_reserved_4(self):
     basedir = "client.Basic.test_reserved_4"
     os.mkdir(basedir)
     fileutil.write(
         os.path.join(basedir, "tahoe.cfg"),
         BASECONFIG + "[storage]\n" + "enabled = true\n" + "reserved_space = 78Gb\n",
     )
     c = client.Client(basedir)
     self.failUnlessEqual(c.getServiceNamed("storage").reserved_space, 78 * 1000 * 1000 * 1000)
Example #22
0
 def test_ftp_auth_no_accountfile_or_url(self):
     basedir = u"client.Basic.test_ftp_auth_no_accountfile_or_url"
     os.mkdir(basedir)
     fileutil.write(os.path.join(basedir, "tahoe.cfg"),
                    (BASECONFIG +
                     "[ftpd]\n"
                     "enabled = true\n"
                     "port = tcp:0:interface=127.0.0.1\n"))
     self.failUnlessRaises(NeedRootcapLookupScheme, client.Client, basedir)
Example #23
0
 def test_nodekey_no_storage(self):
     """
     We have a nodeid if we're not providing storage
     """
     basedir = "test_client.Basic.test_nodekey_no_storage"
     os.mkdir(basedir)
     fileutil.write(os.path.join(basedir, "tahoe.cfg"),
                    BASECONFIG + "[storage]\n" + "enabled = false\n")
     c = yield client.create_client(basedir)
     self.failUnless(c.get_long_nodeid().startswith("v0-"))
Example #24
0
        def _cb(res):
            out, err, rc_or_sig = res
            errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
            assert rc_or_sig == 0, errstr
            self.failUnlessEqual(rc_or_sig, 0)

            # By writing this file, we get two minutes before the client will exit. This ensures
            # that even if the 'stop' command doesn't work (and the test fails), the client should
            # still terminate.
            fileutil.write(exit_trigger_file, "")
Example #25
0
 def test_reserved_2(self):
     basedir = "client.Basic.test_reserved_2"
     os.mkdir(basedir)
     fileutil.write(os.path.join(basedir, "tahoe.cfg"),  \
                        BASECONFIG + \
                        "[storage]\n" + \
                        "enabled = true\n" + \
                        "reserved_space = 10K\n")
     c = client.Client(basedir)
     self.failUnlessEqual(c.getServiceNamed("storage").reserved_space, 10*1000)
Example #26
0
 def _cb2(res):
     out, err, rc_or_sig = res
     errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
     fileutil.write(exit_trigger_file, "")
     self.failUnlessEqual(rc_or_sig, 0, errstr)
     self.failUnlessEqual(out, "", errstr) # If you emit noise, you fail this test.
     errlines = err.split("\n")
     self.failIf([True for line in errlines if (line != "" and "UserWarning: Unbuilt egg for setuptools" not in line
                                                           and "from pkg_resources import load_entry_point" not in line)], errstr)
     if err != "":
         raise unittest.SkipTest("This test is known not to pass on Ubuntu Lucid; see #1235.")
Example #27
0
    def test_error_on_old_config_files(self):
        basedir = "test_client.Basic.test_error_on_old_config_files"
        os.mkdir(basedir)
        fileutil.write(
            os.path.join(basedir, "tahoe.cfg"), BASECONFIG + "[storage]\n" +
            "enabled = false\n" + "reserved_space = bogus\n")
        fileutil.write(os.path.join(basedir, "introducer.furl"), "")
        fileutil.write(os.path.join(basedir, "no_storage"), "")
        fileutil.write(os.path.join(basedir, "readonly_storage"), "")
        fileutil.write(os.path.join(basedir, "debug_discard_storage"), "")

        logged_messages = []
        self.patch(twisted.python.log, 'msg', logged_messages.append)

        e = self.failUnlessRaises(
            OldConfigError,
            read_config,
            basedir,
            "client.port",
            _valid_config_sections=client._valid_config_sections,
        )
        abs_basedir = fileutil.abspath_expanduser_unicode(
            unicode(basedir)).encode(sys.getfilesystemencoding())
        self.failUnlessIn(os.path.join(abs_basedir, "introducer.furl"),
                          e.args[0])
        self.failUnlessIn(os.path.join(abs_basedir, "no_storage"), e.args[0])
        self.failUnlessIn(os.path.join(abs_basedir, "readonly_storage"),
                          e.args[0])
        self.failUnlessIn(os.path.join(abs_basedir, "debug_discard_storage"),
                          e.args[0])

        for oldfile in [
                'introducer.furl', 'no_storage', 'readonly_storage',
                'debug_discard_storage'
        ]:
            logged = [
                m for m in logged_messages
                if ("Found pre-Tahoe-LAFS-v1.3 configuration file" in str(m)
                    and oldfile in str(m))
            ]
            self.failUnless(logged, (oldfile, logged_messages))

        for oldfile in [
                'nickname', 'webport', 'keepalive_timeout',
                'log_gatherer.furl', 'disconnect_timeout',
                'advertised_ip_addresses', 'helper.furl', 'key_generator.furl',
                'stats_gatherer.furl', 'sizelimit', 'run_helper'
        ]:
            logged = [
                m for m in logged_messages
                if ("Found pre-Tahoe-LAFS-v1.3 configuration file" in str(m)
                    and oldfile in str(m))
            ]
            self.failIf(logged, (oldfile, logged_messages))
Example #28
0
        def _started(res):
            # read the client.port file so we can check that its contents
            # don't change on restart
            self.portnum = fileutil.read(portnum_file)

            fileutil.write(exit_trigger_file, "")
            self.failUnless(os.path.exists(twistd_pid_file))

            # rm this so we can detect when the second incarnation is ready
            os.unlink(node_url_file)
            return self.run_bintahoe(["--quiet", "restart", c1])
Example #29
0
        def _started(res):
            # read the client.port file so we can check that its contents
            # don't change on restart
            self.portnum = fileutil.read(portnum_file)

            fileutil.write(exit_trigger_file, "")
            self.failUnless(os.path.exists(twistd_pid_file))

            # rm this so we can detect when the second incarnation is ready
            os.unlink(node_url_file)
            return self.run_bintahoe(["--quiet", "restart", c1])
Example #30
0
 def test_ftp_auth_url(self):
     basedir = u"client.Basic.test_ftp_auth_url"
     os.mkdir(basedir)
     fileutil.write(os.path.join(basedir, "tahoe.cfg"),
                    (BASECONFIG +
                     "[ftpd]\n"
                     "enabled = true\n"
                     "port = tcp:0:interface=127.0.0.1\n"
                     "accounts.url = http://0.0.0.0/\n"))
     c = client.Client(basedir) # just make sure it can be instantiated
     del c
Example #31
0
 def _cb2(res):
     out, err, rc_or_sig = res
     errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
     fileutil.write(exit_trigger_file, "")
     self.failUnlessEqual(rc_or_sig, 0, errstr)
     self.failUnlessEqual(out, "", errstr) # If you emit noise, you fail this test.
     errlines = err.split("\n")
     self.failIf([True for line in errlines if (line != "" and "UserWarning: Unbuilt egg for setuptools" not in line
                                                           and "from pkg_resources import load_entry_point" not in line)], errstr)
     if err != "":
         raise unittest.SkipTest("This test is known not to pass on Ubuntu Lucid; see #1235.")
Example #32
0
 def test_reserved_4(self):
     basedir = "client.Basic.test_reserved_4"
     os.mkdir(basedir)
     fileutil.write(os.path.join(basedir, "tahoe.cfg"), \
                        BASECONFIG + \
                        "[storage]\n" + \
                        "enabled = true\n" + \
                        "reserved_space = 78Gb\n")
     c = client.Client(basedir)
     self.failUnlessEqual(c.getServiceNamed("storage").reserved_space,
                          78*1000*1000*1000)
Example #33
0
 def test_secrets(self):
     basedir = "test_client.Basic.test_secrets"
     os.mkdir(basedir)
     fileutil.write(os.path.join(basedir, "tahoe.cfg"), BASECONFIG)
     c = client.Client(basedir)
     secret_fname = os.path.join(basedir, "private", "secret")
     self.failUnless(os.path.exists(secret_fname), secret_fname)
     renew_secret = c.get_renewal_secret()
     self.failUnless(base32.b2a(renew_secret))
     cancel_secret = c.get_cancel_secret()
     self.failUnless(base32.b2a(cancel_secret))
Example #34
0
 def test_ftp_auth_url(self):
     basedir = u"client.Basic.test_ftp_auth_url"
     os.mkdir(basedir)
     fileutil.write(os.path.join(basedir, "tahoe.cfg"),
                    (BASECONFIG +
                     "[ftpd]\n"
                     "enabled = true\n"
                     "port = tcp:0:interface=127.0.0.1\n"
                     "accounts.url = http://0.0.0.0/\n"))
     c = client.Client(basedir) # just make sure it can be instantiated
     del c
Example #35
0
        def _started(res):
            # read the client.port file so we can check that its contents
            # don't change on restart
            self.portnum = fileutil.read(PORTNUM_FILE)

            fileutil.write(HOTLINE_FILE, "")
            self.failUnless(os.path.exists(TWISTD_PID_FILE))

            # rm this so we can detect when the second incarnation is ready
            os.unlink(NODE_URL_FILE)
            return self.run_bintahoe(["--quiet", "restart", c1])
Example #36
0
 def test_ftp_auth_no_accountfile_or_url(self):
     """
     ftpd requires some way to look up accounts
     """
     basedir = u"client.Basic.test_ftp_auth_no_accountfile_or_url"
     os.mkdir(basedir)
     fileutil.write(os.path.join(basedir, "tahoe.cfg"),
                    (BASECONFIG + "[ftpd]\n"
                     "enabled = true\n"
                     "port = tcp:0:interface=127.0.0.1\n"))
     with self.assertRaises(NeedRootcapLookupScheme):
         yield client.create_client(basedir)
Example #37
0
        def _cb(res):
            out, err, rc_or_sig = res
            self.failUnlessEqual(rc_or_sig, 0)

            # Check that the --webport option worked.
            config = fileutil.read(config_file)
            self.failUnlessIn('\nweb.port = 0\n', config)

            # By writing this file, we get two minutes before the client will exit. This ensures
            # that even if the 'stop' command doesn't work (and the test fails), the client should
            # still terminate.
            fileutil.write(exit_trigger_file, "")
Example #38
0
 def _after_stopping(res):
     out, err, rc_or_sig = res
     fileutil.write(exit_trigger_file, "")
     # the parent has exited by now
     errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
     self.failUnlessEqual(rc_or_sig, 0, errstr)
     self.failUnlessEqual(out, "", errstr)
     # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
     # the parent was supposed to poll and wait until it sees
     # twistd.pid go away before it exits, so twistd.pid should be
     # gone by now.
     self.failIf(os.path.exists(twistd_pid_file))
Example #39
0
 def test_ftp_auth_keyfile(self):
     basedir = u"client.Basic.test_ftp_auth_keyfile"
     os.mkdir(basedir)
     fileutil.write(os.path.join(basedir, "tahoe.cfg"),
                    (BASECONFIG + "[ftpd]\n"
                     "enabled = true\n"
                     "port = tcp:0:interface=127.0.0.1\n"
                     "accounts.file = private/accounts\n"))
     os.mkdir(os.path.join(basedir, "private"))
     fileutil.write(os.path.join(basedir, "private", "accounts"), "\n")
     c = client.Client(basedir)  # just make sure it can be instantiated
     del c
Example #40
0
 def test_web_static(self):
     basedir = u"introducer.Node.test_web_static"
     create_node_dir(basedir, "testing")
     fileutil.write(os.path.join(basedir, "tahoe.cfg"),
                    "[node]\n" +
                    "web.port = tcp:0:interface=127.0.0.1\n" +
                    "web.static = relative\n")
     c = yield create_introducer(basedir)
     w = c.getServiceNamed("webish")
     abs_basedir = fileutil.abspath_expanduser_unicode(basedir)
     expected = fileutil.abspath_expanduser_unicode(u"relative", abs_basedir)
     self.failUnlessReallyEqual(w.staticdir, expected)
Example #41
0
 def test_secrets(self):
     basedir = "test_client.Basic.test_secrets"
     os.mkdir(basedir)
     fileutil.write(os.path.join(basedir, "tahoe.cfg"), \
                        BASECONFIG)
     c = client.Client(basedir)
     secret_fname = os.path.join(basedir, "private", "secret")
     self.failUnless(os.path.exists(secret_fname), secret_fname)
     renew_secret = c.get_renewal_secret()
     self.failUnless(base32.b2a(renew_secret))
     cancel_secret = c.get_cancel_secret()
     self.failUnless(base32.b2a(cancel_secret))
Example #42
0
    def run_one_case(self, case):
        cmd = (case.replace("$PARENTCAP", self.PARENTCAP).replace(
            "$DIRCAP5",
            self.DIRCAP5).replace("$DIRCAP6", self.DIRCAP6).replace(
                "$DIRCAP",
                self.DIRCAP).replace("$DIRALIAS",
                                     "ALIAS:").replace("$FILECAP",
                                                       self.FILECAP).split())
        target = cmd[-1]
        _assert(target == "to" or target.startswith("to/"), target)
        cmd[-1] = os.path.abspath(os.path.join(self.basedir, cmd[-1]))

        # reset
        targetdir = os.path.abspath(os.path.join(self.basedir, "to"))
        fileutil.rm_dir(targetdir)
        os.mkdir(targetdir)

        if target.rstrip("/") == "to/existing-file":
            fileutil.write(cmd[-1], "existing file contents\n")

        # The abspath() for cmd[-1] strips a trailing slash, and we want to
        # test what happens when it is present. So put it back.
        if target.endswith("/"):
            cmd[-1] += "/"

        d = self.do_cli(*cmd)

        def _check(res):
            (rc, out, err) = res
            err = err.strip()
            if rc == 0:
                return self.check_output()
            if rc == 1:
                self.failUnlessEqual(out, "", str(res))
                if "when copying into a directory, all source files must have names, but" in err:
                    return set(["E2-DESTNAME"])
                if err == "cannot copy directories without --recursive":
                    return set(["E4-NEED-R"])
                if err == "cannot copy directory into a file":
                    return set(["E5-DIRTOFILE"])
                if err == "copying multiple things requires target be a directory":
                    return set(["E6-MANYONE"])
                if err == "target is not a directory, but ends with a slash":
                    return set(["E7-BADSLASH"])
                if (err.startswith("source ") and
                        "is not a directory, but ends with a slash" in err):
                    return set(["E8-BADSLASH"])
                if err == "cannot copy multiple files with the same name into the same target directory":
                    return set(["E9-COLLIDING-TARGETS"])
            self.fail("unrecognized error ('%s') %s" % (case, res))

        d.addCallback(_check)
        return d
Example #43
0
    def _generate_config(self, which, basedir):
        config = {}

        allclients = set(range(self.numclients))
        except1 = allclients - {1}
        feature_matrix = {
            ("client", "nickname"):
            except1,

            # Auto-assigning addresses is extremely failure prone and not
            # amenable to automated testing in _this_ manner.
            ("node", "tub.port"):
            allclients,
            ("node", "tub.location"):
            allclients,

            # client 0 runs a webserver and a helper
            # client 3 runs a webserver but no helper
            ("node", "web.port"): {0, 3},
            ("node", "timeout.keepalive"): {0},
            ("node", "timeout.disconnect"): {3},
            ("helper", "enabled"): {0},
        }

        def setconf(config, which, section, feature, value):
            if which in feature_matrix.get((section, feature), {which}):
                config.setdefault(section, {})[feature] = value

        setnode = partial(setconf, config, which, "node")
        sethelper = partial(setconf, config, which, "helper")

        setnode("nickname", u"client %d \N{BLACK SMILING FACE}" % (which, ))

        tub_location_hint, tub_port_endpoint = self.port_assigner.assign(
            reactor)
        setnode("tub.port", tub_port_endpoint)
        setnode("tub.location", tub_location_hint)

        _, web_port_endpoint = self.port_assigner.assign(reactor)
        setnode("web.port", web_port_endpoint)
        setnode("timeout.keepalive", "600")
        setnode("timeout.disconnect", "1800")

        sethelper("enabled", "True")

        iyaml = ("introducers:\n"
                 " petname2:\n"
                 "  furl: %s\n") % self.introducer_furl
        iyaml_fn = os.path.join(basedir, "private", "introducers.yaml")
        fileutil.write(iyaml_fn, iyaml)

        return _render_config(config)
Example #44
0
 def write_config_file(self, name, value, mode="w"):
     """
     writes the given 'value' into a file called 'name' in the config
     directory
     """
     fn = os.path.join(self._basedir, name)
     try:
         fileutil.write(fn, value, mode)
     except EnvironmentError:
         log.err(
             Failure(),
             "Unable to write config file '{}'".format(fn),
         )
Example #45
0
 def test_reserved_bad(self):
     """
     reserved_space option produces errors on non-numbers
     """
     basedir = "client.Basic.test_reserved_bad"
     os.mkdir(basedir)
     fileutil.write(os.path.join(basedir, "tahoe.cfg"), \
                        BASECONFIG + \
                        "[storage]\n" + \
                        "enabled = true\n" + \
                        "reserved_space = bogus\n")
     with self.assertRaises(ValueError):
         yield client.create_client(basedir)
Example #46
0
        def _cb4(res):
            out, err, rc_or_sig = res

            fileutil.write(HOTLINE_FILE, "")
            # the parent has exited by now
            errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
            self.failUnlessEqual(rc_or_sig, 0, errstr)
            self.failUnlessEqual(out, "", errstr)
            # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
            # the parent was supposed to poll and wait until it sees
            # twistd.pid go away before it exits, so twistd.pid should be
            # gone by now.
            self.failIf(os.path.exists(TWISTD_PID_FILE))
Example #47
0
 def test_web_staticdir(self):
     basedir = u"client.Basic.test_web_staticdir"
     os.mkdir(basedir)
     fileutil.write(
         os.path.join(basedir, "tahoe.cfg"), BASECONFIG + "[node]\n" +
         "web.port = tcp:0:interface=127.0.0.1\n" +
         "web.static = relative\n")
     c = client.Client(basedir)
     w = c.getServiceNamed("webish")
     abs_basedir = fileutil.abspath_expanduser_unicode(basedir)
     expected = fileutil.abspath_expanduser_unicode(u"relative",
                                                    abs_basedir)
     self.failUnlessReallyEqual(w.staticdir, expected)
Example #48
0
 def test_manhole_keyfile(self):
     basedir = u"client.Basic.test_manhole_keyfile"
     os.mkdir(basedir)
     fileutil.write(
         os.path.join(basedir, "tahoe.cfg"), BASECONFIG + "[node]\n" +
         "ssh.port = tcp:0:interface=127.0.0.1\n" +
         "ssh.authorized_keys_file = relative\n")
     c = client.Client(basedir)
     m = [s for s in c if isinstance(s, AuthorizedKeysManhole)][0]
     abs_basedir = fileutil.abspath_expanduser_unicode(basedir)
     expected = fileutil.abspath_expanduser_unicode(u"relative",
                                                    abs_basedir)
     self.failUnlessReallyEqual(m.keyfile, expected)
Example #49
0
 def test_reserved_2(self):
     """
     reserved_space option understands 'K' to mean kilobytes
     """
     basedir = "client.Basic.test_reserved_2"
     os.mkdir(basedir)
     fileutil.write(os.path.join(basedir, "tahoe.cfg"),  \
                        BASECONFIG + \
                        "[storage]\n" + \
                        "enabled = true\n" + \
                        "reserved_space = 10K\n")
     c = yield client.create_client(basedir)
     self.failUnlessEqual(c.getServiceNamed("storage").reserved_space, 10*1000)
Example #50
0
 def test_reserved_1(self):
     """
     reserved_space option is propagated
     """
     basedir = "client.Basic.test_reserved_1"
     os.mkdir(basedir)
     fileutil.write(os.path.join(basedir, "tahoe.cfg"), \
                        BASECONFIG + \
                        "[storage]\n" + \
                        "enabled = true\n" + \
                        "reserved_space = 1000\n")
     c = yield client.create_client(basedir)
     self.failUnlessEqual(c.getServiceNamed("storage").reserved_space, 1000)
Example #51
0
    def test_exclude_options(self):
        root_listdir = (u'lib.a', u'_darcs', u'subdir', u'nice_doc.lyx')
        subdir_listdir = (u'another_doc.lyx', u'run_snake_run.py', u'CVS',
                          u'.svn', u'_darcs')
        basedir = "cli/Backup/exclude_options"
        fileutil.make_dirs(basedir)
        nodeurl_path = os.path.join(basedir, 'node.url')
        fileutil.write(nodeurl_path, 'http://example.net:2357/')

        def parse(args):
            return parse_options(basedir, "backup", args)

        # test simple exclude
        backup_options = parse(['--exclude', '*lyx', 'from', 'to'])
        filtered = list(backup_options.filter_listdir(root_listdir))
        self._check_filtering(filtered, root_listdir,
                              (u'lib.a', u'_darcs', u'subdir'),
                              (u'nice_doc.lyx', ))
        # multiple exclude
        backup_options = parse(
            ['--exclude', '*lyx', '--exclude', 'lib.?', 'from', 'to'])
        filtered = list(backup_options.filter_listdir(root_listdir))
        self._check_filtering(filtered, root_listdir, (u'_darcs', u'subdir'),
                              (u'nice_doc.lyx', u'lib.a'))
        # vcs metadata exclusion
        backup_options = parse(['--exclude-vcs', 'from', 'to'])
        filtered = list(backup_options.filter_listdir(subdir_listdir))
        self._check_filtering(filtered, subdir_listdir, (
            u'another_doc.lyx',
            u'run_snake_run.py',
        ), (u'CVS', u'.svn', u'_darcs'))
        # read exclude patterns from file
        exclusion_string = "_darcs\n*py\n.svn"
        excl_filepath = os.path.join(basedir, 'exclusion')
        fileutil.write(excl_filepath, exclusion_string)
        backup_options = parse(['--exclude-from', excl_filepath, 'from', 'to'])
        filtered = list(backup_options.filter_listdir(subdir_listdir))
        self._check_filtering(filtered, subdir_listdir,
                              (u'another_doc.lyx', u'CVS'),
                              (u'.svn', u'_darcs', u'run_snake_run.py'))
        # test BackupConfigurationError
        self.failUnlessRaises(
            cli.BackupConfigurationError, parse,
            ['--exclude-from', excl_filepath + '.no', 'from', 'to'])

        # test that an iterator works too
        backup_options = parse(['--exclude', '*lyx', 'from', 'to'])
        filtered = list(backup_options.filter_listdir(iter(root_listdir)))
        self._check_filtering(filtered, root_listdir,
                              (u'lib.a', u'_darcs', u'subdir'),
                              (u'nice_doc.lyx', ))
Example #52
0
        def _started(res):
            # read the introducer.furl and introducer.port files so we can check that their
            # contents don't change on restart
            self.furl = fileutil.read(INTRODUCER_FURL_FILE)
            self.failUnless(os.path.exists(PORTNUM_FILE))
            self.portnum = fileutil.read(PORTNUM_FILE)

            fileutil.write(HOTLINE_FILE, "")
            self.failUnless(os.path.exists(TWISTD_PID_FILE))
            self.failUnless(os.path.exists(NODE_URL_FILE))

            # rm this so we can detect when the second incarnation is ready
            os.unlink(NODE_URL_FILE)
            return self.run_bintahoe(["--quiet", "restart", c1])
Example #53
0
        def _cb(res):
            out, err, rc_or_sig = res
            self.failUnlessEqual(rc_or_sig, 0)

            # This makes sure that node.url is written, which allows us to
            # detect when the introducer restarts in _node_has_restarted below.
            config = fileutil.read(config_file)
            self.failUnlessIn('\nweb.port = \n', config)
            fileutil.write(config_file, config.replace('\nweb.port = \n', '\nweb.port = 0\n'))

            # by writing this file, we get ten seconds before the node will
            # exit. This insures that even if the test fails (and the 'stop'
            # command doesn't work), the client should still terminate.
            fileutil.write(exit_trigger_file, "")
Example #54
0
    def test_unicode_filename(self):
        self.basedir = "cli/Cp/unicode_filename"

        fn1 = os.path.join(unicode(self.basedir), u"\u00C4rtonwall")
        try:
            fn1_arg = fn1.encode(get_io_encoding())
            artonwall_arg = u"\u00C4rtonwall".encode(get_io_encoding())
        except UnicodeEncodeError:
            raise unittest.SkipTest("A non-ASCII command argument could not be encoded on this platform.")

        skip_if_cannot_represent_filename(fn1)

        self.set_up_grid(oneshare=True)

        DATA1 = "unicode file content"
        fileutil.write(fn1, DATA1)

        fn2 = os.path.join(self.basedir, "Metallica")
        DATA2 = "non-unicode file content"
        fileutil.write(fn2, DATA2)

        d = self.do_cli("create-alias", "tahoe")

        d.addCallback(lambda res: self.do_cli("cp", fn1_arg, "tahoe:"))

        d.addCallback(lambda res: self.do_cli("get", "tahoe:" + artonwall_arg))
        d.addCallback(lambda rc_out_err: self.failUnlessReallyEqual(rc_out_err[1], DATA1))

        d.addCallback(lambda res: self.do_cli("cp", fn2, "tahoe:"))

        d.addCallback(lambda res: self.do_cli("get", "tahoe:Metallica"))
        d.addCallback(lambda rc_out_err: self.failUnlessReallyEqual(rc_out_err[1], DATA2))

        d.addCallback(lambda res: self.do_cli("ls", "tahoe:"))
        def _check(args):
            (rc, out, err) = args
            try:
                unicode_to_output(u"\u00C4rtonwall")
            except UnicodeEncodeError:
                self.failUnlessReallyEqual(rc, 1)
                self.failUnlessReallyEqual(out, "Metallica\n")
                self.failUnlessIn(quote_output(u"\u00C4rtonwall"), err)
                self.failUnlessIn("files whose names could not be converted", err)
            else:
                self.failUnlessReallyEqual(rc, 0)
                self.failUnlessReallyEqual(out.decode(get_io_encoding()), u"Metallica\n\u00C4rtonwall\n")
                self.failUnlessReallyEqual(err, "")
        d.addCallback(_check)

        return d
Example #55
0
    def test_exclude_from_tilde_expansion(self, mock):
        basedir = "cli/Backup/exclude_from_tilde_expansion"
        fileutil.make_dirs(basedir)
        nodeurl_path = os.path.join(basedir, 'node.url')
        fileutil.write(nodeurl_path, 'http://example.net:2357/')

        def parse(args):
            return parse_options(basedir, "backup", args)

        # ensure that tilde expansion is performed on exclude-from argument
        exclude_file = u'~/.tahoe/excludes.dummy'

        mock.return_value = StringIO()
        parse(['--exclude-from', unicode_to_argv(exclude_file), 'from', 'to'])
        self.failUnlessIn(((abspath_expanduser_unicode(exclude_file), ), {}),
                          mock.call_args_list)
Example #56
0
    def _write_downloaded_file(self,
                               local_path_u,
                               abspath_u,
                               file_contents,
                               is_conflict=False,
                               now=None):
        self._log(
            "_write_downloaded_file(%r, <%d bytes>, is_conflict=%r, now=%r)" %
            (abspath_u, len(file_contents), is_conflict, now))

        # 1. Write a temporary file, say .foo.tmp.
        # 2. is_conflict determines whether this is an overwrite or a conflict.
        # 3. Set the mtime of the replacement file to be T seconds before the
        #    current local time.
        # 4. Perform a file replacement with backup filename foo.backup,
        #    replaced file foo, and replacement file .foo.tmp. If any step of
        #    this operation fails, reclassify as a conflict and stop.
        #
        # Returns the path of the destination file.

        precondition_abspath(abspath_u)
        replacement_path_u = abspath_u + u".tmp"  # FIXME more unique
        backup_path_u = abspath_u + u".backup"
        if now is None:
            now = time.time()

        initial_path_u = os.path.dirname(abspath_u)
        fileutil.make_dirs_with_absolute_mode(local_path_u, initial_path_u,
                                              (~self._umask) & 0777)
        fileutil.write(replacement_path_u, file_contents)
        os.chmod(replacement_path_u, (~self._umask) & 0777)

        # FUDGE_SECONDS is used to determine if another process
        # has written to the same file concurrently. This is described
        # in the Earth Dragon section of our design document:
        # docs/proposed/magic-folder/remote-to-local-sync.rst
        os.utime(replacement_path_u, (now, now - self.FUDGE_SECONDS))
        if is_conflict:
            return self._rename_conflicted_file(abspath_u, replacement_path_u)
        else:
            try:
                fileutil.replace_file(abspath_u, replacement_path_u,
                                      backup_path_u)
                return abspath_u
            except fileutil.ConflictError:
                return self._rename_conflicted_file(abspath_u,
                                                    replacement_path_u)
Example #57
0
    def test_mv_error_if_DELETE_fails(self):
        self.basedir = "cli/Mv/mv_error_if_DELETE_fails"
        self.set_up_grid(oneshare=True)
        fn1 = os.path.join(self.basedir, "file1")
        DATA1 = b"Nuclear launch codes"
        fileutil.write(fn1, DATA1)

        original_do_http = tahoe_mv.do_http

        def mock_do_http(method, url, body=b""):
            if method == "DELETE":

                class FakeResponse(object):
                    def read(self):
                        return "response"

                resp = FakeResponse()
                resp.status = '500 Something Went Wrong'
                resp.reason = '*shrug*'
                return resp
            else:
                return original_do_http(method, url, body=body)

        tahoe_mv.do_http = mock_do_http

        # copy file to the grid
        d = self.do_cli("create-alias", "tahoe")
        d.addCallback(lambda res: self.do_cli("cp", fn1, "tahoe:"))

        # do mv file1 file2
        d.addCallback(
            lambda res: self.do_cli("mv", "tahoe:file1", "tahoe:file2"))

        def _check(args):
            (rc, out, err) = args
            self.failIfIn("OK", out,
                          "mv printed 'OK' even though the DELETE failed")
            self.failUnlessEqual(rc, 2)

        d.addCallback(_check)

        def _restore_do_http(res):
            tahoe_mv.do_http = original_do_http
            return res

        d.addBoth(_restore_do_http)
        return d
Example #58
0
    def test_error_on_old_config_files(self, mock_log_msg):
        basedir = "test_client.Basic.test_error_on_old_config_files"
        os.mkdir(basedir)
        fileutil.write(
            os.path.join(basedir, "tahoe.cfg"), BASECONFIG + "[storage]\n" +
            "enabled = false\n" + "reserved_space = bogus\n")
        fileutil.write(os.path.join(basedir, "introducer.furl"), "")
        fileutil.write(os.path.join(basedir, "no_storage"), "")
        fileutil.write(os.path.join(basedir, "readonly_storage"), "")
        fileutil.write(os.path.join(basedir, "debug_discard_storage"), "")

        e = self.failUnlessRaises(OldConfigError, client.Client, basedir)
        self.failUnlessIn(
            os.path.abspath(os.path.join(basedir, "introducer.furl")),
            e.args[0])
        self.failUnlessIn(os.path.abspath(os.path.join(basedir, "no_storage")),
                          e.args[0])
        self.failUnlessIn(
            os.path.abspath(os.path.join(basedir, "readonly_storage")),
            e.args[0])
        self.failUnlessIn(
            os.path.abspath(os.path.join(basedir, "debug_discard_storage")),
            e.args[0])

        for oldfile in [
                'introducer.furl', 'no_storage', 'readonly_storage',
                'debug_discard_storage'
        ]:
            logged = [
                m for m in mock_log_msg.call_args_list
                if ("Found pre-Tahoe-LAFS-v1.3 configuration file" in str(
                    m[0][0]) and oldfile in str(m[0][0]))
            ]
            self.failUnless(logged, (oldfile, mock_log_msg.call_args_list))

        for oldfile in [
                'nickname', 'webport', 'keepalive_timeout',
                'log_gatherer.furl', 'disconnect_timeout',
                'advertised_ip_addresses', 'helper.furl', 'key_generator.furl',
                'stats_gatherer.furl', 'sizelimit', 'run_helper'
        ]:
            logged = [
                m for m in mock_log_msg.call_args_list
                if ("Found pre-Tahoe-LAFS-v1.3 configuration file" in str(
                    m[0][0]) and oldfile in str(m[0][0]))
            ]
            self.failIf(logged, oldfile)
Example #59
0
 def test_unreadable_config(self):
     if sys.platform == "win32":
         # if somebody knows a clever way to do this (cause
         # EnvironmentError when reading a file that really exists), on
         # windows, please fix this
         raise unittest.SkipTest("can't make unreadable files on windows")
     basedir = "test_client.Basic.test_unreadable_config"
     os.mkdir(basedir)
     fn = os.path.join(basedir, "tahoe.cfg")
     fileutil.write(fn, BASECONFIG)
     old_mode = os.stat(fn).st_mode
     os.chmod(fn, 0)
     try:
         e = self.assertRaises(EnvironmentError, client.Client, basedir)
         self.assertIn("Permission denied", str(e))
     finally:
         # don't leave undeleteable junk lying around
         os.chmod(fn, old_mode)
Example #60
0
    def test_get_pathinfo_symlink(self):
        if not hasattr(os, 'symlink'):
            raise unittest.SkipTest("can't create symlinks on this platform")

        basedir = "util/FileUtil/test_get_pathinfo"
        fileutil.make_dirs(basedir)

        f = os.path.join(basedir, "1.txt")
        fileutil.write(f, b"a" * 10)

        # create a symlink pointing to 1.txt
        slname = os.path.join(basedir, "linkto1.txt")
        os.symlink(f, slname)
        symlinkinfo = fileutil.get_pathinfo(slname)
        self.failUnlessTrue(symlinkinfo.islink)
        self.failUnlessTrue(symlinkinfo.exists)
        self.failUnlessFalse(symlinkinfo.isfile)
        self.failUnlessFalse(symlinkinfo.isdir)