Bug 34727 - Import scripts should not create OUs / other missing objects automatically
Import scripts should not create OUs / other missing objects automatically
Status: CLOSED FIXED
Product: UCS@school
Classification: Unclassified
Component: Import scripts
UCS@school 4.2
Other Linux
: P5 enhancement (vote)
: UCS@school 4.2 v6
Assigned To: Florian Best
Daniel Tröder
:
: 27067 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2014-05-02 12:35 CEST by Sönke Schwardt-Krummrich
Modified: 2017-12-21 12:23 CET (History)
4 users (show)

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: 7: Crash: Bug causes crash or data loss
Who will be affected by this bug?: 2: Will only affect a few installed domains
How will those affected feel about the bug?: 5: Blocking further progress on the daily work
User Pain: 0.400
Enterprise Customer affected?:
School Customer affected?: Yes
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number: 2017081521000315, 2017082321000112
Bug group (optional): Roadmap discussion
Max CVSS v3 score:


Attachments
patch (1.43 KB, patch)
2017-09-05 15:25 CEST, Florian Best
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sönke Schwardt-Krummrich univentionstaff 2014-05-02 12:35:26 CEST
From Bug 26137:
> Es sollte geprüft werden, ob das Erstellen einer OU zwingend die Angabe
> des/der Slave-Namen voraussetzen kann. Das würde bedeuten, dass es nicht
> mehr möglich ist, automatisch/implizit eine OU z.B. durch das Anlegen eines
> Users zu erstellen.

The import scripts should not create a missing OUs automatically but should stop if a required object is missing.
Comment 1 Stefan Gohmann univentionstaff 2014-06-17 10:18:16 CEST
Needs to be discussed.
Comment 2 Arvid Requate univentionstaff 2015-01-29 14:20:38 CET
*** Bug 27067 has been marked as a duplicate of this bug. ***
Comment 3 Florian Best univentionstaff 2017-09-05 15:25:11 CEST
Created attachment 9174 [details]
patch
Comment 4 Florian Best univentionstaff 2017-11-01 20:48:47 CET
The patch has been applied. No schools are created anymore implicit by all the import scripts.

ucs-school-import (15.0.3-1)
ed80472edd20 | Bug #34727: Merge branch 'fbest/34727-no-automatic-ou-creation' into 4.2
29d4148265fc | Bug #34727: the import scripts do not create missing OUs automatically anymore

ucs-school-import.yaml
ed80472edd20 | Bug #34727: Merge branch 'fbest/34727-no-automatic-ou-creation' into 4.2
e1901bdbd985 | YAML Bug #34727
Comment 5 Daniel Tröder univentionstaff 2017-11-02 09:02:17 CET
OK: manual tests:

$ /usr/share/ucs-school-import/scripts/ucs-school-create-dummy-users NotExistentSchool > /tmp/bad_import.csv


$ /usr/share/ucs-school-import/scripts/ucs-school-import /tmp/bad_import.csv

-----------------------------------------------------------------------
Processing line 268: A	G.lehmann1	Lehmann	Gabriele	NotExistentSchool	NotExistentSchool-3B,NotExistentSchool-3C,NotExistentSchool-4B,NotExistentSchool-4r,NotExistentSchool-Froesche,NotExistentSchool-Igel,NotExistentSchool-1A,NotExistentSchool-1B,NotExistentSchool-2A,NotExistentSchool-2B		G.lehmann1@uni.dtr	11	0
ERROR: There were problems creating this user: uid=g.lehmann1,cn=lehrer,cn=users,ou=NotExistentSchool,dc=uni,dc=dtr
Traceback (most recent call last):
  File "/usr/share/ucs-school-import/scripts/ucs-school-import", line 1637, in import_user
    result = create_user(person, baseDN, user_module, passwd, OUT, line)
  File "/usr/share/ucs-school-import/scripts/ucs-school-import", line 1485, in create_user
    verify_school_ou(person.sNr, co, lo, baseDN)
  File "/usr/share/ucs-school-import/scripts/ucs-school-import", line 502, in verify_school_ou
    raise SystemExit('ERROR: The specified school %r does not exist.' % (schoolNr,))
SystemExit: ERROR: The specified school 'NotExistentSchool' does not exist.
-----------------------------------------------------------------------


Not this bug, but just verifying that the new [legacy] import handles this the same way:


$ /usr/share/ucs-school-import/scripts/import_user /tmp/bad_import.csv

$ /usr/share/ucs-school-import/scripts/ucs-school-testuser-import --staff 2 --verbose NotExistentSchool

Both:
-----------------------------------------------------------------------
[..]
Entry #2: School 'NotExistentSchool' does not exist.
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/ucsschool/importer/mass_import/user_import.py", line 143, in create_and_modify_users
    success = user.create(lo=self.connection)
  File "/usr/lib/pymodules/python2.7/ucsschool/importer/models/import_user.py", line 204, in create
    self.check_schools(lo)
  File "/usr/lib/pymodules/python2.7/ucsschool/importer/models/import_user.py", line 200, in check_schools
    raise UnkownSchoolName('School {!r} does not exist.'.format(school), input=self.input_data, entry_count=self.entry_count, import_user=self)
