Skip to content

Commit c98084e

Browse files
committed
update yugabyte_test.go
Signed-off-by: Sameer Kulkarni <[email protected]>
1 parent d3447b4 commit c98084e

File tree

1 file changed

+19
-122
lines changed

1 file changed

+19
-122
lines changed

test/yugabyte_test.go

Lines changed: 19 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package yugabyte
33
import (
44
"crypto/tls"
55
"fmt"
6-
"io/ioutil"
76
"os"
87
"path/filepath"
98
"strings"
@@ -71,10 +70,12 @@ func TestYugaByteGcpTerraform(t *testing.T) {
7170
testYugaByteYSQLSH(t, terraformOptions, maxRetries, timeBetweenRetries, keyPair, publicIP)
7271
testYugaByteCQLSH(t, terraformOptions, maxRetries, timeBetweenRetries, keyPair, publicIP)
7372
testYugaByteConf(t, terraformOptions, maxRetries, timeBetweenRetries, keyPair, publicIP, yugabyteDir)
74-
testYugaByteMasterProcess(t, terraformOptions, maxRetries, timeBetweenRetries, keyPair, publicIP)
75-
testYugaByteTserverProcess(t, terraformOptions, maxRetries, timeBetweenRetries, keyPair, publicIP)
76-
testYugaByteMasterLog(t, terraformOptions, maxRetries, timeBetweenRetries, keyPair, publicIP)
77-
testYugaByteTserverLog(t, terraformOptions, maxRetries, timeBetweenRetries, keyPair, publicIP)
73+
testYugaByteProcess(t, terraformOptions, maxRetries, timeBetweenRetries, keyPair, publicIP, "yb-master")
74+
testYugaByteProcess(t, terraformOptions, maxRetries, timeBetweenRetries, keyPair, publicIP, "yb-tserver")
75+
testYugaByteLogFile(t, terraformOptions, maxRetries, timeBetweenRetries, keyPair, publicIP, "master.out", "master")
76+
testYugaByteLogFile(t, terraformOptions, maxRetries, timeBetweenRetries, keyPair, publicIP, "master.err", "master")
77+
testYugaByteLogFile(t, terraformOptions, maxRetries, timeBetweenRetries, keyPair, publicIP, "tserver.out", "tserver")
78+
testYugaByteLogFile(t, terraformOptions, maxRetries, timeBetweenRetries, keyPair, publicIP, "tserver.err", "tserver")
7879

7980
}
8081

@@ -145,37 +146,6 @@ func testYugaByteSSH(t *testing.T, terraformOptions *terraform.Options, maxRetri
145146

146147
}
147148

148-
func testYugaByteDirectory(t *testing.T, terraformOptions *terraform.Options, maxRetries int, timeBetweenRetries time.Duration, keyPair *ssh.KeyPair, publicIP string) {
149-
150-
RemoteDir := filepath.Join("/home/", sshUser)
151-
commandListDirectory := "ls -1 " + RemoteDir
152-
testFile := filepath.Join(yugabyteDir, "/test/DirectoryList")
153-
logger.Logf(t, "testFile :- %s", testFile)
154-
assert.FileExists(t, testFile)
155-
156-
sshHost := ssh.Host{
157-
Hostname: string(publicIP),
158-
SshKeyPair: keyPair,
159-
SshUserName: sshUser,
160-
}
161-
162-
file, err := ioutil.ReadFile(testFile)
163-
if err != nil {
164-
fmt.Print(err)
165-
}
166-
167-
retry.DoWithRetry(t, "Listing Directory", maxRetries, timeBetweenRetries, func() (string, error) {
168-
output, err := ssh.CheckSshCommandE(t, sshHost, commandListDirectory)
169-
if err != nil {
170-
return "", err
171-
}
172-
logger.Logf(t, "Directory list :- %s", output)
173-
174-
assert.Equal(t, strings.TrimSpace(output), strings.TrimSpace(string(file)))
175-
return output, nil
176-
})
177-
}
178-
179149
func testYugaByteYSQLSH(t *testing.T, terraformOptions *terraform.Options, maxRetries int, timeBetweenRetries time.Duration, keyPair *ssh.KeyPair, publicIP string) {
180150

181151
commandConnectYSQLSH := "cd " + filepath.Join("/home/", sshUser, "/yugabyte-db/tserver") + " && ./bin/ysqlsh --echo-queries -h " + string(publicIP)
@@ -239,115 +209,42 @@ func testYugaByteConf(t *testing.T, terraformOptions *terraform.Options, maxRetr
239209
assert.FileExists(t, filepath.Join(yugabyteDir, "/server.conf"))
240210
}
241211

242-
func testYugaByteMasterProcess(t *testing.T, terraformOptions *terraform.Options, maxRetries int, timeBetweenRetries time.Duration, keyPair *ssh.KeyPair, publicIP string) {
243-
212+
func testYugaByteProcess(t *testing.T, terraformOptions *terraform.Options, maxRetries int, timeBetweenRetries time.Duration, keyPair *ssh.KeyPair, publicIP string, processName string) {
244213
sshHost := ssh.Host{
245214
Hostname: string(publicIP),
246215
SshKeyPair: keyPair,
247216
SshUserName: sshUser,
248217
}
249-
sampleText := "yb-master"
250-
retry.DoWithRetry(t, "Checking master process", maxRetries, timeBetweenRetries, func() (string, error) {
251-
output, err := ssh.CheckSshCommandE(t, sshHost, fmt.Sprintf("pgrep --list-name yb-master"))
218+
retry.DoWithRetry(t, "Checking process "+processName, maxRetries, timeBetweenRetries, func() (string, error) {
219+
output, err := ssh.CheckSshCommandE(t, sshHost, fmt.Sprintf("pgrep --list-name '%s'", processName))
252220
if err != nil {
253221
return "", err
254222
}
255-
if ! strings.Contains(output, sampleText) {
256-
return "", fmt.Errorf("Expected: %s. Got: %s\n", sampleText, output)
223+
if ! strings.Contains(output, processName) {
224+
return "", fmt.Errorf("Expected: %s. Got: %s\n", processName, output)
257225
}
258226
return "", nil
259227
})
260228

261229
}
262230

263-
func testYugaByteTserverProcess(t *testing.T, terraformOptions *terraform.Options, maxRetries int, timeBetweenRetries time.Duration, keyPair *ssh.KeyPair, publicIP string) {
264-
231+
func testYugaByteLogFile(t *testing.T, terraformOptions *terraform.Options, maxRetries int, timeBetweenRetries time.Duration, keyPair *ssh.KeyPair, publicIP string, logFile string, logDir string) {
232+
RemoteDir:= filepath.Join("/home", sshUser, "yugabyte-db", logDir)
265233
sshHost := ssh.Host{
266234
Hostname: string(publicIP),
267235
SshKeyPair: keyPair,
268236
SshUserName: sshUser,
269237
}
270-
sampleText := "yb-tserver"
271-
retry.DoWithRetry(t, "Checkng tserver process", maxRetries, timeBetweenRetries, func() (string, error) {
272-
output, err := ssh.CheckSshCommandE(t, sshHost, fmt.Sprintf("pgrep --list-name yb-tserver"))
238+
239+
retry.DoWithRetry(t, "Checking log file "+logFile, maxRetries, timeBetweenRetries, func() (string, error) {
240+
output, err := ssh.CheckSshCommandE(t, sshHost, fmt.Sprintf("ls '%s' | grep '%s'",RemoteDir, logFile))
273241
if err != nil {
274242
return "", err
275243
}
276-
if ! strings.Contains(output, sampleText) {
277-
return "", fmt.Errorf("Expected: %s. Got: %s\n", sampleText, output)
278-
}
279-
return "", nil
280-
})
281-
282-
}
283-
284-
func testYugaByteMasterLog(t *testing.T, terraformOptions *terraform.Options, maxRetries int, timeBetweenRetries time.Duration, keyPair *ssh.KeyPair, publicIP string) {
285-
RemoteDir:= filepath.Join("/home/", sshUser, "/yugabyte-db/master")
286-
sshHost := ssh.Host{
287-
Hostname: string(publicIP),
288-
SshKeyPair: keyPair,
289-
SshUserName: sshUser,
290-
}
291-
//Checking master.out
292-
sampleText := "master.out"
293-
retry.DoWithRetry(t, "Checking master log file master.out", maxRetries, timeBetweenRetries, func() (string, error) {
294-
output, err := ssh.CheckSshCommandE(t, sshHost, fmt.Sprintf("ls %s | grep master.out",RemoteDir))
295-
if err != nil {
296-
return "", err
297-
}
298-
if strings.TrimSpace(sampleText) != strings.TrimSpace(output) {
299-
return "", fmt.Errorf("Expected: %s. Got: %s\n", sampleText, output)
244+
if strings.TrimSpace(logFile) != strings.TrimSpace(output) {
245+
return "", fmt.Errorf("Expected: %s. Got: %s\n", logFile, output)
300246
}
301247
return "", nil
302248
})
303249

304-
//checking master.err
305-
sampleText = "master.err"
306-
retry.DoWithRetry(t, "Checking master log file master.err", maxRetries, timeBetweenRetries, func() (string, error) {
307-
output, err := ssh.CheckSshCommandE(t, sshHost, fmt.Sprintf("ls %s | grep master.err",RemoteDir))
308-
if err != nil {
309-
return "", err
310-
}
311-
if strings.TrimSpace(sampleText) != strings.TrimSpace(output) {
312-
return "", fmt.Errorf("Expected: %s. Got: %s\n", sampleText, output)
313-
}
314-
return "", nil
315-
})
316-
317-
}
318-
319-
func testYugaByteTserverLog(t *testing.T, terraformOptions *terraform.Options, maxRetries int, timeBetweenRetries time.Duration, keyPair *ssh.KeyPair, publicIP string) {
320-
321-
RemoteDir:= filepath.Join("/home/", sshUser, "/yugabyte-db/tserver")
322-
sshHost := ssh.Host{
323-
Hostname: string(publicIP),
324-
SshKeyPair: keyPair,
325-
SshUserName: sshUser,
326-
}
327-
sampleText := "tserver.out"
328-
retry.DoWithRetry(t, "Checking tserver log file tserver.out", maxRetries, timeBetweenRetries, func() (string, error) {
329-
output, err := ssh.CheckSshCommandE(t, sshHost, fmt.Sprintf("ls %s | grep tserver.out",RemoteDir))
330-
if err != nil {
331-
return "", err
332-
}
333-
if strings.TrimSpace(sampleText) != strings.TrimSpace(output) {
334-
return "", fmt.Errorf("Expected: %s. Got: %s\n", sampleText, output)
335-
}
336-
return "", nil
337-
})
338-
339-
sampleText = "tserver.err"
340-
retry.DoWithRetry(t, "Checking tserver log file tserver.err", maxRetries, timeBetweenRetries, func() (string, error) {
341-
output, err := ssh.CheckSshCommandE(t, sshHost, fmt.Sprintf("ls %s | grep tserver.err", RemoteDir))
342-
if err != nil {
343-
return "", err
344-
}
345-
if strings.TrimSpace(sampleText) != strings.TrimSpace(output) {
346-
return "", fmt.Errorf("Expected: %s. Got: %s\n", sampleText, output)
347-
}
348-
return "", nil
349-
})
350-
351-
}
352-
353-
250+
}

0 commit comments

Comments
 (0)