Check infrastructure health with CIT
Build a CIT test that verifies a resource handler’s connection, so you find a broken cloud before your users do
2 minute read
A resource handler is the starting point for provisioning a server and for running remote scripts through a platform’s own channel, so its connection is worth checking on a schedule rather than when an order fails. This example uses Cloud Management Platform (CMP) Continuous Infrastructure Testing to do that. For CIT itself, see Continuous Infrastructure Testing (CIT).
Prerequisites
- You are a super admin in CMP.
- A resource handler is already configured.
- You have its resource handler ID.
Create the test
- Go to Admin > Continuous Infrastructure Testing.
- Select Add > New Action Test.
- Select CloudBolt Plug-in > + Add a New CloudBolt Plug-in.
- Enter a name, then scroll to the bottom of the form.
- For File Location, select Enter code later.
- Select Create.
Add the code
- Find the new test in the Tests list and select its name.
- Under Actions, select the action name to open the plugin for editing.
- Replace the default code with the following, then save.
from common.methods import set_progress
from resourcehandlers.models import ResourceHandler
from utilities.logger import ThreadLogger
logger = ThreadLogger(__name__)
def run(*args, **kwargs):
rh = ResourceHandler.objects.get(id=int("{{ resource_handler }}"))
rh = rh.cast()
if rh.can_verify_connection:
set_progress(f"Verifying connection to '{rh}'.")
rh.verify_connection()
set_progress(f"Successfully verified connection to '{rh}'.")
The plugin reads a resource handler ID from an action input, casts the handler to its concrete type, and calls verify_connection() on it if that handler supports connection checks.
Supply the resource handler ID
- Return to the Continuous Infrastructure Testing page.
- Under Tests, select the pencil icon in the Action column.
- Enter the resource handler ID in Default value for Resource Handler.
- Select Save Changes.
Run it
- On the Continuous Infrastructure Testing page, select Execute Tests > Execute All Tests.
- Select the test name to see its details and status.
A job is created, and it passes or fails according to the health of the resource handler’s connection. To have this run on a schedule, see Schedule tests.
Related
- Continuous Infrastructure Testing (CIT): creating, scheduling, and reading tests generally.
- Resource handlers: configuring the connection being tested.