浏览代码

Ticket 50303 - Add task creation date to task data

Description: Add a new attribute to the slapi task entry containing
             the start date. This provides a nice convenience without
             having to change LDAP clients.

https://pagure.io/389-ds-base/issue/50303

Reviewed by: firstyear & spichugi(Thanks!)
Mark Reynolds 6 年之前
父节点
当前提交
78003de289
共有 4 个文件被更改,包括 36 次插入11 次删除
  1. 18 6
      dirsrvtests/tests/suites/basic/basic_test.py
  2. 9 1
      ldap/schema/02common.ldif
  3. 3 3
      ldap/servers/slapd/slap.h
  4. 6 1
      ldap/servers/slapd/task.c

+ 18 - 6
dirsrvtests/tests/suites/basic/basic_test.py

@@ -248,24 +248,32 @@ def test_basic_import_export(topology_st, import_example_ldif):
 
     log.info('Running test_basic_import_export...')
 
-    tmp_dir = '/tmp'
-
     #
     # Test online/offline LDIF imports
     #
     topology_st.standalone.start()
 
     # Generate a test ldif (50k entries)
+    log.info("Generating LDIF...")
     ldif_dir = topology_st.standalone.get_ldif_dir()
     import_ldif = ldif_dir + '/basic_import.ldif'
     dbgen(topology_st.standalone, 50000, import_ldif, DEFAULT_SUFFIX)
 
     # Online
+    log.info("Importing LDIF online...")
     r = ImportTask(topology_st.standalone)
     r.import_suffix_from_ldif(ldiffile=import_ldif, suffix=DEFAULT_SUFFIX)
+
+    # Good as place as any to quick test the task has some expected attributes
+    assert r.present('nstaskcreated')
+    assert r.present('nstasklog')
+    assert r.present('nstaskcurrentitem')
+    assert r.present('nstasktotalitems')
+
     r.wait()
 
     # Offline
+    log.info("Importing LDIF offline...")
     topology_st.standalone.stop()
     if not topology_st.standalone.ldif2db(DEFAULT_BENAME, None, None, None, import_ldif):
         log.fatal('test_basic_import_export: Offline import failed')
@@ -277,14 +285,15 @@ def test_basic_import_export(topology_st, import_example_ldif):
     #
 
     # Online export
+    log.info("Exporting LDIF online...")
     export_ldif = ldif_dir + '/export.ldif'
 
-
     r = ExportTask(topology_st.standalone)
     r.export_suffix_to_ldif(ldiffile=export_ldif, suffix=DEFAULT_SUFFIX)
     r.wait()
 
     # Offline export
+    log.info("Exporting LDIF offline...")
     topology_st.standalone.stop()
     if not topology_st.standalone.db2ldif(DEFAULT_BENAME, (DEFAULT_SUFFIX,),
                                           None, None, None, export_ldif):
@@ -296,6 +305,7 @@ def test_basic_import_export(topology_st, import_example_ldif):
     #
     # Cleanup - Import the Example LDIF for the other tests in this suite
     #
+    log.info("Restore datrabase, import initial LDIF...")
     ldif = '%s/dirsrv/data/Example.ldif' % topology_st.standalone.get_data_dir()
     import_ldif = topology_st.standalone.get_ldif_dir() + "/Example.ldif"
     shutil.copyfile(ldif, import_ldif)
@@ -361,6 +371,7 @@ def test_basic_backup(topology_st, import_example_ldif):
 
     log.info('test_basic_backup: PASSED')
 
+
 def test_basic_db2index(topology_st, import_example_ldif):
     """Assert db2index can operate correctly.
 
@@ -897,7 +908,7 @@ def create_users(topology_st):
 
     log.info('Adding 5 test users')
     for name in user_names:
-        user = users.create(properties={
+        users.create(properties={
             'uid': name,
             'sn': name,
             'cn': name,
@@ -1015,6 +1026,7 @@ def test_connection_buffer_size(topology_st):
         with pytest.raises(ldap.OPERATIONS_ERROR):
             topology_st.standalone.config.replace('nsslapd-connection-buffer', value)
 
+
 @pytest.mark.bz1637439
 def test_critical_msg_on_empty_range_idl(topology_st):
     """Doing a range index lookup should not report a critical message even if IDL is empty
@@ -1087,6 +1099,7 @@ def test_critical_msg_on_empty_range_idl(topology_st):
     # Step 5
     assert not topology_st.standalone.searchErrorsLog('CRIT - list_candidates - NULL idl was recieved from filter_candidates_ext.')
 
+
 def audit_pattern_found(server, log_pattern):
     file_obj = open(server.ds_paths.audit_log, "r")
 
@@ -1102,6 +1115,7 @@ def audit_pattern_found(server, log_pattern):
 
     return found
 
