Beispiel #1
0
def add_service(basedir, service_type, service_args, comment, swissnum=None):
    if not swissnum:
        swissnum = make_swissnum()
    services_data = load_service_data(basedir)
    relative_service_basedir = find_next_service_basedir(basedir)
    service_basedir = os.path.join(basedir, relative_service_basedir)
    os.makedirs(service_basedir)
    try:
        # validate the service args by instantiating one
        s = build_service(service_basedir, None, service_type, service_args)
        del s
    except:
        shutil.rmtree(service_basedir)
        raise

    services_data["services"][swissnum] = {
        "relative_basedir": relative_service_basedir,
        "type": service_type,
        "args": service_args,
        "comment": comment,
        }
    save_service_data(basedir, services_data)

    furl_prefix = open(os.path.join(basedir, "furl_prefix")).read().strip()
    furl = furl_prefix + swissnum
    return furl, service_basedir
Beispiel #2
0
    def test_save(self):
        basedir = "appserver/ServiceData/save"
        os.makedirs(basedir)
        server.save_service_data(basedir, orig_service_data)

        data = server.load_service_data(basedir)
        self.failUnlessEqual(orig_service_data, data)
Beispiel #3
0
def add_service(basedir, service_type, service_args, comment, swissnum=None):
    if not swissnum:
        swissnum = make_swissnum()
    services_data = load_service_data(basedir)
    relative_service_basedir = find_next_service_basedir(basedir)
    service_basedir = os.path.join(basedir, relative_service_basedir)
    os.makedirs(service_basedir)
    try:
        # validate the service args by instantiating one
        s = build_service(service_basedir, None, service_type, service_args)
        del s
    except:
        shutil.rmtree(service_basedir)
        raise

    services_data["services"][swissnum] = {
        "relative_basedir": relative_service_basedir,
        "type": service_type,
        "args": service_args,
        "comment": comment,
    }
    save_service_data(basedir, services_data)

    furl_prefix = open(os.path.join(basedir, "furl_prefix")).read().strip()
    furl = furl_prefix + swissnum
    return furl, service_basedir
Beispiel #4
0
    def run(self, options):
        basedir = options.basedir
        stdout = options.stdout
        stderr = options.stderr
        if os.path.exists(basedir):
            print >>stderr, "Refusing to touch pre-existing directory %s" % basedir
            return 1

        assert options["port"]
        assert options["location"]

        os.makedirs(basedir)
        os.makedirs(os.path.join(basedir, "services"))
        os.chmod(basedir, 0700)

        # Start the server and let it create the key. The base FURL will be
        # written to a file so that subsequent 'add' and 'list' can compute
        # FURLs without needing to run the Tub (which might already be
        # running).

        f = open(os.path.join(basedir, "port"), "w")
        f.write("%s\n" % options["port"])
        f.close()
        # we'll overwrite BASEDIR/port if necessary

        f = open(os.path.join(basedir, "location"), "w")
        f.write("%s\n" % options["location"])
        f.close()

        f = open(os.path.join(basedir, "umask"), "w")
        f.write("%04o\n" % options["umask"])
        f.close()

        save_service_data(basedir, {"version": 1, "services": {}})

        a = AppServer(basedir, stdout)
        tub = a.tub

        sample_furl = tub.registerReference(Referenceable())
        furl_prefix = sample_furl[:sample_furl.rfind("/")+1]
        f = open(os.path.join(basedir, "furl_prefix"), "w")
        f.write(furl_prefix + "\n")
        f.close()

        f = open(os.path.join(basedir, "flappserver.tac"), "w")
        stashed_path = ""
        for p in sys.path:
            stashed_path += "  %r,\n" % p
        f.write(FLAPPSERVER_TACFILE % { 'path': stashed_path })
        f.close()

        if not options["quiet"]:
            print >>stdout, "Foolscap Application Server created in %s" % basedir
            print >>stdout, "TubID %s, listening on port %s" % (tub.getTubID(),
                                                                options["port"])
            print >>stdout, "Now launch the daemon with 'flappserver start %s'" % basedir
        return defer.succeed(0)
