예제 #1
0
파일: test_files.py 프로젝트: mcclurmc/juju
 def setUp(self):
     self._storage_path = self.makeDir()
     self._storage = LocalStorage(self._storage_path)
     self._log_path = self.makeFile()
     self._pid_path = self.makeFile()
     self._port = get_open_port()
     self._server = StorageServer(
         self._pid_path, self._storage_path, "localhost",
         get_open_port(), self._log_path)
예제 #2
0
 def setUp(self):
     self._storage_path = self.makeDir()
     self._storage = LocalStorage(self._storage_path)
     self._log_path = self.makeFile()
     self._pid_path = self.makeFile()
     self._port = get_open_port()
     self._server = StorageServer(self._pid_path,
                                  self._storage_path, "localhost",
                                  get_open_port(), self._log_path)
예제 #3
0
 def setUp(self):
     yield super(WebFileStorageTest, self).setUp()
     self._storage_path = self.makeDir()
     self._logfile = self.makeFile()
     self._storage = LocalStorage(self._storage_path)
     self._port = get_open_port()
     self._server = StorageServer(
         "ns1", self._storage_path, "localhost", self._port, self._logfile)
예제 #4
0
 def test_capture_errors(self):
     self._port = get_open_port()
     self._server = StorageServer(
         "borken", self._storage_path, "lol borken", self._port,
         self._logfile)
     d = self._server.start()
     e = yield self.assertFailure(d, ServiceError)
     self.assertTrue(str(e).startswith(
         "Failed to start job juju-borken-file-storage; got output:\n"))
     self.assertIn("Wrong number of arguments", str(e))
     yield self._server.stop()
예제 #5
0
파일: test_utils.py 프로젝트: mcclurmc/juju
    def test_get_open_port_with_host(self):
        port = get_open_port("localhost")
        self.assertTrue(isinstance(port, int))

        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
                             socket.IPPROTO_TCP)

        # would raise an error if we got it wrong.
        sock.bind(("127.0.0.1", port))
        sock.listen(1)
        sock.close()
        del sock
예제 #6
0
파일: test_utils.py 프로젝트: mcclurmc/juju
    def test_get_open_port_with_host(self):
        port = get_open_port("localhost")
        self.assertTrue(isinstance(port, int))

        sock = socket.socket(
            socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)

        # would raise an error if we got it wrong.
        sock.bind(("127.0.0.1", port))
        sock.listen(1)
        sock.close()
        del sock
예제 #7
0
    def test_namespacing(self):
        alt_storage_path = self.makeDir()
        alt_storage = LocalStorage(alt_storage_path)
        yield alt_storage.put("some-path", StringIO("alternative"))
        yield self._storage.put("some-path", StringIO("original"))

        alt_server = StorageServer(
            "ns2", alt_storage_path, "localhost", get_open_port(),
            self.makeFile())
        yield alt_server.start()
        yield self._server.start()
        yield self.wait_for_server(alt_server)
        yield self.wait_for_server(self._server)

        alt_contents = yield getPage(
            (yield alt_storage.get_url("some-path")))
        self.assertEquals(alt_contents, "alternative")
        orig_contents = yield getPage(
            (yield self._storage.get_url("some-path")))
        self.assertEquals(orig_contents, "original")

        yield alt_server.stop()
        yield self._server.stop()
예제 #8
0
파일: __init__.py 프로젝트: mcclurmc/juju
    def bootstrap(self):
        """Bootstrap a local development environment.
        """
        # Check for existing environment
        state = yield self.load_state()
        if state is not False:
            raise ProviderError("Environment already bootstrapped")

        # Check for required packages
        log.info("Checking for required packages...")
        missing = check_packages(*REQUIRED_PACKAGES)
        if missing:
            raise ProviderError("Missing packages %s" % (
                ", ".join(sorted(list(missing)))))

        # Get/create directory for zookeeper and files
        zookeeper_dir = os.path.join(self._directory, "zookeeper")
        if not os.path.exists(zookeeper_dir):
            os.makedirs(zookeeper_dir)

        # Start networking, and get an open port.
        log.info("Starting networking...")
        net = Network("default", subnet=122)

        # Start is a noop if its already started, which it is by default,
        # per libvirt-bin package installation
        yield net.start()
        net_attributes = yield net.get_attributes()
        port = get_open_port(net_attributes["ip"]["address"])

        # Start zookeeper
        log.info("Starting zookeeper...")
        # Run zookeeper as the current user, unless we're being run as root
        # in which case run zookeeper as the 'zookeeper' user.
        zookeeper_user = None
        if os.geteuid() == 0:
            zookeeper_user = "******"
        zookeeper = Zookeeper(zookeeper_dir,
                              port=port,
                              host=net_attributes["ip"]["address"],
                              user=zookeeper_user, group=zookeeper_user)

        yield zookeeper.start()

        # Starting provider storage server
        log.info("Starting storage server...")
        storage_server = StorageServer(
            pid_file=os.path.join(self._directory, "storage-server.pid"),
            storage_dir=os.path.join(self._directory, "files"),
            host=net_attributes["ip"]["address"],
            port=get_open_port(net_attributes["ip"]["address"]),
            log_file=os.path.join(self._directory, "storage-server.log"))
        yield storage_server.start()

        # Save the zookeeper start to provider storage.
        yield self.save_state({"zookeeper-instances": ["local"],
                               "zookeeper-address": zookeeper.address})

        # Initialize the zookeeper state
        log.debug("Initializing state...")
        admin_identity = make_identity(
            "admin:%s" % self.config["admin-secret"])
        client = ZookeeperClient(zookeeper.address)
        yield client.connect()
        hierarchy = StateHierarchy(client, admin_identity, "local", "local")
        yield hierarchy.initialize()

        # Store user credentials from the running user
        try:
            public_key = get_user_authorized_keys(self.config)
            public_key = public_key.strip()
        except LookupError, e:
            raise ProviderError(str(e))