sunbeam-charms/run_tox.sh
Hemanth Nakkina df70e376ff
Add zuuljobs
* Add sunbeam project template to run pep8, py3 tests
* Add zuul.d/zuul.yaml to run pep8, py3, cover tests
* Update charmcraft and requirements for each charm
* Add global tox.ini to invoke fmt, pep8, py3, cover,
  build
* Add gitreview file
* Fix py3 test failures in ciner-ceph-k8s, glance-k8s,
  openstack-exporter
* Add jobs for charm builds using files option so that
  job is invoked if files within the component are
  modified. Add charm builds to both check and gate
  pipeline.
* Make function tests as part of global. Split the function
  tests into core, ceph, caas, misc mainly to accomodate
  function tests to run on 8GB. Add function tests as
  part of check pipeline.
* Add zuul job to publish charms in promote pipeline
  Add charmhub token as secret that can be used to
  publish charms.
  Note: Charmhub token is generated with ttl of 90 days.
* Run tox formatting
* Make .gitignore, .jujuignore, .stestr.conf global and
  remove the files from all charms.
* Make libs and templates global. Split libs to internal
  and external so that internal libs can adhere to
  sunbeam formatting styles.
* Add script to copy common files necessary libs, config
  templates, stestr conf, jujuignore during py3 tests
  and charm builds.
* Tests for keystone-ldap-k8s are commented due to
  intermittent bug LP#2045206

Change-Id: I804ca64182c109d16bd820ac00f129aa6dcf4496
2023-11-30 15:32:39 +05:30

111 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
source common.sh
if [[ $1 == "fmt" ]];
then
src_path_array=$(ls -d -1 "charms/"**/src)
tst_path_array=$(ls -d -1 "charms/"**/tests)
lib_path_array=$(ls -d -1 "charms/"**/lib)
src_path="${src_path_array[*]}"
tst_path="${tst_path_array[*]}"
lib_path="${lib_path_array[*]}"
isort ${src_path} ${tst_path}
black --config pyproject.toml ${src_path} ${tst_path}
elif [[ $1 == "pep8" ]];
then
src_path_array=$(ls -d -1 "charms/"**/src)
tst_path_array=$(ls -d -1 "charms/"**/tests)
src_path="${src_path_array[*]}"
tst_path="${tst_path_array[*]}"
codespell ${src_path} ${tst_path}
pflake8 --config pyproject.toml ${src_path} ${tst_path}
isort --check-only --diff ${src_path} ${tst_path}
black --config pyproject.toml --check --diff ${src_path} ${tst_path}
elif [[ $1 =~ ^(py3|py310|py311)$ ]];
then
# Run py3 on ops-sunbeam
pushd ops-sunbeam
stestr run --slowest || exit 1
popd
# Run py3 on all sunbeam charms
charms=($(ls charms))
for charm in ${charms[@]}; do
push_common_files $charm || exit 1
pushd charms/$charm
PYTHONPATH=./src:./lib stestr run --slowest || exit 1
popd
pop_common_files $charm || exit 1
done
elif [[ $1 == "cover" ]];
then
coverage erase
# Run coverage on ops-sunbeam
pushd ops-sunbeam
coverage erase
PYTHON="coverage run --omit .tox/*,tests/*" stestr run --slowest || exit 1
coverage combine
popd
# Run coverage on all sunbeam charms
charms=($(ls charms))
for charm in ${charms[@]}; do
push_common_files $charm || exit 1
pushd charms/$charm
coverage erase
PYTHONPATH=./src:./lib:../../ops-sunbeam PYTHON="coverage run --omit .tox/*,tests/*,src/templates/*" stestr run --slowest || exit 1
coverage combine
popd
done
# Prepare coverage report
coverage combine charms/*/.coverage ops-sunbeam/.coverage
coverage html -d cover
coverage xml -o cover/coverage.xml
coverage report
# Common files should be deleted after coverage combine
for charm in ${charms[@]}; do
pop_common_files $charm || exit 1
done
elif [[ $1 == "build" ]];
then
if [[ $# != 2 ]];
then
echo "Command format: tox -e build <charm>"
exit 1
fi
charm=$2
charms=($(ls charms))
if [[ ! ${charms[@]} =~ $charm ]];
then
echo "Argument should be one of ${charms[@]}";
exit 1
fi
push_common_files $charm || exit 1
pushd charms/$charm
charmcraft -v pack || exit 1
if [[ -e "${charm}.charm" ]];
then
echo "Removing bad downloaded charm maybe?"
rm "${charm}.charm"
fi
echo "Renaming charm ${charm}_*.charm to ${charm}.charm"
mv ${charm}_*.charm ${charm}.charm
popd
pop_common_files $charm || exit 1
else
echo "tox argument should be one of pep8, py3, py310, py311, cover";
exit 1
fi