Re: [devel] [PATCH 1/1] log: Update the try again for admin operation [#3056]

2019-07-02 Thread Lennart Lund
Hi Canh,

Ack. Not tested

Thanks
Lennart


Från: Canh Van Truong 
Skickat: den 1 juli 2019 12:23
Till: Lennart Lund; Vu Minh Nguyen
Kopia: opensaf-devel@lists.sourceforge.net; Canh Van Truong
Ämne: [PATCH 1/1] log: Update the try again for admin operation [#3056]

The logtest 6 49 and logtest 6 50 failed because the admin
operation fail due to closing log file timeout.

Update to try again the command admin operation in test cases
---
 src/log/apitest/tet_LogOiOps.c | 176 +++--
 1 file changed, 101 insertions(+), 75 deletions(-)

diff --git a/src/log/apitest/tet_LogOiOps.c b/src/log/apitest/tet_LogOiOps.c
index 25f53d3a2..f771bea76 100644
--- a/src/log/apitest/tet_LogOiOps.c
+++ b/src/log/apitest/tet_LogOiOps.c
@@ -5479,18 +5479,32 @@ done:
_saLogStreamFixedLogRecordSize, 
SA_IMM_ATTR_SAUINT32T);
 }

+// Execute admin operation command and retry if it failed
+int execute_admin_operation_and_retries(const char *command)
+{
+   int rc = 0;
+   const uint64_t kWaitTime10s = 10 * 1000;
+   struct timespec timeout_time;
+   osaf_set_millis_timeout(kWaitTime10s, _time);
+   while (osaf_is_timeout(_time) == false) {
+   // Do the retries in case rotate/delete file fail due to
+   // filesystem issue
+   rc = systemCall(command);
+   if (rc == 0) break;
+   osaf_nanosleep();
+   }
+   return rc;
+}
+
 //
 // Test case for verifying the admin operation rotates log file is accepted
 // Steps:
 // 1. Create configuration app stream
 // 2. Verify command admin operation rotate log file is ok
 // 3. Delete configuration app stream
