Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.

Commit 0d7be03

Browse files
authored
Improve test box handling (#62)
* molecule_vagrant/test/: Allow to set vagrant box to use for tests Currently, the vagrant boxes used can't be changed and are not all the same, which means that during testing, different boxes are downloaded and used. As a solution, allow to set a box for every box, thanks to the new TESTBOX environment variable. If not set, the current behaviour is not changed. Signed-off-by: Arnaud Patard <[email protected]> * tools/test-setup.sh: Create a vagrant box from setup test image The default image used by molecule-vagrant and the test-setup.sh script are using the generic/alpine310 box. This box can be used for testing molecule-vagrant too but using it will mean to download python3 and rsync everytime a new test is started. To avoid doing it, create a new vagrant box out of the freshly started VM and using Vagrantfile provisionning to install python3 and rsync. To avoid having to handle the vagrant insecure ssh key pubkey, set config.ssh.insert_key to false. Signed-off-by: Arnaud Patard <[email protected]> * tox.ini: Use newly created test box Use the vagrant box created with test-setup.sh to do the testing. This should reduce testing time. Since github actions are not using tools/test-setup.sh, configure the tests to use generic/alpine310 in this case. Signed-off-by: Arnaud Patard <[email protected]>
1 parent b6d0fa7 commit 0d7be03

File tree

11 files changed

+22
-10
lines changed

11 files changed

+22
-10
lines changed

.github/workflows/tox.yml

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ jobs:
6767
run: |
6868
echo "${{ matrix.PREFIX }} tox -e ${{ matrix.tox_env }}"
6969
${{ matrix.PREFIX }} tox -e ${{ matrix.tox_env }}
70+
env:
71+
TESTBOX: "generic/alpine310"
7072

7173
publish:
7274
name: Publish to PyPI registry

bindep.txt

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ libvirt-daemon-kvm [platform:rpm]
1414
libvirt-daemon-system [platform:dpkg]
1515
libvirt-dev [platform:dpkg]
1616
libvirt-devel [platform:rpm]
17+
libguestfs-tools [platform:dpkg platform:rpm]
1718
libxml2-dev [platform:dpkg]
1819
libxslt-dev [platform:dpkg]
1920
make [platform:centos-7 platform:centos-8]

molecule_vagrant/test/functional/test_func.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,16 @@ def test_command_init_scenario(temp_dir):
5454
assert result.returncode == 0
5555

5656
assert os.path.isdir(scenario_directory)
57+
confpath = os.path.join(scenario_directory, "molecule.yml")
58+
conf = util.safe_load_file(confpath)
59+
env = os.environ
60+
if "TESTBOX" in env:
61+
conf["platforms"][0]["box"] = env["TESTBOX"]
5762
if not os.path.exists("/dev/kvm"):
58-
confpath = os.path.join(scenario_directory, "molecule.yml")
59-
conf = util.safe_load_file(confpath)
6063
conf["driver"]["provider"] = {"name": "libvirt"}
6164
for p in conf["platforms"]:
6265
p["provider_options"] = {"driver": '"qemu"'}
63-
util.write_file(confpath, util.safe_dump(conf))
66+
util.write_file(confpath, util.safe_dump(conf))
6467

6568
cmd = ["molecule", "--debug", "test", "-s", "test-scenario"]
6669
result = run_command(cmd)

molecule_vagrant/test/scenarios/molecule/config_options/molecule.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ platforms:
1111
synced_folder: true
1212
provider_options:
1313
driver: "${VIRT_DRIVER:-'kvm'}"
14-
box: centos/7
14+
box: ${TESTBOX:-centos/7}
1515
instance_raw_config_args:
1616
- 'vm.synced_folder ".", "/vagrant", type: "rsync"'
1717
provisioner:

molecule_vagrant/test/scenarios/molecule/default/molecule.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ driver:
77
name: virtualbox
88
platforms:
99
- name: instance
10-
box: generic/alpine310
10+
box: ${TESTBOX:-generic/alpine310}
1111
provision: false
1212
options:
1313
linked_clone: false

molecule_vagrant/test/scenarios/molecule/multi-node/molecule.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ driver:
77
name: virtualbox
88
platforms:
99
- name: instance-1
10-
box: debian/jessie64
10+
box: ${TESTBOX:-debian/jessie64}
1111
interfaces:
1212
- auto_config: true
1313
network_name: private_network
@@ -25,7 +25,7 @@ platforms:
2525
instance_raw_config_args:
2626
- 'vm.synced_folder ".", "/vagrant", type: "rsync"'
2727
- name: instance-2
28-
box: centos/7
28+
box: ${TESTBOX:-centos/7}
2929
interfaces:
3030
- auto_config: true
3131
network_name: private_network

molecule_vagrant/test/scenarios/molecule/provider_config_options/molecule.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ platforms:
1010
provider_options:
1111
nic_model_type: '"e1000"'
1212
driver: "${VIRT_DRIVER:-'kvm'}"
13-
box: centos/7
13+
box: ${TESTBOX:-centos/7}
1414
provisioner:
1515
name: ansible
1616
verifier:

molecule_vagrant/test/scenarios/molecule/vagrant_root/molecule.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ driver:
77
name: libvirt
88
platforms:
99
- name: instance
10-
box: centos/7
10+
box: ${TESTBOX:-centos/7}
1111
provider_options:
1212
driver: "${VIRT_DRIVER:-'kvm'}"
1313
provision: true

tools/Vagrantfile

+2
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ Vagrant.configure("2") do |config|
77
l.cpu_mode = 'custom'
88
l.cpu_model = 'qemu64'
99
end
10+
config.vm.provision :shell, inline: "sudo apk add --no-progress --update python3 rsync"
11+
config.ssh.insert_key = false
1012
end

tools/test-setup.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,8 @@ vagrant plugin list | tee >(grep -q "No plugins installed." && {
128128
cd $DIR
129129

130130
# sudo su: dirty hack to make sure that usermod change has been taken into account
131-
sudo su -l "$(whoami)" -c "cd $(pwd) && timeout 300 vagrant up --no-tty --no-provision --debug"
131+
sudo su -l "$(whoami)" -c "cd $(pwd) && timeout 300 vagrant up --no-tty --debug"
132+
sudo su -l "$(whoami)" -c "cd $(pwd) && timeout 300 vagrant halt"
133+
sudo su -l "$(whoami)" -c "cd $(pwd) && timeout 300 vagrant package --output testbox.box"
134+
sudo su -l "$(whoami)" -c "cd $(pwd) && vagrant box add testbox.box --name testbox"
132135
sudo su -l "$(whoami)" -c "cd $(pwd) && vagrant destroy -f"

tox.ini

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ setenv =
4646
MOLECULE_NO_LOG=false
4747
_EXTRAS=-l --html={envlogdir}/reports.html --self-contained-html
4848
PYTEST_ADDOPTS={env:_EXTRAS} {env:PYTEST_ADDOPTS:}
49+
TESTBOX={env:TESTBOX:testbox}
4950
passenv =
5051
CI
5152
CURL_CA_BUNDLE

0 commit comments

Comments
 (0)