Bug 32692 - rename_class script fails on duplicates
rename_class script fails on duplicates
Status: RESOLVED WONTFIX
Product: UCS@school
Classification: Unclassified
Component: Import scripts
unspecified
All Linux
: P5 normal (vote)
: ---
Assigned To: Bugzilla Mailingliste
:
Depends on:
Blocks: 34209
  Show dependency treegraph
 
Reported: 2013-09-26 09:57 CEST by Sven Osterwalder
Modified: 2014-02-28 15:37 CET (History)
2 users (show)

See Also:
What kind of report is it?: ---
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sven Osterwalder 2013-09-26 09:57:05 CEST
Hello,

This bug concerns at least UCS@school 3.0, 3.1 and 3.1 R2. 

We use the rename_class script to renanme shares and groups. We provide the script a temporary file which contains the old as well as the new names of shares/groups, e.g.:

> nameOld   nameNew

We invoke the script within a python script like this:
>       ...
>       # make sure all written data is on disk before we
>       # send the file to the importer
>       self.outfile.flush()
>
>       script = settings.get_setting('external_programs', 'class_rename_script')
>
>       command = [script, self.outfile.name]
>
>       returncode, stdout, stderr = execute_external(command)
>       stdout.save_as('class_rename_stdout.txt')
>       stderr.save_as('class_rename_stderr.txt')


If a new name happens to be twice in the file/list, the rename_class script exists, which may not be bug (it may be intended), but seems a bit harsh in our opinion.

This can be found at usr/share/ucs-school-import/scripts/rename_class, lines 2716 to 2745:
> 		...
> 		if error:
>			print "ERROR: %s (line %s: %s)" % (error, lineCounter, line)
>			print "do nothing"
>			sys.exit(0)


When commenting out the sys.exit(0), the script runs further but hits a bug, on lines 2770 and 2783:
> ...
>				messages.append("Renaming of group %s to %s failed: %s" % (oldname, newName, str(e)))
> ...
> 				messages.append("Renaming of share %s to %s failed: %s" % (oldname, newName, str(e)))

oldname is not defined, it is oldName instead.


We suggest the following workaround/bugfix:
 * Removal of sys.exit(0) as it is the responsibility of the data provider to ensure that the groups are correctly provided
    -> The script doesn't stop then but skips the already exisitng new shares/groups
 * Change oldname to oldName within lines 2770 resp. 2783


If you have any questions or concerns, do not hesitate to contact me.


Kind regards,

Sven Osterwalder
Comment 1 Sönke Schwardt-Krummrich univentionstaff 2013-09-27 08:33:15 CEST
(In reply to Sven Osterwalder from comment #0)
> We use the rename_class script to renanme shares and groups. We provide the
> script a temporary file which contains the old as well as the new names of
> shares/groups, e.g.:
> 
> > nameOld   nameNew

The order of the renaming steps is important. That is why the script checks the input file for duplicates. An input file like the following would result in an error, because renamings are performed in that order:

class-1A  class-2A
class-2A  class-3A

Given the case that the classes class-1A and class-2A exist, the first renaming of class-1A would fail, because class-2A does already exist. If the line order gets swapped, there should be no problem.

> If a new name happens to be twice in the file/list, the rename_class script
> exists, which may not be bug (it may be intended), but seems a bit harsh in
> our opinion.

Can you give us an example?
Comment 2 Sven Osterwalder 2013-10-03 12:32:59 CEST
Hello,

Thank you for your answer.

(In reply to Sönke Schwardt-Krummrich from comment #1)
> The order of the renaming steps is important. That is why the script checks
> the input file for duplicates. An input file like the following would result
> in an error, because renamings are performed in that order:
> 
> class-1A  class-2A
> class-2A  class-3A
> 
> Given the case that the classes class-1A and class-2A exist, the first
> renaming of class-1A would fail, because class-2A does already exist. If the
> line order gets swapped, there should be no problem.
> [...]
> Can you give us an example?
What I meant was, that when two classes get renamed into the same class, for example:

class-1A  class-2A
class-3A  class-2A

I don't know if this should be possible but we tried to let the script continue instead of exiting, which does - as the script states - nothing resp. no renaming of a specific class, but lets the script continue and rename further classes. In our case we make sure that we have no dependencies (like in your example) before running the script.


Kind regards

Sven Osterwalder
Comment 3 Stefan Gohmann univentionstaff 2013-11-01 22:28:04 CET
(In reply to Sven Osterwalder from comment #2)
> What I meant was, that when two classes get renamed into the same class, for
> example:
> 
> class-1A  class-2A
> class-3A  class-2A
> 
> I don't know if this should be possible but we tried to let the script
> continue instead of exiting, which does - as the script states - nothing
> resp. no renaming of a specific class, but lets the script continue and
> rename further classes. In our case we make sure that we have no
> dependencies (like in your example) before running the script.

Thanks for your explanation.

I don't think it should be possible to rename two classes to one class. But you can easily add a pre or port script to your import and handle this at your own.