Skip to content

Commit 722f650

Browse files
committed
Slit files for getter and regtest in server
1 parent 825a710 commit 722f650

File tree

3 files changed

+274
-0
lines changed

3 files changed

+274
-0
lines changed

server/regtest.go

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
// replication-manager - Replication Manager Monitoring and CLI for MariaDB and MySQL
2+
// Copyright 2017-2021 SIGNAL18 CLOUD SAS
3+
// Author: Guillaume Lefranc <[email protected]>
4+
// License: GNU General Public License, version 3. Redistribution/Reuse of this code is permitted under the GNU v3 license, as an additional term ALL code must carry the original Author(s) credit in comment form.
5+
// See LICENSE in this directory for the integral text.
6+
7+
package server
8+
9+
import (
10+
"sort"
11+
"strings"
12+
13+
"github.com/signal18/replication-manager/cluster"
14+
"github.com/signal18/replication-manager/regtest"
15+
)
16+
17+
// RunAllTests can run
18+
// - Single scenario on the monitored cluster
19+
// - All scenarios on the monitored cluster
20+
// - All found scenarios under a given path in the test suite directory /share/test
21+
// play scenarios listed in files .todo with a config replication-manager.toml found in same directory
22+
//
23+
// Returns
24+
// - A map of cluster.Test executed
25+
// - Saved this map in the cluster datadir under tests.json file acumulate multiple run
26+
//
27+
// Workflow
28+
// - Build a map of cluster.Test based on paramater type
29+
// - Loop over the map
30+
//
31+
// Call the test that
32+
// - Copy the config.toml in cluster include directory
33+
// - Reload repman config
34+
// - Provision the cluster if test suite
35+
// - Play the scenario
36+
// - Unprovision the cluster if test suite
37+
38+
func (repman *ReplicationManager) RunAllTests(cl *cluster.Cluster, testExp string, path string) []cluster.Test {
39+
regtest := new(regtest.RegTest)
40+
var allTests = map[string]cluster.Test{}
41+
pathdefault := cl.GetShareDir() + "/tests/" + cl.GetOrchestrator() + "/config/masterslave/mariadb/without_traffic/10.5/x2/semisync"
42+
if path == "" {
43+
path = pathdefault
44+
}
45+
46+
if testExp == "SUITE" {
47+
allTests = regtest.CreateTestsFromShare(cl)
48+
allTests = regtest.GetTestsFromPath(cl, allTests, path)
49+
} else if testExp == "ALL" {
50+
allTests = regtest.GetTestsFromScenarios(cl, regtest.GetTests())
51+
} else {
52+
allTests = regtest.GetTestsFromScenarios(cl, strings.Split(testExp, ","))
53+
}
54+
55+
for key, test := range allTests {
56+
var res bool
57+
cl.LogPrintf("TEST", "%s", test.Name)
58+
59+
if testExp == "SUITE" {
60+
regtest.CopyConfig(cl, test)
61+
repman.InitConfig(repman.Conf)
62+
cl.ReloadConfig(repman.Confs["test"])
63+
cl = repman.getClusterByName("test")
64+
if !cl.InitTestCluster(test.ConfigFile, &test) {
65+
test.Result = "ERR"
66+
continue
67+
}
68+
}
69+
test.ConfigFile = cl.GetConf().ConfigFile
70+
if test.Name == "testFailoverManual" {
71+
res = regtest.TestFailoverSemisyncAutoRejoinSafeMSMXMS(cl, test.ConfigFile, &test)
72+
}
73+
if test.Name == "testFailoverSemisyncAutoRejoinSafeMSMXMS" {
74+
res = regtest.TestFailoverSemisyncAutoRejoinSafeMSMXMS(cl, test.ConfigFile, &test)
75+
}
76+
if test.Name == "testFailoverSemisyncAutoRejoinSafeMSXMSM" {
77+
res = regtest.TestFailoverSemisyncAutoRejoinSafeMSXMSM(cl, test.ConfigFile, &test)
78+
}
79+
if test.Name == "testFailoverSemisyncAutoRejoinSafeMSMXXXRMXMS" {
80+
res = regtest.TestFailoverSemisyncAutoRejoinSafeMSMXXXRMXMS(cl, test.ConfigFile, &test)
81+
}
82+
if test.Name == "testFailoverSemisyncAutoRejoinSafeMSMXXXRXSMS" {
83+
res = regtest.TestFailoverSemisyncAutoRejoinSafeMSMXXXRXSMS(cl, test.ConfigFile, &test)
84+
}
85+
if test.Name == "testFailoverSemisyncAutoRejoinUnsafeMSMXMS" {
86+
res = regtest.TestFailoverSemisyncAutoRejoinUnsafeMSMXMS(cl, test.ConfigFile, &test)
87+
}
88+
if test.Name == "testFailoverSemisyncAutoRejoinUnsafeMSMXXXMXMS" {
89+
res = regtest.TestFailoverSemisyncAutoRejoinUnsafeMSMXXXMXMS(cl, test.ConfigFile, &test)
90+
}
91+
if test.Name == "testFailoverSemisyncAutoRejoinUnsafeMSMXXXXMSM" {
92+
res = regtest.TestFailoverSemisyncAutoRejoinUnsafeMSMXXXXMSM(cl, test.ConfigFile, &test)
93+
}
94+
if test.Name == "testFailoverSemisyncAutoRejoinUnsafeMSXMSM" {
95+
res = regtest.TestFailoverSemisyncAutoRejoinUnsafeMSXMSM(cl, test.ConfigFile, &test)
96+
}
97+
if test.Name == "testFailoverSemisyncAutoRejoinUnsafeMSXMXXMXMS" {
98+
res = regtest.TestFailoverSemisyncAutoRejoinUnsafeMSXMXXMXMS(cl, test.ConfigFile, &test)
99+
}
100+
if test.Name == "testFailoverSemisyncAutoRejoinUnsafeMSXMXXXMSM" {
101+
res = regtest.TestFailoverSemisyncAutoRejoinUnsafeMSXMXXXMSM(cl, test.ConfigFile, &test)
102+
}
103+
if test.Name == "testFailoverSemisyncAutoRejoinUnsafeMSMXXXRMXMS" {
104+
res = regtest.TestFailoverSemisyncAutoRejoinUnsafeMSMXXXRMXMS(cl, test.ConfigFile, &test)
105+
}
106+
if test.Name == "testFailoverSemisyncAutoRejoinUnsafeMSMXXXRXMSM" {
107+
res = regtest.TestFailoverSemisyncAutoRejoinUnsafeMSMXXXRXMSM(cl, test.ConfigFile, &test)
108+
}
109+
if test.Name == "testFailoverAssyncAutoRejoinNoGtid" {
110+
res = regtest.TestFailoverAssyncAutoRejoinNoGtid(cl, test.ConfigFile, &test)
111+
}
112+
if test.Name == "testFailoverAssyncAutoRejoinRelay" {
113+
res = regtest.TestFailoverAssyncAutoRejoinRelay(cl, test.ConfigFile, &test)
114+
}
115+
if test.Name == "testFailoverSemisyncAutoRejoinMSSXMSXXMSXMSSM" {
116+
res = regtest.TestFailoverSemisyncAutoRejoinMSSXMSXXMSXMSSM(cl, test.ConfigFile, &test)
117+
}
118+
if test.Name == "testFailoverSemisyncAutoRejoinMSSXMSXXMXSMSSM" {
119+
res = regtest.TestFailoverSemisyncAutoRejoinMSSXMSXXMXSMSSM(cl, test.ConfigFile, &test)
120+
}
121+
if test.Name == "testFailoverSemisyncSlavekilledAutoRejoin" {
122+
res = regtest.TestFailoverSemisyncSlavekilledAutoRejoin(cl, test.ConfigFile, &test)
123+
}
124+
if test.Name == "testFailoverSemisyncAutoRejoinFlashback" {
125+
res = regtest.TestFailoverSemisyncAutoRejoinFlashback(cl, test.ConfigFile, &test)
126+
}
127+
if test.Name == "testFailoverAssyncAutoRejoinFlashback" {
128+
res = regtest.TestFailoverAssyncAutoRejoinFlashback(cl, test.ConfigFile, &test)
129+
}
130+
if test.Name == "testFailoverAssyncAutoRejoinNowrites" {
131+
res = regtest.TestFailoverAssyncAutoRejoinNowrites(cl, test.ConfigFile, &test)
132+
}
133+
if test.Name == "testFailoverAssyncAutoRejoinDump" {
134+
res = regtest.TestFailoverAssyncAutoRejoinDump(cl, test.ConfigFile, &test)
135+
}
136+
if test.Name == "testSwitchoverAllSlavesDelayMultimasterNoRplChecksNoSemiSync" {
137+
res = regtest.TestSwitchoverAllSlavesDelayMultimasterNoRplChecksNoSemiSync(cl, test.ConfigFile, &test)
138+
}
139+
if test.Name == "testSwitchoverLongTransactionNoRplCheckNoSemiSync" {
140+
res = regtest.TestSwitchoverLongTransactionNoRplCheckNoSemiSync(cl, test.ConfigFile, &test)
141+
}
142+
if test.Name == "testSwitchoverLongTrxWithoutCommitNoRplCheckNoSemiSync" {
143+
res = regtest.TestSwitchoverLongTrxWithoutCommitNoRplCheckNoSemiSync(cl, test.ConfigFile, &test)
144+
}
145+
if test.Name == "testSwitchoverLongQueryNoRplCheckNoSemiSync" {
146+
res = regtest.TestSwitchoverLongQueryNoRplCheckNoSemiSync(cl, test.ConfigFile, &test)
147+
}
148+
if test.Name == "testSwitchoverNoReadOnlyNoRplCheck" {
149+
res = regtest.TestSwitchoverNoReadOnlyNoRplCheck(cl, test.ConfigFile, &test)
150+
}
151+
if test.Name == "testSwitchoverReadOnlyNoRplCheck" {
152+
res = regtest.TestSwitchoverReadOnlyNoRplCheck(cl, test.ConfigFile, &test)
153+
}
154+
if test.Name == "testSwitchover2TimesReplicationOkNoSemiSyncNoRplCheck" {
155+
res = regtest.TestSwitchover2TimesReplicationOkNoSemiSyncNoRplCheck(cl, test.ConfigFile, &test)
156+
}
157+
if test.Name == "testSwitchover2TimesReplicationOkSemiSyncNoRplCheck" {
158+
res = regtest.TestSwitchover2TimesReplicationOkSemiSyncNoRplCheck(cl, test.ConfigFile, &test)
159+
}
160+
if test.Name == "testSwitchoverBackPreferedMasterNoRplCheckSemiSync" {
161+
res = regtest.TestSwitchoverBackPreferedMasterNoRplCheckSemiSync(cl, test.ConfigFile, &test)
162+
}
163+
if test.Name == "testSwitchoverAllSlavesStopRplCheckNoSemiSync" {
164+
res = regtest.TestSwitchoverAllSlavesStopRplCheckNoSemiSync(cl, test.ConfigFile, &test)
165+
}
166+
if test.Name == "testSwitchoverAllSlavesStopNoSemiSyncNoRplCheck" {
167+
res = regtest.TestSwitchoverAllSlavesStopNoSemiSyncNoRplCheck(cl, test.ConfigFile, &test)
168+
}
169+
if test.Name == "testSwitchoverAllSlavesDelayRplCheckNoSemiSync" {
170+
res = regtest.TestSwitchoverAllSlavesDelayRplCheckNoSemiSync(cl, test.ConfigFile, &test)
171+
}
172+
if test.Name == "testSwitchoverAllSlavesDelayNoRplChecksNoSemiSync" {
173+
res = regtest.TestSwitchoverAllSlavesDelayNoRplChecksNoSemiSync(cl, test.ConfigFile, &test)
174+
}
175+
if test.Name == "testSlaReplAllSlavesStopNoSemiSync" {
176+
res = regtest.TestSlaReplAllSlavesStopNoSemiSync(cl, test.ConfigFile, &test)
177+
}
178+
if test.Name == "testSlaReplAllSlavesDelayNoSemiSync" {
179+
res = regtest.TestSlaReplAllSlavesDelayNoSemiSync(cl, test.ConfigFile, &test)
180+
}
181+
if test.Name == "testFailoverNoRplChecksNoSemiSync" {
182+
res = regtest.TestFailoverNoRplChecksNoSemiSync(cl, test.ConfigFile, &test)
183+
}
184+
if test.Name == "testFailoverAllSlavesDelayNoRplChecksNoSemiSync" {
185+
res = regtest.TestFailoverAllSlavesDelayNoRplChecksNoSemiSync(cl, test.ConfigFile, &test)
186+
}
187+
if test.Name == "testFailoverAllSlavesDelayRplChecksNoSemiSync" {
188+
res = regtest.TestFailoverAllSlavesDelayRplChecksNoSemiSync(cl, test.ConfigFile, &test)
189+
}
190+
if test.Name == "testFailoverNumberFailureLimitReach" {
191+
res = regtest.TestFailoverNumberFailureLimitReach(cl, test.ConfigFile, &test)
192+
}
193+
if test.Name == "testFailoverTimeNotReach" {
194+
res = regtest.TestFailoverTimeNotReach(cl, test.ConfigFile, &test)
195+
}
196+
test.Result = regtest.GetTestResultLabel(res)
197+
if testExp == "SUITE" {
198+
cl.CloseTestCluster(test.ConfigFile, &test)
199+
}
200+
allTests[key] = test
201+
202+
} //end loop on all tests
203+
204+
vals := make([]cluster.Test, 0, len(allTests))
205+
keys := make([]string, 0, len(allTests))
206+
for key, val := range allTests {
207+
keys = append(keys, key)
208+
vals = append(vals, val)
209+
}
210+
sort.Strings(keys)
211+
for _, v := range keys {
212+
cl.LogPrintf("TEST", "Result %s -> %s", strings.Trim(v+strings.Repeat(" ", 60-len(v)), "test"), allTests[v].Result)
213+
}
214+
cl.CleanAll = false
215+
regtest.SaveTestsFromResult(cl, allTests)
216+
return vals
217+
}

