LGTM.

Thanks,
Jose

On Thu, Feb 06, 2014 at 05:24:20PM +0100, Santi Raffa wrote:
> Adds tests to ensure OS parameters are dealt with consistently.
> 
> Signed-off-by: Santi Raffa <[email protected]>
> ---
>  test/py/ganeti.objects_unittest.py | 101 
> +++++++++++++++++++++++++++++++++++++
>  1 file changed, 101 insertions(+)
> 
> diff --git a/test/py/ganeti.objects_unittest.py 
> b/test/py/ganeti.objects_unittest.py
> index eee782e..96f6232 100755
> --- a/test/py/ganeti.objects_unittest.py
> +++ b/test/py/ganeti.objects_unittest.py
> @@ -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()
> -- 
> 1.9.0.rc1.175.g0b1dcb5
> 

-- 
Jose Antonio Lopes
Ganeti Engineering
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
Steuernummer: 48/725/00206
Umsatzsteueridentifikationsnummer: DE813741370

Reply via email to