Commit 82c54b5b authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

config: Add check for disk's “iv_name”

This check verifies “iv_name” of all instance disks. If one is wrong
(which shouldn't happen in the first place), cluster verification will

“ERROR: cluster: Instance '' has wrongly named disks:
name of disk 1 should be 'disk/1', but is 'disk/4'”
Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarIustin Pop <>
Reviewed-by: default avatarRené Nussbaumer <>
parent aa12a891
......@@ -133,6 +133,26 @@ def _MatchNameComponentIgnoreCase(short_name, names):
return utils.MatchNameComponent(short_name, names, case_sensitive=False)
def _CheckInstanceDiskIvNames(disks):
"""Checks if instance's disks' C{iv_name} attributes are in order.
@type disks: list of L{objects.Disk}
@param disks: List of disks
@rtype: list of tuples; (int, string, string)
@return: List of wrongly named disks, each tuple contains disk index,
expected and actual name
result = []
for (idx, disk) in enumerate(disks):
exp_iv_name = "disk/%s" % idx
if disk.iv_name != exp_iv_name:
result.append((idx, exp_iv_name, disk.iv_name))
return result
class ConfigWriter:
"""The interface to the cluster configuration.
......@@ -510,6 +530,15 @@ class ConfigWriter:
(, idx, msg) for msg in disk.Verify()])
result.extend(self._CheckDiskIDs(disk, seen_lids, seen_pids))
wrong_names = _CheckInstanceDiskIvNames(instance.disks)
if wrong_names:
tmp = "; ".join(("name of disk %s should be '%s', but is '%s'" %
(idx, exp_name, actual_name))
for (idx, exp_name, actual_name) in wrong_names)
result.append("Instance '%s' has wrongly named disks: %s" %
(, tmp))
# cluster-wide pool of free ports
for free_port in cluster.tcpudp_port_pool:
if free_port not in ports:
......@@ -39,6 +39,7 @@ from ganeti import objects
from ganeti import utils
from ganeti import netutils
from ganeti import compat
from ganeti import cmdlib
from ganeti.config import TemporaryReservationManager
......@@ -382,5 +383,28 @@ class TestTRM(unittest.TestCase):
class TestCheckInstanceDiskIvNames(unittest.TestCase):
def _MakeDisks(names):
return [objects.Disk(iv_name=name) for name in names]
def testNoError(self):
disks = self._MakeDisks(["disk/0", "disk/1"])
self.assertEqual(config._CheckInstanceDiskIvNames(disks), [])
cmdlib._UpdateIvNames(0, disks)
self.assertEqual(config._CheckInstanceDiskIvNames(disks), [])
def testWrongNames(self):
disks = self._MakeDisks(["disk/1", "disk/3", "disk/2"])
self.assertEqual(config._CheckInstanceDiskIvNames(disks), [
(0, "disk/0", "disk/1"),
(1, "disk/1", "disk/3"),
# Fix names
cmdlib._UpdateIvNames(0, disks)
self.assertEqual(config._CheckInstanceDiskIvNames(disks), [])
if __name__ == '__main__':
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment