e2etest

package
v3.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2023 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package e2etest contains end-to-end test harness.

Index

Constants

View Source
const (
	DefaultShareDir      = "/test-share"
	DefaultMainAgentName = "agent0"

	// VPP input nodes for packet tracing (uncomment when needed)
	Tapv2InputNode = "virtio-input"
)
View Source
const (
	LigatoDNSHostNameSuffix = "test.ligato.io"
)
View Source
const (
	MsNamePrefix = "e2e-test-ms-"
)

Variables

View Source
var Debug bool

Functions

func AgentInstanceName

func AgentInstanceName(testCtx *TestCtx) string

AgentInstanceName provides instance name of VPP-Agent that is created by setup by default. This name is used i.e. in ETCD key prefix.

func AgentStartOptionsForContainerRuntime

func AgentStartOptionsForContainerRuntime(ctx *TestCtx, options interface{}) (interface{}, error)

AgentStartOptionsForContainerRuntime translates AgentOpt to options for ComponentRuntime.Start(option) method implemented by ContainerRuntime

func CreateFileOnSharedVolume

func CreateFileOnSharedVolume(ctx *TestCtx, simpleFileName string, fileContent string) string

CreateFileOnSharedVolume persists fileContent to file in mounted shared volume used for sharing file between containers. It returns the absolute path to the newly created file as seen by the container that creates it.

func DNSServerStartOptionsForContainerRuntime

func DNSServerStartOptionsForContainerRuntime(ctx *TestCtx, options interface{}) (interface{}, error)

DNSServerStartOptionsForContainerRuntime translates DNSOpt to options for ComponentRuntime.Start(option) method implemented by ContainerRuntime

func ETCDStartOptionsForContainerRuntime

func ETCDStartOptionsForContainerRuntime(ctx *TestCtx, options interface{}) (interface{}, error)

ETCDStartOptionsForContainerRuntime translates EtcdOpt to options for ComponentRuntime.Start(option) method implemented by ContainerRuntime

func MicroserviceStartOptionsForContainerRuntime

func MicroserviceStartOptionsForContainerRuntime(ctx *TestCtx, options interface{}) (interface{}, error)

MicroserviceStartOptionsForContainerRuntime translates MicroserviceOpt to options for ComponentRuntime.Start(option) method implemented by ContainerRuntime

func ParseVPPTable

func ParseVPPTable(table string) (parsed []map[string]string)

parseVPPTable parses table returned by one of the VPP show commands.

func SupportsLinuxVRF

func SupportsLinuxVRF() bool

func WithPluginConfigArg

func WithPluginConfigArg(ctx *TestCtx, pluginName string, configContent string) string

WithPluginConfigArg persists configContent for give VPP-Agent plugin (expecting generic plugin config name) and returns argument for VPP-Agent executable to use this plugin configuration file.

Types

type Agent

type Agent struct {
	ComponentRuntime
	// contains filtered or unexported fields
}

Agent represents running VPP-Agent test component

func NewAgent

func NewAgent(ctx *TestCtx, name string, optMods ...AgentOptModifier) (*Agent, error)

NewAgent creates and starts new VPP-Agent container

func (*Agent) Client

func (agent *Agent) Client() ctl.APIClient

func (*Agent) ExecVppctl

func (agent *Agent) ExecVppctl(action string, args ...string) (string, error)

ExecVppctl returns output from vppctl for given action and arguments.

func (*Agent) GRPCConn

func (agent *Agent) GRPCConn() *grpc.ClientConn

GRPCConn provides GRPC client connection for communication with default VPP-Agent test component

func (*Agent) GenericClient

func (agent *Agent) GenericClient() client.GenericClient

GenericClient provides generic client for communication with default VPP-Agent test component

func (*Agent) GetDerivedValueState

func (agent *Agent) GetDerivedValueState(baseValue proto.Message, derivedKey string) kvscheduler.ValueState

func (*Agent) GetDerivedValueStateClb

func (agent *Agent) GetDerivedValueStateClb(baseValue proto.Message, derivedKey string) func() kvscheduler.ValueState

func (*Agent) GetValue

