Lines 52-58
Link Here
|
52 |
from univention.management.console.modules.schoolexam import util |
52 |
from univention.management.console.modules.schoolexam import util |
53 |
|
53 |
|
54 |
from univention.lib.i18n import Translation |
54 |
from univention.lib.i18n import Translation |
55 |
from univention.lib.umc_connection import UMCConnection |
55 |
from univention.lib.umc import Client, ConnectionError, HTTPError |
56 |
|
56 |
|
57 |
from ucsschool.lib.schoolldap import LDAP_Connection, SchoolBaseModule, SchoolSearchBase, SchoolSanitizer |
57 |
from ucsschool.lib.schoolldap import LDAP_Connection, SchoolBaseModule, SchoolSearchBase, SchoolSanitizer |
58 |
from ucsschool.lib import internetrules |
58 |
from ucsschool.lib import internetrules |
Lines 215-231
def _thread():
Link Here
|
215 |
os.chown(itarget, 0, 0) |
215 |
os.chown(itarget, 0, 0) |
216 |
|
216 |
|
217 |
# open a new connection to the master UMC |
217 |
# open a new connection to the master UMC |
218 |
connection = UMCConnection.get_machine_connection() |
218 |
try: |
219 |
if not connection: |
219 |
master = ucr['ldap/master'] |
220 |
MODULE.error('Could not connect to UMC on %s' % (ucr.get('ldap/master'))) |
220 |
client = Client(master) |
|
|
221 |
client.authenticate_with_machine_account() |
222 |
except (ConnectionError, HTTPError) as exc: |
223 |
MODULE.error('Could not connect to UMC on %s: %s' % (master, exc)) |
221 |
raise UMC_Error(_('Could not connect to master server %s.') % ucr.get('ldap/master')) |
224 |
raise UMC_Error(_('Could not connect to master server %s.') % ucr.get('ldap/master')) |
222 |
|
225 |
|
223 |
# mark the computer room for exam mode |
226 |
# mark the computer room for exam mode |
224 |
progress.component(_('Preparing the computer room for exam mode...')) |
227 |
progress.component(_('Preparing the computer room for exam mode...')) |
225 |
connection.request('schoolexam-master/set-computerroom-exammode', dict( |
228 |
client.umc_command('schoolexam-master/set-computerroom-exammode', dict( |
226 |
school=request.options['school'], |
229 |
school=request.options['school'], |
227 |
roomdn=request.options['room'], |
230 |
roomdn=request.options['room'], |
228 |
)) |
231 |
)).result # FIXME: no error handling |
229 |
progress.add_steps(5) |
232 |
progress.add_steps(5) |
230 |
|
233 |
|
231 |
# read all recipients and fetch all user objects |
234 |
# read all recipients and fetch all user objects |
Lines 254-266
def _thread():
Link Here
|
254 |
for iuser in users: |
257 |
for iuser in users: |
255 |
progress.info('%s, %s (%s)' % (iuser.lastname, iuser.firstname, iuser.username)) |
258 |
progress.info('%s, %s (%s)' % (iuser.lastname, iuser.firstname, iuser.username)) |
256 |
try: |
259 |
try: |
257 |
ires = connection.request('schoolexam-master/create-exam-user', dict( |
260 |
ires = client.umc_command('schoolexam-master/create-exam-user', dict( |
258 |
school=request.options['school'], |
261 |
school=request.options['school'], |
259 |
userdn=iuser.dn |
262 |
userdn=iuser.dn |
260 |
)) |
263 |
)).result |
261 |
examUsers.add(ires.get('examuserdn')) |
264 |
examUsers.add(ires.get('examuserdn')) |
262 |
MODULE.info('Exam user has been created: %s' % ires.get('examuserdn')) |
265 |
MODULE.info('Exam user has been created: %s' % ires.get('examuserdn')) |
263 |
except (HTTPException, SocketError) as exc: |
266 |
except (ConnectionError, HTTPError) as exc: |
264 |
MODULE.warn('Could not create exam user account for %r: %s' % (iuser.dn, exc)) |
267 |
MODULE.warn('Could not create exam user account for %r: %s' % (iuser.dn, exc)) |
265 |
|
268 |
|
266 |
# indicate the the user has been processed |
269 |
# indicate the the user has been processed |
Lines 332-362
def _thread():
Link Here
|
332 |
# second step: adjust room settings |
335 |
# second step: adjust room settings |
333 |
progress.component(_('Prepare room settings')) |
336 |
progress.component(_('Prepare room settings')) |
334 |
try: |
337 |
try: |
335 |
userConnection = UMCConnection('localhost', username=self.username, password=self.password) |
338 |
user_client = Client(None, self.username, self.password) |
336 |
except (HTTPException, SocketError) as exc: |
339 |
except (ConnectionError, HTTPError) as exc: |
|
|
340 |
MODULE.warn('Authentication failed: %s' % (exc,)) |
337 |
raise UMC_Error(_('Could not connect to local UMC server.')) |
341 |
raise UMC_Error(_('Could not connect to local UMC server.')) |
338 |
|
342 |
|
339 |
room = request.options['room'] |
343 |
room = request.options['room'] |
340 |
MODULE.info('Acquire room: %s' % (room,)) |
344 |
MODULE.info('Acquire room: %s' % (room,)) |
341 |
userConnection.request('computerroom/room/acquire', dict( |
345 |
user_client.umc_command('computerroom/room/acquire', dict( |
342 |
room=request.options['room'], |
346 |
room=request.options['room'], |
343 |
)) |
347 |
)).result |
344 |
progress.add_steps(1) |
348 |
progress.add_steps(1) |
345 |
MODULE.info('Adjust room settings:\n%s' % '\n'.join([' %s=%s' % (k, v) for k, v in request.options.iteritems()])) |
349 |
MODULE.info('Adjust room settings:\n%s' % '\n'.join([' %s=%s' % (k, v) for k, v in request.options.iteritems()])) |
346 |
userConnection.request('computerroom/exam/start', dict( |
350 |
user_client.umc_command('computerroom/exam/start', dict( |
347 |
room=room, |
351 |
room=room, |
348 |
examDescription=request.options['name'], |
352 |
examDescription=request.options['name'], |
349 |
exam=directory, |
353 |
exam=directory, |
350 |
examEndTime=request.options.get('examEndTime'), |
354 |
examEndTime=request.options.get('examEndTime'), |
351 |
)) |
355 |
)).result |
352 |
progress.add_steps(4) |
356 |
progress.add_steps(4) |
353 |
userConnection.request('computerroom/settings/set', dict( |
357 |
user_client.umc_command('computerroom/settings/set', dict( |
354 |
room=room, |
358 |
room=room, |
355 |
internetRule=request.options['internetRule'], |
359 |
internetRule=request.options['internetRule'], |
356 |
customRule=request.options.get('customRule'), |
360 |
customRule=request.options.get('customRule'), |
357 |
shareMode=request.options['shareMode'], |
361 |
shareMode=request.options['shareMode'], |
358 |
printMode='default', |
362 |
printMode='default', |
359 |
)) |
363 |
)).result |
360 |
progress.add_steps(5) |
364 |
progress.add_steps(5) |
361 |
|
365 |
|
362 |
def _finished(thread, result, request): |
366 |
def _finished(thread, result, request): |
Lines 441-459
def _thread():
Link Here
|
441 |
progress.add_steps(10) |
445 |
progress.add_steps(10) |
442 |
|
446 |
|
443 |
# open a new connection to the master UMC |
447 |
# open a new connection to the master UMC |
444 |
connection = UMCConnection.get_machine_connection() |
448 |
master = ucr['ldap/master'] |
445 |
if not connection: |
449 |
try: |
446 |
MODULE.error('Could not connect to UMC on %s' % (ucr.get('ldap/master'))) |
450 |
client = Client(master) |
447 |
raise UMC_Error(_('Could not connect to master server %s.') % ucr.get('ldap/master')) |
451 |
client.authenticate_with_machine_account() |
|
|
452 |
except (ConnectionError, HTTPError) as exc: |
453 |
MODULE.error('Could not connect to UMC on %s: %s' % (master, exc)) |
454 |
raise UMC_Error(_('Could not connect to master server %s.') % (master,)) |
448 |
|
455 |
|
449 |
school = SchoolSearchBase.getOU(request.options['room']) |
456 |
school = SchoolSearchBase.getOU(request.options['room']) |
450 |
|
457 |
|
451 |
# unset exam mode for the given computer room |
458 |
# unset exam mode for the given computer room |
452 |
progress.component(_('Configuring the computer room...')) |
459 |
progress.component(_('Configuring the computer room...')) |
453 |
connection.request('schoolexam-master/unset-computerroom-exammode', dict( |
460 |
client.umc_command('schoolexam-master/unset-computerroom-exammode', dict( |
454 |
roomdn=request.options['room'], |
461 |
roomdn=request.options['room'], |
455 |
school=school, |
462 |
school=school, |
456 |
)) |
463 |
)).result |
457 |
progress.add_steps(5) |
464 |
progress.add_steps(5) |
458 |
|
465 |
|
459 |
# delete exam users accounts |
466 |
# delete exam users accounts |
Lines 476-485
def _thread():
Link Here
|
476 |
shutil.rmtree(iuser.unixhome, ignore_errors=True) |
483 |
shutil.rmtree(iuser.unixhome, ignore_errors=True) |
477 |
|
484 |
|
478 |
# remove LDAP user entry |
485 |
# remove LDAP user entry |
479 |
connection.request('schoolexam-master/remove-exam-user', dict( |
486 |
client.umc_command('schoolexam-master/remove-exam-user', dict( |
480 |
userdn=iuser.dn, |
487 |
userdn=iuser.dn, |
481 |
school=school, |
488 |
school=school, |
482 |
)) |
489 |
)).result |
483 |
MODULE.info('Exam user has been removed: %s' % iuser.dn) |
490 |
MODULE.info('Exam user has been removed: %s' % iuser.dn) |
484 |
else: |
491 |
else: |
485 |
MODULE.process('Cannot remove the user account %s as it is registered for the running exam "%s", as well' % (iuser.dn, parallelUsers[iuser.username])) |
492 |
MODULE.process('Cannot remove the user account %s as it is registered for the running exam "%s", as well' % (iuser.dn, parallelUsers[iuser.username])) |