def __create_stubs(scenario, data): """ Stub out VMGroups, Workloads, and Results in a scenario. Allows testing _parse_steps without calling _parse_section so they can be tested more independently. Args: scenario (Scenario): Scenario to modify. data (dict): Configuration object. Returns: None """ scenario.vm_groups = {} for vm_group in data.get("vms", []): vm_group_name = vm_group.keys()[0] scenario.vm_groups[vm_group_name] = VMGroup(scenario, vm_group_name) scenario.workloads = {} for workload in data.get("workloads", []): workload_name = workload.keys()[0] vm_group_name = workload.values()[0]["vm_group"] scenario.workloads[workload_name] = Workload(scenario, workload_name, vm_group_name) scenario.results_map = {} for result in data.get("results", []): result_name = result.keys()[0] scenario.results_map[result_name] = BaseResult(scenario, result_name)
def test_workload_prefill_default(self): workload = Workload.parse(self.scenario, "test_workload1", {"vm_group": "group_0", "config_file": "oltp.fio"}) with mock.patch.object(workload, "_config_class") as mock_fio_config: mock_config_instance = mock.Mock(spec=FioConfiguration) mock_fio_config.load.return_value = mock_config_instance workload.prefill_iogen() self.assertEqual(mock_fio_config.load.call_count, 1) mock_config_instance.convert_prefill.assert_called_once_with()
def test_workload_prefill_concurrent_4_node_limited_by_parameter(self): workload = Workload.parse(self.scenario, "test_workload1", {"vm_group": "group_0", "config_file": "oltp.fio"}) with mock.patch.object(workload, "_config_class") as mock_fio_config: mock_config_instance = mock.Mock(spec=FioConfiguration) mock_fio_config.load.return_value = mock_config_instance workload.prefill_iogen(max_concurrent=2) self.assertEqual(mock_fio_config.load.call_count, 1) # Only 2 concurrent but each has own node, so iodepth is 4. mock_config_instance.convert_prefill.assert_called_once_with(iodepth=4)
def test_workload_prefill_concurrent_4_node(self): workload = Workload.parse(self.scenario, "test_workload1", {"vm_group": "group_0", "config_file": "oltp.fio"}) with mock.patch.object(workload, "_config_class") as mock_fio_config: mock_config_instance = mock.Mock(spec=FioConfiguration) mock_fio_config.load.return_value = mock_config_instance workload.prefill_iogen(max_concurrent=8) self.assertEqual(mock_fio_config.load.call_count, 1) # There are 4 nodes and 4 VMs, iodepth is 4. mock_config_instance.convert_prefill.assert_called_once_with(iodepth=4)
def test_PrefillRun_default(self): vmgroup = VMGroup(self.scenario, self.group_name, template="ubuntu1604", template_type="DISK", count_per_cluster=1, data_disks=[16, 16, 16, 16, 16, 16]) workload = Workload(test=self.scenario, name=self.workload_name, vm_group=vmgroup, generator="fio", config_file=self.valid_fio_path) self.scenario.vm_groups = {self.group_name: vmgroup} self.scenario.workloads = {self.workload_name: workload} steps.vm_group.CloneFromTemplate(self.scenario, self.group_name)() steps.vm_group.PowerOn(self.scenario, self.group_name)() steps.workload.PrefillRun(self.scenario, self.workload_name)()
def test_prefill_invalid_fio_path(self): vmgroup = VMGroup(self.scenario, self.group_name, template="ubuntu1604", template_type="DISK", count_per_cluster=1, data_disks=[16, 16, 16, 16, 16, 16]) workload = Workload(test=self.scenario, name=self.workload_name, vm_group=vmgroup, generator="fio", config_file=self.invalid_fio_path) self.scenario.vm_groups = {self.group_name: vmgroup} self.scenario.workloads = {self.workload_name: workload} steps.vm_group.CloneFromTemplate(self.scenario, self.group_name)() steps.vm_group.PowerOn(self.scenario, self.group_name)() with self.assertRaises(CurieTestException): steps.workload.PrefillStart(self.scenario, self.workload_name)()
def test_wait_after_finish(self): vmgroup = VMGroup(self.scenario, self.group_name, template="ubuntu1604", template_type="DISK", count_per_cluster=1, data_disks=[16, 16, 16, 16, 16, 16]) workload = Workload(test=self.scenario, name=self.workload_name, vm_group=vmgroup, generator="fio", config_file=self.valid_fio_path) self.scenario.vm_groups = {self.group_name: vmgroup} self.scenario.workloads = {self.workload_name: workload} steps.vm_group.CloneFromTemplate(self.scenario, self.group_name)() steps.vm_group.PowerOn(self.scenario, self.group_name)() duration_secs = 30 steps.workload.Start(self.scenario, self.workload_name, duration_secs)() steps.workload.Wait(self.scenario, self.workload_name)()
def test_workload_prefill_concurrent_2_node_limited_by_4_vms(self): self.cluster.nodes.return_value = self.nodes[:2] self.cluster.node_count.return_value = len(self.cluster.nodes()) self.vm_group = VMGroup(self.scenario, "group_0", count_per_cluster=4) self.scenario.vm_groups = {self.vm_group._name: self.vm_group} workload = Workload.parse(self.scenario, "test_workload1", {"vm_group": "group_0", "config_file": "oltp.fio"}) with mock.patch.object(workload, "_config_class") as mock_fio_config: mock_config_instance = mock.Mock(spec=FioConfiguration) mock_fio_config.load.return_value = mock_config_instance workload.prefill_iogen(max_concurrent=8) self.assertEqual(mock_fio_config.load.call_count, 1) # There are 2 nodes and 4 VMs, iodepth is 2. mock_config_instance.convert_prefill.assert_called_once_with(iodepth=2)
def test_Stop(self): vmgroup = VMGroup(self.scenario, self.group_name, template="ubuntu1604", template_type="DISK", count_per_cluster=1, data_disks=[16, 16, 16, 16, 16, 16]) workload = Workload(test=self.scenario, name=self.workload_name, vm_group=vmgroup, generator="fio", config_file=self.valid_fio_path) self.scenario.vm_groups = {self.group_name: vmgroup} self.scenario.workloads = {self.workload_name: workload} steps.vm_group.CloneFromTemplate(self.scenario, self.group_name)() steps.vm_group.PowerOn(self.scenario, self.group_name)() duration_secs = 600 start_secs = time.time() steps.workload.Start(self.scenario, self.workload_name, duration_secs, async=True)() time.sleep(30) steps.workload.Stop(self.scenario, self.workload_name, duration_secs)() total_secs = time.time() - start_secs self.assertTrue(total_secs < duration_secs)
def test_wait_after_stop_test(self): vmgroup = VMGroup(self.scenario, self.group_name, template="ubuntu1604", template_type="DISK", count_per_cluster=1, data_disks=[16, 16, 16, 16, 16, 16]) workload = Workload(test=self.scenario, name=self.workload_name, vm_group=vmgroup, generator="fio", config_file=self.valid_fio_path) self.scenario.vm_groups = {self.group_name: vmgroup} self.scenario.workloads = {self.workload_name: workload} steps.vm_group.CloneFromTemplate(self.scenario, self.group_name)() steps.vm_group.PowerOn(self.scenario, self.group_name)() duration_secs = 120 # Set should_stop to return False for 15 seconds, and True after that. self.scenario.should_stop = util.return_until(False, True, duration_secs / 8) start_secs = time.time() steps.workload.Start(self.scenario, self.workload_name, duration_secs)() total_secs = time.time() - start_secs self.assertTrue(total_secs < duration_secs)