func (agent *Agent) GetValue(value proto.Message, view kvs.View) proto.Message

GetValue retrieves value(s) as seen by the given view

func (*Agent) GetValueMetadata

func (agent *Agent) GetValueMetadata(value proto.Message, view kvs.View) (metadata interface{})

GetValueMetadata retrieves metadata associated with the given value.

func (*Agent) GetValueState

func (agent *Agent) GetValueState(value proto.Message) kvscheduler.ValueState

func (*Agent) GetValueStateByKey

func (agent *Agent) GetValueStateByKey(key string) kvscheduler.ValueState

func (*Agent) GetValueStateByKeyClb

func (agent *Agent) GetValueStateByKeyClb(key string) func() kvscheduler.ValueState

func (*Agent) GetValueStateClb

func (agent *Agent) GetValueStateClb(value proto.Message) func() kvscheduler.ValueState

func (*Agent) IsInSync

func (agent *Agent) IsInSync() bool

IsInSync checks if the agent NB config and the SB state (VPP+Linux) are in-sync.

func (*Agent) LinuxInterfaceHandler

func (agent *Agent) LinuxInterfaceHandler() linuxcalls.NetlinkAPI

func (*Agent) NumValues

func (agent *Agent) NumValues(value proto.Message, view kvs.View) int

NumValues returns number of values found under the given model

func (*Agent) PingFromVPP

func (agent *Agent) PingFromVPP(destAddress string, args ...string) error

PingFromVPP pings <dstAddress> from inside the VPP.

func (*Agent) PingFromVPPAsCallback

func (agent *Agent) PingFromVPPAsCallback(destAddress string, args ...string) func() error

PingFromVPPAsCallback can be used to ping repeatedly inside the assertions "Eventually" and "Consistently" from Omega.

func (*Agent) Stop

func (agent *Agent) Stop(options ...interface{}) error

func (*Agent) Sync

func (agent *Agent) Sync() kvs.RecordedTxnOps

Sync runs downstream resync and returns the list of executed operations.

type AgentOpt

type AgentOpt struct {
	Runtime             ComponentRuntime
	RuntimeStartOptions RuntimeStartOptionsFunc
	Name                string
	Image               string
	Env                 []string
	UseEtcd             bool
	InitialResync       bool
	ContainerOptsHook   func(*docker.CreateContainerOptions)
}

AgentOpt is options data holder for customizing setup of agent

func DefaultAgentOpt

func DefaultAgentOpt(testCtx *TestCtx, agentName string) *AgentOpt

DefaultAgentOpt creates default values for AgentOpt

type AgentOptModifier

type AgentOptModifier func(*AgentOpt)

AgentOptModifier is function customizing Agent setup options

func WithAdditionalAgentCmdParams

func WithAdditionalAgentCmdParams(params ...string) AgentOptModifier

WithAdditionalAgentCmdParams is test setup option adding additional command line parameters to executing vpp-agent

func WithoutManualInitialAgentResync

func WithoutManualInitialAgentResync() AgentOptModifier

WithoutManualInitialAgentResync is test setup option disabling manual agent resync just after agent setup

type CommandExecutor

type CommandExecutor interface {
	// ExecCmd executes command inside runtime environment
	ExecCmd(cmd string, args ...string) (stdout, stderr string, err error)
}

CommandExecutor gives test topology components the ability to perform (linux) commands

type ComponentRuntime

type ComponentRuntime interface {
	CommandExecutor

	// Start starts instance of test topology component
	Start(options interface{}) error

	// Stop stops instance of test topology component
	Stop(options ...interface{}) error

	// IPAddress provides ip address for connecting to the component
	IPAddress() string

	// PID provides process id of the main process in component
	PID() int
}

ComponentRuntime represents running instance of test topology component. Different implementation can handle test topology components in different environments (docker container, k8s pods, VMs,...)

type ContainerRuntime

type ContainerRuntime struct {
	// contains filtered or unexported fields
}

ContainerRuntime represents docker container environments for one component of test topology

func (*ContainerRuntime) Dig

