Пример #1
0
def test_handle_openshift_sdn_config(request):
    handler = None
    try:
        bigip = MockBigIp()
        config_template = Template('/tmp/config.$pid')
        config_file = config_template.substitute(pid=os.getpid())

        handler = bigipconfigdriver.ConfigHandler(config_file, bigip, 0)

        obj = {}
        obj['openshift-sdn'] = {
            'vxlan-name': 'vxlan0',
            'vxlan-node-ips': ['198.162.0.1', '198.162.0.2']
        }

        with open(config_file, 'w+') as f:

            def fin():
                os.unlink(config_file)

            request.addfinalizer(fin)
            json.dump(obj, f)

        r = bigipconfigdriver._parse_config(config_file)
        try:
            bigipconfigdriver._handle_openshift_sdn_config(r)
        except:
            assert 0

    finally:
        assert handler is not None

        handler.stop()
        handler._thread.join(30)
        assert handler._thread.is_alive() is False
Пример #2
0
def test_handle_openshift_sdn_config_missing_vxlan_node_ips(request):
    handler = None
    try:
        bigip = MockBigIp()
        config_template = Template('/tmp/config.$pid')
        config_file = config_template.substitute(pid=os.getpid())

        handler = bigipconfigdriver.ConfigHandler(config_file, bigip, 0)

        obj = {}
        obj['openshift-sdn'] = {'vxlan-name': 'vxlan0'}

        with open(config_file, 'w+') as f:

            def fin():
                os.unlink(config_file)

            request.addfinalizer(fin)
            json.dump(obj, f)

        r = bigipconfigdriver._parse_config(config_file)
        with pytest.raises(bigipconfigdriver.ConfigError):
            bigipconfigdriver._handle_openshift_sdn_config(r)
    finally:
        assert handler is not None

        handler.stop()
        handler._thread.join(30)
        assert handler._thread.is_alive() is False
Пример #3
0
def test_handle_bigip_config_missing_partitions(request):
    handler = None
    try:
        bigip = MockBigIp()
        config_template = Template('/tmp/config.$pid')
        config_file = config_template.substitute(pid=os.getpid())

        handler = bigipconfigdriver.ConfigHandler(config_file, bigip, 0)

        obj = {}
        obj['bigip'] = {
            'username': '******',
            'password': '******',
            'url': 'http://10.10.10.10:443',
            'partitions': []
        }

        with open(config_file, 'w+') as f:

            def fin():
                os.unlink(config_file)

            request.addfinalizer(fin)
            json.dump(obj, f)

        r = bigipconfigdriver._parse_config(config_file)
        with pytest.raises(bigipconfigdriver.ConfigError):
            bigipconfigdriver._handle_bigip_config(r)
    finally:
        assert handler is not None

        handler.stop()
        handler._thread.join(30)
        assert handler._thread.is_alive() is False
Пример #4
0
def test_handle_global_config_string_verify_interval(request):
    handler = None
    try:
        bigip = MockBigIp()
        config_template = Template('/tmp/config.$pid')
        config_file = config_template.substitute(pid=os.getpid())

        handler = bigipconfigdriver.ConfigHandler(config_file, bigip, 0)

        obj = {"global": {"log-level": "ERROR", "verify-interval": "hundred"}}

        with open(config_file, 'w+') as f:

            def fin():
                os.unlink(config_file)

            request.addfinalizer(fin)
            json.dump(obj, f)

        r = bigipconfigdriver._parse_config(config_file)
        verify_interval, level = bigipconfigdriver._handle_global_config(r)
        assert verify_interval == bigipconfigdriver.DEFAULT_VERIFY_INTERVAL
        assert level == logging.ERROR

    finally:
        assert handler is not None

        handler.stop()
        handler._thread.join(30)
        assert handler._thread.is_alive() is False
Пример #5
0
def test_handle_global_config_number_log_level(request):
    handler = None
    try:
        bigip = MockBigIp()
        config_template = Template('/tmp/config.$pid')
        config_file = config_template.substitute(pid=os.getpid())

        handler = bigipconfigdriver.ConfigHandler(config_file, bigip, 0)

        obj = {"global": {"log-level": 55, "verify-interval": 100}}

        with open(config_file, 'w+') as f:

            def fin():
                os.unlink(config_file)

            request.addfinalizer(fin)
            json.dump(obj, f)

        r = bigipconfigdriver._parse_config(config_file)
        verify_interval, level = bigipconfigdriver._handle_global_config(r)
        assert verify_interval == 100
        assert level == bigipconfigdriver.DEFAULT_LOG_LEVEL

    finally:
        assert handler is not None

        handler.stop()
        handler._thread.join(30)
        assert handler._thread.is_alive() is False
Пример #6
0
def test_handle_global_config(request):
    handler = None
    try:
        bigip = MockBigIp()
        config_template = Template('/tmp/config.$pid')
        config_file = config_template.substitute(pid=os.getpid())

        handler = bigipconfigdriver.ConfigHandler(config_file, bigip, 0)

        obj = {}
        obj['global'] = {'log-level': 'WARNING', 'verify-interval': 10}

        with open(config_file, 'w+') as f:

            def fin():
                os.unlink(config_file)

            request.addfinalizer(fin)
            json.dump(obj, f)

        r = bigipconfigdriver._parse_config(config_file)
        verify_interval, level = bigipconfigdriver._handle_global_config(r)
        assert verify_interval == 10
        assert level == logging.WARNING

    finally:
        assert handler is not None

        handler.stop()
        handler._thread.join(30)
        assert handler._thread.is_alive() is False
Пример #7
0
def test_parse_config(request):
    handler = None
    try:
        bigip = MockBigIp()
        config_template = Template('/tmp/config.$pid')
        config_file = config_template.substitute(pid=os.getpid())

        handler = bigipconfigdriver.ConfigHandler(config_file, bigip, 0)

        r = bigipconfigdriver._parse_config(config_file)
        assert r is None

        obj = {}
        obj['field1'] = 'one'
        obj['field_string'] = 'string'
        obj['field_number'] = 10

        with open(config_file, 'w+') as f:

            def fin():
                os.unlink(config_file)

            request.addfinalizer(fin)
            json.dump(obj, f)

        r = bigipconfigdriver._parse_config(config_file)
        assert r is not None
        assert r['field1'] == obj['field1']
        assert r['field_string'] == obj['field_string']
        assert r['field_number'] == obj['field_number']
    finally:
        assert handler is not None

        handler.stop()
        handler._thread.join(30)
        assert handler._thread.is_alive() is False