From 90468e074b261351eb24478f3b81c04a3b4d8b18 Mon Sep 17 00:00:00 2001 From: Jan Christoph Uhde Date: Thu, 22 Mar 2018 13:33:49 +0100 Subject: [PATCH 1/4] add test for different deployments --- tests/deployments_test.go | 103 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 tests/deployments_test.go diff --git a/tests/deployments_test.go b/tests/deployments_test.go new file mode 100644 index 000000000..3873049c7 --- /dev/null +++ b/tests/deployments_test.go @@ -0,0 +1,103 @@ +// +// DISCLAIMER +// +// Copyright 2018 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// +// Author Jan Christoph Uhde +// +package tests + +import ( + "context" + "testing" + + "github.com/dchest/uniuri" + + driver "github.com/arangodb/go-driver" + api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha" + kubeArangoClient "github.com/arangodb/kube-arangodb/pkg/client" +) + +// environements: provided from outside + +func TestDeploymentSingleMMFiles(t *testing.T) { + deploymentSubTest(t, api.DeploymentModeSingle, api.StorageEngineMMFiles) +} + +func TestDeploymentSingleRocksDB(t *testing.T) { + deploymentSubTest(t, api.DeploymentModeSingle, api.StorageEngineRocksDB) +} + +func TestDeploymentClusterMMFiles(t *testing.T) { + deploymentSubTest(t, api.DeploymentModeCluster, api.StorageEngineMMFiles) +} + +func TestDeploymentClusterRocksDB(t *testing.T) { + deploymentSubTest(t, api.DeploymentModeCluster, api.StorageEngineRocksDB) +} + +func deploymentSubTest(t *testing.T, mode api.DeploymentMode, engine api.StorageEngine) error { + // check environment + longOrSkip(t) + + k8sNameSpace := getNamespace(t) + k8sClient := mustNewKubeClient(t) + deploymentClient := kubeArangoClient.MustNewInCluster() // + + // Prepare deployment config + deploymentTemplate := newDeployment("test-1-deployment-" + string(mode) + "-" + string(engine) + "-" + uniuri.NewLen(4)) + deploymentTemplate.Spec.Mode = mode + deploymentTemplate.Spec.StorageEngine = engine + deploymentTemplate.Spec.TLS = api.TLSSpec{} // should auto-generate cert + deploymentTemplate.Spec.SetDefaults(deploymentTemplate.GetName()) // this must be last + + // Create deployment + deployment, err := deploymentClient.DatabaseV1alpha().ArangoDeployments(k8sNameSpace).Create(deploymentTemplate) + if err != nil { + t.Fatalf("Create deployment failed: %v", err) + } + + // Wait for deployment to be ready + if _, err := waitUntilDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace, deploymentHasState(api.DeploymentStateRunning)); err != nil { + t.Fatalf("Deployment not running in time: %v", err) + } + + // Create a database client + ctx := context.Background() + DBClient := mustNewArangodDatabaseClient(ctx, k8sClient, deployment, t) + + // deployment checks + if deployment.Spec.Mode == api.DeploymentModeCluster { + // Wait for cluster to be completely ready + if err := waitUntilClusterHealth(DBClient, func(h driver.ClusterHealth) error { + return clusterHealthEqualsSpec(h, deployment.Spec) + }); err != nil { + t.Fatalf("Cluster not running in expected health in time: %v", err) + } + } else if deployment.Spec.Mode == api.DeploymentModeSingle { + if err := waitUntilVersionUp(DBClient); err != nil { + t.Fatalf("Single Server not running in time: %v", err) + } + } else { + t.Fatalf("DeploymentMode %v is not supported!", deployment.Spec.Mode) + } + + // Cleanup + removeDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace) + + return nil +} From 6ee0b23e0935306cb0630c3a836a4674090de61a Mon Sep 17 00:00:00 2001 From: Jan Christoph Uhde Date: Fri, 23 Mar 2018 18:22:32 +0100 Subject: [PATCH 2/4] fix: update deployment after waiting for it to get ready --- tests/deployments_test.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tests/deployments_test.go b/tests/deployments_test.go index 3873049c7..36329ea9e 100644 --- a/tests/deployments_test.go +++ b/tests/deployments_test.go @@ -32,20 +32,24 @@ import ( kubeArangoClient "github.com/arangodb/kube-arangodb/pkg/client" ) -// environements: provided from outside +// TODO - environements (provided from outside) +// test deployment single server mmfiles func TestDeploymentSingleMMFiles(t *testing.T) { deploymentSubTest(t, api.DeploymentModeSingle, api.StorageEngineMMFiles) } +// test deployment single server rocksdb func TestDeploymentSingleRocksDB(t *testing.T) { deploymentSubTest(t, api.DeploymentModeSingle, api.StorageEngineRocksDB) } +// test deployment cluster mmfiles func TestDeploymentClusterMMFiles(t *testing.T) { deploymentSubTest(t, api.DeploymentModeCluster, api.StorageEngineMMFiles) } +// test deployment cluster rocksdb func TestDeploymentClusterRocksDB(t *testing.T) { deploymentSubTest(t, api.DeploymentModeCluster, api.StorageEngineRocksDB) } @@ -56,12 +60,12 @@ func deploymentSubTest(t *testing.T, mode api.DeploymentMode, engine api.Storage k8sNameSpace := getNamespace(t) k8sClient := mustNewKubeClient(t) - deploymentClient := kubeArangoClient.MustNewInCluster() // + deploymentClient := kubeArangoClient.MustNewInCluster() // Prepare deployment config deploymentTemplate := newDeployment("test-1-deployment-" + string(mode) + "-" + string(engine) + "-" + uniuri.NewLen(4)) - deploymentTemplate.Spec.Mode = mode - deploymentTemplate.Spec.StorageEngine = engine + deploymentTemplate.Spec.Mode = api.NewMode(mode) + deploymentTemplate.Spec.StorageEngine = api.NewStorageEngine(engine) deploymentTemplate.Spec.TLS = api.TLSSpec{} // should auto-generate cert deploymentTemplate.Spec.SetDefaults(deploymentTemplate.GetName()) // this must be last @@ -72,7 +76,8 @@ func deploymentSubTest(t *testing.T, mode api.DeploymentMode, engine api.Storage } // Wait for deployment to be ready - if _, err := waitUntilDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace, deploymentHasState(api.DeploymentStateRunning)); err != nil { + deployment, err = waitUntilDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace, deploymentHasState(api.DeploymentStateRunning)) + if err != nil { t.Fatalf("Deployment not running in time: %v", err) } @@ -81,19 +86,20 @@ func deploymentSubTest(t *testing.T, mode api.DeploymentMode, engine api.Storage DBClient := mustNewArangodDatabaseClient(ctx, k8sClient, deployment, t) // deployment checks - if deployment.Spec.Mode == api.DeploymentModeCluster { + switch mode := deployment.Spec.GetMode(); mode { + case api.DeploymentModeCluster: // Wait for cluster to be completely ready if err := waitUntilClusterHealth(DBClient, func(h driver.ClusterHealth) error { return clusterHealthEqualsSpec(h, deployment.Spec) }); err != nil { t.Fatalf("Cluster not running in expected health in time: %v", err) } - } else if deployment.Spec.Mode == api.DeploymentModeSingle { + case api.DeploymentModeSingle: if err := waitUntilVersionUp(DBClient); err != nil { t.Fatalf("Single Server not running in time: %v", err) } - } else { - t.Fatalf("DeploymentMode %v is not supported!", deployment.Spec.Mode) + default: + t.Fatalf("DeploymentMode %v is not supported!", deployment.Spec.GetMode()) } // Cleanup From c9dc159e4deea41d87dd46baa7b74135c74b06f4 Mon Sep 17 00:00:00 2001 From: Jan Christoph Uhde Date: Thu, 22 Mar 2018 13:33:49 +0100 Subject: [PATCH 3/4] add test for resilient single --- tests/deployments_test.go | 45 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/tests/deployments_test.go b/tests/deployments_test.go index 36329ea9e..35eea3423 100644 --- a/tests/deployments_test.go +++ b/tests/deployments_test.go @@ -44,6 +44,16 @@ func TestDeploymentSingleRocksDB(t *testing.T) { deploymentSubTest(t, api.DeploymentModeSingle, api.StorageEngineRocksDB) } +// test deployment resilient single server mmfiles +func TestDeploymentResilientSingleMMFiles(t *testing.T) { + deploymentSubTest(t, api.DeploymentModeResilientSingle, api.StorageEngineMMFiles) +} + +// test deployment resilient single server rocksdb +func TestDeploymentResilientSingleRocksDB(t *testing.T) { + deploymentSubTest(t, api.DeploymentModeResilientSingle, api.StorageEngineRocksDB) +} + // test deployment cluster mmfiles func TestDeploymentClusterMMFiles(t *testing.T) { deploymentSubTest(t, api.DeploymentModeCluster, api.StorageEngineMMFiles) @@ -98,8 +108,41 @@ func deploymentSubTest(t *testing.T, mode api.DeploymentMode, engine api.Storage if err := waitUntilVersionUp(DBClient); err != nil { t.Fatalf("Single Server not running in time: %v", err) } + case api.DeploymentModeResilientSingle: + if err := waitUntilVersionUp(DBClient); err != nil { + t.Fatalf("Single Server not running in time: %v", err) + } + + // FIXME - waitUntilResilientHealth + members := deployment.Status.Members + + singles := members.Single + agents := members.Agents + servers := append(append(api.MemberStatusList{}, singles...), agents...) + + if len(singles) != 2 || len(agents) != 3 { + t.Fatal("Wrong number of servers: single %v - agents %v", len(singles), len(agents)) + } + + // FIXMcase s + // - create dbconnection to each of the servers + // - run api version on connection + + //t.Fatal("This test is not fully implemented!") + + // TEST CODE BELOW + t.Log("##################################") + if len(agents) == 0 { + t.Fatal("This setup requires agents to work!") + } + + t.Logf("agents len: %v", len(agents)) + for _, server := range servers { + t.Logf("Server: %v ", server) + } + t.Log("##################################") default: - t.Fatalf("DeploymentMode %v is not supported!", deployment.Spec.GetMode()) + t.Fatalf("DeploymentMode %v is not supported!", mode) } // Cleanup From a85036cddd651ddaca15298ec09f05f7923b251d Mon Sep 17 00:00:00 2001 From: Jan Christoph Uhde Date: Fri, 23 Mar 2018 19:38:02 +0100 Subject: [PATCH 4/4] add CreateArangodClient and version up check --- tests/deployments_test.go | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/tests/deployments_test.go b/tests/deployments_test.go index 35eea3423..ae88a1fe2 100644 --- a/tests/deployments_test.go +++ b/tests/deployments_test.go @@ -30,6 +30,7 @@ import ( driver "github.com/arangodb/go-driver" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha" kubeArangoClient "github.com/arangodb/kube-arangodb/pkg/client" + arangod "github.com/arangodb/kube-arangodb/pkg/util/arangod" ) // TODO - environements (provided from outside) @@ -113,34 +114,28 @@ func deploymentSubTest(t *testing.T, mode api.DeploymentMode, engine api.Storage t.Fatalf("Single Server not running in time: %v", err) } - // FIXME - waitUntilResilientHealth members := deployment.Status.Members - singles := members.Single agents := members.Agents - servers := append(append(api.MemberStatusList{}, singles...), agents...) if len(singles) != 2 || len(agents) != 3 { t.Fatal("Wrong number of servers: single %v - agents %v", len(singles), len(agents)) } - // FIXMcase s - // - create dbconnection to each of the servers - // - run api version on connection - - //t.Fatal("This test is not fully implemented!") - - // TEST CODE BELOW - t.Log("##################################") - if len(agents) == 0 { - t.Fatal("This setup requires agents to work!") + for _, agent := range agents { + dbclient, err := arangod.CreateArangodClient(ctx, k8sClient.CoreV1(), deployment, api.ServerGroupAgents, agent.ID) + if err != nil { + t.Fatal("Unable to create connection to: %v", agent.ID) + } + waitUntilVersionUp(dbclient) } - - t.Logf("agents len: %v", len(agents)) - for _, server := range servers { - t.Logf("Server: %v ", server) + for _, single := range singles { + dbclient, err := arangod.CreateArangodClient(ctx, k8sClient.CoreV1(), deployment, api.ServerGroupAgents, single.ID) + if err != nil { + t.Fatal("Unable to create connection to: %v", single.ID) + } + waitUntilVersionUp(dbclient) } - t.Log("##################################") default: t.Fatalf("DeploymentMode %v is not supported!", mode) }