openstacktest

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package openstacktest provides a minimal fake OpenStack control plane for tests: a Keystone v3 endpoint that authenticates the service's own user (password or application credential), validates subject tokens issued by the test and serves project records, and a Nova compute endpoint, listed in the service catalog, that serves server records.

Index

Constants

View Source
const Region = "RegionOne"

Region is the region of the endpoints in the service catalog.

Variables

View Source
var Service = User{
	ID: "5e7a0c1d2b3f4a5e6d7c8b9a0f1e2d3c", Name: "spire-issuer",
	DomainID: "default", DomainName: "Default", Roles: []string{"service"},
}

Service is the service's own user, as authenticated through the OS_* variables returned by Env.

Functions

This section is empty.

Types

type Instance

type Instance struct {
	ID               string
	ProjectID        string
	UserID           string
	Status           string
	AvailabilityZone string
	// FlavorName is the flavor's original_name, returned for compute
	// microversions 2.47 and later.
	FlavorName string
}

Instance is a Nova server record.

type Project

type Project struct {
	ID       string
	Name     string
	DomainID string
}

Project is a Keystone project record.

type Server

type Server struct {
	*httptest.Server

	// Authentications counts successful POST /v3/auth/tokens.
	Authentications atomic.Int32
	// Validations counts GET /v3/auth/tokens requests.
	Validations atomic.Int32
	// ServerLookups counts GET /servers/{id} requests.
	ServerLookups atomic.Int32
	// ProjectLookups counts GET /v3/projects/{id} requests.
	ProjectLookups atomic.Int32
	// contains filtered or unexported fields
}

Server is a fake Keystone v3 and Nova control plane over TLS.

func New

func New(t *testing.T) *Server

New starts a fake OpenStack control plane, stopped when the test ends.

func (*Server) AddInstance

func (s *Server) AddInstance(i Instance)

AddInstance adds a server record to the fake Nova.

func (*Server) AddProject

func (s *Server) AddProject(p Project)

AddProject adds a project record to the fake Keystone.

func (*Server) AppCredentialEnv

func (s *Server) AppCredentialEnv() map[string]string

AppCredentialEnv returns the OS_* variables for authenticating with an application credential.

func (*Server) CAFile

func (s *Server) CAFile(t *testing.T) string

CAFile writes the server's certificate to a PEM file and returns its path.

func (*Server) Env

func (s *Server) Env() map[string]string

Env returns the OS_* variables of a typical openrc file for the service user, authenticating with a password and scoped to the service project.

func (*Server) IssueToken

func (s *Server) IssueToken(u User, expires time.Time) string

IssueToken returns a new subject token for the user, valid until expires.

func (*Server) LastComputeMicroversion

func (s *Server) LastComputeMicroversion() string

LastComputeMicroversion returns the compute API microversion requested by the latest server lookup.

func (*Server) RevokeServiceTokens

func (s *Server) RevokeServiceTokens()

RevokeServiceTokens invalidates every token issued to the service user, so that its next request must re-authenticate.

func (*Server) SetDown

func (s *Server) SetDown(down bool)

SetDown makes every request fail with 503 until called with false.

type User

type User struct {
	ID         string
	Name       string
	DomainID   string
	DomainName string
	Roles      []string
}

User is a Keystone user and the roles its tokens carry.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL