Skip to content

Commit 6968837

Browse files
majamassarinimfocko
andcommitted
Create Makefile for Vagrant related targets
Co-authored-by: Matej Focko <[email protected]>
1 parent 006a156 commit 6968837

File tree

2 files changed

+49
-36
lines changed

2 files changed

+49
-36
lines changed

Makefile

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ AP := ansible-playbook -vv -c local -i localhost, -e ansible_python_interpreter=
66
# "By default, Ansible runs as if --tags all had been specified."
77
# https://docs.ansible.com/ansible/latest/user_guide/playbooks_tags.html#special-tags
88
TAGS ?= all
9-
VAGRANT_SSH_PORT = "$(shell cd containers && vagrant ssh-config | awk '/Port/{print $$2}')"
10-
VAGRANT_SSH_USER = "$(shell cd containers && vagrant ssh-config | awk '/User/{print $$2}')"
11-
VAGRANT_SSH_GUEST = "$(shell cd containers && vagrant ssh-config | awk '/HostName/{print $$2}')"
12-
VAGRANT_SSH_IDENTITY_FILE = "$(shell cd containers && vagrant ssh-config | awk '/IdentityFile/{print $$2}')"
13-
VAGRANT_SSH_CONFIG = $(shell cd containers && vagrant ssh-config | awk 'NR>1 {print " -o "$$1"="$$2}')
14-
VAGRANT_SHARED_DIR = "/vagrant"
15-
16-
CENTOS_VAGRANT_BOX = CentOS-Stream-Vagrant-8-latest.x86_64.vagrant-libvirt.box
17-
CENTOS_VAGRANT_URL = https://cloud.centos.org/centos/8-stream/x86_64/images/$(CENTOS_VAGRANT_BOX)
189

1910
CRC_PULL_SECRET ?= "$(shell cat secrets/openshift-local-pull-secret.yml)"
2011

@@ -63,28 +54,11 @@ move-stable:
6354
[[ -d move_stable_repositories ]] || scripts/move_stable.py init
6455
scripts/move_stable.py move-all
6556

66-
oc-cluster-create:
67-
# vagrant pointer is broken...
68-
[[ -f $(CENTOS_VAGRANT_BOX) ]] || wget $(CENTOS_VAGRANT_URL)
69-
cd containers && vagrant up
70-
71-
oc-cluster-destroy:
72-
cd containers && vagrant destroy
73-
74-
oc-cluster-up:
75-
cd containers && vagrant up
76-
cd containers && vagrant ssh -c "cd $(VAGRANT_SHARED_DIR) && $(AP) --extra-vars user=vagrant playbooks/oc-cluster-run.yml"
77-
78-
oc-cluster-down:
79-
cd containers && vagrant halt
80-
81-
oc-cluster-ssh: oc-cluster-up
82-
ssh $(VAGRANT_SSH_CONFIG) localhost
83-
84-
test-deploy:
85-
# to be run inside VM where the oc cluster && tmt is running! Call make tmt-vagrant-tests instead from outside the vagrant machine.
57+
# to be run inside VM where the oc cluster && tmt is running!
58+
# cd containers; make tmt-vagrant-tests instead for testing in the vagrant machine.
8659
# SHARED_DIR could be /vagrant or /home/tmt/deployment, it depends on the VM where tmt is being run
8760
# look inside deployment.fmf to find out the value of SHARED_DIR
61+
test-deploy:
8862
DEPLOYMENT=dev $(AP) playbooks/generate-local-secrets.yml
8963
DEPLOYMENT=dev $(AP) -e '{"user": $(USER), "src_dir": $(SHARED_DIR)}' playbooks/test_deploy_setup.yml
9064
cd $(SHARED_DIR); DEPLOYMENT=dev $(AP) -e '{"container_engine": "podman", "registry": "default-route-openshift-image-registry.apps-crc.testing", "registry_user": "kubeadmin", "user": $(USER), "src_dir": $(SHARED_DIR)}' playbooks/test_deploy.yml
@@ -94,12 +68,6 @@ test-deploy:
9468
check-pull-secret:
9569
if [ ! -f secrets/openshift-local-pull-secret.yml ] && [ ! -n "$(CRC_PULL_SECRET)" ]; then echo "no pull secret available create secrets/openshift-local-pull-secret.yml file or set CRC_PULL_SECRET variable"; exit 1; else echo "pull secret found"; fi
9670

