diff --git a/tests/antithesis/config/docker-compose-1-node.yml b/tests/antithesis/config/docker-compose-1-node.yml index a18651c0b0e8..265f5fd9e84b 100644 --- a/tests/antithesis/config/docker-compose-1-node.yml +++ b/tests/antithesis/config/docker-compose-1-node.yml @@ -50,6 +50,10 @@ services: container_name: client entrypoint: ["/opt/antithesis/entrypoint/entrypoint"] user: "${USER_ID:-root}:${GROUP_ID:-root}" + environment: + ETCD_ROBUSTNESS_ENDPOINTS: "etcd0:2379" + ETCD_ROBUSTNESS_DATA_PATHS: "/var/etcddata0" + ETCD_ROBUSTNESS_REPORT_PATH: "/var/report" depends_on: etcd0: condition: service_started diff --git a/tests/antithesis/config/docker-compose-3-node.yml b/tests/antithesis/config/docker-compose-3-node.yml index c5160ddf10f3..bc779af0de48 100644 --- a/tests/antithesis/config/docker-compose-3-node.yml +++ b/tests/antithesis/config/docker-compose-3-node.yml @@ -106,6 +106,10 @@ services: container_name: client entrypoint: ["/opt/antithesis/entrypoint/entrypoint"] user: "${USER_ID:-root}:${GROUP_ID:-root}" + environment: + ETCD_ROBUSTNESS_ENDPOINTS: "etcd0:2379,etcd1:2379,etcd2:2379" + ETCD_ROBUSTNESS_DATA_PATHS: "/var/etcddata0,/var/etcddata1,/var/etcddata2" + ETCD_ROBUSTNESS_REPORT_PATH: "/var/report" depends_on: etcd0: condition: service_started diff --git a/tests/antithesis/test-template/entrypoint/main.go b/tests/antithesis/test-template/entrypoint/main.go index ab9e365b3dd6..0457dc242516 100644 --- a/tests/antithesis/test-template/entrypoint/main.go +++ b/tests/antithesis/test-template/entrypoint/main.go @@ -35,17 +35,16 @@ var NodeCount = "3" // CheckHealth checks health of all etcd nodes func CheckHealth() bool { cfg := common.MakeConfig(NodeCount) + hosts, _, _ := common.GetPaths(cfg) - nodeOptions := []string{"etcd0", "etcd1", "etcd2"}[:cfg.NodeCount] - - // iterate over each node and check health - for _, node := range nodeOptions { + // iterate over each host and check health + for _, host := range hosts { cli, err := clientv3.New(clientv3.Config{ - Endpoints: []string{fmt.Sprintf("http://%s:2379", node)}, + Endpoints: []string{fmt.Sprintf("http://%s", host)}, DialTimeout: 5 * time.Second, }) if err != nil { - fmt.Printf("Client [entrypoint]: connection failed with %s\n", node) + fmt.Printf("Client [entrypoint]: connection failed with %s\n", host) fmt.Printf("Client [entrypoint]: error: %v\n", err) return false } @@ -60,12 +59,12 @@ func CheckHealth() bool { // fetch the key setting-up to confirm that the node is available _, err = cli.Get(context.Background(), "setting-up") if err != nil { - fmt.Printf("Client [entrypoint]: connection failed with %s\n", node) + fmt.Printf("Client [entrypoint]: connection failed with %s\n", host) fmt.Printf("Client [entrypoint]: error: %v\n", err) return false } - fmt.Printf("Client [entrypoint]: connection successful with %s\n", node) + fmt.Printf("Client [entrypoint]: connection successful with %s\n", host) } return true diff --git a/tests/antithesis/test-template/robustness/common/path.go b/tests/antithesis/test-template/robustness/common/path.go index 99d1cd167272..d7bff6dfc301 100644 --- a/tests/antithesis/test-template/robustness/common/path.go +++ b/tests/antithesis/test-template/robustness/common/path.go @@ -19,6 +19,7 @@ package common import ( "fmt" "os" + "strings" ) const ( @@ -36,9 +37,49 @@ const ( defaultetcdLocalDataPath = "/tmp/etcddata%d" localetcdDataPathEnv = "ETCD_ROBUSTNESS_DATA_PATH_PREFIX" localReportPath = "report" + + endpointsEnv = "ETCD_ROBUSTNESS_ENDPOINTS" + dataPathsEnv = "ETCD_ROBUSTNESS_DATA_PATHS" + reportPathEnv = "ETCD_ROBUSTNESS_REPORT_PATH" ) -func DefaultPaths(cfg *Config) (hosts []string, reportPath string, dataPaths map[string]string) { +func GetPaths(cfg *Config) (hosts []string, reportPath string, dataPaths map[string]string) { + // Check for environment variable overrides first + envDataPathsStr := os.Getenv(dataPathsEnv) + envReportPath := os.Getenv(reportPathEnv) + envEndpointsStr := os.Getenv(endpointsEnv) + + defaultHosts, defaultReportPath, defaultDataPaths := defaultPaths(cfg) + + hosts = defaultHosts + if envEndpointsStr != "" { + hosts = strings.Split(envEndpointsStr, ",") + for i, host := range hosts { + hosts[i] = strings.TrimSpace(host) + } + } + + reportPath = defaultReportPath + if envReportPath != "" { + reportPath = envReportPath + } + + dataPaths = defaultDataPaths + if envDataPathsStr != "" { + envDataPaths := strings.Split(envDataPathsStr, ",") + if len(envDataPaths) != len(hosts) { + panic(fmt.Sprintf("Mismatched number of endpoints and data paths: %d endpoints, %d data paths", len(hosts), len(envDataPaths))) + } + + dataPaths = make(map[string]string) + for i, endpoint := range hosts { + dataPaths[endpoint] = strings.TrimSpace(envDataPaths[i]) + } + } + return hosts, reportPath, dataPaths +} + +func defaultPaths(cfg *Config) (hosts []string, reportPath string, dataPaths map[string]string) { hosts = []string{defaultetcd0, defaultetcd1, defaultetcd2}[:cfg.NodeCount] reportPath = defaultReportPath dataPaths = etcdDataPaths(defaultetcdDataPath, cfg.NodeCount) diff --git a/tests/antithesis/test-template/robustness/finally/main.go b/tests/antithesis/test-template/robustness/finally/main.go index da9b87e591f8..aeffc9735951 100644 --- a/tests/antithesis/test-template/robustness/finally/main.go +++ b/tests/antithesis/test-template/robustness/finally/main.go @@ -44,7 +44,7 @@ func main() { cfg := common.MakeConfig(NodeCount) - _, reportPath, dirs := common.DefaultPaths(cfg) + _, reportPath, dirs := common.GetPaths(cfg) if *local { _, reportPath, dirs = common.LocalPaths(cfg) } diff --git a/tests/antithesis/test-template/robustness/traffic/main.go b/tests/antithesis/test-template/robustness/traffic/main.go index 0fdaf546c333..b4ac6d6a3764 100644 --- a/tests/antithesis/test-template/robustness/traffic/main.go +++ b/tests/antithesis/test-template/robustness/traffic/main.go @@ -69,7 +69,7 @@ func main() { cfg := common.MakeConfig(NodeCount) - hosts, reportPath, etcdetcdDataPaths := common.DefaultPaths(cfg) + hosts, reportPath, etcdetcdDataPaths := common.GetPaths(cfg) if *local { hosts, reportPath, etcdetcdDataPaths = common.LocalPaths(cfg) }