Skip to content

Commit

Permalink
pg 24 - tips
Browse files Browse the repository at this point in the history
Signed-off-by: Amndeep Singh Mann <[email protected]>
  • Loading branch information
Amndeep7 committed Dec 13, 2024
1 parent 6251f30 commit 592361a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/courses/profile-dev-test/21.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
order: 21
next: 22.md
title: Test Kitchen - `kitchen.ec2.yml` File
title: 21. Test Kitchen - `kitchen.ec2.yml` File
author: Aaron Lippold
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
order: 25
next: 26.md
title: Tips, Tricks, and Troubleshooting
order: 24
next: 25.md
title: 24. Tips, Tricks, and Troubleshooting
shortTitle: Tips & Troubleshooting
author: Aaron Lippold
---
Expand All @@ -28,11 +28,15 @@ Test Kitchen stores the current host details of your provisioned test targets in

#### Restoring Access to a Halted or Restarted Test Target

If your test target reboots or updates its network information, you don't need to execute bundle exec kitchen destroy. Instead, update the corresponding .kitchen/#{suite}-#{target}.yml file with the updated information. This will ensure that your kitchen login, kitchen validate, and other kitchen commands function correctly, as they'll be connecting to the correct location instead of using outdated data.
If your test target reboots or updates its network information, you don't need to execute `bundle exec kitchen destroy`. Instead, update the corresponding `.kitchen/#{suite}-#{target}.yml` file with the updated information. This will ensure that your `kitchen login`, `kitchen validate`, and other kitchen commands function correctly, as they'll be connecting to the correct location instead of using outdated data.

#### AWS Console and EC2 Oddities

Since we're using the free-tier for our AWS testing resources instead of a dedicated host, your test targets might shut down or 'reboot in the background' if you stop interacting with them, halt them, put them in a stop state, or leave them overnight. To regain access, edit the .kitchen/#{suite}-#{target}.yml file. As mentioned above, there's no need to recreate your testing targets if you can simply point Test Kitchen to the correct IP address.
Since we're using the free-tier for our AWS testing resources instead of a dedicated host, your test targets might shut down or reboot in the background if you stop interacting with them, halt them, put them in a stop state, or leave them unattended overnight. To regain access, edit the `.kitchen/#{suite}-#{target}.yml` file. As mentioned above, there's no need to recreate your testing targets if you can simply point Test Kitchen to the correct IP address.

:::warning Auto-generated, sensitive files
Since the `.kitchen/` directory is automatically generated by Test Kitchen, you need to be careful not to accidentally mess up its internal workings when editing it by hand as suggested above. Additionally, be sure not to place this directory underneath version control since you could unintentionally leak sensitive information such as your ip addresses and credentials!
:::

## InSpec / Ruby

Expand All @@ -46,13 +50,13 @@ When developing InSpec controls, it's beneficial to use the `kitchen-test` suite
2. Then, insert `binding.pry` at the point in your code where you want to start debugging.
3. When you run your tests, execution will stop at the `binding.pry` line, and you can inspect variables, step through the code, and more.

***!Pro Tip!***

- Remember to remove or comment out the `binding.pry` lines when you're done debugging or you won't have a good 'linting' down the road.
::: tip Linter
Remember to remove or comment out the `binding.pry` lines when you're done debugging or you won't have a good 'linting' down the road.
:::

### Streamlining Your Testing with `inspec shell`

The `inspec shell` command allows you to test your full control update on your test target directly. To do this, you'll need to retrieve the IP address and SSH PEM key for your target instance from the Test Kitchen `.kitchen` directory. For more details on this, refer to the [Finding Your Test Target Login Details](#311-locating-test-target-login-details) section.
The `inspec shell` command allows you to test your full control update on your test target directly. To do this, you'll need to retrieve the IP address and SSH PEM key for your target instance from the Test Kitchen `.kitchen` directory. For more details on this, refer to the [Locating Test Target Login Details](#locating-test-target-login-details) section.

Once you have your IP address and SSH PEM key (for AWS target instances), or the container ID (for Docker test instances), you can use the following commands:

Expand Down

0 comments on commit 592361a

Please sign in to comment.