Migrate charm to python3 only runtime
Change-Id: I921f3e2fc8250ca7250ca7dfc47e12644ce4ef98
This commit is contained in:
parent
df6b239526
commit
9802731e58
@ -1,4 +1,3 @@
|
|||||||
- project:
|
- project:
|
||||||
templates:
|
templates:
|
||||||
- python-charm-jobs
|
- python35-charm-jobs
|
||||||
- openstack-python35-jobs-nonvoting
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
repo: https://github.com/juju/charm-helpers
|
repo: https://github.com/juju/charm-helpers
|
||||||
destination: hooks/charmhelpers
|
destination: charmhelpers
|
||||||
include:
|
include:
|
||||||
- core
|
- core
|
||||||
- osplatform
|
- osplatform
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# Copyright 2016 Canonical Ltd
|
# Copyright 2016 Canonical Ltd
|
||||||
#
|
#
|
||||||
@ -14,60 +14,72 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import json
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from cinder_utils import (
|
|
||||||
register_configs,
|
|
||||||
restart_map,
|
|
||||||
scrub_old_style_ceph,
|
|
||||||
PACKAGES,
|
|
||||||
REQUIRED_INTERFACES,
|
|
||||||
VERSION_PACKAGE,
|
|
||||||
CEPH_CONF,
|
|
||||||
)
|
|
||||||
from cinder_contexts import (
|
|
||||||
CephSubordinateContext,
|
|
||||||
ceph_config_file,
|
|
||||||
)
|
|
||||||
from charmhelpers.contrib.openstack.context import CephContext
|
|
||||||
|
|
||||||
|
_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.contrib.openstack.alternatives import remove_alternative
|
||||||
|
from charmhelpers.contrib.openstack.context import CephContext
|
||||||
|
from charmhelpers.contrib.openstack.utils import (
|
||||||
|
clear_unit_paused,
|
||||||
|
clear_unit_upgrading,
|
||||||
|
os_application_version_set,
|
||||||
|
set_os_workload_status,
|
||||||
|
set_unit_paused,
|
||||||
|
set_unit_upgrading,
|
||||||
|
)
|
||||||
|
from charmhelpers.contrib.storage.linux.ceph import (
|
||||||
|
CephBrokerRq,
|
||||||
|
delete_keyring,
|
||||||
|
ensure_ceph_keyring,
|
||||||
|
is_request_complete,
|
||||||
|
send_request_if_needed,
|
||||||
|
)
|
||||||
from charmhelpers.core.hookenv import (
|
from charmhelpers.core.hookenv import (
|
||||||
Hooks,
|
|
||||||
UnregisteredHookError,
|
|
||||||
config,
|
config,
|
||||||
service_name,
|
Hooks,
|
||||||
relation_set,
|
is_leader,
|
||||||
relation_ids,
|
|
||||||
status_set,
|
|
||||||
log,
|
|
||||||
leader_get,
|
leader_get,
|
||||||
leader_set,
|
leader_set,
|
||||||
is_leader,
|
log,
|
||||||
|
relation_ids,
|
||||||
|
relation_set,
|
||||||
|
service_name,
|
||||||
|
status_set,
|
||||||
|
UnregisteredHookError,
|
||||||
)
|
)
|
||||||
from charmhelpers.fetch import apt_install, apt_update
|
|
||||||
from charmhelpers.core.host import (
|
from charmhelpers.core.host import (
|
||||||
restart_on_change,
|
restart_on_change,
|
||||||
service_restart,
|
service_restart,
|
||||||
)
|
)
|
||||||
from charmhelpers.contrib.openstack.alternatives import remove_alternative
|
from charmhelpers.fetch import apt_install, apt_update
|
||||||
from charmhelpers.contrib.storage.linux.ceph import (
|
|
||||||
send_request_if_needed,
|
|
||||||
is_request_complete,
|
|
||||||
ensure_ceph_keyring,
|
|
||||||
CephBrokerRq,
|
|
||||||
delete_keyring,
|
|
||||||
)
|
|
||||||
from charmhelpers.payload.execd import execd_preinstall
|
from charmhelpers.payload.execd import execd_preinstall
|
||||||
from charmhelpers.contrib.openstack.utils import (
|
|
||||||
set_os_workload_status,
|
from cinder_contexts import (
|
||||||
os_application_version_set,
|
ceph_config_file,
|
||||||
set_unit_paused,
|
CephSubordinateContext,
|
||||||
set_unit_upgrading,
|
)
|
||||||
clear_unit_paused,
|
from cinder_utils import (
|
||||||
clear_unit_upgrading,
|
CEPH_CONF,
|
||||||
|
PACKAGES,
|
||||||
|
register_configs,
|
||||||
|
REQUIRED_INTERFACES,
|
||||||
|
restart_map,
|
||||||
|
scrub_old_style_ceph,
|
||||||
|
VERSION_PACKAGE,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,31 +12,22 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from tempfile import NamedTemporaryFile
|
from tempfile import NamedTemporaryFile
|
||||||
|
|
||||||
|
from charmhelpers.contrib.openstack import (
|
||||||
|
context,
|
||||||
|
templating,
|
||||||
|
)
|
||||||
|
from charmhelpers.contrib.openstack.alternatives import install_alternative
|
||||||
|
from charmhelpers.contrib.openstack.utils import get_os_codename_package
|
||||||
from charmhelpers.core.hookenv import (
|
from charmhelpers.core.hookenv import (
|
||||||
|
hook_name,
|
||||||
relation_ids,
|
relation_ids,
|
||||||
service_name,
|
service_name,
|
||||||
hook_name,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from charmhelpers.contrib.openstack import (
|
|
||||||
templating,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
|
|
||||||
from charmhelpers.contrib.openstack.utils import (
|
|
||||||
get_os_codename_package,
|
|
||||||
)
|
|
||||||
|
|
||||||
from charmhelpers.contrib.openstack.alternatives import install_alternative
|
|
||||||
from charmhelpers.core.host import mkdir
|
from charmhelpers.core.host import mkdir
|
||||||
|
|
||||||
|
|
||||||
@ -89,7 +80,7 @@ def register_configs():
|
|||||||
# lower priority that both of these but thats OK
|
# lower priority that both of these but thats OK
|
||||||
if not os.path.exists(ceph_config_file()):
|
if not os.path.exists(ceph_config_file()):
|
||||||
# touch file for pre-templated generation
|
# touch file for pre-templated generation
|
||||||
open(ceph_config_file(), 'w').close()
|
open(ceph_config_file(), 'wt').close()
|
||||||
install_alternative(os.path.basename(CEPH_CONF),
|
install_alternative(os.path.basename(CEPH_CONF),
|
||||||
CEPH_CONF, ceph_config_file())
|
CEPH_CONF, ceph_config_file())
|
||||||
CONFIG_FILES[ceph_config_file()] = {
|
CONFIG_FILES[ceph_config_file()] = {
|
||||||
@ -113,7 +104,7 @@ def restart_map():
|
|||||||
that should be restarted when file changes.
|
that should be restarted when file changes.
|
||||||
'''
|
'''
|
||||||
_map = []
|
_map = []
|
||||||
for f, ctxt in CONFIG_FILES.iteritems():
|
for f, ctxt in CONFIG_FILES.items():
|
||||||
svcs = []
|
svcs = []
|
||||||
for svc in ctxt['services']:
|
for svc in ctxt['services']:
|
||||||
svcs.append(svc)
|
svcs.append(svc)
|
||||||
@ -130,11 +121,11 @@ def scrub_old_style_ceph():
|
|||||||
# NOTE: purge any CEPH_ARGS data from /etc/environment
|
# NOTE: purge any CEPH_ARGS data from /etc/environment
|
||||||
env_file = '/etc/environment'
|
env_file = '/etc/environment'
|
||||||
ceph_match = re.compile("^CEPH_ARGS.*").search
|
ceph_match = re.compile("^CEPH_ARGS.*").search
|
||||||
with open(env_file, 'r') as input_file:
|
with open(env_file, 'rt') as input_file:
|
||||||
with NamedTemporaryFile(mode='w',
|
with NamedTemporaryFile(mode='wt',
|
||||||
delete=False,
|
delete=False,
|
||||||
dir=os.path.dirname(env_file)) as outfile:
|
dir=os.path.dirname(env_file)) as outfile:
|
||||||
for line in input_file:
|
for line in input_file:
|
||||||
if not ceph_match(line):
|
if not ceph_match(line):
|
||||||
print(line, end='', file=outfile)
|
print(line, end='', file=outfile)
|
||||||
os.rename(outfile.name, input_file.name)
|
os.rename(outfile.name, input_file.name)
|
||||||
|
@ -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}
|
||||||
|
@ -730,6 +730,12 @@ class CinderCephBasicDeployment(OpenStackAmuletDeployment):
|
|||||||
def test_500_ceph_alternatives_cleanup(self):
|
def test_500_ceph_alternatives_cleanup(self):
|
||||||
"""Check ceph alternatives are removed when ceph-mon
|
"""Check ceph alternatives are removed when ceph-mon
|
||||||
relation is broken"""
|
relation is broken"""
|
||||||
|
# Skip this test if release is less than xenial_ocata as in that case
|
||||||
|
# cinder HAS a relation with ceph directly and this test would fail
|
||||||
|
if self._get_openstack_release() < self.xenial_ocata:
|
||||||
|
u.log.debug("No checking 500 ceph alternatives as "
|
||||||
|
"/etc/ceph/ceph.conf will exist.")
|
||||||
|
return
|
||||||
u.log.debug('Checking ceph alternatives are removed '
|
u.log.debug('Checking ceph alternatives are removed '
|
||||||
'upon broken ceph-mon relation')
|
'upon broken ceph-mon relation')
|
||||||
ceph_dir = self.cinder_ceph_sentry.directory_listing('/etc/ceph')
|
ceph_dir = self.cinder_ceph_sentry.directory_listing('/etc/ceph')
|
||||||
|
3
tox.ini
3
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,6 +20,7 @@ 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
|
||||||
|
commands = /bin/true
|
||||||
|
|
||||||
[testenv:py35]
|
[testenv:py35]
|
||||||
basepython = python3.5
|
basepython = python3.5
|
||||||
|
@ -12,5 +12,21 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
sys.path.append('hooks')
|
|
||||||
|
_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)
|
||||||
|
@ -168,12 +168,13 @@ class TestCinderHooks(CharmTestCase):
|
|||||||
def test_ceph_broken(self, mock_config):
|
def test_ceph_broken(self, mock_config):
|
||||||
self.CONFIGS.complete_contexts.return_value = ['ceph']
|
self.CONFIGS.complete_contexts.return_value = ['ceph']
|
||||||
self.service_name.return_value = 'cinder-ceph'
|
self.service_name.return_value = 'cinder-ceph'
|
||||||
hooks.hooks.execute(['hooks/ceph-relation-changed'])
|
with patch.object(hooks, 'CEPH_CONF', new="/some/random/file"):
|
||||||
hooks.hooks.execute(['hooks/ceph-relation-broken'])
|
hooks.hooks.execute(['hooks/ceph-relation-changed'])
|
||||||
|
hooks.hooks.execute(['hooks/ceph-relation-broken'])
|
||||||
self.delete_keyring.assert_called_with(service='cinder-ceph')
|
self.delete_keyring.assert_called_with(service='cinder-ceph')
|
||||||
self.assertTrue(self.CONFIGS.write_all.called)
|
self.assertTrue(self.CONFIGS.write_all.called)
|
||||||
self.remove_alternative.assert_called_with(
|
self.remove_alternative.assert_called_with(
|
||||||
os.path.basename(self.CEPH_CONF),
|
os.path.basename("/some/random/file"),
|
||||||
self.ceph_config_file())
|
self.ceph_config_file())
|
||||||
|
|
||||||
@patch('charmhelpers.core.hookenv.config')
|
@patch('charmhelpers.core.hookenv.config')
|
||||||
|
@ -49,7 +49,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
Block a user