Skip to content

Commit

Permalink
Merge pull request #90 from scality/test-scenarios
Browse files Browse the repository at this point in the history
Rework tests layout
  • Loading branch information
NicolasT committed Jun 27, 2018
2 parents 423b15f + 9efdb39 commit 17c835c
Show file tree
Hide file tree
Showing 36 changed files with 3,591 additions and 135 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ shell: $(VENV_EXISTS) $(REQUIREMENTS_INSTALLED) $(KUBECTL) $(HELM) $(BASHRC) ##
bash --rcfile $(BASHRC); \
elif test -e "$(C)"; then \
# A script \
bash --rcfile $(BASHRC) "$(C)"; \
bash --rcfile $(BASHRC) -i "$(C)"; \
else \
# A command \
bash --rcfile $(BASHRC) -c "$(C)"; \
bash --rcfile $(BASHRC) -i -c "$(C)"; \
fi
.PHONY: shell

Expand Down
57 changes: 2 additions & 55 deletions eve/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,60 +30,7 @@ stages:
retryFetch: true
haltOnFailure: true
- ShellCommand:
name: 'create loopback blockdevice and configure VM'
name: 'Run test-suite'
haltOnFailure: true
command: |-
sudo ./eve/single_node/setup/single_node.sh
- ShellCommand:
name: 'Create virtual env'
haltOnFailure: true
command: |-
make shell
- ShellCommand:
name: 'Run the install with ansible'
haltOnFailure: true
command: >-
./.shell-env/metal-k8s/bin/ansible-playbook
-i eve/single_node/
metal-k8s.yml --skip elasticsearch
env:
ANSIBLE_FORCE_COLOR: 'true'
- ShellCommand:
name: 'Run sample kubectl command'
haltOnFailure: true
command: |-
export PATH=${PATH}:/usr/local/bin
kubectl get nodes
env: &env_kubeconfig
KUBECONFIG: inventories/single-node-ci/artifacts/admin.conf
- ShellCommand:
name: 'Test storage'
haltOnFailure: true
command: |-
export PATH=${PATH}:/usr/local/bin
make test-simple-storage
workdir: build/tests
env: *env_kubeconfig
- ShellCommand:
name: 'Verify that some pv are in released state'
command: |-
export PATH=${PATH}:/usr/local/bin
kubectl get pv
kubectl get pv -o jsonpath={.items[*].status.phase} | grep 'Released' > /dev/null
env: *env_kubeconfig
- ShellCommand:
name: 'Reclaim storage'
haltOnFailure: true
command: >-
./.shell-env/metal-k8s/bin/ansible-playbook
-i eve/single_node/
reclaim-storage.yml
env:
ANSIBLE_FORCE_COLOR: 'true'
- ShellCommand:
name: 'Verify that no pv are in released state'
command: |-
export PATH=${PATH}:/usr/local/bin
kubectl get pv
! kubectl get pv -o jsonpath={.items[*].status.phase}| grep 'Released' > /dev/null
env: *env_kubeconfig
bash ./vendor/bash_unit/bash_unit tests/single-node/test.sh
10 changes: 0 additions & 10 deletions eve/single_node/setup/single_node.sh

This file was deleted.

16 changes: 0 additions & 16 deletions tests/Makefile

This file was deleted.

File renamed without changes.
105 changes: 105 additions & 0 deletions tests/single-node/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
top_srcdir="$(realpath "$(pwd)/../..")"

ANSIBLE_FORCE_COLOR=true
export ANSIBLE_FORCE_COLOR

make_shell() {
make --no-print-directory -C "${top_srcdir}" shell C="$*"
}

die() {
exit 1
}

setup_suite() {
echo "Creating loopback block-device and configuring VM"
sudo truncate -s 20G /kube-lvm || die
sudo losetup /dev/loop0 /kube-lvm || die

echo "Disabling iptables"
sudo systemctl disable --now iptables || die
sudo systemctl disable --now ip6tables || die
sudo iptables -F || die
sudo iptables -X || die

echo "Creating shell environment"
make_shell true

echo "Deploy the cluster"
make_shell ansible-playbook -i "$(pwd)/inventory" metal-k8s.yml --skip elasticsearch || die

KUBECONFIG=$(pwd)/inventory/artifacts/admin.conf
export KUBECONFIG

echo "Run a sample kubectl command"
make_shell kubectl get nodes
}