+
 @pytest.mark.ds50026
 def test_ticketldbm_audit(topology_st):
     """When updating LDBM config attributes, those attributes/values are not listed
@@ -1208,5 +1222,3 @@ if __name__ == '__main__':
     # -s for DEBUG mode
     CURRENT_FILE = os.path.realpath(__file__)
     pytest.main("-s %s" % CURRENT_FILE)
-
-

+ 9 - 1
ldap/schema/02common.ldif

@@ -137,6 +137,13 @@ attributeTypes: ( 2.16.840.1.113730.3.1.3023 NAME 'nsViewFilter' DESC 'Netscape
 attributeTypes: ( 2.16.840.1.113730.3.1.2063 NAME 'nsEncryptionAlgorithm' DESC 'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
 attributeTypes: ( 2.16.840.1.113730.3.1.2094 NAME 'nsslapd-parent-suffix' DESC 'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 X-ORIGIN 'Netscape' )
 attributeTypes: ( 2.16.840.1.113730.3.1.2401 NAME 'ConflictCSN' DESC 'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 USAGE directoryOperation X-ORIGIN 'Netscape Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2085 NAME 'isReplicated' DESC 'Changelog attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 X-ORIGIN 'Netscape Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2354 NAME 'nsTaskLog' DESC 'Slapi Task log' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE X-ORIGIN '389 Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2355 NAME 'nsTaskStatus' DESC 'Slapi Task status' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE X-ORIGIN '389 Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2356 NAME 'nsTaskExitCode' DESC 'Slapi Task exit code' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE X-ORIGIN '389 Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2357 NAME 'nsTaskCurrentItem' DESC 'Slapi Task item' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE X-ORIGIN '389 Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2358 NAME 'nsTaskTotalItems' DESC 'Slapi Task total items' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE X-ORIGIN '389 Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2359 NAME 'nsTaskCreated' DESC 'Slapi Task creation date' SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 SINGLE-VALUE X-ORIGIN '389 Directory Server' )
 #
 # objectclasses:
 #
@@ -169,4 +176,5 @@ objectClasses: ( 2.16.840.1.113730.3.2.503 NAME 'nsDSWindowsReplicationAgreement
 objectClasses: ( 2.16.840.1.113730.3.2.128 NAME 'costemplate' DESC 'Netscape defined objectclass' SUP top MAY ( cn $ cospriority ) X-ORIGIN 'Netscape Directory Server' )
 objectClasses: ( 2.16.840.1.113730.3.2.304 NAME 'nsView' DESC 'Netscape defined objectclass' SUP top AUXILIARY MAY ( nsViewFilter $ description ) X-ORIGIN 'Netscape Directory Server' )
 objectClasses: ( 2.16.840.1.113730.3.2.316 NAME 'nsAttributeEncryption' DESC 'Netscape defined objectclass' SUP top MUST ( cn $ nsEncryptionAlgorithm ) X-ORIGIN 'Netscape Directory Server' )
-attributeTypes: ( 2.16.840.1.113730.3.1.2085 NAME 'isReplicated' DESC 'Changelog attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 X-ORIGIN 'Netscape Directory Server' )
+objectClasses: ( 2.16.840.1.113730.3.2.335 NAME 'nsSlapiTask' DESC 'Slapi_Task objectclass' SUP top MUST ( cn ) MAY ( ttl $ nsTaskLog $ nsTaskStatus $ nsTaskExitCode $ nsTaskCurrentItem $ nsTaskTotalItems $ nsTaskCreated ) X-ORIGIN '389 Directory Server' )
+

+ 3 - 3
ldap/servers/slapd/slap.h

@@ -1731,13 +1731,13 @@ struct slapi_task
     int task_flags;            /* (see above) */
     char *task_status;         /* transient status info */
     char *task_log;            /* appended warnings, etc */
+    char task_date[SLAPI_TIMESTAMP_BUFSIZE]; /* Date/time when task was created */
     void *task_private;        /* allow opaque data to be stashed in the task */
     TaskCallbackFn cancel;     /* task has been cancelled by user */
     TaskCallbackFn destructor; /* task entry is being destroyed */
     int task_refcount;
-    void *origin_plugin;   /* If this is a plugin create task, store the plugin object */
-    PRLock *task_log_lock; /* To protect task_log to be realloced if
-                                   it's in use */
+    void *origin_plugin;       /* If this is a plugin create task, store the plugin object */
+    PRLock *task_log_lock;     /* To protect task_log to be realloced if it's in use */
 } slapi_task;
 /* End of interface to support online tasks **********************************/
 

+ 6 - 1
ldap/servers/slapd/task.c

@@ -45,6 +45,7 @@ static int shutting_down = 0;
 #define TASK_EXITCODE_NAME "nsTaskExitCode"
 #define TASK_PROGRESS_NAME "nsTaskCurrentItem"
 #define TASK_WORK_NAME "nsTaskTotalItems"
+#define TASK_DATE_NAME "nsTaskCreated"
 
 #define DEFAULT_TTL "3600"                        /* seconds */
 #define TASK_SYSCONFIG_FILE_ATTR "sysconfigfile" /* sysconfig reload task file attr */
@@ -347,6 +348,7 @@ slapi_task_status_changed(Slapi_Task *task)
     sprintf(s3, "%d", task->task_work);
     NEXTMOD(TASK_PROGRESS_NAME, s2);
     NEXTMOD(TASK_WORK_NAME, s3);
+    NEXTMOD(TASK_DATE_NAME, task->task_date);
     /* only add the exit code when the job is done */
     if ((task->task_state == SLAPI_TASK_FINISHED) ||
         (task->task_state == SLAPI_TASK_CANCELLED)) {
@@ -604,6 +606,9 @@ new_task(const char *rawdn, void *plugin)
         return NULL;
     }
 
+    /* Set the task creation time */
+    slapi_timestamp_utc_hr(task->task_date, SLAPI_TIMESTAMP_BUFSIZE);
+
     /* Now take our lock to setup everything correctly. */
     PR_Lock(task->task_log_lock);
 
@@ -687,7 +692,7 @@ destroy_task(time_t when, void *arg)
     slapi_delete_internal_pb(pb);
     slapi_pblock_destroy(pb);
 
-    slapi_ch_free((void **)&task->task_dn);
+    slapi_ch_free_string(&task->task_dn);
     slapi_ch_free((void **)&task);
 }