예제 #1
0
 def setUp(self):
     self.log = self.capture_logging("juju.state.init")
     zookeeper.set_debug_level(0)
     self.client = ZookeeperClient(get_test_zookeeper_address())
     self.identity = make_identity("admin:genie")
     self.layout = StateHierarchy(self.client, self.identity, "i-abcdef",
                                  "dummy")
     return self.client.connect()
예제 #2
0
파일: initialize.py 프로젝트: mcclurmc/juju
def command(options):
    """
    Initialize Zookeeper hierarchy
    """
    zk_address = os.environ.get("ZOOKEEPER_ADDRESS", "127.0.0.1:2181")
    client = yield ZookeeperClient(zk_address).connect()
    try:
        hierarchy = StateHierarchy(
            client,
            options.admin_identity,
            options.instance_id,
            options.provider_type)
        yield hierarchy.initialize()
    finally:
        yield client.close()
예제 #3
0
 def setUp(self):
     self.log = self.capture_logging("juju.state.init")
     zookeeper.set_debug_level(0)
     self.client = ZookeeperClient(get_test_zookeeper_address())
     self.identity = make_identity("admin:genie")
     self.layout = StateHierarchy(
         self.client, self.identity, "i-abcdef", "dummy")
     return self.client.connect()
예제 #4
0
class LayoutTest(TestCase):

    def setUp(self):
        self.log = self.capture_logging("juju.state.init")
        zookeeper.set_debug_level(0)
        self.client = ZookeeperClient(get_test_zookeeper_address())
        self.identity = make_identity("admin:genie")
        self.layout = StateHierarchy(
            self.client, self.identity, "i-abcdef", "dummy")
        return self.client.connect()

    def tearDown(self):
        deleteTree(handle=self.client.handle)
        self.client.close()

    @inlineCallbacks
    def assert_existence_and_acl(self, path):
        exists = yield self.client.exists(path)
        self.assertTrue(exists)
        acls, stat = yield self.client.get_acl(path)

        found_admin_acl = False
        for acl in acls:
            if acl["id"] == self.identity \
                   and acl["perms"] == zookeeper.PERM_ALL:
                found_admin_acl = True
                break
        self.assertTrue(found_admin_acl)

    @inlineCallbacks
    def test_initialize(self):
        yield self.layout.initialize()

        yield self.assert_existence_and_acl("/charms")
        yield self.assert_existence_and_acl("/services")
        yield self.assert_existence_and_acl("/units")
        yield self.assert_existence_and_acl("/machines")
        yield self.assert_existence_and_acl("/relations")
        yield self.assert_existence_and_acl("/initialized")

        machine_state_manager = MachineStateManager(self.client)
        machine_state = yield machine_state_manager.get_machine_state(0)
        self.assertTrue(machine_state)
        instance_id = yield machine_state.get_instance_id()
        self.assertEqual(instance_id, "i-abcdef")

        settings_manager = GlobalSettingsStateManager(self.client)
        self.assertEqual((yield settings_manager.get_provider_type()), "dummy")
        self.assertEqual(
            self.log.getvalue().strip(),
            "Initializing zookeeper hierarchy")
예제 #5
0
 def setUp(self):
     yield super(LayoutTest, self).setUp()
     self.log = self.capture_logging("juju.state.init")
     zookeeper.set_debug_level(0)
     self.client = self.get_zookeeper_client()
     self.identity = make_identity("admin:genie")
     constraints_data = {
         "arch": "arm",
         "cpu": None,
         "ubuntu-series": "cranky",
         "provider-type": "dummy"}
     self.layout = StateHierarchy(
         self.client, self.identity, "i-abcdef", constraints_data, "dummy")
     yield self.client.connect()
