def test_get_root_scheduler(self): """Test root scheduler introspection""" (root_host, root_port) = get_service_leader(self.zk_client, ROOT_SCHEDULER_SERVICE) # Verify that an empty root scheduler is constructed # correctly root_sch = get_root_scheduler(root_host, root_port) assert_that(root_sch.id, is_(ROOT_SCHEDULER_ID)) assert_that(root_sch.type, is_(ROOT_SCHEDULER_TYPE)) assert_that(len(root_sch.children), is_(0)) assert_that(root_sch.owner, not_none()) root_owner = root_sch.owner assert_that(root_owner.id, is_(ROOT_SCHEDULER_ID)) assert_that(root_owner.address, is_(root_host)) assert_that(root_owner.port, is_(root_port)) assert_that(root_owner.parent, is_(None)) # Start an agent agent_host = 'localhost' agent_port = 20000 config = self.runtime.get_agent_config(agent_host, agent_port, self.chairman_host, self.chairman_port) res = self.runtime.start_agent(config) agent_client = res[1] # Wait for the root scheduler to be configured _wait_for_configuration(self.root_sch_client, 1) new_root_sch = get_root_scheduler(root_host, root_port) assert_that(len(new_root_sch.children), is_(1)) req = THost.GetConfigRequest() agent_id = agent_client.get_host_config(req).hostConfig.agent_id leaf = new_root_sch.children.values()[0] assert_that(leaf.type, is_(LEAF_SCHEDULER_TYPE)) assert_that(leaf.parent, is_(new_root_sch)) assert_that(len(leaf.children), is_(0)) assert_that(leaf.owner.id, is_(agent_id)) assert_that(leaf.owner.address, is_(agent_host)) assert_that(leaf.owner.port, is_(agent_port)) assert_that(leaf.owner.parent, is_(leaf)) deleted = threading.Event() def _deleted(children): if not children: deleted.set() self.zk_client.ChildrenWatch(ROOT_SCHEDULER_SERVICE, _deleted) stop_service(self.runtime.root_procs[0]) # Wait for the leader to leave deleted.wait(30) emoty_root = get_root_scheduler(root_host, root_port) assert_that(emoty_root, is_(emoty_root))
def test_get_root_scheduler(self): """Test root scheduler introspection""" (root_host, root_port) = get_service_leader(self.zk_client, ROOT_SCHEDULER_SERVICE) # Verify that an empty root scheduler is constructed # correctly root_sch = get_root_scheduler(root_host, root_port) assert_that(root_sch.id, is_(ROOT_SCHEDULER_ID)) assert_that(root_sch.type, is_(ROOT_SCHEDULER_TYPE)) assert_that(len(root_sch.children), is_(0)) assert_that(root_sch.owner, not_none()) root_owner = root_sch.owner assert_that(root_owner.id, is_(ROOT_SCHEDULER_ID)) assert_that(root_owner.address, is_(root_host)) assert_that(root_owner.port, is_(root_port)) assert_that(root_owner.parent, is_(None)) # Start an agent agent_host = "localhost" agent_port = 20000 config = self.runtime.get_agent_config(agent_host, agent_port, self.chairman_host, self.chairman_port) res = self.runtime.start_agent(config) agent_client = res[1] # Wait for the root scheduler to be configured _wait_for_configuration(self.root_sch_client, 1) new_root_sch = get_root_scheduler(root_host, root_port) assert_that(len(new_root_sch.children), is_(1)) req = THost.GetConfigRequest() agent_id = agent_client.get_host_config(req).hostConfig.agent_id leaf = new_root_sch.children.values()[0] assert_that(leaf.type, is_(LEAF_SCHEDULER_TYPE)) assert_that(leaf.parent, is_(new_root_sch)) assert_that(len(leaf.children), is_(0)) assert_that(leaf.owner.id, is_(agent_id)) assert_that(leaf.owner.address, is_(agent_host)) assert_that(leaf.owner.port, is_(agent_port)) assert_that(leaf.owner.parent, is_(leaf)) deleted = threading.Event() def _deleted(children): if not children: deleted.set() self.zk_client.ChildrenWatch(ROOT_SCHEDULER_SERVICE, _deleted) stop_service(self.runtime.root_procs[0]) # Wait for the leader to leave deleted.wait(30) emoty_root = get_root_scheduler(root_host, root_port) assert_that(emoty_root, is_(emoty_root))
def tearDown(self): if self.thrift_server: self.thrift_server.stop_server() self.disconnect() for proc in self.procs: stop_service(proc) self.runtime.cleanup() self.tear_down_kazoo_base()
def test_update_status(self): agent_host = 'localhost' agent_port1 = 20000 config = self.runtime.get_agent_config(agent_host, agent_port1, self.chairman_host, self.chairman_port) res = self.runtime.start_agent(config) _wait_for_configuration(self.root_sch_client, 1) root = get_hierarchy_from_zk(self.zk_client) # Update the hierarchy status root.update_status() # verify that the root scheduler and leaf are online assert_that(root.owner.status, is_(STATUS_ONLINE)) assert_that(len(root.children), is_(1)) assert_that(root.children.values()[0].owner.status, is_(STATUS_ONLINE)) # Kill both root scheduler and leaf host stop_service(self.runtime.root_procs[0]) self.runtime.stop_agent(res[0]) # Update the hierarchy status root.update_status() assert_that(root.owner.status, is_(STATUS_OFFLINE)) assert_that(root.children.values()[0].owner.status, is_(STATUS_OFFLINE)) # Start the root scheduler and leaf scheduler self.runtime.start_root_scheduler(self.root_conf) config = self.runtime.get_agent_config(agent_host, agent_port1, self.chairman_host, self.chairman_port) res = self.runtime.start_agent(config) (self.root_transport, self.root_sch_client) = create_root_client(self.root_port, self.root_host) # Wait for the root scheduler's leader election _wait_on_code(self.root_sch_client.get_schedulers, GetSchedulersResultCode.OK) # Check the status again root.update_status() # verify that the root scheduler and leaf are online assert_that(root.owner.status, is_(STATUS_ONLINE)) assert_that(root.children.values()[0].owner.status, is_(STATUS_ONLINE))
def test_get_service_leader(self): """Test get service leader""" # Check the chairman leader (address, port) = get_service_leader(self.zk_client, CHAIRMAN_SERVICE) assert_that(address, is_(self.chairman_host)) assert_that(port, is_(self.chairman_port)) deleted = threading.Event() def _deleted(children): if not children: deleted.set() self.zk_client.ChildrenWatch(CHAIRMAN_SERVICE, _deleted) # Stop chairman stop_service(self.runtime.chairman_procs[0]) # Wait for the leader to leave deleted.wait(30) res = get_service_leader(self.zk_client, CHAIRMAN_SERVICE) assert_that(res, is_(None))
def test_update_status(self): agent_host = "localhost" agent_port1 = 20000 config = self.runtime.get_agent_config(agent_host, agent_port1, self.chairman_host, self.chairman_port) res = self.runtime.start_agent(config) _wait_for_configuration(self.root_sch_client, 1) root = get_hierarchy_from_zk(self.zk_client) # Update the hierarchy status root.update_status() # verify that the root scheduler and leaf are online assert_that(root.owner.status, is_(STATUS_ONLINE)) assert_that(len(root.children), is_(1)) assert_that(root.children.values()[0].owner.status, is_(STATUS_ONLINE)) # Kill both root scheduler and leaf host stop_service(self.runtime.root_procs[0]) self.runtime.stop_agent(res[0]) # Update the hierarchy status root.update_status() assert_that(root.owner.status, is_(STATUS_OFFLINE)) assert_that(root.children.values()[0].owner.status, is_(STATUS_OFFLINE)) # Start the root scheduler and leaf scheduler self.runtime.start_root_scheduler(self.root_conf) config = self.runtime.get_agent_config(agent_host, agent_port1, self.chairman_host, self.chairman_port) res = self.runtime.start_agent(config) (self.root_transport, self.root_sch_client) = create_root_client(self.root_port, self.root_host) # Wait for the root scheduler's leader election _wait_on_code(self.root_sch_client.get_schedulers, GetSchedulersResultCode.OK) # Check the status again root.update_status() # verify that the root scheduler and leaf are online assert_that(root.owner.status, is_(STATUS_ONLINE)) assert_that(root.children.values()[0].owner.status, is_(STATUS_ONLINE))