Try to get the version of cloud init via popen
Now we can fail while trying to get the version of cloud-init via pkg_resources. Try to get the version via ordinary cmd call 'cloud-init --version'. Change-Id: I39d4d52ba1ac83183a0a46c7f3a70a14b782562a Closes-Bug: #1481614
This commit is contained in:
parent
cd10238cce
commit
04eedc46b8
|
@ -17,6 +17,7 @@ from distutils import version
|
||||||
import errno
|
import errno
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -28,9 +29,20 @@ LOG = logging.getLogger('heat-provision')
|
||||||
|
|
||||||
|
|
||||||
def chk_ci_version():
|
def chk_ci_version():
|
||||||
v = version.LooseVersion(
|
try:
|
||||||
pkg_resources.get_distribution('cloud-init').version)
|
v = version.LooseVersion(
|
||||||
return v >= version.LooseVersion('0.6.0')
|
pkg_resources.get_distribution('cloud-init').version)
|
||||||
|
return v >= version.LooseVersion('0.6.0')
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
data = subprocess.Popen(['cloud-init', '--version'],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE).communicate()
|
||||||
|
if data[0]:
|
||||||
|
raise Exception()
|
||||||
|
# data[1] has such format: 'cloud-init 0.7.5\n', need to parse version
|
||||||
|
v = re.split(' |\n', data[1])[1].split('.')
|
||||||
|
return tuple(v) >= tuple('0', '6', '0')
|
||||||
|
|
||||||
|
|
||||||
def init_logging():
|
def init_logging():
|
||||||
|
@ -74,11 +86,15 @@ def call(args):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
if not chk_ci_version():
|
try:
|
||||||
# pre 0.6.0 - user data executed via cloudinit, not this helper
|
if not chk_ci_version():
|
||||||
LOG.error('Unable to log provisioning, need a newer version of '
|
# pre 0.6.0 - user data executed via cloudinit, not this helper
|
||||||
'cloud-init')
|
LOG.error('Unable to log provisioning, need a newer version of '
|
||||||
return -1
|
'cloud-init')
|
||||||
|
return -1
|
||||||
|
except Exception:
|
||||||
|
LOG.warning('Can not determine the version of cloud-init. It is '
|
||||||
|
'possible to get errors while logging provisioning.')
|
||||||
|
|
||||||
userdata_path = os.path.join(VAR_PATH, 'cfn-userdata')
|
userdata_path = os.path.join(VAR_PATH, 'cfn-userdata')
|
||||||
os.chmod(userdata_path, int("700", 8))
|
os.chmod(userdata_path, int("700", 8))
|
||||||
|
|
Loading…
Reference in New Issue