UnkownSchoolName: School 'NotExistentSchool' does not exist.
Comment 7 Florian Best univentionstaff 2017-11-07 12:21:41 CET
Your QA did only include the import-user script, which is obsolete and must not be used by customers anymore. We have a replacement for this.

The problem is about the scripts import_group, import_computer, import_router, import_networks, create_dc, move_domaincontroller_to_ou, export_computer, set_ou_sharefileserver.

I added an explicit check for every of these scripts in:
ucs-school-import (15.0.3-2)
e885a25761e4 | Bug #34727: make sure all import scripts are explicit affected

(In reply to Daniel Tröder from comment #6)
> Please reply to comments in Gitlab:
> https://git.knut.univention.de/univention/ucsschool/commit/
> 29d4148265fc0c8282aae860b74e27e868d692ea#note_475
I think everything is fine here. The functions themself do it like this by calling sys.exit(1). It's not designed to be a library and we have plans to rewrite it. Only the import-user script makes a try:-except: for all other scripts this is working fine.

> https://git.knut.univention.de/univention/ucsschool/commit/
> e1901bdbd98580b47faf9fe0cdc1fdb2410b014f#note_476
I added the YAML version number.
Comment 8 Daniel Tröder univentionstaff 2017-11-08 09:23:24 CET
OK: advisory
OK: manual tests with faulty input:
----------------------------------------------------------------------------
root@m150:~# cd /usr/share/ucs-school-import/scripts

# ./create_dc --ou NoSchool --name newdc --type educational
ERROR: The specified school 'NoSchool' does not exist.

# ./export_computer NoSchool /tmp/computerexport.csv
ERROR: The specified school 'NoSchool' does not exist.

# ./import_computer ~/computer_import.csv
infile is  : /root/computer_import.csv
Processing line 1: domaincontroller_slave	slavename	52:54:00:e3:a7:6d	NoSchool	10.11.12.13/24	11,12,13,14	edukativ
ERROR: The specified school 'NoSchool' does not exist.

# cat ~/network_group.csv
A	NoSchool	newclass	A new class.

# ./import_group ~/network_group.csv
infile is  : /root/network_group.csv
ERROR: The specified school 'NoSchool' does not exist.

# cat ~/network_import.csv
NoSchool	10.0.0.0/8	10.0.0.1-10.254.254.250	10.254.254.254	10.254.254.253	10.254.254.252

# ./import_networks ~/network_import.csv
infile is  : /root/network_import.csv
ERROR: The specified school 'NoSchool' does not exist.

# cat ~/printer_import.csv
A	NoSchool	spool.uni.dtr	PrinterName	socket://10.20.30.40.:9000/	HP DeskJet 9000

# ./import_printer ~/printer_import.csv
infile is  : /root/printer_import.csv
ERROR: The specified school 'NoSchool' does not exist.

# ./import_router ~/network_import.csv 
infile is  : /root/network_import.csv
ERROR: The specified school 'NoSchool' does not exist.

"import_user" was tested before and its code has not been modifed.

# ./move_domaincontroller_to_ou --dcname $(hostname -s) --ou NoSchool
ERROR: The specified school 'NoSchool' does not exist.

# ./set_ou_sharefileserver NoSchool m150
ERROR: The specified school 'NoSchool' does not exist.

----------------------------------------------------------------------------
OK: manual tests with correct input:
----------------------------------------------------------------------------

# ./create_ou NewSchool1 && echo "OK"
OK

# ./create_dc --ou NewSchool1 --name newdc --type educational && echo OK
creating object cn=newdc,cn=dc,cn=server,cn=computers,ou=NewSchool1,dc=uni,dc=dtr
OK

# sed --in-place 's#NoSchool#NewSchool1#g' ~/computer_import.csv 
# ./import_computer ~/computer_import.csv && echo OK
infile is  : /root/computer_import.csv
Processing line 1: domaincontroller_slave	slavename	52:54:00:e3:a7:6d	NewSchool1	10.11.12.13/24	11,12,13,14	edukativ
generate computer slavename (school NewSchool1)
generate network 10.11.12.0/24
creating object zoneName=12.11.10.in-addr.arpa,cn=dns,dc=uni,dc=dtr
creating object cn=10.11.12.0,cn=newschool1,cn=dhcp,ou=NewSchool1,dc=uni,dc=dtr
creating object cn=newschool1-10.11.12.0,cn=networks,ou=NewSchool1,dc=uni,dc=dtr
set ip to 10.11.12.13 is not net 10.11.12.0
creating object cn=slavename,cn=computers,ou=NewSchool1,dc=uni,dc=dtr
Processing of line 1 completed
OK

# ./create_dc --ou NewSchool1 --name newdc --type educational && echo OK
OK

# ./export_computer NewSchool1 /tmp/computerexport.csv && echo OK
outfile is : /tmp/computerexport.csv
looking for objects... please wait...
writing data of 2 objects...
root@m150:/usr/share/ucs-school-import/scripts# cat /tmp/computerexport.csv
newdc	NewSchool1				
slavename	NewSchool1	11	10.11.12.13	52:54:00:e3:a7:6d	
OK

# sed --in-place 's#NoSchool#NewSchool1#g' ~/group_import.csv 
# ./import_group ~/group_import.csv && echo OK
infile is  : /root/group_import.csv
need to create group cn=newclass,cn=klassen,cn=schueler,cn=groups,ou=NewSchool1,dc=uni,dc=dtr
creating object cn=newclass,cn=klassen,cn=schueler,cn=groups,ou=NewSchool1,dc=uni,dc=dtr
Changed Description of cn=newclass,cn=klassen,cn=schueler,cn=groups,ou=NewSchool1,dc=uni,dc=dtr from  to A new class.
need to create groupshare cn=newclass,cn=klassen,cn=shares,ou=NewSchool1,dc=uni,dc=dtr
creating object cn=newclass,cn=klassen,cn=shares,ou=NewSchool1,dc=uni,dc=dtr
OK

# sed --in-place 's#NoSchool#NewSchool1#g' ~/network_import.csv 
# ./import_networks ~/network_import.csv && echo OK
infile is  : /root/network_import.csv
generate network 10.0.0.0/8
iprange: 10.0.0.1-10.254.254.250
defaultrouter: 10.254.254.254
nameserver: 10.254.254.253
netbiosserver: 10.254.254.252
creating object zoneName=10.in-addr.arpa,cn=dns,dc=uni,dc=dtr
creating object cn=10.0.0.0,cn=newschool1,cn=dhcp,ou=NewSchool1,dc=uni,dc=dtr
creating object cn=newschool1-10.0.0.0,cn=networks,ou=NewSchool1,dc=uni,dc=dtr
setting default router
need to create container cn=dhcp,cn=policies,ou=NewSchool1,dc=uni,dc=dtr
creating object cn=dhcp,cn=policies,ou=NewSchool1,dc=uni,dc=dtr
need to create container cn=routing,cn=dhcp,cn=policies,ou=NewSchool1,dc=uni,dc=dtr
creating object cn=routing,cn=dhcp,cn=policies,ou=NewSchool1,dc=uni,dc=dtr
creating object cn=newschool1-10.0.0.0,cn=routing,cn=dhcp,cn=policies,ou=NewSchool1,dc=uni,dc=dtr
connecting dhcp subnet (cn=10.0.0.0,cn=newschool1,cn=dhcp,ou=NewSchool1,dc=uni,dc=dtr) with policy (cn=newschool1-10.0.0.0,cn=routing,cn=dhcp,cn=policies,ou=NewSchool1,dc=uni,dc=dtr)
setting netbios server
need to create container cn=netbios,cn=dhcp,cn=policies,ou=NewSchool1,dc=uni,dc=dtr
creating object cn=netbios,cn=dhcp,cn=policies,ou=NewSchool1,dc=uni,dc=dtr
creating object cn=newschool1-10.0.0.0,cn=netbios,cn=dhcp,cn=policies,ou=NewSchool1,dc=uni,dc=dtr
connecting dhcp subnet (cn=10.0.0.0,cn=newschool1,cn=dhcp,ou=NewSchool1,dc=uni,dc=dtr) with policy (cn=newschool1-10.0.0.0,cn=netbios,cn=dhcp,cn=policies,ou=NewSchool1,dc=uni,dc=dtr)
setting nameserver
need to create container cn=dns,cn=dhcp,cn=policies,ou=NewSchool1,dc=uni,dc=dtr
creating object cn=dns,cn=dhcp,cn=policies,ou=NewSchool1,dc=uni,dc=dtr
creating object cn=newschool1-10.0.0.0,cn=dns,cn=dhcp,cn=policies,ou=NewSchool1,dc=uni,dc=dtr
connecting dhcp subnet (cn=10.0.0.0,cn=newschool1,cn=dhcp,ou=NewSchool1,dc=uni,dc=dtr) with policy (cn=newschool1-10.0.0.0,cn=dns,cn=dhcp,cn=policies,ou=NewSchool1,dc=uni,dc=dtr)
OK

# sed --in-place 's#NoSchool#NewSchool1#g' ~/printer_import.csv 
# ./import_printer ~/printer_import.csv && echo OK
infile is  : /root/printer_import.csv
creating object cn=PrinterName,cn=printers,ou=NewSchool1,dc=uni,dc=dtr
OK

# ./import_router ~/network_import.csv && echo OK
infile is  : /root/network_import.csv
Router set for subnet.
OK

# ./move_domaincontroller_to_ou --dcname newdc --ou NewSchool1 && echo OK
domaincontroller slave "newdc" is already located below ou "NewSchool1" - stopping here
OK

# ./set_ou_sharefileserver NewSchool1 newdc && echo OK
OK
Comment 9 Sönke Schwardt-Krummrich univentionstaff 2017-12-21 12:23:03 CET
UCS@school 4.2 v6 has been released.

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

If this error occurs again, please clone this bug.