Bug 44838 - (4.2) --dry-run increases username counter
(4.2) --dry-run increases username counter
Status: CLOSED FIXED
Product: UCS@school
Classification: Unclassified
Component: Import scripts
UCS@school 4.2
Other Linux
: P5 normal (vote)
: UCS@school 4.2 v4
Assigned To: Daniel Tröder
Florian Best
:
Depends on: 42465
Blocks:
  Show dependency treegraph
 
Reported: 2017-06-22 08:48 CEST by Daniel Tröder
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

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Tröder univentionstaff 2017-06-22 08:48:51 CEST
+++ This bug was initially created as a clone of Bug #42465 +++

I started an import with --dry-run which increased
ucsschoolUsernameNextNumber: 7
to
ucsschoolUsernameNextNumber: 9

Which should only happen in a real import situation.

[..]

Merge from 4.1 to 4.2 and QA in 4.2 too.
Comment 1 Daniel Tröder univentionstaff 2017-06-26 16:28:26 CEST
oops... all commits for 4.2 have been tagged for the 4.1r2 bug:

r80497: UsernameHandler does not increase counter in LDAP with dry_run anymore
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: 15.0.0-5A~4.2.0.201706261618
Branch: ucs_4.2-0
Scope: ucs-school-4.2
Comment 2 Florian Best univentionstaff 2017-06-27 09:52:30 CEST
REOPEN:
* use ucr['ldap/base'] instead of lo.base
* get_machine_connection() and get_admin_connection() is called at import time:
+	ldap_backend = LdapStorageBackend(get_machine_connection())
→ calls get_machine_connection()

+class LdapStorageBackend(UsernameCounterStorageBackend):
+	def __init__(self, lo=None, pos=None):
+		if lo and pos:
+			self.lo, _pos = lo, pos
+		else:
+			self.lo, _pos = get_admin_connection()
→ as pos is not given in the above call get_admin_connection() is called.
Comment 3 Daniel Tröder univentionstaff 2017-06-27 11:33:14 CEST
(In reply to Florian Best from comment #2)
> REOPEN:
> * use ucr['ldap/base'] instead of lo.base
> * get_machine_connection() and get_admin_connection() is called at import
> time:
> +	ldap_backend = LdapStorageBackend(get_machine_connection())
> → calls get_machine_connection()
fixed

> +class LdapStorageBackend(UsernameCounterStorageBackend):
> +	def __init__(self, lo=None, pos=None):
> +		if lo and pos:
> +			self.lo, _pos = lo, pos
> +		else:
> +			self.lo, _pos = get_admin_connection()
> → as pos is not given in the above call get_admin_connection() is called.
get_machine_connection() return a 2-tuple (lo, pos)

r80505: don't create LDAP connection at import time
r80506: advisories

ucs-school-import (15.0.0-6A~4.2.0.201706271130)
Comment 4 Florian Best univentionstaff 2017-06-27 11:43:23 CEST
REOPEN:
(In reply to Daniel Tröder from comment #3)
> > +class LdapStorageBackend(UsernameCounterStorageBackend):
> > +	def __init__(self, lo=None, pos=None):
> > +		if lo and pos:
> > +			self.lo, _pos = lo, pos
> > +		else:
> > +			self.lo, _pos = get_admin_connection()
> > → as pos is not given in the above call get_admin_connection() is called.
> get_machine_connection() return a 2-tuple (lo, pos)
Yes, it returns a 2-tuple.
And a 2-tuple is not two arguments.

LdapStorageBackend(get_machine_connection())
→ results in the call LdapStorageBackend((connection, position), None)
where the parameter lo is (connection, position) and po is None.

You can use 
LdapStorageBackend(*get_machine_connection())
Comment 5 Daniel Tröder univentionstaff 2017-06-27 18:41:55 CEST
oops... that's what was intended :)
Fixed, commited (80535), yamled (80538).
Comment 6 Florian Best univentionstaff 2017-06-29 15:47:01 CEST
OK: --dry-run causes the counter to not increased
OK: for modifications the counter is not increased
OK: YAML (adjusted in r80627)
Comment 7 Daniel Tröder univentionstaff 2017-07-13 10:16:33 CEST
r81125: adapt 215_import-users_illegal_chars_in_username_v2 to code changes
Comment 8 Sönke Schwardt-Krummrich univentionstaff 2017-10-16 21:32:06 CEST
UCS@school 4.2 v4 has been released.

http://docs.software-univention.de/changelog-ucsschool-4.2v4-de.html

If this error occurs again, please clone this bug.