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

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

Create the test

  1. Go to Admin > Continuous Infrastructure Testing.
  2. Select Add > New Action Test.
  3. Select CloudBolt Plug-in > + Add a New CloudBolt Plug-in.
  4. Enter a name, then scroll to the bottom of the form.
  5. For File Location, select Enter code later.
  6. Select Create.

Add the code

  1. Find the new test in the Tests list and select its name.
  2. Under Actions, select the action name to open the plugin for editing.
  3. 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

  1. Return to the Continuous Infrastructure Testing page.
  2. Under Tests, select the pencil icon in the Action column.
  3. Enter the resource handler ID in Default value for Resource Handler.
  4. Select Save Changes.

Run it

  1. On the Continuous Infrastructure Testing page, select Execute Tests > Execute All Tests.
  2. 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.