|
| 1 | +# Testing with Test Kitchen |
| 2 | + |
| 3 | +The default **Test Kitchen** configuration uses **Dokken**, which is ideal for |
| 4 | +running tests in **GitHub Actions** in a CI environment. However, **Dokken** |
| 5 | +is not always sufficent for local testing, especially when a full-fledged |
| 6 | +virtual machine is required. |
| 7 | + |
| 8 | +To enable local testing, the **Dokken** configuration has been duplicated into |
| 9 | +**.kitchen.vagrant.yml**, allowing you to run tests using **Vagrant** and |
| 10 | +VirtualBox on a **Cinc Workstation** setup. |
| 11 | + |
| 12 | +## Setting up for Local Testing |
| 13 | + |
| 14 | +Follow the "Configuring" guide below to configure your system for |
| 15 | +Vagrant-based testing. To ensure that Test Kitchen uses the Vagrant |
| 16 | +configuration instead of Dokken, set the following environment variable: |
| 17 | + |
| 18 | +```bash |
| 19 | +export KITCHEN_YAML=.kitchen.vagrant.yml |
| 20 | +``` |
| 21 | + |
| 22 | +## Listing Available Test Platforms |
| 23 | + |
| 24 | +To see the available test platforms, run: |
| 25 | + |
| 26 | +```bash |
| 27 | +KITCHEN_YAML=.kitchen.vagrant.yml kitchen list |
| 28 | +``` |
| 29 | + |
| 30 | +Example output: |
| 31 | + |
| 32 | +```bash |
| 33 | +$ KITCHEN_YAML=.kitchen.vagrant.yml kitchen list |
| 34 | +Instance Driver Provisioner Verifier Transport Last Action Last Error |
| 35 | +default-centos-stream-9 Vagrant ChefInfra Inspec Ssh <Not Created> <None> |
| 36 | +default-debian-12 Vagrant ChefInfra Inspec Ssh <Not Created> <None> |
| 37 | +default-ubuntu-2204 Vagrant ChefInfra Inspec Ssh <Not Created> <None> |
| 38 | +default-ubuntu-2404 Vagrant ChefInfra Inspec Ssh <Not Created> <None> |
| 39 | +``` |
| 40 | + |
| 41 | +## Running a Test on a Specific Platform |
| 42 | + |
| 43 | +To test on a specific platform, use the `kitchen converge` command: |
| 44 | + |
| 45 | +```bash |
| 46 | +KITCHEN_YAML=.kitchen.vagrant.yml kitchen converge centos-stream-9 |
| 47 | +``` |
| 48 | + |
| 49 | +Example output: |
| 50 | + |
| 51 | +```bash |
| 52 | + KITCHEN_YAML=.kitchen.vagrant.yml kitchen converge centos-stream-9 |
| 53 | +-----> Starting Test Kitchen (v3.6.0) |
| 54 | +-----> Creating <default-centos-stream-9>... |
| 55 | + Checking for updates to 'bento/centos-stream-9' |
| 56 | + Latest installed version: 202502.21.0 |
| 57 | + Version constraints: > 202502.21.0 |
| 58 | + Provider: virtualbox |
| 59 | + Architecture: "amd64" |
| 60 | + Box 'bento/centos-stream-9' (v202502.21.0) is running the latest version. |
| 61 | + The following boxes will be kept... |
| 62 | +.... |
| 63 | + |
| 64 | + Recipe: fb_init_sample::default |
| 65 | + * fb_helpers_reboot[process deferred reboots] action process_deferred (up to date) |
| 66 | + |
| 67 | + Running handlers: |
| 68 | + Running handlers complete |
| 69 | + Infra Phase complete, 300/585 resources updated in 02 minutes 41 seconds |
| 70 | + [2025-03-09T18:05:51+00:00] WARN: This release of Cinc Client became end of life (EOL) on May 1st 2024. Please update to a supported release to receive new features, bug fixes, and security updates. |
| 71 | + Downloading files from <default-centos-stream-9> |
| 72 | + Finished converging <default-centos-stream-9> (6m24.22s). |
| 73 | +-----> Test Kitchen is finished. (7m3.84s) |
| 74 | +``` |
| 75 | + |
| 76 | +## Limitations and Workarounds |
| 77 | + |
| 78 | +### CentOS Stream 10/RHEL 10 require x86-64-v3 instructions |
| 79 | + |
| 80 | +CentOS Stream 10 and RHEL require x86-64-v3 capabilities to be exposed in |
| 81 | +guest VMs. Make sure you are using at least VirtualBox 7.1, as it now |
| 82 | +supports x86-64-v3 instructions and that you are running on a supported |
| 83 | +host CPU. |
| 84 | + |
| 85 | +If CentOS Stream 10/RHEL10 kernel panics on boot, likely it is due to this |
| 86 | +issue. Make sure you're running on at least version 7.1 of VirtualBox and |
| 87 | +that your host CPU supports x86-64-v3 instructions. |
| 88 | + |
| 89 | +### Cleaning Up: Stopping and Destroying VMs |
| 90 | + |
| 91 | +Unlike with the Dokken driver, running `kitchen destroy` **without parameters** |
| 92 | +will **not** automatically stop and remove running VMs. Instead, you must |
| 93 | +specify the instance explicitly. |
| 94 | + |
| 95 | +```bash |
| 96 | +KITCHEN_YAML=.kitchen.vagrant.yml kitchen destroy centos-stream-9 |
| 97 | +```` |
| 98 | + |
| 99 | +Example output: |
| 100 | + |
| 101 | +```bash |
| 102 | +$ KITCHEN_YAML=.kitchen.vagrant.yml kitchen destroy centos-stream-9 |
| 103 | +-----> Starting Test Kitchen (v3.6.0) |
| 104 | +-----> Destroying <default-centos-stream-9>... |
| 105 | + ==> default: Forcing shutdown of VM... |
| 106 | + ==> default: Destroying VM and associated drives... |
| 107 | + Vagrant instance <default-centos-stream-9> destroyed. |
| 108 | + Finished destroying <default-centos-stream-9> (0m3.74s). |
| 109 | +-----> Test Kitchen is finished. (0m4.47s) |
| 110 | +``` |
| 111 | + |
| 112 | +If a VM is still lingering, you can manually identify and remove it: |
| 113 | + |
| 114 | +1. Find the VM ID: |
| 115 | + |
| 116 | +```bash |
| 117 | +vagrant global-status |
| 118 | +``` |
| 119 | + |
| 120 | +2. Force destroy the VM: |
| 121 | + |
| 122 | +```bash |
| 123 | +vagrant destroy -f <VM-ID> |
| 124 | +``` |
| 125 | + |
| 126 | +### Testing with Different Cinc Client Versions |
| 127 | + |
| 128 | +Similar to the Dokken configuration, if you need to test with a **specific |
| 129 | +version** of the Cinc Client (rather than latest), set the `CHEF_VERSION` |
| 130 | +environment variable before running Test Kitchen: |
| 131 | + |
| 132 | +```bash |
| 133 | +export CHEF_VERSION="18.2.7" |
| 134 | +KITCHEN_YAML=.kitchen.vagrant.yml kitchen converge centos-stream-9 |
| 135 | +``` |
| 136 | + |
| 137 | +This will ensure that the specified verison is installed insdie the test VM. |
| 138 | + |
| 139 | + |
| 140 | +## Configuring an Ubuntu 24.04 Host for Local Testing. |
| 141 | + |
| 142 | +To set up your **Ubuntu 24.04** machine for local testing, ensure you are |
| 143 | +running a **64-bit AMD64-compatible host** with **CPU virtualization enabled** |
| 144 | +in your system's BIOS. |
| 145 | +
|
| 146 | +You'll need to install **VirtualBox, Vagrant, and Cinc Workstation**. |
| 147 | + |
| 148 | +Install [Virtualbox](https://www.virtualbox.org/wiki/Linux_Downloads) |
| 149 | + |
| 150 | +```bash |
| 151 | +# Add Oracle VirtualBox's GPG key: |
| 152 | +wget -O- https://www.virtualbox.org/download/oracle_vbox_2016.asc \ |
| 153 | + | sudo gpg --yes --output /usr/share/keyrings/oracle-virtualbox-2016.gpg --dearmor |
| 154 | +
|
| 155 | +# Add the repository to Apt sources.list.d |
| 156 | +echo \ |
| 157 | + "deb [arch=amd64 signed-by=/usr/share/keyrings/oracle-virtualbox-2016.gpg] https://download.virtualbox.org/virtualbox/debian \ |
| 158 | + $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") contrib" | \ |
| 159 | + sudo tee /etc/apt/sources.list.d/virtualbox.list > /dev/null |
| 160 | + |
| 161 | +# Install the latest version of Oracle VirtualBox |
| 162 | +sudo apt-get update |
| 163 | +sudo apt-get install virtualbox |
| 164 | +
|
| 165 | +# Recommended: Reboot to complete configuration |
| 166 | +sudo reboot |
| 167 | +
|
| 168 | +# Verify that Oracle VirtualBox was installed properly |
| 169 | +# Check the version |
| 170 | +VBoxManage --version |
| 171 | +
|
| 172 | +# Check that the VirtualBox Kernel Modules are loaded properly |
| 173 | +# Expected output should include vboxdrv, vboxnetflt and vboxnetadp |
| 174 | +$ lsmod | grep vbox |
| 175 | +vboxnetadp 28672 0 |
| 176 | +vboxnetflt 32768 0 |
| 177 | +vboxdrv 696320 2 vboxnetadp,vboxnetflt |
| 178 | +``` |
| 179 | + |
| 180 | +Install [Vagrant](https://developer.hashicorp.com/vagrant/downloads#linux): |
| 181 | + |
| 182 | +```bash |
| 183 | +# Add HashiCorp's GPG key: |
| 184 | +wget -O - https://apt.releases.hashicorp.com/gpg \ |
| 185 | + | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg |
| 186 | +
|
| 187 | +# Add the repository to Apt sources.list.d |
| 188 | +echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" \ |
| 189 | + | sudo tee /etc/apt/sources.list.d/hashicorp.list |
| 190 | +
|
| 191 | +# Install the latest version of HashiCorp Vagrant |
| 192 | +sudo apt update |
| 193 | +sudo apt install vagrant |
| 194 | +
|
| 195 | +# Verify vagrant is installed properly - check the vagrant version |
| 196 | +vagrant --version |
| 197 | +``` |
| 198 | + |
| 199 | +Install Cinc Workstation |
| 200 | + |
| 201 | +```bash |
| 202 | +# Download and install cinc-workstatus via omnibus installer |
| 203 | +curl -L https://omnitruck.cinc.sh/install.sh \ |
| 204 | + | sudo bash -s -- -P cinc-workstation -v 25 |
| 205 | +
|
| 206 | +# Verify cinc-workstation is installed properly |
| 207 | +# Check the cinc version |
| 208 | +cinc --version |
| 209 | +
|
| 210 | +# Initialize [cinc-workstation for your shell](https://docs.chef.io/workstation/getting_started/): |
| 211 | +echo 'eval "$(chef shell-init bash)"' >> ~/.bashrc |
| 212 | +source ~/.bashrc |
| 213 | +
|
| 214 | +# Ensure ruby is pointing at the cinc-workstation ruby |
| 215 | +$ which ruby |
| 216 | +/opt/cinc-workstation/embedded/bin/ruby |
| 217 | +``` |
0 commit comments