Migrate charm to Python3

Change-Id: Ibb46dfa766b12aedea90f823d3964c569bdfcb01
This commit is contained in:
Alex Kavanagh 2019-02-04 19:18:02 +00:00
parent 3d3271f1c8
commit 6aa32f2d67
8 changed files with 48 additions and 22 deletions

View File

@ -1,4 +1,3 @@
- project:
templates:
- python-charm-jobs
- openstack-python35-jobs-nonvoting
- python35-charm-jobs

View File

@ -1 +0,0 @@
../charmhelpers

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2018 Canonical Ltd
#
@ -16,8 +16,20 @@
import glob
import os
import sys
import shutil
import sys
_path = os.path.dirname(os.path.realpath(__file__))
_root = os.path.abspath(os.path.join(_path, '..'))
def _add_path(path):
if path not in sys.path:
sys.path.insert(1, path)
_add_path(_root)
from charmhelpers.fetch import add_source, apt_install, apt_update
from charmhelpers.core import hookenv

View File

@ -11,7 +11,7 @@ check_and_install() {
fi
}
PYTHON="python"
PYTHON="python3"
for dep in ${DEPS[@]}; do
check_and_install ${PYTHON} ${dep}

View File

@ -2,7 +2,7 @@
# This file is managed centrally by release-tools and should not be modified
# within individual charm repos.
[tox]
envlist = pep8,py27
envlist = pep8,py3{5,6}
skipsdist = True
[testenv]
@ -20,13 +20,13 @@ passenv = HOME TERM AMULET_* CS_API_*
basepython = python2.7
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
# charm is NOT PY27 compatible
commands = /bin/true
[testenv:py35]
basepython = python3.5
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
# charm is NOT Py3 compatible
commands = /bin/true
[testenv:py36]
basepython = python3.6

View File

@ -0,0 +1,18 @@
import os
import sys
_path = os.path.dirname(os.path.realpath(__file__))
_actions = os.path.abspath(os.path.join(_path, '../actions'))
_hooks = os.path.abspath(os.path.join(_path, '../hooks'))
_charmhelpers = os.path.abspath(os.path.join(_path, '../charmhelpers'))
_unit_tests = os.path.abspath(os.path.join(_path, '../unit_tests'))
def _add_path(path):
if path not in sys.path:
sys.path.insert(1, path)
_add_path(_actions)
_add_path(_hooks)
_add_path(_charmhelpers)
_add_path(_unit_tests)

View File

@ -43,12 +43,11 @@ class TestConfigChanged(CharmTestCase):
@mock.patch.object(hooks, 'update_nrpe_config')
@mock.patch('os.symlink')
@mock.patch('hooks.charmhelpers.core.hookenv.config')
@mock.patch('hooks.charmhelpers.core.hookenv.relations_of_type')
@mock.patch('hooks.charmhelpers.contrib.charmsupport.nrpe'
'.get_nagios_hostname')
@mock.patch('hooks.charmhelpers.contrib.charmsupport.nrpe.config')
@mock.patch('hooks.charmhelpers.contrib.charmsupport.nrpe.local_unit')
@mock.patch('charmhelpers.core.hookenv.config')
@mock.patch('charmhelpers.core.hookenv.relations_of_type')
@mock.patch('charmhelpers.contrib.charmsupport.nrpe.get_nagios_hostname')
@mock.patch('charmhelpers.contrib.charmsupport.nrpe.config')
@mock.patch('charmhelpers.contrib.charmsupport.nrpe.local_unit')
def test_default_config(self, local_unit, nrpe_config, nag_host,
relations_of_type, config, symlink,
update_nrpe_config):
@ -82,12 +81,11 @@ class TestConfigChanged(CharmTestCase):
@mock.patch('os.path.exists')
@mock.patch('os.remove')
@mock.patch('glob.glob')
@mock.patch('hooks.charmhelpers.core.hookenv.config')
@mock.patch('hooks.charmhelpers.core.hookenv.relations_of_type')
@mock.patch('hooks.charmhelpers.contrib.charmsupport.nrpe'
'.get_nagios_hostname')
@mock.patch('hooks.charmhelpers.contrib.charmsupport.nrpe.config')
@mock.patch('hooks.charmhelpers.contrib.charmsupport.nrpe.local_unit')
@mock.patch('charmhelpers.core.hookenv.config')
@mock.patch('charmhelpers.core.hookenv.relations_of_type')
@mock.patch('charmhelpers.contrib.charmsupport.nrpe.get_nagios_hostname')
@mock.patch('charmhelpers.contrib.charmsupport.nrpe.config')
@mock.patch('charmhelpers.contrib.charmsupport.nrpe.local_unit')
def test_uninstall_cron(self, local_unit, nrpe_config, nag_host,
relations_of_type, config, glob, remove, exists,
update_nrpe_config):

View File

@ -36,7 +36,7 @@ def get_default_config():
'''
default_config = {}
config = load_config()
for k, v in config.iteritems():
for k, v in config.items():
if 'default' in v:
default_config[k] = v['default']
else: