Commit d514e18b authored by Helga Velroyen's avatar Helga Velroyen

bootstrap: restrict ipolicy to enabled disk templates

With this patch, on cluster creation, the initial instance
policy's list of allowed disk templates will be modified
in a way that it does not contain any disk templates which
are not enabled cluster-wise.
Signed-off-by: default avatarHelga Velroyen <helgav@google.com>
Reviewed-by: default avatarThomas Thrainer <thomasth@google.com>
parent 33a6464e
......@@ -452,6 +452,26 @@ def _InitCheckEnabledDiskTemplates(enabled_disk_templates):
errors.ECODE_INVAL)
def _RestrictIpolicyToEnabledDiskTemplates(ipolicy, enabled_disk_templates):
"""Restricts the ipolicy's disk templates to the enabled ones.
This function clears the ipolicy's list of allowed disk templates from the
ones that are not enabled by the cluster.
@type ipolicy: dict
@param ipolicy: the instance policy
@type enabled_disk_templates: list of string
@param enabled_disk_templates: the list of cluster-wide enabled disk
templates
"""
assert constants.IPOLICY_DTS in ipolicy
allowed_disk_templates = ipolicy[constants.IPOLICY_DTS]
restricted_disk_templates = list(set(allowed_disk_templates)
.intersection(set(enabled_disk_templates)))
ipolicy[constants.IPOLICY_DTS] = restricted_disk_templates
def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913, R0914
master_netmask, master_netdev, file_storage_dir,
shared_file_storage_dir, candidate_pool_size, secondary_ip=None,
......@@ -595,6 +615,7 @@ def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913, R0914
objects.NIC.CheckParameterSyntax(nicparams)
full_ipolicy = objects.FillIPolicy(constants.IPOLICY_DEFAULTS, ipolicy)
_RestrictIpolicyToEnabledDiskTemplates(full_ipolicy, enabled_disk_templates)
if ndparams is not None:
utils.ForceDictType(ndparams, constants.NDS_PARAMETER_TYPES)
......
......@@ -111,5 +111,24 @@ class TestInitCheckEnabledDiskTemplates(unittest.TestCase):
bootstrap._InitCheckEnabledDiskTemplates, enabled_disk_templates)
class TestRestrictIpolicyToEnabledDiskTemplates(unittest.TestCase):
def testNoRestriction(self):
allowed_disk_templates = list(constants.DISK_TEMPLATES)
ipolicy = {constants.IPOLICY_DTS: allowed_disk_templates}
enabled_disk_templates = list(constants.DISK_TEMPLATES)
bootstrap._RestrictIpolicyToEnabledDiskTemplates(
ipolicy, enabled_disk_templates)
self.assertEqual(ipolicy[constants.IPOLICY_DTS], allowed_disk_templates)
def testRestriction(self):
allowed_disk_templates = [constants.DT_DRBD8, constants.DT_PLAIN]
ipolicy = {constants.IPOLICY_DTS: allowed_disk_templates}
enabled_disk_templates = [constants.DT_PLAIN, constants.DT_FILE]
bootstrap._RestrictIpolicyToEnabledDiskTemplates(
ipolicy, enabled_disk_templates)
self.assertEqual(ipolicy[constants.IPOLICY_DTS], [constants.DT_PLAIN])
if __name__ == "__main__":
testutils.GanetiTestProgram()
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