示例#1
0
def test_get_num_terms_mix():
    # Lab options have a greater priority than machine options
    lab = Lab('mem_test')
    lab.add_option("num_terms", "2")
    kwargs = {"num_terms": "1"}
    device1 = Machine(lab, "test_machine1", **kwargs)
    device2 = Machine(lab, "test_machine2")
    assert device1.get_num_terms() == 2
    assert device2.get_num_terms() == 2
示例#2
0
def test_get_num_terms_from_device_meta():
    kwargs = {"num_terms": "1"}
    device = Machine(Lab("test_lab"), "test_machine", **kwargs)
    assert device.get_num_terms() == 1
示例#3
0
def test_add_meta_port_protocol_exception(default_device: Machine):
    with pytest.raises(MachineOptionError):
        default_device.add_meta("port", "8080/ppp")
示例#4
0
def default_device(mock_docker_container):
    device = Machine(Lab('Default scenario'), "test_device")
    device.add_meta("exec", "ls")
    device.add_meta("mem", "64m")
    device.add_meta("cpus", "2")
    device.add_meta("image", "kathara/test")
    device.add_meta("bridged", False)
    device.api_object = mock_docker_container
    return device
示例#5
0
def test_add_meta_sysctl(default_device: Machine):
    default_device.add_meta("sysctl", "net.ipv4.tcp_syncookies=1")
    assert default_device.meta['sysctls']['net.ipv4.tcp_syncookies'] == 1
示例#6
0
def test_add_meta_port_only_guest(default_device: Machine):
    default_device.add_meta("port", "8080")
    assert default_device.meta['ports'][(3000, "tcp")] == 8080
示例#7
0
def test_get_mem_from_lab_options():
    lab = Lab('mem_test')
    lab.add_option("mem", "150m")
    device = Machine(lab, "test_machine")
    assert device.get_mem() == "150m"
示例#8
0
def test_add_interface_exception(default_device: Machine):
    default_device.add_interface(Link(default_device.lab, "A"))
    with pytest.raises(Exception):
        default_device.add_interface(Link(default_device.lab, "B"), number=0)
示例#9
0
def test_get_image():
    kwargs = {'image': 'kathara/frr'}
    device = Machine(Lab("test_lab"), "test_machine", **kwargs)
    assert device.get_image() == "kathara/frr"
示例#10
0
def test_get_mem_default(default_device: Machine):
    assert default_device.get_mem() is None
示例#11
0
def test_get_image_default(mock_setting_get_instance, default_device: Machine):
    setting_mock = Mock()
    setting_mock.configure_mock(**{'image': "kathara/frr"})
    mock_setting_get_instance.return_value = setting_mock

    assert default_device.get_image() == "kathara/frr"
示例#12
0
def test_check_exception(default_device: Machine):
    default_device.add_interface(Link(default_device.lab, "A"), number=2)
    default_device.add_interface(Link(default_device.lab, "B"), number=4)
    with pytest.raises(NonSequentialMachineInterfaceError):
        default_device.check()
示例#13
0
def test_check(default_device: Machine):
    default_device.add_interface(Link(default_device.lab, "A"), number=0)
    default_device.add_interface(Link(default_device.lab, "B"), number=1)
    default_device.check()
示例#14
0
def default_device():
    return Machine(Lab("test_lab"), "test_machine")
示例#15
0
def test_get_mem_from_device_meta():
    kwargs = {"mem": "200m"}
    device = Machine(Lab("test_lab"), "test_machine", **kwargs)
    assert device.get_mem() == "200m"
示例#16
0
def test_add_interface(default_device: Machine):
    default_device.add_interface(Link(default_device.lab, "A"))
    assert len(default_device.interfaces) == 1
    assert default_device.interfaces[0].name == "A"
示例#17
0
def test_get_cpu_default(default_device: Machine):
    assert default_device.get_cpu() is None
示例#18
0
def test_add_two_interfaces_on_same_cd(default_device: Machine):
    default_device.add_interface(Link(default_device.lab, "A"))
    with pytest.raises(MachineCollisionDomainConflictError):
        default_device.add_interface(Link(default_device.lab, "A"))
示例#19
0
def test_get_cpu_from_device_meta():
    kwargs = {"cpus": "1"}
    device = Machine(Lab("test_lab"), "test_machine", **kwargs)
    assert device.get_cpu() == 1
示例#20
0
def test_add_meta_sysctl_not_format_exception(default_device: Machine):
    with pytest.raises(MachineOptionError):
        default_device.add_meta("sysctl", "kernel.shm_rmid_forced")
示例#21
0
def test_get_num_terms_default(default_device: Machine):
    assert default_device.get_num_terms() == 1
示例#22
0
def test_add_meta_port_host_guest_protocol(default_device: Machine):
    default_device.add_meta("port", "2000:8080/udp")
    assert default_device.meta['ports'][(2000, "udp")] == 8080
示例#23
0
def test_get_num_terms_from_lab_options():
    lab = Lab('mem_test')
    lab.add_option("num_terms", "2")
    device = Machine(lab, "test_machine")
    assert device.get_num_terms() == 2
示例#24
0
def test_add_meta_port_format_exception(default_device: Machine):
    with pytest.raises(MachineOptionError):
        default_device.add_meta("port", ":2000")
示例#25
0
def default_device(mock_kubernetes_deployment):
    device = Machine(Lab("default_scenario"), "test_device")
    device.add_meta("exec", "ls")
    device.add_meta("mem", "64m")
    device.add_meta("cpus", "2")
    device.add_meta("image", "kathara/test")
    device.add_meta("bridged", False)
    device.add_meta('real_name', "devprefix-test-device-ec84ad3b")

    device.api_object = mock_kubernetes_deployment

    return device