Beispiel #5
0
    def run(self, options):
        basedir = options.basedir
        stdout = options.stdout
        stderr = options.stderr
        if os.path.exists(basedir):
            print >> stderr, "Refusing to touch pre-existing directory %s" % basedir
            return 1

        assert options["port"]
        assert options["location"]

        os.makedirs(basedir)
        os.makedirs(os.path.join(basedir, "services"))
        os.chmod(basedir, 0700)

        # Start the server and let it create the key. The base FURL will be
        # written to a file so that subsequent 'add' and 'list' can compute
        # FURLs without needing to run the Tub (which might already be
        # running).

        f = open(os.path.join(basedir, "port"), "w")
        f.write("%s\n" % options["port"])
        f.close()
        # we'll overwrite BASEDIR/port if necessary

        f = open(os.path.join(basedir, "location"), "w")
        f.write("%s\n" % options["location"])
        f.close()

        f = open(os.path.join(basedir, "umask"), "w")
        f.write("%04o\n" % options["umask"])
        f.close()

        save_service_data(basedir, {"version": 1, "services": {}})

        a = AppServer(basedir, stdout)
        tub = a.tub

        sample_furl = tub.registerReference(Referenceable())
        furl_prefix = sample_furl[:sample_furl.rfind("/") + 1]
        f = open(os.path.join(basedir, "furl_prefix"), "w")
        f.write(furl_prefix + "\n")
        f.close()

        f = open(os.path.join(basedir, "flappserver.tac"), "w")
        stashed_path = ""
        for p in sys.path:
            stashed_path += "  %r,\n" % p
        f.write(FLAPPSERVER_TACFILE % {'path': stashed_path})
        f.close()

        if not options["quiet"]:
            print >> stdout, "Foolscap Application Server created in %s" % basedir
            print >> stdout, "TubID %s, listening on port %s" % (
                tub.getTubID(), options["port"])
            print >> stdout, "Now launch the daemon with 'flappserver start %s'" % basedir
        return defer.succeed(0)
Beispiel #6
0
    def test_parse_files_and_upgrade(self):
        # create a structure with individual files, and make sure we parse it
        # correctly. Test the git-foolscap case with slashes in the swissnum.
        basedir = "appserver/ServiceData/parse_files"
        os.makedirs(basedir)
        J = os.path.join

        f = open(os.path.join(basedir, "furl_prefix"), "wb")
        f.write(b"prefix")
        f.close()

        old_add_service(basedir, "type1", ("args1a", "args1b"), None, "swiss1")
        old_add_service(basedir, "type2", ("args2a", "args2b"), "comment2",
                        "swiss2")
        old_add_service(basedir, "type3", ("args3a", "args3b"), "comment3",
                        "swiss3/3")

        data = server.load_service_data(basedir)
        expected = {
            "version": 1,
            "services": {
                "swiss1": {
                    "relative_basedir": J("services", "swiss1"),
                    "type": "type1",
                    "args": ["args1a", "args1b"],
                    "comment": None,
                },
                "swiss2": {
                    "relative_basedir": J("services", "swiss2"),
                    "type": "type2",
                    "args": ["args2a", "args2b"],
                    "comment": "comment2",
                },
                J("swiss3", "3"): {
                    "relative_basedir": J("services", "swiss3", "3"),
                    "type": "type3",
                    "args": ["args3a", "args3b"],
                    "comment": "comment3",
                },
            }
        }
        self.assertEqual(data, expected)

        s4 = {
            "relative_basedir": J("services", "4"),
            "type": "type4",
            "args": ["args4a", "args4b"],
            "comment": "comment4",
        }
        data["services"]["swiss4"] = s4
        server.save_service_data(basedir, data)  # this upgrades to JSON
        data2 = server.load_service_data(basedir)  # reads JSON, not files
        expected["services"]["swiss4"] = s4
        self.assertEqual(data2, expected)
