예제 #1
0
    def _test_method(self, method, m_add_handler, m_del_handler, m_cni_pipe,
                     m_watcher_class):
        self.passed_handler = None

        def _save_handler(params, handler):
            self.passed_handler = handler

        def _call_handler(*args):
            self.passed_handler(mock.sentinel.vif)

        m_add_handler.side_effect = _save_handler
        m_del_handler.side_effect = _save_handler

        m_watcher = mock.MagicMock(
            add=mock.MagicMock(),
            start=mock.MagicMock(side_effect=_call_handler))
        m_watcher_class.return_value = m_watcher

        m_params = mock.MagicMock()
        m_params.args.K8S_POD_NAMESPACE = 'k8s_pod_namespace'
        m_params.args.K8S_POD_NAME = 'k8s_pod'

        cni_plugin = k8s_cni.K8sCNIPlugin()
        result = getattr(cni_plugin, method)(m_params)
        self.assertEqual(mock.sentinel.vif, cni_plugin._vif)
        m_watcher.add.assert_called_with(
            "%(base)s/namespaces/%(namespace)s/pods"
            "?fieldSelector=metadata.name=%(pod)s" % {
                'base': constants.K8S_API_BASE,
                'namespace': m_params.args.K8S_POD_NAMESPACE,
                'pod': m_params.args.K8S_POD_NAME})

        return result
예제 #2
0
def run():
    # REVISIT(ivc): current CNI implementation provided by this package is
    # experimental and its primary purpose is to enable development of other
    # components (e.g. functional tests, service/LBaaSv2 support)
    cni_conf = utils.CNIConfig(jsonutils.load(sys.stdin))
    args = ['--config-file', cni_conf.kuryr_conf]

    try:
        if cni_conf.debug:
            args.append('-d')
    except AttributeError:
        pass
    config.init(args)
    config.setup_logging()

    # Initialize o.vo registry.
    k_objects.register_locally_defined_vifs()
    os_vif.initialize()

    if CONF.cni_daemon.daemon_enabled:
        runner = cni_api.CNIDaemonizedRunner()
    else:
        # TODO(dulek): Switch that to versionutils.deprecation_warning once
        #              bug 1754087 is fixed.
        versionutils.report_deprecated_feature(
            LOG,
            'Deploying kuryr-kubernetes without kuryr-daemon service is '
            'deprecated since Rocky release and may be removed in future '
            'releases.')
        runner = cni_api.CNIStandaloneRunner(k8s_cni.K8sCNIPlugin())
    LOG.info("Using '%s' ", runner.__class__.__name__)

    def _timeout(signum, frame):
        runner._write_dict(sys.stdout, {
            'msg': 'timeout',
            'code': k_const.CNI_TIMEOUT_CODE,
        })
        LOG.debug('timed out')
        sys.exit(1)

    signal.signal(signal.SIGALRM, _timeout)
    signal.alarm(_CNI_TIMEOUT)
    status = runner.run(os.environ, cni_conf, sys.stdout)
    LOG.debug("Exiting with status %s", status)
    if status:
        sys.exit(status)
예제 #3
0
def run():
    if six.PY3:
        d = jsonutils.load(sys.stdin.buffer)
    else:
        d = jsonutils.load(sys.stdin)
    cni_conf = utils.CNIConfig(d)
    args = ['--config-file', cni_conf.kuryr_conf]

    try:
        if cni_conf.debug:
            args.append('-d')
    except AttributeError:
        pass
    config.init(args)
    config.setup_logging()

    # Initialize o.vo registry.
    k_objects.register_locally_defined_vifs()
    os_vif.initialize()

    if CONF.cni_daemon.daemon_enabled:
        runner = cni_api.CNIDaemonizedRunner()
    else:
        LOG.warning('Deploying kuryr-kubernetes without kuryr-daemon service',
                    'R')
        runner = cni_api.CNIStandaloneRunner(k8s_cni.K8sCNIPlugin())
    LOG.info("Using '%s' ", runner.__class__.__name__)

    def _timeout(signum, frame):
        runner._write_dict(sys.stdout, {
            'msg': 'timeout',
            'code': k_const.CNI_TIMEOUT_CODE,
        })
        LOG.debug('timed out')
        sys.exit(1)

    signal.signal(signal.SIGALRM, _timeout)
    signal.alarm(_CNI_TIMEOUT)
    status = runner.run(os.environ, cni_conf, sys.stdout)
    LOG.debug("Exiting with status %s", status)
    if status:
        sys.exit(status)
예제 #4
0
 def setUp(self):
     super(TestCNIStandaloneRunner, self).setUp()
     self.runner = api.CNIStandaloneRunner(k8s_cni.K8sCNIPlugin())