def test_eq(): """Test Virtual Server equality.""" partition = 'Common' name = 'virtual_1' virtual = VirtualServer(default_route_domain=2, **deepcopy(cfg_test)) virtual2 = VirtualServer(default_route_domain=2, **deepcopy(cfg_test)) virtual3 = VirtualServer(default_route_domain=2, **deepcopy(cfg_test)) pool = Pool(name=name, partition=partition) assert virtual assert virtual2 assert virtual3 assert virtual == virtual2 # remove profile context from Virtual2, should still be equal (because # context is optional) del virtual.data['profiles'][0]['context'] assert virtual == virtual2 # remove profile, now unequal del virtual.data['profiles'][0] assert virtual != virtual2 assert virtual3 == virtual2 # not equal virtual2.data['destination'] = '/Test/1.2.3.4:8080' assert virtual3 != virtual2 # different objects assert virtual != pool
def test_eq(): """Test Virtual Server equality.""" partition = 'Common' name = 'virtual_1' virtual = VirtualServer( **cfg_test ) virtual2 = VirtualServer( **cfg_test ) pool = Pool( name=name, partition=partition ) assert virtual assert virtual2 assert virtual == virtual2 # not equal virtual2.data['destination'] = '/Test/1.2.3.4:8080' assert virtual != virtual2 # different objects assert virtual != pool
def test_hash(): """Test Virtual Server hash.""" virtual = VirtualServer( **cfg_test ) virtual1 = VirtualServer( **cfg_test ) cfg_changed = copy(cfg_test) cfg_changed['name'] = 'test' virtual2 = VirtualServer( **cfg_changed ) cfg_changed = copy(cfg_test) cfg_changed['partition'] = 'other' virtual3 = VirtualServer( **cfg_changed ) assert virtual assert virtual1 assert virtual2 assert virtual3 assert hash(virtual) == hash(virtual1) assert hash(virtual) != hash(virtual2) assert hash(virtual) != hash(virtual3)
def test_uri_path(bigip): """Test Virtual Server URI.""" virtual = VirtualServer( **cfg_test ) assert virtual assert virtual._uri_path(bigip) == bigip.tm.ltm.virtuals.virtual
def test_uri_path(bigip): """Test Virtual Server URI.""" virtual = VirtualServer( default_route_domain=2, **cfg_test ) assert virtual assert virtual._uri_path(bigip) == bigip.tm.ltm.virtuals.virtual
def test_ipv6_destination(): cfg = copy(cfg_test) cfg['destination'] = "/Test_1/2001::1%2.80" virtual = VirtualServer(default_route_domain=2, **cfg) destination = virtual.destination assert destination[0] == "/Test_1/2001::1%2.80" assert destination[1] == "Test_1" assert destination[2] == "2001::1%2" assert destination[3] == "80" cfg = copy(cfg_test) cfg['destination'] = "/Test/2001:0db8:85a3:0000:0000:8a2e:0370:7334.80" virtual = VirtualServer(default_route_domain=2, **cfg) destination = virtual.destination assert destination[ 0] == "/Test/2001:0db8:85a3:0000:0000:8a2e:0370:7334%2.80" assert destination[1] == "Test" assert destination[2] == "2001:0db8:85a3:0000:0000:8a2e:0370:7334%2" assert destination[3] == "80" cfg = copy(cfg_test) cfg['destination'] = "/Test/2001:0db8:85a3::8a2e:0370:7334.80" virtual = VirtualServer(default_route_domain=2, **cfg) destination = virtual.destination assert destination[0] == "/Test/2001:0db8:85a3::8a2e:0370:7334%2.80" assert destination[1] == "Test" assert destination[2] == "2001:0db8:85a3::8a2e:0370:7334%2" assert destination[3] == "80" # Negative matches cfg = copy(cfg_test) cfg['destination'] = "Test/2001:0db8:85a3::8a2e:0370:7334.80" virtual = VirtualServer(default_route_domain=2, **cfg) destination = virtual.destination assert destination[0] == "Test/2001:0db8:85a3::8a2e:0370:7334.80" assert not destination[1] assert not destination[2] assert not destination[3] # Negative matches cfg = copy(cfg_test) cfg['destination'] = "/Test/2001:0db8:85a3::8a2e:0370:7334%3:80" virtual = VirtualServer(default_route_domain=2, **cfg) destination = virtual.destination assert destination[0] == "/Test/2001:0db8:85a3::8a2e:0370:7334%3:80" assert not destination[1] assert not destination[2] assert not destination[3]
def test_bigip_properties(bigip_proxy): """Test BIG-IP properties function.""" big_ip = bigip_proxy test_pools = [ IcrPool(**p) for p in big_ip.mgmt_root().bigip_data['pools'] if p['partition'] == 'test' ] test_virtuals = [ VirtualServer(default_route_domain=0, **v) for v in big_ip.mgmt_root().bigip_data['virtuals'] if v['partition'] == 'test' ] # refresh the BIG-IP state big_ip.refresh_ltm() assert len(big_ip.get_pools()) == len(test_pools) for p in test_pools: assert big_ip._pools[p.name] == p assert len(big_ip.get_virtuals()) == len(test_virtuals) for v in test_virtuals: assert big_ip._virtuals[v.name] == v http_hc = big_ip.get_http_monitors() https_hc = big_ip.get_https_monitors() tcp_hc = big_ip.get_tcp_monitors() udp_hc = big_ip.get_udp_monitors() icmp_hc = big_ip.get_icmp_monitors()
def test_bigip_properties(bigip_proxy): """Test BIG-IP properties function.""" big_ip = bigip_proxy test_pools = [] for p in big_ip.mgmt_root().bigip_data['pools']: pool = IcrPool(**p) test_pools.append(pool) test_virtuals = [] for v in big_ip.mgmt_root().bigip_data['virtuals']: test_virtuals.append(VirtualServer(**v)) # refresh the BIG-IP state big_ip.refresh() assert len(big_ip.get_pools()) == len(test_pools) for p in test_pools: assert big_ip._pools[p.name] == p assert len(big_ip.get_virtuals()) == len(test_virtuals) for v in test_virtuals: assert big_ip._virtuals[v.name] == v http_hc = big_ip.get_http_monitors() https_hc = big_ip.get_https_monitors() tcp_hc = big_ip.get_tcp_monitors() icmp_hc = big_ip.get_icmp_monitors()
def test_bigip_refresh(big_ip): """Test BIG-IP refresh function.""" test_pools = [] for p in big_ip.bigip_data['pools']: pool = IcrPool(**p) test_pools.append(pool) test_virtuals = [] for v in big_ip.bigip_data['virtuals']: test_virtuals.append(VirtualServer(**v)) test_iapps = [] for i in big_ip.bigip_data['iapps']: test_iapps.append(ApplicationService(**i)) test_nodes = [] for n in big_ip.bigip_data['nodes']: test_nodes.append(Node(**n)) # refresh the BIG-IP state big_ip.refresh() # verify pools and pool members assert big_ip.tm.ltm.pools.get_collection.called assert len(big_ip._pools) == 2 assert len(big_ip._pools) == len(test_pools) for pool in test_pools: assert big_ip._pools[pool.name] == pool # Make a change, pools will not be equal pool._data['loadBalancingMode'] = 'Not a valid LB mode' assert big_ip._pools[pool.name] != pool # verify virtual servers assert big_ip.tm.ltm.virtuals.get_collection.called assert len(big_ip._virtuals) == 2 assert len(big_ip._virtuals) == len(test_virtuals) for v in test_virtuals: assert big_ip._virtuals[v.name] == v # Make a change, virtuals will not be equal v._data['partition'] = 'NoPartition' assert big_ip._virtuals[v.name] != v # verify application services assert big_ip.tm.sys.application.services.get_collection.called assert len(big_ip._iapps) == 2 assert len(big_ip._iapps) == len(test_iapps) for i in test_iapps: assert big_ip._iapps[i.name] == i # Make a change, iapps will not be equal i._data['template'] = '/Common/NoTemplate' assert big_ip._iapps[i.name] != i # verify nodes assert big_ip.tm.ltm.nodes.get_collection.called assert len(big_ip._nodes) == 4 assert len(big_ip._nodes) == len(test_nodes) for n in test_nodes: assert big_ip._nodes[n.name] == n
def test_eq(): """Test Virtual Server equality.""" partition = 'Common' name = 'virtual_1' virtual = VirtualServer( default_route_domain=2, **deepcopy(cfg_test) ) virtual2 = VirtualServer( default_route_domain=2, **deepcopy(cfg_test) ) virtual3 = VirtualServer( default_route_domain=2, **deepcopy(cfg_test) ) pool = Pool( name=name, partition=partition ) assert virtual assert virtual2 assert virtual3 assert virtual == virtual2 # remove profile context from Virtual2, should still be equal (because # context is optional) del virtual.data['profiles'][0]['context'] assert virtual == virtual2 # remove profile, now unequal del virtual.data['profiles'][0] assert virtual != virtual2 assert virtual3 == virtual2 # not equal virtual2.data['destination'] = '/Test/1.2.3.4:8080' assert virtual3 != virtual2 # different objects assert virtual != pool
def test_create_virtual(): """Test Virtual Server creation.""" virtual = VirtualServer(default_route_domain=2, **cfg_test) assert virtual # verify all cfg items for k, v in cfg_test.items(): if k == "vlans": assert virtual.data[k] == sorted(v) else: assert virtual.data[k] == v
def test_bigip_refresh_ltm(bigip_proxy): """Test BIG-IP refresh_ltm function.""" big_ip = bigip_proxy.mgmt_root() test_pools = [ IcrPool(**p) for p in big_ip.bigip_data['pools'] if p['partition'] == 'test' ] test_virtuals = [ VirtualServer(default_route_domain=0, **v) for v in big_ip.bigip_data['virtuals'] if v['partition'] == 'test' ] test_iapps = [ IcrApplicationService(**i) for i in big_ip.bigip_data['iapps'] if i['partition'] == 'test' ] test_nodes = [ IcrNode(default_route_domain=0, **n) for n in big_ip.bigip_data['nodes'] if n['partition'] == 'test' ] # refresh the BIG-IP state bigip_proxy.refresh_ltm() # verify pools and pool members assert big_ip.tm.ltm.pools.get_collection.called assert len(bigip_proxy._pools) == 1 assert len(bigip_proxy._pools) == len(test_pools) for pool in test_pools: assert bigip_proxy._pools[pool.name] == pool # Make a change, pools will not be equal pool._data['loadBalancingMode'] = 'Not a valid LB mode' assert bigip_proxy._pools[pool.name] != pool # verify virtual servers assert big_ip.tm.ltm.virtuals.get_collection.called assert len(bigip_proxy._virtuals) == 1 assert len(bigip_proxy._virtuals) == len(test_virtuals) for v in test_virtuals: assert bigip_proxy._virtuals[v.name] == v # Make a change, virtuals will not be equal v._data['partition'] = 'NoPartition' assert bigip_proxy._virtuals[v.name] != v # verify application services assert big_ip.tm.sys.application.services.get_collection.called assert len(bigip_proxy._iapps) == 2 assert len(bigip_proxy._iapps) == len(test_iapps) for i in test_iapps: assert bigip_proxy._iapps[i.name] == i # Make a change, iapps will not be equal i._data['template'] = '/Common/NoTemplate' assert bigip_proxy._iapps[i.name] != i # verify nodes assert big_ip.tm.ltm.nodes.get_collection.called assert len(bigip_proxy._nodes) == 4 assert len(bigip_proxy._nodes) == len(test_nodes) for n in test_nodes: assert bigip_proxy._nodes[n.name] == n
def test_ipv4_destination(): """Test Virtual Server destination.""" virtual = VirtualServer(default_route_domain=2, **cfg_test) assert virtual destination = virtual.destination assert destination assert destination[0] == "/Test/1.2.3.4%2:80" assert destination[1] == "Test" assert destination[2] == "1.2.3.4%2" assert destination[3] == "80" cfg = copy(cfg_test) cfg['destination'] = "/Test/1.2.3.4%2:80" virtual = VirtualServer(default_route_domain=2, **cfg) destination = virtual.destination assert destination[0] == "/Test/1.2.3.4%2:80" assert destination[1] == "Test" assert destination[2] == "1.2.3.4%2" assert destination[3] == "80" cfg = copy(cfg_test) cfg['destination'] = "/Test/my_virtual_addr%2:80" virtual = VirtualServer(default_route_domain=2, **cfg) destination = virtual.destination assert destination[0] == "/Test/my_virtual_addr%2:80" assert destination[1] == "Test" assert destination[2] == "my_virtual_addr%2" assert destination[3] == "80" cfg = copy(cfg_test) cfg['destination'] = "/Test_1/my_virtual_addr%2:80" virtual = VirtualServer(default_route_domain=2, **cfg) destination = virtual.destination assert destination[0] == "/Test_1/my_virtual_addr%2:80" assert destination[1] == "Test_1" assert destination[2] == "my_virtual_addr%2" assert destination[3] == "80" cfg = copy(cfg_test) cfg['destination'] = "/Test-1/my_virtual_addr%2:80" virtual = VirtualServer(default_route_domain=2, **cfg) destination = virtual.destination assert destination[0] == "/Test-1/my_virtual_addr%2:80" assert destination[1] == "Test-1" assert destination[2] == "my_virtual_addr%2" assert destination[3] == "80" cfg = copy(cfg_test) cfg['destination'] = "/Test.1/my_virtual_addr%2:80" virtual = VirtualServer(default_route_domain=2, **cfg) destination = virtual.destination assert destination[0] == "/Test.1/my_virtual_addr%2:80" assert destination[1] == "Test.1" assert destination[2] == "my_virtual_addr%2" assert destination[3] == "80"