On Wed, Oct 02, 2013 at 02:33:03PM +0200, Klaus Aehlig wrote:
> Provide a predicate that, given the current version and the
> version to go to, tells whether it is appropriate to call
> cfgupgrade --downgrade.
> 
> Signed-off-by: Klaus Aehlig <[email protected]>
> ---
>  lib/utils/version.py                     | 18 ++++++++++++++++++
>  test/py/ganeti.utils.version_unittest.py |  6 ++++++
>  2 files changed, 24 insertions(+)
> 
> diff --git a/lib/utils/version.py b/lib/utils/version.py
> index ef9aa27..7212b32 100644
> --- a/lib/utils/version.py
> +++ b/lib/utils/version.py
> @@ -119,3 +119,21 @@ def UpgradeRange(version, current=CURRENT_VERSION):
>      return "can only downgrade one minor version at a time"
>  
>    return None
> +
> +
> +def ShouldCfgdowngrade(version, current=CURRENT_VERSION):
> +  """Decide whether cfgupgrade --downgrade should be called.
> +
> +  Given the current version and the version to change to, decide
> +  if in the transition process cfgupgrade --downgrade should
> +  be called
> +
> +  @param version: The version to upgrade to as (major, minor, revision)
> +  @type version: tuple
> +  @param current: The versino to upgrade from as (major, minor, revision)
> +  @type current: tuple
> +  @rtype: bool
> +  @return: True, if cfgupgrade --downgrade should be called.
> +
> +  """
> +  return version[0] == current[0] and version[1] == current[1] - 1
> diff --git a/test/py/ganeti.utils.version_unittest.py 
> b/test/py/ganeti.utils.version_unittest.py
> index 8e175b1..e7658e3 100755
> --- a/test/py/ganeti.utils.version_unittest.py
> +++ b/test/py/ganeti.utils.version_unittest.py
> @@ -56,6 +56,12 @@ class UpgradeRangeTest(unittest.TestCase):
>          self.assertEquals(version.UpgradeRange((2,10,0), current=(2,9,0)),
>                            "automatic upgrades only supported from 2.10 
> onwards")
>  
> +class ShouldCfgdowngradeTest(unittest.TestCase):
> +    def testShouldCfgDowngrade(self):
> +        self.assertTrue(version.ShouldCfgdowngrade((2,9,3), 
> current=(2,10,0)))
> +        self.assertTrue(version.ShouldCfgdowngrade((2,9,0), 
> current=(2,10,4)))
> +        self.assertFalse(version.ShouldCfgdowngrade((2,9,0), 
> current=(2,11,0)))

Doesn't Python coverage test all Boolean paths say, for example, the
'and' test on 'ShouldCfgDowngrade' ?

If so, add tests for major versions as well to maximize coverage.


Rest LGTM.

Thanks,
Jose

> +
>  
>  if __name__ == "__main__":
>    testutils.GanetiTestProgram()
> -- 
> 1.8.4
> 

-- 
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