func (c *ContainerRuntime) Dig(dnsServer net.IP, queryDomain string, requestedInfo DNSRecordType) ([]net.IP, error)

Dig calls linux tool "dig" that query DNS server for domain name (queryDomain) and return records associated of given type (requestedInfo) associated with the domain name.

func (*ContainerRuntime) ExecCmd

func (c *ContainerRuntime) ExecCmd(cmd string, args ...string) (string, string, error)

ExecCmd executes command inside docker container

func (*ContainerRuntime) IPAddress

func (c *ContainerRuntime) IPAddress() string

IPAddress provides ip address for connecting to the component

func (*ContainerRuntime) PID

func (c *ContainerRuntime) PID() int

PID provides process id of the main process in component

func (*ContainerRuntime) Ping

func (c *ContainerRuntime) Ping(destAddress string, opts ...PingOptModifier) error

Ping <destAddress> from inside of the container.

func (*ContainerRuntime) PingAsCallback

func (c *ContainerRuntime) PingAsCallback(destAddress string, opts ...PingOptModifier) func() error

PingAsCallback can be used to ping repeatedly inside the assertions "Eventually" and "Consistently" from Omega.

func (*ContainerRuntime) Start

func (c *ContainerRuntime) Start(options interface{}) error

Start creates and starts container

func (*ContainerRuntime) Stop

func (c *ContainerRuntime) Stop(options ...interface{}) error

Stop stops and removes container

type ContainerStartOptions

type ContainerStartOptions struct {
	ContainerOptions *docker.CreateContainerOptions
	Pull             bool
	AttachLogs       bool
}

ContainerStartOptions are options for ComponentRuntime.Start(option) method implemented by ContainerRuntime

type DNSOpt

type DNSOpt struct {
	Runtime             ComponentRuntime
	RuntimeStartOptions RuntimeStartOptionsFunc

	// DomainNameSuffix is common suffix of all static dns entries configured in hostsConfig
	DomainNameSuffix string
	// HostsConfig is content of configuration of static DNS entries in hosts file format
	HostsConfig string
}

DNSOpt is options data holder for customizing setup of DNS server

func DefaultDNSOpt

func DefaultDNSOpt(testCtx *TestCtx) *DNSOpt

DefaultDNSOpt creates default values for DNSOpt

type DNSOptModifier

type DNSOptModifier func(*DNSOpt)

DNSOptModifier is function customizing DNS server setup options

func WithZonedStaticEntries

func WithZonedStaticEntries(zoneDomainNameSuffix string, staticEntries ...string) DNSOptModifier

WithZonedStaticEntries is test setup option configuring group of static dns cache entries that belong to the same zone (have the same domain name suffix). The static dns cache entries are lines of config file in linux /etc/hosts file format. Currently supporting only one domain name suffix with static entries (even when DNS server solution supports multiple "zones" that each of them can be configured by one file in hosts file format)

type DNSRecordType

type DNSRecordType int

DNSRecordType represent types of records associated with domain name in DNS server

const (
	A DNSRecordType = iota
	AAAA
)

type DNSServer

type DNSServer struct {
	ComponentRuntime
	// contains filtered or unexported fields
}

DNSServer is represents running DNS server

func NewDNSServer

func NewDNSServer(ctx *TestCtx, optMods ...DNSOptModifier) (*DNSServer, error)

NewDNSServer creates and starts new DNS server container

func (*DNSServer) Stop

func (dns *DNSServer) Stop(options ...interface{}) error

type Diger

type Diger interface {
	CommandExecutor

	// Dig calls linux tool "dig" that query DNS server for domain name (queryDomain) and return records associated
	// of given type (requestedInfo) associated with the domain name.
	Dig(dnsServer net.IP, queryDomain string, requestedInfo DNSRecordType) ([]net.IP, error)
}

Diger gives test topology components the ability to perform dig command (DNS-query linux tool)

type Etcd

type Etcd struct {
	ComponentRuntime
	// contains filtered or unexported fields
}

Etcd is represents running ETCD

func NewEtcd

func NewEtcd(ctx *TestCtx, optMods ...EtcdOptModifier) (*Etcd, error)

