def __init__(self, app, conf): """ """ self.app = app self.conf = conf self.logger = get_logger(conf, log_route='keystone_proxy') self.keystone_proxy_common_path = conf.get( 'keystone_proxy_common_path', '/ks') self.keystone_proxy_auth_path = conf.get('keystone_proxy_auth_path', 'auth') self.keystone_proxy_admin_path = conf.get('keystone_proxy_admin_path', 'admin') self.relay_rule = conf.get('relay_rule') if not self.relay_rule: raise ValueError, 'KeyStone Proxy relay_rule is NULL.' self.dispatcher_base_url = conf.get('dispatcher_base_url') if not self.dispatcher_base_url: raise ValueError, 'KeyStone Proxy dispatcher_base_url is NULL.' self.region_name = conf.get('region_name') if not self.region_name: raise ValueError, 'KeyStone Proxy region_name is NULL.' self.keystone_auth_port = int(conf.get('keystone_auth_port', 5000)) self.keystone_admin_port = int(conf.get('keystone_admin_port', 35357)) self.conn_timeout = float(conf.get('conn_timeout', 0.5)) self.timeout = int(conf.get('timeout', 300)) self.req_version_str = 'v[12]\.0' self.merge_str = '__@@__' try: self.loc = Location(self.relay_rule) except: raise ValueError, 'KeyStone Proxy relay rule is invalid.'
def test_02_LOCATION_update_location(self): """ server.txt reload if update.""" loc_str = ':test/server0.txt, local:test/server1.txt, both:(hoge)test/server2.txt (gere)test/server3.txt, remote:test/server4.txt' loc = Location(loc_str) old_server2_swifts = loc.swift_of('remote') with open('test/server4.txt', 'r') as f: olddata = f.read() with open('test/server4.txt', 'w') as f: f.write('http://192.168.2.1:8080') loc.reload() with open('test/server4.txt', 'w') as f: f.write(olddata) self.assertEqual([['http://192.168.2.1:8080']], loc.swift_of('remote'))
def __init__(self, conf): self.conf = conf self.logger = get_logger(conf, log_route='dispatcher') self.dispatcher_addr = conf.get('bind_ip', '127.0.0.1') self.dispatcher_port = int(conf.get('bind_port', 8000)) self.ssl_enabled = True if 'cert_file' in conf else False self.relay_rule = conf.get('relay_rule') self.combinater_char = conf.get('combinater_char', ':') self.node_timeout = int(conf.get('node_timeout', 10)) self.conn_timeout = float(conf.get('conn_timeout', 0.5)) self.client_timeout = int(conf.get('client_timeout', 60)) self.client_chunk_size = int(conf.get('client_chunk_size', 65536)) self.req_version_str = 'v1.0' self.req_auth_str = 'auth' self.merged_combinator_str = '__@@__' self.swift_store_large_chunk_size = int( conf.get('swift_store_large_chunk_size', MAX_FILE_SIZE)) try: self.loc = Location(self.relay_rule) except: raise ValueError, 'dispatcher relay rule is invalid.'
def test_01_LOCATION_load_location(self): """ location str parse and construct server info from server.txt""" loc_str = ':test/server0.txt, local:test/server1.txt, both:(hoge)test/server2.txt (gere)test/server3.txt, remote:test/server4.txt' loc = Location(loc_str) self.assertTrue(loc.has_location('')) self.assertTrue(loc.has_location('local')) self.assertTrue(loc.has_location('remote')) self.assertTrue(loc.has_location('both')) self.assertFalse(loc.has_location('nothing')) self.assertEqual( { 'webcache': { 'http://127.0.0.1:8080': 'http://127.0.0.1:8888' }, 'container_prefix': { 'http://127.0.0.1:8080': None }, 'swift': [['http://127.0.0.1:8080']] }, loc.servers_of('')) self.assertEqual( { 'webcache': { 'http://127.0.0.1:8080': None }, 'container_prefix': { 'http://127.0.0.1:8080': None }, 'swift': [['http://127.0.0.1:8080']] }, loc.servers_of('local')) self.assertEqual( { 'webcache': { 'http://127.0.0.1:18080': None, 'http://127.0.0.1:8080': None }, 'container_prefix': { 'http://127.0.0.1:18080': 'gere', 'http://127.0.0.1:8080': 'hoge' }, 'swift': [['http://127.0.0.1:8080'], ['http://127.0.0.1:18080']] }, loc.servers_of('both')) self.assertEqual( { 'webcache': { 'http://127.0.0.1:18080': None }, 'container_prefix': { 'http://127.0.0.1:18080': None }, 'swift': [['http://127.0.0.1:18080']] }, loc.servers_of('remote')) self.assertEqual([['http://127.0.0.1:8080']], loc.swift_of('')) self.assertEqual([['http://127.0.0.1:8080']], loc.swift_of('local')) self.assertEqual( [['http://127.0.0.1:8080'], ['http://127.0.0.1:18080']], loc.swift_of('both')) self.assertEqual([['http://127.0.0.1:18080']], loc.swift_of('remote')) self.assertFalse(loc.is_merged('')) self.assertFalse(loc.is_merged('local')) self.assertTrue(loc.is_merged('both')) self.assertFalse(loc.is_merged('remote')) self.assertEqual(loc.is_merged('nothing'), None) self.assertEqual(None, loc.container_prefix_of('', 'http://127.0.0.1:8080')) self.assertEqual( 'hoge', loc.container_prefix_of('both', 'http://127.0.0.1:8080')) self.assertEqual( 'gere', loc.container_prefix_of('both', 'http://127.0.0.1:18080')) self.assertEqual({'http://127.0.0.1:8080': 'http://127.0.0.1:8888'}, loc.webcache_of('')) self.assertEqual({'http://127.0.0.1:8080': None}, loc.webcache_of('local')) self.assertEqual( { 'http://127.0.0.1:18080': None, 'http://127.0.0.1:8080': None }, loc.webcache_of('both')) self.assertEqual({'http://127.0.0.1:18080': None}, loc.webcache_of('remote')) self.assertEqual({'http://127.0.0.1:8080': None}, loc.container_prefixes_of('')) self.assertEqual({'http://127.0.0.1:8080': None}, loc.container_prefixes_of('local')) self.assertEqual( { 'http://127.0.0.1:18080': 'gere', 'http://127.0.0.1:8080': 'hoge' }, loc.container_prefixes_of('both')) self.assertEqual({'http://127.0.0.1:18080': None}, loc.container_prefixes_of('remote')) self.assertEqual(['http://127.0.0.1:8080'], loc.servers_by_container_prefix_of('both', 'hoge')) self.assertEqual(['http://127.0.0.1:18080'], loc.servers_by_container_prefix_of('both', 'gere')) self.assertEqual( 'http://127.0.0.1:9999', loc._sock_connect_faster([ 'http://127.0.0.1:8080', 'http://127.0.0.1:18080', 'http://127.0.0.1:9999' ])[2]) loc_str = ':test/server0.txt test/server1.txt' loc = Location(loc_str) self.assertEqual(True, loc.is_merged(''))