Skip to content

Commit

Permalink
fix: TOOLS-2622 correctly parse asconf non humanized uint (#14)
Browse files Browse the repository at this point in the history
* fix: correctly parse asconf non humanized uint

* ci: tests use v1 and v2 feature keys
  • Loading branch information
dwelch-spike authored Aug 15, 2023
1 parent 91e7dd6 commit 8f006d2
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 21 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ jobs:
- name: Install dependencies
run: |
make dependencies
- name: Write feature key
- name: Write feature keys
run: |
echo "$FEATURES" > /tmp/features.conf
echo "$FEATURESV1" > /tmp/featuresv1.conf
echo "$FEATURESV2" > /tmp/featuresv2.conf
env:
FEATURES : ${{secrets.SINGLE_NODE_EE_FEATURE_KEY}}
FEATURESV1 : ${{secrets.FEATURES_V1}}
FEATURESV2 : ${{secrets.FEATURES_V2}}
- name: Run tests
run: |
make coverage
env:
FEATKEY : /tmp/features.conf
FEATKEY : /tmp
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module aerospike/asconfig
go 1.19

require (
github.com/aerospike/aerospike-management-lib v0.0.0-20230628001501-9fe4e850c22f
github.com/aerospike/aerospike-management-lib v0.0.0-20230721181710-e0ad7587b911
github.com/bombsimon/logrusr/v4 v4.0.0
github.com/docker/docker v23.0.3+incompatible
github.com/go-logr/logr v1.2.3
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbt
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/aerospike/aerospike-management-lib v0.0.0-20230628001501-9fe4e850c22f h1:poZZGgsM1Y8so7mISgtUPiWS33kr2bR/gsEjiGcyeuw=
github.com/aerospike/aerospike-management-lib v0.0.0-20230628001501-9fe4e850c22f/go.mod h1:sTlH+QtluBfc1ZkUaB3sfpZxd4aIux13ENkztyh0lsY=
github.com/aerospike/aerospike-management-lib v0.0.0-20230721173757-ee3d780a0142 h1:pv+YsMbXfDDlOJx74CYLEn8amHSOi4YrsaOr3OHde3M=
github.com/aerospike/aerospike-management-lib v0.0.0-20230721173757-ee3d780a0142/go.mod h1:sTlH+QtluBfc1ZkUaB3sfpZxd4aIux13ENkztyh0lsY=
github.com/aerospike/aerospike-management-lib v0.0.0-20230721181710-e0ad7587b911 h1:pZ7Z38Qvy8am2xNrerESD+RDUjR0t4uja5bc1bZGCpc=
github.com/aerospike/aerospike-management-lib v0.0.0-20230721181710-e0ad7587b911/go.mod h1:sTlH+QtluBfc1ZkUaB3sfpZxd4aIux13ENkztyh0lsY=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/bombsimon/logrusr/v4 v4.0.0 h1:Pm0InGphX0wMhPqC02t31onlq9OVyJ98eP/Vh63t1Oo=
github.com/bombsimon/logrusr/v4 v4.0.0/go.mod h1:pjfHC5e59CvjTBIU3V3sGhFWFAnsnhOR03TRc6im0l8=
Expand Down
57 changes: 43 additions & 14 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const (
tmpServerLogPath = "testdata/tmp_server.log"
)

var featKeyPath string
var featKeyDir string

func TestMain(m *testing.M) {
if _, err := os.Stat(destinationPath); errors.Is(err, os.ErrNotExist) {
Expand Down Expand Up @@ -72,12 +72,12 @@ func TestMain(m *testing.M) {
for _, v := range envVars {
pair := strings.Split(v, "=")
if pair[0] == "FEATKEY" {
featKeyPath = pair[1]
featKeyDir = pair[1]
}
}

if featKeyPath == "" {
panic("FEATKEY environement variable must be full path to a valid aerospike feature key file")
if featKeyDir == "" {
panic("FEATKEY environement variable must be full path to a directory containing valid aerospike feature key files featuresv1.conf and featuresv2.conf of feature key format 1 and 2 respectively.")
}

code := m.Run()
Expand Down Expand Up @@ -204,13 +204,13 @@ var testFiles = []testutils.TestData{
Source: filepath.Join(sourcePath, "xdr_dst_cluster_cr.yaml"),
Destination: filepath.Join(destinationPath, "xdr_dst_cluster_cr.conf"),
Expected: filepath.Join(expectedPath, "xdr_dst_cluster_cr.conf"),
Arguments: []string{"convert", "-a", "6.2.0.2", "-o", destinationPath},
Arguments: []string{"convert", "-a", "5.6.0.13", "-o", destinationPath},
},
{
Source: filepath.Join(sourcePath, "xdr_src_cluster_cr.yaml"),
Destination: filepath.Join(destinationPath, "xdr_src_cluster_cr.conf"),
Expected: filepath.Join(expectedPath, "xdr_src_cluster_cr.conf"),
Arguments: []string{"convert", "-a", "5.3.0.16", "-o", filepath.Join(destinationPath, "xdr_src_cluster_cr.conf")},
Arguments: []string{"convert", "-a", "6.3.0.6", "-o", filepath.Join(destinationPath, "xdr_src_cluster_cr.conf")},
},
{
Source: filepath.Join(sourcePath, "missing_heartbeat_mode.yaml"),
Expand All @@ -232,6 +232,28 @@ var testFiles = []testutils.TestData{
},
}

func versionLessThanEqual(l string, r string) bool {
var majorLess, minorLess, patchLess bool
ltok := strings.Split(l, ".")
rtok := strings.Split(r, ".")

lmaj, _ := strconv.Atoi(ltok[0])
lmin, _ := strconv.Atoi(ltok[1])
lpat, _ := strconv.Atoi(ltok[2])

rmaj, _ := strconv.Atoi(rtok[0])
rmin, _ := strconv.Atoi(rtok[1])
rpat, _ := strconv.Atoi(rtok[2])

majorLess = lmaj <= rmaj
minorLess = lmin <= rmin
patchLess = lpat <= rpat

return (majorLess && minorLess && patchLess) ||
(majorLess && minorLess && !patchLess) ||
(majorLess && !minorLess && !patchLess)
}

func getVersion(l []string) (v string) {
i := testutils.IndexOf(l, "-a")
if i >= 0 {
Expand Down Expand Up @@ -382,6 +404,13 @@ func runServer(version string, confPath string, dockerClient *client.Client, t *
}
tmpf.Close()

featureKeyPath := filepath.Join(featKeyDir, "featuresv2.conf")
lastServerWithFeatureKeyVersion1 := "5.3.0"
if versionLessThanEqual(strings.TrimPrefix(version, "ee-"), lastServerWithFeatureKeyVersion1) {
featureKeyPath = filepath.Join(featKeyDir, "featuresv1.conf")
}
fmt.Println(featureKeyPath)

containerHostConf := &container.HostConfig{
Mounts: []mount.Mount{
{
Expand All @@ -391,12 +420,12 @@ func runServer(version string, confPath string, dockerClient *client.Client, t *
},
{
Type: mount.TypeBind,
Source: featKeyPath,
Source: featureKeyPath,
Target: "/etc/aerospike/secret/features.conf",
},
{
Type: mount.TypeBind,
Source: featKeyPath,
Source: featureKeyPath,
Target: "/etc/aerospike/features.conf",
},
{
Expand Down Expand Up @@ -633,7 +662,7 @@ var confToYamlTests = []testutils.TestData{
Source: filepath.Join(expectedPath, "xdr_src_cluster_cr.conf"),
Destination: filepath.Join(destinationPath, "xdr_src_cluster_cr.yaml"),
Expected: filepath.Join(sourcePath, "xdr_src_cluster_cr.yaml"),
Arguments: []string{"convert", "-a", "5.3.0.16", "--format", "asconfig", "-o", filepath.Join(destinationPath, "xdr_src_cluster_cr.yaml")},
Arguments: []string{"convert", "-a", "6.3.0.6", "--format", "asconfig", "-o", filepath.Join(destinationPath, "xdr_src_cluster_cr.yaml")},
},
{
Source: filepath.Join(expectedPath, "missing_heartbeat_mode.conf"),
Expand Down Expand Up @@ -673,7 +702,7 @@ func TestConfToYaml(t *testing.T) {
test.Env = []string{"GOCOVERDIR=" + coveragePath}
out, err := test.Output()
if err != nil {
t.Error(string(err.(*exec.ExitError).Stderr))
t.Errorf("\nTESTCASE: %+v\nERR: %+v\n", tf, string(err.(*exec.ExitError).Stderr))
}

var actual []byte
Expand All @@ -682,7 +711,7 @@ func TestConfToYaml(t *testing.T) {
} else {
actual, err = os.ReadFile(tf.Destination)
if err != nil {
t.Error(err)
t.Errorf("\nTESTCASE: %+v\nERR: %+v\n", tf, err)
}
}

Expand All @@ -708,7 +737,7 @@ func TestConfToYaml(t *testing.T) {
test.Env = []string{"GOCOVERDIR=" + coveragePath}
_, err = test.Output()
if err != nil {
t.Error(string(err.(*exec.ExitError).Stderr))
t.Errorf("\nTESTCASE: %+v\nERR: %+v\n", tf, string(err.(*exec.ExitError).Stderr))
}

// verify that the generated conf matches the source conf
Expand All @@ -724,11 +753,11 @@ func TestConfToYaml(t *testing.T) {

// cleanup the destination files
if err := os.Remove(finalConfPath); err != nil {
t.Error(err)
t.Errorf("\nTESTCASE: %+v\nERR: %+v\n", tf, err)
}

if err := os.Remove(confPath); err != nil {
t.Error(err)
t.Errorf("\nTESTCASE: %+v\nERR: %+v\n", tf, err)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions testdata/cases/stop-write/conf-tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"Source":"testdata/cases/stop-write/stop-write.conf","Destination":"testdata/cases/stop-write/stop-write-res-.yaml","Expected":"testdata/cases/stop-write/stop-write.yaml","Arguments":["convert","--aerospike-version","6.3.0.6","--format","asconfig","--output","testdata/cases/stop-write/stop-write-res-.yaml"],"SkipServerTest":false,"ServerErrorAllowList":null}]
59 changes: 59 additions & 0 deletions testdata/cases/stop-write/stop-write.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

logging {

console {
context any info
}
}

namespace test {
memory-size 1G
replication-factor 2

storage-engine device {
data-in-memory true
file /opt/aerospike/data/test.dat
filesize 2000000000
}

set s1 {
stop-writes-count 10G
stop-writes-size 10M
}
}

network {

fabric {
port 3001
}

heartbeat {
mode multicast
port 3002
}

service {
port 3000
}
}

security {
}

service {
feature-key-file /etc/aerospike/secret/features.conf
}

xdr {

dc dc1 {
auth-mode internal
auth-password-file /etc/aerospike/secret/password_DC1.txt
auth-user admin
node-address-port aeroclusterdst-0-0 3000

namespace test {
}
}
}
38 changes: 38 additions & 0 deletions testdata/cases/stop-write/stop-write.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
logging:
- any: info
name: console
namespaces:
- memory-size: 1073741824
name: test
replication-factor: 2
sets:
- name: s1
stop-writes-count: 10737418240
stop-writes-size: 10485760
storage-engine:
data-in-memory: true
files:
- /opt/aerospike/data/test.dat
filesize: 2000000000
type: device
network:
fabric:
port: 3001
heartbeat:
mode: multicast
port: 3002
service:
port: 3000
security: {}
service:
feature-key-file: /etc/aerospike/secret/features.conf
xdr:
dcs:
- auth-mode: internal
auth-password-file: /etc/aerospike/secret/password_DC1.txt
auth-user: admin
name: dc1
namespaces:
- name: test
node-address-ports:
- aeroclusterdst-0-0:3000
1 change: 1 addition & 0 deletions testdata/cases/stop-write/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"TestedVersion":"6.3.0.6","OriginallyUsedVersion":"6.3.0.6"}
1 change: 1 addition & 0 deletions testdata/cases/stop-write/yaml-tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"Source":"testdata/cases/stop-write/stop-write.yaml","Destination":"testdata/cases/stop-write/stop-write-res-.conf","Expected":"testdata/cases/stop-write/stop-write.conf","Arguments":["convert","--aerospike-version","6.3.0.6","--format","yaml","--output","testdata/cases/stop-write/stop-write-res-.conf"],"SkipServerTest":false,"ServerErrorAllowList":null}]
7 changes: 6 additions & 1 deletion testdata/expected/xdr_src_cluster_cr.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ logging {
}

namespace test {
memory-size 3000000000
memory-size 18446744073709551615
replication-factor 2

storage-engine device {
data-in-memory true
file /opt/aerospike/data/test.dat
filesize 2000000000
}

set s1 {
stop-writes-count 18446744073709551615
stop-writes-size 18446744073709551615
}
}

network {
Expand Down
6 changes: 5 additions & 1 deletion testdata/sources/xdr_src_cluster_cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ logging:
- any: info
name: console
namespaces:
- memory-size: 3000000000
- memory-size: 18446744073709551615
name: test
replication-factor: 2
sets:
- name: s1
stop-writes-count: 18446744073709551615
stop-writes-size: 18446744073709551615
storage-engine:
data-in-memory: true
files:
Expand Down

0 comments on commit 8f006d2

Please sign in to comment.