Bug 42465 - (4.1r2) --dry-run increases username counter
(4.1r2) --dry-run increases username counter
Status: CLOSED FIXED
Product: UCS@school
Classification: Unclassified
Component: Import scripts
UCS@school 4.1 R2
Other Linux
: P5 normal (vote)
: UCS@school 4.1 R2 v14
Assigned To: Daniel Tröder
Florian Best
:
Depends on:
Blocks: 44838 44898
  Show dependency treegraph
 
Reported: 2016-09-21 17:53 CEST by Florian Best
Modified: 2017-10-16 21:33 CEST (History)
3 users (show)

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: 3: Simply Wrong: The implementation doesn't match the docu
Who will be affected by this bug?: 3: Will affect average number of installed domains
How will those affected feel about the bug?: 2: A Pain – users won’t like this once they notice it
User Pain: 0.103
Enterprise Customer affected?:
School Customer affected?: Yes
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional): Usability
Max CVSS v3 score:


Attachments
42465_username_counter_dry-run.patch (7.51 KB, patch)
2017-06-22 10:51 CEST, Daniel Tröder
Details | Diff
42465_username_counter_dry-run_ucs-test.patch (11.80 KB, patch)
2017-06-22 10:53 CEST, Daniel Tröder
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Best univentionstaff 2016-09-21 17:53:24 CEST
I started an import with --dry-run which increased
ucsschoolUsernameNextNumber: 7
to
ucsschoolUsernameNextNumber: 9

Which should only happen in a real import situation.

In general I think this is not good to make the ldap modify call everytime but only once after the full import and increase a internal python variable instead.

This makes the function UsernameHandler.format_username() also very slow and changing this could improve the performance very much!

As one can see calling the function 100 times takes 10 seconds:

# python -m timeit -s 'from ucsschool.importer.utils.username_handler import UsernameHandler; u = UsernameHandler(20)' -n 100 'u.format_username("foo[ALWAYSCOUNTER]")'
100 loops, best of 3: 92.2 msec per loop

Also if importing of the users fails the counter gets increased.
Comment 1 Sönke Schwardt-Krummrich univentionstaff 2016-09-22 11:55:11 CEST
(In reply to Florian Best from comment #0)
> I started an import with --dry-run which increased
> ucsschoolUsernameNextNumber: 7
> to
> ucsschoolUsernameNextNumber: 9
> 
> Which should only happen in a real import situation.

Yes, this is a problem.
 
> In general I think this is not good to make the ldap modify call everytime
> but only once after the full import and increase a internal python variable
> instead.
> 
> This makes the function UsernameHandler.format_username() also very slow and
> changing this could improve the performance very much!

But it makes the import in general more unreliable, because the window for conflict gets even larger. If a manual user import happens during a larger multi-hour-long import, the chance of a conflict is extremely high if the values are only changed after the import is finished.
 
> As one can see calling the function 100 times takes 10 seconds:
> 
> # python -m timeit -s 'from ucsschool.importer.utils.username_handler import
> UsernameHandler; u = UsernameHandler(20)' -n 100
> 'u.format_username("foo[ALWAYSCOUNTER]")'
> 100 loops, best of 3: 92.2 msec per loop
Comment 2 Michel Smidt 2017-05-30 20:21:14 CEST
(In reply to Sönke Schwardt-Krummrich from comment #1)
> (In reply to Florian Best from comment #0)
> > I started an import with --dry-run which increased
> > ucsschoolUsernameNextNumber: 7
> > to
> > ucsschoolUsernameNextNumber: 9
> > 
> > Which should only happen in a real import situation.
> 
> Yes, this is a problem.
This is a real bad problem because no customer understand why the usernames of the initial import all start with e.g. username3
Happened today at the startup workshop.
Comment 3 Daniel Tröder univentionstaff 2017-05-31 08:08:21 CEST
This bug is scheduled to be fixed in the next 4 weeks.
Comment 4 Daniel Tröder univentionstaff 2017-06-22 10:51:28 CEST
Created attachment 8952 [details]
42465_username_counter_dry-run.patch

* when used with --dry-run, use a dict() instead of LDAP as counter storage
* initialize values in dict from LDAP (using a r/o connection)
* adapt code and documentation to changed signature

M       doc/manual/ucsschool-import-handbuch-4.1r2.xml
M       ucs-school-import/debian/changelog
M       ucs-school-import/modules/ucsschool/importer/default_user_import_factory.py
M       ucs-school-import/modules/ucsschool/importer/models/import_user.py
M       ucs-school-import/modules/ucsschool/importer/utils/ldap_connection.py
M       ucs-school-import/modules/ucsschool/importer/utils/username_handler.py
Comment 5 Daniel Tröder univentionstaff 2017-06-22 10:53:45 CEST
Created attachment 8953 [details]
42465_username_counter_dry-run_ucs-test.patch

Add test:
1) import user for real
2) delete user
3) import same user with --dry-run
→ username counter should not rise

A  +    ucs-test-ucsschool/90_ucsschool/215_import-users_username_dry-run
M       ucs-test-ucsschool/debian/changelog
Comment 6 Daniel Tröder univentionstaff 2017-06-26 16:26:42 CEST
r80496: UsernameHandler does not increase counter in LDAP with dry_run anymore
r80497: merge to UCS@school 4.2
r80498+r80499: advisories

"dry_run" has to be set in __init__(), to prevent a dependency on the configuration singleton. Using the configuration object requires a lot of initialization that is not needed for this utility class.

Overwriting UsernameHandler.get_storage_backend() allows to change the storage backend.

Package: ucs-school-import
Version: 14.0.16-44.335.201706261615
Branch: ucs_4.1-0
Scope: ucs-school-4.1r2

Package: ucs-school-import
Version: 15.0.0-5A~4.2.0.201706261618
Branch: ucs_4.2-0
Scope: ucs-school-4.2
Comment 7 Daniel Tröder univentionstaff 2017-06-27 11:33:12 CEST
r80504: don't create LDAP connection at import time
r80506: advisories

ucs-school-import (14.0.16-45.336.201706271132)
Comment 8 Daniel Tröder univentionstaff 2017-06-27 18:42:31 CEST
Fixed: 80536, 80537, 80538
Comment 9 Florian Best univentionstaff 2017-06-29 16:50:05 CEST
OK: --dry-run causes the counter to not increased
OK: for modifications the counter is not increased
OK: import of multiple users / single users
OK: YAML
Comment 10 Sönke Schwardt-Krummrich univentionstaff 2017-10-16 21:33:07 CEST
UCS@school 4.1 R2 v14 has been released.

http://docs.software-univention.de/changelog-ucsschool-4.1R2v14-de.html

If this error occurs again, please clone this bug.