Beispiel #7
0
    def test_parse_files_and_upgrade(self):
        # create a structure with individual files, and make sure we parse it
        # correctly. Test the git-foolscap case with slashes in the swissnum.
        basedir = "appserver/ServiceData/parse_files"
        os.makedirs(basedir)
        J = os.path.join

        f = open(os.path.join(basedir, "furl_prefix"), "wb")
        f.write("prefix")
        f.close()

        old_add_service(basedir,
                        "type1", ("args1a", "args1b"), None, "swiss1")
        old_add_service(basedir,
                        "type2", ("args2a", "args2b"), "comment2", "swiss2")
        old_add_service(basedir,
                        "type3", ("args3a", "args3b"), "comment3", "swiss3/3")

        data = server.load_service_data(basedir)
        expected = {"version": 1,
                    "services": {
                        "swiss1": {"relative_basedir": J("services","swiss1"),
                                   "type": "type1",
                                   "args": ["args1a", "args1b"],
                                   "comment": None,
                                   },
                        "swiss2": {"relative_basedir": J("services","swiss2"),
                                   "type": "type2",
                                   "args": ["args2a", "args2b"],
                                   "comment": "comment2",
                                   },
                        J("swiss3","3"): {"relative_basedir":
                                        J("services","swiss3","3"),
                                        "type": "type3",
                                        "args": ["args3a", "args3b"],
                                        "comment": "comment3",
                                        },
                        }}
        self.failUnlessEqual(data, expected)

        s4 = {"relative_basedir": J("services","4"),
              "type": "type4",
              "args": ["args4a", "args4b"],
              "comment": "comment4",
              }
        data["services"]["swiss4"] = s4
        server.save_service_data(basedir, data) # this upgrades to JSON
        data2 = server.load_service_data(basedir) # reads JSON, not files
        expected["services"]["swiss4"] = s4
        self.failUnlessEqual(data2, expected)
Beispiel #8
0
    def run(self, options):
        basedir = options.basedir
        stdout = options.stdout
        stderr = options.stderr
        if os.path.exists(basedir):
            print >> stderr, "Refusing to touch pre-existing directory %s" % basedir
            return 1

        os.makedirs(basedir)
        os.makedirs(os.path.join(basedir, "services"))
        os.chmod(basedir, 0700)

        # start the server and let it run briefly. This lets the Tub spin up,
        # create the key, decide upon a port, and auto-determine its location
        # (if one was not provided with --location=). The base FURL will be
        # written to a file so that subsequent 'add' and 'list' can compute
        # FURLs without needing to run the Tub (which might already be
        # running).

        f = open(os.path.join(basedir, "port"), "w")
        f.write("%s\n" % options["port"])
        f.close()
        # we'll overwrite BASEDIR/port if necessary

        f = open(os.path.join(basedir, "location"), "w")
        f.write("%s\n" % options["location"])
        f.close()

        f = open(os.path.join(basedir, "umask"), "w")
        f.write("%04o\n" % options["umask"])
        f.close()

        save_service_data(basedir, {"version": 1, "services": {}})

        self.server = None
        d = fireEventually(basedir)
        d.addCallback(AppServer, stdout)
        d.addCallback(self.stash_and_start_appserver)
        d.addCallback(self.appserver_ready, options)
        d.addBoth(self.stop_appserver)
        d.addCallback(lambda ign: 0)
        return d
Beispiel #9
0
    def run(self, options):
        basedir = options.basedir
        stdout = options.stdout
        stderr = options.stderr
        if os.path.exists(basedir):
            print >> stderr, "Refusing to touch pre-existing directory %s" % basedir
            return 1

        os.makedirs(basedir)
        os.makedirs(os.path.join(basedir, "services"))
        os.chmod(basedir, 0700)

        # start the server and let it run briefly. This lets the Tub spin up,
        # create the key, decide upon a port, and auto-determine its location
        # (if one was not provided with --location=). The base FURL will be
        # written to a file so that subsequent 'add' and 'list' can compute
        # FURLs without needing to run the Tub (which might already be
        # running).

        f = open(os.path.join(basedir, "port"), "w")
        f.write("%s\n" % options["port"])
        f.close()
        # we'll overwrite BASEDIR/port if necessary

        f = open(os.path.join(basedir, "location"), "w")
        f.write("%s\n" % options["location"])
        f.close()

        f = open(os.path.join(basedir, "umask"), "w")
        f.write("%04o\n" % options["umask"])
        f.close()

        save_service_data(basedir, {"version": 1, "services": {}})

        self.server = None
        d = fireEventually(basedir)
        d.addCallback(AppServer, stdout)
        d.addCallback(self.stash_and_start_appserver)
        d.addCallback(self.appserver_ready, options)
        d.addBoth(self.stop_appserver)
        d.addCallback(lambda ign: 0)
        return d