From 77e731861327e56a2986c217151d314f1e4949fa Mon Sep 17 00:00:00 2001 From: William Banfield Date: Mon, 24 Oct 2022 12:04:50 -0400 Subject: [PATCH] include cidr block range in the infrastructure data --- test/e2e/pkg/infrastructure.go | 16 ++++++++++++++++ test/e2e/pkg/testnet.go | 34 +++++----------------------------- test/e2e/runner/main.go | 4 ++-- 3 files changed, 23 insertions(+), 31 deletions(-) diff --git a/test/e2e/pkg/infrastructure.go b/test/e2e/pkg/infrastructure.go index fffe50f3e..e15ecc8ab 100644 --- a/test/e2e/pkg/infrastructure.go +++ b/test/e2e/pkg/infrastructure.go @@ -7,6 +7,14 @@ import ( "os" ) +const ( + dockerIPv4CIDR = "10.186.73.0/24" + dockerIPv6CIDR = "fd80:b10c::/48" + + globalIPv4CIDR = "0.0.0.0/0" + globalIPv6CIDR = "0:0::/0" +) + // InfrastructureData contains the relevant information for a set of existing // infrastructure that is to be used for running a testnet. type InfrastructureData struct { @@ -21,6 +29,10 @@ type InfrastructureData struct { // The key of the map is the name of the instance, which each must correspond // to the names of one of the testnet nodes defined in the testnet manifest. Instances map[string]InstanceData `json:"instances"` + + // Network is the CIDR notation range of IP addresses that all of the instances' + // IP addresses are expected to be within. + Network string `json:"network"` } // InstanceData contains the relevant information for a machine instance backing @@ -42,6 +54,7 @@ func NewDockerInfrastructureData(m Manifest) (InfrastructureData, error) { ifd := InfrastructureData{ Provider: "docker", Instances: make(map[string]InstanceData), + Network: netAddress, } for name := range m.Nodes { ifd.Instances[name] = InstanceData{ @@ -58,5 +71,8 @@ func InfrastructureDataFromFile(p string) (InfrastructureData, error) { if err != nil { return InfrastructureData{}, err } + if ifd.Network == "" { + ifd.Network = globalIPv4CIDR + } return ifd, nil } diff --git a/test/e2e/pkg/testnet.go b/test/e2e/pkg/testnet.go index 58c336dfa..3f83c0a9a 100644 --- a/test/e2e/pkg/testnet.go +++ b/test/e2e/pkg/testnet.go @@ -21,11 +21,6 @@ import ( const ( randomSeed int64 = 2308084734268 proxyPortFirst uint32 = 5701 - dockerIPv4CIDR = "10.186.73.0/24" - dockerIPv6CIDR = "fd80:b10c::/48" - - globalIPv4CIDR = "0.0.0.0/0" - globalIPv6CIDR = "0:0::/0" ) type ( @@ -105,37 +100,18 @@ type Node struct { // random seed to generate e.g. keys. func LoadTestnet(manifest Manifest, fname string, ifd InfrastructureData) (*Testnet, error) { dir := strings.TrimSuffix(fname, filepath.Ext(fname)) - - // Set up resource generators. These must be deterministic. - var netAddress string - switch ifd.Provider { - case "docker": - netAddress = dockerIPv4CIDR - if manifest.IPv6 { - netAddress = dockerIPv6CIDR - } - default: - // TODO(williambanfield): add list of CIDR blocks to the infrastructure - // data struct to allow tighter validation of IP addresses. - netAddress = globalIPv4CIDR - if manifest.IPv6 { - netAddress = globalIPv6CIDR - } - } - _, ipNet, err := net.ParseCIDR(netAddress) - if err != nil { - return nil, fmt.Errorf("invalid IP network address %q: %w", netAddress, err) - } - - ipGen := newIPGenerator(ipNet) keyGen := newKeyGenerator(randomSeed) proxyPortGen := newPortGenerator(proxyPortFirst) + _, ipNet, err := net.ParseCIDR(ifd.Network) + if err != nil { + return nil, fmt.Errorf("invalid IP network address %q: %w", ifd.Network, err) + } testnet := &Testnet{ Name: filepath.Base(dir), File: fname, Dir: dir, - IP: ipGen.Network(), + IP: ipNet, InitialHeight: 1, InitialState: manifest.InitialState, Validators: map[*Node]int64{}, diff --git a/test/e2e/runner/main.go b/test/e2e/runner/main.go index 69e9360a3..fdfec7bbe 100644 --- a/test/e2e/runner/main.go +++ b/test/e2e/runner/main.go @@ -73,7 +73,7 @@ func NewCLI() *CLI { } ifd, err = e2e.InfrastructureDataFromFile(p) if err != nil { - return err + return fmt.Errorf("parsing infrastructure data: %s", err) } default: return fmt.Errorf("unknown infrastructure type '%s'", inft) @@ -81,7 +81,7 @@ func NewCLI() *CLI { testnet, err := e2e.LoadTestnet(m, file, ifd) if err != nil { - return err + return fmt.Errorf("loading testnet: %s", err) } cli.testnet = testnet