config

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Overview

Package config provides an API for setting native config on DUTs via vendor-specific (non-gNMI) protocols.

We use the following example snippet to understand various aspects of the Config API.

dut.Config().New().
	WithAristaText(`
interface {{ port "port1" }}
 no switchport
 ip address 192.0.2.1/30
 ip address {{ var "ipv4addr" }}
 ipv6 address 2001:DB8::1/126
 load-interval 30`).
	WithCiscoText(`
interface {{ port "port1" }}
 ipv4 address {{ var "ipv4addr" }}
 ipv6 address 2001:DB8::1/126
 load-interval 30`).
	WithJuniperFile(`path/to/juniper.config`).
	WithVarValue("ipv4addr", computeV4Address()).
	Push(t)

Per-Vendor Configs

In the example above, one of three possible native configs are pushed to the device depending upon the vendor of the device at runtime. If the vendor is not one of those three, the VendorConfig.Push function fails fatally. The `With<Vendor>Text` methods will push a vendor-specific text string and the `With<Vendor>File` methods will push the text in a vendor-specific file.

If the test has already pre-computed the native config in a way that has taken the vendor into account, perhaps by calling an external config-generation service, the test can push that config without regard to the vendor using the functions VendorConfig.WithText or VendorConfig.WithFile.

Templated Variables

As shown, the syntax for the config allows templated port names like `{{ port "port1" }}`. That placeholder will be replaced at runtime with the name given to `port1`, where `port1` is the ID of a port in the testbed file. The syntax may also contain instances of `{{ var "<key>" }}`, which will be replaced at runtime by calling `WithVarValue` or `WithVarMap` on the config object.

Push vs Append

The effect of Push is to reset the device back to its original config (the config the device had when it was reserved) and then to append the specified config. As a result, test cases that use native config don't usually need to reset the device config to be hermetic; it suffices to just start the test case with a call to Push. If a test wants only to append config and skip the reset behavior, it should call VendorConfig.Append instead.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type VendorConfig

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

VendorConfig is a vendor configuration for a DUT.

func NewVendorConfig

func NewVendorConfig(dut binding.DUT) *VendorConfig

NewVendorConfig returns a new vendor configuration for a DUT. Tests must not call this method directly.

func (*VendorConfig) Append

func (c *VendorConfig) Append(t testing.TB)

Append appends the specified config to the current config.

func (*VendorConfig) Push

func (c *VendorConfig) Push(t testing.TB)

Push resets the device to its base config and appends the specified config.

func (*VendorConfig) String

func (c *VendorConfig) String() string

func (*VendorConfig) WithAristaFile

func (c *VendorConfig) WithAristaFile(path string) *VendorConfig

WithAristaFile sets the config to be pushed if the DUT vendor is Arista.

func (*VendorConfig) WithAristaText

func (c *VendorConfig) WithAristaText(text string) *VendorConfig

WithAristaText sets the config to be pushed if the DUT vendor is Arista.

func (*VendorConfig) WithCienaFile added in v0.5.0

func (c *VendorConfig) WithCienaFile(path string) *VendorConfig

WithCienaFile sets the config to be pushed if the DUT vendor is Ciena.

func (*VendorConfig) WithCienaText added in v0.5.0

func (c *VendorConfig) WithCienaText(text string) *VendorConfig

WithCienaText sets the config to be pushed if the DUT vendor is Ciena.

func (*VendorConfig) WithCiscoFile

func (c *VendorConfig) WithCiscoFile(path string) *VendorConfig

WithCiscoFile sets the config to be pushed if the DUT vendor is Cisco.

func (*VendorConfig) WithCiscoText

func (c *VendorConfig) WithCiscoText(text string) *VendorConfig

WithCiscoText sets the config to be pushed if the DUT vendor is Cisco.

func (*VendorConfig) WithFile

func (c *VendorConfig) WithFile(path string) *VendorConfig

WithFile sets the config to be pushed regardless of the DUT vendor. This should only be used when the DUT vendor was already taken into account in the generation of the config and only when no per-vendor configs are set.

func (*VendorConfig) WithJuniperFile

func (c *VendorConfig) WithJuniperFile(path string) *VendorConfig

WithJuniperFile sets the config to be pushed if the DUT vendor is Juniper.

func (*VendorConfig) WithJuniperText

func (c *VendorConfig) WithJuniperText(text string) *VendorConfig

WithJuniperText sets the config to be pushed if the DUT vendor is Juniper.

func (*VendorConfig) WithText

func (c *VendorConfig) WithText(text string) *VendorConfig

WithText sets the config to be pushed regardless of the DUT vendor. This should only be used when the DUT vendor was already taken into account in the generation of the config and only when no per-vendor configs are set.

func (*VendorConfig) WithVarMap

func (c *VendorConfig) WithVarMap(m map[string]string) *VendorConfig

WithVarMap sets the map used to replace each occurrence of {{ var "key" }} in the pushed config.

func (*VendorConfig) WithVarValue

func (c *VendorConfig) WithVarValue(key, value string) *VendorConfig

WithVarValue replaces each occurrence of {{ var "key" }} in the pushed config with the specified value.

Jump to

Keyboard shortcuts

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