summaryrefslogtreecommitdiff
diff options
authorDrew Freiberger <drew.freiberger@canonical.com>2020-07-31 16:38:59 -0500
committerDrew Freiberger <drew.freiberger@canonical.com>2020-07-31 16:38:59 -0500
commit46ff090b40837d0d82e5349cd370e7ca28d20a32 (patch)
tree4a1be9c1e4ce9d0bab30b8543686151f4654f720
parent92a24f9739e46b8ac0cd09609ae0d763f0ae31ec (diff)
Imported standard Makefile and tox.ini and fixed up testsmakefile-20.08
-rw-r--r--.gitignore46
-rw-r--r--.jujuignore1
-rw-r--r--Makefile89
-rw-r--r--tests/bundles/overlays/local-charm-overlay.yaml.j23
-rw-r--r--tests/functional/requirements.txt (renamed from tests/test_requirements.txt)0
-rw-r--r--tests/functional/tests/bundles/bionic-shard.yaml (renamed from tests/bundles/bionic-shard.yaml)0
-rw-r--r--tests/functional/tests/bundles/bionic.yaml (renamed from tests/bundles/bionic.yaml)0
-rw-r--r--tests/functional/tests/bundles/focal.yaml (renamed from tests/bundles/focal.yaml)0
-rw-r--r--tests/functional/tests/bundles/overlays/bionic-shard.yaml.j2 (renamed from tests/bundles/overlays/bionic-shard.yaml.j2)0
-rw-r--r--tests/functional/tests/bundles/overlays/local-charm-overlay.yaml.j23
-rw-r--r--tests/functional/tests/bundles/xenial.yaml (renamed from tests/bundles/xenial.yaml)0
-rw-r--r--tests/functional/tests/tests.yaml (renamed from tests/tests.yaml)0
-rw-r--r--tests/functional/tests/tests_mongodb.py (renamed from tests/tests_mongodb.py)0
-rw-r--r--tests/unit/__init__.py (renamed from unit_tests/__init__.py)0
-rw-r--r--tests/unit/requirements.txt (renamed from test_requirements.txt)0
-rw-r--r--tests/unit/test_hooks.py (renamed from unit_tests/test_hooks.py)0
-rw-r--r--tests/unit/test_utils.py (renamed from unit_tests/test_utils.py)0
-rw-r--r--tests/unit/test_write_log_rotate_config.py (renamed from unit_tests/test_write_log_rotate_config.py)0
-rw-r--r--tox.ini65
19 files changed, 139 insertions, 68 deletions
diff --git a/.gitignore b/.gitignore
index e6ff298..4bb6965 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,11 +1,39 @@
-.git
-.project
-.pydevproject
+# Juju files
+.unit-state.db
+
+layers/*
+interfaces/*
+
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# Tests files and dir
+.pytest_cache/
.coverage
-.settings
+.tox
+report/
+htmlcov/
+
+# Log files
+*.log
+
+# pycharm
.idea/
-*.pyc
-.tox/
-bin/*
-scripts/charm-helpers-sync.py
-exec.d/*
+
+# vi
+.*.swp
+
+# version data
+repo-info
+
+# Python builds
+deb_dist/
+dist/
+
+# Snaps
+*.snap
+
+# Builds
+.build/ \ No newline at end of file
diff --git a/.jujuignore b/.jujuignore
new file mode 100644
index 0000000..b7f1399
--- /dev/null
+++ b/.jujuignore
@@ -0,0 +1 @@
+.build \ No newline at end of file
diff --git a/Makefile b/Makefile
index fde3fc8..14580fe 100644
--- a/Makefile
+++ b/Makefile
@@ -1,44 +1,69 @@
-# This file is part of the mongodb charm.
-# Copyright (C) 2013 Canonical Ltd.
-#
-# This program is free software: you can redistribute it and/or modify it under
-# the terms of the GNU Affero General Public License version 3, as published by
-# the Free Software Foundation.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
-# SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-PYTHON := /usr/bin/env python3
-ACTIONS := $(shell grep -slE '\#!(.*)python3' actions/*)
-PROJECTPATH := $(realpath $(dir $(realpath $(firstword $(MAKEFILE_LIST)))))
+PYTHON := /usr/bin/python3
+PROJECTPATH=$(dir $(realpath $(MAKEFILE_LIST)))
+ifndef CHARM_BUILD_DIR
+ CHARM_BUILD_DIR=${PROJECTPATH}.build
+endif
+METADATA_FILE="metadata.yaml"
+CHARM_NAME=$(shell cat ${PROJECTPATH}/${METADATA_FILE} | grep -E '^name:' | awk '{print $$2}')
+
+help:
+ @echo "This project supports the following targets"
+ @echo ""
+ @echo " make help - show this text"
+ @echo " make clean - remove unneeded files"
+ @echo " make submodules - make sure that the submodules are up-to-date"
+ @echo " make submodules-update - update submodules to latest changes on remote branch"
+ @echo " make build - build the charm"
+ @echo " make release - run clean and build targets"
+ @echo " make lint - run flake8 and black"
+ @echo " make proof - run charm proof"
+ @echo " make unittests - run the tests defined in the unittest subdirectory"
+ @echo " make functional - run the tests defined in the functional subdirectory"
+ @echo " make test - run lint, proof, unittests and functional targets"
+ @echo ""
clean:
- git clean -fXd
+ @echo "Cleaning files"
+ @git clean -fXd
+ @echo "Cleaning existing build"
+ @rm -rf ${CHARM_BUILD_DIR}/${CHARM_NAME}
+
+submodules:
+ @echo "Cloning submodules"
+ @git submodule update --init --recursive
+
+submodules-update:
+ @echo "Pulling latest updates for submodules"
+ @git submodule update --init --recursive --remote --merge
+
+build:
+ @echo "Building charm to base directory ${CHARM_BUILD_DIR}/${CHARM_NAME}"
+ @-git describe --tags > ./repo-info
+ @mkdir -p ${CHARM_BUILD_DIR}/${CHARM_NAME}
+ @cp -a ./* ${CHARM_BUILD_DIR}/${CHARM_NAME}
+
+release: clean build
+ @echo "Charm is built at ${CHARM_BUILD_DIR}/${CHARM_NAME}"
lint:
- @echo Starting flake8...
+ @echo "Running lint checks"
@tox -e lint
-unit:
- @echo Starting unit tests...
- @tox -e unit
+proof:
+ @echo "Running charm proof"
+ @-charm proof
-functional:
- @echo Starting functional tests...
- @@CHARM_BUILD_DIR="$(PROJECTPATH)" tox -e functional
+unittests:
+ @echo "Running unit tests"
+ @tox -e unit
-test: lint unit functional
+functional: build
+ @echo "Executing functional tests in ${CHARM_BUILD_DIR}"
+ @CHARM_BUILD_DIR=${CHARM_BUILD_DIR} tox -e func
-sync:
- @mkdir -p bin
- @curl -o bin/charm_helpers_sync.py https://raw.githubusercontent.com/juju/charm-helpers/master/tools/charm_helpers_sync/charm_helpers_sync.py
- @$(PYTHON) bin/charm_helpers_sync.py -c charm-helpers-sync.yaml
+test: lint proof unittests functional
+ @echo "Charm ${CHARM_NAME} has been tested"
# The targets below don't depend on a file
-.PHONY: lint test unittest functional publish sync
+.PHONY: help submodules submodules-update clean build release lint proof unittests functional test
diff --git a/tests/bundles/overlays/local-charm-overlay.yaml.j2 b/tests/bundles/overlays/local-charm-overlay.yaml.j2
deleted file mode 100644
index 0a63173..0000000
--- a/tests/bundles/overlays/local-charm-overlay.yaml.j2
+++ /dev/null
@@ -1,3 +0,0 @@
-applications:
- {{ charm_name }}:
- charm: "{{ CHARM_BUILD_DIR }}"
diff --git a/tests/test_requirements.txt b/tests/functional/requirements.txt
index 9fbeeab..9fbeeab 100644
--- a/tests/test_requirements.txt
+++ b/tests/functional/requirements.txt
diff --git a/tests/bundles/bionic-shard.yaml b/tests/functional/tests/bundles/bionic-shard.yaml
index 215c095..215c095 100644
--- a/tests/bundles/bionic-shard.yaml
+++ b/tests/functional/tests/bundles/bionic-shard.yaml
diff --git a/tests/bundles/bionic.yaml b/tests/functional/tests/bundles/bionic.yaml
index cef11a1..cef11a1 100644
--- a/tests/bundles/bionic.yaml
+++ b/tests/functional/tests/bundles/bionic.yaml
diff --git a/tests/bundles/focal.yaml b/tests/functional/tests/bundles/focal.yaml
index e485f5e..e485f5e 100644
--- a/tests/bundles/focal.yaml
+++ b/tests/functional/tests/bundles/focal.yaml
diff --git a/tests/bundles/overlays/bionic-shard.yaml.j2 b/tests/functional/tests/bundles/overlays/bionic-shard.yaml.j2
index 8310b25..8310b25 100644
--- a/tests/bundles/overlays/bionic-shard.yaml.j2
+++ b/tests/functional/tests/bundles/overlays/bionic-shard.yaml.j2
diff --git a/tests/functional/tests/bundles/overlays/local-charm-overlay.yaml.j2 b/tests/functional/tests/bundles/overlays/local-charm-overlay.yaml.j2
new file mode 100644
index 0000000..e78574f
--- /dev/null
+++ b/tests/functional/tests/bundles/overlays/local-charm-overlay.yaml.j2
@@ -0,0 +1,3 @@
+applications:
+ {{ charm_name }}:
+ charm: "{{ CHARM_BUILD_DIR }}/{{ charm_name }}"
diff --git a/tests/bundles/xenial.yaml b/tests/functional/tests/bundles/xenial.yaml
index a17f8b7..a17f8b7 100644
--- a/tests/bundles/xenial.yaml
+++ b/tests/functional/tests/bundles/xenial.yaml
diff --git a/tests/tests.yaml b/tests/functional/tests/tests.yaml
index 6461753..6461753 100644
--- a/tests/tests.yaml
+++ b/tests/functional/tests/tests.yaml
diff --git a/tests/tests_mongodb.py b/tests/functional/tests/tests_mongodb.py
index dc50d8d..dc50d8d 100644
--- a/tests/tests_mongodb.py
+++ b/tests/functional/tests/tests_mongodb.py
diff --git a/unit_tests/__init__.py b/tests/unit/__init__.py
index 5dd2748..5dd2748 100644
--- a/unit_tests/__init__.py
+++ b/tests/unit/__init__.py
diff --git a/test_requirements.txt b/tests/unit/requirements.txt
index aaa5368..aaa5368 100644
--- a/test_requirements.txt
+++ b/tests/unit/requirements.txt
diff --git a/unit_tests/test_hooks.py b/tests/unit/test_hooks.py
index e97ef91..e97ef91 100644
--- a/unit_tests/test_hooks.py
+++ b/tests/unit/test_hooks.py
diff --git a/unit_tests/test_utils.py b/tests/unit/test_utils.py
index 583cce2..583cce2 100644
--- a/unit_tests/test_utils.py
+++ b/tests/unit/test_utils.py
diff --git a/unit_tests/test_write_log_rotate_config.py b/tests/unit/test_write_log_rotate_config.py
index ef1cd98..ef1cd98 100644
--- a/unit_tests/test_write_log_rotate_config.py
+++ b/tests/unit/test_write_log_rotate_config.py
diff --git a/tox.ini b/tox.ini
index 66228b4..cce4a51 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,44 +1,61 @@
[tox]
skipsdist=True
-envlist = unit, functional, lint
skip_missing_interpreters = True
+envlist = lint, unit, func
[testenv]
basepython = python3
setenv =
- PYTHONPATH = .
+ PYTHONPATH = {toxinidir}:{toxinidir}/lib/:{toxinidir}/hooks/
passenv =
HOME
+ PATH
CHARM_BUILD_DIR
+ PYTEST_KEEP_MODEL
+ PYTEST_CLOUD_NAME
+ PYTEST_CLOUD_REGION
+ PYTEST_MODEL
MODEL_SETTINGS
+ HTTP_PROXY
+ HTTPS_PROXY
+ NO_PROXY
+ SNAP_HTTP_PROXY
+ SNAP_HTTPS_PROXY
[testenv:lint]
-deps = -r{toxinidir}/test_requirements.txt
-commands = flake8 {posargs:hooks/ unit_tests/ tests/}
- charm-proof
-
-
-[testenv:unit]
-commands =
- nosetests -v -s --nologcapture --with-coverage unit_tests/ actions/
-deps = -r{toxinidir}/test_requirements.txt
-
-[testenv:functional]
-commands =
- functest-run-suite --keep-model
-deps = -r{toxinidir}/tests/test_requirements.txt
-
-[testenv:func-smoke]
commands =
- functest-run-suite --keep-model --smoke
-deps = -r{toxinidir}/tests/test_requirements.txt
+ flake8
+#TODO black --check --exclude "/(\.eggs|\.git|\.tox|\.venv|\.build|dist|charmhelpers|mod)/" .
+deps =
+ black
+ flake8
+#TODO flake8-docstrings
+#TODO flake8-import-order
+#TODO pep8-naming
+ flake8-colors
[flake8]
ignore = E402,E226,W504
exclude =
- hooks/charmhelpers,
- .git,
- __pycache__,
- .tox,
+ .git,
+ __pycache__,
+ .tox,
+ charmhelpers,
+ mod,
+ .build
+
+#TODO max-line-length = 88
max-line-length = 120
max-complexity = 10
+
+[testenv:unit]
+commands =
+ coverage run -m unittest discover -s {toxinidir}/tests/unit -v
+ coverage report --omit tests/*,mod/*,.tox/*
+ coverage html --omit tests/*,mod/*,.tox/*
+deps = -r{toxinidir}/tests/unit/requirements.txt
+
+[testenv:func]
+changedir = {toxinidir}/tests/functional
+commands = functest-run-suite {posargs}
+deps = -r{toxinidir}/tests/functional/requirements.txt