def test_create_bucket_test_load(self): shell = RemoteMachineShellConnection(self.master) self.init_rebalance_cluster_create_testbucket() if self._os == "centos" or self._os == "ubuntu": self.log.info("Load {0} through cbworkloadgen ..".format(self.num_items)) _1 = "cd /home/{0}/opt/couchbase &&".format(self.master.ssh_username) _2 = " ./bin/cbworkloadgen -n localhost:8091" _3 = " -r .8 -i {0} -s 256 -b testbucket -t 1".format(self.num_items) _4 = " -u {0} -p {1}".format(self.master.rest_username, self.master.rest_password) command_to_load = _1 + _2 + _3 + _4 o, e = shell.execute_non_sudo_command(command_to_load) shell.log_command_output(o, e) time.sleep(20) rest = RestConnection(self.master) item_count = rest.fetch_bucket_stats(bucket="testbucket")["op"]["samples"]["curr_items"][-1] if (item_count == self.num_items): self.log.info("Item count matched, {0}={1}".format(item_count, self.num_items)) else: self.fail("Item count: Not what's expected, {0}!={1}".format(item_count, self.num_items)) self.log.info("Deleting testbucket .."); _1 = "cd /home/{0}/opt/couchbase &&".format(self.master.ssh_username) _2 = " ./bin/couchbase-cli bucket-delete -c localhost:8091" _3 = " --bucket=testbucket" _4 = " -u {0} -p {1}".format(self.master.rest_username, self.master.rest_password) command_to_delete_bucket = _1 + _2 + _3 + _4 o, e = shell.execute_non_sudo_command(command_to_delete_bucket) shell.log_command_output(o, e) time.sleep(10) elif self._os == "windows": # TODO: Windows support self.log.info("Yet to add support for windows!") pass
def non_root_install(self): for server in self.servers: shell = RemoteMachineShellConnection(server) info = shell.extract_remote_info() if self._os == "centos": command0 = "rm -rf opt/ etc/ && rm -rf {0}".format(self.build) command1 = "wget http://builds.hq.northscale.net/latestbuilds/{0}".format( self.build) command2 = "rpm2cpio {0} | cpio --extract --make-directories --no-absolute-filenames".format( self.build) command3 = "cd /home/{0}/opt/couchbase && ./bin/install/reloc.sh `pwd`".format( server.ssh_username) command4 = "cd /home/{0}/opt/couchbase && ./bin/couchbase-server -- -noinput -detached".format( server.ssh_username) command5 = "cd /home/{0}/opt/couchbase && ./bin/couchbase-server -k".format( server.ssh_username) o, e = shell.execute_non_sudo_command(command0) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command1) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command2) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command3) shell.log_command_output(o, e) self.log.info( "Starting couchbase server <non-root, non-sudo> ..") o, e = shell.execute_non_sudo_command(command4) shell.log_command_output(o, e) elif self._os == "ubuntu": command0 = "rm -rf opt/ etc/ && rm -rf {0}".format(self.build) command1 = "wget http://builds.hq.northscale.net/latestbuilds/{0}".format( self.build) command2 = "dpkg-deb -x {0} /home/{1}".format( self.build, server.ssh_username) command3 = "cd /home/{0}/opt/couchbase && ./bin/install/reloc.sh `pwd`".format( server.ssh_username) command4 = "cd /home/{0}/opt/couchbase && ./bin/couchbase-server -- -noinput -detached".format( server.ssh_username) command5 = "cd /home/{0}/opt/couchbase && ./bin/couchbase-server -k".format( server.ssh_username) o, e = shell.execute_non_sudo_command(command0) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command1) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command2) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command3) shell.log_command_output(o, e) self.log.info( "Starting couchbase server <non-root, non-sudo> ..") o, e = shell.execute_non_sudo_command(command4) shell.log_command_output(o, e) elif self._os == "windows": self.fail("TODO: Add instructions for windows") else: self.fail( "Enter valid os name, options: centos, ubuntu, windows; entered name: {0} - invalid." .format(self._os))
def non_root_install(self): ssh_client = paramiko.SSHClient() ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) for server in self.servers: shell = RemoteMachineShellConnection(server) info = shell.extract_remote_info() ssh_client.connect(hostname=server.ip,key_filename=server.ssh_key) sftp_client = ssh_client.open_sftp() if self._os == "centos": command0 = "rm -rf opt/ etc/ && rm -rf couchbase-server-enterprise_x86_64_2.2.0-772-rel.rpm" command1 = "wget http://builds.hq.northscale.net/latestbuilds/couchbase-server-enterprise_x86_64_2.2.0-772-rel.rpm" command2 = "rpm2cpio couchbase-server-enterprise_x86_64_2.2.0-772-rel.rpm | cpio --extract --make-directories --no-absolute-filenames" command3 = "cd /home/{0}/opt/couchbase && ./bin/install/reloc.sh `pwd`".format(server.ssh_username) command4 = "cd /home/{0}/opt/couchbase && ./bin/couchbase-server -- -noinput -detached".format(server.ssh_username) command5 = "cd /home/{0}/opt/couchbase && ./bin/couchbase-server -k".format(server.ssh_username) o, e = shell.execute_non_sudo_command(command0) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command1) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command2) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command3) shell.log_command_output(o, e) self.log.info("Starting couchbase server <non-root, non-sudo> ..") o, e = shell.execute_non_sudo_command(command4) shell.log_command_output(o, e) elif self._os == "ubuntu": command0 = "rm -rf opt/ etc/ && rm -rf couchbase-server-enterprise_x86_64_2.2.0-772-rel.deb" command1 = "wget http://builds.hq.northscale.net/latestbuilds/couchbase-server-enterprise_x86_64_2.2.0-772-rel.deb" command2 = "dpkg-deb -x couchbase-server-enterprise_x86_64_2.2.0-772-rel.deb /home/{0}".format(server.ssh_username) command3 = "cd /home/{0}/opt/couchbase && ./bin/install/reloc.sh `pwd`".format(server.ssh_username) command4 = "cd /home/{0}/opt/couchbase && ./bin/couchbase-server -- -noinput -detached".format(server.ssh_username) command5 = "cd /home/{0}/opt/couchbase && ./bin/couchbase-server -k".format(server.ssh_username) o, e = shell.execute_non_sudo_command(command0) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command1) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command2) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command3) shell.log_command_output(o, e) self.log.info("Starting couchbase server <non-root, non-sudo> ..") o, e = shell.execute_non_sudo_command(command4) shell.log_command_output(o, e) self.fail("TODO: Add instructions for ubuntu") elif self._os == "windows": self.fail("TODO: Add instructions for windows") else: self.fail("Enter valid os name, options: centos, ubuntu, windows; entered name: {0} - invalid.".format(self._os)) ssh_client.close()
def setup_xdcr_start_replication(self, src, dest, rep_type, bidirectional): shell1 = RemoteMachineShellConnection(src) shell2 = RemoteMachineShellConnection(dest) if self._os == "centos" or self._os == "ubuntu": self.log.info("Setting up XDCR from source cluster to destination cluster ..") _1 = "cd /home/{0}/opt/couchbase &&".format(src.ssh_username) _2 = " ./bin/couchbase-cli xdcr-setup -c localhost:8091" _3 = " --create --xdcr-cluster-name=_dest --xdcr-hostname={0}:8091".format(dest.ip) _4 = " --xdcr-username={0} --xdcr-password={1}".format(dest.rest_username, dest.rest_password) _5 = " -u {0} -p {1}".format(src.rest_username, src.rest_password) command_to_setup_xdcr = _1 + _2 + _3 + _4 + _5 o, e = shell1.execute_non_sudo_command(command_to_setup_xdcr) shell1.log_command_output(o, e) if bidirectional: self.log.info("Setting up XDCR from destination cluster to source cluster ..") _1 = "cd /home/{0}/opt/couchbase &&".format(dest.ssh_username) _2 = " ./bin/couchbase-cli xdcr-setup -c localhost:8091" _3 = " --create --xdcr-cluster-name=_src --xdcr-hostname={0}:8091".format(src.ip) _4 = " --xdcr-username={0} --xdcr-password={1}".format(src.rest_username, src.rest_password) _5 = " -u {0} -p {1}".format(dest.rest_username, dest.rest_password) command_to_setup_xdcr = _1 + _2 + _3 + _4 + _5 o, e = shell2.execute_non_sudo_command(command_to_setup_xdcr) shell2.log_command_output(o, e) time.sleep(10) self.log.info("Starting replication from source to destination ..") _1 = "cd /home/{0}/opt/couchbase &&".format(src.ssh_username) _2 = " ./bin/couchbase-cli xdcr-replicate -c localhost:8091" _3 = " --create --xdcr-cluster-name=_dest --xdcr-from-bucket=testbucket" _4 = " --xdcr-to-bucket=testbucket --xdcr-replication-mode={0}".format(rep_type) _5 = " -u {0} -p {1}".format(src.rest_username, src.rest_password) command_to_setup_xdcr = _1 + _2 + _3 + _4 + _5 o, e = shell1.execute_non_sudo_command(command_to_setup_xdcr) shell1.log_command_output(o, e) if bidirectional: self.log.info("Starting replication from destination to source ..") _1 = "cd /home/{0}/opt/couchbase &&".format(dest.ssh_username) _2 = " ./bin/couchbase-cli xdcr-replicate -c localhost:8091" _3 = " --create --xdcr-cluster-name=_src --xdcr-from-bucket=testbucket" _4 = " --xdcr-to-bucket=testbucket --xdcr-replication-mode={0}".format(rep_type) _5 = " -u {0} -p {1}".format(dest.rest_username, dest.rest_password) command_to_setup_xdcr = _1 + _2 + _3 + _4 + _5 o, e = shell2.execute_non_sudo_command(command_to_setup_xdcr) shell2.log_command_output(o, e) time.sleep(10) elif self._os == "windows": # TODO: WIndows support pass shell1.disconnect() shell2.disconnect()
def init_rebalance_cluster_create_testbucket(self): shell = RemoteMachineShellConnection(self.master) if self._os == "centos" or self._os == "ubuntu": _1 = "cd /home/{0}/opt/couchbase &&".format( self.master.ssh_username) _2 = " ./bin/couchbase-cli cluster-init -c localhost:8091" _3 = " --cluster-init-username={0} --cluster-init-password={1}".format( self.master.rest_username, self.master.rest_password) _4 = " --cluster-init-port=8091 --cluster-init-ramsize=1000" command_to_init = _1 + _2 + _3 + _4 o, e = shell.execute_non_sudo_command(command_to_init) shell.log_command_output(o, e) time.sleep(10) for i in range(1, len(self.servers)): _1 = "cd /home/{0}/opt/couchbase &&".format( self.master.ssh_username) _2 = " ./bin/couchbase-cli server-add -c {1}:8091".format( self.master.ip) _3 = " --server-add={2}:8091".format(self.servers[i].ip) _4 = " --server-add-username={3}".format( self.servers[i].rest_username) _5 = " --server-add-password={4}".format( self.servers[i].rest_password) _6 = " -u {0} -p {1}".format(self.servers[i].rest_username, self.servers[i].rest_password) command_to_rebalance = _1 + _2 + _3 + _4 + _5 + _6 o, e = shell.execute_non_sudo_command(command_to_rebalance) shell.log_command_output(o, e) time.sleep(10) if len(self.servers) < 2: rep_count = 0 else: rep_count = 1 self.log.info("Cluster set up, now creating a bucket ..") _1 = "cd /home/{0}/opt/couchbase &&".format( self.master.ssh_username) _2 = " ./bin/couchbase-cli bucket-create -c localhost:8091" _3 = " --bucket=testbucket --bucket-type=couchbase --bucket-port=11211" _4 = " --bucket-ramsize=500 --bucket-replica={0} --wait".format( rep_count) _5 = " -u {0} -p {1}".format(self.master.rest_username, self.master.rest_password) command_to_create_bucket = _1 + _2 + _3 + _4 + _5 o, e = shell.execute_non_sudo_command(command_to_create_bucket) shell.log_command_output(o, e) time.sleep(30) elif self._os == "windows": # TODO: Windows support pass
def clean_up(self): self.log.info("Cleaning up nodes, stopping previous couchbase instances if any ..") for server in self.servers: shell = RemoteMachineShellConnection(server) if self._os == "centos" or self._os == "ubuntu": command = "cd /home/{0}/opt/couchbase && ./bin/couchbase-server -k".format(server.ssh_username) o, e = shell.execute_non_sudo_command(command) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command("rm -rf etc/ opt/ couchbase-server-enterprise_x86_64_2.2.0-772-rel.*") shell.log_command_output(o, e) command = "rm -rf backup/" shell.log_command_output(o, e) else: #Handling Windows? pass shell.disconnect()
def tearDown(self): """ Delete the non-root installation """ self.log.info("============== NonRootTests tearDown was started ==============") for server in self.servers: shell = RemoteMachineShellConnection(server) if self._os == "centos" or self._os == "ubuntu": command = "cd /home/{0}/opt/couchbase && ./bin/couchbase-server -k".format(server.ssh_username) o, e = shell.execute_non_sudo_command(command) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command("rm -rf etc/ opt/ couchbase-server-enterprise_x86_64_2.2.0-772-rel.*") shell.log_command_output(o, e) else: #Handling Windows? pass shell.disconnect()
def non_root_install(self): for server in self.servers: shell = RemoteMachineShellConnection(server) info = shell.extract_remote_info() if self._os == "centos": command0 = "rm -rf opt/ etc/ && rm -rf {0}".format(self.build) command1 = "wget http://builds.hq.northscale.net/latestbuilds/{0}".format(self.build) command2 = "rpm2cpio {0} | cpio --extract --make-directories --no-absolute-filenames".format(self.build) command3 = "cd /home/{0}/opt/couchbase && ./bin/install/reloc.sh `pwd`".format(server.ssh_username) command4 = "cd /home/{0}/opt/couchbase && ./bin/couchbase-server -- -noinput -detached".format(server.ssh_username) command5 = "cd /home/{0}/opt/couchbase && ./bin/couchbase-server -k".format(server.ssh_username) o, e = shell.execute_non_sudo_command(command0) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command1) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command2) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command3) shell.log_command_output(o, e) self.log.info("Starting couchbase server <non-root, non-sudo> ..") o, e = shell.execute_non_sudo_command(command4) shell.log_command_output(o, e) elif self._os == "ubuntu": command0 = "rm -rf opt/ etc/ && rm -rf {0}".format(self.build) command1 = "wget http://builds.hq.northscale.net/latestbuilds/{0}".format(self.build) command2 = "dpkg-deb -x {0} /home/{1}".format(self.build, server.ssh_username) command3 = "cd /home/{0}/opt/couchbase && ./bin/install/reloc.sh `pwd`".format(server.ssh_username) command4 = "cd /home/{0}/opt/couchbase && ./bin/couchbase-server -- -noinput -detached".format(server.ssh_username) command5 = "cd /home/{0}/opt/couchbase && ./bin/couchbase-server -k".format(server.ssh_username) o, e = shell.execute_non_sudo_command(command0) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command1) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command2) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command3) shell.log_command_output(o, e) self.log.info("Starting couchbase server <non-root, non-sudo> ..") o, e = shell.execute_non_sudo_command(command4) shell.log_command_output(o, e) elif self._os == "windows": self.fail("TODO: Add instructions for windows") else: self.fail("Enter valid os name, options: centos, ubuntu, windows; entered name: {0} - invalid.".format(self._os))
def test_create_bucket_test_load(self): shell = RemoteMachineShellConnection(self.master) self.init_rebalance_cluster_create_testbucket(self.master, self.servers) if self._os == "centos" or self._os == "ubuntu": self.log.info("Load {0} through cbworkloadgen ..".format( self.num_items)) _1 = "cd /home/{0}/opt/couchbase &&".format( self.master.ssh_username) _2 = " ./bin/cbworkloadgen -n localhost:8091" _3 = " -r .8 -i {0} -s 256 -b testbucket -t 1".format( self.num_items) _4 = " -u {0} -p {1}".format(self.master.rest_username, self.master.rest_password) command_to_load = _1 + _2 + _3 + _4 o, e = shell.execute_non_sudo_command(command_to_load) shell.log_command_output(o, e) time.sleep(20) rest = RestConnection(self.master) item_count = rest.fetch_bucket_stats( bucket="testbucket")["op"]["samples"]["curr_items"][-1] if (item_count == self.num_items): self.log.info("Item count matched, {0}={1}".format( item_count, self.num_items)) else: self.fail("Item count: Not what's expected, {0}!={1}".format( item_count, self.num_items)) self.log.info("Deleting testbucket ..") _1 = "cd /home/{0}/opt/couchbase &&".format( self.master.ssh_username) _2 = " ./bin/couchbase-cli bucket-delete -c localhost:8091" _3 = " --bucket=testbucket" _4 = " -u {0} -p {1}".format(self.master.rest_username, self.master.rest_password) command_to_delete_bucket = _1 + _2 + _3 + _4 o, e = shell.execute_non_sudo_command(command_to_delete_bucket) shell.log_command_output(o, e) time.sleep(10) elif self._os == "windows": # TODO: Windows support self.log.info("Yet to add support for windows!") pass shell.disconnect()
def clean_up(self): self.log.info( "Cleaning up nodes, stopping previous couchbase instances if any .." ) for server in self.servers: shell = RemoteMachineShellConnection(server) if self._os == "centos" or self._os == "ubuntu": command = "cd /home/{0}/opt/couchbase && ./bin/couchbase-server -k".format( server.ssh_username) o, e = shell.execute_non_sudo_command(command) shell.log_command_output(o, e) command = "rm -rf etc/ opt/ usr/ {0}.*".format(self.build[:-4]) o, e = shell.execute_non_sudo_command(command) shell.log_command_output(o, e) command = "rm -rf backup/" shell.log_command_output(o, e) else: #Handling Windows? pass shell.disconnect()
def tearDown(self): """ Delete the non-root installation """ self.log.info( "============== NonRootTests tearDown was started ==============") for server in self.servers: shell = RemoteMachineShellConnection(server) if self._os == "centos" or self._os == "ubuntu": command = "cd /home/{0}/opt/couchbase && ./bin/couchbase-server -k".format( server.ssh_username) o, e = shell.execute_non_sudo_command(command) shell.log_command_output(o, e) command = "rm -rf etc/ opt/ usr/ {0}.*".format(self.build[:-4]) o, e = shell.execute_non_sudo_command(command) shell.log_command_output(o, e) else: #Handling Windows? pass shell.disconnect()
def init_rebalance_cluster_create_testbucket(self, master, servers): shell = RemoteMachineShellConnection(master) if self._os == "centos" or self._os == "ubuntu": _1 = "cd /home/{0}/opt/couchbase &&".format(master.ssh_username) _2 = " ./bin/couchbase-cli cluster-init -c localhost:8091" _3 = " --cluster-init-username={0} --cluster-init-password={1}".format(master.rest_username, master.rest_password) _4 = " --cluster-init-port=8091 --cluster-init-ramsize=1000" command_to_init = _1 + _2 + _3 + _4 o, e = shell.execute_non_sudo_command(command_to_init) shell.log_command_output(o, e) time.sleep(10) for i in range(1, len(servers)): _1 = "cd /home/{0}/opt/couchbase &&".format(master.ssh_username) _2 = " ./bin/couchbase-cli rebalance -c {0}:8091".format(master.ip) _3 = " --server-add={0}:8091".format(servers[i].ip) _4 = " --server-add-username={0}".format(servers[i].rest_username) _5 = " --server-add-password={0}".format(servers[i].rest_password) _6 = " -u {0} -p {1}".format(servers[i].rest_username, servers[i].rest_password) command_to_rebalance = _1 + _2 + _3 + _4 + _5 + _6 o, e = shell.execute_non_sudo_command(command_to_rebalance) shell.log_command_output(o, e) time.sleep(10) if len(servers) < 2: rep_count = 0 else: rep_count = 1 self.log.info("Cluster set up, now creating a bucket ..") _1 = "cd /home/{0}/opt/couchbase &&".format(master.ssh_username) _2 = " ./bin/couchbase-cli bucket-create -c localhost:8091" _3 = " --bucket=testbucket --bucket-type=couchbase --bucket-port=11211" _4 = " --bucket-ramsize=500 --bucket-replica={0} --wait".format(rep_count) _5 = " -u {0} -p {1}".format(master.rest_username, master.rest_password) command_to_create_bucket = _1 + _2 + _3 + _4 + _5 o, e = shell.execute_non_sudo_command(command_to_create_bucket) shell.log_command_output(o, e) time.sleep(30) elif self._os == "windows": # TODO: Windows support pass shell.disconnect()
def restart_es(self): shell = RemoteMachineShellConnection(self.__host) es_restart_cmd = "/etc/init.d/elasticsearch restart" o, e = shell.execute_non_sudo_command(es_restart_cmd) shell.log_command_output(o, e) es_start = False for i in range(2): self.sleep(10) if self.is_running(): es_start = True break if not es_start: self.fail("Could not reach Elastic Search server on %s" % self.ip) else: self.__log.info("Restarted ES server %s successfully" % self.__host.ip)
def check_if_eventing_consumers_are_cleaned_up(self): eventing_nodes = self.cluster_util.get_nodes_from_services_map(service_type="eventing", get_all_nodes=True) array_of_counts = [] command = "ps -ef | grep eventing-consumer | grep -v grep | wc -l" for eventing_node in eventing_nodes: shell = RemoteMachineShellConnection(eventing_node) count, error = shell.execute_non_sudo_command(command) if isinstance(count, list): count = int(count[0]) else: count = int(count) self.log.info("Node : {0} , eventing_consumer processes running : {1}".format(eventing_node.ip, count)) array_of_counts.append(count) count_of_all_eventing_consumers = sum(array_of_counts) if count_of_all_eventing_consumers != 0: return False return True
def non_root_install(self): ssh_client = paramiko.SSHClient() ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) for server in self.servers: shell = RemoteMachineShellConnection(server) info = shell.extract_remote_info() ssh_client.connect(hostname=server.ip, key_filename=server.ssh_key) sftp_client = ssh_client.open_sftp() if self._os == "centos": command0 = "rm -rf opt/ etc/ && rm -rf couchbase-server-enterprise_x86_64_2.2.0-772-rel.rpm" command1 = "wget http://builds.hq.northscale.net/latestbuilds/couchbase-server-enterprise_x86_64_2.2.0-772-rel.rpm" command2 = "rpm2cpio couchbase-server-enterprise_x86_64_2.2.0-772-rel.rpm | cpio --extract --make-directories --no-absolute-filenames" command3 = "cd /home/{0}/opt/couchbase && ./bin/install/reloc.sh `pwd`".format( server.ssh_username) command4 = "cd /home/{0}/opt/couchbase && ./bin/couchbase-server -- -noinput -detached".format( server.ssh_username) command5 = "cd /home/{0}/opt/couchbase && ./bin/couchbase-server -k".format( server.ssh_username) o, e = shell.execute_non_sudo_command(command0) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command1) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command2) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command3) shell.log_command_output(o, e) self.log.info( "Starting couchbase server <non-root, non-sudo> ..") o, e = shell.execute_non_sudo_command(command4) shell.log_command_output(o, e) elif self._os == "ubuntu": command0 = "rm -rf opt/ etc/ && rm -rf couchbase-server-enterprise_x86_64_2.2.0-772-rel.deb" command1 = "wget http://builds.hq.northscale.net/latestbuilds/couchbase-server-enterprise_x86_64_2.2.0-772-rel.deb" command2 = "dpkg-deb -x couchbase-server-enterprise_x86_64_2.2.0-772-rel.deb /home/{0}".format( server.ssh_username) command3 = "cd /home/{0}/opt/couchbase && ./bin/install/reloc.sh `pwd`".format( server.ssh_username) command4 = "cd /home/{0}/opt/couchbase && ./bin/couchbase-server -- -noinput -detached".format( server.ssh_username) command5 = "cd /home/{0}/opt/couchbase && ./bin/couchbase-server -k".format( server.ssh_username) o, e = shell.execute_non_sudo_command(command0) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command1) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command2) shell.log_command_output(o, e) o, e = shell.execute_non_sudo_command(command3) shell.log_command_output(o, e) self.log.info( "Starting couchbase server <non-root, non-sudo> ..") o, e = shell.execute_non_sudo_command(command4) shell.log_command_output(o, e) self.fail("TODO: Add instructions for ubuntu") elif self._os == "windows": self.fail("TODO: Add instructions for windows") else: self.fail( "Enter valid os name, options: centos, ubuntu, windows; entered name: {0} - invalid." .format(self._os)) ssh_client.close()
def test_bucket_backup_restore(self): shell = RemoteMachineShellConnection(self.master) self.init_rebalance_cluster_create_testbucket() if self._os == "centos" or self._os == "ubuntu": self.log.info("Load {0} through cbworkloadgen ..".format( self.num_items)) _1 = "cd /home/{0}/opt/couchbase &&".format( self.master.ssh_username) _2 = " ./bin/cbworkloadgen -n localhost:8091" _3 = " -r .8 -i {0} -s 256 -b testbucket -t 1".format( self.num_items) _4 = " -u {0} -p {1}".format(self.master.rest_username, self.master.rest_password) command_to_load = _1 + _2 + _3 + _4 o, e = shell.execute_non_sudo_command(command_to_load) shell.log_command_output(o, e) time.sleep(20) rest = RestConnection(self.master) ini_item_count = rest.fetch_bucket_stats( bucket="testbucket")["op"]["samples"]["curr_items"][-1] self.log.info("Backing up bucket 'testbucket' ..") _1 = "cd /home/{0}/opt/couchbase &&".format( self.master.ssh_username) _2 = " ./bin/cbbackup http://localhost:8091" _3 = " /home/{0}/backup".format(self.master.ssh_username) _4 = " -u {0} -p {1}".format(self.master.rest_username, self.master.rest_password) command_to_backup = _1 + _2 + _3 + _4 o, e = shell.execute_non_sudo_command(command_to_backup) shell.log_command_output(o, e) time.sleep(10) self.log.info("Deleting bucket ..") _1 = "cd /home/{0}/opt/couchbase &&".format( self.master.ssh_username) _2 = " ./bin/couchbase-cli bucket-delete -c localhost:8091" _3 = " --bucket=testbucket" _4 = " -u {0} -p {1}".format(self.master.rest_username, self.master.rest_password) command_to_delete_bucket = _1 + _2 + _3 + _4 o, e = shell.execute_non_sudo_command(command_to_delete_bucket) shell.log_command_output(o, e) time.sleep(20) if len(self.servers) < 2: rep_count = 0 else: rep_count = 1 self.log.info("Recreating bucket ..") _1 = "cd /home/{0}/opt/couchbase &&".format( self.master.ssh_username) _2 = " ./bin/couchbase-cli bucket-create -c localhost:8091" _3 = " --bucket=testbucket --bucket-type=couchbase --bucket-port=11211" _4 = " --bucket-ramsize=500 --bucket-replica={0} --wait".format( rep_count) _5 = " -u {0} -p {1}".format(self.master.rest_username, self.master.rest_password) command_to_create_bucket = _1 + _2 + _3 + _4 + _5 o, e = shell.execute_non_sudo_command(command_to_create_bucket) shell.log_command_output(o, e) time.sleep(20) self.log.info("Restoring bucket 'testbucket' ..") _1 = "cd /home/{0}/opt/couchbase &&".format( self.master.ssh_username) _2 = " ./bin/cbrestore /home/{0}/backup http://localhost:8091".format( self.master.ssh_username) _3 = " -b testbucket -B testbucket" _4 = " -u {0} -p {1}".format(self.master.rest_username, self.master.rest_password) command_to_restore = _1 + _2 + _3 + _4 o, e = shell.execute_non_sudo_command(command_to_restore) shell.log_command_output(o, e) time.sleep(10) rest = RestConnection(self.master) fin_item_count = rest.fetch_bucket_stats( bucket="testbucket")["op"]["samples"]["curr_items"][-1] self.log.info("Removing backed-up folder ..") command_to_remove_folder = "rm -rf /home/{0}/backup".format( self.master.ssh_username) o, e = shell.execute_non_sudo_command(command_to_remove_folder) shell.log_command_output(o, e) if (fin_item_count == ini_item_count): self.log.info( "Item count before and after deleting with backup/restore matched, {0}={1}" .format(fin_item_count, ini_item_count)) else: self.fail( "Item count didnt match - backup/restore, {0}!={1}".format( fin_item_count, ini_item_count)) self.log.info("Deleting testbucket ..") _1 = "cd /home/{0}/opt/couchbase &&".format( self.master.ssh_username) _2 = " ./bin/couchbase-cli bucket-delete -c localhost:8091" _3 = " --bucket=testbucket" _4 = " -u {0} -p {1}".format(self.master.rest_username, self.master.rest_password) command_to_delete_bucket = _1 + _2 + _3 + _4 o, e = shell.execute_non_sudo_command(command_to_delete_bucket) shell.log_command_output(o, e) time.sleep(10) elif self._os == "windows": # TODO: Windows support self.log.info("Yet to add support for windows!") pass
def test_xdcr(self): _rep_type = self.input.param("replication_type", "capi") # capi or xmem _bixdcr = self.input.param("bidirectional", "false") _clusters_dic = self.input.clusters _src_nodes = copy.copy(_clusters_dic[0]) _src_master = _src_nodes[0] _dest_nodes = copy.copy(_clusters_dic[1]) _dest_master = _dest_nodes[0] # Build source cluster self.init_rebalance_cluster_create_testbucket(_src_master, _src_nodes) # Build destination cluster self.init_rebalance_cluster_create_testbucket(_dest_master, _dest_nodes) # Setting up XDCR self.setup_xdcr_start_replication(_src_master, _dest_master, _rep_type, _bixdcr) shell1 = RemoteMachineShellConnection(_src_master) shell2 = RemoteMachineShellConnection(_dest_master) src_item_count = 0 dest_item_count = 0 if self._os == "centos" or self._os == "ubuntu": self.log.info("Load {0} through cbworkloadgen at src..".format(self.num_items)) _1 = "cd /home/{0}/opt/couchbase &&".format(_src_master.ssh_username) _2 = " ./bin/cbworkloadgen -n localhost:8091 --prefix=s_" _3 = " -r .8 -i {0} -s 256 -b testbucket -t 1".format(self.num_items) _4 = " -u {0} -p {1}".format(_src_master.rest_username, _src_master.rest_password) command_to_load = _1 + _2 + _3 + _4 o, e = shell1.execute_non_sudo_command(command_to_load) shell1.log_command_output(o, e) time.sleep(20) rest = RestConnection(_src_master) src_item_count = rest.fetch_bucket_stats(bucket="testbucket")["op"]["samples"]["curr_items"][-1] if _bixdcr: self.log.info("Load {0} through cbworkloadgen at src..".format(self.num_items)) _1 = "cd /home/{0}/opt/couchbase &&".format(_dest_master.ssh_username) _2 = " ./bin/cbworkloadgen -n localhost:8091 --prefix=d_" _3 = " -r .8 -i {0} -s 256 -b testbucket -t 1".format(self.num_items) _4 = " -u {0} -p {1}".format(_dest_master.rest_username, _dest_master.rest_password) command_to_load = _1 + _2 + _3 + _4 o, e = shell2.execute_non_sudo_command(command_to_load) shell2.log_command_output(o, e) time.sleep(20) rest = RestConnection(_dest_master) dest_item_count = rest.fetch_bucket_stats(bucket="testbucket")["op"]["samples"]["curr_items"][-1] self.wait_for_replication_to_catchup(_src_master, _dest_master, 1200, "destination") if _bixdcr: self.wait_for_replication_to_catchup(_dest_master, _src_master, 1200, "source") self.log.info("XDC REPLICATION caught up") rest1 = RestConnection(_src_master) rest2 = RestConnection(_dest_master) curr_count_on_src = rest1.fetch_bucket_stats(bucket="testbucket")["op"]["samples"]["curr_items"][-1] curr_count_on_dest = rest2.fetch_bucket_stats(bucket="testbucket")["op"]["samples"]["curr_items"][-1] assert(curr_count_on_src==(src_item_count + dest_item_count), "ItemCount on source not what's expected") assert(curr_count_on_dest==(src_item_count + dest_item_count), "ItemCount on destination not what's expected") elif self._os == "windows": # TODO: Windows support self.log.info("Yet to add support for windows!") pass shell1.disconnect() shell2.disconnect()
def test_bucket_backup_restore(self): shell = RemoteMachineShellConnection(self.master) self.init_rebalance_cluster_create_testbucket() if self._os == "centos" or self._os == "ubuntu": self.log.info("Load {0} through cbworkloadgen ..".format(self.num_items)) _1 = "cd /home/{0}/opt/couchbase &&".format(self.master.ssh_username) _2 = " ./bin/cbworkloadgen -n localhost:8091" _3 = " -r .8 -i {0} -s 256 -b testbucket -t 1".format(self.num_items) _4 = " -u {0} -p {1}".format(self.master.rest_username, self.master.rest_password) command_to_load = _1 + _2 + _3 + _4 o, e = shell.execute_non_sudo_command(command_to_load) shell.log_command_output(o, e) time.sleep(20) rest = RestConnection(self.master) ini_item_count = rest.fetch_bucket_stats(bucket="testbucket")["op"]["samples"]["curr_items"][-1] self.log.info("Backing up bucket 'testbucket' ..") _1 = "cd /home/{0}/opt/couchbase &&".format(self.master.ssh_username) _2 = " ./bin/cbbackup http://localhost:8091" _3 = " /home/{0}/backup".format(self.master.ssh_username) _4 = " -u {0} -p {1}".format(self.master.rest_username, self.master.rest_password) command_to_backup = _1 + _2 + _3 + _4 o, e = shell.execute_non_sudo_command(command_to_backup) shell.log_command_output(o, e) time.sleep(10) self.log.info("Deleting bucket ..") _1 = "cd /home/{0}/opt/couchbase &&".format(self.master.ssh_username) _2 = " ./bin/couchbase-cli bucket-delete -c localhost:8091" _3 = " --bucket=testbucket" _4 = " -u {0} -p {1}".format(self.master.rest_username, self.master.rest_password) command_to_delete_bucket = _1 + _2 + _3 + _4 o, e = shell.execute_non_sudo_command(command_to_delete_bucket) shell.log_command_output(o, e) time.sleep(20) if len(self.servers) < 2: rep_count = 0 else: rep_count = 1 self.log.info("Recreating bucket ..") _1 = "cd /home/{0}/opt/couchbase &&".format(self.master.ssh_username) _2 = " ./bin/couchbase-cli bucket-create -c localhost:8091" _3 = " --bucket=testbucket --bucket-type=couchbase --bucket-port=11211" _4 = " --bucket-ramsize=500 --bucket-replica={0} --wait".format(rep_count) _5 = " -u {0} -p {1}".format(self.master.rest_username, self.master.rest_password) command_to_create_bucket = _1 + _2 + _3 + _4 + _5 o, e = shell.execute_non_sudo_command(command_to_create_bucket) shell.log_command_output(o, e) time.sleep(20) self.log.info("Restoring bucket 'testbucket' ..") _1 = "cd /home/{0}/opt/couchbase &&".format(self.master.ssh_username) _2 = " ./bin/cbrestore /home/{0}/backup http://localhost:8091".format(self.master.ssh_username) _3 = " -b testbucket -B testbucket" _4 = " -u {0} -p {1}".format(self.master.rest_username, self.master.rest_password) command_to_restore = _1 + _2 + _3 + _4 o, e = shell.execute_non_sudo_command(command_to_restore) shell.log_command_output(o, e) time.sleep(10) rest = RestConnection(self.master) fin_item_count = rest.fetch_bucket_stats(bucket="testbucket")["op"]["samples"]["curr_items"][-1] self.log.info("Removing backed-up folder ..") command_to_remove_folder = "rm -rf /home/{0}/backup".format(self.master.ssh_username) o, e = shell.execute_non_sudo_command(command_to_remove_folder) shell.log_command_output(o, e) if (fin_item_count == ini_item_count): self.log.info("Item count before and after deleting with backup/restore matched, {0}={1}".format( fin_item_count, ini_item_count)) else: self.fail("Item count didnt match - backup/restore, {0}!={1}".format(fin_item_count, ini_item_count)) self.log.info("Deleting testbucket .."); _1 = "cd /home/{0}/opt/couchbase &&".format(self.master.ssh_username) _2 = " ./bin/couchbase-cli bucket-delete -c localhost:8091" _3 = " --bucket=testbucket" _4 = " -u {0} -p {1}".format(self.master.rest_username, self.master.rest_password) command_to_delete_bucket = _1 + _2 + _3 + _4 o, e = shell.execute_non_sudo_command(command_to_delete_bucket) shell.log_command_output(o, e) time.sleep(10) elif self._os == "windows": # TODO: Windows support self.log.info("Yet to add support for windows!") pass
def test_xdcr(self): _rep_type = self.input.param("replication_type", "capi") # capi or xmem _bixdcr = self.input.param("bidirectional", "false") _clusters_dic = self.input.clusters _src_nodes = copy.copy(_clusters_dic[0]) _src_master = _src_nodes[0] _dest_nodes = copy.copy(_clusters_dic[1]) _dest_master = _dest_nodes[0] # Build source cluster self.init_rebalance_cluster_create_testbucket(_src_master, _src_nodes) # Build destination cluster self.init_rebalance_cluster_create_testbucket(_dest_master, _dest_nodes) # Setting up XDCR self.setup_xdcr_start_replication(_src_master, _dest_master, _rep_type, _bixdcr) shell1 = RemoteMachineShellConnection(_src_master) shell2 = RemoteMachineShellConnection(_dest_master) src_item_count = 0 dest_item_count = 0 if self._os == "centos" or self._os == "ubuntu": self.log.info("Load {0} through cbworkloadgen at src..".format( self.num_items)) _1 = "cd /home/{0}/opt/couchbase &&".format( _src_master.ssh_username) _2 = " ./bin/cbworkloadgen -n localhost:8091 --prefix=s_" _3 = " -r .8 -i {0} -s 256 -b testbucket -t 1".format( self.num_items) _4 = " -u {0} -p {1}".format(_src_master.rest_username, _src_master.rest_password) command_to_load = _1 + _2 + _3 + _4 o, e = shell1.execute_non_sudo_command(command_to_load) shell1.log_command_output(o, e) time.sleep(20) rest = RestConnection(_src_master) src_item_count = rest.fetch_bucket_stats( bucket="testbucket")["op"]["samples"]["curr_items"][-1] if _bixdcr: self.log.info("Load {0} through cbworkloadgen at src..".format( self.num_items)) _1 = "cd /home/{0}/opt/couchbase &&".format( _dest_master.ssh_username) _2 = " ./bin/cbworkloadgen -n localhost:8091 --prefix=d_" _3 = " -r .8 -i {0} -s 256 -b testbucket -t 1".format( self.num_items) _4 = " -u {0} -p {1}".format(_dest_master.rest_username, _dest_master.rest_password) command_to_load = _1 + _2 + _3 + _4 o, e = shell2.execute_non_sudo_command(command_to_load) shell2.log_command_output(o, e) time.sleep(20) rest = RestConnection(_dest_master) dest_item_count = rest.fetch_bucket_stats( bucket="testbucket")["op"]["samples"]["curr_items"][-1] self.wait_for_replication_to_catchup(_src_master, _dest_master, 1200, "destination") if _bixdcr: self.wait_for_replication_to_catchup(_dest_master, _src_master, 1200, "source") self.log.info("XDC REPLICATION caught up") rest1 = RestConnection(_src_master) rest2 = RestConnection(_dest_master) curr_count_on_src = rest1.fetch_bucket_stats( bucket="testbucket")["op"]["samples"]["curr_items"][-1] curr_count_on_dest = rest2.fetch_bucket_stats( bucket="testbucket")["op"]["samples"]["curr_items"][-1] assert (curr_count_on_src == (src_item_count + dest_item_count), "ItemCount on source not what's expected") assert (curr_count_on_dest == (src_item_count + dest_item_count), "ItemCount on destination not what's expected") elif self._os == "windows": # TODO: Windows support self.log.info("Yet to add support for windows!") pass shell1.disconnect() shell2.disconnect()
def setup_xdcr_start_replication(self, src, dest, rep_type, bidirectional): shell1 = RemoteMachineShellConnection(src) shell2 = RemoteMachineShellConnection(dest) if self._os == "centos" or self._os == "ubuntu": self.log.info( "Setting up XDCR from source cluster to destination cluster .." ) _1 = "cd /home/{0}/opt/couchbase &&".format(src.ssh_username) _2 = " ./bin/couchbase-cli xdcr-setup -c localhost:8091" _3 = " --create --xdcr-cluster-name=_dest --xdcr-hostname={0}:8091".format( dest.ip) _4 = " --xdcr-username={0} --xdcr-password={1}".format( dest.rest_username, dest.rest_password) _5 = " -u {0} -p {1}".format(src.rest_username, src.rest_password) command_to_setup_xdcr = _1 + _2 + _3 + _4 + _5 o, e = shell1.execute_non_sudo_command(command_to_setup_xdcr) shell1.log_command_output(o, e) if bidirectional: self.log.info( "Setting up XDCR from destination cluster to source cluster .." ) _1 = "cd /home/{0}/opt/couchbase &&".format(dest.ssh_username) _2 = " ./bin/couchbase-cli xdcr-setup -c localhost:8091" _3 = " --create --xdcr-cluster-name=_src --xdcr-hostname={0}:8091".format( src.ip) _4 = " --xdcr-username={0} --xdcr-password={1}".format( src.rest_username, src.rest_password) _5 = " -u {0} -p {1}".format(dest.rest_username, dest.rest_password) command_to_setup_xdcr = _1 + _2 + _3 + _4 + _5 o, e = shell2.execute_non_sudo_command(command_to_setup_xdcr) shell2.log_command_output(o, e) time.sleep(10) self.log.info("Starting replication from source to destination ..") _1 = "cd /home/{0}/opt/couchbase &&".format(src.ssh_username) _2 = " ./bin/couchbase-cli xdcr-replicate -c localhost:8091" _3 = " --create --xdcr-cluster-name=_dest --xdcr-from-bucket=testbucket" _4 = " --xdcr-to-bucket=testbucket --xdcr-replication-mode={0}".format( rep_type) _5 = " -u {0} -p {1}".format(src.rest_username, src.rest_password) command_to_setup_xdcr = _1 + _2 + _3 + _4 + _5 o, e = shell1.execute_non_sudo_command(command_to_setup_xdcr) shell1.log_command_output(o, e) if bidirectional: self.log.info( "Starting replication from destination to source ..") _1 = "cd /home/{0}/opt/couchbase &&".format(dest.ssh_username) _2 = " ./bin/couchbase-cli xdcr-replicate -c localhost:8091" _3 = " --create --xdcr-cluster-name=_src --xdcr-from-bucket=testbucket" _4 = " --xdcr-to-bucket=testbucket --xdcr-replication-mode={0}".format( rep_type) _5 = " -u {0} -p {1}".format(dest.rest_username, dest.rest_password) command_to_setup_xdcr = _1 + _2 + _3 + _4 + _5 o, e = shell2.execute_non_sudo_command(command_to_setup_xdcr) shell2.log_command_output(o, e) time.sleep(10) elif self._os == "windows": # TODO: WIndows support pass shell1.disconnect() shell2.disconnect()