server/server_add.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// replication-manager - Replication Manager Monitoring and CLI for MariaDB and MySQL
2+
// Copyright 2017-2021 SIGNAL18 CLOUD SAS
3+
// Author: Guillaume Lefranc <[email protected]>
4+
// License: GNU General Public License, version 3. Redistribution/Reuse of this code is permitted under the GNU v3 license, as an additional term ALL code must carry the original Author(s) credit in comment form.
5+
// See LICENSE in this directory for the integral text.
6+
7+
package server
8+
9+
import "github.com/signal18/replication-manager/config"
10+
11+
func (repman *ReplicationManager) AddCluster(clusterName string, clusterHead string) error {
12+
var myconf = make(map[string]config.Config)
13+
14+
myconf[clusterName] = repman.Conf
15+
repman.Lock()
16+
repman.ClusterList = append(repman.ClusterList, clusterName)
17+
//repman.ClusterList = repman.ClusterList
18+
repman.Confs[clusterName] = repman.Conf
19+
repman.Unlock()
20+
/*file, err := os.OpenFile(repman.Conf.ClusterConfigPath+"/"+clusterName+".toml", os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0666)
21+
if err != nil {
22+
if os.IsPermission(err) {
23+
log.Errorf("Read file permission denied: %s", repman.Conf.ClusterConfigPath+"/"+clusterName+".toml")
24+
}
25+
return err
26+
}
27+
defer file.Close()
28+
err = toml.NewEncoder(file).Encode(myconf)
29+
if err != nil {
30+
return err
31+
}*/
32+
33+
cluster, _ := repman.StartCluster(clusterName)
34+
cluster.SetClusterHead(clusterHead)
35+
cluster.SetClusterList(repman.Clusters)
36+
cluster.Save()
37+
38+
return nil
39+
40+
}

server/server_get.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// replication-manager - Replication Manager Monitoring and CLI for MariaDB and MySQL
2+
// Copyright 2017-2021 SIGNAL18 CLOUD SAS
3+
// Author: Guillaume Lefranc <[email protected]>
4+
// License: GNU General Public License, version 3. Redistribution/Reuse of this code is permitted under the GNU v3 license, as an additional term ALL code must carry the original Author(s) credit in comment form.
5+
// See LICENSE in this directory for the integral text.
6+
7+
package server
8+
9+
import "github.com/signal18/replication-manager/cluster"
10+
11+
func (repman *ReplicationManager) getClusterByName(clname string) *cluster.Cluster {
12+
var c *cluster.Cluster
13+
repman.Lock()
14+
c = repman.Clusters[clname]
15+
repman.Unlock()
16+
return c
17+
}

0 commit comments

Comments
 (0)