Migrate charm to Python3
Change-Id: Ibb46dfa766b12aedea90f823d3964c569bdfcb01
This commit is contained in:
parent
3d3271f1c8
commit
6aa32f2d67
|
@ -1,4 +1,3 @@
|
||||||
- project:
|
- project:
|
||||||
templates:
|
templates:
|
||||||
- python-charm-jobs
|
- python35-charm-jobs
|
||||||
- openstack-python35-jobs-nonvoting
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
../charmhelpers
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# Copyright 2018 Canonical Ltd
|
# Copyright 2018 Canonical Ltd
|
||||||
#
|
#
|
||||||
|
@ -16,8 +16,20 @@
|
||||||
|
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import shutil
|
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.fetch import add_source, apt_install, apt_update
|
||||||
from charmhelpers.core import hookenv
|
from charmhelpers.core import hookenv
|
||||||
|
|
|
@ -11,7 +11,7 @@ check_and_install() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
PYTHON="python"
|
PYTHON="python3"
|
||||||
|
|
||||||
for dep in ${DEPS[@]}; do
|
for dep in ${DEPS[@]}; do
|
||||||
check_and_install ${PYTHON} ${dep}
|
check_and_install ${PYTHON} ${dep}
|
||||||
|
|
6
tox.ini
6
tox.ini
|
@ -2,7 +2,7 @@
|
||||||
# This file is managed centrally by release-tools and should not be modified
|
# This file is managed centrally by release-tools and should not be modified
|
||||||
# within individual charm repos.
|
# within individual charm repos.
|
||||||
[tox]
|
[tox]
|
||||||
envlist = pep8,py27
|
envlist = pep8,py3{5,6}
|
||||||
skipsdist = True
|
skipsdist = True
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
|
@ -20,13 +20,13 @@ passenv = HOME TERM AMULET_* CS_API_*
|
||||||
basepython = python2.7
|
basepython = python2.7
|
||||||
deps = -r{toxinidir}/requirements.txt
|
deps = -r{toxinidir}/requirements.txt
|
||||||
-r{toxinidir}/test-requirements.txt
|
-r{toxinidir}/test-requirements.txt
|
||||||
|
# charm is NOT PY27 compatible
|
||||||
|
commands = /bin/true
|
||||||
|
|
||||||
[testenv:py35]
|
[testenv:py35]
|
||||||
basepython = python3.5
|
basepython = python3.5
|
||||||
deps = -r{toxinidir}/requirements.txt
|
deps = -r{toxinidir}/requirements.txt
|
||||||
-r{toxinidir}/test-requirements.txt
|
-r{toxinidir}/test-requirements.txt
|
||||||
# charm is NOT Py3 compatible
|
|
||||||
commands = /bin/true
|
|
||||||
|
|
||||||
[testenv:py36]
|
[testenv:py36]
|
||||||
basepython = python3.6
|
basepython = python3.6
|
||||||
|
|
|
@ -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)
|
|
@ -43,12 +43,11 @@ class TestConfigChanged(CharmTestCase):
|
||||||
|
|
||||||
@mock.patch.object(hooks, 'update_nrpe_config')
|
@mock.patch.object(hooks, 'update_nrpe_config')
|
||||||
@mock.patch('os.symlink')
|
@mock.patch('os.symlink')
|
||||||
@mock.patch('hooks.charmhelpers.core.hookenv.config')
|
@mock.patch('charmhelpers.core.hookenv.config')
|
||||||
@mock.patch('hooks.charmhelpers.core.hookenv.relations_of_type')
|
@mock.patch('charmhelpers.core.hookenv.relations_of_type')
|
||||||
@mock.patch('hooks.charmhelpers.contrib.charmsupport.nrpe'
|
@mock.patch('charmhelpers.contrib.charmsupport.nrpe.get_nagios_hostname')
|
||||||
'.get_nagios_hostname')
|
@mock.patch('charmhelpers.contrib.charmsupport.nrpe.config')
|
||||||
@mock.patch('hooks.charmhelpers.contrib.charmsupport.nrpe.config')
|
@mock.patch('charmhelpers.contrib.charmsupport.nrpe.local_unit')
|
||||||
@mock.patch('hooks.charmhelpers.contrib.charmsupport.nrpe.local_unit')
|
|
||||||
def test_default_config(self, local_unit, nrpe_config, nag_host,
|
def test_default_config(self, local_unit, nrpe_config, nag_host,
|
||||||
relations_of_type, config, symlink,
|
relations_of_type, config, symlink,
|
||||||
update_nrpe_config):
|
update_nrpe_config):
|
||||||
|
@ -82,12 +81,11 @@ class TestConfigChanged(CharmTestCase):
|
||||||
@mock.patch('os.path.exists')
|
@mock.patch('os.path.exists')
|
||||||
@mock.patch('os.remove')
|
@mock.patch('os.remove')
|
||||||
@mock.patch('glob.glob')
|
@mock.patch('glob.glob')
|
||||||
@mock.patch('hooks.charmhelpers.core.hookenv.config')
|
@mock.patch('charmhelpers.core.hookenv.config')
|
||||||
@mock.patch('hooks.charmhelpers.core.hookenv.relations_of_type')
|
@mock.patch('charmhelpers.core.hookenv.relations_of_type')
|
||||||
@mock.patch('hooks.charmhelpers.contrib.charmsupport.nrpe'
|
@mock.patch('charmhelpers.contrib.charmsupport.nrpe.get_nagios_hostname')
|
||||||
'.get_nagios_hostname')
|
@mock.patch('charmhelpers.contrib.charmsupport.nrpe.config')
|
||||||
@mock.patch('hooks.charmhelpers.contrib.charmsupport.nrpe.config')
|
@mock.patch('charmhelpers.contrib.charmsupport.nrpe.local_unit')
|
||||||
@mock.patch('hooks.charmhelpers.contrib.charmsupport.nrpe.local_unit')
|
|
||||||
def test_uninstall_cron(self, local_unit, nrpe_config, nag_host,
|
def test_uninstall_cron(self, local_unit, nrpe_config, nag_host,
|
||||||
relations_of_type, config, glob, remove, exists,
|
relations_of_type, config, glob, remove, exists,
|
||||||
update_nrpe_config):
|
update_nrpe_config):
|
||||||
|
|
|
@ -36,7 +36,7 @@ def get_default_config():
|
||||||
'''
|
'''
|
||||||
default_config = {}
|
default_config = {}
|
||||||
config = load_config()
|
config = load_config()
|
||||||
for k, v in config.iteritems():
|
for k, v in config.items():
|
||||||
if 'default' in v:
|
if 'default' in v:
|
||||||
default_config[k] = v['default']
|
default_config[k] = v['default']
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue