def test_to_json(self): """ Test to_json() method. """ endpoint1 = Endpoint("aabbccddeeff112233", "active", "11-22-33-44-55-66", if_name="eth0") assert_equal(endpoint1.ep_id, "aabbccddeeff112233") assert_equal(endpoint1.state, "active") assert_equal(endpoint1.mac, "11-22-33-44-55-66") assert_equal(endpoint1.profile_id, None) expected = {"state": "active", "name": "caliaabbccddeef", "mac": "11-22-33-44-55-66", "container:if_name": "eth0", "profile_id": None, "ipv4_nets": [], "ipv6_nets": [], "ipv4_gateway": None, "ipv6_gateway": None} assert_dict_equal(json.loads(endpoint1.to_json()), expected) endpoint1.profile_id = "TEST12" endpoint1.ipv4_nets.add(IPNetwork("192.168.1.23/32")) endpoint1.ipv4_gateway = IPAddress("192.168.1.1") expected["profile_id"] = "TEST12" expected["ipv4_nets"] = ["192.168.1.23/32"] expected["ipv4_gateway"] = "192.168.1.1" assert_dict_equal(json.loads(endpoint1.to_json()), expected)
IPV6_POOLS_PATH = CALICO_V_PATH + "/ipam/v6/pool/" BGP_PEERS_PATH = CALICO_V_PATH + "/config/bgp_peer_rr_v4/" TEST_PROFILE_PATH = CALICO_V_PATH + "/policy/profile/TEST/" ALL_PROFILES_PATH = CALICO_V_PATH + "/policy/profile/" ALL_ENDPOINTS_PATH = CALICO_V_PATH + "/host/" ALL_HOSTS_PATH = CALICO_V_PATH + "/host/" TEST_ENDPOINT_PATH = CALICO_V_PATH + "/host/TEST_HOST/workload/docker/1234/" \ "endpoint/1234567890ab" TEST_CONT_ENDPOINT_PATH = CALICO_V_PATH + "/host/TEST_HOST/workload/docker/" \ "1234/endpoint/" TEST_CONT_PATH = CALICO_V_PATH + "/host/TEST_HOST/workload/docker/1234/" CONFIG_PATH = CALICO_V_PATH + "/config/" # 4 endpoints, with 2 TEST profile and 2 UNIT profile. EP_56 = Endpoint("567890abcdef", "active", "AA-22-BB-44-CC-66", if_name="eth0") EP_56.profile_id = "TEST" EP_78 = Endpoint("7890abcdef12", "active", "11-AA-33-BB-55-CC", if_name="eth0") EP_78.profile_id = "TEST" EP_90 = Endpoint("90abcdef1234", "active", "1A-2B-3C-4D-5E-6E", if_name="eth0") EP_90.profile_id = "UNIT" EP_12 = Endpoint(TEST_ENDPOINT_ID, "active", "11-22-33-44-55-66", if_name="eth0") EP_12.profile_id = "UNIT" # A complicated set of Rules JSON for testing serialization / deserialization. RULES_JSON = """ { "id": "PROF_GROUP1", "inbound_rules": [ { "action": "allow",