From e0ecacbbc5c11ddaa3abbf3bbca1f5b372c9a9b5 Mon Sep 17 00:00:00 2001 From: Sujay Gad Date: Wed, 2 Mar 2022 09:47:38 +0530 Subject: [PATCH] Eventing: fixing log rotation and cli tests Change-Id: I638ce5f2f27e4740b599df7cc0c7b65877d9ff66 Reviewed-on: https://review.couchbase.org/c/testrunner/+/171617 Reviewed-by: Chanabasappa Ghali Tested-by: Sujay Gad --- conf/eventing/eventing_logging.conf | 2 +- conf/eventing/eventing_tools.conf | 6 ++--- pytests/eventing/eventing_base.py | 4 ++-- pytests/eventing/eventing_tools.py | 35 ++++++++++++++++++++--------- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/conf/eventing/eventing_logging.conf b/conf/eventing/eventing_logging.conf index f807d2e563..980cc5211b 100644 --- a/conf/eventing/eventing_logging.conf +++ b/conf/eventing/eventing_logging.conf @@ -3,4 +3,4 @@ eventing.eventing_logging.EventingLogging: test_eventing_with_log_redaction,nodes_init=3,services_init=kv:eventing-index-n1ql,dataset=default,groups=simple,reset_services=True,skip_cleanup=True,non_default_collection=True,java_sdk_client=True test_log_rotation,nodes_init=4,services_init=kv-eventing-index-n1ql,dataset=default,groups=simple,reset_services=True,skip_cleanup=True test_log_rotation,nodes_init=4,services_init=kv-eventing-eventing-index:n1ql,dataset=default,groups=simple,reset_services=True,skip_cleanup=True - test_audit_event_for_authentication_failure_and_authorization_failure,nodes_init=4,services_init=kv-eventing-eventing-index:n1ql,dataset=default,groups=simple,reset_services=True,skip_cleanup=True \ No newline at end of file + test_audit_event_for_authentication_failure_and_authorization_failure,nodes_init=4,services_init=kv-eventing-eventing-index:n1ql,dataset=default,groups=simple,reset_services=True,skip_cleanup=True,java_sdk_client=True \ No newline at end of file diff --git a/conf/eventing/eventing_tools.conf b/conf/eventing/eventing_tools.conf index 16b1cf8eb9..bcdbb44b7b 100644 --- a/conf/eventing/eventing_tools.conf +++ b/conf/eventing/eventing_tools.conf @@ -2,8 +2,8 @@ eventing.eventing_tools.EventingTools: #backup restore cases cover in backup restore testing #test_backup_create,nodes_init=1,services_init=kv:eventing,dataset=default,groups=simple #test_backup_create,nodes_init=1,services_init=kv:eventing,dataset=default,groups=simple,handler_code=bucket_op_with_cron_timers - test_eventing_lifecycle_with_couchbase_cli,nodes_init=4,services_init=kv-eventing-index-n1ql,dataset=default,groups=simple,reset_services=True,skip_cleanup=True - test_eventing_lifecycle_with_couchbase_cli_from_now,nodes_init=4,services_init=kv-eventing-index-n1ql,dataset=default,groups=simple,reset_services=True,skip_cleanup=True + test_eventing_lifecycle_with_couchbase_cli,nodes_init=4,services_init=kv-eventing-index-n1ql,dataset=default,groups=simple,reset_services=True,skip_cleanup=True,global_function_scope=True + test_eventing_lifecycle_with_couchbase_cli_from_now,nodes_init=4,services_init=kv-eventing-index-n1ql,dataset=default,groups=simple,reset_services=True,skip_cleanup=True,global_function_scope=True test_export_rest_import_cli,nodes_init=4,services_init=kv-eventing-index-n1ql,dataset=default,groups=simple,reset_services=True,skip_cleanup=True test_export_cli_import_rest,nodes_init=4,services_init=kv-eventing-index-n1ql,dataset=default,groups=simple,reset_services=True,skip_cleanup=True - test_importing_paused_function_via_cli,nodes_init=4,services_init=kv-eventing-index-n1ql,dataset=default,groups=simple,reset_services=True,skip_cleanup=True + test_importing_paused_function_via_cli,nodes_init=4,services_init=kv-eventing-index-n1ql,dataset=default,groups=simple,reset_services=True,skip_cleanup=True,global_function_scope=True diff --git a/pytests/eventing/eventing_base.py b/pytests/eventing/eventing_base.py index 754e8083f4..5b6ee39b68 100644 --- a/pytests/eventing/eventing_base.py +++ b/pytests/eventing/eventing_base.py @@ -851,7 +851,7 @@ def resume_handler_by_name(self, name,wait_for_resume=True): def check_word_count_eventing_log(self,function_name,word,expected_count,return_count_only=False): eventing_nodes = self.get_nodes_from_services_map(service_type="eventing", get_all_nodes=True) array_of_counts = [] - command = "cat /opt/couchbase/var/lib/couchbase/data/@eventing/"+ function_name +"* | grep -a \""+word+"\" | wc -l" + command = "cat /opt/couchbase/var/lib/couchbase/data/@eventing/b_travel-sample/s__default/"+ function_name +"* | grep -a \""+word+"\" | wc -l" for eventing_node in eventing_nodes: shell = RemoteMachineShellConnection(eventing_node) count, error = shell.execute_non_sudo_command(command) @@ -873,7 +873,7 @@ def check_word_count_eventing_log(self,function_name,word,expected_count,return_ def check_number_of_files(self): eventing_nodes = self.get_nodes_from_services_map(service_type="eventing", get_all_nodes=True) array_of_counts = [] - command = "cd /opt/couchbase/var/lib/couchbase/data/@eventing;ls | wc -l" + command = "cd /opt/couchbase/var/lib/couchbase/data/@eventing/b_travel-sample/s__default;ls | wc -l" for eventing_node in eventing_nodes: shell = RemoteMachineShellConnection(eventing_node) count, error = shell.execute_non_sudo_command(command) diff --git a/pytests/eventing/eventing_tools.py b/pytests/eventing/eventing_tools.py index c25f08bc57..1e2ab7cb55 100644 --- a/pytests/eventing/eventing_tools.py +++ b/pytests/eventing/eventing_tools.py @@ -258,7 +258,8 @@ def test_eventing_lifecycle_with_couchbase_cli(self): # import the function self._couchbase_cli_eventing(eventing_node, "Function_396275055_test_export_function", "import", "SUCCESS: Events imported", - file_name="Function_396275055_test_export_function.json") + file_name="Function_396275055_test_export_function.json", + function_scope=False) # deploy the function self._couchbase_cli_eventing(eventing_node, "Function_396275055_test_export_function", "deploy --boundary from-everything", "SUCCESS: Request to deploy the function was accepted") @@ -283,7 +284,8 @@ def test_eventing_lifecycle_with_couchbase_cli(self): skip_stats_validation=True) # list the function self._couchbase_cli_eventing(eventing_node, "Function_396275055_test_export_function", "list", - " Status: deployed") + " Status: deployed", name=False, + function_scope=False) # export the function self._couchbase_cli_eventing(eventing_node, "Function_396275055_test_export_function", "export", "SUCCESS: Function exported to: Function_396275055_test_export_function2.json", @@ -296,7 +298,7 @@ def test_eventing_lifecycle_with_couchbase_cli(self): # export-all functions self._couchbase_cli_eventing(eventing_node, "Function_396275055_test_export_function", "export-all", "SUCCESS: All functions exported to: export_all.json", - file_name="export_all.json", name=False) + file_name="export_all.json", name=False, function_scope=False) # check if the exported function actually exists exists = remote_client.file_exists("/root", "export_all.json") # check if the exported file exists @@ -335,7 +337,8 @@ def test_eventing_lifecycle_with_couchbase_cli_from_now(self): # import the function self._couchbase_cli_eventing(eventing_node, "Function_396275055_test_export_function", "import", "SUCCESS: Events imported", - file_name="Function_396275055_test_export_function.json") + file_name="Function_396275055_test_export_function.json", + function_scope=False) # deploy the function self._couchbase_cli_eventing(eventing_node, "Function_396275055_test_export_function", "deploy --boundary from-now", "SUCCESS: Request to deploy the function was accepted") @@ -363,7 +366,8 @@ def test_eventing_lifecycle_with_couchbase_cli_from_now(self): skip_stats_validation=True) # list the function self._couchbase_cli_eventing(eventing_node, "Function_396275055_test_export_function", "list", - " Status: deployed") + " Status: deployed", name=False, + function_scope=False) # export the function self._couchbase_cli_eventing(eventing_node, "Function_396275055_test_export_function", "export", "SUCCESS: Function exported to: Function_396275055_test_export_function2.json", @@ -376,7 +380,8 @@ def test_eventing_lifecycle_with_couchbase_cli_from_now(self): # export-all functions self._couchbase_cli_eventing(eventing_node, "Function_396275055_test_export_function", "export-all", "SUCCESS: All functions exported to: export_all.json", - file_name="export_all.json", name=False) + file_name="export_all.json", name=False, + function_scope=False) # check if the exported function actually exists exists = remote_client.file_exists("/root", "export_all.json") # check if the exported file exists @@ -424,7 +429,8 @@ def test_export_rest_import_cli(self): # import the function from cli self._couchbase_cli_eventing(eventing_node, self.function_name, "import", "SUCCESS: Events imported", - file_name="test_export_function.json") + file_name="test_export_function.json", + function_scope=False) # deploy the function self._couchbase_cli_eventing(eventing_node, self.function_name, "deploy --boundary from-now", @@ -548,16 +554,21 @@ def test_importing_paused_function_via_cli(self): remote_client.write_remote_file_single_quote("/root", "test_export_function.json", json.dumps(output, indent=4)) # import the function from cli - self._couchbase_cli_eventing(eventing_node, self.function_name, "import", - "SUCCESS: Events imported", - file_name="test_export_function.json") + try: + self._couchbase_cli_eventing(eventing_node, self.function_name, "import", + "SUCCESS: Events imported", + file_name="test_export_function.json", + function_scope=False) + except Exception as e: + self.log.info(e) + assert "ERR_INVALID_REQUEST" in str(e) and "another function with same name is already present" in str(e), True status = self.rest.get_composite_eventing_status() for i in range(len(status['apps'])): if status['apps'][i]['name'] == self.function_name and status['apps'][i]['composite_status'] != "paused": self.fail("Handler state changed which is not expected") self.undeploy_and_delete_function(body) - def _couchbase_cli_eventing(self, host, function_name, operation, result, file_name=None, name=True): + def _couchbase_cli_eventing(self, host, function_name, operation, result, file_name=None, name=True, function_scope=True): remote_client = RemoteMachineShellConnection(host) cmd = "couchbase-cli eventing-function-setup -c {0} -u {1} -p {2} --{3} ".format( host.ip, host.rest_username, host.rest_password, operation) @@ -565,6 +576,8 @@ def _couchbase_cli_eventing(self, host, function_name, operation, result, file_n cmd += " --name {0}".format(function_name) if file_name: cmd += " --file {0}".format(file_name) + if function_scope: + cmd += " --bucket '{0}' --scope '{1}'".format(self.function_scope["bucket"], self.function_scope["scope"]) command = "{0}/{1}".format(self.cli_command_location, cmd) log.info(command) output, error = remote_client.execute_command(command)