NewEtcd creates and starts new ETCD container

func (*Etcd) Get

func (ec *Etcd) Get(key string) (string, error)

Get retrieves value for the key from the ETCD that is running in its docker container

func (*Etcd) GetAll

func (ec *Etcd) GetAll() (string, error)

GetAll retrieves all key-value pairs from the ETCD that is running in its docker container

func (*Etcd) Put

func (ec *Etcd) Put(key string, value string) error

Put inserts key-value pair into the ETCD inside its running docker container

type EtcdOpt

type EtcdOpt struct {
	Runtime                       ComponentRuntime
	RuntimeStartOptions           RuntimeStartOptionsFunc
	UseHTTPS                      bool
	UseTestContainerForNetworking bool
}

EtcdOpt is options data holder for customizing setup of ETCD

func DefaultEtcdOpt

func DefaultEtcdOpt(ctx *TestCtx) *EtcdOpt

DefaultEtcdOpt creates default values for EtcdOpt

type EtcdOptModifier

type EtcdOptModifier func(*EtcdOpt)

EtcdOptModifier is function customizing ETCD setup options

func WithEtcdHTTPsConnection

func WithEtcdHTTPsConnection() EtcdOptModifier

WithEtcdHTTPsConnection is ETCD test setup option that will use HTTPS connection to ETCD (by default it is used unsecure HTTP connection)

func WithEtcdTestContainerNetworking

func WithEtcdTestContainerNetworking() EtcdOptModifier

WithEtcdTestContainerNetworking is ETCD test setup option that will use main Test container for networking (by default the ETCD has separate networking)

type Microservice

type Microservice struct {
	ComponentRuntime
	Pinger
	Diger
	// contains filtered or unexported fields
}

Microservice represents running microservice

func NewMicroservice

func NewMicroservice(
	ctx *TestCtx,
	msName string,
	nsCalls nslinuxcalls.NetworkNamespaceAPI,
	optMods ...MicroserviceOptModifier,
) (*Microservice, error)

NewMicroservice creates and starts new microservice container

func (*Microservice) EnterNetNs

func (ms *Microservice) EnterNetNs() (exitNetNs func())

TODO this is runtime specific -> integrate it into runtime concept enterNetNs enters the **network** namespace of the microservice (other namespaces remain unchanged). Leave using the returned callback.

func (*Microservice) Stop

func (ms *Microservice) Stop(options ...interface{}) error

type MicroserviceOpt

type MicroserviceOpt struct {
	Runtime             ComponentRuntime
	RuntimeStartOptions RuntimeStartOptionsFunc
	Name                string
	ContainerOptsHook   func(*docker.CreateContainerOptions)
}

MicroserviceOpt is options data holder for customizing setup of microservice

func DefaultMicroserviceOpt

func DefaultMicroserviceOpt(testCtx *TestCtx, msName string) *MicroserviceOpt

DefaultMicroserviceiOpt creates default values for MicroserviceOpt

type MicroserviceOptModifier

type MicroserviceOptModifier func(*MicroserviceOpt)

MicroserviceOptModifier is function customizing Microservice setup options

func WithMSContainerStartHook

func WithMSContainerStartHook(hook func(*docker.CreateContainerOptions)) MicroserviceOptModifier

WithMSContainerStartHook is microservice test setup option that will set the microservice container start hook that will modify the microservice start options.

type PingOpt

type PingOpt struct {
	AllowedLoss int    // percentage of allowed loss for success
	SourceIface string // outgoing interface name
	MaxTimeout  int    // timeout in seconds before ping exits
	Count       int    // number of pings
}

PingOpt are options for pinging command.

func DefaultPingOpts

func DefaultPingOpts() *PingOpt

DefaultPingOpts creates default values for PingOpt

func NewPingOpts

func NewPingOpts(opts ...PingOptModifier) *PingOpt

NewPingOpts create new PingOpt

type PingOptModifier

type PingOptModifier func(*PingOpt)

PingOptModifier is modifiers of pinging options

func PingWithAllowedLoss

func PingWithAllowedLoss(maxLoss int) PingOptModifier

