#50304 Ticket 50303 - Add task creation date to task data
Closed 3 years ago by spichugi. Opened 5 years ago by mreynolds.
mreynolds/389-ds-base ticket50303  into  master

@@ -248,24 +248,32 @@ 

  

      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 @@ 

      #

  

      # 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 @@ 

      #

      # 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 @@ 

  

      log.info('test_basic_backup: PASSED')

  

+ 

  def test_basic_db2index(topology_st, import_example_ldif):

      """Assert db2index can operate correctly.

  
@@ -897,7 +908,7 @@ 

  

      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 @@ 

          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 @@ 

      # 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 @@ 

  

      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 @@ 

      # -s for DEBUG mode

      CURRENT_FILE = os.path.realpath(__file__)

      pytest.main("-s %s" % CURRENT_FILE)

- 

- 

file modified
+9 -1
@@ -137,6 +137,13 @@ 

  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.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' )

+ 

file modified
+3 -3
@@ -1731,13 +1731,13 @@ 

      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 **********************************/

  

file modified
+6 -1
@@ -45,6 +45,7 @@ 

  #define TASK_EXITCODE_NAME "nsTaskExitCode"

  #define TASK_PROGRESS_NAME "nsTaskCurrentItem"

  #define TASK_WORK_NAME "nsTaskTotalItems"

+ #define TASK_DATE_NAME "nsTaskCreated"

Is this attribute in schema?

  

  #define DEFAULT_TTL "3600"                        /* seconds */

  #define TASK_SYSCONFIG_FILE_ATTR "sysconfigfile" /* sysconfig reload task file attr */
@@ -347,6 +348,7 @@ 

      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 @@ 

          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 @@ 

      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);

  }

  

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: ?

The code looks good to me. Also the change works and outputs the date in a format:

nstaskcreated: 20190327154713Z

Could you please add some simple test for the feature?

Is this attribute in schema?

Is this attribute in schema?

None of the task attributes are in the schema :-/

Is this a time where we should add them then?

rebased onto c99aef54a7467b77e2a4315b28d0ecee82f00aaa

5 years ago

@firstyear - updated schema. I left "extensibleObject" in the task creation because it looks like many other tasks randomly add unknown attributes. We can look into that later, but at least the core task schema is defined.

Please review...

rebased onto 39ea1360782748df8a4c20fd12bda5579db87ecf

5 years ago

rebased onto cb56598ca3c6e39b4b53f478a6dd8d46f15ebf5a

5 years ago

rebased onto 8f6d8db76ebcccb2d55610eb0c475c2af6d0ef5c

5 years ago

Perfect, thank you! If every time wedo this, we add a bit more, we'll eventually be rid of extensibleObject in dse.ldif ....

Ack!

rebased onto 78003de

5 years ago

Pull-Request has been merged by mreynolds

5 years ago

389-ds-base is moving from Pagure to Github. This means that new issues and pull requests
will be accepted only in 389-ds-base's github repository.

This pull request has been cloned to Github as issue and is available here:
- https://github.com/389ds/389-ds-base/issues/3363

If you want to continue to work on the PR, please navigate to the github issue,
download the patch from the attachments and file a new pull request.

Thank you for understanding. We apologize for all inconvenience.

Pull-Request has been closed by spichugi

3 years ago