Skip to content
Ugur edited this page Feb 22, 2024 · 14 revisions

Welcome to the Rancher wiki!


Shepherd

Shepherd provides tools for writing integrations and validation tests. Shepherd manages interactions with the external services being tested and aids in cleaning up resources after a test is completed.

Shepherd is organized into two disciplines: clients, and extensions. Shepherd consists of a few core libraries used to make it easy to write homologous tests. See extensions and clients for more details.


Concepts

Integration vs Validation

Integration tests - Don't require any external configuration or access to any other external services. These should also be short running as they will run on every PR within CI. Integration tests do not need access keys to cloud providers to run.

Validation tests - Require access to external services, and needs to a config file to run them.

Extensions

Extensions are functions that complete common operations used by tests. Extensions should not require much configuration or support multiple behaviors. Extensions should be simple enough that they can be used in many tests without needing to be tested themselves.

Clients

Clients are used to create the resources in the tests. The advantage of the cients is they register the cleanups with sessions, making resource cleanup trivial. There are three clients; the rancher client, dynamic client, and the k3d client. The rancher client is used to create resources on a rancher instance. Given a host url, and a bearer token the rancher client communicates directly with the rancher instance. The dynamic client is used as means of communication on a downstream cluster, and used for kubernete resource management on that cluster. The k3d client is used to create a minimal k3d cluster, this is to give the integration tests the ability to test against a downstream cluster.

Wait

Wait is used to monitor resources, and wait for specified conditions. There are multiple ways to wait for a resource. There is WatchWait that uses the watch.Interface of a resource to wait until the check function returns true. For more generic polling or waiting, the "k8s.io/apimachinery/pkg/util/wait" package can be used.

Sessions

Sessions are used to track resources created by tests. A session allows cleanup functions to be registered while it is open. Once a session is closed the cleanup functions will be called latest to oldest. Sessions should be closed after a set of tests that use the same resources is completed. This eliminates the need for each test to create and tear down its own resources allowing for more efficient reuse of some resources. When pared with a client sessions are a powerful tool that can track and cleanup any resource a tests creates with no additional work from the developer.

Configuration

Configuration is loaded from the yaml or json file described in CATTLE_TEST_CONFIG. Configuration objects are loaded from their associated key in the configuration file. Default values can also be set on configuration objects.


Table of Contents