Revision 285ece5b
b/test/py/ganeti.objects_unittest.py | ||
---|---|---|
23 | 23 |
|
24 | 24 |
|
25 | 25 |
import copy |
26 |
import pprint |
|
26 | 27 |
import unittest |
27 | 28 |
|
28 | 29 |
from ganeti import constants |
29 | 30 |
from ganeti import objects |
30 | 31 |
from ganeti import errors |
32 |
from ganeti import serializer |
|
31 | 33 |
|
32 | 34 |
import testutils |
33 | 35 |
|
... | ... | |
763 | 765 |
self.assertEqual(dev_type, disk.children[0].dev_type) |
764 | 766 |
|
765 | 767 |
|
768 |
class TestSimpleFillOS(unittest.TestCase): |
|
769 |
# We have to make sure that: |
|
770 |
# * From within the configuration, variants override defaults |
|
771 |
# * Temporary values override configuration |
|
772 |
# * No overlap between public, private and secret dicts is allowed |
|
773 |
# |
|
774 |
# As a result, here are the actors in this test: |
|
775 |
# |
|
776 |
# A: temporary public |
|
777 |
# B: temporary private |
|
778 |
# C: temporary secret |
|
779 |
# X: temporary public private secret |
|
780 |
# D: configuration public variant |
|
781 |
# E: configuration public base |
|
782 |
# F: configuration private variant |
|
783 |
# G: configuration private base |
|
784 |
# |
|
785 |
# Every time a param is assigned "ERROR", we expect FillOSParams to override |
|
786 |
# it. If it doesn't, it's an error. |
|
787 |
# |
|
788 |
# Every time a param is assigned itself as a value, it's the value we expect |
|
789 |
# FillOSParams to give us back. |
|
790 |
|
|
791 |
def setUp(self): |
|
792 |
self.fake_cl = objects.Cluster() |
|
793 |
self.fake_cl.UpgradeConfig() |
|
794 |
self.fake_cl.osparams = {"os": {"A": "ERROR", |
|
795 |
"D": "ERROR", |
|
796 |
"E": "E"}, |
|
797 |
"os+a": {"D": "D"}} |
|
798 |
self.fake_cl.osparams_private_cluster = {"os": {"B": "ERROR", |
|
799 |
"F": "ERROR", |
|
800 |
"G": "G"}, |
|
801 |
"os+a": {"F": "F"}} |
|
802 |
|
|
803 |
def testConflictPublicPrivate(self): |
|
804 |
"Make sure we disallow attempts to override params based on visibility." |
|
805 |
public_dict = {"A": "A", "X": "X"} |
|
806 |
private_dict = {"B": "B", "X": "X"} |
|
807 |
secret_dict = {"C": "C"} |
|
808 |
dicts_pp = (public_dict, private_dict) |
|
809 |
dicts_pps = (public_dict, private_dict, secret_dict) |
|
810 |
|
|
811 |
# Without secret parameters |
|
812 |
self.assertRaises(errors.OpPrereqError, |
|
813 |
lambda: self.fake_cl.SimpleFillOS("os+a", *dicts_pp)) |
|
814 |
|
|
815 |
# but also with those. |
|
816 |
self.assertRaises(errors.OpPrereqError, |
|
817 |
lambda: self.fake_cl.SimpleFillOS("os+a", *dicts_pps)) |
|
818 |
|
|
819 |
def testConflictPublicSecret(self): |
|
820 |
"Make sure we disallow attempts to override params based on visibility." |
|
821 |
public_dict = {"A": "A", "X": "X"} |
|
822 |
private_dict = {"B": "B"} |
|
823 |
secret_dict = {"C": "C", "X": "X"} |
|
824 |
dicts_pps = (public_dict, private_dict, secret_dict) |
|
825 |
|
|
826 |
self.assertRaises(errors.OpPrereqError, |
|
827 |
lambda: self.fake_cl.SimpleFillOS("os+a", *dicts_pps)) |
|
828 |
|
|
829 |
def testConflictPrivateSecret(self): |
|
830 |
"Make sure we disallow attempts to override params based on visibility." |
|
831 |
public_dict = {"A": "A"} |
|
832 |
private_dict = {"B": "B", "X": "X"} |
|
833 |
secret_dict = {"C": "C", "X": "X"} |
|
834 |
dicts_pps = (public_dict, private_dict, secret_dict) |
|
835 |
|
|
836 |
self.assertRaises(errors.OpPrereqError, |
|
837 |
lambda: self.fake_cl.SimpleFillOS("os+a", *dicts_pps)) |
|
838 |
|
|
839 |
def testValidValues(self): |
|
840 |
"Make sure we handle all overriding we do allow correctly." |
|
841 |
public_dict = {"A": "A"} |
|
842 |
private_dict = {"B": "B"} |
|
843 |
secret_dict = {"C": "C"} |
|
844 |
dicts_p = (public_dict,) |
|
845 |
dicts_pp = (public_dict, private_dict) |
|
846 |
dicts_pps = (public_dict, private_dict, secret_dict) |
|
847 |
expected_keys_p = ("A", "D", "E") # nothing private, secret |
|
848 |
expected_keys_pp = ("A", "B", "D", "E", "F", "G") # nothing secret |
|
849 |
expected_keys_pps = ("A", "B", "C", "D", "E", "F", "G") # all of them |
|
850 |
|
|
851 |
for (dicts, expected_keys) in [(dicts_p, expected_keys_p), |
|
852 |
(dicts_pp, expected_keys_pp), |
|
853 |
(dicts_pps, expected_keys_pps)]: |
|
854 |
result = self.fake_cl.SimpleFillOS("os+a", *dicts) |
|
855 |
# Values |
|
856 |
for key in result: |
|
857 |
if not result[key] == key: |
|
858 |
self.fail("Invalid public-private fill with input:\n%s\n%s" |
|
859 |
% (pprint.pformat(dicts), result)) |
|
860 |
# Completeness |
|
861 |
if set(result) != set(expected_keys): |
|
862 |
self.fail("Problem with key %s from merge result of:\n%s\n%s" |
|
863 |
% (set(expected_keys) ^ set(result), # symmetric difference |
|
864 |
pprint.pformat(dicts), |
|
865 |
result)) |
|
866 |
|
|
766 | 867 |
if __name__ == "__main__": |
767 | 868 |
testutils.GanetiTestProgram() |
Also available in: Unified diff