test_reclaim_storage() {
echo "Listing all PVs before test (some should be available)"
make_shell kubectl get pv

echo "Running simple Pod with PersistentVolumeClaim"
make_shell kubectl apply -f - << EOF
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: testclaim
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 2Gi
---
apiVersion: v1
kind: Pod
metadata:
name: test-pv
spec:
restartPolicy: Never
containers:
- name: test-pv
image: busybox
command: ['/bin/sh']
args:
- "-c"
- "mount | grep /var/test_pv && touch /var/test_pv/foo"
volumeMounts:
- name: test-volume
mountPath: /var/test_pv
volumes:
- name: test-volume
persistentVolumeClaim:
claimName: testclaim
EOF

echo "Wait for Pod to exit"
#TODO This could loop forever...
until make_shell kubectl get pods test-pv -o jsonpath='{.status.phase}' | grep -E '(Failed|Succeeded)'; do
echo "Sleeping..."
sleep 1
done

RESULT=$(make_shell kubectl get pods test-pv -o jsonpath='{.status.phase}')
echo "Pod exited, listing all PVs:"
make_shell kubectl get pv

echo "Cleaning up resources"
make_shell kubectl delete pod test-pv
make_shell kubectl delete pvc testclaim

assert_equals "Succeeded" "${RESULT}"

echo "Verify some PVs are in Released state"
assert 'make_shell kubectl get pv -o jsonpath={.items[*].status.phase} | grep Released > /dev/null' \
"No PVs in Released state"

echo "Reclaim storage"
make_shell ansible-playbook -i "$(pwd)/inventory" reclaim-storage.yml

echo "Verify that no PV is in released state"
assert_fails 'make_shell kubectl get pv -o jsonpath={.items[*].status.phase} | grep Released > /dev/null' \
"PVs in Released state found"
}
32 changes: 0 additions & 32 deletions tests/storage/test_pv.yml

This file was deleted.

20 changes: 0 additions & 20 deletions tests/test-simple-storage.sh

This file was deleted.

6 changes: 6 additions & 0 deletions third-party.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ modules:
repository: https://github.com/kubernetes-incubator/kubespray.git
ref: master
license: Apache-2.0
- path: vendor/bash_unit
source:
type: git-subtree
repository: https://github.com/pgrange/bash_unit.git
ref: v1.6.1
license: GPL-3.0-or-later

charts:
- role: kube_heapster
Expand Down
1 change: 1 addition & 0 deletions vendor/bash_unit/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bash_unit filter=insert_tag
2 changes: 2 additions & 0 deletions vendor/bash_unit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.swp
token
46 changes: 46 additions & 0 deletions vendor/bash_unit/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
**bash unit testing enterprise edition framework for professionals ![bash_unit](img/bu_50.png)**

If you like bash_unit and want to contribute, you can do so in one of the
following ways (order might matter).

# Spread the word

Talking about bash_unit is a very welcomed contribution.

Share your success with bash_unit on your blog, twitter, stackoverflow...

Nice words to share your experience with bash_unit is always appreciated.
If you want to say something nice about bash_unit but can not think of a
place for that right now, just add a comment to
[issue #37](https://github.com/pgrange/bash_unit/issues/37).

Starring the project is also appreciated.

# Suggest improvements

When you see something that is not working with bash_unit, or if you feel
something is missing, open an
[issue](https://github.com/pgrange/bash_unit/issues).

Opening issues helps improving bash_unit.

# Contribute code

If you use a tool like bash_unit, odds are high that you already heard
about software development. Just code the improvement you have in mind
and create a pull-request.

You can contribute with new features you think are missing but you can
also find inspiration with the
[open issues](https://github.com/pgrange/bash_unit/issues) of bash_unit.

See [how to contribute code](CONTRIBUTING_CODE.md).

# Donate

bash_unit is free software I develop during my (not so) free time. If you feel
bash_unit is helpfull enough to you that you want to compensate for some of
the time spent developing or promoting it, you can contribute with your money
on liberapay:

[![liberapay](https://liberapay.com/assets/widgets/donate.svg)](https://liberapay.com/bash_unit/donate)
3 changes: 3 additions & 0 deletions vendor/bash_unit/CONTRIBUTING_CODE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
To perform a new release, run ./release in current directory.

See help for more informations.

0 comments on commit 17c835c

Please sign in to comment.