Beispiel #1
0
    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()
        self.sleep(5)

        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="******", password="******")
            self.assertEqual(output[0], "SUCCESS: init localhost")

            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)
            # MB-8202 cluster-init/edit doesn't provide status
            self.assertTrue(output == [])
            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
            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")
            # MB-8202 cluster-init/edit doesn't provide status
            self.assertTrue(output == [])

            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:
            rest = RestConnection(server)
            rest.force_eject_node()
            self.sleep(5)
            rest.init_cluster()
Beispiel #2
0
    def testXDCRSetup(self):
        '''xdcr-setup OPTIONS:
        --create                           create a new xdcr configuration
        --edit                             modify existed xdcr configuration
        --delete                           delete existed xdcr configuration
        --xdcr-cluster-name=CLUSTERNAME    cluster name
        --xdcr-hostname=HOSTNAME           remote host name to connect to
        --xdcr-username=USERNAME           remote cluster admin username
        --xdcr-password=PASSWORD           remtoe cluster admin password'''
        remote_client = RemoteMachineShellConnection(self.master)
        try:
            #rest = RestConnection(self.master)
            #xdcr_cluster_name & xdcr_hostname=the number of server in ini file to add to master as replication
            xdcr_cluster_name = self.input.param("xdcr-cluster-name", None)
            xdcr_hostname = self.input.param("xdcr-hostname", None)
            xdcr_username = self.input.param("xdcr-username", None)
            xdcr_password = self.input.param("xdcr-password", None)
            output_error = ""
            ip = None
            if xdcr_cluster_name is not None:
                ip = self.servers[xdcr_cluster_name].ip
#            if ip is not None:
#                output_error = 'SUCCESS: init {0}'.format(ip)
            output_error = self.input.param("output_error", 'SUCCESS: init HOSTIP').replace(";", ",")
            if ip is not None:
                output_error = output_error.replace("HOSTIP", ip)
            cli_command = "xdcr-setup"
            options = "--create"
            options += (" --xdcr-cluster-name={0}".format(ip), "")[xdcr_cluster_name is None]
            if xdcr_hostname is not None:
                options += " --xdcr-hostname={0}".format(self.servers[xdcr_hostname].ip)
            options += (" --xdcr-username={0}".format(xdcr_username), "")[xdcr_username is None]
            options += (" --xdcr-password={0}".format(xdcr_password), "")[xdcr_password is None]
            output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, options=options, cluster_host="localhost", user="******", password="******")
            self.assertEqual([s.rstrip() for s in output], [s for s in output_error.split(',')])

            if "SUCCESS: init" in output_error:
                #MB-8570 add verification when will be fixed
                options = options.replace("--create ", "--edit ")
                output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, options=options, cluster_host="localhost", user="******", password="******")

            if "SUCCESS: init" in output_error and xdcr_cluster_name is None:
                #MB-8573 couchbase-cli: quotes are not supported when try to remove remote xdcr cluster that has white spaces in the name
                options = "--delete --xdcr-cluster-name={0}".format("remote%20cluster")
            else:
                options = "--delete --xdcr-cluster-name={0}".format(self.servers[xdcr_cluster_name].ip)
            output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, options=options, cluster_host="localhost", user="******", password="******")

            if "SUCCESS: init" in output_error:
                self.assertEqual(output, ["SUCCESS: delete {0}".format(self.servers[xdcr_cluster_name].ip)])
            else:
                self.assertEqual(output, ["ERROR: unable to delete xdcr remote site localhost (404) Object Not Found", "unknown remote cluster"])


        finally:
            remote_client.disconnect()
            self._teardown_xdcr()
Beispiel #3
0
    def testBucketModification(self):
        cli_command = "bucket-edit"
        bucket_type = self.input.param("bucket_type", "couchbase")
        bucket_password = self.input.param("bucket_password", None)
        bucket_port = self.input.param("bucket_port", 11211)
        enable_flush = self.input.param("enable_flush", None)
        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")
        bucket_ramsize = self.input.param("bucket_ramsize", 200)
        bucket_replica = self.input.param("bucket_replica", 1)
        enable_flush = self.input.param("enable_flush", None)
        enable_index_replica = self.input.param("enable_index_replica", None)
        wait = self.input.param("wait", False)

        remote_client = RemoteMachineShellConnection(self.master)

        self._create_bucket(remote_client, bucket, 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)

        cli_command = "bucket-edit"
        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=self.ldapUser, password=self.ldapPass)
        expectedResults = {'bucket_name':'BBB', 'ram_quota':465567744, 'num_replicas':1,
                            'replica_index':True, 'eviction_policy':'value_only', 'type':'membase', \
                            'auth_type':'none', "autocompaction":'false', "purge_interval":"undefined", \
                            "flush_enabled":True, "num_threads":3, "source":self.source, \
                            "user":self.ldapUser, "ip":'127.0.0.1', "port":57457, 'sessionid':'',
                            "moxi_port":1224 }
        self.checkConfig(8202, self.master, expectedResults)

        cli_command = "bucket-flush --force"
        options = "--bucket={0}".format(bucket)
        if enable_flush_new is not None:
            output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, options=options, cluster_host="localhost", user=self.ldapUser, password=self.ldapPass)
        expectedResults = {"bucket_name":"BBB", "source":self.source, "user":self.ldapUser, "ip":"127.0.0.1", 'port':57457}
        self.checkConfig(8204, self.master, expectedResults)

        cli_command = "bucket-delete"
        output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, options=options, cluster_host="localhost", user=self.ldapUser, password=self.ldapPass)
        expectedResults = {"bucket_name":"BBB", "source":self.source, "user":self.ldapUser, "ip":"127.0.0.1", "port":57457}
        self.checkConfig(8203, self.master, expectedResults)

        remote_client.disconnect()
Beispiel #4
0
    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="******", password="******")
        server_info = self._get_cluster_info(remote_client)
        result = server_info["otpNode"] + " " + server_info["hostname"] + " " + server_info["status"] + " " + server_info["clusterMembership"]
        self.assertEqual(result, "ns_1@{0} {0}:8091 healthy active".format("127.0.0.1"))

        cli_command = "bucket-list"
        output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, cluster_host="localhost", user="******", password="******")
        self.assertEqual([], output)
        remote_client.disconnect()
