Commit 285ece5b authored by Santi Raffa's avatar Santi Raffa Committed by Jose A. Lopes
Browse files

SimpleFillOS: add unit tests for OS parameter merging



Adds tests to ensure OS parameters are dealt with consistently.
Signed-off-by: default avatarSanti Raffa <rsanti@google.com>
Reviewed-by: default avatarJose A. Lopes <jabolopes@google.com>
parent 3062d395
......@@ -23,11 +23,13 @@
import copy
import pprint
import unittest
from ganeti import constants
from ganeti import objects
from ganeti import errors
from ganeti import serializer
import testutils
......@@ -763,5 +765,104 @@ class TestDisk(unittest.TestCase):
self.assertEqual(dev_type, disk.children[0].dev_type)
class TestSimpleFillOS(unittest.TestCase):
# We have to make sure that:
# * From within the configuration, variants override defaults
# * Temporary values override configuration
# * No overlap between public, private and secret dicts is allowed
#
# As a result, here are the actors in this test:
#
# A: temporary public
# B: temporary private
# C: temporary secret
# X: temporary public private secret
# D: configuration public variant
# E: configuration public base
# F: configuration private variant
# G: configuration private base
#
# Every time a param is assigned "ERROR", we expect FillOSParams to override
# it. If it doesn't, it's an error.
#
# Every time a param is assigned itself as a value, it's the value we expect
# FillOSParams to give us back.
def setUp(self):
self.fake_cl = objects.Cluster()
self.fake_cl.UpgradeConfig()
self.fake_cl.osparams = {"os": {"A": "ERROR",
"D": "ERROR",
"E": "E"},
"os+a": {"D": "D"}}
self.fake_cl.osparams_private_cluster = {"os": {"B": "ERROR",
"F": "ERROR",
"G": "G"},
"os+a": {"F": "F"}}
def testConflictPublicPrivate(self):
"Make sure we disallow attempts to override params based on visibility."
public_dict = {"A": "A", "X": "X"}
private_dict = {"B": "B", "X": "X"}
secret_dict = {"C": "C"}
dicts_pp = (public_dict, private_dict)
dicts_pps = (public_dict, private_dict, secret_dict)
# Without secret parameters
self.assertRaises(errors.OpPrereqError,
lambda: self.fake_cl.SimpleFillOS("os+a", *dicts_pp))
# but also with those.
self.assertRaises(errors.OpPrereqError,
lambda: self.fake_cl.SimpleFillOS("os+a", *dicts_pps))
def testConflictPublicSecret(self):
"Make sure we disallow attempts to override params based on visibility."
public_dict = {"A": "A", "X": "X"}
private_dict = {"B": "B"}
secret_dict = {"C": "C", "X": "X"}
dicts_pps = (public_dict, private_dict, secret_dict)
self.assertRaises(errors.OpPrereqError,
lambda: self.fake_cl.SimpleFillOS("os+a", *dicts_pps))
def testConflictPrivateSecret(self):
"Make sure we disallow attempts to override params based on visibility."
public_dict = {"A": "A"}
private_dict = {"B": "B", "X": "X"}
secret_dict = {"C": "C", "X": "X"}
dicts_pps = (public_dict, private_dict, secret_dict)
self.assertRaises(errors.OpPrereqError,
lambda: self.fake_cl.SimpleFillOS("os+a", *dicts_pps))
def testValidValues(self):
"Make sure we handle all overriding we do allow correctly."
public_dict = {"A": "A"}
private_dict = {"B": "B"}
secret_dict = {"C": "C"}
dicts_p = (public_dict,)
dicts_pp = (public_dict, private_dict)
dicts_pps = (public_dict, private_dict, secret_dict)
expected_keys_p = ("A", "D", "E") # nothing private, secret
expected_keys_pp = ("A", "B", "D", "E", "F", "G") # nothing secret
expected_keys_pps = ("A", "B", "C", "D", "E", "F", "G") # all of them
for (dicts, expected_keys) in [(dicts_p, expected_keys_p),
(dicts_pp, expected_keys_pp),
(dicts_pps, expected_keys_pps)]:
result = self.fake_cl.SimpleFillOS("os+a", *dicts)
# Values
for key in result:
if not result[key] == key:
self.fail("Invalid public-private fill with input:\n%s\n%s"
% (pprint.pformat(dicts), result))
# Completeness
if set(result) != set(expected_keys):
self.fail("Problem with key %s from merge result of:\n%s\n%s"
% (set(expected_keys) ^ set(result), # symmetric difference
pprint.pformat(dicts),
result))
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