Beispiel #1
0
def load_config(filename,
                path="calico/felix/test/data/",
                env_dict=None,
                host_dict=None,
                global_dict=None):
    if env_dict is None:
        env_dict = {}
    if host_dict is None:
        host_dict = {}
    if global_dict is None:
        global_dict = {}

    global_dict.setdefault("InterfacePrefix", "tap")

    with mock.patch.dict("os.environ", env_dict):
        with mock.patch('calico.common.complete_logging'):
            config = Config()

    combined_dict = global_dict.copy()
    combined_dict.update(host_dict)

    with mock.patch('calico.common.complete_logging'):
        config.update_from(combined_dict)

    return config
Beispiel #2
0
def main():
    common.default_logging(gevent_in_use=False)

    # The parent process sends us communication pipes as FD 3 and 4. Open
    # those as files.  Wrap the resulting files in a FileObject to make
    # them cooperate with gevent.
    pipe_from_parent = os.fdopen(3, 'rb', -1)
    pipe_to_parent = os.fdopen(4, 'wb', -1)

    reader = MessageReader(pipe_from_parent)
    writer = MessageWriter(pipe_to_parent)

    config = Config()

    while True:
        for msg_type, msg, seq_no in reader.new_messages():
            _log.info("New %s message (#%s)", msg_type, seq_no)
            if msg_type == MSG_TYPE_CONFIG_UPDATE:
                config.update_from(msg.config)
            elif msg_type == MSG_TYPE_IPSET_DELTA:
                _log.info("IP set delta message: %s", msg)
            elif msg_type == MSG_TYPE_IPSET_REMOVED:
                _log.info("IP set removed message: %s", msg)
            elif msg_type == MSG_TYPE_IPSET_UPDATE:
                _log.info("IP set added message: %s", msg)
            elif msg_type == MSG_TYPE_WL_EP_UPDATE:
                _log.info("Workload endpoint update message: %s", msg)
            elif msg_type == MSG_TYPE_WL_EP_REMOVE:
                _log.info("Workload endpoint remove message: %s", msg)
            elif msg_type == MSG_TYPE_HOST_EP_UPDATE:
                _log.info("Host endpoint update message: %s", msg)
            elif msg_type == MSG_TYPE_HOST_EP_REMOVE:
                _log.info("Host endpoint update remove: %s", msg)
            elif msg_type == MSG_TYPE_HOST_METADATA_UPDATE:
                _log.info("Host endpoint update message: %s", msg)
            elif msg_type == MSG_TYPE_HOST_METADATA_REMOVE:
                _log.info("Host endpoint remove message: %s", msg)
            elif msg_type == MSG_TYPE_IPAM_POOL_UPDATE:
                _log.info("IPAM pool update messages:%s", msg)
            elif msg_type == MSG_TYPE_IPAM_POOL_REMOVE:
                _log.info("IPAM pool remove message: %s", msg)
            elif msg_type == MSG_TYPE_POLICY_UPDATE:
                _log.info("Policy update message: %s", msg)
            elif msg_type == MSG_TYPE_POLICY_REMOVED:
                _log.info("Policy update message: %s", msg)
            elif msg_type == MSG_TYPE_PROFILE_UPDATE:
                _log.info("Profile update message: %s", msg)
            elif msg_type == MSG_TYPE_PROFILE_REMOVED:
                _log.info("Profile update message: %s", msg)
            elif msg_type == MSG_TYPE_IN_SYNC:
                _log.info("In sync message: %s", msg)
            else:
                _log.error("Unexpected message %r %s", msg_type, msg)
Beispiel #3
0
    def test_default_ipset_size(self):
        """
        Test that ipset size is defaulted if out of range.
        """
        with mock.patch('calico.common.complete_logging'):
            config = Config("calico/felix/test/data/felix_missing.cfg")
        cfg_dict = {
            "InterfacePrefix": "blah",
            "MaxIpsetSize": "0",
        }
        with mock.patch('calico.common.complete_logging'):
            config.update_from({}, cfg_dict)

        self.assertEqual(config.MAX_IPSET_SIZE, 2**20)