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
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
def test_add_meta_port_protocol_exception(default_device: Machine): with pytest.raises(MachineOptionError): default_device.add_meta("port", "8080/ppp")
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
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
def test_add_meta_port_only_guest(default_device: Machine): default_device.add_meta("port", "8080") assert default_device.meta['ports'][(3000, "tcp")] == 8080
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"
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)
def test_get_image(): kwargs = {'image': 'kathara/frr'} device = Machine(Lab("test_lab"), "test_machine", **kwargs) assert device.get_image() == "kathara/frr"
def test_get_mem_default(default_device: Machine): assert default_device.get_mem() is None
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"
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()
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()
def default_device(): return Machine(Lab("test_lab"), "test_machine")
def test_get_mem_from_device_meta(): kwargs = {"mem": "200m"} device = Machine(Lab("test_lab"), "test_machine", **kwargs) assert device.get_mem() == "200m"
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"
def test_get_cpu_default(default_device: Machine): assert default_device.get_cpu() is None
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"))
def test_get_cpu_from_device_meta(): kwargs = {"cpus": "1"} device = Machine(Lab("test_lab"), "test_machine", **kwargs) assert device.get_cpu() == 1
def test_add_meta_sysctl_not_format_exception(default_device: Machine): with pytest.raises(MachineOptionError): default_device.add_meta("sysctl", "kernel.shm_rmid_forced")
def test_get_num_terms_default(default_device: Machine): assert default_device.get_num_terms() == 1
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
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
def test_add_meta_port_format_exception(default_device: Machine): with pytest.raises(MachineOptionError): default_device.add_meta("port", ":2000")
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