예제 #1
0
파일: __init__.py 프로젝트: mcclurmc/juju
    def destroy_environment(self):
        """Shutdown the machine environment.
        """
        # Stop all the containers
        log.info("Destroying unit containers...")
        yield self._destroy_containers()

        # Stop the machine agent
        log.debug("Stopping machine agent...")
        pid_file = os.path.join(self._directory, "machine-agent.pid")
        agent = ManagedMachineAgent(pid_file)
        yield agent.stop()

        # Stop the storage server
        log.debug("Stopping storage server...")
        pid_file = os.path.join(self._directory, "storage-server.pid")
        storage_server = StorageServer(pid_file)
        yield storage_server.stop()

        # Stop zookeeper
        log.debug("Stopping zookeeper...")
        zookeeper_dir = os.path.join(self._directory, "zookeeper")
        zookeeper = Zookeeper(zookeeper_dir, None)
        yield zookeeper.stop()

        # Clean out local state
        yield self.save_state(False)

        # Don't stop the network since we're using the default libvirt
        log.debug("Environment destroyed.")
예제 #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 test_stop_missing_pid(self):
     server = StorageServer(self._pid_path)
     server.stop()
예제 #4
0
 def test_start_missing_args(self):
     server = StorageServer(self._pid_path)
     return self.assertFailure(server.start(), AssertionError)
예제 #5
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))