Use charm-helper for version comparisons

This commit is contained in:
James Page 2014-07-23 12:37:44 +01:00
parent acdc9cdef6
commit 2f8a854869
2 changed files with 4 additions and 22 deletions

View File

@ -11,7 +11,6 @@ import json
import subprocess
import time
import os
import apt_pkg
from socket import gethostname as get_unit_hostname
@ -220,21 +219,3 @@ def get_named_key(name, caps=None):
if 'key' in element:
key = element.split(' = ')[1].strip() # IGNORE:E1103
return key
def get_ceph_version(package=None):
apt_pkg.init()
# Force Apt to build its cache in memory. That way we avoid race
# conditions with other applications building the cache in the same
# place.
apt_pkg.config.set("Dir::Cache::pkgcache", "")
cache = apt_pkg.Cache()
pkg = cache[package or 'ceph']
if pkg.current_ver:
return apt_pkg.upstream_version(pkg.current_ver.ver_str)
else:
return None
def version_compare(a, b):
return apt_pkg.version_compare(a, b)

View File

@ -38,6 +38,7 @@ from utils import (
)
from charmhelpers.payload.execd import execd_preinstall
from charmhelpers.core.host import cmp_pkgrevno
from socket import gethostname as get_unit_hostname
hooks = Hooks()
@ -73,13 +74,13 @@ def emit_cephconf():
'auth_supported': get_auth() or 'none',
'mon_hosts': ' '.join(get_mon_hosts()),
'hostname': get_unit_hostname(),
'version': ceph.get_ceph_version('radosgw'),
'old_auth': cmp_pkgrevno('radosgw', "0.51") < 0,
'use_syslog': str(config('use-syslog')).lower()
}
# Check to ensure that correct version of ceph is
# in use
if ceph.get_ceph_version('radosgw') >= "0.55":
if cmp_pkgrevno('radosgw', '0.55') >= 0:
# Add keystone configuration if found
ks_conf = get_keystone_conf()
if ks_conf:
@ -208,7 +209,7 @@ def restart():
@hooks.hook('identity-service-relation-joined')
def identity_joined(relid=None):
if ceph.get_ceph_version('radosgw') < "0.55":
if cmp_pkgrevno('radosgw', '0.55') < 0:
log('Integration with keystone requires ceph >= 0.55')
sys.exit(1)