PingWithAllowedLoss sets max allowed packet loss for pinging to be considered successful.

func PingWithSourceInterface

func PingWithSourceInterface(iface string) PingOptModifier

PingWithSourceInterface set source interface for ping packets.

type Pinger

type Pinger interface {
	CommandExecutor

	// Ping <destAddress> from inside of the container.
	Ping(destAddress string, opts ...PingOptModifier) error

	// PingAsCallback can be used to ping repeatedly inside the assertions "Eventually"
	// and "Consistently" from Omega.
	PingAsCallback(destAddress string, opts ...PingOptModifier) func() error
}

Pinger gives test topology components the ability to perform pinging (pinging from them to other places)

type RuntimeStartOptionsFunc

type RuntimeStartOptionsFunc func(ctx *TestCtx, options interface{}) (interface{}, error)

RuntimeStartOptionsFunc is function that provides component runtime start options

type SetupOpt

type SetupOpt struct {
	AgentOptMods   []AgentOptModifier
	EtcdOptMods    []EtcdOptModifier
	DNSOptMods     []DNSOptModifier
	SetupAgent     bool
	SetupEtcd      bool
	SetupDNSServer bool
	// contains filtered or unexported fields
}

SetupOpt is options data holder for customizing setup of tests

func DefaultSetupOpt

func DefaultSetupOpt(testCtx *TestCtx) *SetupOpt

DefaultSetupOpt creates default values for SetupOpt

type SetupOptModifier

type SetupOptModifier func(*SetupOpt)

SetupOptModifier is function customizing general setup options

func WithCustomVPPAgent

func WithCustomVPPAgent() SetupOptModifier

WithCustomVPPAgent is test setup option using alternative vpp-agent image (customized original vpp-agent)

func WithDNSServer

func WithDNSServer(dnsOpts ...DNSOptModifier) SetupOptModifier

WithDNSServer is test setup option enabling setup of container serving as dns server

func WithEtcd

func WithEtcd(etcdOptMods ...EtcdOptModifier) SetupOptModifier

WithEtcd is test setup option enabling etcd setup

func WithoutVPPAgent

func WithoutVPPAgent() SetupOptModifier

WithoutVPPAgent is test setup option disabling vpp-agent setup

type TestCtx

type TestCtx struct {
	*gomega.WithT

	Agent     *Agent // the main agent (first agent in multi-agent test scenario)
	Etcd      *Etcd
	DNSServer *DNSServer

	DataDir  string
	ShareDir string

	Logger *log.Logger
	// contains filtered or unexported fields
}

TestCtx represents data context fur currently running test

func NewTest

func NewTest(t *testing.T) *TestCtx

NewTest creates new TestCtx for given runnin test

func Setup

func Setup(t *testing.T, optMods ...SetupOptModifier) *TestCtx

Setup setups the testing environment according to options

func (*TestCtx) AgentInSync

func (test *TestCtx) AgentInSync() bool

AgentInSync checks if the agent NB config and the SB state (VPP+Linux) are in-sync.

func (*TestCtx) ExecCmd

func (test *TestCtx) ExecCmd(cmd string, args ...string) (stdout, stderr string, err error)

ExecCmd executes command in agent and returns stdout, stderr as strings and error.

func (*TestCtx) ExecVppctl

func (test *TestCtx) ExecVppctl(action string, args ...string) (string, error)

ExecVppctl returns output from vppctl for given action and arguments.

func (*TestCtx) GRPCConn

func (test *TestCtx) GRPCConn() *grpc.ClientConn

GRPCConn provides GRPC client connection for communication with default VPP-Agent test component

func (*TestCtx) GenericClient

func (test *TestCtx) GenericClient() client.GenericClient

GenericClient provides generic client for communication with default VPP-Agent test component

func (*TestCtx) GetDerivedValueState

func (test *TestCtx) GetDerivedValueState(baseValue proto.Message, derivedKey string) kvscheduler.ValueState

func (*TestCtx) GetDerivedValueStateClb

func (test *TestCtx) GetDerivedValueStateClb(baseValue proto.Message, derivedKey string) func() kvscheduler.ValueState

