|
| 1 | +// |
| 2 | +// DISCLAIMER |
| 3 | +// |
| 4 | +// Copyright 2018 ArangoDB GmbH, Cologne, Germany |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// |
| 18 | +// Copyright holder is ArangoDB GmbH, Cologne, Germany |
| 19 | +// |
| 20 | +// Author Jan Christoph Uhde <jan@uhdejc.com> |
| 21 | +// |
| 22 | +package tests |
| 23 | + |
| 24 | +import ( |
| 25 | + "context" |
| 26 | + "testing" |
| 27 | + |
| 28 | + "github.com/dchest/uniuri" |
| 29 | + |
| 30 | + driver "github.com/arangodb/go-driver" |
| 31 | + api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha" |
| 32 | + kubeArangoClient "github.com/arangodb/kube-arangodb/pkg/client" |
| 33 | + arangod "github.com/arangodb/kube-arangodb/pkg/util/arangod" |
| 34 | +) |
| 35 | + |
| 36 | +// TODO - environements (provided from outside) |
| 37 | + |
| 38 | +// test deployment single server mmfiles |
| 39 | +func TestDeploymentSingleMMFiles(t *testing.T) { |
| 40 | + deploymentSubTest(t, api.DeploymentModeSingle, api.StorageEngineMMFiles) |
| 41 | +} |
| 42 | + |
| 43 | +// test deployment single server rocksdb |
| 44 | +func TestDeploymentSingleRocksDB(t *testing.T) { |
| 45 | + deploymentSubTest(t, api.DeploymentModeSingle, api.StorageEngineRocksDB) |
| 46 | +} |
| 47 | + |
| 48 | +// test deployment resilient single server mmfiles |
| 49 | +func TestDeploymentResilientSingleMMFiles(t *testing.T) { |
| 50 | + deploymentSubTest(t, api.DeploymentModeResilientSingle, api.StorageEngineMMFiles) |
| 51 | +} |
| 52 | + |
| 53 | +// test deployment resilient single server rocksdb |
| 54 | +func TestDeploymentResilientSingleRocksDB(t *testing.T) { |
| 55 | + deploymentSubTest(t, api.DeploymentModeResilientSingle, api.StorageEngineRocksDB) |
| 56 | +} |
| 57 | + |
| 58 | +// test deployment cluster mmfiles |
| 59 | +func TestDeploymentClusterMMFiles(t *testing.T) { |
| 60 | + deploymentSubTest(t, api.DeploymentModeCluster, api.StorageEngineMMFiles) |
| 61 | +} |
| 62 | + |
| 63 | +// test deployment cluster rocksdb |
| 64 | +func TestDeploymentClusterRocksDB(t *testing.T) { |
| 65 | + deploymentSubTest(t, api.DeploymentModeCluster, api.StorageEngineRocksDB) |
| 66 | +} |
| 67 | + |
| 68 | +func deploymentSubTest(t *testing.T, mode api.DeploymentMode, engine api.StorageEngine) error { |
| 69 | + // check environment |
| 70 | + longOrSkip(t) |
| 71 | + |
| 72 | + k8sNameSpace := getNamespace(t) |
| 73 | + k8sClient := mustNewKubeClient(t) |
| 74 | + deploymentClient := kubeArangoClient.MustNewInCluster() |
| 75 | + |
| 76 | + // Prepare deployment config |
| 77 | + deploymentTemplate := newDeployment("test-1-deployment-" + string(mode) + "-" + string(engine) + "-" + uniuri.NewLen(4)) |
| 78 | + deploymentTemplate.Spec.Mode = api.NewMode(mode) |
| 79 | + deploymentTemplate.Spec.StorageEngine = api.NewStorageEngine(engine) |
| 80 | + deploymentTemplate.Spec.TLS = api.TLSSpec{} // should auto-generate cert |
| 81 | + deploymentTemplate.Spec.SetDefaults(deploymentTemplate.GetName()) // this must be last |
| 82 | + |
| 83 | + // Create deployment |
| 84 | + deployment, err := deploymentClient.DatabaseV1alpha().ArangoDeployments(k8sNameSpace).Create(deploymentTemplate) |
| 85 | + if err != nil { |
| 86 | + t.Fatalf("Create deployment failed: %v", err) |
| 87 | + } |
| 88 | + |
| 89 | + // Wait for deployment to be ready |
| 90 | + deployment, err = waitUntilDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace, deploymentHasState(api.DeploymentStateRunning)) |
| 91 | + if err != nil { |
| 92 | + t.Fatalf("Deployment not running in time: %v", err) |
| 93 | + } |
| 94 | + |
| 95 | + // Create a database client |
| 96 | + ctx := context.Background() |
| 97 | + DBClient := mustNewArangodDatabaseClient(ctx, k8sClient, deployment, t) |
| 98 | + |
| 99 | + // deployment checks |
| 100 | + switch mode := deployment.Spec.GetMode(); mode { |
| 101 | + case api.DeploymentModeCluster: |
| 102 | + // Wait for cluster to be completely ready |
| 103 | + if err := waitUntilClusterHealth(DBClient, func(h driver.ClusterHealth) error { |
| 104 | + return clusterHealthEqualsSpec(h, deployment.Spec) |
| 105 | + }); err != nil { |
| 106 | + t.Fatalf("Cluster not running in expected health in time: %v", err) |
| 107 | + } |
| 108 | + case api.DeploymentModeSingle: |
| 109 | + if err := waitUntilVersionUp(DBClient); err != nil { |
| 110 | + t.Fatalf("Single Server not running in time: %v", err) |
| 111 | + } |
| 112 | + case api.DeploymentModeResilientSingle: |
| 113 | + if err := waitUntilVersionUp(DBClient); err != nil { |
| 114 | + t.Fatalf("Single Server not running in time: %v", err) |
| 115 | + } |
| 116 | + |
| 117 | + members := deployment.Status.Members |
| 118 | + singles := members.Single |
| 119 | + agents := members.Agents |
| 120 | + |
| 121 | + if len(singles) != 2 || len(agents) != 3 { |
| 122 | + t.Fatal("Wrong number of servers: single %v - agents %v", len(singles), len(agents)) |
| 123 | + } |
| 124 | + |
| 125 | + for _, agent := range agents { |
| 126 | + dbclient, err := arangod.CreateArangodClient(ctx, k8sClient.CoreV1(), deployment, api.ServerGroupAgents, agent.ID) |
| 127 | + if err != nil { |
| 128 | + t.Fatal("Unable to create connection to: %v", agent.ID) |
| 129 | + } |
| 130 | + waitUntilVersionUp(dbclient) |
| 131 | + } |
| 132 | + for _, single := range singles { |
| 133 | + dbclient, err := arangod.CreateArangodClient(ctx, k8sClient.CoreV1(), deployment, api.ServerGroupAgents, single.ID) |
| 134 | + if err != nil { |
| 135 | + t.Fatal("Unable to create connection to: %v", single.ID) |
| 136 | + } |
| 137 | + waitUntilVersionUp(dbclient) |
| 138 | + } |
| 139 | + default: |
| 140 | + t.Fatalf("DeploymentMode %v is not supported!", mode) |
| 141 | + } |
| 142 | + |
| 143 | + // Cleanup |
| 144 | + removeDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace) |
| 145 | + |
| 146 | + return nil |
| 147 | +} |
0 commit comments