def services_to_check(): # Filter SERVICES down to what should be running on the node. # server_type returns a dict of {'object': bool, etc} prefix_server_type = tuple(k for k, v in server_type().items() if v) services = [s for s in SERVICES if s.startswith(prefix_server_type)] return services
def not_swift_owned(): results = set() # Check /etc/swift and its children p = SWIFT_DIR if os.path.isdir(p): for root, dirs, files in os.walk(p, followlinks=True): for d in dirs: x = os.path.join(root, d) _is_swift_owned(results, x) for f in files: x = os.path.join(root, f) _is_swift_owned(results, x) else: add_result(results, p, 'missing') # Check all disk directories in /srv/node/ p = NODE_DIR if os.path.isdir(p): # We need to use topdown otherwise the directory tree is generated # first, This would be unacceptably slow with large numbers or objects for root, dirs, _ in os.walk(p, topdown=True): for d in dirs: x = os.path.join(root, d) _is_swift_owned(results, x) break # We only want to check immediate child directories else: if server_type(ServerType.object): # We only care that this directory is missing on object servers. add_result(results, p, 'missing') return results
def test_server_type(self, mock_isfile): mock_isfile.return_value = True expected = {"object": True, "proxy": True, "container": True, "account": True} # test dict of all ServerTypes. actual = utility.server_type() self.assertDictEqual(expected, actual) # test a single ServerType is_o = utility.server_type(ServerType.object) self.assertTrue(is_o) # test multiple ServerTypes is_o, is_a = utility.server_type(ServerType.object, ServerType.account) self.assertTrue(is_o) self.assertTrue(is_a) with self.assertRaisesRegexp(ValueError, "ServerType"): utility.server_type("test")
def main(): """Checks connectivity to memcache and object servers.""" results = [] if server_type(ServerType.proxy): cp = configparser.ConfigParser() cp.read(os.path.join(SWIFT_PROXY_PATH, 'proxy-server.conf')) try: memcache_servers = [ HostPort.from_string(s) for s in cp.get('filter:cache', 'memcache_servers').split(',') ] except configparser.NoSectionError: memcache_servers = [] check(memcache_servers, memcache_check, results) try: # Remove the version api path. ise = cp.get('filter:authtoken', 'identity_uri') parsed = urlparse.urlparse(ise) endpoint_servers = [HostPort(parsed.hostname, str(parsed.port))] except configparser.NoSectionError: endpoint_servers = [] check(endpoint_servers, connect_check, results) # TODO -- rewrite this as a connect_check # try: # ping_targets = [] # devices = get_ring_hosts(ring_type=None) # ip_set = set() # # for device in devices: # if device.ip not in ip_set: # # Port not relevant for ping_check. (Empty string is an # # invalid dimension value, Hence '_' used for target_port) # ping_targets.append(HostPort(device.ip, '_')) # ip_set.add(device.ip) # # except Exception: # noqa # # may be some problem loading ring files, but not concern of this check # # to diagnose any further. # pass # # check(ping_targets, ping_check, results) return results
def test_server_type(self, mock_isfile): mock_isfile.return_value = True expected = { 'object': True, 'proxy': True, 'container': True, 'account': True } # test dict of all ServerTypes. actual = utility.server_type() self.assertDictEqual(expected, actual) # test a single ServerType is_o = utility.server_type(ServerType.object) self.assertTrue(is_o) # test multiple ServerTypes is_o, is_a = utility.server_type(ServerType.object, ServerType.account) self.assertTrue(is_o) self.assertTrue(is_a) with self.assertRaisesRegexp(ValueError, 'ServerType'): utility.server_type('test')
def empty_files(results): # Check individual files if not server_type(ServerType.proxy): _is_empty_file(results, CONF_DIR + '/rsyncd.conf') _is_empty_file(results, CONF_DIR + '/rsyslog.conf') # Check all children in /etc/swift p = SWIFT_DIR if os.path.isdir(p): for root, _, files in os.walk(p, followlinks=True): for f in files: x = os.path.join(root, f) _is_empty_file(results, x) else: add_result(results, p, 'missing') return results
def empty_files(): results = set() # Check individual files if not server_type(ServerType.proxy): _is_empty_file(results, CONF_DIR + '/rsyncd.conf') _is_empty_file(results, CONF_DIR + '/rsyslog.conf') # Check all children in /etc/swift p = SWIFT_DIR if os.path.isdir(p): for root, _, files in os.walk(p, followlinks=True): for f in files: x = os.path.join(root, f) _is_empty_file(results, x) else: add_result(results, p, 'missing') return results
def main(): """Checks connectivity to memcache and object servers.""" results = [] if server_type(ServerType.proxy): cp = configparser.ConfigParser() cp.read(os.path.join(MEMCACHE_CONF_PATH, 'memcache.conf')) try: memcache_servers = [ HostPort.from_string(s) for s in cp.get('memcache', 'memcache_servers').split(',') ] except configparser.NoSectionError: memcache_servers = [] check(memcache_servers, memcache_check, results) # Check Keystone token-validation endpoint scheme = 'http' cp.read(os.path.join(SWIFT_PROXY_PATH, 'proxy-server.conf')) try: ise = cp.get('filter:authtoken', 'auth_url') parsed = urlparse.urlparse(ise) endpoint_servers = [HostPort(parsed.hostname, str(parsed.port))] scheme = parsed.scheme except configparser.NoSectionError: endpoint_servers = [] check(endpoint_servers, connect_check, results, scheme=scheme) # rsync is required for ACO servers so filter on these server_type() if (server_type(ServerType.account) or server_type(ServerType.container) or server_type(ServerType.object)): # swiftlm-scan.conf is the ansible-generated source of truth # default in the case of ansible not laying down the rsync-target port cp = configparser.ConfigParser() cp.read(os.path.join(SWIFTLM_SCAN_PATH, 'swiftlm-scan.conf')) # this assumes (rightfully so) that all nodes will be using # the same rsync_bind_port as opposed to querying each node # for its possibly uniquely-configured port try: rsync_bind_port = cp.get('rsync-target', 'rsync_bind_port') except (configparser.NoSectionError, configparser.NoOptionError): rsync_bind_port = '873' try: # retrieve unique list of nodes in the ring using the ring file # and utilizing the configured replication network IP rsync_targets = [] devices = get_ring_hosts(ring_type=None) rsync_set = set() for device in devices: if device.replication_ip not in rsync_set: rsync_host = socket.gethostbyaddr(device.replication_ip) rsync_targets.append( HostPort(rsync_host[0], rsync_bind_port)) rsync_set.add(device.replication_ip) except Exception: pass check(rsync_targets, rsync_check, results) # TODO -- rewrite this as a connect_check # try: # ping_targets = [] # devices = get_ring_hosts(ring_type=None) # ip_set = set() # # for device in devices: # if device.ip not in ip_set: # # Port not relevant for ping_check. (Empty string is an # # invalid dimension value, Hence '_' used for target_port) # ping_targets.append(HostPort(device.ip, '_')) # ip_set.add(device.ip) # # except Exception: # noqa # # may be some problem loading ring files, but not concern of this check # # to diagnose any further. # pass # # check(ping_targets, ping_check, results) return results