1import json
2import time
3import unittest
4import urllib
5import testconstants
6from TestInput import TestInputSingleton
7
8from community.community_base import CommunityBaseTest
9from community.community_base import CommunityXDCRBaseTest
10from memcached.helper.data_helper import  MemcachedClientHelper
11from membase.api.rest_client import RestConnection, Bucket, RestHelper
12from membase.helper.rebalance_helper import RebalanceHelper
13from membase.api.exception import RebalanceFailedException
14from couchbase_helper.documentgenerator import BlobGenerator
15from remote.remote_util import RemoteMachineShellConnection
16from membase.helper.cluster_helper import ClusterOperationHelper
17from scripts.install import InstallerJob
18from testconstants import SHERLOCK_VERSION
19from testconstants import COUCHBASE_FROM_WATSON, COUCHBASE_FROM_SPOCK,\
20                          COUCHBASE_FROM_VULCAN
21from testconstants import WIN_BACKUP_PATH, WIN_BACKUP_C_PATH, WIN_COUCHBASE_BIN_PATH
22from testconstants import LINUX_COUCHBASE_BIN_PATH
23
24
25
26
27class CommunityTests(CommunityBaseTest):
28    def setUp(self):
29        super(CommunityTests, self).setUp()
30        self.command = self.input.param("command", "")
31        self.zone = self.input.param("zone", 1)
32        self.replica = self.input.param("replica", 1)
33        self.command_options = self.input.param("command_options", '')
34        self.set_get_ratio = self.input.param("set_get_ratio", 0.9)
35        self.item_size = self.input.param("item_size", 128)
36        self.shutdown_zone = self.input.param("shutdown_zone", 1)
37        self.do_verify = self.input.param("do-verify", True)
38        self.num_node = self.input.param("num_node", 4)
39        self.services = self.input.param("services", None)
40        self.start_node_services = self.input.param("start_node_services", "kv")
41        self.add_node_services = self.input.param("add_node_services", "kv")
42        self.timeout = 6000
43        self.user_add = self.input.param("user_add", None)
44        self.user_role = self.input.param("user_role", None)
45
46
47    def tearDown(self):
48        super(CommunityTests, self).tearDown()
49
50    def test_disabled_zone(self):
51        disabled_zone = False
52        zone_name = "group1"
53        serverInfo = self.servers[0]
54        self.rest = RestConnection(serverInfo)
55        try:
56            self.log.info("create zone name 'group1'!")
57            result = self.rest.add_zone(zone_name)
58            print "result  ",result
59        except Exception, e :
60            if e:
61                print e
62                disabled_zone = True
63                pass
64        if not disabled_zone:
65            self.fail("CE version should not have zone feature")
66
67    def check_audit_available(self):
68        audit_available = False
69        try:
70            self.rest.getAuditSettings()
71            audit_available = True
72        except Exception, e :
73            if e:
74                print e
75        if audit_available:
76            self.fail("This feature 'audit' only available on "
77                      "Enterprise Edition")
78
79    def check_ldap_available(self):
80        ldap_available = False
81        self.rest = RestConnection(self.master)
82        try:
83            s, c, h = self.rest.clearLDAPSettings()
84            if s:
85                ldap_available = True
86        except Exception, e :
87            if e:
88                print e
89        if ldap_available:
90            self.fail("This feature 'ldap' only available on "
91                      "Enterprise Edition")
92
93    def check_set_services(self):
94        self.rest.force_eject_node()
95        self.sleep(7, "wait for node reset done")
96        try:
97            status = self.rest.init_node_services(hostname=self.master.ip,
98                                                 services=[self.services])
99        except Exception, e:
100            if e:
101                print e
102        if self.services == "kv":
103            if status:
104                self.log.info("CE could set {0} only service."
105                                  .format(self.services))
106            else:
107                self.fail("Failed to set {0} only service."
108                                   .format(self.services))
109        elif self.services == "index,kv":
110            if status:
111                self.fail("CE does not support kv and index on same node")
112            else:
113                self.log.info("services enforced in CE")
114        elif self.services == "kv,n1ql":
115            if status:
116                self.fail("CE does not support kv and n1ql on same node")
117            else:
118                self.log.info("services enforced in CE")
119        elif self.services == "kv,eventing":
120            if status:
121                self.fail("CE does not support kv and eventing on same node")
122            else:
123                self.log.info("services enforced in CE")
124        elif self.services == "index,n1ql":
125            if status:
126                self.fail("CE does not support index and n1ql on same node")
127            else:
128                self.log.info("services enforced in CE")
129        elif self.services == "index,kv,n1ql":
130            if status:
131                self.log.info("CE could set all services {0} on same nodes."
132                                                           .format(self.services))
133            else:
134                self.fail("Failed to set kv, index and query services on CE")
135        elif self.version[:5] in COUCHBASE_FROM_WATSON:
136            if self.version[:5] in COUCHBASE_FROM_VULCAN and "eventing" in self.services:
137                if status:
138                    self.fail("CE does not support eventing in vulcan")
139                else:
140                    self.log.info("services enforced in CE")
141            elif self.services == "fts,index,kv":
142                if status:
143                    self.fail("CE does not support fts, index and kv on same node")
144                else:
145                    self.log.info("services enforced in CE")
146            elif self.services == "fts,index,n1ql":
147                if status:
148                    self.fail("CE does not support fts, index and n1ql on same node")
149                else:
150                    self.log.info("services enforced in CE")
151            elif self.services == "fts,kv,n1ql":
152                if status:
153                    self.fail("CE does not support fts, kv and n1ql on same node")
154                else:
155                    self.log.info("services enforced in CE")
156            elif self.services == "fts,index,kv,n1ql":
157                if status:
158                    self.log.info("CE could set all services {0} on same nodes."
159                                                           .format(self.services))
160                else:
161                    self.fail("Failed to set "
162                              "fts, index, kv, and query services on CE")
163        else:
164            self.fail("some services don't support")
165
166    def check_set_services_when_add_node(self):
167        self.rest.force_eject_node()
168        sherlock_services_in_ce = ["kv", "index,kv,n1ql"]
169        watson_services_in_ce = ["kv", "index,kv,n1ql", "fts,index,kv,n1ql"]
170        self.sleep(5, "wait for node reset done")
171        try:
172            self.log.info("Initialize node with services {0}"
173                                  .format(self.start_node_services))
174            status = self.rest.init_node_services(hostname=self.master.ip,
175                                        services=[self.start_node_services])
176            init_node = self.cluster.async_init_node(self.master,
177                                            services = [self.start_node_services])
178        except Exception, e:
179            if e:
180                print e
181        if not status:
182            if self.version not in COUCHBASE_FROM_WATSON and \
183                         self.start_node_services not in sherlock_services_in_ce:
184                self.log.info("initial services setting enforced in Sherlock CE")
185            elif self.version in COUCHBASE_FROM_WATSON and \
186                         self.start_node_services not in watson_services_in_ce:
187                self.log.info("initial services setting enforced in Watson CE")
188
189        elif status and init_node.result() != 0:
190            add_node = False
191            try:
192                self.log.info("node with services {0} try to add"
193                                  .format(self.add_node_services))
194                add_node = self.cluster.rebalance(self.servers[:2],
195                                                  self.servers[1:2], [],
196                                      services = [self.add_node_services])
197            except Exception:
198                pass
199            if add_node:
200                self.get_services_map()
201                list_nodes = self.get_nodes_from_services_map(get_all_nodes=True)
202                map = self.get_nodes_services()
203                if map[self.master.ip] == self.start_node_services and \
204                    map[self.servers[1].ip] == self.add_node_services:
205                    self.log.info("services set correctly when node added & rebalance")
206                else:
207                    self.fail("services set incorrectly when node added & rebalance. "
208                        "cluster expected services: {0}; set cluster services {1} ."
209                        "add node expected srv: {2}; set add node srv {3}"\
210                        .format(map[self.master.ip], self.start_node_services, \
211                         map[self.servers[1].ip], self.add_node_services))
212            else:
213                if self.version not in COUCHBASE_FROM_WATSON:
214                    if self.start_node_services in ["kv", "index,kv,n1ql"] and \
215                          self.add_node_services not in ["kv", "index,kv,n1ql"]:
216                        self.log.info("services are enforced in CE")
217                    elif self.start_node_services not in ["kv", "index,kv,n1ql"]:
218                        self.log.info("services are enforced in CE")
219                    else:
220                        self.fail("maybe bug in add node")
221                elif self.version in COUCHBASE_FROM_WATSON:
222                    if self.start_node_services in ["kv", "index,kv,n1ql",
223                         "fts,index,kv,n1ql"] and self.add_node_services not in \
224                                    ["kv", "index,kv,n1ql", "fts,index,kv,n1ql"]:
225                        self.log.info("services are enforced in CE")
226                    elif self.start_node_services not in ["kv", "index,kv,n1ql",
227                                                            "fts,index,kv,n1ql"]:
228                        self.log.info("services are enforced in CE")
229                    else:
230                        self.fail("maybe bug in add node")
231        else:
232            self.fail("maybe bug in node initialization")
233
234    def check_full_backup_only(self):
235        """ for windows vm, ask IT to put uniq.exe at
236            /cygdrive/c/Program Files (x86)/ICW/bin directory """
237
238        self.remote = RemoteMachineShellConnection(self.master)
239        """ put params items=0 in test param so that init items = 0 """
240        self.remote.execute_command("{0}cbworkloadgen -n {1}:8091 -j -i 1000 " \
241                                    "-u Administrator -p password" \
242                                            .format(self.bin_path, self.master.ip))
243        """ delete backup location before run backup """
244        self.remote.execute_command("rm -rf {0}*".format(self.backup_location))
245        output, error = self.remote.execute_command("ls -lh {0}"
246                                                     .format(self.backup_location))
247        self.remote.log_command_output(output, error)
248
249        """ first full backup """
250        self.remote.execute_command("{0}cbbackup http://{1}:8091 {2} -m full " \
251                                    "-u Administrator -p password"\
252                                    .format(self.bin_path,
253                                            self.master.ip,
254                                            self.backup_c_location))
255        output, error = self.remote.execute_command("ls -lh {0}*/"
256                                        .format(self.backup_location))
257        self.remote.log_command_output(output, error)
258        output, error = self.remote.execute_command("{0}cbtransfer -u Administrator "\
259                                           "-p password {1}*/*-full/ " \
260                                           "stdout: | grep set | uniq | wc -l"\
261                                           .format(self.bin_path,
262                                                   self.backup_c_location))
263        self.remote.log_command_output(output, error)
264        if int(output[0]) != 1000:
265            self.fail("full backup did not work in CE. "
266                      "Expected 1000, actual: {0}".format(output[0]))
267        self.remote.execute_command("{0}cbworkloadgen -n {1}:8091 -j -i 1000 "\
268                                    " -u Administrator -p password --prefix=t_"
269                                    .format(self.bin_path, self.master.ip))
270        """ do different backup mode """
271        self.remote.execute_command("{0}cbbackup -u Administrator -p password "\
272                                    "http://{1}:8091 {2} -m {3}"\
273                                    .format(self.bin_path,
274                                            self.master.ip,
275                                            self.backup_c_location,
276                                            self.backup_option))
277        output, error = self.remote.execute_command("ls -lh {0}"
278                                                     .format(self.backup_location))
279        self.remote.log_command_output(output, error)
280        output, error = self.remote.execute_command("{0}cbtransfer -u Administrator "\
281                                           "-p password {1}*/*-{2}/ stdout: "\
282                                           "| grep set | uniq | wc -l"\
283                                           .format(self.bin_path,
284                                                   self.backup_c_location,
285                                                   self.backup_option))
286        self.remote.log_command_output(output, error)
287        if int(output[0]) == 2000:
288            self.log.info("backup option 'diff' is enforced in CE")
289        elif int(output[0]) == 1000:
290            self.fail("backup option 'diff' is not enforced in CE. "
291                      "Expected 2000, actual: {0}".format(output[0]))
292        else:
293            self.fail("backup failed to backup correct items")
294        self.remote.disconnect()
295
296    def check_ent_backup(self):
297        """ for CE version from Watson, cbbackupmgr exe file should not in bin """
298        command = "cbbackupmgr"
299        self.remote = RemoteMachineShellConnection(self.master)
300        self.log.info("check if {0} in {1} directory".format(command, self.bin_path))
301        found = self.remote.file_exists(self.bin_path, command)
302        if found:
303            self.log.info("found {0} in {1} directory".format(command, self.bin_path))
304            self.fail("CE from Watson should not contain {0}".format(command))
305        elif not found:
306            self.log.info("Ent. backup in CE is enforced, not in bin!")
307        self.remote.disconnect()
308
309    def check_memory_optimized_storage_mode(self):
310        """ from Watson, CE should not have option 'memory_optimized' to set """
311        self.rest.force_eject_node()
312        self.sleep(5, "wait for node reset done")
313        try:
314            self.log.info("Initialize node with 'Memory Optimized' option")
315            status = self.rest.set_indexer_storage_mode(
316                            username=self.input.membase_settings.rest_username,
317                            password=self.input.membase_settings.rest_password,
318                                                storageMode='memory_optimized')
319        except Exception, ex:
320            if ex:
321                print ex
322        if not status:
323            self.log.info("Memory Optimized setting enforced in CE "
324                          "Could not set memory_optimized option")
325        else:
326            self.fail("Memory Optimzed setting does not enforced in CE "
327                      "We could set this option in")
328
329    def check_x509_cert(self):
330        """ from Watson, X509 certificate only support in EE """
331        api = self.rest.baseUrl + "pools/default/certificate?extended=true"
332        self.log.info("request to get certificate at "
333                      "'pools/default/certificate?extended=true' "
334                      "should return False")
335        try:
336            status, content, header = self.rest._http_request(api, 'GET')
337        except Exception, ex:
338            if ex:
339                print ex
340        if status:
341            self.fail("This X509 certificate feature only available in EE")
342        elif not status:
343            if "requires enterprise edition" in content:
344                self.log.info("X509 cert is enforced in CE")
345
346    def check_roles_base_access(self):
347        """ from Watson, roles base access for admin should not in in CE """
348        if self.user_add is None:
349            self.fail("We need to pass user name (user_add) to run this test. ")
350        if self.user_role is None:
351            self.fail("We need to pass user roles (user_role) to run this test. ")
352        api = self.rest.baseUrl + "settings/rbac/users/" + self.user_add
353        self.log.info("url to run this test: %s" % api)
354        """ add admin user """
355        param = "name=%s&roles=%s" % (self.user_add, self.user_role)
356        try:
357            status, content, header = self.rest._http_request(api, 'PUT', param)
358        except Exception, ex:
359            if ex:
360                print ex
361        if status:
362            self.fail("CE should not allow to add admin users")
363        else:
364            self.log.info("roles base is enforced in CE! ")
365
366    def check_root_certificate(self):
367        """ from watson, ce should not see root certificate
368            manual test:
369            curl -u Administrator:password -X GET
370                            http://localhost:8091/pools/default/certificate """
371        api = self.rest.baseUrl + "pools/default/certificate"
372        try:
373            status, content, header = self.rest._http_request(api, 'GET')
374        except Exception, ex:
375            if ex:
376                print ex
377        if status:
378            self.fail("CE should not see root certificate!")
379        elif "requires enterprise edition" in content:
380            self.log.info("root certificate is enforced in CE! ")
381
382    def check_settings_audit(self):
383        """ from watson, ce should not set audit
384            manual test:
385            curl -u Administrator:password -X GET
386                            http://localhost:8091/settings/audit """
387        api = self.rest.baseUrl + "settings/audit"
388        try:
389            status, content, header = self.rest._http_request(api, 'GET')
390        except Exception, ex:
391            if ex:
392                print ex
393        if status:
394            self.fail("CE should not allow to set audit !")
395        elif "requires enterprise edition" in content:
396            self.log.info("settings audit is enforced in CE! ")
397
398    def check_infer(self):
399        """ from watson, ce should not see infer
400            manual test:
401            curl -H "Content-Type: application/json" -X POST
402                 -d '{"statement":"infer `bucket_name`;"}'
403                       http://localhost:8093/query/service
404            test params: new_services=kv-index-n1ql,default_bucket=False """
405        self.rest.force_eject_node()
406        self.sleep(7, "wait for node reset done")
407        self.rest.init_node()
408        bucket = "default"
409        self.rest.create_bucket(bucket, ramQuotaMB=200)
410        api = self.rest.query_baseUrl + "query/service"
411        param = urllib.urlencode({"statement":"infer `%s` ;" % bucket})
412        try:
413            status, content, header = self.rest._http_request(api, 'POST', param)
414            json_parsed = json.loads(content)
415        except Exception, ex:
416            if ex:
417                print ex
418        if json_parsed["status"] == "success":
419            self.fail("CE should not allow to run INFER !")
420        elif json_parsed["status"] == "fatal":
421            self.log.info("INFER is enforced in CE! ")
422
423    def check_auto_complete(self):
424        """ this feature has not complete to block in CE """
425
426    """ Check new features from spock start here """
427    def check_cbbackupmgr(self):
428        """ cbbackupmgr should not available in CE from spock """
429        if self.cb_version[:5] in COUCHBASE_FROM_SPOCK:
430            file_name = "cbbackupmgr" + self.file_extension
431            self.log.info("check if cbbackupmgr in bin dir in CE")
432            result = self.remote.file_exists(self.bin_path, file_name)
433            if result:
434                self.fail("cbbackupmgr should not in bin dir of CE")
435            else:
436                self.log.info("cbbackupmgr is enforced in CE")
437        self.remote.disconnect()
438
439    def test_max_ttl_bucket(self):
440        """
441            From vulcan, EE bucket has has an option to set --max-ttl, not it CE.
442            This test is make sure CE could not create bucket with option --max-ttl
443            This test must pass default_bucket=False
444        """
445        if self.cb_version[:5] not in COUCHBASE_FROM_VULCAN:
446            self.log.info("This test only for vulcan and later")
447            return
448        cmd = 'curl -X POST -u Administrator:password \
449                                    http://{0}:8091/pools/default/buckets \
450                                 -d name=bucket0 \
451                                 -d maxTTL=100 \
452                                 -d authType=sasl \
453                                 -d ramQuotaMB=100 '.format(self.master.ip)
454        if self.cli_test:
455            cmd = "{0}couchbase-cli bucket-create -c {1}:8091 --username Administrator \
456                --password password --bucket bucket0 --bucket-type couchbase \
457                --bucket-ramsize 512 --bucket-replica 1 --bucket-priority high \
458                --bucket-eviction-policy fullEviction --enable-flush 0 \
459                --enable-index-replica 1 --max-ttl 200".format(self.bin_path,
460                                                               self.master.ip)
461        conn = RemoteMachineShellConnection(self.master)
462        output, error = conn.execute_command(cmd)
463        conn.log_command_output(output, error)
464        mesg = "Max TTL is supported in enterprise edition only"
465        if self.cli_test:
466            mesg = "Maximum TTL can only be configured on enterprise edition"
467        if output and mesg not in str(output[0]):
468            self.fail("max ttl feature should not in Community Edition")
469        buckets = RestConnection(self.master).get_buckets()
470        if buckets:
471            for bucket in buckets:
472                self.log.info("bucekt in cluser: {0}".format(bucket.name))
473                if bucket.name == "bucket0":
474                    self.fail("Failed to enforce feature max ttl in CE.")
475        conn.disconnect()
476
477    def test_setting_audit(self):
478        """
479           CE does not allow to set audit from vulcan 5.5.0
480        """
481        if self.cb_version[:5] not in COUCHBASE_FROM_VULCAN:
482            self.log.info("This test only for vulcan and later")
483            return
484        cmd = 'curl -X POST -u Administrator:password \
485              http://{0}:8091/settings/audit \
486              -d auditdEnabled=true '.format(self.master.ip)
487        if self.cli_test:
488            cmd = "{0}couchbase-cli setting-audit -c {1}:8091 -u Administrator \
489                -p password --audit-enabled 1 --audit-log-rotate-interval 604800 \
490                --audit-log-path /opt/couchbase/var/lib/couchbase/logs "\
491                .format(self.bin_path, self.master.ip)
492
493        conn = RemoteMachineShellConnection(self.master)
494        output, error = conn.execute_command(cmd)
495        conn.log_command_output(output, error)
496        mesg = "This http API endpoint requires enterprise edition"
497        if output and mesg not in str(output[0]):
498            self.fail("setting-audit feature should not in Community Edition")
499        conn.disconnect()
500
501    def test_setting_autofailover_enterprise_only(self):
502        """
503           CE does not allow set auto failover if disk has issue
504           and failover group from vulcan 5.5.0
505        """
506        if self.cb_version[:5] not in COUCHBASE_FROM_VULCAN:
507            self.log.info("This test only for vulcan and later")
508            return
509        self.failover_disk_period = self.input.param("failover_disk_period", False)
510        self.failover_server_group = self.input.param("failover_server_group", False)
511
512        failover_disk_period = ""
513        if self.failover_disk_period:
514            if self.cli_test:
515                failover_disk_period = "--failover-data-disk-period 300"
516            else:
517                failover_disk_period = "-d failoverOnDataDiskIssues[timePeriod]=300"
518        failover_server_group = ""
519        if self.failover_server_group and self.cli_test:
520            failover_server_group = "--enable-failover-of-server-group 1"
521
522
523        cmd = 'curl -X POST -u Administrator:password \
524              http://{0}:8091/settings/autoFailover -d enabled=true -d timeout=120 \
525              -d maxCount=1 \
526              -d failoverOnDataDiskIssues[enabled]=true {1} \
527              -d failoverServerGroup={2}'.format(self.master.ip, failover_disk_period,
528                                                 self.failover_server_group)
529        if self.cli_test:
530            cmd = "{0}couchbase-cli setting-autofailover -c {1}:8091 \
531                   -u Administrator -p password \
532                   --enable-failover-on-data-disk-issues 1 {2} {3} "\
533                  .format(self.bin_path, self.master.ip,
534                          failover_disk_period,
535                          failover_server_group)
536        conn = RemoteMachineShellConnection(self.master)
537        output, error = conn.execute_command(cmd)
538        conn.log_command_output(output, error)
539        mesg = "Auto failover on Data Service disk issues can only be " + \
540               "configured on enterprise edition"
541        if not self.cli_test:
542            if self.failover_disk_period or \
543                                   self.failover_server_group:
544                if output and not error:
545                    self.fail("setting autofailover disk issues feature\
546                               should not in Community Edition")
547        else:
548            if self.failover_server_group:
549                mesg = "--enable-failover-of-server-groups can only be " + \
550                       "configured on enterprise edition"
551
552        if output and mesg not in str(output[0]):
553            self.fail("Setting EE autofailover features \
554                       should not in Community Edition")
555        else:
556            self.log.info("EE setting autofailover are disable in CE")
557        conn.disconnect()
558
559    def test_set_bucket_compression(self):
560        """
561           CE does not allow to set bucket compression to bucket
562           from vulcan 5.5.0.   Mode compression: off,active,passive
563           Note: must set defaultbucket=False for this test
564        """
565        if self.cb_version[:5] not in COUCHBASE_FROM_VULCAN:
566            self.log.info("This test only for vulcan and later")
567            return
568        self.compression_mode = self.input.param("compression_mode", "off")
569        cmd = 'curl -X POST -u Administrator:password \
570                                    http://{0}:8091/pools/default/buckets \
571                                 -d name=bucket0 \
572                                 -d compressionMode={1} \
573                                 -d authType=sasl \
574                                 -d ramQuotaMB=100 '.format(self.master.ip,
575                                                            self.compression_mode)
576        if self.cli_test:
577            cmd = "{0}couchbase-cli bucket-create -c {1}:8091 --username Administrator \
578                --password password --bucket bucket0 --bucket-type couchbase \
579                --bucket-ramsize 512 --bucket-replica 1 --bucket-priority high \
580                --bucket-eviction-policy fullEviction --enable-flush 0 \
581                --enable-index-replica 1 --compression-mode {2}".format(self.bin_path,
582                                                                 self.master.ip,
583                                                                 self.compression_mode)
584        conn = RemoteMachineShellConnection(self.master)
585        output, error = conn.execute_command(cmd)
586        conn.log_command_output(output, error)
587        mesg = "Compression mode is supported in enterprise edition only"
588        if self.cli_test:
589            mesg = "Compression mode can only be configured on enterprise edition"
590        if output and mesg not in str(output[0]):
591            self.fail("Setting bucket compression should not in CE")
592        conn.disconnect()
593
594
595class CommunityXDCRTests(CommunityXDCRBaseTest):
596    def setUp(self):
597        super(CommunityXDCRTests, self).setUp()
598        self.master = self._servers[0]
599        self.cli_test = self._input.param("cli_test", False)
600        self.bin_path = LINUX_COUCHBASE_BIN_PATH
601        remote = RemoteMachineShellConnection(self.master)
602        type = remote.extract_remote_info().distribution_type
603        if type.lower() == 'windows':
604            self.is_linux = False
605            self.backup_location = WIN_BACKUP_PATH
606            self.backup_c_location = WIN_BACKUP_C_PATH
607            self.bin_path = WIN_COUCHBASE_BIN_PATH
608            self.file_extension = ".exe"
609        else:
610            self.is_linux = True
611        self.cb_version = None
612        if RestHelper(RestConnection(self.master)).is_ns_server_running():
613            """ since every new couchbase version, there will be new features
614                that test code will not work on previous release.  So we need
615                to get couchbase version to filter out those tests. """
616            self.cb_version = RestConnection(self.master).get_nodes_version()
617        remote.disconnect()
618
619    def tearDown(self):
620        super(CommunityXDCRTests, self).tearDown()
621
622    def test_xdcr_filter(self):
623        filter_on = False
624        serverInfo = self._servers[0]
625        self.rest = RestConnection(serverInfo)
626        self.rest.remove_all_replications()
627        self.remote = RemoteMachineShellConnection(serverInfo)
628        output, error = self.remote.execute_command('curl -X POST '
629                                         '-u Administrator:password '
630                     ' http://{0}:8091/controller/createReplication '
631                     '-d fromBucket="default" '
632                     '-d toCluster="cluster1" '
633                     '-d toBucket="default" '
634                     '-d replicationType="continuous" '
635                     '-d filterExpression="some_exp"'
636                                              .format(serverInfo.ip))
637        if output:
638            self.log.info(output[0])
639        if output and "default" in output[0]:
640            self.fail("XDCR Filter feature should not available in "
641                      "Community Edition")
642        self.remote.disconnect()
643
644    def test_lww(self):
645        server = self._servers[0]
646        conn = RemoteMachineShellConnection(server)
647        output, error = conn.execute_command('curl -X POST -u Administrator:password '
648                                                    'http://{0}:8091/pools/default/buckets '
649                                                    '-d name=default '
650                                                    '-d conflictResolutionType=lww '
651                                                    '-d authType=sasl '
652                                                    '-d ramQuotaMB=100 '.format(server.ip))
653        conn.log_command_output(output, error)
654        if output and "Conflict resolution type 'lww' is supported only in enterprise edition"\
655                  not in str(output[0]):
656            self.fail("XDCR LWW feature should not be available in Community Edition")
657        self.log.info("XDCR LWW feature not available in Community Edition as expected")
658        conn.disconnect()
659
660    def test_xdcr_compression(self):
661        """
662           flag --enable-compression should not work in CE from vulcan
663        """
664        self.compression_mode = self._input.param("compression_mode", "Auto")
665        if self.cb_version[:5] not in COUCHBASE_FROM_VULCAN:
666            self.log.info("This test only for vulcan and later")
667            return
668        self.log.info("Remove any existing replican")
669        RestConnection(self.src_master).remove_all_replications()
670        conn = RemoteMachineShellConnection(self.src_master)
671
672        cmd = 'curl -X POST -u Administrator:password \
673                              http://{0}:8091/controller/createReplication \
674                                 -d fromBucket=default \
675                                 -d toBucket=default \
676                                 -d toCluster=cluster1 \
677                                 -d replicationType=continuous \
678                                 -d compressionType={1}'.format(self.src_master.ip,
679                                                            self.compression_mode)
680        if self.cli_test:
681            cmd = "{0}couchbase-cli setting-xdcr -c {1}:8091 -u Administrator \
682                   -p password --enable-compression 1 ".format(self.bin_path,
683                                                                 self.src_master.ip)
684        output, error = conn.execute_command(cmd)
685
686        mesg = '"compressionType":"The value can be specified only in enterprise edition"'
687        if self.cli_test:
688            mesg = "ERROR: --enable-compression can only be configured on enterprise edition"
689        if output and mesg not in str(output[0]):
690            self.fail("Setting bucket compression should not in CE")
691        conn.disconnect()