GetDerivedValueStateClb can be used to repeatedly check derived value state inside the assertions "Eventually" and "Consistently" from Omega.

func (*TestCtx) GetRunningMicroservice

func (test *TestCtx) GetRunningMicroservice(msName string) *Microservice

GetRunningMicroservice retrieves already running microservice by its name.

func (*TestCtx) GetValue

func (test *TestCtx) GetValue(value proto.Message, view kvs.View) proto.Message

GetValue retrieves value(s) as seen by the given view

func (*TestCtx) GetValueMetadata

func (test *TestCtx) GetValueMetadata(value proto.Message, view kvs.View) (metadata interface{})

GetValueMetadata retrieves metadata associated with the given value.

func (*TestCtx) GetValueState

func (test *TestCtx) GetValueState(value proto.Message) kvscheduler.ValueState

func (*TestCtx) GetValueStateByKey

func (test *TestCtx) GetValueStateByKey(key string) kvscheduler.ValueState

func (*TestCtx) GetValueStateClb

func (test *TestCtx) GetValueStateClb(value proto.Message) func() kvscheduler.ValueState

GetValueStateClb can be used to repeatedly check value state inside the assertions "Eventually" and "Consistently" from Omega.

func (*TestCtx) NumValues

func (test *TestCtx) NumValues(value proto.Message, view kvs.View) int

NumValues returns number of values found under the given model

func (*TestCtx) PingFromMs

func (test *TestCtx) PingFromMs(msName, dstAddress string, opts ...PingOptModifier) error

PingFromMs pings <dstAddress> from the microservice <msName> Deprecated: use ctx.AlreadyRunningMicroservice(msName).Ping(dstAddress, opts...) instead (or ms := ctx.StartMicroservice; ms.Ping(dstAddress, opts...))

func (*TestCtx) PingFromMsClb

func (test *TestCtx) PingFromMsClb(msName, dstAddress string, opts ...PingOptModifier) func() error

PingFromMsClb can be used to ping repeatedly inside the assertions "Eventually" and "Consistently" from Omega. Deprecated: use ctx.AlreadyRunningMicroservice(msName).PingAsCallback(dstAddress, opts...) instead (or ms := ctx.StartMicroservice; ms.PingAsCallback(dstAddress, opts...))

func (*TestCtx) PingFromVPP

func (test *TestCtx) PingFromVPP(destAddress string) error

PingFromVPP pings <dstAddress> from inside the VPP.

func (*TestCtx) PingFromVPPClb

func (test *TestCtx) PingFromVPPClb(destAddress string) func() error

PingFromVPPClb can be used to ping repeatedly inside the assertions "Eventually" and "Consistently" from Omega.

func (*TestCtx) StartAgent

func (test *TestCtx) StartAgent(name string, optMods ...AgentOptModifier) *Agent

StartAgent starts new VPP-Agent with given name and according to options

func (*TestCtx) StartMicroservice

func (test *TestCtx) StartMicroservice(name string, optMods ...MicroserviceOptModifier) *Microservice

StartMicroservice starts microservice according to given options

func (*TestCtx) StopAgent

func (test *TestCtx) StopAgent(name string)

StopAgent stops VPP-Agent with given name

func (*TestCtx) StopMicroservice

func (test *TestCtx) StopMicroservice(name string)

StopMicroservice stops microservice with given name

func (*TestCtx) Teardown

func (test *TestCtx) Teardown()

Teardown perform test cleanup

func (*TestCtx) TestConnection

func (test *TestCtx) TestConnection(
	fromMs, toMs, toAddr, listenAddr string,
	toPort, listenPort uint16, udp bool,
	traceVPPNodes ...string,
) error

TestConnection starts a simple TCP or UPD server and client, sends some data and stops the client and server.

If upd is true and there was no prior traffic (TPC/UDP/ICMP) between the endpoints, ARP glean may happen and TestConnection may fail.

func (*TestCtx) VppRelease

func (test *TestCtx) VppRelease() string

VppRelease provides VPP version of VPP in default VPP-Agent test component

Jump to

Keyboard shortcuts

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