Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
 def test_get_endpoint_exists(self):
     """
     Test get_endpoint() for an endpoint that exists.
     """
     ep = Endpoint(TEST_ENDPOINT_ID, "active", "11-22-33-44-55-66",
                   if_name="eth1")
     self.etcd_client.read.side_effect = mock_read_for_endpoint(ep)
     ep2 = self.datastore.get_endpoint(TEST_HOST,
                                       TEST_CONT_ID,
                                       TEST_ENDPOINT_ID)
     assert_equal(ep.to_json(), ep2.to_json())
     assert_equal(ep.ep_id, ep2.ep_id)