Browse Source

Class selector and pep check

changes/13/749213/1
Liam Young 2 years ago
parent
commit
2bb403f7ad
  1. 1
      .gitignore
  2. 14
      ops_openstack.py
  3. 5
      test-requirements.txt
  4. 82
      tox.ini

1
.gitignore vendored

@ -0,0 +1 @@
.tox

14
ops_openstack.py

@ -17,7 +17,6 @@ from ops.model import (
)
import charmhelpers.contrib.openstack.utils as os_utils
import logging
import copy
# Stolen from charms.ceph
UCA_CODENAME_MAP = {
@ -40,6 +39,7 @@ UCA_CODENAME_MAP = {
_releases = {}
logger = logging.getLogger()
class OSBaseCharm(CharmBase):
state = StoredState()
@ -76,7 +76,7 @@ class OSBaseCharm(CharmBase):
missing_relations = []
for relation in self.REQUIRED_RELATIONS:
if not self.framework.model.get_relation(relation):
missing_relations.append(relation)
missing_relations.append(relation)
if missing_relations:
self.model.unit.status = BlockedStatus(
'Missing relations: {}'.format(', '.join(missing_relations)))
@ -114,7 +114,8 @@ class OSBaseCharm(CharmBase):
def charm_class(cls):
_releases[cls.release] = {'deb': cls}
_releases[cls.release] = {'deb': cls}
# Adapted from charms_openstack.charm.core
def get_charm_class(release=None, package_type='deb', all_releases=None,
@ -166,6 +167,7 @@ def get_charm_class(release=None, package_type='deb', all_releases=None,
raise RuntimeError("Release {} is not supported".format(release))
return cls
# Adapted from charms_openstack.charm.core
def get_charm_instance(release=None, package_type='deb', all_releases=None,
*args, **kwargs):
@ -175,6 +177,7 @@ def get_charm_instance(release=None, package_type='deb', all_releases=None,
all_releases=all_releases,
*args, **kwargs)(release=release, *args, **kwargs)
def get_charm_class_for_release():
_origin = None
current_model = ops.model.ModelBackend()
@ -185,8 +188,9 @@ def get_charm_class_for_release():
_origin = config['openstack-origin']
else:
_origin = 'distro'
target_releae = os_utils.get_os_codename_install_source(_origin)
# XXX Make this support openstack and ceph
target_release = os_utils.get_os_codename_install_source(_origin)
# Check for a cepch charm match first:
ceph_release = UCA_CODENAME_MAP[target_releae]
ceph_release = UCA_CODENAME_MAP[target_release]
releases = sorted(list(set(UCA_CODENAME_MAP.values())))
return get_charm_class(release=ceph_release, all_releases=releases)

5
test-requirements.txt

@ -0,0 +1,5 @@
# Lint and unit test requirements
flake8>=2.2.4,<=2.4.1
mock>=1.2
nose>=1.3.7
coverage>=3.6

82
tox.ini

@ -0,0 +1,82 @@
# Source charm: ./tox.ini
# This file is managed centrally by release-tools and should not be modified
# within individual charm repos. See the 'global' dir contents for available
# choices of tox.ini for OpenStack Charms:
# https://github.com/openstack-charmers/release-tools
[tox]
skipsdist = True
envlist = pep8,py3
# NOTE: Avoid build/test env pollution by not enabling sitepackages.
sitepackages = False
# NOTE: Avoid false positives by not skipping missing interpreters.
skip_missing_interpreters = False
[testenv]
setenv = VIRTUAL_ENV={envdir}
PYTHONHASHSEED=0
TERM=linux
install_command =
pip install {opts} {packages}
deps =
-r{toxinidir}/requirements.txt
[testenv:py3]
basepython = python3
deps = -r{toxinidir}/test-requirements.txt
commands = stestr run --slowest {posargs}
[testenv:py35]
basepython = python3.5
deps = -r{toxinidir}/test-requirements.txt
commands = stestr run --slowest {posargs}
[testenv:py36]
basepython = python3.6
deps = -r{toxinidir}/test-requirements.txt
commands = stestr run --slowest {posargs}
[testenv:py37]
basepython = python3.7
deps = -r{toxinidir}/test-requirements.txt
commands = stestr run --slowest {posargs}
[testenv:pep8]
basepython = python3
deps = -r{toxinidir}/test-requirements.txt
commands = flake8 {posargs} .
[testenv:cover]
# Technique based heavily upon
# https://github.com/openstack/nova/blob/master/tox.ini
basepython = python3
deps = -r{toxinidir}/test-requirements.txt
setenv =
{[testenv]setenv}
PYTHON=coverage run
commands =
coverage erase
stestr run --slowest {posargs}
coverage combine
coverage html -d cover
coverage xml -o cover/coverage.xml
coverage report
[coverage:run]
branch = True
concurrency = multiprocessing
parallel = True
source =
.
omit =
.tox/*
*/charmhelpers/*
unit_tests/*
[testenv:venv]
basepython = python3
commands = {posargs}
[flake8]
# E402 ignore necessary for path append before sys module import in actions
ignore = E402,W504
Loading…
Cancel
Save