/
couchbase_clitest.py
1457 lines (1347 loc) · 95.3 KB
/
couchbase_clitest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import json
from threading import Thread
from membase.api.rest_client import RestConnection
from TestInput import TestInputSingleton
from clitest.cli_base import CliBaseTest
from remote.remote_util import RemoteMachineShellConnection
from pprint import pprint
from testconstants import CLI_COMMANDS
help = {'CLUSTER': '--cluster=HOST[:PORT] or -c HOST[:PORT]',
'COMMAND': {'bucket-compact': 'compact database and index data',
'bucket-create': 'add a new bucket to the cluster',
'bucket-delete': 'delete an existing bucket',
'bucket-edit': 'modify an existing bucket',
'bucket-flush': 'flush all data from disk for a given bucket',
'bucket-list': 'list all buckets in a cluster',
'cluster-edit': 'modify cluster settings',
'cluster-init': 'set the username,password and port of the cluster',
'failover': 'failover one or more servers',
'group-manage': 'manage server groups',
'help': 'show longer usage/help and examples',
'node-init': 'set node specific parameters',
'rebalance': 'start a cluster rebalancing',
'rebalance-status': 'show status of current cluster rebalancing',
'rebalance-stop': 'stop current cluster rebalancing',
'recovery': 'recover one or more servers',
'server-add': 'add one or more servers to the cluster',
'server-info': 'show details on one server',
'server-list': 'list all servers in a cluster',
'server-readd': 'readd a server that was failed over',
'setting-alert': 'set email alert settings',
'setting-autofailover': 'set auto failover settings',
'setting-compaction': 'set auto compaction settings',
'setting-notification': 'set notification settings',
'setting-xdcr': 'set xdcr related settings',
'ssl-manage': 'manage cluster certificate',
'user-manage': 'manage read only user',
'xdcr-replicate': 'xdcr operations',
'xdcr-setup': 'set up XDCR connection'},
'EXAMPLES': {'Add a node to a cluster and rebalance': 'couchbase-cli rebalance -c 192.168.0.1:8091 --server-add=192.168.0.2:8091 --server-add-username=Administrator1 --server-add-password=password1 --group-name=group1 -u Administrator -p password',
'Add a node to a cluster, but do not rebalance': 'couchbase-cli server-add -c 192.168.0.1:8091 --server-add=192.168.0.2:8091 --server-add-username=Administrator1 --server-add-password=password1 --group-name=group1 -u Administrator -p password',
'Change the data path': 'couchbase-cli node-init -c 192.168.0.1:8091 --node-init-data-path=/tmp -u Administrator -p password',
'Create a couchbase bucket and wait for bucket ready': 'couchbase-cli bucket-create -c 192.168.0.1:8091 --bucket=test_bucket --bucket-type=couchbase --bucket-port=11222 --bucket-ramsize=200 --bucket-replica=1 --bucket-priority=low --wait -u Administrator -p password',
'Create a new dedicated port couchbase bucket': 'couchbase-cli bucket-create -c 192.168.0.1:8091 --bucket=test_bucket --bucket-type=couchbase --bucket-port=11222 --bucket-ramsize=200 --bucket-replica=1 --bucket-priority=high -u Administrator -p password',
'Create a new sasl memcached bucket': 'couchbase-cli bucket-create -c 192.168.0.1:8091 --bucket=test_bucket --bucket-type=memcached --bucket-password=password --bucket-ramsize=200 --bucket-eviction-policy=valueOnly --enable-flush=1 -u Administrator -p password',
'Delete a bucket': 'couchbase-cli bucket-delete -c 192.168.0.1:8091 --bucket=test_bucket',
'Flush a bucket': 'couchbase-cli xdcr-replicate -c 192.168.0.1:8091 --list -u Administrator -p password',
'List buckets in a cluster': 'couchbase-cli bucket-list -c 192.168.0.1:8091',
'List read only user in a cluster': 'couchbase-cli ssl-manage -c 192.168.0.1:8091 --regenerate-cert=/tmp/test.pem -u Administrator -p password',
'List servers in a cluster': 'couchbase-cli server-list -c 192.168.0.1:8091',
'Modify a dedicated port bucket': 'couchbase-cli bucket-edit -c 192.168.0.1:8091 --bucket=test_bucket --bucket-port=11222 --bucket-ramsize=400 --bucket-eviction-policy=fullEviction --enable-flush=1 --bucket-priority=high -u Administrator -p password',
'Remove a node from a cluster and rebalance': 'couchbase-cli rebalance -c 192.168.0.1:8091 --server-remove=192.168.0.2:8091 -u Administrator -p password',
'Remove and add nodes from/to a cluster and rebalance': 'couchbase-cli rebalance -c 192.168.0.1:8091 --server-remove=192.168.0.2 --server-add=192.168.0.4 --server-add-username=Administrator1 --server-add-password=password1 --group-name=group1 -u Administrator -p password',
'Server information': 'couchbase-cli server-info -c 192.168.0.1:8091',
'Set data path and hostname for an unprovisioned cluster': 'couchbse-cli node-init -c 192.168.0.1:8091 --node-init-data-path=/tmp/data --node-init-index-path=/tmp/index --node-init-hostname=myhostname -u Administrator -p password',
'Set recovery type to a server': 'couchbase-cli rebalance -c 192.168.0.1:8091 --recovery-buckets="default,bucket1" -u Administrator -p password',
'Set the username, password, port and ram quota': 'couchbase-cli cluster-init -c 192.168.0.1:8091 --cluster-username=Administrator --cluster-password=password --cluster-port=8080 --cluster-ramsize=300',
'Stop the current rebalancing': 'couchbase-cli rebalance-stop -c 192.168.0.1:8091 -u Administrator -p password',
'change the cluster username, password, port and ram quota': 'couchbase-cli cluster-edit -c 192.168.0.1:8091 --cluster-username=Administrator1 --cluster-password=password1 --cluster-port=8080 --cluster-ramsize=300 -u Administrator -p password'},
'OPTIONS': {'-o KIND, --output=KIND': 'KIND is json or standard\n-d, --debug',
'-p PASSWORD, --password=PASSWORD': 'admin password of the cluster',
'-u USERNAME, --user=USERNAME': 'admin username of the cluster'},
'bucket-* OPTIONS': {'--bucket-eviction-policy=[valueOnly|fullEviction]': ' policy how to retain meta in memory',
'--bucket-password=PASSWORD': 'standard port, exclusive with bucket-port',
'--bucket-port=PORT': 'supports ASCII protocol and is auth-less',
'--bucket-priority=[low|high]': 'priority when compared to other buckets',
'--bucket-ramsize=RAMSIZEMB': 'ram quota in MB',
'--bucket-replica=COUNT': 'replication count',
'--bucket-type=TYPE': 'memcached or couchbase',
'--bucket=BUCKETNAME': ' bucket to act on',
'--data-only': ' compact datbase data only',
'--enable-flush=[0|1]': 'enable/disable flush',
'--enable-index-replica=[0|1]': 'enable/disable index replicas',
'--force': ' force to execute command without asking for confirmation',
'--view-only': ' compact view data only',
'--wait': 'wait for bucket create to be complete before returning'},
'cluster-* OPTIONS': {'--cluster-password=PASSWORD': ' new admin password',
'--cluster-port=PORT': ' new cluster REST/http port',
'--cluster-ramsize=RAMSIZEMB': ' per node ram quota in MB',
'--cluster-username=USER': ' new admin username'},
'description': 'couchbase-cli - command-line cluster administration tool',
'failover OPTIONS': {'--force': ' failover node from cluster right away',
'--server-failover=HOST[:PORT]': ' server to failover'},
'group-manage OPTIONS': {'--add-servers=HOST[:PORT];HOST[:PORT]': 'add a list of servers to group\n--move-servers=HOST[:PORT];HOST[:PORT] move a list of servers from group',
'--create': 'create a new group',
'--delete': 'delete an empty group',
'--from-group=GROUPNAME': 'group name that to move servers from',
'--group-name=GROUPNAME': 'group name',
'--list': 'show group/server relationship map',
'--rename=NEWGROUPNAME': ' rename group to new name',
'--to-group=GROUPNAME': 'group name tat to move servers to'},
'node-init OPTIONS': {'--node-init-data-path=PATH': 'per node path to store data',
'--node-init-hostname=NAME': ' hostname for the node. Default is 127.0.0.1',
'--node-init-index-path=PATH': ' per node path to store index'},
'rebalance OPTIONS': {'--recovery-buckets=BUCKETS': 'comma separated list of bucket name. Default is for all buckets.',
'--server-add*': ' see server-add OPTIONS',
'--server-remove=HOST[:PORT]': ' the server to be removed'},
'recovery OPTIONS': {'--recovery-type=TYPE[delta|full]': 'type of recovery to be performed for a node',
'--server-recovery=HOST[:PORT]': ' server to recover'},
'server-add OPTIONS': {'--group-name=GROUPNAME': 'group that server belongs',
'--server-add-password=PASSWORD': 'admin password for the\nserver to be added',
'--server-add-username=USERNAME': 'admin username for the\nserver to be added',
'--server-add=HOST[:PORT]': 'server to be added'},
'server-readd OPTIONS': {'--group-name=GROUPNAME': 'group that server belongs',
'--server-add-password=PASSWORD': 'admin password for the\nserver to be added',
'--server-add-username=USERNAME': 'admin username for the\nserver to be added',
'--server-add=HOST[:PORT]': 'server to be added'},
'setting-alert OPTIONS': {'--alert-auto-failover-cluster-small': " node wasn't auto fail over as cluster was too small",
'--alert-auto-failover-max-reached': ' maximum number of auto failover nodes was reached',
'--alert-auto-failover-node': 'node was auto failover',
'--alert-auto-failover-node-down': " node wasn't auto failover as other nodes are down at the same time",
'--alert-disk-space': 'disk space used for persistent storgage has reached at least 90% capacity',
'--alert-ip-changed': 'node ip address has changed unexpectedly',
'--alert-meta-oom': 'bucket memory on a node is entirely used for metadata',
'--alert-meta-overhead': ' metadata overhead is more than 50%',
'--alert-write-failed': 'writing data to disk for a specific bucket has failed',
'--email-host=HOST': ' email server host',
'--email-password=PWD': 'email server password',
'--email-port=PORT': ' email server port',
'--email-recipients=RECIPIENT': 'email recipents, separate addresses with , or ;',
'--email-sender=SENDER': ' sender email address',
'--email-user=USER': ' email server username',
'--enable-email-alert=[0|1]': 'allow email alert',
'--enable-email-encrypt=[0|1]': 'email encrypt'},
'setting-autofailover OPTIONS': {'--auto-failover-timeout=TIMEOUT (>=30)': 'specify timeout that expires to trigger auto failover',
'--enable-auto-failover=[0|1]': 'allow auto failover'},
'setting-compaction OPTIONS': {'--compaction-db-percentage=PERCENTAGE': ' at which point database compaction is triggered',
'--compaction-db-size=SIZE[MB]': ' at which point database compaction is triggered',
'--compaction-period-from=HH:MM': 'allow compaction time period from',
'--compaction-period-to=HH:MM': 'allow compaction time period to',
'--compaction-view-percentage=PERCENTAGE': ' at which point view compaction is triggered',
'--compaction-view-size=SIZE[MB]': ' at which point view compaction is triggered',
'--enable-compaction-abort=[0|1]': ' allow compaction abort when time expires',
'--enable-compaction-parallel=[0|1]': 'allow parallel compaction for database and view',
'--metadata-purge-interval=DAYS': 'how frequently a node will purge metadata on deleted items'},
'setting-notification OPTIONS': {'--enable-notification=[0|1]': ' allow notification'},
'setting-xdcr OPTIONS': {'--checkpoint-interval=[1800]': ' intervals between checkpoints, 60 to 14400 seconds.',
'--doc-batch-size=[2048]KB': 'document batching size, 10 to 100000 KB',
'--failure-restart-interval=[30]': 'interval for restarting failed xdcr, 1 to 300 seconds\n--optimistic-replication-threshold=[256] document body size threshold (bytes) to trigger optimistic replication',
'--max-concurrent-reps=[32]': ' maximum concurrent replications per bucket, 8 to 256.',
'--worker-batch-size=[500]': 'doc batch size, 500 to 10000.'},
'ssl-manage OPTIONS': {'--regenerate-cert=CERTIFICATE': 'regenerate cluster certificate AND save to a pem file',
'--retrieve-cert=CERTIFICATE': 'retrieve cluster certificate AND save to a pem file'},
'usage': ' couchbase-cli COMMAND CLUSTER [OPTIONS]',
'user-manage OPTIONS': {'--delete': ' delete read only user',
'--list': ' list any read only user',
'--ro-password=PASSWORD': ' readonly user password',
'--ro-username=USERNAME': ' readonly user name',
'--set': 'create/modify a read only user'},
'xdcr-replicate OPTIONS': {'--checkpoint-interval=[1800]': ' intervals between checkpoints, 60 to 14400 seconds.',
'--create': ' create and start a new replication',
'--delete': ' stop and cancel a replication',
'--doc-batch-size=[2048]KB': 'document batching size, 10 to 100000 KB',
'--failure-restart-interval=[30]': 'interval for restarting failed xdcr, 1 to 300 seconds\n--optimistic-replication-threshold=[256] document body size threshold (bytes) to trigger optimistic replication',
'--list': ' list all xdcr replications',
'--max-concurrent-reps=[32]': ' maximum concurrent replications per bucket, 8 to 256.',
'--pause': 'pause the replication',
'--resume': ' resume the replication',
'--settings': ' update settings for the replication',
'--worker-batch-size=[500]': 'doc batch size, 500 to 10000.',
'--xdcr-clucter-name=CLUSTERNAME': 'remote cluster to replicate to',
'--xdcr-from-bucket=BUCKET': 'local bucket name to replicate from',
'--xdcr-replication-mode=[xmem|capi]': 'replication protocol, either capi or xmem.',
'--xdcr-replicator=REPLICATOR': ' replication id',
'--xdcr-to-bucket=BUCKETNAME': 'remote bucket to replicate to',
'--source-nozzle-per-node=[1-10]': 'the number of source nozzles per source node',
'--target-nozzle-per-node=[1-100]': 'the number of outgoing nozzles per target node',
'--max-expected-replication-lag=MS': 'the maximum replication lag (in millisecond) that can be tolerated before it is considered timeout',
'--timeout-percentage-cap=[1-100]': 'the maximum allowed timeout percentage.If this limit is exceeded, replication is considered as not healthy and may be reported'},
'xdcr-setup OPTIONS': {'--create': ' create a new xdcr configuration',
'--delete': ' delete existed xdcr configuration',
'--edit': ' modify existed xdcr configuration',
'--list': ' list all xdcr configurations',
'--xdcr-certificate=CERTIFICATE': ' pem-encoded certificate. Need be present if xdcr-demand-encryption is true',
'--xdcr-cluster-name=CLUSTERNAME': 'cluster name',
'--xdcr-demand-encryption=[0|1]': ' allow data encrypted using ssl',
'--xdcr-hostname=HOSTNAME': ' remote host name to connect to',
'--xdcr-password=PASSWORD': ' remote cluster admin password',
'--xdcr-username=USERNAME': ' remote cluster admin username'}}
""" in 3.0, we add 'recovery recover one or more servers' into couchbase-cli """
help_short = {'COMMANDs include': {'bucket-compact': 'compact database and index data',
'bucket-create': 'add a new bucket to the cluster',
'bucket-delete': 'delete an existing bucket',
'bucket-edit': 'modify an existing bucket',
'bucket-flush': 'flush all data from disk for a given bucket',
'bucket-list': 'list all buckets in a cluster',
'cluster-edit': 'modify cluster settings',
'cluster-init': 'set the username,password and port of the cluster',
'recovery': 'recover one or more servers',
'failover': 'failover one or more servers',
'group-manage': 'manage server groups',
'help': 'show longer usage/help and examples',
'node-init': 'set node specific parameters',
'rebalance': 'start a cluster rebalancing',
'rebalance-status': 'show status of current cluster rebalancing',
'rebalance-stop': 'stop current cluster rebalancing',
'server-add': 'add one or more servers to the cluster',
'server-info': 'show details on one server',
'server-list': 'list all servers in a cluster',
'server-readd': 'readd a server that was failed over',
'setting-alert': 'set email alert settings',
'setting-autofailover': 'set auto failover settings',
'setting-compaction': 'set auto compaction settings',
'setting-notification': 'set notification settings',
'setting-xdcr': 'set xdcr related settings',
'ssl-manage': 'manage cluster certificate',
'user-manage': 'manage read only user',
'xdcr-replicate': 'xdcr operations',
'xdcr-setup': 'set up XDCR connection'},
'description': 'CLUSTER is --cluster=HOST[:PORT] or -c HOST[:PORT]',
'usage': ' couchbase-cli COMMAND CLUSTER [OPTIONS]'}
class CouchbaseCliTest(CliBaseTest):
def setUp(self):
TestInputSingleton.input.test_params["default_bucket"] = False
super(CouchbaseCliTest, self).setUp()
def tearDown(self):
super(CouchbaseCliTest, self).tearDown()
def _get_dict_from_output(self, output):
result = {}
if output[0].startswith("couchbase-cli"):
result["description"] = output[0]
result["usage"] = output[2].split("usage:")[1]
else:
result["usage"] = output[0].split("usage:")[1]
result["description"] = output[2]
upper_key = ""
for line in output[3:]:
line = line.strip()
if line == "":
if not upper_key == "EXAMPLES":
upper_key = ""
continue
# line = ""
if line.endswith(":") and upper_key != "EXAMPLES":
upper_key = line[:-1]
result[upper_key] = {}
continue
elif line == "COMMANDs include":
upper_key = line
result[upper_key] = {}
continue
elif upper_key in ["COMMAND", "COMMANDs include"] :
result[upper_key][line.split()[0]] = line.split(line.split()[0])[1].strip()
if len(line.split(line.split()[0])) > 2:
if line.split()[0] == 'help':
result[upper_key][line.split()[0]] = (line.split(line.split()[0])[1] + 'help' + line.split(line.split()[0])[-1]).strip()
else:
result[upper_key][line.split()[0]] = line.split(line.split(line.split()[0])[1])[-1].strip()
elif upper_key in ["CLUSTER"]:
result[upper_key] = line
elif upper_key.endswith("OPTIONS"):
# for u=instance:" -u USERNAME, --user=USERNAME admin username of the cluster"
temp = line.split(" ")
temp = [item for item in temp if item != ""]
if len(temp) > 1:
result[upper_key][temp[0]] = temp[1]
previous_key = temp[0]
else:
result[upper_key][previous_key] = result[upper_key][previous_key] + "\n" + temp[0]
elif upper_key in ["EXAMPLES"] :
if line.endswith(":"):
previous_key = line[:-1]
result[upper_key][previous_key] = ""
else:
line = line.strip()
if line.startswith("couchbase-cli"):
result[upper_key][previous_key] = line.replace("\\", "")
else:
result[upper_key][previous_key] = (result[upper_key][previous_key] + line).replace("\\", "")
previous_line = result[upper_key][previous_key]
elif line == "The default PORT number is 8091.":
continue
else:
self.fail(line)
return result
def _get_cluster_info(self, remote_client, cluster_host="localhost", cluster_port=None, user="Administrator", password="password"):
command = "server-info"
output, error = remote_client.execute_couchbase_cli(command, cluster_host=cluster_host, cluster_port=cluster_port, user=user, password=password)
if not error:
content = ""
for line in output:
content += line
return json.loads(content)
else:
self.fail("server-info return error output")
def _create_bucket(self, remote_client, bucket="default", bucket_type="couchbase", bucket_port=11211, bucket_password=None, \
bucket_ramsize=200, bucket_replica=1, wait=False, enable_flush=None, enable_index_replica=None):
options = "--bucket={0} --bucket-type={1} --bucket-port={2} --bucket-ramsize={3} --bucket-replica={4}".\
format(bucket, bucket_type, bucket_port, bucket_ramsize, bucket_replica)
options += (" --enable-flush={0}".format(enable_flush), "")[enable_flush is None]
options += (" --enable-index-replica={0}".format(enable_index_replica), "")[enable_index_replica is None]
options += (" --enable-flush={0}".format(enable_flush), "")[enable_flush is None]
options += (" --bucket-password={0}".format(bucket_password), "")[bucket_password is None]
options += (" --wait", "")[wait]
cli_command = "bucket-create"
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, options=options, cluster_host="localhost", user="Administrator", password="password")
if "TIMED OUT" in output[0]:
raise Exception("Timed out. Could not create bucket")
else:
self.assertTrue("SUCCESS: bucket-create" in output[0], "Fail to create bucket")
def testHelp(self):
command_with_error = {}
shell = RemoteMachineShellConnection(self.master)
for cli in CLI_COMMANDS:
""" excluded_commands should separate by ';' """
if self.excluded_commands is not None:
if ";" in self.excluded_commands:
excluded_commands = self.excluded_commands.split(";")
else:
excluded_commands = self.excluded_commands
if cli in excluded_commands:
self.log.info("command {0} test will be skipped.".format(cli))
continue
if self.os == "windows":
cli = '.'.join([cli, "exe"])
option = " -h"
if cli == "erl":
option = " -version"
command = ''.join([self.cli_command_path, cli, option])
self.log.info("test -h of command {0}".format(cli))
output, error = shell.execute_command(command, use_channel=True)
""" check if the first line is not empty """
if not output[0]:
self.log.error("this help command {0} may not work!".format(cli))
if error:
command_with_error[cli] = error[0]
if command_with_error:
raise Exception("some commands throw out error %s " % command_with_error)
shell.disconnect()
def testInfoCommands(self):
remote_client = RemoteMachineShellConnection(self.master)
cli_command = "server-list"
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
cluster_host="localhost", user="Administrator", password="password")
server_info = self._get_cluster_info(remote_client)
""" In new single node not join any cluster yet,
IP of node will be 127.0.0.1 """
if "127.0.0.1" in server_info["otpNode"]:
server_info["otpNode"] = "ns_1@{0}".format(remote_client.ip)
server_info["hostname"] = "{0}:8091".format(remote_client.ip)
result = server_info["otpNode"] + " " + server_info["hostname"] + " " \
+ server_info["status"] + " " + server_info["clusterMembership"]
self.assertEqual(result, "ns_1@{0} {0}:8091 healthy active" \
.format(remote_client.ip))
cli_command = "bucket-list"
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
cluster_host="localhost", user="Administrator", password="password")
self.assertEqual([], output)
remote_client.disconnect()
def testAddRemoveNodes(self):
nodes_add = self.input.param("nodes_add", 1)
nodes_rem = self.input.param("nodes_rem", 1)
nodes_failover = self.input.param("nodes_failover", 0)
nodes_readd = self.input.param("nodes_readd", 0)
remote_client = RemoteMachineShellConnection(self.master)
cli_command = "server-add"
if int(nodes_add) < len(self.servers):
for num in xrange(nodes_add):
self.log.info("add node {0} to cluster".format(self.servers[num + 1].ip))
options = "--server-add={0}:8091 --server-add-username=Administrator \
--server-add-password=password".format(self.servers[num + 1].ip)
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
options=options, cluster_host="localhost", \
user="Administrator", password="password")
self.assertEqual(output, ["SUCCESS: server-add {0}:8091" \
.format(self.servers[num + 1].ip)])
else:
raise Exception("Node add should be smaller total number vms in ini file")
cli_command = "rebalance"
for num in xrange(nodes_rem):
options = "--server-remove={0}:8091".format(self.servers[nodes_add - num].ip)
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
options=options, cluster_host="localhost", \
user="Administrator", password="password")
self.assertTrue("INFO: rebalancing" in output[0])
self.assertEqual(output[1], "SUCCESS: rebalanced cluster")
if nodes_rem == 0 and nodes_add > 0:
cli_command = "rebalance"
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
cluster_host="localhost", user="Administrator", password="password")
self.assertEqual(output, ["INFO: rebalancing . ", "SUCCESS: rebalanced cluster"])
""" when no bucket, have to add option --force to failover
since no data => no graceful failover. Need to add test
to detect no graceful failover if no bucket """
self._create_bucket(remote_client,bucket_replica=self.num_replicas)
cli_command = "failover"
for num in xrange(nodes_failover):
self.log.info("failover node {0}" \
.format(self.servers[nodes_add - nodes_rem - num].ip))
options = "--server-failover={0}:8091" \
.format(self.servers[nodes_add - nodes_rem - num].ip)
if self.force_failover:
options += " --force"
output, error = remote_client.execute_couchbase_cli(\
cli_command=cli_command, options=options, \
cluster_host="localhost", user="Administrator", \
password="password")
self.assertEqual(output, ["SUCCESS: failover ns_1@{0}" \
.format(self.servers[nodes_add - nodes_rem - num].ip)])
else:
output, error = remote_client.execute_couchbase_cli(\
cli_command=cli_command, options=options, \
cluster_host="localhost", user="Administrator", \
password="password")
output[0] = output[0].rstrip(" .")
self.assertEqual(output, ["INFO: graceful failover", \
"SUCCESS: failover ns_1@{0}" \
.format(self.servers[nodes_add - nodes_rem - num].ip)])
cli_command = "server-readd"
for num in xrange(nodes_readd):
self.log.info("add back node {0} to cluster" \
.format(self.servers[nodes_add - nodes_rem - num ].ip))
options = "--server-add={0}:8091 --server-add-username=Administrator \
--server-add-password=password" \
.format(self.servers[nodes_add - nodes_rem - num ].ip)
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
options=options, cluster_host="localhost", \
user="Administrator", password="password")
self.assertEqual(output, ["SUCCESS: re-add ns_1@{0}" \
.format(self.servers[nodes_add - nodes_rem - num ].ip)])
cli_command = "rebalance"
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
cluster_host="localhost", user="Administrator", password="password")
output[0] = output[0].rstrip(" .")
self.assertEqual(output, ["INFO: rebalancing", "SUCCESS: rebalanced cluster"])
remote_client.disconnect()
def testAddRemoveNodesWithRecovery(self):
nodes_add = self.input.param("nodes_add", 1)
nodes_rem = self.input.param("nodes_rem", 1)
nodes_failover = self.input.param("nodes_failover", 0)
nodes_recovery = self.input.param("nodes_recovery", 0)
nodes_readd = self.input.param("nodes_readd", 0)
remote_client = RemoteMachineShellConnection(self.master)
cli_command = "server-add"
if int(nodes_add) < len(self.servers):
for num in xrange(nodes_add):
self.log.info("add node {0} to cluster".format(self.servers[num + 1].ip))
options = "--server-add={0}:8091 --server-add-username=Administrator --server-add-password=password".format(self.servers[num + 1].ip)
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, options=options, cluster_host="localhost", user="Administrator", password="password")
self.assertEqual(output, ["SUCCESS: server-add {0}:8091".format(self.servers[num + 1].ip)])
else:
raise Exception("Node add should be smaller total number vms in ini file")
cli_command = "rebalance"
for num in xrange(nodes_rem):
options = "--server-remove={0}:8091".format(self.servers[nodes_add - num].ip)
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, options=options, cluster_host="localhost", user="Administrator", password="password")
self.assertTrue("INFO: rebalancing" in output[0])
self.assertEqual(output[1], "SUCCESS: rebalanced cluster")
if nodes_rem == 0 and nodes_add > 0:
cli_command = "rebalance"
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, cluster_host="localhost", user="Administrator", password="password")
self.assertTrue(output, ["INFO: rebalancing . ", "SUCCESS: rebalanced cluster"])
self._create_bucket(remote_client)
cli_command = "failover"
for num in xrange(nodes_failover):
self.log.info("failover node {0}".format(self.servers[nodes_add - nodes_rem - num].ip))
options = "--server-failover={0}:8091".format(self.servers[nodes_add - nodes_rem - num].ip)
if self.force_failover or num == nodes_failover - 1:
options += " --force"
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, options=options, cluster_host="localhost", user="Administrator", password="password")
self.assertTrue('SUCCESS: failover ns_1@{0}'.format(self.servers[nodes_add - nodes_rem - num].ip) in output, error)
cli_command = "recovery"
for num in xrange(nodes_failover):
# try to set recovery when nodes failovered (MB-11230)
options = "--server-recovery={0}:8091 --recovery-type=delta".format(self.servers[nodes_add - nodes_rem - num].ip)
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, options=options, cluster_host="localhost", user="Administrator", password="password")
self.assertEqual("SUCCESS: setRecoveryType for node ns_1@{0}".format(self.servers[nodes_add - nodes_rem - num].ip), output[0])
for num in xrange(nodes_recovery):
cli_command = "server-readd"
self.log.info("add node {0} back to cluster".format(self.servers[nodes_add - nodes_rem - num].ip))
options = "--server-add={0}:8091 --server-add-username=Administrator --server-add-password=password".format(self.servers[nodes_add - nodes_rem - num].ip)
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, options=options, cluster_host="localhost", user="Administrator", password="password")
self.assertEqual(output, ["SUCCESS: re-add ns_1@{0}".format(self.servers[nodes_add - nodes_rem - num].ip)])
cli_command = "recovery"
options = "--server-recovery={0}:8091 --recovery-type=delta".format(self.servers[nodes_add - nodes_rem - num].ip)
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, options=options, cluster_host="localhost", user="Administrator", password="password")
self.assertEqual(output, ["SUCCESS: setRecoveryType for node ns_1@{0}".format(self.servers[nodes_add - nodes_rem - num].ip)])
cli_command = "server-readd"
for num in xrange(nodes_readd):
self.log.info("add back node {0} to cluster".format(self.servers[nodes_add - nodes_rem - num ].ip))
options = "--server-add={0}:8091 --server-add-username=Administrator --server-add-password=password".format(self.servers[nodes_add - nodes_rem - num ].ip)
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, options=options, cluster_host="localhost", user="Administrator", password="password")
self.assertEqual(output, ["SUCCESS: re-add ns_1@{0}".format(self.servers[nodes_add - nodes_rem - num ].ip)])
cli_command = "rebalance"
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, cluster_host="localhost", user="Administrator", password="password")
self.assertTrue("INFO: rebalancing . " in output[0])
self.assertEqual("SUCCESS: rebalanced cluster", output[1])
remote_client.disconnect()
def testStartStopRebalance(self):
nodes_add = self.input.param("nodes_add", 1)
nodes_rem = self.input.param("nodes_rem", 1)
remote_client = RemoteMachineShellConnection(self.master)
cli_command = "rebalance-status"
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
cluster_host="localhost", user="Administrator", password="password")
self.assertEqual(output, ["(u'notRunning', None)"])
cli_command = "server-add"
for num in xrange(nodes_add):
options = "--server-add={0}:8091 --server-add-username=Administrator \
--server-add-password=password".format(self.servers[num + 1].ip)
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
options=options, cluster_host="localhost", \
user="Administrator", password="password")
self.assertEqual(output, ["SUCCESS: server-add {0}:8091" \
.format(self.servers[num + 1].ip)])
cli_command = "rebalance-status"
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
cluster_host="localhost", user="Administrator", password="password")
self.assertEqual(output, ["(u'notRunning', None)"])
self._create_bucket(remote_client)
cli_command = "rebalance"
t = Thread(target=remote_client.execute_couchbase_cli, name="rebalance_after_add",
args=(cli_command, "localhost", '', None, "Administrator", "password"))
t.start()
self.sleep(5)
cli_command = "rebalance-status"
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
cluster_host="localhost", user="Administrator", password="password")
self.assertEqual(output, ["(u'running', None)"])
t.join()
cli_command = "rebalance"
for num in xrange(nodes_rem):
options = "--server-remove={0}:8091".format(self.servers[nodes_add - num].ip)
t = Thread(target=remote_client.execute_couchbase_cli, name="rebalance_after_add",
args=(cli_command, "localhost", options, None, "Administrator", "password"))
t.start()
self.sleep(5)
cli_command = "rebalance-status"
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
cluster_host="localhost", user="Administrator", password="password")
self.assertEqual(output, ["(u'running', None)"])
cli_command = "rebalance-stop"
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
cluster_host="localhost", user="Administrator", password="password")
t.join()
cli_command = "rebalance"
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
cluster_host="localhost", user="Administrator", password="password")
self.assertEqual(output[1], "SUCCESS: rebalanced cluster")
cli_command = "rebalance-status"
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
cluster_host="localhost", user="Administrator", password="password")
self.assertEqual(output, ["(u'notRunning', None)"])
remote_client.disconnect()
def testNodeInit(self):
server = self.servers[-1]
remote_client = RemoteMachineShellConnection(server)
prefix = ''
type = remote_client.extract_remote_info().distribution_type
if type.lower() == 'windows':
prefix_path = "C:"
data_path = self.input.param("data_path", None)
index_path = self.input.param("index_path", None)
if data_path is not None:
data_path = prefix + data_path.replace('|', "/")
if index_path is not None:
index_path = prefix + index_path.replace('|', "/")
server_info = self._get_cluster_info(remote_client, cluster_port=server.port, \
user=server.rest_username, password=server.rest_password)
data_path_before = server_info["storage"]["hdd"][0]["path"]
index_path_before = server_info["storage"]["hdd"][0]["index_path"]
try:
rest = RestConnection(server)
rest.force_eject_node()
cli_command = "node-init"
options = ""
options += ("--node-init-data-path={0} ".format(data_path), "")[data_path is None]
options += ("--node-init-index-path={0} ".format(index_path), "")[index_path is None]
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
options=options, cluster_host="localhost", \
user="Administrator", password="password")
self.sleep(7) # time needed to reload couchbase
""" no output print out. Bug https://issues.couchbase.com/browse/MB-13704
output []
error []
It need to check when this bug is fixed """
#self.assertEqual(output[0], "SUCCESS: init localhost")
rest.init_cluster()
server_info = self._get_cluster_info(remote_client, cluster_port=server.port, user=server.rest_username, password=server.rest_password)
data_path_after = server_info["storage"]["hdd"][0]["path"]
index_path_after = server_info["storage"]["hdd"][0]["index_path"]
self.assertEqual((data_path, data_path_before)[data_path is None], data_path_after)
self.assertEqual((index_path, index_path_before)[index_path is None], index_path_after)
finally:
rest = RestConnection(server)
rest.force_eject_node()
rest.init_cluster()
def testClusterInit(self):
cluster_init_username = self.input.param("cluster_init_username", "Administrator")
cluster_init_password = self.input.param("cluster_init_password", "password")
cluster_init_port = self.input.param("cluster_init_port", 8091)
cluster_init_ramsize = self.input.param("cluster_init_ramsize", 300)
command_init = self.input.param("command_init", "cluster-init")
param_prefix = self.input.param("param_prefix", "--cluster-init")
server = self.servers[-1]
remote_client = RemoteMachineShellConnection(server)
rest = RestConnection(server)
rest.force_eject_node()
try:
cli_command = command_init
options = "--cluster-init-username={0} {1}-password={2} {3}-port={4} {5}-ramsize={6}".\
format(cluster_init_username, param_prefix, cluster_init_password, param_prefix, cluster_init_port, param_prefix, cluster_init_ramsize)
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, options=options, cluster_host="localhost", user="Administrator", password="password")
self.assertEqual(output[0], "SUCCESS: init localhost")
if cli_command == "cluster-init":
options = "{0}-username={1} {2}-password={3} {4}-port={5} {6}-ramsize={7}".\
format(param_prefix, cluster_init_username + "1", param_prefix, cluster_init_password + "1", param_prefix, str(cluster_init_port)[:-1] + "9", param_prefix, cluster_init_ramsize)
elif cli_command == "cluster-edit":
options = "{0}-username={1} {2}-password={3} {4}-port={5}".\
format(param_prefix, cluster_init_username + "1", param_prefix, cluster_init_password + "1", param_prefix, str(cluster_init_port)[:-1] + "9")
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, options=options, cluster_host="localhost", user=cluster_init_username, password=cluster_init_password)
self.sleep(7) # time needed to reload couchbase
""" work around bug MB-10927 and remove these codes when it is fixed. Rerun with new credential setup.
If no error throw out, rewrite the output """
if "Connection refused" in output[0]:
output_tm, error_tm = remote_client.execute_couchbase_cli(cli_command="server-info", cluster_host="localhost", cluster_port=str(cluster_init_port)[:-1] + "9", user=cluster_init_username + "1", password=cluster_init_password + "1")
if "availableStorage" in output_tm[1]:
output[0] = "SUCCESS: init localhost"
self.assertEqual(output[0], "SUCCESS: init localhost")
server.rest_username = cluster_init_username + "1"
server.rest_password = cluster_init_password + "1"
server.port = str(cluster_init_port)[:-1] + "9"
cli_command = "server-list"
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, cluster_host="localhost", cluster_port=str(cluster_init_port)[:-1] + "9", user=cluster_init_username + "1", password=cluster_init_password + "1")
self.assertTrue("{0} healthy active".format(str(cluster_init_port)[:-1] + "9") in output[0])
server_info = self._get_cluster_info(remote_client, cluster_port=server.port, user=server.rest_username, password=server.rest_password)
result = server_info["otpNode"] + " " + server_info["hostname"] + " " + server_info["status"] + " " + server_info["clusterMembership"]
self.assertTrue("{0} healthy active".format(str(cluster_init_port)[:-1] + "9") in result)
cli_command = command_init
if cli_command == "cluster-init":
options = "{0}-username={1} {2}-password={3} {4}-port={5} {6}-ramsize={7}".\
format(param_prefix, cluster_init_username, param_prefix, cluster_init_password, param_prefix, cluster_init_port, param_prefix, cluster_init_ramsize)
elif cli_command == "cluster-edit":
options = "{0}-username={1} {2}-password={3} {4}-port={5}".\
format(param_prefix, cluster_init_username, param_prefix, cluster_init_password, param_prefix, cluster_init_port)
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, options=options, cluster_host="localhost", cluster_port=str(cluster_init_port)[:-1] + "9", user=(cluster_init_username + "1"), password=cluster_init_password + "1")
self.sleep(7) # time needed to reload couchbase
""" work around bug MB-10927 and remove these codes when it is fixed. Rerun with new credential setup.
If no error throw out, rewrite the output """
if "Connection refused" in output[0]:
output_tm, error_tm = remote_client.execute_couchbase_cli(cli_command="server-info", cluster_host="localhost", cluster_port=str(cluster_init_port)[:-1] + "9", user=cluster_init_username + "1", password=cluster_init_password + "1")
if "availableStorage" in output_tm[1]:
output[0] = "SUCCESS: init localhost"
self.assertEqual(output[0], "SUCCESS: init localhost")
server.rest_username = cluster_init_username
server.rest_password = cluster_init_password
server.port = cluster_init_port
remote_client = RemoteMachineShellConnection(server)
cli_command = "server-list"
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, cluster_host="localhost", user=cluster_init_username, password=cluster_init_password)
self.assertTrue("{0} healthy active".format(str(cluster_init_port)) in output[0])
server_info = self._get_cluster_info(remote_client, cluster_port=server.port, user=server.rest_username, password=server.rest_password)
result = server_info["otpNode"] + " " + server_info["hostname"] + " " + server_info["status"] + " " + server_info["clusterMembership"]
self.assertTrue("{0} healthy active".format(str(cluster_init_port)) in result)
remote_client.disconnect()
finally:
try:
server.rest_username = cluster_init_username
server.rest_password = cluster_init_password
server.port = cluster_init_port
rest = RestConnection(server)
rest.force_eject_node()
rest.init_cluster()
except Exception:
server.rest_username = cluster_init_username + "1"
server.rest_password = cluster_init_password + "1"
server.port = str(cluster_init_port)[:-1] + "9"
rest = RestConnection(server)
rest.force_eject_node()
rest.init_cluster()
# It will go to tearDown function after this finally block
server.rest_username = cluster_init_username
server.rest_password = cluster_init_password
server.port = cluster_init_port
def testClusterInitNegative(self):
cluster_init_username = self.input.param("cluster_init_username", None)
cluster_init_password = self.input.param("cluster_init_password", None)
cluster_init_port = self.input.param("cluster_init_port", None)
cluster_init_ramsize = self.input.param("cluster_init_ramsize", None)
command_init = self.input.param("command_init", "cluster-init")
server = self.servers[-1]
remote_client = RemoteMachineShellConnection(server)
rest = RestConnection(server)
rest.force_eject_node()
try:
cli_command = command_init
options = ""
if cluster_init_username is not None:
options += "--cluster-init-username={0} ".format(cluster_init_username)
if cluster_init_password is not None:
options += "--cluster-init-password={0} ".format(cluster_init_password)
if cluster_init_port is not None:
options += "--cluster-init-port={0} ".format(cluster_init_port)
if cluster_init_ramsize is None:
options += "--cluster-init-ramsize={0} ".format(cluster_init_ramsize)
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
options=options, cluster_host="localhost", user=None, password=None)
self.sleep(7) # time needed to reload couchbase
self.assertEqual(output, [u'ERROR: Both username and password are required.']
or output == [u'The password must be at least six characters.'])
remote_client.disconnect()
finally:
rest = RestConnection(server)
rest.force_eject_node()
rest.init_cluster()
def testBucketCreation(self):
bucket_name = self.input.param("bucket", "default")
bucket_type = self.input.param("bucket_type", "couchbase")
bucket_port = self.input.param("bucket_port", 11211)
bucket_replica = self.input.param("bucket_replica", 1)
bucket_password = self.input.param("bucket_password", None)
bucket_ramsize = self.input.param("bucket_ramsize", 200)
wait = self.input.param("wait", False)
enable_flush = self.input.param("enable_flush", None)
enable_index_replica = self.input.param("enable_index_replica", None)
remote_client = RemoteMachineShellConnection(self.master)
rest = RestConnection(self.master)
self._create_bucket(remote_client, bucket=bucket_name, bucket_type=bucket_type, bucket_port=bucket_port, bucket_password=bucket_password, \
bucket_ramsize=bucket_ramsize, bucket_replica=bucket_replica, wait=wait, enable_flush=enable_flush, enable_index_replica=enable_index_replica)
buckets = rest.get_buckets()
result = True
if len(buckets) != 1:
self.log.error("Expected to get only 1 bucket")
result = False
bucket = buckets[0]
if bucket_name != bucket.name:
self.log.error("Bucket name is not correct")
result = False
if not (bucket_port == bucket.nodes[0].moxi or bucket_port == bucket.port):
self.log.error("Bucket port is not correct")
result = False
if bucket_type == "couchbase" and "membase" != bucket.type or\
(bucket_type == "memcached" and "memcached" != bucket.type):
self.log.error("Bucket type is not correct")
result = False
if bucket_type == "couchbase" and bucket_replica != bucket.numReplicas:
self.log.error("Bucket num replica is not correct")
result = False
if bucket.saslPassword != (bucket_password, "")[bucket_password is None]:
self.log.error("Bucket password is not correct")
result = False
if bucket_ramsize * 1048576 not in range(int(int(buckets[0].stats.ram) * 0.95), int(int(buckets[0].stats.ram) * 1.05)):
self.log.error("Bucket RAM size is not correct")
result = False
if not result:
self.fail("Bucket was created with incorrect properties")
remote_client.disconnect()
def testBucketModification(self):
cli_command = "bucket-edit"
bucket_password = self.input.param("bucket_password", None)
bucket_port = self.input.param("bucket_port", 11211)
enable_flush = self.input.param("enable_flush", None)
self.testBucketCreation()
bucket_port_new = self.input.param("bucket_port_new", None)
bucket_password_new = self.input.param("bucket_password_new", None)
bucket_ramsize_new = self.input.param("bucket_ramsize_new", None)
enable_flush_new = self.input.param("enable_flush_new", None)
enable_index_replica_new = self.input.param("enable_index_replica_new", None)
bucket_ramsize_new = self.input.param("bucket_ramsize_new", None)
bucket = self.input.param("bucket", "default")
rest = RestConnection(self.master)
remote_client = RemoteMachineShellConnection(self.master)
options = "--bucket={0}".format(bucket)
options += (" --enable-flush={0}".format(enable_flush_new), \
"")[enable_flush_new is None]
options += (" --enable-index-replica={0}".format(enable_index_replica_new), \
"")[enable_index_replica_new is None]
options += (" --bucket-port={0}".format(bucket_port_new), \
"")[bucket_port_new is None]
options += (" --bucket-password={0}".format(bucket_password_new), \
"")[bucket_password_new is None]
options += (" --bucket-ramsize={0}".format(bucket_ramsize_new), \
"")[bucket_ramsize_new is None]
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
options=options, cluster_host="localhost", \
user="Administrator", password="password")
self.assertEqual(output, ['SUCCESS: bucket-edit'])
if bucket_password_new is not None:
bucket_password_new = bucket_password
if bucket_port_new is not None:
bucket_port = bucket_port_new
if bucket_ramsize_new is not None:
bucket_ramsize = bucket_ramsize_new
buckets = rest.get_buckets()
result = True
if len(buckets) != 1:
self.log.error("Expected to ge only 1 bucket")
result = False
bucket = buckets[0]
if not (bucket_port == bucket.nodes[0].moxi or bucket_port == bucket.port):
self.log.error("Bucket port is not correct")
result = False
if bucket.saslPassword != (bucket_password, "")[bucket_password is None]:
self.log.error("Bucket password is not correct")
result = False
if bucket_ramsize * 1048576 not in range(int(int(buckets[0].stats.ram) * 0.95), \
int(int(buckets[0].stats.ram) * 1.05)):
self.log.error("Bucket RAM size is not correct")
result = False
if not result:
self.fail("Bucket was created with incorrect properties")
options = ""
cli_command = "bucket-flush"
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command,
options=options, cluster_host="localhost",
user="Administrator", password="password")
self.assertEqual(output, ['Running this command will totally PURGE database'
' data from disk. Do you really want to do it? (Yes/No)TIMED OUT:'
' command: bucket-flush: localhost:8091, most likely bucket is not flushed'])
if not enable_flush:
cli_command = "bucket-flush --force"
options = "--bucket={0}".format(bucket)
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command,
options=options, cluster_host="localhost",
user="Administrator", password="password")
self.assertEqual(output, ['Database data will be purged from disk ...',
'ERROR: unable to bucket-flush; please check if the bucket exists or not;'
' (400) Bad Request', "{u'_': u'Flush is disabled for the bucket'}"])
cli_command = "bucket-edit"
options = "--bucket={0} --enable-flush=1 --bucket-ramsize=500".format(bucket)
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command,
options=options, cluster_host="localhost",
user="Administrator", password="password")
self.assertEqual(output, ['SUCCESS: bucket-edit'])
cli_command = "bucket-flush --force"
options = "--bucket={0}".format(bucket)
if enable_flush_new is None:
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command,
options=options, cluster_host="localhost",
user="Administrator", password="password")
self.assertEqual(output, ['Database data will be purged from disk ...',
'SUCCESS: bucket-flush'])
elif int(enable_flush_new) == 0:
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command,
options=options, cluster_host="localhost",
user="Administrator", password="password")
self.assertEqual(output, ['Database data will be purged from disk ...',
'ERROR: unable to bucket-flush; please check if the '
'bucket exists or not; (400) Bad Request',
"{u'_': u'Flush is disabled for the bucket'}"])
cli_command = "bucket-delete"
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command,
options=options, cluster_host="localhost",
user="Administrator", password="password")
self.assertEqual(output, ['SUCCESS: bucket-delete'])
remote_client.disconnect()
# MB-8566
def testSettingCompacttion(self):
'''setting-compacttion OPTIONS:
--compaction-db-percentage=PERCENTAGE at which point database compaction is triggered
--compaction-db-size=SIZE[MB] at which point database compaction is triggered
--compaction-view-percentage=PERCENTAGE at which point view compaction is triggered
--compaction-view-size=SIZE[MB] at which point view compaction is triggered
--compaction-period-from=HH:MM allow compaction time period from
--compaction-period-to=HH:MM allow compaction time period to
--enable-compaction-abort=[0|1] allow compaction abort when time expires
--enable-compaction-parallel=[0|1] allow parallel compaction for database and view'''
compaction_db_percentage = self.input.param("compaction-db-percentage", None)
compaction_db_size = self.input.param("compaction-db-size", None)
compaction_view_percentage = self.input.param("compaction-view-percentage", None)
compaction_view_size = self.input.param("compaction-view-size", None)
compaction_period_from = self.input.param("compaction-period-from", None)
compaction_period_to = self.input.param("compaction-period-to", None)
enable_compaction_abort = self.input.param("enable-compaction-abort", None)
enable_compaction_parallel = self.input.param("enable-compaction-parallel", None)
bucket = self.input.param("bucket", "default")
output = self.input.param("output", '')
rest = RestConnection(self.master)
remote_client = RemoteMachineShellConnection(self.master)
self.testBucketCreation()
cli_command = "setting-compacttion"
options = "--bucket={0}".format(bucket)
options += (" --compaction-db-percentage={0}".format(compaction_db_percentage), "")[compaction_db_percentage is None]
options += (" --compaction-db-size={0}".format(compaction_db_size), "")[compaction_db_size is None]
options += (" --compaction-view-percentage={0}".format(compaction_view_percentage), "")[compaction_view_percentage is None]
options += (" --compaction-view-size={0}".format(compaction_view_size), "")[compaction_view_size is None]
options += (" --compaction-period-from={0}".format(compaction_period_from), "")[compaction_period_from is None]
options += (" --compaction-period-to={0}".format(compaction_period_to), "")[compaction_period_to is None]
options += (" --enable-compaction-abort={0}".format(enable_compaction_abort), "")[enable_compaction_abort is None]
options += (" --enable-compaction-parallel={0}".format(enable_compaction_parallel), "")[enable_compaction_parallel is None]
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, options=options, cluster_host="localhost", user="Administrator", password="password")
self.assertEqual(output, ['SUCCESS: bucket-edit'])
cluster_status = rest.cluster_status()
remote_client.disconnect()
""" tests for the group-manage option. group creation, renaming and deletion are tested .
These tests require a cluster of four or more nodes. """
def testCreateRenameDeleteGroup(self):
remote_client = RemoteMachineShellConnection(self.master)
cli_command = "group-manage"
if self.os == "linux":
# create group
options = " --create --group-name=group2"
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
options=options, cluster_host="localhost", user="Administrator", password="password")
output = self.del_runCmd_value(output)
self.assertEqual(output, ["SUCCESS: group created group2"])
# create existing group. operation should fail
options = " --create --group-name=group2"
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
options=options, cluster_host="localhost", user="Administrator", password="password")
output = self.del_runCmd_value(output)
self.assertEqual(output[0], "ERROR: unable to create group group2 (400) Bad Request")
self.assertEqual(output[1], "{u'name':u'already exists'}")
# rename group test
options = " --rename=group3 --group-name=group2"
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
options=options, cluster_host="localhost", user="Administrator", password="password")
output = self.del_runCmd_value(output)
self.assertEqual(output, ["SUCCESS: group renamed group2"])
# delete group test
options = " --delete --group-name=group3"
output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
options=options, cluster_host="localhost", user="Administrator", password="password")
output = self.del_runCmd_value(output)
self.assertEqual(output, ["SUCCESS: group deleted group3"])
# delete non-empty group test