97-
# Execute tmt deployment test on a vagrant virtual machine
98-
# The virtual machine has to be already up and running,
99-
# using the target oc-cluster-up
100-
tmt-vagrant-test: check-pull-secret
101-
tmt run --all provision --how connect --user vagrant --guest $(VAGRANT_SSH_GUEST) --port $(VAGRANT_SSH_PORT) --key $(VAGRANT_SSH_IDENTITY_FILE) plan --name deployment/vagrant
102-
10371
# Execute tmt deployment test on a local virtual machine provisioned by tmt
10472
#
10573
# tmt local provisioned virtual machine have by default 2 cpu cores
@@ -110,7 +78,7 @@ tmt-vagrant-test: check-pull-secret
11078
# github action, there are no other ways (at the moment) to deal with
11179
# the secrets (in our case the pull_request Openshift Local secret).
11280
# For this reason the deployment/remote plan is not called by this file
113-
# but is called from the testing farm github action configured in this PR
81+
# instead it is called from the testing farm github action
11482
#
11583
# Useful tmt/virsh commands to debug this test are listed below
11684
# tmt run --id deployment --until execute

containers/Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
ANSIBLE_PYTHON ?= $(shell command -v /usr/bin/python3 2> /dev/null || echo /usr/bin/python2)
2+
AP := ansible-playbook -vv -c local -i localhost, -e ansible_python_interpreter=$(ANSIBLE_PYTHON)
3+
VAGRANT_SSH_PORT = "$(shell vagrant ssh-config | awk '/Port/{print $$2}')"
4+
VAGRANT_SSH_USER = "$(shell vagrant ssh-config | awk '/User/{print $$2}')"
5+
VAGRANT_SSH_GUEST = "$(shell vagrant ssh-config | awk '/HostName/{print $$2}')"
6+
VAGRANT_SSH_IDENTITY_FILE = "$(shell vagrant ssh-config | awk '/IdentityFile/{print $$2}')"
7+
VAGRANT_SSH_CONFIG = $(shell vagrant ssh-config | awk 'NR>1 {print " -o "$$1"="$$2}')
8+
VAGRANT_SHARED_DIR = "/vagrant"
9+
10+
# to be used when the vagrant box link is broken, should be kept in sync with the Vagrant file
11+
#CENTOS_VAGRANT_BOX = CentOS-Stream-Vagrant-8-latest.x86_64.vagrant-libvirt.box
12+
#CENTOS_VAGRANT_URL = https://cloud.centos.org/centos/8-stream/x86_64/images/$(CENTOS_VAGRANT_BOX)
13+
14+
CRC_PULL_SECRET ?= "$(shell cat secrets/openshift-local-pull-secret.yml)"
15+
16+
# for this command to work, you may need to:
17+
# sudo systemctl enable --now libvirtd
18+
# sudo systemctl enable --now virtnetworkd
19+
oc-cluster-create:
20+
if [ ! -z "$(CENTOS_VAGRANT_BOX)" ] && [ -f $(CENTOS_VAGRANT_BOX) ]; then wget $(CENTOS_VAGRANT_URL); fi;
21+
vagrant up
22+
23+
oc-cluster-destroy:
24+
vagrant destroy
25+
26+
oc-cluster-up:
27+
vagrant up
28+
vagrant ssh -c "cd $(VAGRANT_SHARED_DIR) && $(AP) --extra-vars user=vagrant playbooks/oc-cluster-run.yml"
29+
30+
oc-cluster-down:
31+
vagrant halt
32+
33+
oc-cluster-ssh: oc-cluster-up
34+
ssh $(VAGRANT_SSH_CONFIG) localhost
35+
36+
# Openshift Local pull_secret must exist locally
37+
# or you can also define the CRC_PULL_SECRET var
38+
check-pull-secret:
39+
if [ ! -f ../secrets/openshift-local-pull-secret.yml ] && [ ! -n "$(CRC_PULL_SECRET)" ]; then echo "no pull secret available create secrets/openshift-local-pull-secret.yml file or set CRC_PULL_SECRET variable"; exit 1; else echo "pull secret found"; fi
40+
41+
# Execute tmt deployment test on a vagrant virtual machine
42+
# The virtual machine has to be already up and running,
43+
# use the target oc-cluster-up
44+
tmt-vagrant-test: check-pull-secret
45+
tmt run --all provision --how connect --user vagrant --guest $(VAGRANT_SSH_GUEST) --port $(VAGRANT_SSH_PORT) --key $(VAGRANT_SSH_IDENTITY_FILE) plan --name deployment/vagrant

0 commit comments

Comments
 (0)