Skip to content

Commit

Permalink
Eventing: fixing log rotation and cli tests
Browse files Browse the repository at this point in the history
Change-Id: I638ce5f2f27e4740b599df7cc0c7b65877d9ff66
Reviewed-on: https://review.couchbase.org/c/testrunner/+/171617
Reviewed-by: Chanabasappa Ghali <chanabasappa.ghali@couchbase.com>
Tested-by: Sujay Gad <sujay.gad@couchbase.com>
  • Loading branch information
Sujay2611 committed Mar 7, 2022
1 parent c7debb2 commit e0ecacb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion conf/eventing/eventing_logging.conf
Expand Up @@ -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
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
6 changes: 3 additions & 3 deletions conf/eventing/eventing_tools.conf
Expand Up @@ -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
4 changes: 2 additions & 2 deletions pytests/eventing/eventing_base.py
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
35 changes: 24 additions & 11 deletions pytests/eventing/eventing_tools.py
Expand Up @@ -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")
Expand All @@ -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",
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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",
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -548,23 +554,30 @@ 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)
if name:
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)
Expand Down

0 comments on commit e0ecacb

Please sign in to comment.