def test_disable_cbs_ssl_in_cluster_config(): persist_cluster_config_environment_prop(MOCK_CLUSTER_CONFIG, 'cbs_ssl_enabled', False) c = Cluster(MOCK_CLUSTER_CONFIG) assert not c.cbs_ssl with open(MOCK_CLUSTER_CONFIG + ".json") as f: cluster_json = json.loads(f.read()) assert "environment" in cluster_json assert not cluster_json["environment"]["cbs_ssl_enabled"] config = ConfigParser.ConfigParser() config.read(MOCK_CLUSTER_CONFIG) assert config.has_section("environment") assert not config.getboolean('environment', 'cbs_ssl_enabled')
def test_invalid_revs_limit_with_allow_conflicts(params_from_base_test_setup, sg_conf_name, revs_limit): """ @summary Verify all borders of revs limit Test case in Excel sheet : https://docs.google.com/spreadsheets/d/1YwI_gCeoBebQKBybkzoAEoXSc0XLReszDA-mPFQapgk/edit#gid=0 Covered Test case #2 Steps: - Add a doc - Have allow_conflicts to true in sg config - Put revs_limit=1 or any number lower than 20 and restart sync-gateway - Verify it fails - change revs_limit=20 and start sync-gateway - Verify it starts without any error """ cluster_config = params_from_base_test_setup["cluster_config"] mode = params_from_base_test_setup["mode"] no_conflicts_enabled = params_from_base_test_setup["no_conflicts_enabled"] if no_conflicts_enabled: pytest.skip( '--no-conflicts is enabled, this test needs to create conflicts, so skipping the test' ) sg_conf = sync_gateway_config_path_for_mode(sg_conf_name, mode) clust = cluster.Cluster(cluster_config) clust.reset(sg_conf) temp_cluster_config = copy_to_temp_conf(cluster_config, mode) persist_cluster_config_environment_prop(temp_cluster_config, 'revs_limit', revs_limit, property_name_check=False) status = clust.sync_gateways[0].restart(config=sg_conf, cluster_config=temp_cluster_config) assert status != 0, "Syncgateway started with revs limit 1 when no conflicts disabled" # Now change the revs_limit to 20 revs_limit = 20 persist_cluster_config_environment_prop(temp_cluster_config, 'revs_limit', revs_limit, property_name_check=False) status = clust.sync_gateways[0].restart(config=sg_conf, cluster_config=temp_cluster_config) assert status == 0, "Syncgateway did not start after revs_limit changed to 20"
def params_from_base_suite_setup(request): log_info("Setting up 'params_from_base_suite_setup' ...") # pytest command line parameters server_version = request.config.getoption("--server-version") sync_gateway_version = request.config.getoption("--sync-gateway-version") mode = request.config.getoption("--mode") skip_provisioning = request.config.getoption("--skip-provisioning") race_enabled = request.config.getoption("--race") cbs_ssl = request.config.getoption("--server-ssl") xattrs_enabled = request.config.getoption("--xattrs") sg_lb = request.config.getoption("--sg-lb") sg_ce = request.config.getoption("--sg-ce") use_sequoia = request.config.getoption("--sequoia") no_conflicts_enabled = request.config.getoption("--no-conflicts") if xattrs_enabled and version_is_binary(sync_gateway_version): check_xattr_support(server_version, sync_gateway_version) log_info("server_version: {}".format(server_version)) log_info("sync_gateway_version: {}".format(sync_gateway_version)) log_info("mode: {}".format(mode)) log_info("skip_provisioning: {}".format(skip_provisioning)) log_info("race_enabled: {}".format(race_enabled)) log_info("cbs_ssl: {}".format(cbs_ssl)) log_info("xattrs_enabled: {}".format(xattrs_enabled)) log_info("sg_lb: {}".format(sg_lb)) log_info("sg_ce: {}".format(sg_ce)) log_info("no conflicts enabled {}".format(no_conflicts_enabled)) # sg-ce is invalid for di mode if mode == "di" and sg_ce: raise FeatureSupportedError( "SGAccel is only available as an enterprise edition") if no_conflicts_enabled and sync_gateway_version < "2.0": raise FeatureSupportedError( 'No conflicts feature not available for sync-gateway version below 2.0, so skipping the test' ) # Make sure mode for sync_gateway is supported ('cc' or 'di') validate_sync_gateway_mode(mode) # use load_balancer_cc cluster config if mode is "cc" or load_balancer_di cluster config if mode is "di" cluster_config = "{}/load_balancer_{}".format( keywords.constants.CLUSTER_CONFIGS_DIR, mode) sg_config = sync_gateway_config_path_for_mode( "sync_gateway_default_functional_tests", mode) # Add load balancer prop and check if load balancer IP is available if sg_lb: persist_cluster_config_environment_prop(cluster_config, 'sg_lb_enabled', True) log_info("Running tests with load balancer enabled: {}".format( get_load_balancer_ip(cluster_config))) else: log_info("Running tests with load balancer disabled") persist_cluster_config_environment_prop(cluster_config, 'sg_lb_enabled', False) if cbs_ssl: log_info("Running tests with cbs <-> sg ssl enabled") # Enable ssl in cluster configs persist_cluster_config_environment_prop(cluster_config, 'cbs_ssl_enabled', True) else: log_info("Running tests with cbs <-> sg ssl disabled") # Disable ssl in cluster configs persist_cluster_config_environment_prop(cluster_config, 'cbs_ssl_enabled', False) if xattrs_enabled: log_info("Running test with xattrs for sync meta storage") persist_cluster_config_environment_prop(cluster_config, 'xattrs_enabled', True) else: log_info("Using document storage for sync meta data") persist_cluster_config_environment_prop(cluster_config, 'xattrs_enabled', False) try: server_version except NameError: log_info("Server version is not provided") persist_cluster_config_environment_prop(cluster_config, 'server_version', "") else: log_info("Running test with server version {}".format(server_version)) persist_cluster_config_environment_prop(cluster_config, 'server_version', server_version) try: sync_gateway_version except NameError: log_info("Sync gateway version is not provided") persist_cluster_config_environment_prop(cluster_config, 'sync_gateway_version', "") else: log_info("Running test with sync_gateway version {}".format( sync_gateway_version)) persist_cluster_config_environment_prop(cluster_config, 'sync_gateway_version', sync_gateway_version) if no_conflicts_enabled: log_info("Running with no conflicts") persist_cluster_config_environment_prop(cluster_config, 'no_conflicts_enabled', True) else: log_info("Running with allow conflicts") persist_cluster_config_environment_prop(cluster_config, 'no_conflicts_enabled', False) if sync_gateway_version < "2.0.0" and no_conflicts_enabled: pytest.skip( "Test cannot run with no-conflicts with sg version < 2.0.0") # Skip provisioning if user specifies '--skip-provisoning' or '--sequoia' should_provision = True if skip_provisioning or use_sequoia: should_provision = False cluster_utils = ClusterKeywords() if should_provision: try: cluster_utils.provision_cluster( cluster_config=cluster_config, server_version=server_version, sync_gateway_version=sync_gateway_version, sync_gateway_config=sg_config, race_enabled=race_enabled, sg_ce=sg_ce) except ProvisioningError: logging_helper = Logging() logging_helper.fetch_and_analyze_logs( cluster_config=cluster_config, test_name=request.node.name) raise # Hit this intalled running services to verify the correct versions are installed cluster_utils.verify_cluster_versions( cluster_config, expected_server_version=server_version, expected_sync_gateway_version=sync_gateway_version) yield {"cluster_config": cluster_config, "mode": mode} log_info("Tearing down 'params_from_base_suite_setup' ...") # Stop all sync_gateway and sg_accels as test finished c = cluster.Cluster(cluster_config) c.stop_sg_and_accel()
def setup_client_syncgateway_suite(request): """Suite setup fixture for client sync_gateway tests""" log_info("Setting up client sync_gateway suite ...") liteserv_platform = request.config.getoption("--liteserv-platform") liteserv_version = request.config.getoption("--liteserv-version") liteserv_host = request.config.getoption("--liteserv-host") liteserv_port = request.config.getoption("--liteserv-port") liteserv_storage_engine = request.config.getoption("--liteserv-storage-engine") skip_provisioning = request.config.getoption("--skip-provisioning") sync_gateway_version = request.config.getoption("--sync-gateway-version") sync_gateway_mode = request.config.getoption("--sync-gateway-mode") server_version = request.config.getoption("--server-version") xattrs_enabled = request.config.getoption("--xattrs") device_enabled = request.config.getoption("--device") liteserv = LiteServFactory.create(platform=liteserv_platform, version_build=liteserv_version, host=liteserv_host, port=liteserv_port, storage_engine=liteserv_storage_engine) if xattrs_enabled and version_is_binary(sync_gateway_version): check_xattr_support(server_version, sync_gateway_version) log_info("Downloading LiteServ ...") # Download LiteServ liteserv.download() # Install LiteServ if device_enabled and liteserv_platform == "ios": liteserv.install_device() else: liteserv.install() cluster_config = "{}/base_{}".format(CLUSTER_CONFIGS_DIR, sync_gateway_mode) try: server_version except NameError: log_info("Server version is not provided") persist_cluster_config_environment_prop(cluster_config, 'server_version', "") else: log_info("Running test with server version {}".format(server_version)) persist_cluster_config_environment_prop(cluster_config, 'server_version', server_version) try: sync_gateway_version except NameError: log_info("Sync gateway version is not provided") persist_cluster_config_environment_prop(cluster_config, 'sync_gateway_version', "") else: log_info("Running test with sync_gateway version {}".format(sync_gateway_version)) persist_cluster_config_environment_prop(cluster_config, 'sync_gateway_version', sync_gateway_version) if xattrs_enabled: log_info("Running test with xattrs for sync meta storage") persist_cluster_config_environment_prop(cluster_config, 'xattrs_enabled', True) else: log_info("Using document storage for sync meta data") persist_cluster_config_environment_prop(cluster_config, 'xattrs_enabled', False) sg_config = sync_gateway_config_path_for_mode("listener_tests/listener_tests", sync_gateway_mode) if not skip_provisioning: log_info("Installing Sync Gateway + Couchbase Server + Accels ('di' only)") cluster_utils = ClusterKeywords() cluster_utils.provision_cluster( cluster_config=cluster_config, server_version=server_version, sync_gateway_version=sync_gateway_version, sync_gateway_config=sg_config ) # Wait at the yeild until tests referencing this suite setup have run, # Then execute the teardown yield { "liteserv": liteserv, "cluster_config": cluster_config, "sg_mode": sync_gateway_mode, "xattrs_enabled": xattrs_enabled, "device_enabled": device_enabled, "liteserv_platform": liteserv_platform, "liteserv_version": liteserv_version } log_info("Tearing down suite ...") if not (device_enabled and liteserv_platform == "ios"): liteserv.remove()
def test_enable_disable_xattrs(): with open(MOCK_CLUSTER_CONFIG + ".json") as f: cluster_json = json.loads(f.read()) config = ConfigParser.ConfigParser() config.read(MOCK_CLUSTER_CONFIG) c = Cluster(MOCK_CLUSTER_CONFIG) assert not c.xattrs assert "environment" in cluster_json assert not cluster_json["environment"]["xattrs_enabled"] assert config.has_section("environment") assert not config.getboolean("environment", "xattrs_enabled") assert not is_xattrs_enabled(MOCK_CLUSTER_CONFIG) # Enable XATTRs persist_cluster_config_environment_prop(MOCK_CLUSTER_CONFIG, "xattrs_enabled", True) c = Cluster(MOCK_CLUSTER_CONFIG) assert c.xattrs # Reload cluster config and ma with open(MOCK_CLUSTER_CONFIG + ".json") as f: cluster_json = json.loads(f.read()) config = ConfigParser.ConfigParser() config.read(MOCK_CLUSTER_CONFIG) # Make sure xattrs are enabled assert "environment" in cluster_json assert cluster_json["environment"]["xattrs_enabled"] assert config.has_section("environment") assert config.getboolean("environment", "xattrs_enabled") assert is_xattrs_enabled(MOCK_CLUSTER_CONFIG) # Disable XATTRs persist_cluster_config_environment_prop(MOCK_CLUSTER_CONFIG, "xattrs_enabled", False) c = Cluster(MOCK_CLUSTER_CONFIG) assert not c.xattrs # Reload cluster config and ma with open(MOCK_CLUSTER_CONFIG + ".json") as f: cluster_json = json.loads(f.read()) config = ConfigParser.ConfigParser() config.read(MOCK_CLUSTER_CONFIG) # Make sure xattrs are disabled assert "environment" in cluster_json assert not cluster_json["environment"]["xattrs_enabled"] assert config.has_section("environment") assert not config.getboolean("environment", "xattrs_enabled") assert not is_xattrs_enabled(MOCK_CLUSTER_CONFIG)
def provision_cluster(cluster_config, couchbase_server_config, sync_gateway_config, sg_ce=False, cbs_platform="centos7", sg_platform="centos", sa_platform="centos"): log_info("\n>>> Cluster info:\n") server_version = "{}-{}".format(couchbase_server_config.version, couchbase_server_config.build) sg_version = "{}-{}".format(sync_gateway_config._version_number, sync_gateway_config._build_number) try: server_version except NameError: log_info("Server version is not provided") persist_cluster_config_environment_prop(cluster_config, 'server_version', "") else: log_info("Running test with server version {}".format(server_version)) persist_cluster_config_environment_prop(cluster_config, 'server_version', server_version) try: sg_version except NameError: log_info("Sync gateway version is not provided") persist_cluster_config_environment_prop(cluster_config, 'sync_gateway_version', "") else: log_info("Running test with sync_gateway version {}".format(sg_version)) persist_cluster_config_environment_prop(cluster_config, 'sync_gateway_version', sg_version) with open(cluster_config, "r") as ansible_hosts: log_info(ansible_hosts.read()) log_info(couchbase_server_config) log_info(sync_gateway_config) if not sync_gateway_config.is_valid(): log_info("Invalid sync_gateway provisioning configuration. Exiting ...") sys.exit(1) cluster = Cluster(config=cluster_config) config_path_full = os.path.abspath(sync_gateway_config.config_path) config = Config(config_path_full) is_valid, reason = validate_cluster( cluster.sync_gateways, cluster.sg_accels, config, ) if not is_valid: raise ProvisioningError(reason) log_info(">>> Provisioning cluster...") # Get server base url and package name cluster_keywords = ClusterKeywords() cluster_topology = cluster_keywords.get_cluster_topology(cluster_config) server_url = cluster_topology["couchbase_servers"][0] cb_server = CouchbaseServer(server_url) server_baseurl, server_package_name = couchbase_server_config.get_baseurl_package(cb_server, cbs_platform) log_info(">>> Server package: {0}/{1}".format(server_baseurl, server_package_name)) log_info(">>> Using sync_gateway config: {}".format(sync_gateway_config.config_path)) # Reset previous installs clean_cluster(cluster_config) # Install server package log_info("Installing Couchbase Server") install_couchbase_server.install_couchbase_server( cluster_config=cluster_config, couchbase_server_config=couchbase_server_config, cbs_platform=cbs_platform ) # Install sync_gateway log_info("Installing Sync Gateway") install_sync_gateway.install_sync_gateway( cluster_config=cluster_config, sync_gateway_config=sync_gateway_config, sg_platform=sg_platform, sa_platform=sa_platform, sg_ce=sg_ce ) # Install nginx install_nginx(cluster_config) log_info(">>> Done provisioning cluster...")
def params_from_base_test_setup(request, params_from_base_suite_setup): # Code before the yeild will execute before each test starts # pytest command line parameters cluster_config = params_from_base_suite_setup["cluster_config"] cluster_topology = params_from_base_suite_setup["cluster_topology"] mode = params_from_base_suite_setup["mode"] xattrs_enabled = params_from_base_suite_setup["xattrs_enabled"] server_version = params_from_base_suite_setup["server_version"] sync_gateway_version = params_from_base_suite_setup["sync_gateway_version"] server_upgraded_version = params_from_base_suite_setup[ "server_upgraded_version"] sync_gateway_upgraded_version = params_from_base_suite_setup[ "sync_gateway_upgraded_version"] liteserv_host = params_from_base_suite_setup["liteserv_host"] liteserv_port = params_from_base_suite_setup["liteserv_port"] liteserv_version = params_from_base_suite_setup["liteserv_version"] liteserv_platform = params_from_base_suite_setup["liteserv_platform"] liteserv_storage_engine = params_from_base_suite_setup[ "liteserv_storage_engine"] liteserv = params_from_base_suite_setup["liteserv"] num_docs = params_from_base_suite_setup["num_docs"] cbs_platform = params_from_base_suite_setup["cbs_platform"] cbs_toy_build = params_from_base_suite_setup["cbs_toy_build"] test_name = request.node.name log_info("Running test '{}'".format(test_name)) log_info("cluster_config: {}".format(cluster_config)) log_info("cluster_topology: {}".format(cluster_topology)) log_info("mode: {}".format(mode)) log_info("xattrs_enabled: {}".format(xattrs_enabled)) client = MobileRestClient() # Start LiteServ and delete any databases ls_url = liteserv.start("{}/logs/{}-{}-{}.txt".format( RESULTS_DIR, type(liteserv).__name__, test_name, datetime.datetime.now())) client.delete_databases(ls_url) cluster_helper = ClusterKeywords() cluster_hosts = cluster_helper.get_cluster_topology( cluster_config=cluster_config) sg_url = cluster_hosts["sync_gateways"][0]["public"] sg_admin_url = cluster_hosts["sync_gateways"][0]["admin"] if xattrs_enabled: log_info("Running upgrade with xattrs for sync meta storage") persist_cluster_config_environment_prop(cluster_config, 'xattrs_enabled', True) else: log_info("Using document storage for sync meta data") persist_cluster_config_environment_prop(cluster_config, 'xattrs_enabled', False) # This dictionary is passed to each test yield { "cluster_config": cluster_config, "cluster_topology": cluster_topology, "mode": mode, "xattrs_enabled": xattrs_enabled, "server_version": server_version, "sync_gateway_version": sync_gateway_version, "server_upgraded_version": server_upgraded_version, "sync_gateway_upgraded_version": sync_gateway_upgraded_version, "liteserv_host": liteserv_host, "liteserv_port": liteserv_port, "liteserv_version": liteserv_version, "liteserv_platform": liteserv_platform, "liteserv_storage_engine": liteserv_storage_engine, "ls_url": ls_url, "sg_url": sg_url, "sg_admin_url": sg_admin_url, "num_docs": num_docs, "cbs_platform": cbs_platform, "cbs_toy_build": cbs_toy_build } client.delete_databases(ls_url) liteserv.stop() # Code after the yield will execute when each test finishes log_info("Tearing down test '{}'".format(test_name)) network_utils = NetworkUtils() network_utils.list_connections() # Verify all sync_gateways and sg_accels are reachable c = cluster.Cluster(cluster_config) errors = c.verify_alive(mode) # Fetch logs logging_helper = Logging() logging_helper.fetch_and_analyze_logs(cluster_config=cluster_config, test_name=test_name) assert len(errors) == 0 # Scan logs # SG logs for panic, data race # System logs for OOM ansible_runner = AnsibleRunner(cluster_config) script_name = "{}/utilities/check_logs.sh".format(os.getcwd()) status = ansible_runner.run_ansible_playbook( "check-logs.yml", extra_vars={"script_name": script_name}) if status != 0: raise LogScanningError("Errors found in the logs")
def params_from_base_suite_setup(request): log_info("Setting up 'params_from_base_suite_setup' ...") # pytest command line parameters server_version = request.config.getoption("--server-version") sync_gateway_version = request.config.getoption("--sync-gateway-version") mode = request.config.getoption("--mode") use_sequoia = request.config.getoption("--sequoia") skip_provisioning = request.config.getoption("--skip-provisioning") cbs_ssl = request.config.getoption("--server-ssl") xattrs_enabled = request.config.getoption("--xattrs") server_seed_docs = request.config.getoption("--server-seed-docs") max_docs = request.config.getoption("--max-docs") num_users = request.config.getoption("--num-users") create_batch_size = request.config.getoption("--create-batch-size") create_delay = request.config.getoption("--create-delay") update_runtime_sec = request.config.getoption("--update-runtime-sec") update_batch_size = request.config.getoption("--update-batch-size") update_docs_percentage = request.config.getoption( "--update-docs-percentage") update_delay = request.config.getoption("--update-delay") changes_delay = request.config.getoption("--changes-delay") changes_limit = request.config.getoption("--changes-limit") if xattrs_enabled and version_is_binary(sync_gateway_version): check_xattr_support(server_version, sync_gateway_version) log_info("server_version: {}".format(server_version)) log_info("sync_gateway_version: {}".format(sync_gateway_version)) log_info("mode: {}".format(mode)) log_info("skip_provisioning: {}".format(skip_provisioning)) log_info("cbs_ssl: {}".format(cbs_ssl)) log_info("xattrs_enabled: {}".format(xattrs_enabled)) # Make sure mode for sync_gateway is supported ('cc' or 'di') validate_sync_gateway_mode(mode) # use ci_lb_cc cluster config if mode is "cc" or ci_lb_di cluster config if more is "di" log_info("Using 'ci_lb_{}' config!".format(mode)) cluster_config = "{}/ci_lb_{}".format(CLUSTER_CONFIGS_DIR, mode) try: server_version except NameError: log_info("Server version is not provided") persist_cluster_config_environment_prop(cluster_config, 'server_version', "") else: log_info("Running test with server version {}".format(server_version)) persist_cluster_config_environment_prop(cluster_config, 'server_version', server_version) try: sync_gateway_version except NameError: log_info("Sync gateway version is not provided") persist_cluster_config_environment_prop(cluster_config, 'sync_gateway_version', "") else: log_info("Running test with sync_gateway version {}".format( sync_gateway_version)) persist_cluster_config_environment_prop(cluster_config, 'sync_gateway_version', sync_gateway_version) # Only works with load balancer configs persist_cluster_config_environment_prop(cluster_config, 'sg_lb_enabled', True) if cbs_ssl: log_info("Running tests with cbs <-> sg ssl enabled") # Enable ssl in cluster configs persist_cluster_config_environment_prop(cluster_config, 'cbs_ssl_enabled', True) else: log_info("Running tests with cbs <-> sg ssl disabled") # Disable ssl in cluster configs persist_cluster_config_environment_prop(cluster_config, 'cbs_ssl_enabled', False) if xattrs_enabled: log_info("Running test with xattrs for sync meta storage") persist_cluster_config_environment_prop(cluster_config, 'xattrs_enabled', True) else: log_info("Using document storage for sync meta data") persist_cluster_config_environment_prop(cluster_config, 'xattrs_enabled', False) sg_config = sync_gateway_config_path_for_mode( "sync_gateway_default_functional_tests", mode) # Skip provisioning if user specifies '--skip-provisoning' or '--sequoia' should_provision = True if skip_provisioning or use_sequoia: should_provision = False cluster_utils = ClusterKeywords() if should_provision: try: cluster_utils.provision_cluster( cluster_config=cluster_config, server_version=server_version, sync_gateway_version=sync_gateway_version, sync_gateway_config=sg_config) except ProvisioningError: logging_helper = Logging() logging_helper.fetch_and_analyze_logs( cluster_config=cluster_config, test_name=request.node.name) raise # Hit this intalled running services to verify the correct versions are installed cluster_utils.verify_cluster_versions( cluster_config, expected_server_version=server_version, expected_sync_gateway_version=sync_gateway_version) # Load topology as a dictionary cluster_topology = cluster_utils.get_cluster_topology(cluster_config) yield { "cluster_config": cluster_config, "cluster_topology": cluster_topology, "mode": mode, "xattrs_enabled": xattrs_enabled, "server_seed_docs": server_seed_docs, "max_docs": max_docs, "num_users": num_users, "create_batch_size": create_batch_size, "create_delay": create_delay, "update_runtime_sec": update_runtime_sec, "update_batch_size": update_batch_size, "update_docs_percentage": update_docs_percentage, "update_delay": update_delay, "changes_delay": changes_delay, "changes_limit": changes_limit } log_info("Tearing down 'params_from_base_suite_setup' ...")
def test_no_conflicts_with_revs_limit(params_from_base_test_setup, sg_conf_name, num_of_docs, revs_limit): """ @summary Enable no conflicts and with non default revs_limit and verify revs_limit is maintained Test case link : https://docs.google.com/spreadsheets/d/1YwI_gCeoBebQKBybkzoAEoXSc0XLReszDA-mPFQapgk/edit#gid=0 covered #4, #5 Steps: 1. Enable allow_conflicts = false in SG config with parametrized revs_limit 2. Add docs to SG. 3. Update docs more than revs_limit. 4. Create a conflict and verify it fails. 5. Get number of revisions and verify length is equal to revs_limit set to 6. Update the docs 1 more time 7. Get number of revisions and verify number of revisions should be same as revs_limit 8. Verify previous revisions does not exist """ # Setup cluster_config = params_from_base_test_setup["cluster_config"] topology = params_from_base_test_setup["cluster_topology"] no_conflicts_enabled = params_from_base_test_setup["no_conflicts_enabled"] mode = params_from_base_test_setup["mode"] sg_url = topology["sync_gateways"][0]["public"] sg_admin_url = topology["sync_gateways"][0]["admin"] sg_db = "db" if not no_conflicts_enabled: pytest.skip('--no-conflicts is not enabled, so skipping the test') sg_conf = sync_gateway_config_path_for_mode(sg_conf_name, mode) c = cluster.Cluster(cluster_config) c.reset(sg_conf) sg_client = MobileRestClient() channels = ["no-conflicts"] sg_client.create_user(url=sg_admin_url, db=sg_db, name='autotest', password='******', channels=channels) autouser_session = sg_client.create_session(url=sg_admin_url, db=sg_db, name='autotest', password='******') # end of Set up # 1. Enable allow_conflicts = false in SG config with revs_limit temp_cluster_config = copy_to_temp_conf(cluster_config, mode) persist_cluster_config_environment_prop(temp_cluster_config, 'revs_limit', revs_limit, property_name_check=False) status = c.sync_gateways[0].restart(config=sg_conf, cluster_config=temp_cluster_config) assert status == 0, "Syncgateway did not start after having revs_limit 1 with no conflicts mode" # 2. Add docs to SG. sgdoc_bodies = document.create_docs(doc_id_prefix='sg_docs', number=num_of_docs, attachments_generator=attachment.generate_2_png_10_10, channels=channels) sg_docs = sg_client.add_bulk_docs(url=sg_url, db=sg_db, docs=sgdoc_bodies, auth=autouser_session) assert len(sgdoc_bodies) == num_of_docs # 3. Update the docs few times prev_revs = [] for i in xrange(revs_limit + 5): update_sg_docs = sg_client.update_docs(url=sg_url, db=sg_db, docs=sg_docs, number_updates=1, delay=None, auth=autouser_session, channels=channels) rev = update_sg_docs[0]['rev'].split('-')[1] prev_revs.append(rev) # 4. Try to create a conflict for doc in sg_docs: with pytest.raises(HTTPError) as he: sg_client.add_conflict(url=sg_url, db=sg_db, doc_id=doc["id"], parent_revisions=doc["rev"], new_revision="2-foo", auth=autouser_session) assert he.value.message.startswith('409 Client Error: Conflict for url:') # 5. Get number of revisions and verify length is equal to revs_limit set to for doc in sg_docs: num_of_revs = sg_client.get_revs_num_in_history(url=sg_url, db=sg_db, doc_id=doc["id"], auth=autouser_session) assert len(num_of_revs) == revs_limit, "Number of revisions in history is more than revs_limit set in sg config" for i in xrange(4): assert prev_revs[i] not in num_of_revs # 6. Update the docs 1 more time sg_client.update_docs(url=sg_url, db=sg_db, docs=sg_docs, number_updates=1, delay=None, auth=autouser_session, channels=channels) # 7. Get number of revisions and verify number of revisions should be same revs_limit # 8. Verify previous revisions does not exist for doc in sg_docs: num_of_revs = sg_client.get_revs_num_in_history(url=sg_url, db=sg_db, doc_id=doc["id"], auth=autouser_session) assert len(num_of_revs) == revs_limit, "Number of revisions in history is more than revs_limit set in sg config" for i in xrange(5): assert prev_revs[i] not in num_of_revs
def params_from_base_suite_setup(request): log_info("Setting up 'params_from_base_suite_setup' ...") # pytest command line parameters server_version = request.config.getoption("--server-version") sync_gateway_version = request.config.getoption("--sync-gateway-version") server_upgraded_version = request.config.getoption( "--server-upgraded-version") sync_gateway_upgraded_version = request.config.getoption( "--sync-gateway-upgraded-version") mode = request.config.getoption("--mode") cluster_config = request.config.getoption("--cluster-config") # use_sequoia = request.config.getoption("--sequoia") skip_provisioning = request.config.getoption("--skip-provisioning") cbs_ssl = request.config.getoption("--server-ssl") xattrs_enabled = request.config.getoption("--xattrs") liteserv_host = request.config.getoption("--liteserv-host") liteserv_port = request.config.getoption("--liteserv-port") liteserv_version = request.config.getoption("--liteserv-version") liteserv_platform = request.config.getoption("--liteserv-platform") liteserv_storage_engine = request.config.getoption( "--liteserv-storage-engine") num_docs = request.config.getoption("--num-docs") cbs_platform = request.config.getoption("--cbs-platform") cbs_toy_build = request.config.getoption("--cbs-upgrade-toybuild") if xattrs_enabled and version_is_binary(sync_gateway_version): check_xattr_support(server_upgraded_version, sync_gateway_upgraded_version) log_info("server_version: {}".format(server_version)) log_info("sync_gateway_version: {}".format(sync_gateway_version)) log_info("server_upgraded_version: {}".format(server_upgraded_version)) log_info("sync_gateway_upgraded_version: {}".format( sync_gateway_upgraded_version)) log_info("mode: {}".format(mode)) log_info("skip_provisioning: {}".format(skip_provisioning)) log_info("cbs_ssl: {}".format(cbs_ssl)) log_info("xattrs_enabled: {}".format(xattrs_enabled)) log_info("liteserv_host: {}".format(liteserv_host)) log_info("liteserv_port: {}".format(liteserv_port)) log_info("liteserv_version: {}".format(liteserv_version)) log_info("liteserv_platform: {}".format(liteserv_platform)) log_info("liteserv_storage_engine: {}".format(liteserv_storage_engine)) log_info("num_docs: {}".format(num_docs)) log_info("cbs_platform: {}".format(cbs_platform)) log_info("cbs_toy_build: {}".format(cbs_toy_build)) # Make sure mode for sync_gateway is supported ('cc' or 'di') validate_sync_gateway_mode(mode) # use ci_lb_cc cluster config if mode is "cc" or ci_lb_di cluster config if more is "di" # use base_(lb_)cc cluster config if mode is "cc" or base_(lb_)di cluster config if mode is "di" cluster_config = "{}/{}_{}".format(CLUSTER_CONFIGS_DIR, cluster_config, mode) log_info("Using '{}' config!".format(cluster_config)) try: server_version except NameError: log_info("Server version is not provided") persist_cluster_config_environment_prop(cluster_config, 'server_version', "") else: log_info("Running test with server version {}".format(server_version)) persist_cluster_config_environment_prop(cluster_config, 'server_version', server_version) try: sync_gateway_version except NameError: log_info("Sync gateway version is not provided") persist_cluster_config_environment_prop(cluster_config, 'sync_gateway_version', "") else: log_info("Running test with sync_gateway version {}".format( sync_gateway_version)) persist_cluster_config_environment_prop(cluster_config, 'sync_gateway_version', sync_gateway_version) # Only works with load balancer configs persist_cluster_config_environment_prop(cluster_config, 'sg_lb_enabled', True) if cbs_ssl: log_info("Running tests with cbs <-> sg ssl enabled") # Enable ssl in cluster configs persist_cluster_config_environment_prop(cluster_config, 'cbs_ssl_enabled', True) else: log_info("Running tests with cbs <-> sg ssl disabled") # Disable ssl in cluster configs persist_cluster_config_environment_prop(cluster_config, 'cbs_ssl_enabled', False) sg_config = sync_gateway_config_path_for_mode( "sync_gateway_default_functional_tests", mode) liteserv = LiteServFactory.create(platform=liteserv_platform, version_build=liteserv_version, host=liteserv_host, port=liteserv_port, storage_engine=liteserv_storage_engine) log_info("Downloading LiteServ ...") # Download LiteServ liteserv.download() # Install LiteServ liteserv.install() # Skip provisioning if user specifies '--skip-provisoning' or '--sequoia' should_provision = True if skip_provisioning: should_provision = False cluster_utils = ClusterKeywords() if should_provision: try: cluster_utils.provision_cluster( cluster_config=cluster_config, server_version=server_version, sync_gateway_version=sync_gateway_version, sync_gateway_config=sg_config, cbs_platform=cbs_platform) except ProvisioningError: logging_helper = Logging() logging_helper.fetch_and_analyze_logs( cluster_config=cluster_config, test_name=request.node.name) raise # Hit this intalled running services to verify the correct versions are installed cluster_utils.verify_cluster_versions( cluster_config, expected_server_version=server_version, expected_sync_gateway_version=sync_gateway_version) # Load topology as a dictionary cluster_topology = cluster_utils.get_cluster_topology(cluster_config) yield { "cluster_config": cluster_config, "cluster_topology": cluster_topology, "mode": mode, "xattrs_enabled": xattrs_enabled, "server_version": server_version, "sync_gateway_version": sync_gateway_version, "server_upgraded_version": server_upgraded_version, "sync_gateway_upgraded_version": sync_gateway_upgraded_version, "liteserv_host": liteserv_host, "liteserv_port": liteserv_port, "liteserv_version": liteserv_version, "liteserv_platform": liteserv_platform, "liteserv_storage_engine": liteserv_storage_engine, "liteserv": liteserv, "num_docs": num_docs, "cbs_platform": cbs_platform, "cbs_toy_build": cbs_toy_build } log_info("Tearing down 'params_from_base_suite_setup' ...")
def test_migrate_conflicts_delete_last_rev(params_from_base_test_setup, sg_conf_name, num_of_docs): """ @summary Migrate conflicts to no-conflicts mode and delete last revision and verify revisions exists in open revisions Test case link : https://docs.google.com/spreadsheets/d/1YwI_gCeoBebQKBybkzoAEoXSc0XLReszDA-mPFQapgk/edit#gid=0 covered #19 Steps: 1. Start sg with default(i.e allow_conflicts=true) 2. Add docs to SG. 3. Update docs few times . 4. Create a conflicts and verify it is successful. 5. Modify sg config by enabling allow_conflicts to false 6. restart sg. 7. Delete doc by revision of current active open revision 8. Verify all revisions in history exists in open revisions which got at step 4. """ # Setup cluster_config = params_from_base_test_setup["cluster_config"] topology = params_from_base_test_setup["cluster_topology"] no_conflicts_enabled = params_from_base_test_setup["no_conflicts_enabled"] mode = params_from_base_test_setup["mode"] sg_url = topology["sync_gateways"][0]["public"] sg_admin_url = topology["sync_gateways"][0]["admin"] sync_gateway_version = params_from_base_test_setup["sync_gateway_version"] sg_db = "db" if no_conflicts_enabled or sync_gateway_version < "2.0": pytest.skip('--no-conflicts is enabled and does not work with sg < 2.0 , so skipping the test') sg_conf = sync_gateway_config_path_for_mode(sg_conf_name, mode) # 1. Start sg with default(i.e allow_conflicts=true) c = cluster.Cluster(cluster_config) c.reset(sg_conf) sg_client = MobileRestClient() channels = ["no-conflicts"] sg_client.create_user(url=sg_admin_url, db=sg_db, name='autotest', password='******', channels=channels) autouser_session = sg_client.create_session(url=sg_admin_url, db=sg_db, name='autotest', password='******') # end of Set up # 2. Add docs to SG. sgdoc_bodies = document.create_docs(doc_id_prefix="sg_docs", number=num_of_docs, channels=channels) sg_docs = sg_client.add_bulk_docs(url=sg_url, db=sg_db, docs=sgdoc_bodies, auth=autouser_session) assert len(sgdoc_bodies) == num_of_docs # 3. Update the docs few times prev_revs = [] for i in xrange(5): update_sg_docs = sg_client.update_docs(url=sg_url, db=sg_db, docs=sg_docs, number_updates=1, delay=None, auth=autouser_session, channels=channels) rev = update_sg_docs[0]['rev'].split('-')[1] prev_revs.append(rev) # 4. Create a conflicts and verify it is successful. for doc in sg_docs: conflicted_rev = sg_client.add_conflict(url=sg_url, db=sg_db, doc_id=doc["id"], parent_revisions=doc["rev"], new_revision="2-foo", auth=autouser_session) assert conflicted_rev["rev"] == "2-foo" for doc in sg_docs: num_of_open_revs = sg_client.get_open_revs_ids(url=sg_url, db=sg_db, doc_id=doc["id"], rev="2-foo", auth=autouser_session) time.sleep(5) # 5. Enable allow_conflicts = false in SG config and 6. restart sg revs_limit = 2 temp_cluster_config = copy_to_temp_conf(cluster_config, mode) persist_cluster_config_environment_prop(temp_cluster_config, 'no_conflicts_enabled', "True", property_name_check=False) persist_cluster_config_environment_prop(temp_cluster_config, 'revs_limit', revs_limit, property_name_check=False) status = c.sync_gateways[0].restart(config=sg_conf, cluster_config=temp_cluster_config) assert status == 0, "Syncgateway did not start after no conflicts is enabled" sg_client.update_docs(url=sg_url, db=sg_db, docs=sg_docs, number_updates=1, auth=autouser_session, channels=channels) # 6. Delete doc by revision of current active open revision for doc in sg_docs: num_of_revs = sg_client.get_doc(url=sg_url, db=sg_db, doc_id=doc["id"], auth=autouser_session) sg_client.delete_doc(url=sg_url, db=sg_db, doc_id=doc["id"], rev=num_of_revs["_rev"], auth=autouser_session) # 7.Verify all revisions in history exists in open revisions which got at step 4. for doc in sg_docs: num_of_revs_history = sg_client.get_revs_num_in_history(url=sg_url, db=sg_db, doc_id=doc["id"], auth=autouser_session) for rev in num_of_revs_history: assert rev in num_of_open_revs, "Expected revision does not exist in revision history "
def test_concurrent_updates_no_conflicts(params_from_base_test_setup, sg_conf_name, num_of_docs, revs_limit): """@summary Test with concurrent updates with no conflicts enabled Test case link : https://docs.google.com/spreadsheets/d/1YwI_gCeoBebQKBybkzoAEoXSc0XLReszDA-mPFQapgk/edit#gid=0 covered #15 Steps: 1. Start sg with some revs_limit specified 2. Add docs to SG. 3. Update docs few times via sg . 4. Update docs few times vis sdk concurrently with sg. -> There are chances of getting conflict errors on both, handled the error appropriately 5. update docs few number of times. 6. Verify it can maintain default revisions. 7. Verify previous revisions deleted and revisions maintained based on revs_limit """ # Setup cluster_config = params_from_base_test_setup["cluster_config"] topology = params_from_base_test_setup["cluster_topology"] no_conflicts_enabled = params_from_base_test_setup["no_conflicts_enabled"] mode = params_from_base_test_setup["mode"] sg_url = topology["sync_gateways"][0]["public"] sg_admin_url = topology["sync_gateways"][0]["admin"] sg_db = "db" if revs_limit is None: revs_limit = 1000 additional_updates = revs_limit total_updates = revs_limit + additional_updates if not no_conflicts_enabled: pytest.skip('--no-conflicts is not enabled, so skipping the test') sg_conf = sync_gateway_config_path_for_mode(sg_conf_name, mode) # 1. Start sg c = cluster.Cluster(cluster_config) c.reset(sg_conf) sg_client = MobileRestClient() channels = ["no-conflicts"] sg_client.create_user(url=sg_admin_url, db=sg_db, name='autotest', password='******', channels=channels) autouser_session = sg_client.create_session(url=sg_admin_url, db=sg_db, name='autotest', password='******') temp_cluster_config = copy_to_temp_conf(cluster_config, mode) persist_cluster_config_environment_prop(temp_cluster_config, 'revs_limit', revs_limit, property_name_check=False) status = c.sync_gateways[0].restart(config=sg_conf, cluster_config=temp_cluster_config) assert status == 0, "Syncgateway did not start after no conflicts is enabled" # end of Set up # 2. Add docs to SG. sgdoc_bodies = document.create_docs(doc_id_prefix='sg_docs', number=num_of_docs, attachments_generator=attachment.generate_2_png_10_10, channels=channels) sg_docs = sg_client.add_bulk_docs(url=sg_url, db=sg_db, docs=sgdoc_bodies, auth=autouser_session) assert len(sgdoc_bodies) == num_of_docs # Connect to server via SDK log_info('Connecting to bucket ...') bucket_name = 'data-bucket' cbs_url = topology['couchbase_servers'][0] cbs_ip = host_for_url(cbs_url) sdk_client = Bucket('couchbase://{}/{}'.format(cbs_ip, bucket_name), password='******', timeout=SDK_TIMEOUT) sg_doc_ids = [doc['id'] for doc in sg_docs] sdk_docs_resp = sdk_client.get_multi(sg_doc_ids) # Update the same documents concurrently from a sync gateway client and and sdk client with ThreadPoolExecutor(max_workers=9) as tpe: update_from_sdk_task = tpe.submit(sdk_bulk_update, sdk_client, sdk_docs_resp, 10) update_from_sg_task = tpe.submit(sg_doc_updates, sg_client, sg_url=sg_url, sg_db=sg_db, sg_docs=sg_docs, number_updates=10, auth=autouser_session, channels=channels) update_from_sg_task.result() update_from_sdk_task.result() # 3. Update the docs few times prev_revs = [] for i in xrange(total_updates): update_sg_docs = sg_client.update_docs(url=sg_url, db=sg_db, docs=sg_docs, number_updates=1, delay=None, auth=autouser_session, channels=channels) rev = update_sg_docs[0]['rev'].split('-')[1] prev_revs.append(rev) # 4. Verify it can maintain default revisions. # 5. Verify previous revisions deleted. for doc in sg_docs: num_of_revs = sg_client.get_revs_num_in_history(url=sg_url, db=sg_db, doc_id=doc["id"], auth=autouser_session) assert len(num_of_revs) == revs_limit, "Number of revisions in history is more than revs_limit set in sg config" for i in xrange(additional_updates): assert prev_revs[i] not in num_of_revs
def test_migrate_conflicts_to_noConflicts(params_from_base_test_setup, sg_conf_name, num_of_docs, revs_limit): """ @summary Migrating from no conflicts false to true Test case link : https://docs.google.com/spreadsheets/d/1YwI_gCeoBebQKBybkzoAEoXSc0XLReszDA-mPFQapgk/edit#gid=0 covered #6, #7, #8 Steps: 1. Start sg with default(i.e allow_conflicts=true) 2. Add docs to SG. 3. Update docs few times . 4. Create a conflicts and verify it is successful. 5. Modify sg config by enabling allow_conflicts to false 6. restart sg. 7. Create a conflict and verify conflict throws 409. 8. update docs few number of times. 9. Verify it can maintain default revisions. 10. Verify previous revisions deleted. """ # Setup cluster_config = params_from_base_test_setup["cluster_config"] topology = params_from_base_test_setup["cluster_topology"] no_conflicts_enabled = params_from_base_test_setup["no_conflicts_enabled"] mode = params_from_base_test_setup["mode"] sg_url = topology["sync_gateways"][0]["public"] sg_admin_url = topology["sync_gateways"][0]["admin"] sync_gateway_version = params_from_base_test_setup["sync_gateway_version"] sg_db = "db" if revs_limit is None: revs_limit = 1000 additional_updates = revs_limit if no_conflicts_enabled or sync_gateway_version < "2.0": pytest.skip('--no-conflicts is enabled and does not work with sg < 2.0 , so skipping the test') sg_conf = sync_gateway_config_path_for_mode(sg_conf_name, mode) # 1. Start sg with default(i.e allow_conflicts=true) c = cluster.Cluster(cluster_config) c.reset(sg_conf) sg_client = MobileRestClient() channels = ["no-conflicts"] sg_client.create_user(url=sg_admin_url, db=sg_db, name='autotest', password='******', channels=channels) autouser_session = sg_client.create_session(url=sg_admin_url, db=sg_db, name='autotest', password='******') # end of Set up # 2. Add docs to SG. sgdoc_bodies = document.create_docs(doc_id_prefix='sg_docs', number=num_of_docs, attachments_generator=attachment.generate_2_png_10_10, channels=channels) sg_docs = sg_client.add_bulk_docs(url=sg_url, db=sg_db, docs=sgdoc_bodies, auth=autouser_session) assert len(sgdoc_bodies) == num_of_docs # 3. Update the docs few times prev_revs = [] for i in xrange(revs_limit): update_sg_docs = sg_client.update_docs(url=sg_url, db=sg_db, docs=sg_docs, number_updates=1, delay=None, auth=autouser_session, channels=channels) rev = update_sg_docs[0]['rev'].split('-')[1] prev_revs.append(rev) # 4. Create a conflicts and verify it is successful. for doc in sg_docs: conflicted_rev = sg_client.add_conflict(url=sg_url, db=sg_db, doc_id=doc["id"], parent_revisions=doc["rev"], new_revision="2-foo", auth=autouser_session) assert conflicted_rev["rev"] == "2-foo" # 5. Enable allow_conflicts = false in SG config and 6. restart sg temp_cluster_config = copy_to_temp_conf(cluster_config, mode) persist_cluster_config_environment_prop(temp_cluster_config, 'no_conflicts_enabled', "True", property_name_check=False) persist_cluster_config_environment_prop(temp_cluster_config, 'revs_limit', revs_limit, property_name_check=False) status = c.sync_gateways[0].restart(config=sg_conf, cluster_config=temp_cluster_config) assert status == 0, "Syncgateway did not start after no conflicts is enabled" sg_client.update_docs(url=sg_url, db=sg_db, docs=sg_docs, number_updates=1, auth=autouser_session, channels=channels) # 7. Create a conflict and verify conflict throws 409. for doc in sg_docs: with pytest.raises(HTTPError) as he: sg_client.add_conflict(url=sg_url, db=sg_db, doc_id=doc["id"], parent_revisions=doc["rev"], new_revision="2-foo1", auth=autouser_session) assert he.value.message.startswith('409 Client Error: Conflict for url:') # 8. update docs few number of times. update_sg_docs = sg_client.update_docs(url=sg_url, db=sg_db, docs=sg_docs, number_updates=additional_updates, auth=autouser_session, channels=channels) # 9. Verify it can maintain default revisions. # 10. Verify previous revisions deleted. for doc in sg_docs: num_of_revs = sg_client.get_revs_num_in_history(url=sg_url, db=sg_db, doc_id=doc["id"], auth=autouser_session) assert len(num_of_revs) == revs_limit, "Number of revisions in history is more than revs_limit set in sg config" for i in xrange(additional_updates): assert prev_revs[i] not in num_of_revs
def test_conflicts_sg_accel_added(params_from_base_test_setup, sg_conf_name, num_of_docs, revs_limit, additional_updates): """ @summary Verify no conflicts feature works with sg accel down Test case link : https://docs.google.com/spreadsheets/d/1YwI_gCeoBebQKBybkzoAEoXSc0XLReszDA-mPFQapgk/edit#gid=0 covered #12, #16, #21 Steps: 1. Enable allow_conflicts = false in SG config with revs_limit 2. Add docs to SG. 3. Update the docs few times and get all revisions of updates 4. Get number of revisions and verify length is equal to revs_limit set to 5. Start sg accel 6. Update the docs with few updates 7. Get number of revisions and verify number of revisions is equvalent to revs_limit set to """ # Setup cluster_config = params_from_base_test_setup["cluster_config"] topology = params_from_base_test_setup["cluster_topology"] mode = params_from_base_test_setup["mode"] sg_url = topology["sync_gateways"][0]["public"] sg_admin_url = topology["sync_gateways"][0]["admin"] no_conflicts_enabled = params_from_base_test_setup["no_conflicts_enabled"] sg_db = "db" total_updates = revs_limit + additional_updates new_updates = 2 if not no_conflicts_enabled or mode != "di": pytest.skip('--no-conflicts is not enabled or mode is not di, so skipping the test') sg_conf = sync_gateway_config_path_for_mode(sg_conf_name, mode) c = cluster.Cluster(cluster_config) c.reset(sg_conf) c.sg_accels[0].stop() sg_client = MobileRestClient() channels = ["no-conflicts"] sg_client.create_user(url=sg_admin_url, db=sg_db, name='autotest', password='******', channels=channels) autouser_session = sg_client.create_session(url=sg_admin_url, db=sg_db, name='autotest', password='******') # end of Set up # 1. Enable allow_conflicts = false in SG config with revs_limit temp_cluster_config = copy_to_temp_conf(cluster_config, mode) persist_cluster_config_environment_prop(temp_cluster_config, 'revs_limit', revs_limit, property_name_check=False) status = c.sync_gateways[0].restart(config=sg_conf, cluster_config=temp_cluster_config) assert status == 0, "Syncgateway did not start after having revs_limit with no conflicts mode" # 2. Add docs to SG. sgdoc_bodies = document.create_docs(doc_id_prefix="sg_docs", number=num_of_docs, channels=channels) sg_docs = sg_client.add_bulk_docs(url=sg_url, db=sg_db, docs=sgdoc_bodies, auth=autouser_session) assert len(sgdoc_bodies) == num_of_docs # 3. Update the docs few times and get all revisions of updates prev_revs = [] for i in xrange(total_updates): update_sg_docs = sg_client.update_docs(url=sg_url, db=sg_db, docs=sg_docs, number_updates=1, delay=None, auth=autouser_session, channels=channels) rev = update_sg_docs[0]['rev'].split('-')[1] prev_revs.append(rev) # 4. Get number of revisions and verify length is equal to revs_limit set to for doc in sg_docs: num_of_revs = sg_client.get_revs_num_in_history(url=sg_url, db=sg_db, doc_id=doc["id"], auth=autouser_session) assert len(num_of_revs) == revs_limit, "Number of revisions in history is more than revs_limit set in sg config" for i in xrange(additional_updates): assert prev_revs[i] not in num_of_revs # 5. Start sg accel status = c.sg_accels[0].start(config=sg_conf) assert status == 0, "sync_gateway accel did not start" # 6. Update the docs with few updates sg_client.update_docs(url=sg_url, db=sg_db, docs=sg_docs, number_updates=new_updates, delay=None, auth=autouser_session, channels=channels) # 7. Get number of revisions and verify number of revisions is equvalent to revs_limit set to for doc in sg_docs: num_of_revs = sg_client.get_revs_num_in_history(url=sg_url, db=sg_db, doc_id=doc["id"], auth=autouser_session) assert len(num_of_revs) == revs_limit, "Number of revisions in history is more than revs_limit set in sg config" for i in xrange(additional_updates + new_updates): assert prev_revs[i] not in num_of_revs
def test_no_conflicts_update_revs_limit(params_from_base_test_setup, sg_conf_name, num_of_docs, revs_limit): """ @summary Enable no conflicts and with non default revs_limit and verify revs_limit is maintained Test case link : https://docs.google.com/spreadsheets/d/1YwI_gCeoBebQKBybkzoAEoXSc0XLReszDA-mPFQapgk/edit#gid=0 covered #14 Steps: 1. Enable allow_conflicts = false in SG config with parametried revs_limit 2. Add docs to SG. 3. Update the more than revs_limit. 4. Check the revision list for the doc. 5. Modify the revs_limit to 2 6. Update doc 7. Verify the revision history shows only 2 revisions now 8. Verify previous revisions deleted """ # Setup cluster_config = params_from_base_test_setup["cluster_config"] topology = params_from_base_test_setup["cluster_topology"] no_conflicts_enabled = params_from_base_test_setup["no_conflicts_enabled"] mode = params_from_base_test_setup["mode"] sg_url = topology["sync_gateways"][0]["public"] sg_admin_url = topology["sync_gateways"][0]["admin"] sg_db = "db" reduced_revs_limit = revs_limit - 3 total_updates = revs_limit + 5 if not no_conflicts_enabled: pytest.skip('--no-conflicts is not enabled, so skipping the test') sg_conf = sync_gateway_config_path_for_mode(sg_conf_name, mode) c = cluster.Cluster(cluster_config) c.reset(sg_conf) sg_client = MobileRestClient() channels = ["no-conflicts"] sg_client.create_user(url=sg_admin_url, db=sg_db, name='autotest', password='******', channels=channels) autouser_session = sg_client.create_session(url=sg_admin_url, db=sg_db, name='autotest', password='******') # end of Set up # 1. Enable allow_conflicts = false in SG config with revs_limit=5 temp_cluster_config = copy_to_temp_conf(cluster_config, mode) persist_cluster_config_environment_prop(temp_cluster_config, 'revs_limit', revs_limit, property_name_check=False) status = c.sync_gateways[0].restart(config=sg_conf, cluster_config=temp_cluster_config) assert status == 0, "Syncgateway did not start after having revs_limit 1 with no conflicts mode" # 2. Add docs to SG. sgdoc_bodies = document.create_docs(doc_id_prefix="sg_docs", number=num_of_docs, channels=channels) sg_docs = sg_client.add_bulk_docs(url=sg_url, db=sg_db, docs=sgdoc_bodies, auth=autouser_session) assert len(sgdoc_bodies) == num_of_docs # 3. Update the docs few times prev_revs = [] for i in xrange(total_updates): update_sg_docs = sg_client.update_docs(url=sg_url, db=sg_db, docs=sg_docs, number_updates=1, delay=None, auth=autouser_session, channels=channels) rev = update_sg_docs[0]['rev'].split('-')[1] prev_revs.append(rev) # 4. Get number of revisions and verify length is equal to revs_limit set to for doc in sg_docs: num_of_revs = sg_client.get_revs_num_in_history(url=sg_url, db=sg_db, doc_id=doc["id"], auth=autouser_session) assert len(num_of_revs) == revs_limit, "Number of revisions in history is more than revs_limit set in sg config" for i in xrange(5): assert prev_revs[i] not in num_of_revs # 5. Modify the revs_limit to 2 temp_cluster_config = copy_to_temp_conf(cluster_config, mode) persist_cluster_config_environment_prop(temp_cluster_config, 'revs_limit', reduced_revs_limit, property_name_check=False) status = c.sync_gateways[0].restart(config=sg_conf, cluster_config=temp_cluster_config) assert status == 0, "Syncgateway did not start after having revs_limit 2 with no conflicts mode" # 6. Update the docs 1 more time sg_client.update_docs(url=sg_url, db=sg_db, docs=sg_docs, number_updates=2, delay=None, auth=autouser_session, channels=channels) # 7. Get number of revisions and verify number of revisions is equivalent to revs_limit set to for doc in sg_docs: num_of_revs = sg_client.get_revs_num_in_history(url=sg_url, db=sg_db, doc_id=doc["id"], auth=autouser_session) assert len(num_of_revs) == 2, "Number of revisions in history is more than revs_limit set in sg config" for i in xrange(total_updates - reduced_revs_limit): assert prev_revs[i] not in num_of_revs