Skip to content

Commit

Permalink
Improve running Molecule tests locally
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisdenny authored and openshift-merge-bot[bot] committed Jul 9, 2024
1 parent 687e80e commit 3d799fb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ run_ctx_pre_commit: ci_ctx ## Run pre-commit check in a container
"make pre_commit_nodeps BASEDIR=$(BASEDIR)" ;

.PHONY: run_ctx_molecule
run_ctx_molecule: export MOLECULE_CONFIG=".config/molecule/config_local.yml"
run_ctx_molecule: ci_ctx ## Run molecule check in a container
podman run \
--rm \
Expand All @@ -170,6 +171,7 @@ run_ctx_molecule: ci_ctx ## Run molecule check in a container
--user root \
-e MOLECULE_CONFIG=${MOLECULE_CONFIG} \
-e TEST_ALL_ROLES=$(TEST_ALL_ROLES) \
-e TEST_SINGLE_ROLE=$(TEST_SINGLE_ROLE) \
${CI_CTX_NAME} \
bash -c \
"make molecule_nodeps MOLECULE_CONFIG=${MOLECULE_CONFIG}";
Expand Down
14 changes: 10 additions & 4 deletions scripts/run_molecule
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,21 @@ MOLECULE_CONFIG=${MOLECULE_CONFIG:-.config/molecule/config_podman.yml}
TEST_ALL_ROLES=${TEST_ALL_ROLES:-no}
TEST_VERBOSITY=${TEST_VERBOSITY:-'--debug'}
# Run local test
(test -d ${ROLE_DIR} || (echo 'No such directory: ${ROLE_DIR}' && exit 1) ) || exit 1
(test -d "${ROLE_DIR}" || (echo "No such directory: ${ROLE_DIR}" && exit 1) ) || exit 1

pushd "${ROLE_DIR}"
local_roledir=$(echo $ROLE_DIR | sed 's|\.\?\./||g')

# Find what roles were modified
ROLES_LIST=$(git diff --dirstat=files,0,cumulative HEAD^..HEAD | sed "s|^[ 0-9.]\+% \(${local_roledir}\)\?||g" | cut -d/ -f1 | sort -u )
if [ ${TEST_ALL_ROLES} == 'yes' ]; then
if [[ ${TEST_ALL_ROLES} == 'yes' ]]; then
ROLES_LIST=$(ls -1)
elif [[ -n ${TEST_SINGLE_ROLE} ]]; then
(test -d "${TEST_SINGLE_ROLE}" || (echo "No such directory: ${TEST_SINGLE_ROLE}" && exit 1) ) || exit 1
ROLES_LIST=${TEST_SINGLE_ROLE}
fi

# Find what roles were modified
if [[ -z ${ROLES_LIST} ]]; then
ROLES_LIST=$(git diff --dirstat=files,0,cumulative HEAD^..HEAD | sed "s|^[ 0-9.]\+% \(${local_roledir}\)\?||g" | cut -d/ -f1 | sort -u )
fi

git clone https://github.com/openstack-k8s-operators/install_yamls /root/src/github.com/openstack-k8s-operators/install_yamls || true
Expand Down

0 comments on commit 3d799fb

Please sign in to comment.