Beispiel #5
0
    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="******", password="******")
        self.assertEqual(output, ["(u'none', 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="******", 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="******", password="******")
        self.assertEqual(output, ["(u'none', 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="******", 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="******", 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="******", password="******")

            t.join()

            cli_command = "rebalance"
            output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, cluster_host="localhost", user="******", 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="******", password="******")
            self.assertEqual(output, ["(u'none', None)"])
        remote_client.disconnect()
Beispiel #6
0
    def testBucketModification(self):
        if self.role in ['replication_admin','views_admin[*]']:
            result = "Forbidden"
        elif self.role in ['admin','cluster_admin','bucket_admin[*]']:
            result = 'SUCCESS'
        cli_command = "bucket-edit"
        bucket_type = self.input.param("bucket_type", "couchbase")
        enable_flush = self.input.param("enable_flush", None)
        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")
        bucket_ramsize = self.input.param("bucket_ramsize", 200)
        bucket_replica = self.input.param("bucket_replica", 1)
        enable_flush = self.input.param("enable_flush", None)
        enable_index_replica = self.input.param("enable_index_replica", None)
        wait = self.input.param("wait", False)

        remote_client = RemoteMachineShellConnection(self.master)

        self._create_bucket(remote_client, bucket, bucket_type=bucket_type, bucket_ramsize=bucket_ramsize,
                            bucket_replica=bucket_replica, wait=wait, enable_flush=enable_flush,
                            enable_index_replica=enable_index_replica,user="******",password='******')

        cli_command = "bucket-edit"
        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-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=self.ldapUser, password=self.ldapPass)
        self._validate_roles(output,result)

        cli_command = "bucket-flush --force"
        options = "--bucket={0}".format(bucket)
        if enable_flush_new is not None:
            output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, options=options, cluster_host="localhost", user=self.ldapUser, password=self.ldapPass)
        self._validate_roles(output,result)

        cli_command = "bucket-delete"
        output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, options=options, cluster_host="localhost", user=self.ldapUser, password=self.ldapPass)
        expectedResults = {"bucket_name":"BBB", "source":self.source, "user":self.ldapUser, "ip":"127.0.0.1", "port":57457}
        self._validate_roles(output,result)

        remote_client.disconnect()
Beispiel #7
0
    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", '')
        remote_client = RemoteMachineShellConnection(self.master)
        cli_command = "setting-compaction"
        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="******", password="******")
        expectedResults = {"parallel_db_and_view_compaction":False, "database_fragmentation_threshold:size":10485760, "database_fragmentation_threshold:view_fragmentation_threshold":{}, "real_userid:source":"ns_server", "real_userid:user":"******", "remote:ip":"127.0.0.1", "remote:port":60019}
        self.checkConfig(8225, self.master, expectedResults)
        remote_client.disconnect()
Beispiel #8
0
 def testSSLManage(self):
     """ssl-manage OPTIONS:
     --retrieve-cert=CERTIFICATE            retrieve cluster certificate AND save to a pem file
     --regenerate-cert=CERTIFICATE          regenerate cluster certificate AND save to a pem file"""
     xdcr_cert = self.input.param("xdcr-certificate", None)
     xdcr_cert = "/tmp/" + xdcr_cert
     cli_command = "ssl-manage"
     remote_client = RemoteMachineShellConnection(self.master)
     options = "--regenerate-cert={0}".format(xdcr_cert)
     output, error = remote_client.execute_couchbase_cli(
         cli_command=cli_command,
         options=options,
         cluster_host="localhost",
         user=self.ldapUser,
         password=self.ldapPass,
     )
     self.assertFalse(error, "Error thrown during CLI execution %s" % error)
     self.shell.execute_command("rm {0}".format(xdcr_cert))
     expectedResults = {
         "real_userid:source": self.source,
         "real_userid:user": self.ldapUser,
         "remote:ip": "127.0.0.1",
         "port": 60035,
     }
     self.checkConfig(8226, self.master, expectedResults)
    def test_compaction_with_cluster_ramquota_change(self):
        self.make_ddocs(self.ddocs_num, self.view_per_ddoc)
        self.create_ddocs()
        gen_load = BlobGenerator("test_view_compaction", "test_view_compaction-", self.value_size, end=self.num_items)
        self._load_all_buckets(self.master, gen_load, "create", 0)
        for ddoc in self.ddocs:
            fragmentation_monitor = self.cluster.async_monitor_view_fragmentation(
                self.master, ddoc.name, self.fragmentation_value
            )
            while fragmentation_monitor.state != "FINISHED":
                self._load_all_buckets(self.master, gen_load, "update", 0)
                for view in ddoc.views:
                    self.cluster.query_view(self.master, ddoc.name, view.name, {})
            fragmentation_monitor.result()

        compaction_tasks = []
        for ddoc in self.ddocs:
            compaction_tasks.append(self.cluster.async_compact_view(self.master, ddoc.name))

        remote = RemoteMachineShellConnection(self.master)
        cli_command = "cluster-init"
        options = "--cluster-init-ramsize=%s" % (self.quota + 10)
        output, error = remote.execute_couchbase_cli(
            cli_command=cli_command,
            options=options,
            cluster_host="localhost",
            user=self.master.rest_username,
            password=self.master.rest_password,
        )
        self.assertTrue("\n".join(output).find("SUCCESS") != -1, "ram wasn't changed")
        self.log.info("Quota was changed")
        for task in compaction_tasks:
            task.result()
Beispiel #10
0
 def execute_admin_role_manage(self, options):
     cli_command = 'user-manage'
     options = options
     remote_client = RemoteMachineShellConnection(self.master)
     output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
                 options=options, cluster_host="localhost", user=self.ldapUser, password=self.ldapPass)
     return output, error
Beispiel #11
0
 def _retrieve_cluster_cert_extended(self,server):
     cli_command = 'ssl-manage'
     options = "--cluster-cert-info --extended"
     remote_client = RemoteMachineShellConnection(server)
     output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
                 options=options, cluster_host="localhost", user=self.ldapUser, password=self.ldapPass)
     return output, error
    def test_full_eviction_changed_to_value_eviction(self):

        KEY_NAME = 'key1'

        gen_create = BlobGenerator('eviction', 'eviction-', self.value_size, end=self.num_items)
        gen_create2 = BlobGenerator('eviction2', 'eviction2-', self.value_size, end=self.num_items)
        self._load_all_buckets(self.master, gen_create, "create", 0)

        self._wait_for_stats_all_buckets(self.servers[:self.nodes_init])
        self._verify_stats_all_buckets(self.servers[:self.nodes_init])
        remote = RemoteMachineShellConnection(self.master)
        for bucket in self.buckets:
            output, _ = remote.execute_couchbase_cli(cli_command='bucket-edit',
                                                         cluster_host="localhost",
                                                         user=self.master.rest_username,
                                                         password=self.master.rest_password,
                                                         options='--bucket=%s --bucket-eviction-policy=valueOnly' % bucket.name)
            self.assertTrue(' '.join(output).find('SUCCESS') != -1, 'Eviction policy wasn\'t changed')
        ClusterOperationHelper.wait_for_ns_servers_or_assert(
                                            self.servers[:self.nodes_init], self,
                                            wait_time=self.wait_timeout, wait_if_warmup=True)
        self.sleep(10, 'Wait some time before next load')
        #self._load_all_buckets(self.master, gen_create2, "create", 0)
        #import pdb;pdb.set_trace()


        rest = RestConnection(self.master)
        client = VBucketAwareMemcached(rest, 'default')
        mcd = client.memcached(KEY_NAME)
        try:
            rc = mcd.set(KEY_NAME, 0,0, json.dumps({'value':'value2'}))
            self.fail('Bucket is incorrectly functional')
        except MemcachedError, e:
            pass   # this is the exception we are hoping for
Beispiel #13
0
    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()
        self.sleep(5)

        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.assertEqual(output[0], 'ERROR: unable to init localhost (400) Bad Request')
            self.assertTrue(output[1] == "[u'Username and password are required.']" or output[1] == "[u'The password must be at least six characters.']")
            remote_client.disconnect()
        finally:
            rest = RestConnection(server)
            rest.force_eject_node()
            self.sleep(5)
            rest.init_cluster()
