On 11/10/2014 06:12 PM, Aaron Karper wrote: > On Thu, Nov 06, 2014 at 12:30:47AM +0200, Alex Pyrgiotis wrote: >> Check if the GetDiskInfo and GetDiskInfoByName functions operate as >> expected. >> >> Signed-off-by: Alex Pyrgiotis <[email protected] <mailto:[email protected]>> >> >> diff --git a/test/py/ganeti.config___unittest.py > <http://ganeti.config_unittest.py> b/test/py/ganeti.config___unittest.py > <http://ganeti.config_unittest.py> >> index efcf9cb..22f34dd 100755 >> --- a/test/py/ganeti.config___unittest.py > <http://ganeti.config_unittest.py> >> +++ b/test/py/ganeti.config___unittest.py > <http://ganeti.config_unittest.py> >> @@ -148,6 +148,48 @@ class TestConfigRunner(unittest.__TestCase): >> self.assertEqual(all_nodes[0], iobj.primary_node, >> msg="Primary node not first node in list") >> >> + def testDisksInfo(self): >> + """Check if the GetDiskInfo function works as intented.""" >> + # Create mock config writer >> + cfg = self._get_object_mock() >> + >> + # Construct instance and add a plain disk >> + inst = self._create_instance(cfg) >> + cfg.AddInstance(inst, "my-job") >> + disk = objects.Disk(dev_type=__constants.DT_PLAIN, size=128, >> + logical_id=("myxenvg", "disk25494"), > uuid="disk0", >> + name="name0") >> + cfg.AddInstanceDisk(inst.uuid, disk) >> + >> + # Test 1 - Search this disk by UUID >> + result = cfg.GetDiskInfo("disk0") >> + self.assertEqual(disk, result) >> + >> + # Test 2 - Search this disk by name >> + result = cfg.GetDiskInfoByName("name0") >> + self.assertEqual(disk, result) >> + >> + # Test 3 - Search this disk by wrong UUID and check that 'None' > is returned >> + result = cfg.GetDiskInfo("disk1134") >> + self.assertEqual(None, result) >> + >> + # Test 4 - Search this disk by wrong name and check that 'None' > is returned >> + result = cfg.GetDiskInfoByName("__name1134") >> + self.assertEqual(None, result) >> + >> + # Test 5 - Add an extra disk with different UUID but same name. Then, >> + # search for a disk with that name and assert that we raise an > exception >> + # about two disks with the same name. >> + disk = objects.Disk(dev_type=__constants.DT_PLAIN, size=128, >> + logical_id=("myxenvg", "disk25494"), > uuid="disk1", >> + name="name0") >> + cfg.AddInstanceDisk(inst.uuid, disk) >> + >> + with self.assertRaises(errors.__ConfigurationError) as cm: >> + cfg.GetDiskInfoByName("name0") >> + self.assertEqual(cm.exception.__message, "There are 2 disks with > this name:" >> + " name0") >> + > > Please use separate test methods. >
ACK >> >> def testInstNodesNoDisks(self): >> """Test all_nodes/secondary_nodes when there are no disks""" >> # construct instance >> -- >> 1.7.10.4 >> > > -- > Google Germany GmbH > Dienerstr. 12 > 80331 München > > Registergericht und -nummer: Hamburg, HRB 86891 > Sitz der Gesellschaft: Hamburg > Geschäftsführer: Graham Law, Christine Elizabeth Flores -- Alex | [email protected]