-//
 void admin_rotate_log_file(void)
 {
-   int rc = 0;
 char command[MAX_DATA];
-   const uint64_t kWaitTime10s = 10 * 1000;
 const char *object_dn =
 "safLgStrCfg=admin_rotate_file,safApp=safLogService";

@@ -5498,19 +5512,11 @@ void admin_rotate_log_file(void)
 sprintf(command, "immcfg -c SaLogStreamConfig %s "
 "-a saLogStreamPathName=. "
 "-a saLogStreamFileName=admin_rotate_file ", 
object_dn);
-   rc = systemCall(command);
+   int rc = systemCall(command);
 if (rc == 0) {
 // Admin operation rotate log file
 sprintf(command, "immadm -o 2 %s", object_dn);
-   struct timespec timeout_time;
-   osaf_set_millis_timeout(kWaitTime10s, _time);
-   do {
-   // Do the retries in case rotate file fail due to
-   // filesystem issue
-   osaf_nanosleep();
-   rc = systemCall(command);
-   } while (rc != 0 && !osaf_is_timeout(_time));
-
+   rc = execute_admin_operation_and_retries(command);
 rc_validate(rc, 0);

 // Delete object
@@ -5529,29 +5535,29 @@ void admin_rotate_log_file(void)
 // Step2: Verify that total is 4 cfg and log files (2 log files and 2 cfg 
files)
 void verRotatedLogCfgFile(void)
 {
-   char command1[MAX_DATA], command2[MAX_DATA];
 const char *object_dn =
 "safLgStrCfg=verRotatedFile,safApp=safLogService";
 const int max_file = 2;
-   char num_files_c[10];
-   uint32_t num_files = 0;

 // Command to create configuration application stream
-   sprintf(command1, "immcfg -c SaLogStreamConfig %s "
- "-a saLogStreamPathName=. "
- "-a saLogStreamFileName=verRotatedFile"
- " -a saLogStreamMaxFilesRotated=%d",
- object_dn, max_file);
+   char create_cfg_application_stream[MAX_DATA];
+   sprintf(create_cfg_application_stream,
+   "immcfg -c SaLogStreamConfig %s "
+   "-a saLogStreamPathName=. "
+   "-a saLogStreamFileName=verRotatedFile1"
+   " -a saLogStreamMaxFilesRotated=%d",
+   object_dn, max_file);
 // Command to delete configuration application stream
-   sprintf(command2, "immcfg -d %s", object_dn);
+   char delete_cfg_application_stream[MAX_DATA];
+   sprintf(delete_cfg_application_stream, "immcfg -d %s", object_dn);

 // Create and delete the app stream 4 times.
 // Log/cfg are created during creating stream.
 for (int i = 0; i < max_file + 1; ++i) {
-   int rc = systemCall(command1);
+   int rc = systemCall(create_cfg_application_stream);
 if (rc == 0) {
 osaf_nanosleep();
-   rc = systemCall(command2);
+   rc = systemCall(delete_cfg_application_stream);
 osaf_nanosleep();
 }
 if (rc != 0) {
@@ -5559,21 +5565,28 @@ void verRotatedLogCfgFile(void)
  

[devel] [PATCH 1/1] log: Update the try again for admin operation [#3056]

2019-07-01 Thread Canh Van Truong
The logtest 6 49 and logtest 6 50 failed because the admin
operation fail due to closing log file timeout.

Update to try again the command admin operation in test cases
---
 src/log/apitest/tet_LogOiOps.c | 176 +++--
 1 file changed, 101 insertions(+), 75 deletions(-)

diff --git a/src/log/apitest/tet_LogOiOps.c b/src/log/apitest/tet_LogOiOps.c
index 25f53d3a2..f771bea76 100644
--- a/src/log/apitest/tet_LogOiOps.c
+++ b/src/log/apitest/tet_LogOiOps.c
@@ -5479,18 +5479,32 @@ done:
   _saLogStreamFixedLogRecordSize, SA_IMM_ATTR_SAUINT32T);
 }
 
+// Execute admin operation command and retry if it failed
+int execute_admin_operation_and_retries(const char *command)
+{
+   int rc = 0;
+   const uint64_t kWaitTime10s = 10 * 1000;
+   struct timespec timeout_time;
+   osaf_set_millis_timeout(kWaitTime10s, _time);
+   while (osaf_is_timeout(_time) == false) {
+   // Do the retries in case rotate/delete file fail due to
+   // filesystem issue
+   rc = systemCall(command);
+   if (rc == 0) break;
+   osaf_nanosleep();
+   }
+   return rc;
+}
+
 //
 // Test case for verifying the admin operation rotates log file is accepted
 // Steps:
 // 1. Create configuration app stream
 // 2. Verify command admin operation rotate log file is ok
 // 3. Delete configuration app stream
-//
 void admin_rotate_log_file(void)
 {
-   int rc = 0;
char command[MAX_DATA];
-   const uint64_t kWaitTime10s = 10 * 1000;
const char *object_dn =
"safLgStrCfg=admin_rotate_file,safApp=safLogService";
 
@@ -5498,19 +5512,11 @@ void admin_rotate_log_file(void)
sprintf(command, "immcfg -c SaLogStreamConfig %s "
"-a saLogStreamPathName=. "
"-a saLogStreamFileName=admin_rotate_file ", object_dn);
-   rc = systemCall(command);
+   int rc = systemCall(command);
if (rc == 0) {
// Admin operation rotate log file
sprintf(command, "immadm -o 2 %s", object_dn);
-   struct timespec timeout_time;
-   osaf_set_millis_timeout(kWaitTime10s, _time);
-   do {
-   // Do the retries in case rotate file fail due to
-   // filesystem issue
-   osaf_nanosleep();
-   rc = systemCall(command);
-   } while (rc != 0 && !osaf_is_timeout(_time));
-
+   rc = execute_admin_operation_and_retries(command);
rc_validate(rc, 0);
 
// Delete object
@@ -5529,29 +5535,29 @@ void admin_rotate_log_file(void)
 // Step2: Verify that total is 4 cfg and log files (2 log files and 2 cfg 
files)
 void verRotatedLogCfgFile(void)
 {
-   char command1[MAX_DATA], command2[MAX_DATA];
const char *object_dn =
"safLgStrCfg=verRotatedFile,safApp=safLogService";
const int max_file = 2;
-   char num_files_c[10];
-   uint32_t num_files = 0;
 
// Command to create configuration application stream
-   sprintf(command1, "immcfg -c SaLogStreamConfig %s "
- "-a saLogStreamPathName=. "
- "-a saLogStreamFileName=verRotatedFile"
- " -a saLogStreamMaxFilesRotated=%d",
- object_dn, max_file);
+   char create_cfg_application_stream[MAX_DATA];
+   sprintf(create_cfg_application_stream,
+   "immcfg -c SaLogStreamConfig %s "
+   "-a saLogStreamPathName=. "
+   "-a saLogStreamFileName=verRotatedFile1"
+   " -a saLogStreamMaxFilesRotated=%d",
+   object_dn, max_file);
// Command to delete configuration application stream
-   sprintf(command2, "immcfg -d %s", object_dn);
+   char delete_cfg_application_stream[MAX_DATA];
+   sprintf(delete_cfg_application_stream, "immcfg -d %s", object_dn);
 
// Create and delete the app stream 4 times.
// Log/cfg are created during creating stream.
for (int i = 0; i < max_file + 1; ++i) {
-   int rc = systemCall(command1);
+   int rc = systemCall(create_cfg_application_stream);
if (rc == 0) {
osaf_nanosleep();
-   rc = systemCall(command2);
+   rc = systemCall(delete_cfg_application_stream);
osaf_nanosleep();
}
if (rc != 0) {
@@ -5559,21 +5565,28 @@ void verRotatedLogCfgFile(void)
return;
}
}
-   // Command to count number of log/cfg files on disk
-   sprintf(command1, "find %s -type f -mmin -1 "
- "| egrep '%s.*\\.[log$\\|cfg$]' "
- "| wc -l | awk '{printf $1}'",
- 

[devel] [PATCH 1/1] log: Update the try again for admin operation [#3056]

2019-06-27 Thread Canh Van Truong
The logtest 6 49 and logtest 6 50 failed because the admin
operation fail due to closing log file timeout.

Update to try again the command admin operation in test cases
---
 src/log/apitest/tet_LogOiOps.c | 54 ++
 1 file changed, 34 insertions(+), 20 deletions(-)

diff --git a/src/log/apitest/tet_LogOiOps.c b/src/log/apitest/tet_LogOiOps.c
index 25f53d3a2..4133b6bbe 100644
--- a/src/log/apitest/tet_LogOiOps.c
+++ b/src/log/apitest/tet_LogOiOps.c
@@ -5479,6 +5479,23 @@ done:
   _saLogStreamFixedLogRecordSize, SA_IMM_ATTR_SAUINT32T);
 }
 
+// Execute admin operation command and retry if it failed
+int execute_admin_operation_and_retries(const char *command)
+{
+   int rc = 0;
+   const uint64_t kWaitTime10s = 10 * 1000;
+   struct timespec timeout_time;
+   osaf_set_millis_timeout(kWaitTime10s, _time);
+   while (!osaf_is_timeout(_time)) {
+   // Do the retries in case rotate/delete file fail due to
+   // filesystem issue
+   rc = systemCall(command);
+   if (rc == 0) break;
+   osaf_nanosleep();
+   }
+   return rc;
+}
+
 //
 // Test case for verifying the admin operation rotates log file is accepted
 // Steps:
@@ -5490,7 +5507,6 @@ void admin_rotate_log_file(void)
 {
int rc = 0;
char command[MAX_DATA];
-   const uint64_t kWaitTime10s = 10 * 1000;
const char *object_dn =
"safLgStrCfg=admin_rotate_file,safApp=safLogService";
 
@@ -5502,15 +5518,7 @@ void admin_rotate_log_file(void)
if (rc == 0) {
// Admin operation rotate log file
sprintf(command, "immadm -o 2 %s", object_dn);
-   struct timespec timeout_time;
-   osaf_set_millis_timeout(kWaitTime10s, _time);
-   do {
-   // Do the retries in case rotate file fail due to
-   // filesystem issue
-   osaf_nanosleep();
-   rc = systemCall(command);
-   } while (rc != 0 && !osaf_is_timeout(_time));
-
+   rc = execute_admin_operation_and_retries(command);
rc_validate(rc, 0);
 
// Delete object
@@ -5568,7 +5576,8 @@ void verRotatedLogCfgFile(void)
FILE *fp = popen(command1, "r");
 
// Get number of cfg and log file
-   while (fgets(num_files_c, sizeof(num_files_c) - 1, fp) != NULL) {};
+   while (fgets(num_files_c, sizeof(num_files_c) - 1, fp) != NULL) {
+   };
pclose(fp);
 
// Verify cfg/log files are rotated by checking
@@ -5588,7 +5597,7 @@ void verRotatedLogCfgFile(void)
 void verRotatedLogCfgFile2(void)
 {
int rc;
-   char command[MAX_DATA];
+   char command[MAX_DATA], command1[MAX_DATA];
const char *object_dn =
"safLgStrCfg=verRotatedFile2,safApp=safLogService";
char num_files_c[10];
@@ -5600,20 +5609,24 @@ void verRotatedLogCfgFile2(void)
 "-a saLogStreamFileName=verRotatedFile2"
 " -a saLogStreamMaxFilesRotated=2",
 object_dn);
+   // Command to delete configuration application stream
+   sprintf(command1, "immcfg -d %s", object_dn);
+
// Create  the app stream.
rc = systemCall(command);
if (rc != 0) {
rc_validate(rc, 0);
return;
}
+   osaf_nanosleep();
 
// Do admin operation to rotate log file without the parameter
// Two new log files are created. One oldest file is removed.
sprintf(command, "immadm -o 2 %s", object_dn);
for (int i = 0; i < 2; ++i) {
-   osaf_nanosleep();
-   rc = systemCall(command);
+   rc = execute_admin_operation_and_retries(command);
if (rc != 0) {
+   systemCall(command1);
rc_validate(rc, 0);
return;
}
@@ -5626,13 +5639,12 @@ void verRotatedLogCfgFile2(void)
 log_root_path, "verRotatedFile2");
FILE *fp = popen(command, "r");
// Get number of log files
-   while (fgets(num_files_c, sizeof(num_files_c) - 1, fp) != NULL) {};
+   while (fgets(num_files_c, sizeof(num_files_c) - 1, fp) != NULL) {
+   };
pclose(fp);
 
-   // Command to delete configuration application stream
-   sprintf(command, "immcfg -d %s", object_dn);
// Close the application stream
-   rc = systemCall(command);
+   rc = systemCall(command1);
if (rc != 0) {
rc_validate(rc, 0);
return;
@@ -5689,8 +5701,9 @@ void verRotatedLogCfgFile3(void)
// Admin operation to remove 1 oldest log files
sprintf(command1, "immadm -o 2 -p numberOfFilesToRemove:SA_UINT32_T:1 "
  "%s", object_dn);
-   rc =