Beispiel #14
0
 def _download_node_cert(self,server):
     cli_command = 'ssl-manage'
     options = "--node-cert-info"
     remote_client = RemoteMachineShellConnection(server)
     output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
                 options=options, cluster_host=server.ip + ":8091", user=self.ldapUser, password=self.ldapPass)
     return output, error
Beispiel #15
0
 def test_enableDisableLdap(self):
     rest = RestConnection(self.master)
     remote_client = RemoteMachineShellConnection(self.master)
     origState = rest.ldapRestOperationGetResponse()['enabled']
     cli_command = 'setting-ldap'
     options = "--ldap-enable=0"
     output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
                 options=options, cluster_host="localhost", user=self.ldapUser, password=self.ldapPass)
     tempStatus = rest.ldapRestOperationGetResponse()['enabled']
     self.assertFalse(tempStatus, "Issues with setting LDAP enable/disable")
     cli_command = 'setting-ldap'
     options = "--ldap-enable=1"
     output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
                 options=options, cluster_host="localhost", user="******", password="******")
     tempStatus = rest.ldapRestOperationGetResponse()['enabled']
     self.assertTrue(tempStatus, "Issues with setting LDAP enable/disable")
Beispiel #16
0
 def execute_password_policy(self, options):
     cli_command = 'setting-password-policy'
     options = options
     remote_client = RemoteMachineShellConnection(self.master)
     output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
                 options=options, cluster_host="localhost", user=self.ldapUser, password=self.ldapPass)
     return output, error
Beispiel #17
0
 def disableLdap(self):
     cli_command = 'setting-ldap'
     options = "--ldap-enable=0"
     remote_client = RemoteMachineShellConnection(self.master)
     output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
                 options=options, cluster_host="localhost", user="******", password="******")
     print output
     print error
    def test_cli_travel_sample_bucket(self):
        sample = "travel-sample"
        num_expected = self.input.param('num_items', 31569)
        """ couchbase-cli does not have option to reset the node yet
            use rest to reset node to set services correctly: index,kv,n1ql """
        self.rest.force_eject_node()

        shell = RemoteMachineShellConnection(self.master)
        options = '--cluster-init-username="******" \
                        --cluster-init-password="******" \
                        --cluster-init-port=8091 \
                        --cluster-ramsize=300 \
                        --cluster-index-ramsize=300 \
                        --services=data,index,query'
        o, e = shell.execute_couchbase_cli(cli_command="cluster-init", options=options)
        self.assertEqual(o[0], "SUCCESS: init/edit localhost")

        shell = RemoteMachineShellConnection(self.master)
        shell.execute_command("{0}cbdocloader -u Administrator -p password \
                      -n {1} -b travel-sample -s 100 {2}travel-sample.zip" \
                   .format(self.bin_path, self.master.ip, self.sample_path))
        shell.disconnect()

        buckets = RestConnection(self.master).get_buckets()
        for bucket in buckets:
            if bucket.name != "travel-sample":
                self.fail("travel-sample bucket did not create")

        """ check for load data into travel-sample bucket """
        end_time = time.time() + 120
        while time.time() < end_time:
            self.sleep(10)
            num_actual = self.get_item_count(self.master,"travel-sample")
            if num_actual == num_expected:
                break
        self.assertTrue(num_actual == num_expected,
                        "Items number expected %s, actual %s" % (
                                                    num_expected, num_actual))

        """ check all indexes are completed """
        index_name = []
        result = self.rest.index_tool_stats()
        end_time_i = time.time() + 60
        for map in result:
            if result["indexes"]:
                for x in result["indexes"]:
                    if x["bucket"] == "travel-sample":
                        if x["progress"] == 100 and x["index"] not in index_name:
                            index_name.append(x["index"])
            else:
                self.fail("indexing failed to build")
        if len(index_name) < 8:
            self.log.info("index list {0}".format(index_name))
            self.fail("some indexing may not complete")
        elif len(index_name) == 8:
            self.log.info("travel-sample bucket is created and complete indexing")
            self.log.info("index list in travel-sample bucket: {0}"
                                       .format(index_name))
Beispiel #19
0
 def test_enableDisableAudit(self):
     auditIns = audit(host=self.master)
     remote_client = RemoteMachineShellConnection(self.master)
     tempEnable = auditIns.getAuditStatus()
     try:
         cli_command = 'setting-audit'
         options = "--audit-enable=0"
         output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
                     options=options, cluster_host="localhost", user=self.ldapUser, password=self.ldapPass)
         tempEnable = auditIns.getAuditStatus()
         self.assertFalse(tempEnable, "Issues enable/disable via CLI")
         options = "--audit-enable=1"
         output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
                     options=options, cluster_host="localhost", user=self.ldapUser, password=self.ldapPass)
         tempEnable = auditIns.getAuditStatus()
         self.assertTrue(tempEnable, "Issues enable/disable via CLI")
     finally:
         auditIns.setAuditEnable(self.returnBoolVal(tempEnable))
    def testSettingNotification(self):
        setting_enable_notification = self.input.param("enable-notification", 1)

        remote_client = RemoteMachineShellConnection(self.master)
        cli_command = "setting-notification"
        options = (" --enable-notification={0}".format(setting_enable_notification))

        output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, options=options, cluster_host="localhost", user=self.ldapUser, password=self.ldapPass)
        remote_client.disconnect()
Beispiel #21
0
 def _upload_cert_cli(self):
     path_to_root_cert = self.install_path + x509main.CHAINFILEPATH + "/root.crt"
     self._copy_root_crt()
     cli_command = 'ssl-manage'
     options = "--upload-cluster-ca={0}".format(path_to_root_cert)
     remote_client = RemoteMachineShellConnection(self.master)
     output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
                 options=options, cluster_host="localhost", user=self.ldapUser, password=self.ldapPass)
     return output, error
 def test_hostname_mgmt_server_list(self):
     hostnames = self.rename_nodes(self.servers[:self.nodes_init])
     self._set_hostames_to_servers_objs(hostnames)
     self.verify_referenced_by_names(self.servers[:self.nodes_init], hostnames)
     remote = RemoteMachineShellConnection(self.master)
     cli_command = "server-list"
     output, error = remote.execute_couchbase_cli(cli_command=cli_command,
                                                  cluster_host=self.master.hostname,
                                                  user="******", password="******")
     self.assertEqual(''.join(output), "ns_1@{0} {0}:8091 healthy active".format(self.master.hostname))
 def test_hostname_mgmt_buckets_list(self):
     hostnames = self.rename_nodes(self.servers[:self.nodes_init])
     self._set_hostames_to_servers_objs(hostnames)
     self.verify_referenced_by_names(self.servers[:self.nodes_init], hostnames)
     remote_client = RemoteMachineShellConnection(self.master)
     cli_command = "bucket-list"
     output, error = remote_client.execute_couchbase_cli(cli_command=cli_command,
                                                         cluster_host=self.master.hostname,
                                                         user="******", password="******")
     self.assertTrue(''.join(output).find(''.join([b.name for b in self.buckets])) != -1)
     remote_client.disconnect()
Beispiel #24
0
 def _reset_original(self):
     self.log.info ("Reverting to original state - regenerating certificate and removing inbox folder")
     tmp_path = "/tmp/abcd.pem"
     for servers in self.servers:
         cli_command = "ssl-manage"
         remote_client = RemoteMachineShellConnection(servers)
         options = "--regenerate-cert={0}".format(tmp_path)
         output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, options=options,
                                                             cluster_host=servers.ip, user="******",
                                                             password="******")
         x509main(servers)._delete_inbox_folder()
