From 38c3e83cd57236ed6978e851da8060aa0ea7707f Mon Sep 17 00:00:00 2001 From: Jesse Schmidt Date: Wed, 10 Jan 2024 15:29:37 -0600 Subject: [PATCH] one more time --- integration_test.go | 139 +++++++++++++++++- .../expected/dim_nostorage_cluster_cr.conf | 1 + .../expected/hdd_dii_storage_cluster_cr.conf | 5 +- .../expected/hdd_dim_storage_cluster_cr.conf | 1 + .../expected/host_network_cluster_cr.conf | 1 + testdata/expected/podspec_cr.conf | 1 + .../expected/rack_enabled_cluster_cr.conf | 1 + testdata/expected/sc_mode_cluster_cr.conf | 1 + .../expected/shadow_device_cluster_cr.conf | 1 + testdata/expected/shadow_file_cluster_cr.conf | 3 +- .../sources/dim_nostorage_cluster_cr.yaml | 1 + .../sources/hdd_dii_storage_cluster_cr.yaml | 5 +- .../sources/hdd_dim_storage_cluster_cr.yaml | 1 + testdata/sources/host_network_cluster_cr.yaml | 1 + testdata/sources/podspec_cr.yaml | 1 + testdata/sources/rack_enabled_cluster_cr.yaml | 1 + testdata/sources/sc_mode_cluster_cr.yaml | 1 + .../sources/shadow_device_cluster_cr.yaml | 1 + testdata/sources/shadow_file_cluster_cr.yaml | 3 +- 19 files changed, 155 insertions(+), 14 deletions(-) diff --git a/integration_test.go b/integration_test.go index 6514c0c..7b21fbb 100644 --- a/integration_test.go +++ b/integration_test.go @@ -17,10 +17,13 @@ import ( "testing" "time" + as "github.com/aerospike/aerospike-client-go/v6" mgmtLib "github.com/aerospike/aerospike-management-lib" + mgmtLibInfo "github.com/aerospike/aerospike-management-lib/info" "github.com/aerospike/asconfig/cmd" "github.com/aerospike/asconfig/conf/metadata" "github.com/aerospike/asconfig/testutils" + "github.com/go-logr/logr" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" @@ -310,7 +313,7 @@ func TestYamlToConf(t *testing.T) { // test that the converted config works with an Aerospike server if !tf.SkipServerTest { version := getVersion(tf.Arguments) - id := runServer(version, confPath, dockerClient, t, tf) + id, _ := runServer(version, tf.ServerImage, confPath, tf.DockerAuth, dockerClient, t) time.Sleep(time.Second * 3) // need this to allow logs to accumulate checkContainerLogs(id, t, tf, tmpServerLogPath) @@ -381,10 +384,10 @@ func getDockerAuthFromEnv(auth testutils.DockerAuth) (string, error) { return authStr, nil } -func runServer(version string, confPath string, dockerClient *client.Client, t *testing.T, td testutils.TestData) string { +func runServer(version string, serverVersion string, confPath string, auth testutils.DockerAuth, dockerClient *client.Client, t *testing.T) (string, string) { containerName := "aerospike:" + version - if td.ServerImage != "" { - containerName = td.ServerImage + if serverVersion != "" { + containerName = serverVersion } var err error @@ -419,7 +422,7 @@ func runServer(version string, confPath string, dockerClient *client.Client, t * featureKeyPath := filepath.Join(featKeyDir, "featuresv2.conf") lastServerWithFeatureKeyVersion1 := "5.3.0" - if val, err := mgmtLib.CompareVersions(strings.TrimPrefix(version, "ee-"), lastServerWithFeatureKeyVersion1); err != nil { + if val, err := mgmtLib.CompareVersionsIgnoreRevision(strings.TrimPrefix(version, "ee-"), lastServerWithFeatureKeyVersion1); err != nil { t.Error(err) } else if val <= 0 { featureKeyPath = filepath.Join(featKeyDir, "featuresv1.conf") @@ -455,7 +458,7 @@ func runServer(version string, confPath string, dockerClient *client.Client, t * }, } - dockerAuth, err := getDockerAuthFromEnv(td.DockerAuth) + dockerAuth, err := getDockerAuthFromEnv(auth) if err != nil { t.Error(err) } @@ -469,15 +472,25 @@ func runServer(version string, confPath string, dockerClient *client.Client, t * id, err := testutils.CreateAerospikeContainer(containerName, containerConf, containerHostConf, imagePullOptions, dockerClient) if err != nil { t.Error(err) + return "", "" } + ctx := context.Background() + err = testutils.StartAerospikeContainer(id, dockerClient) if err != nil { t.Error(err) + return "", "" } - return id + resp, err := dockerClient.ContainerInspect(ctx, id) + if err != nil { + t.Error(err) + return "", "" + } + + return id, resp.NetworkSettings.IPAddress } func stopServer(id string, dockerClient *client.Client) error { @@ -710,7 +723,7 @@ func TestConfToYaml(t *testing.T) { // test that the converted config works with an Aerospike server if !tf.SkipServerTest { version := getVersion(tf.Arguments) - id := runServer(version, finalConfPath, dockerClient, t, tf) + id, _ := runServer(version, tf.ServerImage, finalConfPath, tf.DockerAuth, dockerClient, t) time.Sleep(time.Second * 3) // need this to allow logs to accumulate checkContainerLogs(id, t, tf, tmpServerLogPath) @@ -1060,3 +1073,113 @@ func TestStdinValidate(t *testing.T) { } } } + +type generateTC struct { + source string + destination string + arguments []string + version string +} + +var generateTests = []generateTC{ + { + source: filepath.Join(expectedPath, "dim_nostorage_cluster_cr.conf"), + destination: filepath.Join(destinationPath, "dim_nostorage_cluster_cr.conf"), + arguments: []string{"generate", "-h", "", "-Uadmin", "-Padmin", "--format", "asconfig", "-o", filepath.Join(destinationPath, "dim_nostorage_cluster_cr.conf")}, + version: "ee-6.4.0.2", + }, + // Uncomment after https://github.com/aerospike/schemas/pull/6 is merged and + // the schemas submodule is updated + // { + // source: filepath.Join(expectedPath, "hdd_dii_storage_cluster_cr.conf"), + // destination: filepath.Join(destinationPath, "hdd_dii_storage_cluster_cr.conf"), + // arguments: []string{"generate", "-h", "", "-Uadmin", "-Padmin", "--format", "asconfig", "-o", filepath.Join(destinationPath, "hdd_dii_storage_cluster_cr.conf")}, + // version: "ee-6.2.0.2", + // }, + // { + // source: filepath.Join(expectedPath, "hdd_dim_storage_cluster_cr.conf"), + // destination: filepath.Join(destinationPath, "hdd_dim_storage_cluster_cr.conf"), + // arguments: []string{"generate", "-h", "", "-Uadmin", "-Padmin", "--format", "asconfig", "--output", filepath.Join(destinationPath, "hdd_dim_storage_cluster_cr.conf")}, + // version: "ee-6.4.0.2", + // }, + { + source: filepath.Join(expectedPath, "podspec_cr.conf"), + destination: filepath.Join(destinationPath, "podspec_cr.conf"), + arguments: []string{"generate", "-h", "", "-Uadmin", "-Padmin", "--format", "asconfig", "-o", filepath.Join(destinationPath, "podspec_cr.conf")}, + version: "ee-6.4.0.2", + }, + { + source: filepath.Join(expectedPath, "shadow_file_cluster_cr.conf"), + destination: filepath.Join(destinationPath, "shadow_file_cluster_cr.conf"), + arguments: []string{"generate", "-h", "", "-Uadmin", "-Padmin", "--format", "asconfig", "-o", filepath.Join(destinationPath, "shadow_file_cluster_cr.conf")}, + version: "ee-6.4.0.2", + }, +} + +func TestGenerate(t *testing.T) { + dockerClient, _ := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) + + for _, tf := range generateTests { + var err error + + id, ip := runServer(tf.version, "", tf.source, testutils.DockerAuth{}, dockerClient, t) + + // Make a copy of tf.firstArgs + firstArgs := make([]string, len(tf.arguments)) + copy(firstArgs, tf.arguments) + + for idx, arg := range firstArgs { + if arg == "" { + firstArgs[idx] = ip + } + } + + time.Sleep(time.Second * 3) // need this to allow aerospike to startup + + test := exec.Command(binPath+"/asconfig.test", firstArgs...) + test.Env = []string{"GOCOVERDIR=" + coveragePath} + _, err = test.Output() + if err != nil { + t.Errorf("\nTESTCASE: %+v\nERR: %+v\n", firstArgs, string(err.(*exec.ExitError).Stderr)) + return + } + + asPolicy := as.NewClientPolicy() + asHost := as.NewHost(ip, 3000) + + asPolicy.User = "admin" + asPolicy.Password = "admin" + + firstConf, err := mgmtLibInfo.NewAsInfo(logr.Logger{}, asHost, asPolicy).AllConfigs() + + if err != nil { + t.Errorf("\nTESTCASE: %+v\nERR: %+v\n", tf, err) + } + + err = stopServer(id, dockerClient) + if err != nil { + t.Errorf("\nTESTCASE: %+v\nERR: %+v\n", tf, string(err.(*exec.ExitError).Stderr)) + } + + id, ip = runServer(tf.version, "", tf.destination, testutils.DockerAuth{}, dockerClient, t) + + time.Sleep(time.Second * 3) // need this to allow aerospike to startup + + asHost = as.NewHost(ip, 3000) + secondConf, err := mgmtLibInfo.NewAsInfo(logr.Logger{}, asHost, asPolicy).AllConfigs() + + if err != nil { + t.Errorf("\nTESTCASE: %+v\nERR: %+v\n", tf, err) + } + + err = stopServer(id, dockerClient) + if err != nil { + t.Errorf("\nTESTCASE: %+v\nERR: %+v\n", tf, string(err.(*exec.ExitError).Stderr)) + } + + // Compare the config of the two servers + if !reflect.DeepEqual(firstConf, secondConf) { + t.Errorf("\nTESTCASE: %+v\ndiff: %+v, %+v\n", tf, firstConf, secondConf) + } + } +} diff --git a/testdata/expected/dim_nostorage_cluster_cr.conf b/testdata/expected/dim_nostorage_cluster_cr.conf index 159ddfe..20340d4 100644 --- a/testdata/expected/dim_nostorage_cluster_cr.conf +++ b/testdata/expected/dim_nostorage_cluster_cr.conf @@ -24,6 +24,7 @@ network { heartbeat { mode multicast + multicast-group 239.1.99.222 port 3002 } diff --git a/testdata/expected/hdd_dii_storage_cluster_cr.conf b/testdata/expected/hdd_dii_storage_cluster_cr.conf index f74b048..d2cd6a1 100644 --- a/testdata/expected/hdd_dii_storage_cluster_cr.conf +++ b/testdata/expected/hdd_dii_storage_cluster_cr.conf @@ -14,7 +14,7 @@ namespace test { storage-engine device { data-in-memory true - file /opt/aerospike/data/test/test.dat + file /opt/aerospike/data/test.dat filesize 2000000000 } } @@ -27,7 +27,7 @@ namespace bar { storage-engine device { data-in-memory true - file /opt/aerospike/data/bar/bar.dat + file /opt/aerospike/data/bar.dat filesize 2000000000 } } @@ -40,6 +40,7 @@ network { heartbeat { mode multicast + multicast-group 239.1.99.222 port 3002 } diff --git a/testdata/expected/hdd_dim_storage_cluster_cr.conf b/testdata/expected/hdd_dim_storage_cluster_cr.conf index 2da659e..0165fe9 100644 --- a/testdata/expected/hdd_dim_storage_cluster_cr.conf +++ b/testdata/expected/hdd_dim_storage_cluster_cr.conf @@ -25,6 +25,7 @@ network { heartbeat { mode multicast + multicast-group 239.1.99.222 port 3002 } diff --git a/testdata/expected/host_network_cluster_cr.conf b/testdata/expected/host_network_cluster_cr.conf index bbf54c8..c5fc97b 100644 --- a/testdata/expected/host_network_cluster_cr.conf +++ b/testdata/expected/host_network_cluster_cr.conf @@ -23,6 +23,7 @@ network { heartbeat { mode multicast + multicast-group 239.1.99.222 port 3002 } diff --git a/testdata/expected/podspec_cr.conf b/testdata/expected/podspec_cr.conf index d8a86fe..eddd2d7 100644 --- a/testdata/expected/podspec_cr.conf +++ b/testdata/expected/podspec_cr.conf @@ -20,6 +20,7 @@ network { heartbeat { mode multicast + multicast-group 239.1.99.222 port 3002 } diff --git a/testdata/expected/rack_enabled_cluster_cr.conf b/testdata/expected/rack_enabled_cluster_cr.conf index 5c04fea..3bc06ca 100644 --- a/testdata/expected/rack_enabled_cluster_cr.conf +++ b/testdata/expected/rack_enabled_cluster_cr.conf @@ -29,6 +29,7 @@ network { heartbeat { mode multicast + multicast-group 239.1.99.222 port 3002 } diff --git a/testdata/expected/sc_mode_cluster_cr.conf b/testdata/expected/sc_mode_cluster_cr.conf index 8e8aea0..acb0bbf 100644 --- a/testdata/expected/sc_mode_cluster_cr.conf +++ b/testdata/expected/sc_mode_cluster_cr.conf @@ -24,6 +24,7 @@ network { heartbeat { mode multicast + multicast-group 239.1.99.222 port 3002 } diff --git a/testdata/expected/shadow_device_cluster_cr.conf b/testdata/expected/shadow_device_cluster_cr.conf index 0d02a60..0233b74 100644 --- a/testdata/expected/shadow_device_cluster_cr.conf +++ b/testdata/expected/shadow_device_cluster_cr.conf @@ -23,6 +23,7 @@ network { heartbeat { mode multicast + multicast-group 239.1.99.222 port 3002 } diff --git a/testdata/expected/shadow_file_cluster_cr.conf b/testdata/expected/shadow_file_cluster_cr.conf index cf324e0..d487e06 100644 --- a/testdata/expected/shadow_file_cluster_cr.conf +++ b/testdata/expected/shadow_file_cluster_cr.conf @@ -11,7 +11,7 @@ namespace test { replication-factor 2 storage-engine device { - file /local/test.dat /remote/test.dat + file /opt/aerospike/data/test.dat /opt/aerospike/data/shadow-test.dat filesize 2000000000 } } @@ -24,6 +24,7 @@ network { heartbeat { mode multicast + multicast-group 239.1.99.222 port 3002 } diff --git a/testdata/sources/dim_nostorage_cluster_cr.yaml b/testdata/sources/dim_nostorage_cluster_cr.yaml index b97cc66..a986275 100644 --- a/testdata/sources/dim_nostorage_cluster_cr.yaml +++ b/testdata/sources/dim_nostorage_cluster_cr.yaml @@ -14,6 +14,7 @@ network: port: 3001 heartbeat: mode: multicast + multicast-group: 239.1.99.222 port: 3002 service: port: 3000 diff --git a/testdata/sources/hdd_dii_storage_cluster_cr.yaml b/testdata/sources/hdd_dii_storage_cluster_cr.yaml index 97da7e5..fa5618b 100644 --- a/testdata/sources/hdd_dii_storage_cluster_cr.yaml +++ b/testdata/sources/hdd_dii_storage_cluster_cr.yaml @@ -10,7 +10,7 @@ namespaces: storage-engine: data-in-memory: true files: - - /opt/aerospike/data/test/test.dat + - /opt/aerospike/data/test.dat filesize: 2000000000 type: device - data-in-index: true @@ -21,7 +21,7 @@ namespaces: storage-engine: data-in-memory: true files: - - /opt/aerospike/data/bar/bar.dat + - /opt/aerospike/data/bar.dat filesize: 2000000000 type: device network: @@ -29,6 +29,7 @@ network: port: 3001 heartbeat: mode: multicast + multicast-group: 239.1.99.222 port: 3002 service: port: 3000 diff --git a/testdata/sources/hdd_dim_storage_cluster_cr.yaml b/testdata/sources/hdd_dim_storage_cluster_cr.yaml index 9f2a98a..24e5467 100644 --- a/testdata/sources/hdd_dim_storage_cluster_cr.yaml +++ b/testdata/sources/hdd_dim_storage_cluster_cr.yaml @@ -16,6 +16,7 @@ network: port: 3001 heartbeat: mode: multicast + multicast-group: 239.1.99.222 port: 3002 service: port: 3000 diff --git a/testdata/sources/host_network_cluster_cr.yaml b/testdata/sources/host_network_cluster_cr.yaml index 53a7e6b..f5309cc 100644 --- a/testdata/sources/host_network_cluster_cr.yaml +++ b/testdata/sources/host_network_cluster_cr.yaml @@ -14,6 +14,7 @@ network: port: 3001 heartbeat: mode: multicast + multicast-group: 239.1.99.222 port: 3002 service: port: 3000 diff --git a/testdata/sources/podspec_cr.yaml b/testdata/sources/podspec_cr.yaml index e4cc01e..ca0f800 100644 --- a/testdata/sources/podspec_cr.yaml +++ b/testdata/sources/podspec_cr.yaml @@ -12,6 +12,7 @@ network: port: 3001 heartbeat: mode: multicast + multicast-group: 239.1.99.222 port: 3002 service: port: 3000 diff --git a/testdata/sources/rack_enabled_cluster_cr.yaml b/testdata/sources/rack_enabled_cluster_cr.yaml index a5002c5..72237b6 100644 --- a/testdata/sources/rack_enabled_cluster_cr.yaml +++ b/testdata/sources/rack_enabled_cluster_cr.yaml @@ -19,6 +19,7 @@ network: port: 3001 heartbeat: mode: multicast + multicast-group: 239.1.99.222 port: 3002 service: port: 3000 diff --git a/testdata/sources/sc_mode_cluster_cr.yaml b/testdata/sources/sc_mode_cluster_cr.yaml index b369252..f75a9d7 100644 --- a/testdata/sources/sc_mode_cluster_cr.yaml +++ b/testdata/sources/sc_mode_cluster_cr.yaml @@ -15,6 +15,7 @@ network: port: 3001 heartbeat: mode: multicast + multicast-group: 239.1.99.222 port: 3002 service: port: 3000 diff --git a/testdata/sources/shadow_device_cluster_cr.yaml b/testdata/sources/shadow_device_cluster_cr.yaml index f19e18e..a184ed7 100644 --- a/testdata/sources/shadow_device_cluster_cr.yaml +++ b/testdata/sources/shadow_device_cluster_cr.yaml @@ -14,6 +14,7 @@ network: port: 3001 heartbeat: mode: multicast + multicast-group: 239.1.99.222 port: 3002 service: port: 3000 diff --git a/testdata/sources/shadow_file_cluster_cr.yaml b/testdata/sources/shadow_file_cluster_cr.yaml index 5780d54..4e1514a 100644 --- a/testdata/sources/shadow_file_cluster_cr.yaml +++ b/testdata/sources/shadow_file_cluster_cr.yaml @@ -7,7 +7,7 @@ namespaces: replication-factor: 2 storage-engine: files: - - /local/test.dat /remote/test.dat + - /opt/aerospike/data/test.dat /opt/aerospike/data/shadow-test.dat filesize: 2000000000 type: device network: @@ -15,6 +15,7 @@ network: port: 3001 heartbeat: mode: multicast + multicast-group: 239.1.99.222 port: 3002 service: port: 3000