def test_duration_secs_end_none(self, mock_time): scenario = Scenario() scenario._end_time_secs = None scenario._start_time_secs = 12345 mock_time.time.return_value = 12346 self.assertEqual(1, scenario.duration_secs())
def test_repr(self): scenario = Scenario() self.assertEqual( "<Scenario(name=None, display_name=None, id=%d, status=<Status.NOT_STARTED: 0>)>" % scenario.id, repr(scenario)) scenario = Scenario(name="fake_test") self.assertEqual( "<Scenario(name='fake_test', display_name='fake_test', id=%d, status=<Status.NOT_STARTED: 0>)>" % scenario.id, repr(scenario)) scenario = Scenario(name="fake_test", display_name="Fake Test") self.assertEqual( "<Scenario(name='fake_test', display_name='Fake Test', id=%d, status=<Status.NOT_STARTED: 0>)>" % scenario.id, repr(scenario))
def setUp(self): self.vm_group = mock.Mock(spec=VMGroup) self.vm_group.get_vms.return_value = [] self.cluster = mock.Mock(spec=Cluster) self.scenario = Scenario( cluster=self.cluster, output_directory=environment.test_output_dir(self))
def test_parse_section(self): scenario = Scenario() yaml_str = """ results: - OLTP: arg_0: apple - VDI: arg_0: banana arg_1: cantaloupe - Network Bandwidth: # Suppose this guy is disabled. arg_0: durian """ data = yaml.load(yaml_str) self.__create_stubs(scenario, data) mock_cls = mock.Mock() expected = ["return_value_0", "return_value_1", None] mock_cls.parse.side_effect = expected ret = scenario_parser._parse_section(scenario, data, "results", mock_cls) self.assertEqual(["OLTP", "VDI"], ret.keys()) self.assertEqual(expected[:2], ret.values()) mock_cls.parse.assert_has_calls([mock.call(scenario, "OLTP", {"arg_0": "apple"}), mock.call(scenario, "VDI", {"arg_0": "banana", "arg_1": "cantaloupe"}), mock.call(scenario, "Network Bandwidth", {"arg_0": "durian"}), ])
def test_parse_results(self): scenario = Scenario() yaml_str = """ vms: - OLTP: {} results: - IOPS: vm_group: OLTP result_type: iops result_hint: "Higher is better!" result_expected_value: 10 result_value_bands: - name: big band 0 upper: 1000 lower: 10 """ data = yaml.load(yaml_str) self.__create_stubs(scenario, data) parsed = scenario_parser._parse_section(scenario, data, "results", BaseResult) self.assertEqual(parsed["IOPS"].kwargs["result_hint"], "Higher is better!") self.assertEqual(parsed["IOPS"].kwargs["result_expected_value"], 10) self.assertEqual(parsed["IOPS"].kwargs["result_value_bands"], [{"name": "big band 0", "upper": 1000, "lower": 10}])
def setUp(self): self.cluster = mock.Mock(spec=Cluster) self.vms = [mock.Mock(spec=Vm) for _ in xrange(4)] self.scenario = Scenario( cluster=self.cluster, output_directory=environment.test_output_dir(self)) self.iogen = iogen.IOGen("test_iogen", self.scenario, "", "test_iogen")
def test_PrismHostsInSameCluster_missing(self, m_NutanixRestApiClient): self.cluster = mock_cluster(spec=NutanixVsphereCluster) self.scenario = Scenario( cluster=self.cluster, output_directory=environment.test_output_dir(self)) m_client = mock.Mock() m_client.host = "fake_prism_host" m_client.hosts_get.return_value = { "entities": [ {"hypervisorAddress": "169.254.0.0"}, {"hypervisorAddress": "169.254.0.1"}, # {"hypervisorAddress": "169.254.0.2"}, {"hypervisorAddress": "169.254.0.3"}, ] } m_NutanixRestApiClient.from_proto.return_value = m_client step = check.PrismHostInSameCluster(self.scenario, 2) with self.assertRaises(CurieTestException) as ar: step() self.assertEqual( "Cause: Node '2' with hypervisor address '169.254.0.2' is not a member " "of the Nutanix cluster managed at 'fake_prism_host'.\n\n" "Impact: The configured nodes belong to multiple Nutanix clusters, " "which is not supported.\n\n" "Corrective Action: Please choose a set of nodes that belong to a " "single Nutanix cluster. If the target is configured for metro " "availability, please choose nodes that all belong to a single site.\n\n" "Traceback: None", str(ar.exception))
def setUp(self): self.cluster = mock_cluster() self.scenario = Scenario( cluster=self.cluster, output_directory=environment.test_output_dir(self)) self.vm_group = VMGroup(self.scenario, "group_0") self.scenario.vm_groups = {self.vm_group._name: self.vm_group}
def setUp(self): self.cluster = mock.Mock(spec=Cluster) self.cluster.name.return_value = "Mock Cluster" self.vms = [mock.Mock(spec=Vm) for _ in xrange(4)] self.cluster.find_vms_regex.return_value = self.vms _nodes = [mock.Mock(spec=Node) for _ in xrange(4)] self.cluster_metadata = CurieSettings.Cluster() self.cluster_metadata.cluster_name = "mock_cluster" self.cluster_metadata.cluster_hypervisor_info.CopyFrom( CurieSettings.Cluster.ClusterHypervisorInfo()) self.cluster_metadata.cluster_management_server_info.CopyFrom( CurieSettings.Cluster.ClusterManagementServerInfo()) self.cluster_metadata.cluster_software_info.CopyFrom( CurieSettings.Cluster.ClusterSoftwareInfo()) for id, node in enumerate(_nodes): node.node_id.return_value = id curr_node = self.cluster_metadata.cluster_nodes.add() curr_node.id = str(id) self.cluster.metadata.return_value = self.cluster_metadata self.cluster.nodes.return_value = _nodes self.cluster.node_count.return_value = len(_nodes) self.scenario = Scenario( cluster=self.cluster, output_directory=environment.test_output_dir(self), goldimages_directory="/fake/goldimages/directory/") self.vm_group = VMGroup(self.scenario, "group_0.*[(-!&") for mock_vm, vm_name in zip(self.vms, self.vm_group.get_vms_names()): mock_vm.vm_name.return_value = vm_name self.scenario.vm_groups = {self.vm_group._name: self.vm_group}
def setUp(self): self.cluster = util.cluster_from_json(gflags.FLAGS.cluster_config_path) self.cluster.update_metadata(False) self.scenario = Scenario( cluster=self.cluster, output_directory=environment.test_output_dir(self), goldimages_directory=gflags.FLAGS.curie_vmdk_goldimages_dir)
def setUp(self): self.cluster = mock.Mock(spec=Cluster) proto_patch_encryption_support(CurieSettings) cluster_metadata = CurieSettings.Cluster() cluster_metadata.cluster_name = "MockCluster" self.nodes = [mock.Mock(spec=Node) for _ in xrange(4)] for id, node in enumerate(self.nodes): node.node_id.return_value = id node.node_index.return_value = id curr_node = cluster_metadata.cluster_nodes.add() curr_node.id = str(id) oob_info = curr_node.node_out_of_band_management_info oob_info.interface_type = oob_info.kIpmi oob_info.vendor = oob_info.kUnknownVendor oob_info.ip_address = "1.2.3.%d" % id oob_info.username = "******" oob_info.password = "******" self.cluster.nodes.return_value = self.nodes self.cluster.node_count.return_value = len(self.nodes) self.cluster.metadata.return_value = cluster_metadata self.scenario = Scenario( cluster=self.cluster, output_directory=environment.test_output_dir(self))
def test_scenario_target_config(self): scenario = Scenario(name="Fake Scenario") scenario.cluster = mock_cluster() scenario.cluster.name.return_value = "fake_cluster" vm_group = VMGroup(scenario, "nasty\nvg?nm /\t#$\\") mock_vms = [mock.Mock(spec=Vm) for _ in xrange(3)] mock_vms[0].vm_name.return_value = "mock_vm_0" mock_vms[1].vm_name.return_value = "mock_vm_1" mock_vms[2].vm_name.return_value = "mock_vm_2" mock_vms[0].vm_ip.return_value = "fake_addr_0" mock_vms[1].vm_ip.return_value = "fake_addr_1" mock_vms[2].vm_ip.return_value = None scenario.vm_groups = {"fake_vm_group": vm_group} with mock.patch.object(vm_group, "get_vms") as mock_get_vms: mock_get_vms.return_value = mock_vms ret = prometheus.scenario_target_config(scenario) expected = [ { "labels": { "cluster_name": "fake_cluster", "instance": "mock_vm_0", "job": "xray", "scenario_display_name": "Fake Scenario", "scenario_id": str(scenario.id), "scenario_name": "Fake Scenario", "vm_group": "nasty\nvg?nm /\t#$\\", }, "targets": [ "fake_addr_0:9100", ], }, { "labels": { "cluster_name": "fake_cluster", "instance": "mock_vm_1", "job": "xray", "scenario_display_name": "Fake Scenario", "scenario_id": str(scenario.id), "scenario_name": "Fake Scenario", "vm_group": "nasty\nvg?nm /\t#$\\", }, "targets": [ "fake_addr_1:9100", ], } ] self.assertEqual(ret, expected)
def test_from_path_packaged_scenarios_small_large_clusters(self): three_node_cluster = mock_cluster(3) one_hundred_twenty_eight_node_cluster = mock_cluster(128) for path in Scenario.find_configuration_files(): scenario_parser.from_path( path, cluster=three_node_cluster) scenario_parser.from_path( path, cluster=one_hundred_twenty_eight_node_cluster)
def test_from_path_packaged_scenarios(self): for path in Scenario.find_configuration_files(): scenario = scenario_parser.from_path(path) first_setup_step = scenario.steps[Phase.SETUP][0] self.assertIsInstance( first_setup_step, CleanUp, "The first step in the setup phase should be cluster.CleanUp " "(path: %s, found: %s)" % (path, first_setup_step))
def setUp(self): self.cluster = mock_cluster() vms = [mock.Mock(spec=Vm) for _ in xrange(4)] for index, vm in enumerate(vms): vm.vm_name.return_value = "fake_vm_%d" % index self.cluster.vms.return_value = vms self.scenario = Scenario( cluster=self.cluster, output_directory=environment.test_output_dir(self))
def setUp(self): self.cluster = util.cluster_from_json(gflags.FLAGS.cluster_config_path) self.cluster.update_metadata(False) assert isinstance(self.cluster, VsphereCluster), \ "This test must run on a vCenter cluster" self.scenario = Scenario( cluster=self.cluster, output_directory=environment.test_output_dir(self), goldimages_directory=gflags.FLAGS.curie_vmdk_goldimages_dir)
def test_VSphereDatastoreVisible_nodeid_is_hostname(self): self.cluster = mock_cluster(spec=VsphereCluster) self.scenario = Scenario( cluster=self.cluster, output_directory=environment.test_output_dir(self)) for index, cluster_node in enumerate(self.cluster.nodes()): cluster_node.node_id.return_value = "fake_node_%d.rtp.nutanix.com" % index step = check.VSphereDatastoreVisible(self.scenario, "fake_datastore_name", 0) step() self.scenario.cluster.datastore_visible.assert_called_once_with("fake_datastore_name", host_name="fake_node_0.rtp.nutanix.com")
def setUp(self): path = environment.test_output_dir(self) if os.path.isdir(path): shutil.rmtree(path) os.makedirs(path) self.scenario = Scenario(name="Fake Scenario") self.scenario.cluster = mock_cluster() self.scenario.output_directory = path self.mock_setup_step = mock.Mock(spec=BaseStep) self.mock_setup_step.description = "Some mock Setup thing" self.mock_setup_step.status = Status.NOT_STARTED self.mock_setup_step.requirements.return_value = set() self.mock_run_step = mock.Mock(spec=BaseStep) self.mock_run_step.description = "Some mock Run thing" self.mock_run_step.status = Status.NOT_STARTED self.mock_run_step.requirements.return_value = set() self.scenario.add_step(self.mock_setup_step, Phase.SETUP) self.scenario.add_step(self.mock_run_step, Phase.RUN) self.scenario._status = Status.EXECUTING
def setUp(self): self.cluster = util.cluster_from_json(gflags.FLAGS.cluster_config_path) self.cluster.update_metadata(False) self.scenario = Scenario( cluster=self.cluster, output_directory=environment.test_output_dir(self), goldimages_directory=gflags.FLAGS.curie_vmdk_goldimages_dir) self.group_name = "".join([ random.choice(string.printable) for _ in xrange(VMGroup.MAX_NAME_LENGTH) ])
def test_parse_steps_step_not_found(self): scenario = Scenario() yaml_str = """ setup: - vm_group.Invalid: {} """ data = yaml.load(yaml_str) self.__create_stubs(scenario, data) with self.assertRaises(ValueError) as ar: scenario_parser._parse_steps(scenario, data) self.assertIn("Step 'vm_group.Invalid' does not exist", str(ar.exception))
def setUp(self): self.iogen = mock.Mock(spec=IOGen) self.iogen.reporting_interval = 1 self.workload = mock.Mock(spec=Workload) self.workload.iogen.return_value = self.iogen vm_group = mock.Mock(spec=VMGroup) vm_group.get_vms.return_value = [] self.cluster = mock.Mock(spec=Cluster) self.scenario = Scenario( cluster=self.cluster, output_directory=environment.test_output_dir(self))
def setUp(self): self.cluster = util.cluster_from_json(gflags.FLAGS.cluster_config_path) self.cluster.update_metadata(False) self.scenario = Scenario( cluster=self.cluster, output_directory=environment.test_output_dir(self), goldimages_directory=gflags.FLAGS.curie_vmdk_goldimages_dir) self.uuid = str(uuid.uuid4()) log.debug("Setting up test %s - tagged with UUID %s", self._testMethodName, self.uuid) self.group_name = self.uuid[0:VMGroup.MAX_NAME_LENGTH]
def setUp(self): self.cluster_size = 4 self.cluster = mock.Mock(spec=Cluster) self.nodes = [mock.Mock(spec=Node) for _ in xrange(self.cluster_size)] for id, node in enumerate(self.nodes): node.node_id.return_value = id self.cluster.nodes.return_value = self.nodes self.scenario = Scenario( cluster=self.cluster, output_directory=environment.test_output_dir(self)) self.__delete_output_directory() os.makedirs(self.scenario.output_directory)
def test_power_on_with_cluster_using_only_a_subset_of_nodes(self): with open(gflags.FLAGS.cluster_config_path) as f: config = json.load(f) config["nodes"] = config["nodes"][:1] # Keep only the first node. cluster = util.cluster_from_metis_config(config) cluster.update_metadata(False) scenario = Scenario( cluster=cluster, output_directory=environment.test_output_dir(self), goldimages_directory=gflags.FLAGS.curie_vmdk_goldimages_dir) scenario.vm_groups = { self.group_name: VMGroup(scenario, self.group_name, template="ubuntu1604", template_type="DISK", count_per_cluster=1)} vms = steps.vm_group.CloneFromTemplate(scenario, self.group_name)() steps.vm_group.PowerOn(scenario, self.group_name)() for vm in self.cluster.find_vms([vm.vm_name() for vm in vms]): self.assertTrue(vm.is_powered_on()) self.assertTrue(vm.is_accessible())
def test_duration_secs_start_none(self): scenario = Scenario() scenario._start_time_secs = None scenario._end_time_secs = 12345 with self.assertRaises(RuntimeError): scenario.duration_secs()
def test_parse_steps_missing_required_phase(self): scenario = Scenario() yaml_str = """ vms: - OLTP: {} # setup phase is missing! run: - vm_group.CloneFromTemplate: vm_group_name: OLTP """ data = yaml.load(yaml_str) self.__create_stubs(scenario, data) with self.assertRaises(ValueError) as ar: scenario_parser._parse_steps(scenario, data) self.assertIn("Phase 'setup' is required", str(ar.exception))
def setUp(self): self.cluster = util.cluster_from_json(gflags.FLAGS.cluster_config_path) self.cluster.update_metadata(False) self.group_name = "".join( [random.choice(string.printable) for _ in xrange(VMGroup.MAX_NAME_LENGTH)]) self.workload_name = "".join( [random.choice(string.printable) for _ in xrange(40)]) self.scenario = Scenario( cluster=self.cluster, source_directory=os.path.join(environment.resource_dir(), "fio"), output_directory=environment.test_output_dir(self), goldimages_directory=gflags.FLAGS.curie_vmdk_goldimages_dir) self.valid_fio_path = "oltp.fio" self.invalid_fio_path = "not-a-file.bogus"
def test_save_state_unexpected_oserror(self, mock_makedirs): scenario = Scenario() scenario.cluster = mock_cluster() scenario.output_directory = environment.test_output_dir(self) err = OSError() err.errno = errno.EIO mock_makedirs.side_effect = err with self.assertRaises(OSError) as ar: scenario.save_state() self.assertEqual(errno.EIO, ar.exception.errno)
def setUp(self): self.cluster = util.cluster_from_json(gflags.FLAGS.cluster_config_path) self.cluster.update_metadata(False) self.scenario = Scenario( cluster=self.cluster, goldimages_directory=gflags.FLAGS.curie_vmdk_goldimages_dir, output_directory=environment.test_output_dir(self), source_directory=os.path.join(environment.resource_dir(), "playbooks")) self.scenario.vm_groups = dict() self.uuid = str(uuid.uuid4()) log.debug("Setting up test %s - tagged with UUID %s", self._testMethodName, self.uuid) self.vm_group_names = \ [(self.uuid[0:(VMGroup.MAX_NAME_LENGTH - 2)] + "-" + str(i)) for i in range(2)]
def test_parse_steps_misaligned(self): scenario = Scenario() yaml_str = """ vms: - OLTP: {} setup: - vm_group.CloneFromTemplate: vm_group_name: OLTP run: - vm_group.PowerOn: {} vm_group_name: OLTP # misaligned """ data = yaml.load(yaml_str) self.__create_stubs(scenario, data) with self.assertRaises(ValueError) as ar: scenario_parser._parse_steps(scenario, data) self.assertIn("Missing required arguments ['vm_group_name']", str(ar.exception))