Beispiel #25
0
 def test_setLDAPParam(self):
     cli_command = "setting-ldap"
     options = " --ldap-enable={0}".format(self.enableStatus)
     options += " --ldap-roadmins={0}".format(",".join(self.roAdmin))
     options += " --ldap-admins={0}".format(",".join(self.admin))
     options += " --ldap-default={0}".format(self.default)
     remote_client = RemoteMachineShellConnection(self.master)
     output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
                 options=options, cluster_host="localhost", user=self.ldapUser, password=self.ldapPass)
     tempFlag = self.validateSettings(self.enableStatus, self.admin, self.roAdmin, self.default)
     self.assertTrue(tempFlag)
Beispiel #26
0
    def testSettingCompacttion(self):
        if self.role in ["replication_admin", "views_admin[*]", "bucket_admin[*]"]:
            result = "Forbidden"
        elif self.role in ["admin", "cluster_admin"]:
            result = "SUCCESS"
        cli_command = "bucket-edit"
        """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", "")
        remote_client = RemoteMachineShellConnection(self.master)
        cli_command = "setting-compaction"
        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=self.ldapUser,
            password=self.ldapPass,
        )
        self._validate_roles(output, result)
        remote_client.disconnect()
 def test_rebalance_in_with_cluster_ramquota_change(self):
     rebalance = self.cluster.async_rebalance(self.servers[:self.nodes_init],
                                              self.servers[self.nodes_init:self.nodes_init + self.nodes_in],
                                              [])
     self.sleep(10, "Wait for rebalance have some progress")
     remote = RemoteMachineShellConnection(self.master)
     cli_command = "setting-cluster"
     options = "--cluster-ramsize=%s" % (3000)
     output, error = remote.execute_couchbase_cli(cli_command=cli_command, options=options, cluster_host="localhost",
                                                  user=self.master.rest_username, password=self.master.rest_password)
     self.assertTrue('\n'.join(output).find('SUCCESS') != -1, 'RAM wasn\'t chnged')
     rebalance.result()
 def test_hostname_mgmt_create_bucket(self):
     hostnames = self.rename_nodes(self.servers[:self.nodes_init])
     self._set_hostames_to_servers_objs(hostnames)
     self.verify_referenced_by_names(self.servers[:self.nodes_init], hostnames)
     remote_client = RemoteMachineShellConnection(self.master)
     cli_command = "bucket-create"
     output, error = remote_client.execute_couchbase_cli(cli_command=cli_command,
                                                         cluster_host=self.master.hostname,
                                                         user="******", password="******",
                                                         options=' --bucket=test --bucket-type=couchbase --bucket-port=11210 --bucket-ramsize=100 --bucket-replica=1')
     self.assertTrue(''.join(output).find(''.join([b.name for b in self.buckets])) != -1)
     remote_client.disconnect()
 def test_hostname_mgmt_remove_bucket(self):
     hostnames = self.rename_nodes(self.servers[:self.nodes_init])
     self._set_hostames_to_servers_objs(hostnames)
     self.verify_referenced_by_names(self.servers[:self.nodes_init], hostnames)
     remote_client = RemoteMachineShellConnection(self.master)
     cli_command = "bucket-delete"
     output, error = remote_client.execute_couchbase_cli(cli_command=cli_command,
                                                         cluster_host=self.master.hostname,
                                                         user="******", password="******",
                                                         options='--bucket=default')
     self.assertEqual(['SUCCESS: bucket-delete'], [i for i in output if i != ''])
     remote_client.disconnect()
    def testSettingFailover(self):
        setting_enable_auto_failover = self.input.param("enable-auto-failover", 1)
        setting_auto_failover_timeout = self.input.param("auto-failover-timeout", 50)

        remote_client = RemoteMachineShellConnection(self.master)
        cli_command = "setting-autofailover"
        options = (" --enable-auto-failover={0}".format(setting_enable_auto_failover))
        options += (" --auto-failover-timeout={0}".format(setting_auto_failover_timeout))

        output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, options=options, cluster_host="localhost", user=self.ldapUser, password=self.ldapPass)
        expectedResults = {"max_nodes":1, "timeout":50, "real_userid:source":self.source, "real_userid:user":self.ldapUser, "remote:ip":"127.0.0.1", "port":60033}
        self.checkConfig(8220, self.master, expectedResults)
        remote_client.disconnect()
Beispiel #31
0
    def test_compression_active_and_off(self):
        '''
        test reproducer for MB-29272,
        Load some documents with compression mode set to active
        get the cbstats
        change compression mode to off and wait for minimum 250ms
        Load some more documents and check the compression is not done
        epengine.basic_ops.basic_ops.test_compression_active_and_off,items=10000,compression_mode=active

        :return:
        '''
        # Load some documents with compression mode as active
        gen_create = BlobGenerator('eviction',
                                   'eviction-',
                                   self.value_size,
                                   end=self.num_items)
        gen_create2 = BlobGenerator('eviction2',
                                    'eviction2-',
                                    self.value_size,
                                    end=self.num_items)
        def_bucket = self.bucket_util.get_all_buckets()[0]
        print_ops_task = self.bucket_util.async_print_bucket_ops(def_bucket)
        task = self.task.async_load_gen_docs(self.cluster,
                                             def_bucket,
                                             gen_create,
                                             "create",
                                             0,
                                             batch_size=10,
                                             process_concurrency=8,
                                             replicate_to=self.replicate_to,
                                             persist_to=self.persist_to,
                                             durability=self.durability_level,
                                             timeout_secs=self.sdk_timeout,
                                             retries=self.sdk_retries)
        self.task.jython_task_manager.get_task_result(task)
        self.bucket_util._wait_for_stats_all_buckets()
        self.bucket_util.verify_stats_all_buckets(self.num_items)
        print_ops_task.end_task()

        remote = RemoteMachineShellConnection(self.cluster.master)
        for bucket in self.buckets:
            # change compression mode to off
            output, _ = remote.execute_couchbase_cli(
                cli_command='bucket-edit',
                cluster_host="localhost:8091",
                user=self.cluster.master.rest_username,
                password=self.cluster.master.rest_password,
                options='--bucket=%s --compression-mode off' % bucket.name)
            self.assertTrue(' '.join(output).find('SUCCESS') != -1,
                            'compression mode set to off')

            # sleep for 10 sec (minimum 250sec)
            time.sleep(10)

        # Load data and check stats to see compression
        # is not done for newly added data
        print_ops_task = self.bucket_util.async_print_bucket_ops(def_bucket)
        task = self.task.async_load_gen_docs(self.cluster,
                                             def_bucket,
                                             gen_create2,
                                             "create",
                                             0,
                                             batch_size=10,
                                             process_concurrency=8,
                                             replicate_to=self.replicate_to,
                                             persist_to=self.persist_to,
                                             durability=self.durability_level,
                                             timeout_secs=self.sdk_timeout,
                                             retries=self.sdk_retries)
        self.task.jython_task_manager.get_task_result(task)
        self.bucket_util._wait_for_stats_all_buckets()
        self.bucket_util.verify_stats_all_buckets(self.num_items)
        print_ops_task.end_task()
Beispiel #32
0
    def testBucketModification(self):
        if self.role in ['replication_admin', 'views_admin[*]']:
            result = "Forbidden"
        elif self.role in ['admin', 'cluster_admin', 'bucket_admin[*]']:
            result = 'SUCCESS'
        cli_command = "bucket-edit"
        bucket_type = self.input.param("bucket_type", "couchbase")
        enable_flush = self.input.param("enable_flush", None)
        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")
        bucket_ramsize = self.input.param("bucket_ramsize", 200)
        bucket_replica = self.input.param("bucket_replica", 1)
        enable_flush = self.input.param("enable_flush", None)
        enable_index_replica = self.input.param("enable_index_replica", None)
        wait = self.input.param("wait", False)

        remote_client = RemoteMachineShellConnection(self.master)

        self._create_bucket(remote_client,
                            bucket,
                            bucket_type=bucket_type,
                            bucket_ramsize=bucket_ramsize,
                            bucket_replica=bucket_replica,
                            wait=wait,
                            enable_flush=enable_flush,
                            enable_index_replica=enable_index_replica,
                            user="******",
                            password='******')

        cli_command = "bucket-edit"
        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-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="127.0.0.1:8091",
            user=self.ldapUser,
            password=self.ldapPass)
        self._validate_roles(output, result)

        cli_command = "bucket-flush --force"
        options = "--bucket={0}".format(bucket)
        if enable_flush_new is not None:
            output, error = remote_client.execute_couchbase_cli(
                cli_command=cli_command,
                options=options,
                cluster_host="127.0.0.1:8091",
                user=self.ldapUser,
                password=self.ldapPass)
        self._validate_roles(output, result)

        cli_command = "bucket-delete"
        output, error = remote_client.execute_couchbase_cli(
            cli_command=cli_command,
            options=options,
            cluster_host="127.0.0.1:8091",
            user=self.ldapUser,
            password=self.ldapPass)
        expectedResults = {
            "bucket_name": "BBB",
            "source": self.source,
            "user": self.ldapUser,
            "ip": "127.0.0.1",
            "port": 57457
        }
        self._validate_roles(output, result)

        remote_client.disconnect()
Beispiel #33
0
    def testSettingCompacttion(self):
        if self.role in [
                'replication_admin', 'views_admin[*]', 'bucket_admin[*]'
        ]:
            result = "Forbidden"
        elif self.role in ['admin', 'cluster_admin']:
            result = 'SUCCESS'
        cli_command = "bucket-edit"
        '''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", '')
        remote_client = RemoteMachineShellConnection(self.master)
        cli_command = "setting-compaction"
        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="127.0.0.1:8091",
            user=self.ldapUser,
            password=self.ldapPass)
        self._validate_roles(output, result)
        remote_client.disconnect()
    def testBucketModification(self):
        cli_command = "bucket-edit"
        bucket_type = self.input.param("bucket_type", "couchbase")
        bucket_password = self.input.param("bucket_password", None)
        bucket_port = self.input.param("bucket_port", 11211)
        enable_flush = self.input.param("enable_flush", None)
        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")
        bucket_ramsize = self.input.param("bucket_ramsize", 200)
        bucket_replica = self.input.param("bucket_replica", 1)
        enable_flush = self.input.param("enable_flush", None)
        enable_index_replica = self.input.param("enable_index_replica", None)
        wait = self.input.param("wait", False)

        remote_client = RemoteMachineShellConnection(self.master)

        self._create_bucket(remote_client,
                            bucket,
                            bucket_type=bucket_type,
                            bucket_ramsize=bucket_ramsize,
                            bucket_replica=bucket_replica,
                            wait=wait,
                            enable_flush=enable_flush,
                            enable_index_replica=enable_index_replica)

        cli_command = "bucket-edit"
        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-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=self.ldapUser,
            password=self.ldapPass)
        expectedResults = {'bucket_name':'BBB', 'ram_quota':465567744, 'num_replicas':1,
                            'replica_index':True, 'eviction_policy':'value_only', 'type':'membase', \
                            'auth_type':'none', "autocompaction":'false', "purge_interval":"undefined", \
                            "flush_enabled":True, "num_threads":3, "source":self.source, \
                            "user":self.ldapUser, "ip":'::1', "port":57457, 'sessionid':'',
                            'auth_type':self.source, 'storage_mode': 'couchstore'}
        self.checkConfig(8202, self.master, expectedResults)

        cli_command = "bucket-flush --force"
        options = "--bucket={0}".format(bucket)
        if enable_flush_new is not None:
            output, error = remote_client.execute_couchbase_cli(
                cli_command=cli_command,
                options=options,
                cluster_host="localhost",
                user=self.ldapUser,
                password=self.ldapPass)
        expectedResults = {
            "bucket_name": "BBB",
            "source": self.source,
            "user": self.ldapUser,
            "ip": "::1",
            'port': 57457
        }
        self.checkConfig(8204, self.master, expectedResults)

        cli_command = "bucket-delete"
        output, error = remote_client.execute_couchbase_cli(
            cli_command=cli_command,
            options=options,
            cluster_host="localhost",
            user=self.ldapUser,
            password=self.ldapPass)
        expectedResults = {
            "bucket_name": "BBB",
            "source": self.source,
            "user": self.ldapUser,
            "ip": "::1",
            "port": 57457
        }
        self.checkConfig(8203, self.master, expectedResults)

        remote_client.disconnect()
    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", '')
        remote_client = RemoteMachineShellConnection(self.master)
        cli_command = "setting-compaction"
        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=self.ldapUser,
            password=self.ldapPass)
        expectedResults = {
            "parallel_db_and_view_compaction": False,
            "database_fragmentation_threshold:size": 10485760,
            "database_fragmentation_threshold:view_fragmentation_threshold":
            {},
            "real_userid:source": self.source,
            "real_userid:user": self.ldapUser,
            "remote:ip": "::1",
            "remote:port": 60019
        }
        self.checkConfig(8225, self.master, expectedResults)
        remote_client.disconnect()
    def testSettingEmail(self):
        setting_enable_email_alert = self.input.param("enable-email-alert", 1)
        setting_email_recipients = self.input.param("email-recipients",
                                                    '*****@*****.**')
        setting_email_sender = self.input.param("email-sender",
                                                '*****@*****.**')
        setting_email_user = self.input.param("email-user", 'ritam')
        setting_emaiL_password = self.input.param("email-password", 'password')
        setting_email_host = self.input.param("email-host", 'localhost')
        setting_email_port = self.input.param("email-port", '25')
        setting_email_encrypt = self.input.param("enable-email-encrypt", 0)

        remote_client = RemoteMachineShellConnection(self.master)
        cli_command = "setting-alert"
        options = (
            " --enable-email-alert={0}".format(setting_enable_email_alert))
        options += (" --email-recipients={0}".format(setting_email_recipients))
        options += (" --email-sender={0}".format(setting_email_sender))
        options += (" --email-user={0}".format(setting_email_user))
        options += (" --email-password={0}".format(setting_emaiL_password))
        options += (" --email-host={0}".format(setting_email_host))
        options += (" --email-port={0}".format(setting_email_port))
        options += (
            " --enable-email-encrypt={0}".format(setting_email_encrypt))
        options += (" --alert-auto-failover-node")
        options += (" --alert-auto-failover-max-reached")
        options += (" --alert-auto-failover-node-down")
        options += (" --alert-auto-failover-cluster-small")
        options += (" --alert-ip-changed")
        options += (" --alert-disk-space")
        options += (" --alert-meta-overhead")
        options += (" --alert-meta-oom")
        options += (" --alert-write-failed")

        output, error = remote_client.execute_couchbase_cli(
            cli_command=cli_command,
            options=options,
            cluster_host="localhost",
            user=self.ldapUser,
            password=self.ldapPass)
        expectedResults = {
            "email_server:encrypt":
            False,
            "email_server:port":
            25,
            "email_server:host":
            "localhost",
            "email_server:user":
            "******",
            "alerts": [
                "auto_failover_node", "auto_failover_maximum_reached",
                "auto_failover_other_nodes_down",
                "auto_failover_cluster_too_small", "ip", "disk", "overhead",
                "ep_oom_errors", "ep_item_commit_failed"
            ],
            "recipients": ["*****@*****.**"],
            "sender":
            "*****@*****.**",
            "real_userid:source":
            self.source,
            "real_userid:user":
            self.ldapUser,
            "remote:ip":
            "127.0.0.1",
            "port":
            60025
        }
        self.checkConfig(8223, self.master, expectedResults)
        remote_client.disconnect()
    def testCreateRenameDeleteGroup(self):
        remote_client = RemoteMachineShellConnection(self.master)
        cli_command = "group-manage"
        source = self.source
        user = self.ldapUser
        rest = RestConnection(self.master)

        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=self.ldapUser, password=self.ldapPass)
            output = self.del_runCmd_value(output)
            self.assertEqual(output[1], "SUCCESS: Server group created")
            expectedResults = {
                'group_name': 'group2',
                'source': source,
                'user': user,
                'ip': '127.0.0.1',
                'port': 1234
            }
            tempStr = rest.get_zone_uri()[expectedResults['group_name']]
            tempStr = (tempStr.split("/"))[4]
            expectedResults['uuid'] = tempStr
            self.checkConfig(8210, self.master, expectedResults)

            # 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=self.ldapUser, password=self.ldapPass)
            output = self.del_runCmd_value(output)
            self.assertEqual(output[1], ["SUCCESS: group renamed group"])
            expectedResults = {}
            expectedResults = {
                'group_name': 'group3',
                'source': source,
                'user': user,
                'ip': '127.0.0.1',
                'port': 1234,
                'nodes': []
            }
            expectedResults['uuid'] = tempStr
            self.checkConfig(8212, self.master, expectedResults)

            # 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=self.ldapUser, password=self.ldapPass)
            output = self.del_runCmd_value(output)
            self.assertEqual(output[1], ["SUCCESS: group deleted group"])
            expectedResults = {}
            expectedResults = {
                'group_name': 'group3',
                'source': source,
                'user': user,
                'ip': '127.0.0.1',
                'port': 1234
            }
            expectedResults['uuid'] = tempStr
            self.checkConfig(8211, self.master, expectedResults)

        if self.os == "windows":
            # create group
            options = " --create --group-name=group2"
            output, error = remote_client.execute_couchbase_cli(cli_command=cli_command, \
                    options=options, cluster_host="localhost", user=self.ldapUser, password=self.ldapPass)
            self.assertEqual(output[0], "SUCCESS: group created group2")
            expectedResults = {
                'group_name': 'group2',
                'source': source,
                'user': user,
                'ip': '127.0.0.1',
                'port': 1234
            }
            tempStr = rest.get_zone_uri()[expectedResults['group_name']]
            tempStr = (tempStr.split("/"))[4]
            expectedResults['uuid'] = tempStr
            self.checkConfig(8210, self.master, expectedResults)

            # 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=self.ldapUser, password=self.ldapPass)
            self.assertEqual(output[0], "SUCCESS: group renamed group2")
            expectedResults = {}
            expectedResults = {
                'group_name': 'group3',
                'source': source,
                'user': user,
                'ip': '127.0.0.1',
                'port': 1234,
                'nodes': []
            }
            expectedResults['uuid'] = tempStr
            self.checkConfig(8212, self.master, expectedResults)

            # 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=self.ldapUser, password=self.ldapPass)
            self.assertEqual(output[0], "SUCCESS: group deleted group3")
            expectedResults = {}
            expectedResults = {
                'group_name': 'group3',
                'source': source,
                'user': user,
                'ip': '127.0.0.1',
                'port': 1234
            }
            expectedResults['uuid'] = tempStr
            self.checkConfig(8211, self.master, expectedResults)

            remote_client.disconnect()
class XdcrCLITest(CliBaseTest):
    def setUp(self):
        TestInputSingleton.input.test_params["default_bucket"] = False
        super(XdcrCLITest, self).setUp()
        self.ldapUser = self.input.param("ldapUser", 'Administrator')
        self.ldapPass = self.input.param('ldapPass', 'password')
        self.source = self.input.param('source', 'ns_server')
        self.__user = self.input.param("ldapUser", 'Administrator')
        self.__password = self.input.param('ldapPass', 'password')
        self.shell = RemoteMachineShellConnection(self.master)
        info = self.shell.extract_remote_info()
        type = info.type.lower()
        if type == 'windows' and self.source == 'saslauthd':
            raise Exception(" Ldap Tests cannot run on windows")
        elif self.source == 'saslauthd':
            rest = RestConnection(self.master)
            self.setupLDAPSettings(rest)
            #rest.ldapUserRestOperation(True, [[self.ldapUser]], exclude=None)
            self.set_user_role(rest, self.ldapUser)

    def tearDown(self):
        for server in self.servers:
            rest = RestConnection(server)
            rest.remove_all_remote_clusters()
            rest.remove_all_replications()
            rest.remove_all_recoveries()
        super(XdcrCLITest, self).tearDown()

    def set_user_role(self, rest, username, user_role='admin'):
        payload = "name=" + username + "&roles=" + user_role
        content = rest.set_user_roles(user_id=username, payload=payload)

    def setupLDAPSettings(self, rest):
        api = rest.baseUrl + 'settings/saslauthdAuth'
        params = urllib.urlencode({
            "enabled": 'true',
            "admins": [],
            "roAdmins": []
        })
        status, content, header = rest._http_request(api, 'POST', params)
        return status, content, header

    #Wrapper around auditmain
    def checkConfig(self, eventID, host, expectedResults):
        Audit = audit(eventID=eventID, host=host)
        fieldVerification, valueVerification = Audit.validateEvents(
            expectedResults)
        self.assertTrue(fieldVerification, "One of the fields is not matching")
        self.assertTrue(valueVerification,
                        "Values for one of the fields is not matching")

    def __execute_cli(self,
                      cli_command,
                      options,
                      cluster_host="localhost",
                      user=None,
                      password=None):
        if user is None:
            user = self.__user
            password = self.__password
        return self.shell.execute_couchbase_cli(cli_command=cli_command,
                                                options=options,
                                                cluster_host=cluster_host,
                                                user=user,
                                                password=password)

    def __xdcr_setup_create(self):
        # xdcr_hostname=the number of server in ini file to add to master as replication
        xdcr_cluster_name = self.input.param("xdcr-cluster-name", None)
        xdcr_hostname = self.input.param("xdcr-hostname", None)
        xdcr_username = self.input.param("xdcr-username", None)
        xdcr_password = self.input.param("xdcr-password", None)
        demand_encyrption = self.input.param("demand-encryption", 0)
        xdcr_cert = self.input.param("xdcr-certificate", None)
        wrong_cert = self.input.param("wrong-certificate", None)

        cli_command = "xdcr-setup"
        options = "--create"
        options += (" --xdcr-cluster-name=\'{0}\'".format(xdcr_cluster_name),
                    "")[xdcr_cluster_name is None]
        print("Value of xdcr_home is {0}".format(xdcr_hostname))
        if xdcr_hostname is not None:
            options += " --xdcr-hostname={0}".format(
                self.servers[xdcr_hostname].ip)
        options += (" --xdcr-username={0}".format(xdcr_username),
                    "")[xdcr_username is None]
        options += (" --xdcr-password={0}".format(xdcr_password),
                    "")[xdcr_password is None]
        options += (" --xdcr-demand-encryption={0}".format(demand_encyrption))

        cluster_host = self.servers[xdcr_hostname].ip
        output, _ = self.__execute_cli(
            cli_command="ssl-manage",
            options="--retrieve-cert={0}".format(xdcr_cert),
            cluster_host=cluster_host,
            user='******',
            password='******')
        options += (" --xdcr-certificate={0}".format(xdcr_cert),
                    "")[xdcr_cert is None]
        #self.assertNotEqual(output[0].find("SUCCESS"), -1, "ssl-manage CLI failed to retrieve certificate")

        output, error = self.__execute_cli(cli_command=cli_command,
                                           options=options)
        return output, error, xdcr_cluster_name, xdcr_hostname, cli_command, options

    def testXDCRSetup(self):
        output, _, xdcr_cluster_name, xdcr_hostname, cli_command, options = self.__xdcr_setup_create(
        )
        expectedResults = {
            "real_userid:source": self.source,
            "user": self.__user,
            "cluster_name": "remote",
            "cluster_hostname": self.servers[xdcr_hostname].ip + ":8091",
            "is_encrypted": False
        }
        self.checkConfig(16384, self.master, expectedResults)

        if xdcr_cluster_name:
            options = options.replace("--create ", "--edit ")
            output, _ = self.__execute_cli(cli_command=cli_command,
                                           options=options)
            expectedResults = {
                "real_userid:source": self.source,
                "user": self.__user,
                "cluster_name": "remote",
                "cluster_hostname": self.servers[xdcr_hostname].ip + ":8091",
                "is_encrypted": False,
                'encryption_type': ''
            }
            self.checkConfig(16385, self.master, expectedResults)

        if not xdcr_cluster_name:
            options = "--delete --xdcr-cluster-name=\'{0}\'".format(
                "remote cluster")
        else:
            options = "--delete --xdcr-cluster-name=\'{0}\'".format(
                xdcr_cluster_name)
        output, _ = self.__execute_cli(cli_command=cli_command,
                                       options=options)
        expectedResults = {
            "real_userid:source": self.source,
            "user": self.__user,
            "cluster_name": "remote",
            "cluster_hostname": self.servers[xdcr_hostname].ip + ":8091",
            "is_encrypted": False
        }
        self.checkConfig(16386, self.master, expectedResults)

    def testXdcrReplication(self):
        '''xdcr-replicate OPTIONS:
        --create                               create and start a new replication
        --delete                               stop and cancel a replication
        --list                                 list all xdcr replications
        --xdcr-from-bucket=BUCKET              local bucket name to replicate from
        --xdcr-cluster-name=CLUSTERNAME        remote cluster to replicate to
        --xdcr-to-bucket=BUCKETNAME            remote bucket to replicate to'''
        to_bucket = self.input.param("xdcr-to-bucket", None)
        from_bucket = self.input.param("xdcr-from-bucket", None)
        error_expected = self.input.param("error-expected", False)
        replication_mode = self.input.param("replication_mode", None)
        pause_resume = self.input.param("pause-resume", None)
        _, _, xdcr_cluster_name, xdcr_hostname, _, _ = self.__xdcr_setup_create(
        )
        cli_command = "xdcr-replicate"
        options = "--create"
        options += (" --xdcr-cluster-name=\'{0}\'".format(xdcr_cluster_name),
                    "")[xdcr_cluster_name is None]
        options += (" --xdcr-from-bucket=\'{0}\'".format(from_bucket),
                    "")[from_bucket is None]
        options += (" --xdcr-to-bucket=\'{0}\'".format(to_bucket),
                    "")[to_bucket is None]
        options += (
            " --xdcr-replication-mode=\'{0}\'".format(replication_mode),
            "")[replication_mode is None]
        self.bucket_size = self._get_bucket_size(self.quota, 1)
        if from_bucket:
            bucket_params = self._create_bucket_params(
                server=self.master,
                size=self.bucket_size,
                replicas=self.num_replicas,
                enable_replica_index=self.enable_replica_index)
            self.cluster.create_default_bucket(bucket_params)
        if to_bucket:
            bucket_params = self._create_bucket_params(
                server=self.servers[xdcr_hostname],
                size=self.bucket_size,
                replicas=self.num_replicas,
                enable_replica_index=self.enable_replica_index)
            self.cluster.create_default_bucket(bucket_params)
        output, _ = self.__execute_cli(cli_command, options)
        expectedResults = {
            "real_userid:source": self.source,
            "user": self.__user,
            "local_cluster_name": self.master.ip + ":8091",
            "source_bucket_name": "default",
            "remote_cluster_name": "remote",
            "target_bucket_name": "default"
        }
        self.checkConfig(16387, self.master, expectedResults)

        self.sleep(8)
        options = "--list"
        output, _ = self.__execute_cli(cli_command, options)
        for value in output:
            if value.startswith("stream id"):
                replicator = value.split(":")[1].strip()
                if pause_resume is not None:
                    # pause replication
                    options = "--pause"
                    options += (" --xdcr-replicator={0}".format(replicator))
                    output, _ = self.__execute_cli(cli_command, options)
                    # validate output message
                    expectedResults = {
                        "real_userid:source": self.source,
                        "user": self.__user,
                        "local_cluster_name": self.master.ip + ":8091",
                        "source_bucket_name": "default",
                        "remote_cluster_name": "remote",
                        "target_bucket_name": "default"
                    }
                    self.checkConfig(16388, self.master, expectedResults)
                    expectedResults = {
                        "source_bucket_name": "default",
                        "remote_cluster_name": "remote",
                        "target_bucket_name": "default",
                        "real_userid:source": "internal",
                        "user": self.__user,
                        "local_cluster_name": self.master.ip + ":8091",
                        "updated_settings:pauseRequested": True
                    }
                    self.checkConfig(16392, self.master, expectedResults)

                    self.sleep(60)
                    # resume replication
                    options = "--resume"
                    options += (" --xdcr-replicator={0}".format(replicator))
                    output, _ = self.__execute_cli(cli_command, options)
                    expectedResults = {
                        "real_userid:source": self.source,
                        "user": self.__user,
                        "local_cluster_name": self.master.ip + ":8091",
                        "source_bucket_name": "default",
                        "remote_cluster_name": "remote",
                        "target_bucket_name": "default"
                    }
                    self.checkConfig(16389, self.master, expectedResults)

                options = "--delete"
                options += (" --xdcr-replicator={0}".format(replicator))
                output, _ = self.__execute_cli(cli_command, options)
                expectedResults = {
                    "real_userid:source": self.source,
                    "user": self.__user,
                    "local_cluster_name": self.master.ip + ":8091",
                    "source_bucket_name": "default",
                    "remote_cluster_name": "remote",
                    "target_bucket_name": "default"
                }
                self.checkConfig(16390, self.master, expectedResults)
Beispiel #39
0
    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)
        force_failover = self.input.param("force_failover", False)
        nodes_readd = self.input.param("nodes_readd", 0)
        cli_command = self.input.param("cli_command", None)
        source = self.source
        remote_client = RemoteMachineShellConnection(self.master)
        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='server-add',
                options=options,
                cluster_host="localhost",
                user=self.ldapUser,
                password=self.ldapPass)
        output, error = remote_client.execute_couchbase_cli(
            cli_command='rebalance',
            cluster_host="localhost",
            user=self.ldapUser,
            password=self.ldapPass)

        if (cli_command == "server-add"):
            expectedResults = {
                "services": ['kv'],
                'port': 8091,
                'hostname': self.servers[num + 1].ip,
                'groupUUID': "0",
                'node': 'ns_1@' + self.servers[num + 1].ip,
                'source': source,
                'user': self.master.rest_username,
                "real_userid:user": self.ldapUser,
                "ip": '127.0.0.1',
                "remote:port": 57457
            }
            self.checkConfig(self.eventID, self.master, expectedResults)
            expectedResults = {
                "delta_recovery_buckets":
                "all",
                'known_nodes':
                ["ns_1@" + self.servers[num + 1].ip, "ns_1@" + self.master.ip],
                'ejected_nodes': [],
                'source':
                'ns_server',
                'source':
                source,
                'user':
                self.master.rest_username,
                "ip":
                '127.0.0.1',
                "port":
                57457,
                "real_userid:user":
                self.ldapUser
            }
            self.checkConfig(8200, self.master, expectedResults)

        if (cli_command == 'server-remove'):
            for num in xrange(nodes_rem):
                cli_command = "rebalance"
                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=self.ldapUser,
                    password=self.ldapPass)
                #expectedResults = {'node':'ns_1@' + self.servers[num + 1].ip, 'source':source, 'user':self.master.rest_username, "ip":'127.0.0.1', "port":57457}
                #self.checkConfig(self.eventID, self.master, expectedResults)
                expectedResults = {
                    "delta_recovery_buckets":
                    "all",
                    'known_nodes': [
                        "ns_1@" + self.servers[num + 1].ip,
                        "ns_1@" + self.master.ip
                    ],
                    'ejected_nodes': ["ns_1@" + self.servers[num + 1].ip],
                    'source':
                    source,
                    'user':
                    self.master.rest_username,
                    "ip":
                    '127.0.0.1',
                    "port":
                    57457,
                    "real_userid:user":
                    self.ldapUser
                }
                self.checkConfig(8200, self.master, expectedResults)

        if (cli_command in ["failover"]):
            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)
                options += " --force"
                output, error = remote_client.execute_couchbase_cli(
                    cli_command=cli_command,
                    options=options,
                    cluster_host="localhost",
                    user=self.ldapUser,
                    password=self.ldapPass)
                expectedResults = {
                    'source': source,
                    "real_userid:user": self.ldapUser,
                    'user': self.master.rest_username,
                    "ip": '127.0.0.1',
                    "port": 57457,
                    'type': 'hard',
                    'node':
                    'ns_1@' + self.servers[nodes_add - nodes_rem - num].ip
                }
                self.checkConfig(self.eventID, self.master, expectedResults)

        if (cli_command == "server-readd"):
            for num in xrange(nodes_readd):
                cli_command = '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)
                options += " --force"
                output, error = remote_client.execute_couchbase_cli(
                    cli_command=cli_command,
                    options=options,
                    cluster_host="localhost",
                    user=self.ldapUser,
                    password=self.ldapPass)
                self.log.info("add back node {0} to cluster".format(
                    self.servers[nodes_add - nodes_rem - num].ip))
                cli_command = "server-readd"
                options = "--server-add={0}:8091 ".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=self.ldapUser,
                    password=self.ldapPass)
                expectedResults = {
                    'node':
                    'ns_1@' + self.servers[nodes_add - nodes_rem - num].ip,
                    'type': 'full',
                    "real_userid:user": self.ldapUser,
                    'source': source,
                    'user': self.master.rest_username,
                    "ip": '127.0.0.1',
                    "port": 57457
                }
                self.checkConfig(self.eventID, self.master, expectedResults)

        remote_client.disconnect()
Beispiel #40
0
    def testAddRemoveNodes(self):
        if self.role in [
                'replication_admin', 'views_admin[*]', 'bucket_admin[*]'
        ]:
            result = "Forbidden"
        elif self.role in ['admin', 'cluster_admin']:
            result = 'SUCCESS'
        nodes_add = self.input.param("nodes_add", 1)
        nodes_rem = self.input.param("nodes_rem", 1)
        nodes_failover = self.input.param("nodes_failover", 0)
        force_failover = self.input.param("force_failover", False)
        nodes_readd = self.input.param("nodes_readd", 0)
        cli_command = self.input.param("cli_command", None)
        source = self.source
        remote_client = RemoteMachineShellConnection(self.master)
        for num in xrange(nodes_add):
            options = "--server-add=http://{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='server-add',
                options=options,
                cluster_host="127.0.0.1:8091",
                user=self.ldapUser,
                password=self.ldapPass)
        output, error = remote_client.execute_couchbase_cli(
            cli_command='rebalance',
            cluster_host="127.0.0.1:8091",
            user=self.ldapUser,
            password=self.ldapPass)
        self._validate_roles(output, result)

        if (cli_command == 'server-remove'):
            for num in xrange(nodes_rem):
                cli_command = "rebalance"
                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="127.0.0.1:8091",
                    user=self.ldapUser,
                    password=self.ldapPass)
            self._validate_roles(output, result)

        if (cli_command in ["failover"]):
            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)
                options += " --force"
                output, error = remote_client.execute_couchbase_cli(
                    cli_command=cli_command,
                    options=options,
                    cluster_host="127.0.0.1:8091",
                    user=self.ldapUser,
                    password=self.ldapPass)
            self._validate_roles(output, result)

        if (cli_command == "server-readd"):
            for num in xrange(nodes_readd):
                cli_command = '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)
                options += " --force"
                output, error = remote_client.execute_couchbase_cli(
                    cli_command=cli_command,
                    options=options,
                    cluster_host="127.0.0.1:8091",
                    user=self.ldapUser,
                    password=self.ldapPass)
                self._validate_roles(output, result)
                self.log.info("add back node {0} to cluster".format(
                    self.servers[nodes_add - nodes_rem - num].ip))
                cli_command = "server-readd"
                options = "--server-add={0}:8091".format(
                    self.servers[nodes_add - nodes_rem - num].ip)
                output, error = remote_client.execute_couchbase_cli(
                    cli_command=cli_command,
                    options=options,
                    cluster_host="127.0.0.1:8091",
                    user=self.ldapUser,
                    password=self.ldapPass)
            self._validate_roles(output, result)
        remote_client.disconnect()