예제 #6
0
class LayoutTest(TestCase):
    def setUp(self):
        self.log = self.capture_logging("juju.state.init")
        zookeeper.set_debug_level(0)
        self.client = ZookeeperClient(get_test_zookeeper_address())
        self.identity = make_identity("admin:genie")
        self.layout = StateHierarchy(self.client, self.identity, "i-abcdef",
                                     "dummy")
        return self.client.connect()

    def tearDown(self):
        deleteTree(handle=self.client.handle)
        self.client.close()

    @inlineCallbacks
    def assert_existence_and_acl(self, path):
        exists = yield self.client.exists(path)
        self.assertTrue(exists)
        acls, stat = yield self.client.get_acl(path)

        found_admin_acl = False
        for acl in acls:
            if acl["id"] == self.identity \
                   and acl["perms"] == zookeeper.PERM_ALL:
                found_admin_acl = True
                break
        self.assertTrue(found_admin_acl)

    @inlineCallbacks
    def test_initialize(self):
        yield self.layout.initialize()

        yield self.assert_existence_and_acl("/charms")
        yield self.assert_existence_and_acl("/services")
        yield self.assert_existence_and_acl("/units")
        yield self.assert_existence_and_acl("/machines")
        yield self.assert_existence_and_acl("/relations")
        yield self.assert_existence_and_acl("/initialized")

        machine_state_manager = MachineStateManager(self.client)
        machine_state = yield machine_state_manager.get_machine_state(0)
        self.assertTrue(machine_state)
        instance_id = yield machine_state.get_instance_id()
        self.assertEqual(instance_id, "i-abcdef")

        settings_manager = GlobalSettingsStateManager(self.client)
        self.assertEqual((yield settings_manager.get_provider_type()), "dummy")
        self.assertEqual(self.log.getvalue().strip(),
                         "Initializing zookeeper hierarchy")
예제 #7
0
class LayoutTest(EnvironmentsConfigTestBase):

    @inlineCallbacks
    def setUp(self):
        yield super(LayoutTest, self).setUp()
        self.log = self.capture_logging("juju.state.init")
        zookeeper.set_debug_level(0)
        self.client = self.get_zookeeper_client()
        self.identity = make_identity("admin:genie")
        constraints_data = {
            "arch": "arm",
            "cpu": None,
            "ubuntu-series": "cranky",
            "provider-type": "dummy"}
        self.layout = StateHierarchy(
            self.client, self.identity, "i-abcdef", constraints_data, "dummy")
        yield self.client.connect()

    def tearDown(self):
        deleteTree(handle=self.client.handle)
        self.client.close()

    @inlineCallbacks
    def assert_existence_and_acl(self, path):
        exists = yield self.client.exists(path)
        self.assertTrue(exists)
        acls, stat = yield self.client.get_acl(path)

        found_admin_acl = False
        for acl in acls:
            if acl["id"] == self.identity \
                   and acl["perms"] == zookeeper.PERM_ALL:
                found_admin_acl = True
                break
        self.assertTrue(found_admin_acl)

    @inlineCallbacks
    def test_initialize(self):
        yield self.layout.initialize()

        yield self.assert_existence_and_acl("/charms")
        yield self.assert_existence_and_acl("/services")
        yield self.assert_existence_and_acl("/units")
        yield self.assert_existence_and_acl("/machines")
        yield self.assert_existence_and_acl("/relations")
        yield self.assert_existence_and_acl("/initialized")

        # To check that the constraints landed correctly, we need the
        # environment config to have been sent, or we won't be able to
        # get a provider to help us construct the appropriate objects.
        yield self.push_default_config(with_constraints=False)

        esm = EnvironmentStateManager(self.client)
        env_constraints = yield esm.get_constraints()
        self.assertEquals(env_constraints, {
            "provider-type": "dummy",
            "ubuntu-series": None,
            "arch": "arm",
            "cpu": None,
            "mem": 512})

        machine_state_manager = MachineStateManager(self.client)
        machine_state = yield machine_state_manager.get_machine_state(0)
        machine_constraints = yield machine_state.get_constraints()
        self.assertTrue(machine_constraints.complete)
        self.assertEquals(machine_constraints, {
            "provider-type": "dummy",
            "ubuntu-series": "cranky",
            "arch": "arm",
            "cpu": None,
            "mem": 512})
        instance_id = yield machine_state.get_instance_id()
        self.assertEqual(instance_id, "i-abcdef")

        settings_manager = GlobalSettingsStateManager(self.client)
        self.assertEqual((yield settings_manager.get_provider_type()), "dummy")
        self.assertEqual(
            self.log.getvalue().strip(),
            "Initializing zookeeper hierarchy")
예제 #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))