Hi

I just wanted to highlight some new functionality that has been added to
charm-helpers [1] to make comparing Ubuntu versions more robust.  In the
OpenStack team, all of our charms are 'multi-series' in that a single charm
support multiple versions of Ubuntu and multiple versions of OpenStack
(often simultaneously).

The code was using statements along the lines of:

    if ubuntu_version > 'trusty':

The eagle-eyed amongst you will have noticed the impending y2k-type bug,
with the (possible) imminent wrap from 'zesty' -> '???'.

So we decided to fix this across our 30-odd charms and add a couple of
functions to charm-helpers to aid in this.

Firstly, charm-helpers.core.strutils.BasicStringComparator class is an
abstract-ish class to be used as a base class for building a comparator of
an ordered list.  It provides __eq__, __ne__, __lt__ (and so on)
comparisons for two strings.  it also checks that the strings provided are
in the defined list, which helps with mistyping of string literals.

Then for the Ubuntu releases, the
charmhelpers.core.host.CompareHostReleases class is used to compare two
Ubuntu release for equality or 'earlier than' and 'later than;.

So instead of:

    if ubuntu_version > 'trusty':

We do:

    cmp_version = CompareHostReleases(ubuntu_version)
    if cmp_version > 'trusty':

This version of the code checks that ubuntu_version and 'trusty' strings
are known releases and makes it easy to fix existing code.  >, <, >=< <=,
==, != are all supported.

We did consider a number of approaches, but felt that this one was simple
to retro-fit to existing charms and also spot in reviews going forward if
they have been missed.

Also, for charms in the OpenStack ecosystem, there is an additional
comparator class:

    charmhelpers.contrib.openstack.utils.CompareOpenStackReleases

which is used in the same way, but works with all of the OpenStack releases.

Thus:

    cmp_os_release = CompareOpenStackReleases(os_release)
    if cmp_os_release > 'mitaka':

We're now in the process of finalises the fixes to the OpenStack charms and
they'll be in 'next' over the coming week.

Thanks, and hope this is useful.
Best
Alex.


[1] -- charm-helpers: https://launchpad.net/charm-helpers

-- 
Alex Kavanagh - Software Engineer
Cloud Dev Ops - Solutions & Product Engineering - Canonical Ltd
-- 
Juju mailing list
Juju@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/juju

Reply via email to