def test_zero_delays(self): zero_delay_spec = DelaySpec({"delay_ms": 0, "jitter_ms": 0}) node = DelayNode() node.add("fake_ip_str_1", zero_delay_spec) node.add("fake_ip_str_2", zero_delay_spec) node.add("fake_ip_str_3", zero_delay_spec) expected = [] actual = node.generate_delay_commands() self.assertEqual(len(actual), len(expected)) for i, expect in enumerate(expected): self.assertEqual(actual[i].command, expect)
def parse_cluster(self): """Create cluster for each topology and delay""" inf_prov_out = self.config["infrastructure_provisioning"] client_config = inf_prov_out["out"]["workload_client"][0] client_ip = client_config["private_ip"] DelayGraph.client_ip = client_ip topologies = self.mongodb_setup.get("topology", []) network_delays = self.mongodb_setup.get("network_delays", {}) delay_configs = network_delays.get("clusters", []) version_flag = str_to_version_flag( network_delays.get("version_flag", "default")) DelayGraph.client_node = DelayNode(version_flag) delays = DelayGraph.from_topologies(topologies, delay_configs, version_flag) client_config = ClientConfig(self.config) self.client = Client(client_config) # pylint: disable=consider-using-enumerate for i in range(len(topologies)): self.clusters.append( mongodb_cluster.create_cluster(topologies[i], delays[i], self.config))
def test_establish_delays_runs_commands(self): mocked_host = MagicMock() mocked_host.run = MagicMock() mocked_host.run.return_value = True nonzero_delay_spec_1 = DelaySpec({"delay_ms": 700, "jitter_ms": 10}) nonzero_delay_spec_2 = DelaySpec({"delay_ms": 300, "jitter_ms": 0}) delay = DelayNode() delay.add("fake_ip_1", nonzero_delay_spec_1) delay.add("fake_ip_2", nonzero_delay_spec_2) delay.reset_delays(mocked_host) delay.establish_delays(mocked_host) expected_calls = [ call(["bash", "-c", '\'uname -r | cut -d "." -f 1 | grep -q "4"\'']), call( [ "bash", "-c", '\'yum info iproute | grep "Version" | cut -d ":" -f 2 | cut -d " " -f 2 | cut -d "." -f 1 | grep -q "4"\'', ] ), call(["bash", "-c", "'sudo tc qdisc del dev eth0 root'"]), call(["bash", "-c", "'sudo tc qdisc add dev eth0 root handle 1: htb default 1'"]), call( [ "bash", "-c", "'sudo tc class add dev eth0 parent 1: classid 1:1 htb rate 100tbit prio 0'", ] ), call( [ "bash", "-c", "'sudo tc class add dev eth0 parent 1: classid 1:2 htb rate 100tbit prio 0'", ] ), call(["bash", "-c", "'sudo tc qdisc add dev eth0 parent 1:2 netem delay 700ms 10ms'"]), call( [ "bash", "-c", "'sudo tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip dst fake_ip_1 flowid 1:2'", ] ), call( [ "bash", "-c", "'sudo tc class add dev eth0 parent 1: classid 1:3 htb rate 100tbit prio 0'", ] ), call(["bash", "-c", "'sudo tc qdisc add dev eth0 parent 1:3 netem delay 300ms 0ms'"]), call( [ "bash", "-c", "'sudo tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip dst fake_ip_2 flowid 1:3'", ] ), ] self.assertEqual(mocked_host.run.call_count, len(expected_calls)) mocked_host.run.assert_has_calls(expected_calls)
def test_differing_delays(self): nonzero_delay_spec_1 = DelaySpec({"delay_ms": 200, "jitter_ms": 30}) nonzero_delay_spec_2 = DelaySpec({"delay_ms": 100, "jitter_ms": 5}) nonzero_delay_spec_3 = DelaySpec({"delay_ms": 500, "jitter_ms": 50}) nonzero_delay_spec_4 = DelaySpec({"delay_ms": 10, "jitter_ms": 0}) node = DelayNode() node.add("fake_ip_str_1", nonzero_delay_spec_1) node.add("fake_ip_str_2", nonzero_delay_spec_2) node.add("fake_ip_str_3", nonzero_delay_spec_3) node.add("fake_ip_str_4", nonzero_delay_spec_4) expected = [ ["bash", "-c", "'sudo tc qdisc add dev eth0 root handle 1: htb default 1'"], [ "bash", "-c", "'sudo tc class add dev eth0 parent 1: classid 1:1 htb rate 100tbit prio 0'", ], [ "bash", "-c", "'sudo tc class add dev eth0 parent 1: classid 1:2 htb rate 100tbit prio 0'", ], ["bash", "-c", "'sudo tc qdisc add dev eth0 parent 1:2 netem delay 200ms 30ms'"], [ "bash", "-c", "'sudo tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip dst fake_ip_str_1 flowid 1:2'", ], [ "bash", "-c", "'sudo tc class add dev eth0 parent 1: classid 1:3 htb rate 100tbit prio 0'", ], ["bash", "-c", "'sudo tc qdisc add dev eth0 parent 1:3 netem delay 100ms 5ms'"], [ "bash", "-c", "'sudo tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip dst fake_ip_str_2 flowid 1:3'", ], [ "bash", "-c", "'sudo tc class add dev eth0 parent 1: classid 1:4 htb rate 100tbit prio 0'", ], ["bash", "-c", "'sudo tc qdisc add dev eth0 parent 1:4 netem delay 500ms 50ms'"], [ "bash", "-c", "'sudo tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip dst fake_ip_str_3 flowid 1:4'", ], [ "bash", "-c", "'sudo tc class add dev eth0 parent 1: classid 1:5 htb rate 100tbit prio 0'", ], ["bash", "-c", "'sudo tc qdisc add dev eth0 parent 1:5 netem delay 10ms 0ms'"], [ "bash", "-c", "'sudo tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip dst fake_ip_str_4 flowid 1:5'", ], ] actual = node.generate_delay_commands() self.assertEqual(len(actual), len(expected)) for i, expect in enumerate(expected): self.assertEqual(actual[i].command, expect)