def test_server_hostname(self): """Test returning hostname for given server.presence node.""" self.assertEqual(presence.server_hostname('xxx.xx.com'), 'xxx.xx.com') self.assertEqual( presence.server_hostname('yyy.yy.com#12345'), 'yyy.yy.com' )
def _server_presence_watch(server_presence): """Watch server presence.""" for node in sorted(server_presence, reverse=True): if presence.server_hostname(node) == self._hostname: _LOGGER.info('Presence node found: %s, watching.', node) zkclient.DataWatch(z.path.server_presence(node), _server_presence_update) return False _LOGGER.info('Presence node not found, waiting.') return not shutdown.is_set()
def test(): """Create sysapps test class.""" admin_srv = admin.Server(context.GLOBAL.ldap.conn) cell = context.GLOBAL.cell ldap_servers = [item['_id'] for item in admin_srv.list({'cell': cell})] zkclient = context.GLOBAL.zk.conn configured_servers = zkclient.get_children(z.SERVERS) up_servers = [presence.server_hostname(node) for node in zkclient.get_children(z.SERVER_PRESENCE)] blackedout_servers = zkclient.get_children(z.BLACKEDOUT_SERVERS) rebooted_servers = zkclient.get_children(z.REBOOTS) class LdapSyncTest(unittest.TestCase): """Checks LDAP to Zookeeper server sync.""" for server in ldap_servers: @chk.T(LdapSyncTest, server=server, configured_servers=configured_servers) def _test_server_configured(self, server, configured_servers): """Check if server is synced between LDAP and Zk: {server}.""" self.assertIn(server, configured_servers) class ServerTest(unittest.TestCase): """Checks server(s) are up and alive.""" expected_up = ( set(configured_servers) - set(blackedout_servers) - set(rebooted_servers) ) for server in expected_up: @chk.T(ServerTest, server=server, up_servers=up_servers) def _test_server_up(self, server, up_servers): """Check if server is up: {server}.""" self.assertIn(server, up_servers) @chk.T(ServerTest, server=server) def _test_server_ssh(self, server): """Check if SSH port is open: {server}.""" self.assertTrue(chk.telnet(server, 22)) # TODO: implement test that for each partition sum of available capacity # is not below partition threshold. return [LdapSyncTest, ServerTest]
def test(): """Create server test class.""" zkclient = context.GLOBAL.zk.conn servers = [ presence.server_hostname(node) for node in zkclient.get_children(z.SERVER_PRESENCE) ] nodeinfo_endpoints = zkclient.get_children(z.path.endpoint_proid('root')) server_endpoints = dict() for name in nodeinfo_endpoints: server_endpoints[name[:name.index('#')]] = name class NodeinfoTest(unittest.TestCase): """Checks server nodeinfo API.""" server = None for server in servers: @chk.T(NodeinfoTest, server=server, server_endpoints=server_endpoints) def _is_present(self, server, server_endpoints): """Nodeinfo is present for server: {server}.""" self.assertIn(server, server_endpoints) @chk.T(NodeinfoTest, server=server, server_endpoints=server_endpoints) def _is_up(self, server, server_endpoints): """Nodeinfo is up for server: {server}.""" hostport, _metadata = zkclient.get( z.join_zookeeper_path(z.ENDPOINTS, 'root', server_endpoints[server])) host, port = hostport.split(':') url = 'http://%s:%s' % (host, port) print(url) self.assertTrue(chk.connect(host, port)) self.assertTrue(chk.url_check(url)) return NodeinfoTest