Exemplo n.º 1
0
 def test_content_utilized(self):
     """
     The entire key content can be specified via configuration.
     """
     config = {"authorized-keys": "abc"}
     key_data = get_user_authorized_keys(config)
     self.assertEqual(key_data, config["authorized-keys"])
Exemplo n.º 2
0
 def test_content_utilized(self):
     """
     The entire key content can be specified via configuration.
     """
     config = {"authorized-keys": "abc"}
     key_data = get_user_authorized_keys(config)
     self.assertEqual(key_data, config["authorized-keys"])
Exemplo n.º 3
0
 def test_qualified_path(self):
     """
     An alternate path can be specified with user directory expansion.
     """
     alternate_dir = os.path.join(self.tmp_home, "es")
     os.mkdir(alternate_dir)
     self.makeFile("public-abc",
                   path=os.path.join(alternate_dir, "juju_key.pub"))
     config = {"authorized-keys-path": "~/es/juju_key.pub"}
     key_data = get_user_authorized_keys(config)
     self.assertEqual(key_data, "public-abc")
Exemplo n.º 4
0
 def test_qualified_path(self):
     """
     An alternate path can be specified with user directory expansion.
     """
     alternate_dir = os.path.join(self.tmp_home, "es")
     os.mkdir(alternate_dir)
     self.makeFile(
         "public-abc",
         path=os.path.join(alternate_dir, "juju_key.pub"))
     config = {"authorized-keys-path": "~/es/juju_key.pub"}
     key_data = get_user_authorized_keys(config)
     self.assertEqual(key_data, "public-abc")
Exemplo n.º 5
0
 def test_key_retrieval(self):
     """
     The F{juju.providers.common.get_user_authorized_keys} will retrieve
     a key's contents from disk and return the key data.
     """
     data = "alice in wonderland"
     self.makeFile(
         data,
         path=os.path.join(self.tmp_home, ".ssh", "identity_foobar.pub"))
     config = {"authorized-keys-path": "identity_foobar.pub"}
     key_data = get_user_authorized_keys(config)
     self.assertEqual(data, key_data)
Exemplo n.º 6
0
 def test_key_retrieval(self):
     """
     The F{juju.providers.common.get_user_authorized_keys} will retrieve
     a key's contents from disk and return the key data.
     """
     data = "alice in wonderland"
     self.makeFile(data,
                   path=os.path.join(self.tmp_home, ".ssh",
                                     "identity_foobar.pub"))
     config = {"authorized-keys-path": "identity_foobar.pub"}
     key_data = get_user_authorized_keys(config)
     self.assertEqual(data, key_data)
Exemplo n.º 7
0
    def bootstrap(self, constraints):
        """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)))))

        # 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))
Exemplo n.º 8
0
    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))