@@ -3,7 +3,6 @@ package yugabyte
3
3
import (
4
4
"crypto/tls"
5
5
"fmt"
6
- "io/ioutil"
7
6
"os"
8
7
"path/filepath"
9
8
"strings"
@@ -71,10 +70,12 @@ func TestYugaByteGcpTerraform(t *testing.T) {
71
70
testYugaByteYSQLSH (t , terraformOptions , maxRetries , timeBetweenRetries , keyPair , publicIP )
72
71
testYugaByteCQLSH (t , terraformOptions , maxRetries , timeBetweenRetries , keyPair , publicIP )
73
72
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" )
78
79
79
80
}
80
81
@@ -145,37 +146,6 @@ func testYugaByteSSH(t *testing.T, terraformOptions *terraform.Options, maxRetri
145
146
146
147
}
147
148
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
-
179
149
func testYugaByteYSQLSH (t * testing.T , terraformOptions * terraform.Options , maxRetries int , timeBetweenRetries time.Duration , keyPair * ssh.KeyPair , publicIP string ) {
180
150
181
151
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
239
209
assert .FileExists (t , filepath .Join (yugabyteDir , "/server.conf" ))
240
210
}
241
211
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 ) {
244
213
sshHost := ssh.Host {
245
214
Hostname : string (publicIP ),
246
215
SshKeyPair : keyPair ,
247
216
SshUserName : sshUser ,
248
217
}
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 ))
252
220
if err != nil {
253
221
return "" , err
254
222
}
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 )
257
225
}
258
226
return "" , nil
259
227
})
260
228
261
229
}
262
230
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 )
265
233
sshHost := ssh.Host {
266
234
Hostname : string (publicIP ),
267
235
SshKeyPair : keyPair ,
268
236
SshUserName : sshUser ,
269
237
}
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 ))
273
241
if err != nil {
274
242
return "" , err
275
243
}
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 )
300
246
}
301
247
return "" , nil
302
248
})
303
249
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