1#
2# Authors: Sergey Satskiy
3#
4# $Id: netschedule_tests_pack_4_10.py 591938 2019-08-22 17:35:24Z satskyse $
5#
6
7"""
8Netschedule server tests pack for the features appeared in NS-4.10.0
9"""
10
11import time, socket
12from netschedule_tests_pack import TestBase
13
14# Works for python 2.5. Python 2.7 has it in urlparse module
15from cgi import parse_qs
16
17
18NON_EXISTED_JOB = "JSID_01_777_130.14.24.83_9101"
19ANY_AUTH_TOKEN = '1166018352_2'
20
21
22def getClientInfo( ns, clientNode = None,
23                    minClients = 1, maxClients = None, verbose = True ):
24    " Provides the client info "
25    servers = ns.get_servers()
26    if len( servers ) != 1:
27        raise Exception( "Invalid number of servers returned." )
28    serverClients = servers[ 0 ].get_client_info( verbose )
29    if minClients is not None and len( serverClients ) < minClients:
30        raise Exception( "Too few clients returned (" +
31                str( len( serverClients ) ) + "); minimum: " + \
32                            str( minClients ) )
33    if maxClients is not None and len( serverClients ) > maxClients:
34        raise Exception( "Too many clients returned (" +
35                str( len( serverClients ) ) + "); maximum: " + \
36                            str( maxClients ) )
37    if len( serverClients ) == 0 or not clientNode:
38        return None
39
40    for clientInfo in serverClients:
41        if clientInfo[ 'client_node' ] == clientNode:
42            return clientInfo
43
44    raise Exception( "Unable to find client '" + clientNode + "'" )
45
46def getAffinityInfo( ns, verbose = True, expectedAffinities = 1, affIndex = 0 ):
47    " Provides the affinity info "
48    servers = ns.get_servers()
49    if len( servers ) != 1:
50        raise Exception( "Invalid number of servers returned." )
51
52    serverAffinities = servers[ 0 ].get_affinity_info( verbose )
53    if len( serverAffinities ) != expectedAffinities:
54        raise Exception( "Expected " + str( expectedAffinities ) + \
55                         " affinity(s). Received " + \
56                         str( len( serverAffinities ) ) + " affinity(s)" )
57    if expectedAffinities <= 0:
58        return None
59    return serverAffinities[ affIndex ]
60
61def getNotificationInfo( ns, verbose = True, expectedNotifications = 1,
62                         notifIndex = 0 ):
63    " Provides the notification info "
64    servers = ns.get_servers()
65    if len( servers ) != 1:
66        raise Exception( "Invalid number of servers returned." )
67
68    serverNotifications = servers[ 0 ].get_notification_info( verbose )
69    if len( serverNotifications ) != expectedNotifications:
70        raise Exception( "Expected " + str( expectedNotifications ) + \
71                         " notification(s). Received " + \
72                         str( len( serverNotifications ) ) + \
73                         " notification(s)" )
74    if expectedNotifications <= 0:
75        return None
76    return serverNotifications[ notifIndex ]
77
78def getGroupInfo( ns, verbose = True, expectedGroups = 1,
79                  groupIndex = 0 ):
80    " Provides the group info "
81    servers = ns.get_servers()
82    if len( servers ) != 1:
83        raise Exception( "Invalid number of servers returned." )
84
85    serverGroups = servers[ 0 ].get_job_group_info( verbose )
86    if len( serverGroups ) != expectedGroups:
87        raise Exception( "Expected " + str( expectedGroups ) + \
88                         " group(s). Received " + \
89                         str( len( serverGroups ) ) + \
90                         " group(s)" )
91    if expectedGroups <= 0:
92        return None
93    return serverGroups[ groupIndex ]
94
95def changeAffinity( ns, toAdd, toDel, serverIndex = 0 ):
96    " Changes preferred affinities on the given server "
97    servers = ns.get_servers()
98    if len( servers ) == 0:
99        raise Exception( "Cannot get any servers" )
100    server = servers[ serverIndex ]
101    server.change_preferred_affinities( toAdd, toDel )
102    return
103
104def execAny( ns, cmd, serverIndex = 0, isMultiline = False ):
105    " Execute any command on the given server "
106    servers = ns.get_servers()
107    if len( servers ) == 0:
108        raise Exception( "Cannot get any servers" )
109    server = servers[ serverIndex ]
110    return server.execute( cmd, isMultiline )
111
112
113
114class Scenario100( TestBase ):
115    " Scenario 100 "
116
117    def __init__( self, netschedule ):
118        TestBase.__init__( self, netschedule )
119        return
120
121    @staticmethod
122    def getScenario():
123        " Provides the scenario "
124        return "Get the NS version in a new format"
125
126    def execute( self ):
127        " Should return True if the execution completed successfully "
128        self.fromScratch()
129
130        result = self.ns.getVersion()
131        if "server_version" not in result:
132            raise Exception( "No 'server_version' in VERSION output" )
133        if "storage_version" not in result:
134            raise Exception( "No 'storage_version' in VERSION output" )
135        if "protocol_version" not in result:
136            raise Exception( "No 'protocol_version' in VERSION output" )
137        if "ns_node" not in result:
138            raise Exception( "No 'ns_node' in VERSION output" )
139        if "ns_session" not in result:
140            raise Exception( "No ns_session' in VERSION output" )
141        return True
142
143class Scenario101( TestBase ):
144    " Scenario 101 "
145
146    def __init__( self, netschedule ):
147        TestBase.__init__( self, netschedule )
148        return
149
150    @staticmethod
151    def getScenario():
152        " Provides the scenario "
153        return "Get the NS version, restart NS, get NS version; " \
154               "Make sure that the session is regenerated"
155
156    def getSession( self, result ):
157        " provides the session ID from the output "
158        for line in result.split( "\n" ):
159            if "ns_session" not in line:
160                continue
161            parts = line.split( "ns_session" )
162            if len( parts ) != 2:
163                raise Exception( "Cannot find ns_session" )
164            part = parts[ 1 ].strip()
165            if part.startswith( '=' ):
166                part = part[ 1: ]
167            if len( part ) == 0:
168                raise Exception( "Unexpected ns_session format" )
169            return part
170        raise Exception( "No ns_session in the VERSION output" )
171
172
173    def getNode( self, result ):
174        " provides the node ID from the output "
175        for line in result.split( "\n" ):
176            if "ns_node" not in line:
177                continue
178            parts = line.split( "ns_node" )
179            if len( parts ) != 2:
180                raise Exception( "Cannot find ns_node" )
181            part = parts[ 1 ].strip()
182            if part.startswith( '=' ):
183                part = part[ 1: ]
184            part = part.split( '&' )[ 0 ]
185            if len( part ) == 0:
186                raise Exception( "Unexpected ns_node format" )
187            return part
188        raise Exception( "No ns_node in the VERSION output" )
189
190    def execute( self ):
191        " Should return True if the execution completed successfully "
192        self.fromScratch()
193        result = self.ns.getVersion()
194
195        # Extract ns_session
196        firstSession = self.getSession( result )
197        firstNode = self.getNode( result )
198
199        self.ns.safeStop()
200        time.sleep( 1 )
201        self.ns.start()
202        time.sleep( 1 )
203
204        result = self.ns.getVersion()
205
206        # Extract ns_session
207        secondSession = self.getSession( result )
208        secondNode = self.getNode( result )
209
210        if firstSession == secondSession:
211            raise Exception( "NS did not regenerate its session after restart" )
212        if firstNode != secondNode:
213            raise Exception( "NS changes node ID after restart. Was: " + \
214                             firstNode + " Became: " + secondNode )
215        return True
216
217class Scenario102( TestBase ):
218    " Scenario 102 "
219
220    def __init__( self, netschedule ):
221        TestBase.__init__( self, netschedule )
222        return
223
224    @staticmethod
225    def getScenario():
226        " Provides the scenario "
227        return "Login with client_node and without client_session"
228
229    def execute( self ):
230        " Should return True if the execution completed successfully "
231        self.fromScratch()
232
233        try:
234            self.ns.getVersion( node = "my_node", session = "" )
235        except Exception as exc:
236            if "client_node is provided but " \
237               "client_session is not" in str( exc ):
238                return True
239            raise
240
241        return False
242
243class Scenario103( TestBase ):
244    " Scenario 103 "
245
246    def __init__( self, netschedule ):
247        TestBase.__init__( self, netschedule )
248        return
249
250    @staticmethod
251    def getScenario():
252        " Provides the scenario "
253        return "Login without client_node and with client_session"
254
255    def execute( self ):
256        " Should return True if the execution completed successfully "
257        self.fromScratch()
258
259        try:
260            self.ns.getVersion( node = "", session = "my_session" )
261        except Exception as exc:
262            if "client_session is provided " \
263               "but client_node is not" in str( exc ):
264                return True
265            raise
266
267        return False
268
269class Scenario104( TestBase ):
270    " Scenario 104 "
271
272    def __init__( self, netschedule ):
273        TestBase.__init__( self, netschedule )
274        return
275
276    @staticmethod
277    def getScenario():
278        " Provides the scenario "
279        return "Get empty list of registered clients"
280
281    def execute( self ):
282        " Should return True if the execution completed successfully "
283        self.fromScratch()
284
285        ns_client = self.getNetScheduleService( 'TEST', 'scenario104' )
286        try:
287            ns_client.set_client_identification( '', '' )
288        except:
289            pass
290        getClientInfo( ns_client, None, 0, 0 )
291        return True
292
293class Scenario105( TestBase ):
294    " Scenario 105 "
295
296    def __init__( self, netschedule ):
297        TestBase.__init__( self, netschedule )
298        return
299
300    @staticmethod
301    def getScenario():
302        " Provides the scenario "
303        return "STAT CLIENTS on behalf an identified client"
304
305    def execute( self ):
306        " Should return True if the execution completed successfully "
307        self.fromScratch()
308
309        ns_client = self.getNetScheduleService( 'TEST', 'scenario105' )
310        ns_client.set_client_identification( 'mynode', 'mysession' )
311
312        client = getClientInfo( ns_client, 'mynode' )
313        if client[ 'session' ] == 'mysession' and \
314           ( client[ 'type' ] in [ 'unknown', 'admin' ]):
315            return True
316
317        raise Exception( "Unexpected client info: " + str( client ) )
318
319class Scenario106( TestBase ):
320    " Scenario 106 "
321
322    def __init__( self, netschedule ):
323        TestBase.__init__( self, netschedule )
324        return
325
326    @staticmethod
327    def getScenario():
328        " Provides the scenario "
329        return "SUBMIT as identified, STAT CLIENTS and check the client type"
330
331    def execute( self ):
332        " Should return True if the execution completed successfully "
333        self.fromScratch()
334
335        ns_client = self.getNetScheduleService( 'TEST', 'scenario105' )
336
337        self.ns.submitJob( 'TEST', 'bla', '', '', 'node', '000' )
338
339        client = getClientInfo( ns_client, 'node' )
340        if client[ 'session' ] == '000' and \
341           client[ 'type' ] == 'submitter':
342            return True
343
344        raise Exception( "Unexpected client info: " + str( client ) )
345
346class Scenario107( TestBase ):
347    " Scenario 107 "
348
349    def __init__( self, netschedule ):
350        TestBase.__init__( self, netschedule )
351        return
352
353    @staticmethod
354    def getScenario():
355        " Provides the scenario "
356        return "Get a job as identified, check the clients list"
357
358    def execute( self ):
359        " Should return True if the execution completed successfully "
360        self.fromScratch()
361
362        jobID = self.ns.submitJob( 'TEST', 'bla' )
363        self.ns.getJob( 'TEST', -1, '', "",
364                        'scenario107', 'default' )
365
366        ns_client = self.getNetScheduleService( 'TEST', 'scenario107' )
367        client = getClientInfo( ns_client, 'scenario107' )
368
369        if client[ 'session' ] == 'default' and \
370           client[ 'type' ] == 'worker node' and \
371           len( client[ 'running_jobs' ] ) == 1 and \
372           client[ 'running_jobs' ][ 0 ] == jobID:
373            return True
374
375        raise Exception( "Unexpected client info: " + str( client ) )
376
377class Scenario108( TestBase ):
378    " Scenario 108 "
379
380    def __init__( self, netschedule ):
381        TestBase.__init__( self, netschedule )
382        return
383
384    @staticmethod
385    def getScenario():
386        " Provides the scenario "
387        return "SUBMIT, GET, PUT as anon. READ as identified, STAT CLIENTS"
388
389    def execute( self ):
390        " Should return True if the execution completed successfully "
391        self.fromScratch()
392
393        jobID = self.ns.submitJob( 'TEST', 'bla' )
394        jobInfo = self.ns.getJob( 'TEST' )
395        self.ns.putJob( 'TEST', jobID, jobInfo[ 1 ], 0, "" )
396
397        key, state, passport = self.ns.getJobsForReading2( 'TEST', -1, '',
398                                                           'mynode',
399                                                           'mysession' )
400
401        ns_client = self.getNetScheduleService( 'TEST', 'scenario108' )
402        client = getClientInfo( ns_client, 'mynode' )
403        if client[ 'session' ] == 'mysession' and \
404           client[ 'type' ] == 'reader' and \
405           len( client[ 'reading_jobs' ] ) == 1 and \
406           client[ 'reading_jobs' ][ 0 ] == key:
407            return True
408
409        raise Exception( "Unexpected client info: " + str( client ) )
410
411class Scenario109( TestBase ):
412    " Scenario 109 "
413
414    def __init__( self, netschedule ):
415        TestBase.__init__( self, netschedule )
416        return
417
418    @staticmethod
419    def getScenario():
420        " Provides the scenario "
421        return "SUBMIT, GET, PUT, READ as identified, STAT CLIENTS VERBOSE"
422
423    def execute( self ):
424        " Should return True if the execution completed successfully "
425        self.fromScratch()
426
427        jobID = self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', '0' )
428        jobInfo = self.ns.getJob( 'TEST', -1, '', '', 'mynode', '0' )
429        self.ns.putJob( 'TEST', jobID, jobInfo[ 1 ], 0, "", 'mynode', '0' )
430
431        key, state, passport = self.ns.getJobsForReading2( 'TEST', -1, '',
432                                                           'mynode',
433                                                           '0' )
434        ns_client = self.getNetScheduleService( 'TEST', 'scenario109' )
435        client = getClientInfo( ns_client, 'mynode' )
436        if client[ 'session' ] == '0' and \
437           client[ 'type' ] == 'submitter | worker node | reader' and \
438           len( client[ 'reading_jobs' ] ) == 1 and \
439           client[ 'reading_jobs' ][ 0 ] == key:
440            return True
441
442        raise Exception( "Unexpected client info: " + str( client ) )
443
444class Scenario110( TestBase ):
445    " Scenario 110 "
446
447    def __init__( self, netschedule ):
448        TestBase.__init__( self, netschedule )
449        return
450
451    @staticmethod
452    def getScenario():
453        " Provides the scenario "
454        return "SUBMIT, GET, PUT, READ as identified, STAT CLIENTS"
455
456    def execute( self ):
457        " Should return True if the execution completed successfully "
458        self.fromScratch()
459
460        jobID = self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', '0' )
461        jobInfo = self.ns.getJob( 'TEST', -1, '', '', 'mynode', '0' )
462        self.ns.putJob( 'TEST', jobID, jobInfo[ 1 ], 0, "", 'mynode', '0' )
463
464        key, state, passport = self.ns.getJobsForReading2( 'TEST', -1, '',
465                                                           'mynode',
466                                                           '0' )
467        ns_client = self.getNetScheduleService( 'TEST', 'scenario110' )
468        client = getClientInfo( ns_client, 'mynode', verbose = False )
469        if client[ 'session' ] == '0' and \
470           client[ 'number_of_submitted_jobs' ] == 1 and \
471           client[ 'number_of_jobs_given_for_execution' ] == 1 and \
472           client[ 'number_of_jobs_given_for_reading' ] == 1 and \
473           client[ 'type' ] == 'submitter | worker node | reader' and \
474           client[ 'number_of_reading_jobs' ] == 1:
475            return True
476
477        raise Exception( "Unexpected client info: " + str( client ) )
478
479class Scenario111( TestBase ):
480    " Scenario 111 "
481
482    def __init__( self, netschedule ):
483        TestBase.__init__( self, netschedule )
484        return
485
486    @staticmethod
487    def getScenario():
488        " Provides the scenario "
489        return "Connect with one session, reconnect with another"
490
491    def execute( self ):
492        " Should return True if the execution completed successfully "
493        self.fromScratch()
494
495        ns_client = self.getNetScheduleService( 'TEST', 'scenario111' )
496
497        # get original session
498        self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', '0' )
499        client = getClientInfo( ns_client, 'mynode' )
500        if client[ 'session' ] != '0':
501            raise Exception( "Unexpected session. Expected '0'. " \
502                             "Received: '" + client[ 'session' ] )
503
504        # get modified session session
505        self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', '1' )
506        client = getClientInfo( ns_client, 'mynode' )
507        if client[ 'session' ] != '1':
508            raise Exception( "Unexpected session. Expected '1'. " \
509                             "Received: '" + client[ 'session' ] )
510
511        return True
512
513class Scenario112( TestBase ):
514    " Scenario 112 "
515
516    def __init__( self, netschedule ):
517        TestBase.__init__( self, netschedule )
518        return
519
520    @staticmethod
521    def getScenario():
522        " Provides the scenario "
523        return "Connect with a session, check clients list, " \
524               "reconnect with the same session, check clients list, " \
525               "issue CLRN, check clients list"
526
527    def execute( self ):
528        " Should return True if the execution completed successfully "
529        self.fromScratch()
530
531        ns_client = self.getNetScheduleService( 'TEST', 'scenario112' )
532        ns_client.set_client_identification( 'mynode', 'session1' )
533
534        client = getClientInfo( ns_client, 'mynode' )
535        if client[ 'session' ] != 'session1':
536            raise Exception( "Unexpected session. Expected 'session1'. " \
537                             "Received: '" + client[ 'session' ] )
538
539        ns_client = self.getNetScheduleService( 'TEST', 'scenario112' )
540        ns_client.set_client_identification( 'mynode', 'session1' )
541        client = getClientInfo( ns_client, 'mynode' )
542        if client[ 'session' ] != 'session1':
543            raise Exception( "Unexpected session. Expected 'session1'. " \
544                             "Received: '" + client[ 'session' ] )
545
546        # CLRN
547        execAny( ns_client, 'CLRN' )
548
549        ns_client = self.getNetScheduleService( 'TEST', 'scenario112' )
550        info = getClientInfo( ns_client, 'mynode' )
551        if info[ 'session' ] != 'n/a':
552            raise Exception( "Unexpected session. Expected 'n/a', " \
553                             "received: " + info[ 'session' ] )
554
555        return True
556
557class Scenario113( TestBase ):
558    " Scenario 113 "
559
560    def __init__( self, netschedule ):
561        TestBase.__init__( self, netschedule )
562        return
563
564    @staticmethod
565    def getScenario():
566        " Provides the scenario "
567        return "Get a job with one session, reconnect with another session"
568
569    def execute( self ):
570        " Should return True if the execution completed successfully "
571        self.fromScratch()
572
573        ns_client = self.getNetScheduleService( 'TEST', 'scenario113' )
574
575        # get original session
576        jobID = self.ns.submitJob( 'TEST', 'bla' )
577        self.ns.getJob( 'TEST', -1, '', '', 'mynode', 'mysession' )
578
579        client = getClientInfo( ns_client, 'mynode' )
580        if client[ 'running_jobs' ][ 0 ] != jobID:
581            raise Exception( "Running job is not registered" )
582
583        # To touch the clients registry with another session
584        self.ns.submitJob( 'TEST', 'bla2', '', '', 'mynode', 'changedsession' )
585        client = getClientInfo( ns_client, 'mynode' )
586        if 'running_jobs' in client:
587            raise Exception( "Running job is still there" )
588
589        # Check the status
590        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
591        status2 = self.ns.getJobStatus( 'TEST', jobID )
592
593        info = self.ns.getJobInfo( 'TEST', jobID )
594        status3 = info[ "status" ]
595
596        if status1 != "Pending" or \
597           status2 != "Pending" or \
598           status3 != "Pending":
599            return False
600        return True
601
602class Scenario114( TestBase ):
603    " Scenario 114 "
604
605    def __init__( self, netschedule ):
606        TestBase.__init__( self, netschedule )
607        return
608
609    @staticmethod
610    def getScenario():
611        " Provides the scenario "
612        return "Get a job with one session, issue CLRN"
613
614    def execute( self ):
615        " Should return True if the execution completed successfully "
616        self.fromScratch()
617
618        ns_client = self.getNetScheduleService( 'TEST', 'scenario114' )
619        ns_client.set_client_identification( 'mynode', 'mysession' )
620
621        jobID = self.ns.submitJob( 'TEST', 'bla' )
622        self.ns.getJob( 'TEST', -1, '', '', 'mynode', 'mysession' )
623
624        client = getClientInfo( ns_client, 'mynode' )
625        if client[ 'running_jobs' ][ 0 ] != jobID:
626            raise Exception( "Running job is not registered" )
627
628        execAny( ns_client, 'CLRN' )
629        client = getClientInfo( ns_client, 'mynode' )
630        if 'running_jobs' in client:
631            raise Exception( "Running job is still there" )
632
633        # Check the status
634        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
635        status2 = self.ns.getJobStatus( 'TEST', jobID )
636
637        info = self.ns.getJobInfo( 'TEST', jobID )
638        status3 = info[ "status" ]
639
640        if status1 != "Pending" or \
641           status2 != "Pending" or \
642           status3 != "Pending":
643            return False
644        return True
645
646class Scenario115( TestBase ):
647    " Scenario 115 "
648
649    def __init__( self, netschedule ):
650        TestBase.__init__( self, netschedule )
651        return
652
653    @staticmethod
654    def getScenario():
655        " Provides the scenario "
656        return "SUBMIT, GET, PUT as anon. READ as identified, STAT CLIENTS. " \
657               "Reconnect with another session, check the job status"
658
659    def execute( self ):
660        " Should return True if the execution completed successfully "
661        self.fromScratch()
662
663        ns_client = self.getNetScheduleService( 'TEST', 'scenario115' )
664
665        jobID = self.ns.submitJob( 'TEST', 'bla' )
666        jobInfo = self.ns.getJob( 'TEST' )
667        self.ns.putJob( 'TEST', jobID, jobInfo[ 1 ], 0, "" )
668
669        key, state, passport = self.ns.getJobsForReading2( 'TEST', -1, '',
670                                                           'mynode',
671                                                           'session1' )
672
673        client = getClientInfo( ns_client, 'mynode' )
674        if 'running_jobs' in client:
675            raise Exception( "Running job is still there" )
676        if client[ 'number_of_jobs_given_for_reading' ] != 1:
677            raise Exception( "Unexpected number of running jobs" )
678
679        # Another sesson
680        self.ns.getFastJobStatus( 'TEST', jobID, 'mynode', 'session2' )
681
682        # Check the status
683        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
684        status2 = self.ns.getJobStatus( 'TEST', jobID )
685
686        info = self.ns.getJobInfo( 'TEST', jobID )
687        status3 = info[ "status" ]
688
689        if status1 != "Done" or \
690           status2 != "Done" or \
691           status3 != "Done":
692            return False
693        return True
694
695class Scenario116( TestBase ):
696    " Scenario 116 "
697
698    def __init__( self, netschedule ):
699        TestBase.__init__( self, netschedule )
700        return
701
702    @staticmethod
703    def getScenario():
704        " Provides the scenario "
705        return "SUBMIT, GET, PUT as anon. READ as identified, STAT CLIENTS. " \
706               "CLRN, check the job status"
707
708    def execute( self ):
709        " Should return True if the execution completed successfully "
710        self.fromScratch()
711
712        ns_client = self.getNetScheduleService( 'TEST', 'scenario116' )
713        ns_client.set_client_identification( 'mynode', 'session1' )
714
715        jobID = self.ns.submitJob( 'TEST', 'bla' )
716        jobInfo = self.ns.getJob( 'TEST' )
717        self.ns.putJob( 'TEST', jobID, jobInfo[ 1 ], 0, "" )
718
719        key, state, passport = self.ns.getJobsForReading2( 'TEST', -1, '',
720                                                           'mynode',
721                                                           'session1' )
722
723        client = getClientInfo( ns_client, 'mynode' )
724        if 'reading_jobs' not in client:
725            raise Exception( "Reading job is not found" )
726        if client[ 'number_of_jobs_given_for_reading' ] != 1:
727            raise Exception( "Unexpected number of running jobs" )
728
729        execAny( ns_client, 'CLRN' )
730
731        client = getClientInfo( ns_client, 'mynode' )
732        if 'reading_jobs' in client:
733            raise Exception( "Reading job is still there" )
734        if client[ 'number_of_jobs_given_for_reading' ] != 1:
735            raise Exception( "Unexpected number of running jobs" )
736
737        # Check the status
738        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
739        status2 = self.ns.getJobStatus( 'TEST', jobID )
740
741        info = self.ns.getJobInfo( 'TEST', jobID )
742        status3 = info[ "status" ]
743
744        if status1 != "Done" or \
745           status2 != "Done" or \
746           status3 != "Done":
747            return False
748        return True
749
750class Scenario117( TestBase ):
751    " Scenario 117 "
752
753    def __init__( self, netschedule ):
754        TestBase.__init__( self, netschedule )
755        return
756
757    @staticmethod
758    def getScenario():
759        " Provides the scenario "
760        return "Two records in the clients registry"
761
762    def execute( self ):
763        " Should return True if the execution completed successfully "
764        self.fromScratch()
765
766        self.ns.getJob( 'TEST', -1, '', "", 'scenario117-1', 'default' )
767        self.ns.getJob( 'TEST', -1, '', "", 'scenario117-2', 'default' )
768
769        ns_client = self.getNetScheduleService( 'TEST', 'scenario117' )
770        try:
771            ns_client.set_client_identification( '', '' )
772        except:
773            pass
774        getClientInfo( ns_client, minClients = 2, maxClients = 2 )
775        return True
776
777class Scenario118( TestBase ):
778    " Scenario 118 "
779
780    def __init__( self, netschedule ):
781        TestBase.__init__( self, netschedule )
782        return
783
784    @staticmethod
785    def getScenario():
786        " Provides the scenario "
787        return "CHAFF as anon"
788
789    def execute( self ):
790        " Should return True if the execution completed successfully "
791        self.fromScratch()
792
793        try:
794            ns_client = self.getNetScheduleService( 'TEST', 'scenario118' )
795            try:
796                ns_client.set_client_identification( '', '' )
797            except:
798                pass
799            changeAffinity( ns_client, [ 'a1' ], [] )
800        except Exception as excp:
801            if "cannot use CHAFF command" in str( excp ):
802                return True
803            raise
804        return False
805
806class Scenario119( TestBase ):
807    " Scenario 119 "
808
809    def __init__( self, netschedule ):
810        TestBase.__init__( self, netschedule )
811        return
812
813    @staticmethod
814    def getScenario():
815        " Provides the scenario "
816        return "CHAFF as identified, STAT CLIENTS"
817
818    def execute( self ):
819        " Should return True if the execution completed successfully "
820        self.fromScratch()
821
822        ns_client = self.getNetScheduleService( 'TEST', 'scenario119' )
823        ns_client.set_client_identification( 'mynode', 'mysession' )
824        changeAffinity( ns_client, [ 'a1', 'a2' ], [] )
825
826        client = getClientInfo( ns_client, 'mynode', verbose = False )
827        if client[ 'number_of_preferred_affinities' ] != 2:
828            raise Exception( 'Unexpected length of preferred_affinities' )
829        if client[ 'type' ] not in [ 'unknown', 'worker node', 'worker node | admin' ]:
830            raise Exception( 'Unexpected client type: ' + client[ 'type' ] )
831
832        return True
833
834class Scenario120( TestBase ):
835    " Scenario 120 "
836
837    def __init__( self, netschedule ):
838        TestBase.__init__( self, netschedule )
839        return
840
841    @staticmethod
842    def getScenario():
843        " Provides the scenario "
844        return "CHAFF as identified, STAT CLIENTS VERBOSE"
845
846    def execute( self ):
847        " Should return True if the execution completed successfully "
848        self.fromScratch()
849
850        ns_client = self.getNetScheduleService( 'TEST', 'scenario120' )
851        ns_client.set_client_identification( 'mynode', 'mysession' )
852        changeAffinity( ns_client, [ 'a1', 'a2' ], [] )
853
854        client = getClientInfo( ns_client, 'mynode' )
855        if len( client[ 'preferred_affinities' ] ) != 2:
856            raise Exception( 'Unexpected length of preferred_affinities' )
857        if client[ 'preferred_affinities' ][ 0 ] != 'a1':
858            raise Exception( 'Unexpected preferred_affinities[ 0 ]' )
859        if client[ 'preferred_affinities' ][ 1 ] != 'a2':
860            raise Exception( 'Unexpected preferred_affinities[ 1 ]' )
861        if client[ 'type' ] not in [ 'unknown', 'worker node', 'worker node | admin' ]:
862            raise Exception( 'Unexpected client type: ' + client[ 'type' ] )
863
864        return True
865
866class Scenario121( TestBase ):
867    " Scenario 121 "
868
869    def __init__( self, netschedule ):
870        TestBase.__init__( self, netschedule )
871        self.warning = ""
872        return
873
874    @staticmethod
875    def getScenario():
876        " Provides the scenario "
877        return "CHAFF as identified (rm), STAT CLIENTS"
878
879    def report_warning( self, msg, server ):
880        self.warning = msg
881        return
882
883    def execute( self ):
884        " Should return True if the execution completed successfully "
885        self.fromScratch()
886
887        ns_client = self.getNetScheduleService( 'TEST', 'scenario121' )
888        ns_client.set_client_identification( 'node', 'session' )
889        ns_client.on_warning = self.report_warning
890        changeAffinity( ns_client, [], [ 'a1', 'a2' ] )
891
892        getClientInfo( ns_client, 'node', 1, 1 )
893        if "unknown affinity to delete" in self.warning:
894            return True
895        raise Exception( "The expected warning has not received" )
896
897class Scenario122( TestBase ):
898    " Scenario 122 "
899
900    def __init__( self, netschedule ):
901        TestBase.__init__( self, netschedule )
902        self.warning = ""
903        return
904
905    @staticmethod
906    def getScenario():
907        " Provides the scenario "
908        return "CHAFF as identified (add, rm), STAT CLIENTS"
909
910    def report_warning( self, msg, server ):
911        self.warning = msg
912        return
913
914    def execute( self ):
915        " Should return True if the execution completed successfully "
916        self.fromScratch()
917
918        ns_client = self.getNetScheduleService( 'TEST', 'scenario122' )
919        ns_client.set_client_identification( 'node', 'session' )
920        ns_client.on_warning = self.report_warning
921
922        changeAffinity( ns_client, [ 'a1', 'a2', 'a3' ], [] )
923        changeAffinity( ns_client, [ 'a2', 'a4' ], [ 'a1' ] )
924        client = getClientInfo( ns_client, 'node' )
925        if "already registered affinity to add" not in self.warning:
926            raise Exception( "The expected warning has not received" )
927
928        if len( client[ 'preferred_affinities' ] ) != 3 or \
929           'a2' not in client[ 'preferred_affinities' ] or \
930           'a3' not in client[ 'preferred_affinities' ] or \
931           'a4' not in client[ 'preferred_affinities' ]:
932            raise Exception( "Unexpected preferred affinities" )
933        return True
934
935class Scenario123( TestBase ):
936    " Scenario 123 "
937
938    def __init__( self, netschedule ):
939        TestBase.__init__( self, netschedule )
940        return
941
942    @staticmethod
943    def getScenario():
944        " Provides the scenario "
945        return "CHAFF as identified (add), CLRN, STAT CLIENTS"
946
947    def execute( self ):
948        " Should return True if the execution completed successfully "
949        self.fromScratch()
950
951        ns_client = self.getNetScheduleService( 'TEST', 'scenario123' )
952        ns_client.set_client_identification( 'node', 'session' )
953        changeAffinity( ns_client, [ 'a1', 'a2' ], [] )
954
955        execAny( ns_client, 'CLRN' )
956        client = getClientInfo( ns_client, 'node' )
957        if 'number_of_preferred_affinities' in client:
958            if client[ 'number_of_preferred_affinities' ] != 0:
959                raise Exception( "Expected no preferred affinities, got some." )
960        return True
961
962class Scenario124( TestBase ):
963    " Scenario 124 "
964
965    def __init__( self, netschedule ):
966        TestBase.__init__( self, netschedule )
967        return
968
969    @staticmethod
970    def getScenario():
971        " Provides the scenario "
972        return "CHAFF as identified (add), connect with another session, " \
973               "STAT CLIENTS"
974
975    def execute( self ):
976        " Should return True if the execution completed successfully "
977        self.fromScratch()
978
979        ns_client = self.getNetScheduleService( 'TEST', 'scenario124' )
980        ns_client.set_client_identification( 'node', 'session' )
981        changeAffinity( ns_client, [ 'a1', 'a2' ], [] )
982
983        self.ns.submitJob( 'TEST', 'bla', '', '', 'node', 'other_session' )
984
985        client = getClientInfo( ns_client, 'node' )
986        if 'number_of_preferred_affinities' in client:
987            if client[ 'number_of_preferred_affinities' ] != 0:
988                raise Exception( "Expected no preferred affinities, got some." )
989        return True
990
991class Scenario125( TestBase ):
992    " Scenario 125 "
993
994    def __init__( self, netschedule ):
995        TestBase.__init__( self, netschedule )
996        return
997
998    @staticmethod
999    def getScenario():
1000        " Provides the scenario "
1001        return "GET2 as anon"
1002
1003    def execute( self ):
1004        " Should return True if the execution completed successfully "
1005        self.fromScratch()
1006
1007        try:
1008            ns_client = self.getNetScheduleService( 'TEST', 'scenario125' )
1009            try:
1010                ns_client.set_client_identification( '', '' )
1011            except:
1012                pass
1013            output = execAny( ns_client,                       # analysis:ignore
1014                              'GET2 wnode_aff=1 any_aff=1' )
1015        except Exception as exc:
1016            if "Anonymous client" in str( exc ):
1017                return True
1018            raise
1019        return False
1020
1021class Scenario126( TestBase ):
1022    " Scenario 126 "
1023
1024    def __init__( self, netschedule ):
1025        TestBase.__init__( self, netschedule )
1026        return
1027
1028    @staticmethod
1029    def getScenario():
1030        " Provides the scenario "
1031        return "SUBMIT with a1, CHAFF as identified (add a0, a1, a2), " \
1032               "GET2 wnode_aff = 1"
1033
1034    def execute( self ):
1035        " Should return True if the execution completed successfully "
1036        self.fromScratch()
1037
1038        jobID = self.ns.submitJob( 'TEST', 'bla', 'a1' )
1039
1040        ns_client = self.getNetScheduleService( 'TEST', 'scenario126' )
1041        ns_client.set_client_identification( 'node', 'session' )
1042        changeAffinity( ns_client, [ 'a0', 'a1', 'a2' ], [] )
1043
1044        output = execAny( ns_client,
1045                          'GET2 wnode_aff=1 any_aff=0' )
1046        if '&' in output:
1047            values = parse_qs( output, True, True )
1048            receivedJobID = values[ 'job_key' ][ 0 ]
1049            passport = values[ 'auth_token' ][ 0 ]
1050        else:
1051            receivedJobID = output.split()[ 0 ].strip()
1052            passport = output.split( '"' )[ -1 ].strip().split()[ -1 ].strip()  # analysis:ignore
1053
1054        if jobID != receivedJobID:
1055            raise Exception( "Received job ID does not match. Expected: " + \
1056                             jobID + " Received: " + receivedJobID )
1057        return True
1058
1059class Scenario127( TestBase ):
1060    " Scenario 127 "
1061
1062    def __init__( self, netschedule ):
1063        TestBase.__init__( self, netschedule )
1064        return
1065
1066    @staticmethod
1067    def getScenario():
1068        " Provides the scenario "
1069        return "SUBMIT with a1, CHAFF as identified (add a0, a2), " \
1070               "GET2 wnode_aff = 1"
1071
1072    def execute( self ):
1073        " Should return True if the execution completed successfully "
1074        self.fromScratch()
1075
1076        jobID = self.ns.submitJob( 'TEST', 'bla', 'a1' )    # analysis:ignore
1077
1078        ns_client = self.getNetScheduleService( 'TEST', 'scenario126' )
1079        ns_client.set_client_identification( 'node', 'session' )
1080        changeAffinity( ns_client, [ 'a0', 'a2' ], [] )
1081
1082        output = execAny( ns_client,
1083                          'GET2 wnode_aff=1 any_aff=0' )
1084        if output != "":
1085            raise Exception( "Expect no jobs, but received one." )
1086        return True
1087
1088class Scenario128( TestBase ):
1089    " Scenario 128 "
1090
1091    def __init__( self, netschedule ):
1092        TestBase.__init__( self, netschedule )
1093        return
1094
1095    @staticmethod
1096    def getScenario():
1097        " Provides the scenario "
1098        return "CHAFF as identified (add a0, a1, a2), SUBMIT with a1, " \
1099               "GET2 wnode_aff = 1"
1100
1101    def execute( self ):
1102        " Should return True if the execution completed successfully "
1103        self.fromScratch()
1104
1105        ns_client = self.getNetScheduleService( 'TEST', 'scenario126' )
1106        ns_client.set_client_identification( 'node', 'session' )
1107        changeAffinity( ns_client, [ 'a0', 'a1', 'a2' ], [] )
1108        jobID = self.ns.submitJob( 'TEST', 'bla', 'a1' )
1109
1110        output = execAny( ns_client,
1111                          'GET2 wnode_aff=1 any_aff=0' )
1112        if '&' in output:
1113            values = parse_qs( output, True, True )
1114            receivedJobID = values[ 'job_key' ][ 0 ]
1115            passport = values[ 'auth_token' ][ 0 ]
1116        else:
1117            receivedJobID = output.split()[ 0 ].strip()
1118            passport = output.split( '"' )[ -1 ].strip().split()[ -1 ].strip()  # analysis:ignore
1119
1120        if jobID != receivedJobID:
1121            raise Exception( "Received job ID does not match. Expected: " + \
1122                             jobID + " Received: " + receivedJobID )
1123        return True
1124
1125class Scenario129( TestBase ):
1126    " Scenario 129 "
1127
1128    def __init__( self, netschedule ):
1129        TestBase.__init__( self, netschedule )
1130        return
1131
1132    @staticmethod
1133    def getScenario():
1134        " Provides the scenario "
1135        return "CHAFF as identified (add a0, a1, a2), SUBMIT with a5, " \
1136               "GET2 wnode_aff = 1"
1137
1138    def execute( self ):
1139        " Should return True if the execution completed successfully "
1140        self.fromScratch()
1141
1142        ns_client = self.getNetScheduleService( 'TEST', 'scenario126' )
1143        ns_client.set_client_identification( 'node', 'session' )
1144
1145        changeAffinity( ns_client, [ 'a0', 'a1', 'a2' ], [] )
1146        jobID = self.ns.submitJob( 'TEST', 'bla', 'a5' )    # analysis:ignore
1147
1148        output = execAny( ns_client,
1149                          'GET2 wnode_aff=1 any_aff=0' )
1150
1151        if output != "":
1152            raise Exception( "Expect no jobs, but received one." )
1153        return True
1154
1155class Scenario131( TestBase ):
1156    " Scenario 131 "
1157
1158    def __init__( self, netschedule ):
1159        TestBase.__init__( self, netschedule )
1160        return
1161
1162    @staticmethod
1163    def getScenario():
1164        " Provides the scenario "
1165        return "SUBMIT with a1, CHAFF add=a2, GET2 wnode_aff = 1 any_aff=1"
1166
1167    def execute( self ):
1168        " Should return True if the execution completed successfully "
1169        self.fromScratch()
1170
1171        jobID = self.ns.submitJob( 'TEST', 'bla', 'a1' )
1172
1173        ns_client = self.getNetScheduleService( 'TEST', 'scenario131' )
1174        ns_client.set_client_identification( 'node', 'session' )
1175
1176        changeAffinity( ns_client, [ 'a2' ], [] )
1177
1178        output = execAny( ns_client,
1179                          'GET2 wnode_aff=1 any_aff=1' )
1180        if '&' in output:
1181            values = parse_qs( output, True, True )
1182            receivedJobID = values[ 'job_key' ][ 0 ]
1183            passport = values[ 'auth_token' ][ 0 ]
1184        else:
1185            receivedJobID = output.split()[ 0 ].strip()
1186            passport = output.split( '"' )[ -1 ].strip().split()[ -1 ].strip() # analysis:ignore
1187
1188        if jobID != receivedJobID:
1189            raise Exception( "Received job ID does not match. Expected: " + \
1190                             jobID + " Received: " + receivedJobID )
1191        return True
1192
1193class Scenario132( TestBase ):
1194    " Scenario 132 "
1195
1196    def __init__( self, netschedule ):
1197        TestBase.__init__( self, netschedule )
1198        return
1199
1200    @staticmethod
1201    def getScenario():
1202        " Provides the scenario "
1203        return "SUBMIT with a0, SUBMIT with a1, SUBMIT with no aff, " \
1204               "CHAFF add=a2, GET2 aff=a1 wnode_aff = 1 any_aff=1"
1205
1206    def execute( self ):
1207        " Should return True if the execution completed successfully "
1208        self.fromScratch()
1209
1210        jobID1 = self.ns.submitJob( 'TEST', 'bla', 'a0' )   # analysis:ignore
1211        jobID2 = self.ns.submitJob( 'TEST', 'bla', 'a1' )
1212        jobID3 = self.ns.submitJob( 'TEST', 'bla', '' )     # analysis:ignore
1213
1214        ns_client = self.getNetScheduleService( 'TEST', 'scenario132' )
1215        ns_client.set_client_identification( 'node', 'session' )
1216
1217        changeAffinity( ns_client, [ 'a2' ], [] )
1218
1219        output = execAny( ns_client,
1220                          'GET2 wnode_aff=1 any_aff=1 aff=a1' )
1221        if '&' in output:
1222            values = parse_qs( output, True, True )
1223            receivedJobID = values[ 'job_key' ][ 0 ]
1224            passport = values[ 'auth_token' ][ 0 ]
1225        else:
1226            receivedJobID = output.split()[ 0 ].strip()
1227            passport = output.split( '"' )[ -1 ].strip().split()[ -1 ].strip()  # analysis:ignore
1228
1229        if jobID2 != receivedJobID:
1230            raise Exception( "Received job ID does not match. Expected: " + \
1231                             jobID2 + " Received: " + receivedJobID )
1232        return True
1233
1234class Scenario133( TestBase ):
1235    " Scenario 133 "
1236
1237    def __init__( self, netschedule ):
1238        TestBase.__init__( self, netschedule )
1239        return
1240
1241    @staticmethod
1242    def getScenario():
1243        " Provides the scenario "
1244        return "SUBMIT with a1, SUBMIT with a2, SUBMIT with no aff, " \
1245               "CHAFF add=a2, GET2 aff=a5 wnode_aff = 1 any_aff=1"
1246
1247    def execute( self ):
1248        " Should return True if the execution completed successfully "
1249        self.fromScratch()
1250
1251        jobID1 = self.ns.submitJob( 'TEST', 'bla', 'a1' )   # analysis:ignore
1252        jobID2 = self.ns.submitJob( 'TEST', 'bla', 'a2' )
1253        jobID3 = self.ns.submitJob( 'TEST', 'bla', '' )     # analysis:ignore
1254
1255        ns_client = self.getNetScheduleService( 'TEST', 'scenario133' )
1256        ns_client.set_client_identification( 'node', 'session' )
1257
1258        changeAffinity( ns_client, [ 'a2' ], [] )
1259
1260        output = execAny( ns_client,
1261                          'GET2 wnode_aff=1 any_aff=1 aff=a5' )
1262        if '&' in output:
1263            values = parse_qs( output, True, True )
1264            receivedJobID = values[ 'job_key' ][ 0 ]
1265            passport = values[ 'auth_token' ][ 0 ]
1266        else:
1267            receivedJobID = output.split()[ 0 ].strip()
1268            passport = output.split( '"' )[ -1 ].strip().split()[ -1 ].strip()  # analysis:ignore
1269
1270        if jobID2 != receivedJobID:
1271            raise Exception( "Received job ID does not match. Expected: " + \
1272                             jobID2 + " Received: " + receivedJobID )
1273        return True
1274
1275class Scenario134( TestBase ):
1276    " Scenario 134 "
1277
1278    def __init__( self, netschedule ):
1279        TestBase.__init__( self, netschedule )
1280        return
1281
1282    @staticmethod
1283    def getScenario():
1284        " Provides the scenario "
1285        return "SUBMIT with a1, SUBMIT with a2, SUBMIT with no aff, " \
1286               "CHAFF add=a2, GET2 aff=a5 wnode_aff=0 any_aff=1"
1287
1288    def execute( self ):
1289        " Should return True if the execution completed successfully "
1290        self.fromScratch()
1291
1292        jobID1 = self.ns.submitJob( 'TEST', 'bla', 'a1' )
1293        jobID2 = self.ns.submitJob( 'TEST', 'bla', 'a2' )   # analysis:ignore
1294        jobID3 = self.ns.submitJob( 'TEST', 'bla', '' )     # analysis:ignore
1295
1296        ns_client = self.getNetScheduleService( 'TEST', 'scenario134' )
1297        ns_client.set_client_identification( 'node', 'session' )
1298
1299        changeAffinity( ns_client, [ 'a2' ], [] )
1300
1301        output = execAny( ns_client,
1302                          'GET2 wnode_aff=0 any_aff=1 aff=a5' )
1303        if '&' in output:
1304            values = parse_qs( output, True, True )
1305            receivedJobID = values[ 'job_key' ][ 0 ]
1306            passport = values[ 'auth_token' ][ 0 ]
1307        else:
1308            receivedJobID = output.split()[ 0 ].strip()
1309            passport = output.split( '"' )[ -1 ].strip().split()[ -1 ].strip()  # analysis:ignore
1310
1311        if jobID1 != receivedJobID:
1312            raise Exception( "Received job ID does not match. Expected: " + \
1313                             jobID1 + " Received: " + receivedJobID )
1314        return True
1315
1316class Scenario135( TestBase ):
1317    " Scenario 135 "
1318
1319    def __init__( self, netschedule ):
1320        TestBase.__init__( self, netschedule )
1321        return
1322
1323    @staticmethod
1324    def getScenario():
1325        " Provides the scenario "
1326        return "SUBMIT with a1, SUBMIT with a2, SUBMIT with no aff, " \
1327               "CHAFF add=a7, GET2 aff=a5 wnode_aff=1 any_aff=0"
1328
1329    def execute( self ):
1330        " Should return True if the execution completed successfully "
1331        self.fromScratch()
1332
1333        jobID1 = self.ns.submitJob( 'TEST', 'bla', 'a1' )   # analysis:ignore
1334        jobID2 = self.ns.submitJob( 'TEST', 'bla', 'a2' )   # analysis:ignore
1335        jobID3 = self.ns.submitJob( 'TEST', 'bla', '' )     # analysis:ignore
1336
1337        ns_client = self.getNetScheduleService( 'TEST', 'scenario135' )
1338        ns_client.set_client_identification( 'node', 'session' )
1339
1340        changeAffinity( ns_client, [ 'a7' ], [] )
1341
1342        output = execAny( ns_client,
1343                          'GET2 wnode_aff=1 any_aff=0 aff=a5' )
1344        if output != "":
1345            raise Exception( "Expect no jobs, but received one." )
1346        return True
1347
1348class Scenario136( TestBase ):
1349    " Scenario 136 "
1350
1351    def __init__( self, netschedule ):
1352        TestBase.__init__( self, netschedule )
1353        return
1354
1355    @staticmethod
1356    def getScenario():
1357        " Provides the scenario "
1358        return "SUBMIT with a1, SUBMIT with a2, SUBMIT with no aff, " \
1359               "CHAFF add=a7, GET2 aff=a5 wnode_aff=1 any_aff=1"
1360
1361    def execute( self ):
1362        " Should return True if the execution completed successfully "
1363        self.fromScratch()
1364
1365        jobID1 = self.ns.submitJob( 'TEST', 'bla', 'a1' )
1366        jobID2 = self.ns.submitJob( 'TEST', 'bla', 'a2' )   # analysis:ignore
1367        jobID3 = self.ns.submitJob( 'TEST', 'bla', '' )     # analysis:ignore
1368
1369        ns_client = self.getNetScheduleService( 'TEST', 'scenario136' )
1370        ns_client.set_client_identification( 'node', 'session' )
1371
1372        changeAffinity( ns_client, [ 'a7' ], [] )
1373
1374        output = execAny( ns_client,
1375                          'GET2 wnode_aff=1 any_aff=1 aff=a5' )
1376        if '&' in output:
1377            values = parse_qs( output, True, True )
1378            receivedJobID = values[ 'job_key' ][ 0 ]
1379            passport = values[ 'auth_token' ][ 0 ]
1380        else:
1381            receivedJobID = output.split()[ 0 ].strip()
1382            passport = output.split( '"' )[ -1 ].strip().split()[ -1 ].strip()  # analysis:ignore
1383
1384        if jobID1 != receivedJobID:
1385            raise Exception( "Received job ID does not match. Expected: " + \
1386                             jobID1 + " Received: " + receivedJobID )
1387        return True
1388
1389class Scenario137( TestBase ):
1390    " Scenario 137 "
1391
1392    def __init__( self, netschedule ):
1393        TestBase.__init__( self, netschedule )
1394        return
1395
1396    @staticmethod
1397    def getScenario():
1398        " Provides the scenario "
1399        return "SUBMIT with a1, restart netschedule, " \
1400               "CHAFF add=a1, GET2 wnode_aff=1"
1401
1402    def execute( self ):
1403        " Should return True if the execution completed successfully "
1404        self.fromScratch()
1405
1406        jobID1 = self.ns.submitJob( 'TEST', 'bla', 'a1' )
1407
1408        self.ns.shutdown()
1409        self.ns.resetPID()
1410        time.sleep( 15 )
1411        if self.ns.isRunning():
1412            raise Exception( "Cannot shutdown netschedule" )
1413
1414        self.ns.start()
1415        if not self.ns.isRunning():
1416            raise Exception( "Cannot start netschedule" )
1417
1418        ns_client = self.getNetScheduleService( 'TEST', 'scenario136' )
1419        ns_client.set_client_identification( 'node', 'session' )
1420
1421        changeAffinity( ns_client, [ 'a1' ], [] )
1422
1423        output = execAny( ns_client,
1424                          'GET2 wnode_aff=1 any_aff=0' )
1425        if '&' in output:
1426            values = parse_qs( output, True, True )
1427            receivedJobID = values[ 'job_key' ][ 0 ]
1428            passport = values[ 'auth_token' ][ 0 ]
1429        else:
1430            receivedJobID = output.split()[ 0 ].strip()
1431            passport = output.split( '"' )[ -1 ].strip().split()[ -1 ].strip()  # analysis:ignore
1432
1433        if jobID1 != receivedJobID:
1434            raise Exception( "Received job ID does not match. Expected: " + \
1435                             jobID1 + " Received: " + receivedJobID )
1436        return True
1437
1438class Scenario138( TestBase ):
1439    " Scenario 138 "
1440
1441    def __init__( self, netschedule ):
1442        TestBase.__init__( self, netschedule )
1443        return
1444
1445    @staticmethod
1446    def getScenario():
1447        " Provides the scenario "
1448        return " Return unknown job "
1449
1450    def execute( self ):
1451        " Should return True if the execution completed successfully "
1452        self.fromScratch()
1453
1454        try:
1455            # Job is unknown, but the key format is just fine
1456            self.ns.returnJob( "TEST", NON_EXISTED_JOB, ANY_AUTH_TOKEN )
1457        except Exception as exc:
1458            if "Job not found" in str( exc ) or \
1459               "eJobNotFound" in str( exc ):
1460                return True
1461            raise
1462
1463        return False
1464
1465
1466class Scenario139( TestBase ):
1467    " Scenario 139 "
1468
1469    def __init__( self, netschedule ):
1470        TestBase.__init__( self, netschedule )
1471        return
1472
1473    @staticmethod
1474    def getScenario():
1475        " Provides the scenario "
1476        return " SUBMIT a job, DROJ it. Check the job status. "
1477
1478    def execute( self ):
1479        " Should return True if the execution completed successfully "
1480        self.fromScratch()
1481
1482        jobID = self.ns.submitJob( 'TEST', 'bla' )
1483        # DROJ is obsolete, it is now == cancel
1484        self.ns.cancelJob( 'TEST', jobID )
1485
1486        # Check the job status using 3 ways
1487        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
1488        status2 = self.ns.getJobStatus( 'TEST', jobID )
1489
1490        info = self.ns.getJobInfo( 'TEST', jobID )
1491        status3 = info[ "status" ]
1492
1493        if status1 == "Canceled" and \
1494           status2 == "Canceled" and \
1495           status3 == "Canceled":
1496            return True
1497        return False
1498
1499
1500class Scenario140( TestBase ):
1501    " Scenario 140 "
1502
1503    def __init__( self, netschedule ):
1504        TestBase.__init__( self, netschedule )
1505        return
1506
1507    @staticmethod
1508    def getScenario():
1509        " Provides the scenario "
1510        return " GETCONF as an administrator "
1511
1512    def execute( self ):
1513        " Should return True if the execution completed successfully "
1514        self.fromScratch()
1515
1516        config = self.ns.getServerConfiguration( "netschedule_admin" )
1517        return "node_id" in config
1518
1519
1520class Scenario141( TestBase ):
1521    " Scenario 141 "
1522
1523    def __init__( self, netschedule ):
1524        TestBase.__init__( self, netschedule )
1525        return
1526
1527    @staticmethod
1528    def getScenario():
1529        " Provides the scenario "
1530        return " GETCONF as nobody "
1531
1532    def execute( self ):
1533        " Should return True if the execution completed successfully "
1534        self.fromScratch()
1535
1536        try:
1537            self.ns.getServerConfiguration()
1538        except Exception as exc:
1539            if "Access denied: admin privileges required" in str( exc ):
1540                return True
1541            raise
1542
1543        return False
1544
1545
1546class Scenario142( TestBase ):
1547    " Scenario 142 "
1548
1549    def __init__( self, netschedule ):
1550        TestBase.__init__( self, netschedule )
1551        return
1552
1553    @staticmethod
1554    def getScenario():
1555        " Provides the scenario "
1556        return " CANCEL a job twice "
1557
1558    def execute( self ):
1559        " Should return True if the execution completed successfully "
1560        self.fromScratch()
1561
1562        jobID = self.ns.submitJob( 'TEST', 'bla' )
1563        self.ns.cancelJob( 'TEST', jobID )
1564
1565        # Check the job status using 3 ways
1566        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
1567        status2 = self.ns.getJobStatus( 'TEST', jobID )
1568
1569        info = self.ns.getJobInfo( 'TEST', jobID )
1570        status3 = info[ "status" ]
1571
1572        if status1 != "Canceled" or \
1573           status2 != "Canceled" or \
1574           status3 != "Canceled":
1575            return False
1576
1577        # Cancel the job again
1578        self.ns.cancelJob( 'TEST', jobID )
1579
1580        # Check the job status using 3 ways
1581        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
1582        status2 = self.ns.getJobStatus( 'TEST', jobID )
1583
1584        info = self.ns.getJobInfo( 'TEST', jobID )
1585        status3 = info[ "status" ]
1586
1587        if status1 != "Canceled" or \
1588           status2 != "Canceled" or \
1589           status3 != "Canceled":
1590            return False
1591
1592        return True
1593
1594
1595class Scenario143( TestBase ):
1596    " Scenario 143 "
1597
1598    def __init__( self, netschedule ):
1599        TestBase.__init__( self, netschedule )
1600        return
1601
1602    @staticmethod
1603    def getScenario():
1604        " Provides the scenario "
1605        return " SUBMIT, GET, wait till timeout, check status "
1606
1607    def execute( self ):
1608        " Should return True if the execution completed successfully "
1609        self.fromScratch()
1610
1611        jobID = self.ns.submitJob( 'TEST', 'bla' )
1612        jobIDReceived = self.ns.getJob( 'TEST' )[ 0 ]
1613
1614        if jobID != jobIDReceived:
1615            raise Exception( "Inconsistency detected" )
1616
1617        time.sleep( 15 )
1618
1619        # Check the status
1620        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
1621        status2 = self.ns.getJobStatus( 'TEST', jobID )
1622
1623        info = self.ns.getJobInfo( 'TEST', jobID )
1624        status3 = info[ "status" ]
1625
1626        if status1 != "Pending" or \
1627           status2 != "Pending" or \
1628           status3 != "Pending":
1629            return False
1630        return True
1631
1632class Scenario144( TestBase ):
1633    " Scenario 144 "
1634
1635    def __init__( self, netschedule ):
1636        TestBase.__init__( self, netschedule )
1637        return
1638
1639    @staticmethod
1640    def getScenario():
1641        " Provides the scenario "
1642        return " SUBMIT, GET, PUT, READ, wait till timeout, check status "
1643
1644    def execute( self ):
1645        " Should return True if the execution completed successfully "
1646        self.fromScratch()
1647
1648        jobID = self.ns.submitJob( 'TEST', 'bla' )
1649        jobInfo = self.ns.getJob( 'TEST' )
1650
1651        if jobID != jobInfo[ 0 ]:
1652            raise Exception( "Inconsistency detected" )
1653
1654        self.ns.putJob( 'TEST', jobID, jobInfo[ 1 ], 0, "" )
1655        readJobID, state, passport = self.ns.getJobsForReading2( 'TEST', -1, '',
1656                                                                 'mynode',
1657                                                                 'session1' )
1658        if readJobID != jobID:
1659            raise Exception( "Unexpected job received for reading." )
1660
1661        time.sleep( 15 )
1662
1663        # Check the status
1664        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
1665        status2 = self.ns.getJobStatus( 'TEST', jobID )
1666
1667        info = self.ns.getJobInfo( 'TEST', jobID )
1668        status3 = info[ "status" ]
1669
1670        if status1 != "Done" or \
1671           status2 != "Done" or \
1672           status3 != "Done":
1673            raise Exception( "Unexpected job status. Expected: Done. "
1674                             "WST report: " + status1 + " "
1675                             "SST report: " + status2 + " "
1676                             "DUMP report: " + status3 )
1677        return True
1678
1679class Scenario145( TestBase ):
1680    " Scenario 145 "
1681
1682    def __init__( self, netschedule ):
1683        TestBase.__init__( self, netschedule )
1684        return
1685
1686    @staticmethod
1687    def getScenario():
1688        " Provides the scenario "
1689        return " SUBMIT, GET, wait till timeout, disconnect, GET, check status "
1690
1691    def execute( self ):
1692        " Should return True if the execution completed successfully "
1693        self.fromScratch()
1694
1695        jobID = self.ns.submitJob( 'TEST', 'bla' )
1696        jobIDReceived = self.ns.getJob( 'TEST', node = 'client1' )[ 0 ]
1697
1698        if jobID != jobIDReceived:
1699            raise Exception( "Inconsistency 1 detected" )
1700
1701        time.sleep( 15 )
1702
1703        jobInfo = self.ns.getJob( 'TEST', node = 'client2' )
1704        if not jobInfo or jobID != jobInfo[ 0 ]:
1705            raise Exception( "Inconsistency 2 detected" )
1706
1707        # Check the status
1708        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
1709        status2 = self.ns.getJobStatus( 'TEST', jobID )
1710
1711        info = self.ns.getJobInfo( 'TEST', jobID )
1712        status3 = info[ "status" ]
1713
1714        if status1 != "Running" or \
1715           status2 != "Running" or \
1716           status3 != "Running":
1717            return False
1718        return True
1719
1720
1721class Scenario146( TestBase ):
1722    " Scenario 146 "
1723
1724    def __init__( self, netschedule ):
1725        TestBase.__init__( self, netschedule )
1726        self.jobID = None
1727        return
1728
1729    @staticmethod
1730    def getScenario():
1731        " Provides the scenario "
1732        return " SUBMIT, [GET, FAIL] 3 times, check run_counter "
1733
1734    def getAndFail( self, clientNode ):
1735        " get a job and then fail it "
1736        jobInfo = self.ns.getJob( 'TEST', node = clientNode )
1737        jobIDReceived = jobInfo[ 0 ]
1738        if self.jobID != jobIDReceived:
1739            raise Exception( "Inconsistency detected" )
1740        self.ns.failJob( 'TEST', self.jobID, jobInfo[ 1 ], 3 )
1741        return
1742
1743    def execute( self ):
1744        " Should return True if the execution completed successfully "
1745        self.fromScratch()
1746
1747        self.jobID = self.ns.submitJob( 'TEST', 'bla' )
1748        self.getAndFail('client1')
1749        self.getAndFail('client2')
1750        self.getAndFail('client3')
1751
1752        # Check the run_counter
1753        info = self.ns.getJobInfo( 'TEST', self.jobID )
1754        return info[ "run_counter" ] == "3"
1755
1756
1757
1758class Scenario147( TestBase ):
1759    " Scenario 147 "
1760
1761    def __init__( self, netschedule ):
1762        TestBase.__init__( self, netschedule )
1763        self.jobID = None
1764        return
1765
1766    @staticmethod
1767    def getScenario():
1768        " Provides the scenario "
1769        return " SUBMIT, [GET, FAIL] 4 times, check status "
1770
1771    def getAndFail( self, clientNode ):
1772        " get a job and then fail it "
1773        jobInfo = self.ns.getJob( 'TEST', node = clientNode )
1774        jobIDReceived = jobInfo[ 0 ]
1775        if self.jobID != jobIDReceived:
1776            raise Exception( "Inconsistency detected" )
1777        self.ns.failJob( 'TEST', self.jobID, jobInfo[ 1 ], 3 )
1778        return
1779
1780    def execute( self ):
1781        " Should return True if the execution completed successfully "
1782        self.fromScratch()
1783
1784        self.jobID = self.ns.submitJob( 'TEST', 'bla' )
1785        self.getAndFail('client1')
1786        self.getAndFail('client2')
1787        self.getAndFail('client3')
1788        self.getAndFail('client4')
1789
1790        # Check the status
1791        status1 = self.ns.getFastJobStatus( 'TEST', self.jobID )
1792        status2 = self.ns.getJobStatus( 'TEST', self.jobID )
1793
1794        info = self.ns.getJobInfo( 'TEST', self.jobID )
1795        status3 = info[ "status" ]
1796
1797        if status1 != "Failed" or \
1798           status2 != "Failed" or \
1799           status3 != "Failed":
1800            return False
1801        return True
1802
1803class Scenario148( TestBase ):
1804    " Scenario 148 "
1805
1806    def __init__( self, netschedule ):
1807        TestBase.__init__( self, netschedule )
1808        self.count = 0
1809        return
1810
1811    @staticmethod
1812    def getScenario():
1813        " Provides the scenario "
1814        return " SUBMIT, GET, [READ, FAIL READ] 4 times, check status "
1815
1816    def readAndFail( self ):
1817        " get a job and then fail it "
1818        readJobID, \
1819        state, \
1820        passport = self.ns.getJobsForReading2( 'TEST', -1, '',
1821                                               str( self.count ),
1822                                               str( self.count ) )
1823        self.ns.failRead2( 'TEST', readJobID, passport, "",
1824                           str( self.count ), str( self.count ) )
1825        self.count += 1
1826        return
1827
1828    def execute( self ):
1829        " Should return True if the execution completed successfully "
1830        self.fromScratch()
1831
1832        jobID = self.ns.submitJob( 'TEST', 'bla' )
1833        jobInfo = self.ns.getJob( 'TEST' )
1834        self.ns.putJob( 'TEST', jobID, jobInfo[ 1 ], 0, "" )
1835
1836        self.readAndFail()
1837        self.readAndFail()
1838        self.readAndFail()
1839        self.readAndFail()
1840
1841        # Check the status
1842        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
1843        status2 = self.ns.getJobStatus( 'TEST', jobID )
1844
1845        info = self.ns.getJobInfo( 'TEST', jobID )
1846        status3 = info[ "status" ]
1847
1848        if status1 != "ReadFailed" or \
1849           status2 != "ReadFailed" or \
1850           status3 != "ReadFailed":
1851            return False
1852        return True
1853
1854class Scenario149( TestBase ):
1855    " Scenario 149 "
1856
1857    def __init__( self, netschedule ):
1858        TestBase.__init__( self, netschedule )
1859        self.jobID = None
1860        return
1861
1862    @staticmethod
1863    def getScenario():
1864        " Provides the scenario "
1865        return " SUBMIT, [GET, wait till fail] 4 times, check status "
1866
1867    def getAndWaitTillFail( self, clientNode ):
1868        " get a job and then fail it "
1869        jobIDReceived = self.ns.getJob( 'TEST', node = clientNode )[ 0 ]
1870        if self.jobID != jobIDReceived:
1871            raise Exception( "Inconsistency detected" )
1872        time.sleep( 15 )
1873        return
1874
1875    def execute( self ):
1876        " Should return True if the execution completed successfully "
1877        self.fromScratch()
1878
1879        self.jobID = self.ns.submitJob( 'TEST', 'bla' )
1880        self.getAndWaitTillFail('client1')
1881        self.getAndWaitTillFail('client2')
1882        self.getAndWaitTillFail('client3')
1883        self.getAndWaitTillFail('client4')
1884
1885        # Check the status
1886        status1 = self.ns.getFastJobStatus( 'TEST', self.jobID )
1887        status2 = self.ns.getJobStatus( 'TEST', self.jobID )
1888
1889        info = self.ns.getJobInfo( 'TEST', self.jobID )
1890        status3 = info[ "status" ]
1891
1892        if status1 != "Failed" or \
1893           status2 != "Failed" or \
1894           status3 != "Failed":
1895            return False
1896        return True
1897
1898class Scenario150( TestBase ):
1899    " Scenario 150 "
1900
1901    def __init__( self, netschedule ):
1902        TestBase.__init__( self, netschedule )
1903        self.count = 0
1904        self.jobID = None
1905        return
1906
1907    @staticmethod
1908    def getScenario():
1909        " Provides the scenario "
1910        return " SUBMIT, GET, PUT, [READ, wait till fail] 4 times, check status "
1911
1912    def readAndWaitTillFail( self ):
1913        " read a job and then fail it "
1914        readJobID, \
1915        state, \
1916        passport = self.ns.getJobsForReading2( 'TEST', -1, '',
1917                                               str( self.count ),
1918                                               str( self.count ) )
1919        self.count += 1
1920        if self.jobID != readJobID:
1921            raise Exception( "Inconsistency detected" )
1922        time.sleep( 15 )
1923        return
1924
1925    def execute( self ):
1926        " Should return True if the execution completed successfully "
1927        self.fromScratch()
1928
1929        self.jobID = self.ns.submitJob( 'TEST', 'bla' )
1930        jobInfo = self.ns.getJob( 'TEST' )
1931        receivedJobID = jobInfo[ 0 ]
1932        if self.jobID != receivedJobID:
1933            raise Exception( "Inconsistency detected. Submitted job: '" +
1934                             self.jobID + "', received job: '" +
1935                             receivedJobID + "'" )
1936        self.ns.putJob( 'TEST', self.jobID, jobInfo[ 1 ], 0, "" )
1937
1938        self.readAndWaitTillFail()
1939        self.readAndWaitTillFail()
1940        self.readAndWaitTillFail()
1941        self.readAndWaitTillFail()
1942
1943        # Check the status
1944        status1 = self.ns.getFastJobStatus( 'TEST', self.jobID )
1945        status2 = self.ns.getJobStatus( 'TEST', self.jobID )
1946
1947        info = self.ns.getJobInfo( 'TEST', self.jobID )
1948        status3 = info[ "status" ]
1949
1950        if status1 != "ReadFailed" or \
1951           status2 != "ReadFailed" or \
1952           status3 != "ReadFailed":
1953            return False
1954        return True
1955
1956class Scenario151( TestBase ):
1957    " Scenario 151 "
1958
1959    def __init__( self, netschedule ):
1960        TestBase.__init__( self, netschedule )
1961        self.jobID = None
1962        return
1963
1964    @staticmethod
1965    def getScenario():
1966        " Provides the scenario "
1967        return "SUBMIT, GET, PUT, READ, DUMP -> check read counter, " \
1968               "wait till timeout, READ, DUMP -> check read counter, " \
1969               "RDRB, DUMP -> check read counter, " \
1970               "READ, DUMP -> check read counter, " \
1971               "CFRM, DUMP -> check read counter"
1972
1973    def checkReadCounter( self, expectedCount ):
1974        " Checks a job read counter "
1975        info = self.ns.getJobInfo( 'TEST', self.jobID )
1976        counter = int( info[ "read_counter" ] )
1977        if counter != expectedCount:
1978            raise Exception( "Unexpected read counter. Expected: " + \
1979                             str( expectedCount ) + \
1980                             " Received: " + str( counter ) )
1981        return
1982
1983    def execute( self ):
1984        " Should return True if the execution completed successfully "
1985        self.fromScratch()
1986
1987        self.jobID = self.ns.submitJob( 'TEST', 'bla' )
1988        jobInfo = self.ns.getJob( 'TEST' )
1989        receivedJobID = jobInfo[ 0 ]
1990        if self.jobID != receivedJobID:
1991            raise Exception( "Inconsistency detected" )
1992        self.ns.putJob( 'TEST', self.jobID, jobInfo[ 1 ], 0, "" )
1993        jobID, s, p = self.ns.getJobsForReading2( 'TEST', -1, '', 'n1', 's' )
1994        self.checkReadCounter( 1 )
1995
1996        time.sleep( 15 )
1997        jobID, s, p = self.ns.getJobsForReading2( 'TEST', -1, '', 'n2', 's' )
1998        self.checkReadCounter( 2 )
1999
2000        self.ns.rollbackRead2( 'TEST', self.jobID, p, "n", "s" )
2001        self.checkReadCounter( 1 )
2002
2003        jobID, s, p = self.ns.getJobsForReading2( 'TEST', -1, '', 'n3', 's' )
2004        self.checkReadCounter( 2 )
2005
2006        self.ns.confirmRead2( 'TEST', self.jobID, p, 'n', 's' )
2007        self.checkReadCounter( 2 )
2008        return True
2009
2010class Scenario153( TestBase ):
2011    " Scenario 153 "
2012
2013    def __init__( self, netschedule ):
2014        TestBase.__init__( self, netschedule )
2015        return
2016
2017    @staticmethod
2018    def getScenario():
2019        " Provides the scenario "
2020        return "SUBMIT, GET, PUT, READ, check status, STAT CLIENTS"
2021
2022    def execute( self ):
2023        " Should return True if the execution completed successfully "
2024        self.fromScratch()
2025
2026        jobID = self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', 'mysession' )
2027        jobInfo = self.ns.getJob( 'TEST',
2028                node = 'mynode', session = 'mysession' )
2029        if jobID != jobInfo[ 0 ]:
2030            raise Exception( "Inconsistency detected" )
2031        self.ns.putJob( 'TEST', jobID, jobInfo[ 1 ], 0, "",
2032                        'mynode', 'mysession' )
2033        readJobID, \
2034        state, \
2035        passport = self.ns.getJobsForReading2( 'TEST', -1, '',
2036                                               'mynode', 'mysession' )
2037
2038        # Check the status
2039        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
2040        status2 = self.ns.getJobStatus( 'TEST', jobID )
2041
2042        info = self.ns.getJobInfo( 'TEST', jobID )
2043        status3 = info[ "status" ]
2044
2045        if status1 != "Reading" or \
2046           status2 != "Reading" or \
2047           status3 != "Reading":
2048            return False
2049
2050        ns_client = self.getNetScheduleService( 'TEST', 'scenario169' )
2051        client = getClientInfo( ns_client, 'mynode' )
2052        if len( client[ 'reading_jobs' ] ) != 1 or \
2053           client[ 'reading_jobs' ][ 0 ] != jobID:
2054            raise Exception( "Wrong job in the reading jobs list" )
2055        return True
2056
2057class Scenario154( TestBase ):
2058    " Scenario 154 "
2059
2060    def __init__( self, netschedule ):
2061        TestBase.__init__( self, netschedule )
2062        return
2063
2064    @staticmethod
2065    def getScenario():
2066        " Provides the scenario "
2067        return "SUBMIT, GET, PUT, READ, CFRM, check status and reading count"
2068
2069    def execute( self ):
2070        " Should return True if the execution completed successfully "
2071        self.fromScratch()
2072
2073        jobID = self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', 'mysession' )
2074        jobInfo = self.ns.getJob( 'TEST', -1, '', "", 'mynode', 'mysession' )
2075        jobIDReceived = jobInfo[ 0 ]
2076        if jobID != jobIDReceived:
2077            raise Exception( "Inconsistency detected" )
2078        self.ns.putJob( 'TEST', jobID, jobInfo[ 1 ], 0, "",
2079                        'mynode', 'mysession' )
2080        jobIDReceived, \
2081        state, \
2082        passport = self.ns.getJobsForReading2( 'TEST', -1, '',
2083                                               'mynode', 'mysession' )
2084        if jobID != jobIDReceived:
2085            raise Exception( "Inconsistency detected" )
2086        self.ns.confirmRead2( 'TEST', jobID, passport, 'mynode', 'mysession' )
2087
2088        # Check the status
2089        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
2090        status2 = self.ns.getJobStatus( 'TEST', jobID )
2091
2092        info = self.ns.getJobInfo( 'TEST', jobID )
2093        status3 = info[ "status" ]
2094
2095        if status1 != "Confirmed" or \
2096           status2 != "Confirmed" or \
2097           status3 != "Confirmed":
2098            raise Exception( "Unexpected job status" )
2099        if int( info[ "read_counter" ] ) != 1:
2100            raise Exception( "Unexpected reading count" )
2101        return True
2102
2103class Scenario155( TestBase ):
2104    " Scenario 155 "
2105
2106    def __init__( self, netschedule ):
2107        TestBase.__init__( self, netschedule )
2108        return
2109
2110    @staticmethod
2111    def getScenario():
2112        " Provides the scenario "
2113        return "SUBMIT, GET, PUT, READ, RDRB, check status and reading count"
2114
2115    def execute( self ):
2116        " Should return True if the execution completed successfully "
2117        self.fromScratch()
2118
2119        jobID = self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', 'mysession' )
2120        jobInfo = self.ns.getJob( 'TEST', -1, '', "", 'mynode', 'mysession' )
2121        jobIDReceived = jobInfo [ 0 ]
2122        if jobID != jobIDReceived:
2123            raise Exception( "Inconsistency detected" )
2124        self.ns.putJob( 'TEST', jobID, jobInfo[ 1 ], 0, "",
2125                        'mynode', 'mysession' )
2126        jobIDReceived, \
2127        state, \
2128        passport = self.ns.getJobsForReading2( 'TEST', -1, '',
2129                                               'mynode', 'mysession' )
2130        if jobID != jobIDReceived:
2131            raise Exception( "Inconsistency detected" )
2132        self.ns.rollbackRead2( 'TEST', jobID, passport, 'mynode', 'mysession' )
2133
2134        # Check the status
2135        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
2136        status2 = self.ns.getJobStatus( 'TEST', jobID )
2137
2138        info = self.ns.getJobInfo( 'TEST', jobID )
2139        status3 = info[ "status" ]
2140
2141        if status1 != "Done" or \
2142           status2 != "Done" or \
2143           status3 != "Done":
2144            raise Exception( "Unexpected job status" )
2145        if int( info[ "read_counter" ] ) != 0:
2146            raise Exception( "Unexpected reading count" )
2147        return True
2148
2149class Scenario156( TestBase ):
2150    " Scenario 156 "
2151
2152    def __init__( self, netschedule ):
2153        TestBase.__init__( self, netschedule )
2154        return
2155
2156    @staticmethod
2157    def getScenario():
2158        " Provides the scenario "
2159        return "SUBMIT, GET, PUT, READ, RDRB (wrong passport), check status and reading count"
2160
2161    def execute( self ):
2162        " Should return True if the execution completed successfully "
2163        self.fromScratch()
2164
2165        jobID = self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', 'mysession' )
2166        jobInfo = self.ns.getJob( 'TEST', -1, '', "", 'mynode', 'mysession' )
2167        jobIDReceived = jobInfo[ 0 ]
2168        if jobID != jobIDReceived:
2169            raise Exception( "Inconsistency detected" )
2170        self.ns.putJob( 'TEST', jobID, jobInfo[ 1 ], 0, "",
2171                        'mynode', 'mysession' )
2172        jobIDReceived, \
2173        state, \
2174        passport = self.ns.getJobsForReading2( 'TEST', -1, '',
2175                                               'mynode', 'mysession' )
2176        if jobID != jobIDReceived:
2177            raise Exception( "Inconsistency detected" )
2178        try:
2179            parts = passport.split( '_' )
2180            if len( parts ) != 2:
2181                raise Exception( "Unexpected passport format" )
2182            badPassport = str( int( parts[ 0 ] ) + 1 ) + '_' + parts[ 1 ] + '7'
2183            self.ns.rollbackRead2( 'TEST', jobID, badPassport,
2184                                   'mynode', 'mysession' )
2185            raise Exception( "Wrong RDRB but no exception" )
2186        except Exception as excpt:
2187            if "Authorization token does not match" not in str( excpt ):
2188                raise
2189
2190        # Check the status
2191        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
2192        status2 = self.ns.getJobStatus( 'TEST', jobID )
2193
2194        info = self.ns.getJobInfo( 'TEST', jobID )
2195        status3 = info[ "status" ]
2196
2197        if status1 != "Reading" or \
2198           status2 != "Reading" or \
2199           status3 != "Reading":
2200            raise Exception( "Unexpected job status" )
2201        if int( info[ "read_counter" ] ) != 1:
2202            raise Exception( "Unexpected reading count" )
2203        return True
2204
2205class Scenario157( TestBase ):
2206    " Scenario 157 "
2207
2208    def __init__( self, netschedule ):
2209        TestBase.__init__( self, netschedule )
2210        return
2211
2212    @staticmethod
2213    def getScenario():
2214        " Provides the scenario "
2215        return "SUBMIT, GET, PUT, READ, FRED, check status and reading count"
2216
2217    def execute( self ):
2218        " Should return True if the execution completed successfully "
2219        self.fromScratch()
2220
2221        jobID = self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', 'mysession' )
2222        jobInfo = self.ns.getJob( 'TEST', -1, '', "",
2223                                        'mynode', 'mysession'  )
2224        jobIDReceived = jobInfo[ 0 ]
2225        if jobID != jobIDReceived:
2226            raise Exception( "Inconsistency detected" )
2227        self.ns.putJob( 'TEST', jobID, jobInfo[ 1 ], 0, "",
2228                        'mynode', 'mysession' )
2229        jobIDReceived, \
2230        state, \
2231        passport = self.ns.getJobsForReading2( 'TEST', -1, '',
2232                                               'mynode', 'mysession' )
2233        if jobID != jobIDReceived:
2234            raise Exception( "Inconsistency detected" )
2235        self.ns.failRead2( 'TEST', jobID, passport, "",
2236                          'mynode', 'mysession' )
2237
2238        # Check the status
2239        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
2240        status2 = self.ns.getJobStatus( 'TEST', jobID )
2241
2242        info = self.ns.getJobInfo( 'TEST', jobID )
2243        status3 = info[ "status" ]
2244
2245        if status1 != "Done" or \
2246           status2 != "Done" or \
2247           status3 != "Done":
2248            raise Exception( "Unexpected job status" )
2249        if int( info[ "read_counter" ] ) != 1:
2250            raise Exception( "Unexpected reading count" )
2251        return True
2252
2253class Scenario158( TestBase ):
2254    " Scenario 158 "
2255
2256    def __init__( self, netschedule ):
2257        TestBase.__init__( self, netschedule )
2258        return
2259
2260    @staticmethod
2261    def getScenario():
2262        " Provides the scenario "
2263        return "SUBMIT, GET, PUT, READ, FRED (wrong passport), check status and reading count"
2264
2265    def execute( self ):
2266        " Should return True if the execution completed successfully "
2267        self.fromScratch()
2268
2269        jobID = self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', 'mysession' )
2270        jobInfo = self.ns.getJob( 'TEST', -1, '', "", 'mynode', 'mysession'  )
2271        jobIDReceived = jobInfo[ 0 ]
2272        if jobID != jobIDReceived:
2273            raise Exception( "Inconsistency detected" )
2274        self.ns.putJob( 'TEST', jobID, jobInfo[ 1 ], 0, "",
2275                        'mynode', 'mysession' )
2276        jobIDReceived, \
2277        state, \
2278        passport = self.ns.getJobsForReading2( 'TEST', -1, '',
2279                                               'mynode', 'mysession' )
2280        if jobID != jobIDReceived:
2281            raise Exception( "Inconsistency detected" )
2282
2283        try:
2284            self.ns.failRead2( 'TEST', jobID, "7" + passport, "",
2285                               'mynode', 'mysession' )
2286            raise Exception( "Wrong FRED but no exception" )
2287        except Exception as excpt:
2288            if "authorization" not in str( excpt ).lower():
2289                raise
2290
2291        # Check the status
2292        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
2293        status2 = self.ns.getJobStatus( 'TEST', jobID )
2294
2295        info = self.ns.getJobInfo( 'TEST', jobID )
2296        status3 = info[ "status" ]
2297
2298        if status1 != "Reading" or \
2299           status2 != "Reading" or \
2300           status3 != "Reading":
2301            raise Exception( "Unexpected job status" )
2302        if int( info[ "read_counter" ] ) != 1:
2303            raise Exception( "Unexpected reading count" )
2304        return True
2305
2306class Scenario159( TestBase ):
2307    " Scenario 159 "
2308
2309    def __init__( self, netschedule ):
2310        TestBase.__init__( self, netschedule )
2311        return
2312
2313    @staticmethod
2314    def getScenario():
2315        " Provides the scenario "
2316        return "SUBMIT, GET, PUT, READ, CANCEL, CFRM, check status and reading count"
2317
2318    def execute( self ):
2319        " Should return True if the execution completed successfully "
2320        self.fromScratch()
2321
2322        jobID = self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', 'mysession' )
2323        jobInfo = self.ns.getJob( 'TEST', -1, '', "",
2324                                        'mynode', 'mysession'  )
2325        jobIDReceived = jobInfo[ 0 ]
2326        if jobID != jobIDReceived:
2327            raise Exception( "Inconsistency detected" )
2328        self.ns.putJob( 'TEST', jobID, jobInfo[ 1 ], 0, "",
2329                        'mynode', 'mysession' )
2330
2331        readJobID, \
2332        state, \
2333        passport = self.ns.getJobsForReading2( 'TEST', -1, '',
2334                                               'mynode', 'mysession' )
2335
2336        if jobID != readJobID:
2337            raise Exception( "Inconsistency detected" )
2338
2339        self.ns.cancelJob( 'TEST', jobID, 'mynode', 'mysession')
2340
2341        try:
2342            self.ns.confirmRead2( 'TEST', jobID, passport,
2343                                "mynode", "mysession" )
2344            raise Exception( "Expected error, got nothing" )
2345        except Exception as exc:
2346            if not "Canceled" in str( exc ):
2347                raise
2348
2349        # Check the status
2350        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
2351        status2 = self.ns.getJobStatus( 'TEST', jobID )
2352
2353        info = self.ns.getJobInfo( 'TEST', jobID )
2354        status3 = info[ "status" ]
2355
2356        if status1 != "Canceled" or \
2357           status2 != "Canceled" or \
2358           status3 != "Canceled":
2359            raise Exception( "Unexpected job status"  )
2360        if int( info[ "read_counter" ] ) != 1:
2361            raise Exception( "Unexpected reading count" )
2362        return True
2363
2364class Scenario160( TestBase ):
2365    " Scenario 160 "
2366
2367    def __init__( self, netschedule ):
2368        TestBase.__init__( self, netschedule )
2369        self.jobID = None
2370        return
2371
2372    @staticmethod
2373    def getScenario():
2374        " Provides the scenario "
2375        return " SUBMIT as identified, check submit event "
2376
2377    def execute( self ):
2378        " Should return True if the execution completed successfully "
2379        self.fromScratch()
2380
2381        jobID = self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', 'mysession' )
2382        info = self.ns.getJobInfo( 'TEST', jobID )
2383
2384        return info[ 'event' ] == 'Submit' and \
2385               info[ "node" ] == "mynode" and \
2386               info[ "session" ] == "mysession"
2387
2388class Scenario161( TestBase ):
2389    " Scenario 161 "
2390
2391    def __init__( self, netschedule ):
2392        TestBase.__init__( self, netschedule )
2393        self.jobID = None
2394        return
2395
2396    @staticmethod
2397    def getScenario():
2398        " Provides the scenario "
2399        return " SUBMIT as anonymous, check submit event "
2400
2401    def execute( self ):
2402        " Should return True if the execution completed successfully "
2403        self.fromScratch()
2404
2405        jobID = self.ns.submitJob( 'TEST', 'bla' )
2406        info = self.ns.getJobInfo( 'TEST', jobID )
2407
2408        if "event" in info:
2409            # grid 1.5
2410            return info[ 'event' ] == 'Submit' and \
2411                   info[ "node" ] == "" and \
2412                   info[ "session" ] == ""
2413        # grid 1.4
2414        return "event=Submit" in info[ "event1" ] and \
2415               "node=''" in info[ "event1" ] and \
2416               "session=''" in info[ "event1" ]
2417
2418class Scenario162( TestBase ):
2419    " Scenario 162 "
2420
2421    def __init__( self, netschedule ):
2422        TestBase.__init__( self, netschedule )
2423        self.jobID = None
2424        return
2425
2426    @staticmethod
2427    def getScenario():
2428        " Provides the scenario "
2429        return "SUBMIT, GET, wait till timeout as c1; GET, RETURN as c2; " \
2430               "GET, FPUT as c3; GET, PUT, READ, timeout as c4; " \
2431               "READ, RETURN as c5; READ, FRED as c6; READ, CFRM, CANCEL as c7; " \
2432               "DUMP and check the history"
2433
2434    def checkEvent( self, client, event, status, node, session ):
2435        " Checks the last event fields "
2436        info = self.ns.getJobInfo( 'TEST', self.jobID )
2437        if info[ 'client' ] != client:
2438            raise Exception( "Unexpected client. Expected: " + client +
2439                             " Received: " + str( info ) )
2440        if info[ 'event' ] != event:
2441            raise Exception( "Unexpected event. Expected: " + event +
2442                             " Received: " + str( info ) )
2443        if info[ 'status' ] != status:
2444            raise Exception( "Unexpected status. Expected: " + status +
2445                             " Received: " + str( info ) )
2446        if info[ 'node' ] != node:
2447            raise Exception( "Unexpected node. Expected: " + node +
2448                             " Received: " + str( info ) )
2449        if info[ 'session' ] != session:
2450            raise Exception( "Unexpected node. Expected: " + session +
2451                             " Received: " + str( info ) )
2452        return
2453
2454    def execute( self ):
2455        " Should return True if the execution completed successfully "
2456        self.fromScratch()
2457
2458        self.jobID = self.ns.submitJob( 'TEST', 'bla', '', '', 'c1', 'session1' )
2459        self.checkEvent( 'localhost', 'Submit', 'Pending', 'c1', 'session1' )
2460
2461        self.ns.getJob( 'TEST', -1, '', "",
2462                                        'c2', 'session2' )
2463        self.checkEvent( 'localhost', 'Request', 'Running', 'c2', 'session2' )
2464        time.sleep( 15 )
2465        self.checkEvent( 'ns', 'Timeout', 'Pending', '', '' )
2466
2467        jobInfo = self.ns.getJob( 'TEST', -1, '', "",
2468                                        'c3', 'session3' )
2469        self.checkEvent( 'localhost', 'Request', 'Running', 'c3', 'session3' )
2470        self.ns.returnJob( 'TEST', self.jobID, jobInfo[ 1 ], 'c31', 'session31' )
2471        self.checkEvent( 'localhost', 'Return', 'Pending', 'c31', 'session31' )
2472
2473        jobInfo = self.ns.getJob( 'TEST', -1, '', "",
2474                                        'c4', 'session4' )
2475        self.checkEvent( 'localhost', 'Request', 'Running', 'c4', 'session4' )
2476        self.ns.failJob( 'TEST', self.jobID, jobInfo[ 1 ], 4, '', '', 'c5', 'session5' )
2477        self.checkEvent( 'localhost', 'Fail', 'Pending', 'c5', 'session5' )
2478
2479        jobInfo = self.ns.getJob( 'TEST', -1, '', "",
2480                                        'c6', 'session6' )
2481        self.checkEvent( 'localhost', 'Request', 'Running', 'c6', 'session6' )
2482        self.ns.putJob( 'TEST', jobInfo[ 0 ], jobInfo[ 1 ], 0, "", 'c7', 'session7' )
2483        self.checkEvent( 'localhost', 'Done', 'Done', 'c7', 'session7' )
2484
2485        readJobID, \
2486        state, \
2487        passport = self.ns.getJobsForReading2( 'TEST', -1, '',
2488                                               'c8', 'session8' )
2489        self.checkEvent( 'localhost', 'Read', 'Reading', 'c8', 'session8' )
2490        time.sleep( 15 )
2491        self.checkEvent( 'ns', 'ReadTimeout', 'Done', '', '' )
2492
2493        readJobID, \
2494        state, \
2495        passport = self.ns.getJobsForReading2( 'TEST', -1, '',
2496                                               'c9', 'session9' )
2497        self.checkEvent( 'localhost', 'Read', 'Reading', 'c9', 'session9' )
2498        self.ns.rollbackRead2( 'TEST', self.jobID, passport, 'c10', 'session10' )
2499        self.checkEvent( 'localhost', 'ReadRollback', 'Done', 'c10', 'session10' )
2500
2501        readJobID, \
2502        state, \
2503        passport = self.ns.getJobsForReading2( 'TEST', -1, '',
2504                                               'c11', 'session11' )
2505        self.checkEvent( 'localhost', 'Read', 'Reading', 'c11', 'session11' )
2506        self.ns.failRead2( 'TEST', self.jobID, passport, "", 'c12', 'session12' )
2507        self.checkEvent( 'localhost', 'ReadFail', 'Done', 'c12', 'session12' )
2508
2509        readJobID, \
2510        state, \
2511        passport = self.ns.getJobsForReading2( 'TEST', -1, '',
2512                                               'c13', 'session13' )
2513        self.checkEvent( 'localhost', 'Read', 'Reading', 'c13', 'session13' )
2514        self.ns.confirmRead2( 'TEST', self.jobID, passport, "c14", "session14" )
2515        self.checkEvent( 'localhost', 'ReadDone', 'Confirmed', 'c14', 'session14' )
2516
2517        self.ns.cancelJob( 'TEST', self.jobID, 'c15', 'session15' )
2518        self.checkEvent( 'localhost', 'Cancel', 'Canceled', 'c15', 'session15' )
2519        return True
2520
2521class Scenario163( TestBase ):
2522    " Scenario 163 "
2523
2524    def __init__( self, netschedule ):
2525        TestBase.__init__( self, netschedule )
2526        self.jobID = None
2527        return
2528
2529    @staticmethod
2530    def getScenario():
2531        " Provides the scenario "
2532        return " SUBMIT as anonymous, GET, FAIL, check fail event "
2533
2534    def execute( self ):
2535        " Should return True if the execution completed successfully "
2536        self.fromScratch( 3 )
2537
2538        jobID = self.ns.submitJob( 'TEST', 'bla' )
2539        jobInfo = self.ns.getJob( 'TEST' )
2540        jobIDReceived = jobInfo[ 0 ]
2541        if jobID != jobIDReceived:
2542            raise Exception( "Inconsistency detected" )
2543
2544        self.ns.failJob( 'TEST', jobID, jobInfo[ 1 ], 4 )
2545        info = self.ns.getJobInfo( 'TEST', jobID )
2546
2547        if "event" in info:
2548            # grid 1.5
2549            return info[ 'event' ] == 'Fail' and \
2550                   info[ "status" ] == "Failed" and \
2551                   info[ "ret_code" ] == "4"
2552        # grid 1.4
2553        return "event=Fail" in info[ "event3" ] and \
2554               "status=Failed" in info[ "event3" ] and \
2555               "ret_code=4" in info[ "event3" ]
2556
2557
2558class Scenario164( TestBase ):
2559    " Scenario 164 "
2560
2561    def __init__( self, netschedule ):
2562        TestBase.__init__( self, netschedule )
2563        self.jobID = None
2564        return
2565
2566    @staticmethod
2567    def getScenario():
2568        " Provides the scenario "
2569        return " SUBMIT as anonymous, GET, wait till fail, check fail event "
2570
2571    def execute( self ):
2572        " Should return True if the execution completed successfully "
2573        self.fromScratch( 3 )
2574
2575        jobID = self.ns.submitJob( 'TEST', 'bla' )
2576        jobIDReceived = self.ns.getJob( 'TEST' )[ 0 ]
2577        if jobID != jobIDReceived:
2578            raise Exception( "Inconsistency detected" )
2579
2580        time.sleep( 15 )
2581
2582        info = self.ns.getJobInfo( 'TEST', jobID )
2583
2584        if "event" in info:
2585            # grid 1.5
2586            return info[ 'event' ] == 'Timeout' and \
2587                   info[ "status" ] == "Failed" and \
2588                   info[ "run_counter" ] == "1"
2589        # grid 1.4
2590        return "event=Timeout" in info[ "event3" ] and \
2591               "status=Failed" in info[ "event3" ] and \
2592               info[ "run_counter" ] == "1"
2593
2594class Scenario165( TestBase ):
2595    " Scenario 165 "
2596
2597    def __init__( self, netschedule ):
2598        TestBase.__init__( self, netschedule )
2599        self.jobID = None
2600        return
2601
2602    @staticmethod
2603    def getScenario():
2604        " Provides the scenario "
2605        return "SUBMIT as anonymous, GET, CLRN, check the job status"
2606
2607    def execute( self ):
2608        " Should return True if the execution completed successfully "
2609        self.fromScratch( 3 )
2610
2611        jobID = self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', 'mysession' )
2612        jobIDReceived = self.ns.getJob( 'TEST', -1, '', "",
2613                                        'mynode', 'mysession' )[ 0 ]
2614        if jobID != jobIDReceived:
2615            raise Exception( "Inconsistency detected" )
2616
2617        ns_client = self.getNetScheduleService( 'TEST', 'scenario123' )
2618        ns_client.set_client_identification( 'mynode', 'mysession' )
2619        execAny( ns_client, 'CLRN' )
2620
2621        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
2622        status2 = self.ns.getJobStatus( 'TEST', jobID )
2623
2624        info = self.ns.getJobInfo( 'TEST', jobID )
2625        status3 = info[ "status" ]
2626
2627        if status1 != "Failed" or \
2628           status2 != "Failed" or \
2629           status3 != "Failed":
2630            return False
2631        return True
2632
2633class Scenario166( TestBase ):
2634    " Scenario 166 "
2635
2636    def __init__( self, netschedule ):
2637        TestBase.__init__( self, netschedule )
2638        return
2639
2640    @staticmethod
2641    def getScenario():
2642        " Provides the scenario "
2643        return "SUBMIT as anonymous, GET, PUT, READ, FRED, check history"
2644
2645    def execute( self ):
2646        " Should return True if the execution completed successfully "
2647        self.fromScratch( 3 )
2648
2649        jobID = self.ns.submitJob( 'TEST', 'bla' )
2650        jobInfo = self.ns.getJob( 'TEST' )
2651        jobIDReceived = jobInfo[ 0 ]
2652        if jobID != jobIDReceived:
2653            raise Exception( "Inconsistency detected" )
2654
2655        self.ns.putJob( 'TEST', jobID, jobInfo[ 1 ], 0, "" )
2656
2657        readJobID, \
2658        state, \
2659        passport = self.ns.getJobsForReading2( 'TEST', -1, '',
2660                                               'node', 'session' )
2661        self.ns.failRead2( 'TEST', readJobID, passport, "", "node", "session" )
2662        info = self.ns.getJobInfo( 'TEST', jobID )
2663
2664        if info[ 'event' ] != 'ReadFail':
2665            raise Exception( "Unexpected event: " + info[ 'event' ] )
2666
2667        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
2668        status2 = self.ns.getJobStatus( 'TEST', jobID )
2669        status3 = info[ "status" ]
2670
2671        if status1 != "ReadFailed" or \
2672           status2 != "ReadFailed" or \
2673           status3 != "ReadFailed":
2674            return False
2675        return True
2676
2677class Scenario167( TestBase ):
2678    " Scenario 167 "
2679
2680    def __init__( self, netschedule ):
2681        TestBase.__init__( self, netschedule )
2682        return
2683
2684    @staticmethod
2685    def getScenario():
2686        " Provides the scenario "
2687        return "SUBMIT as anonymous, GET, PUT, READ, timeout, check history"
2688
2689    def execute( self ):
2690        " Should return True if the execution completed successfully "
2691        self.fromScratch( 3 )
2692
2693        jobID = self.ns.submitJob( 'TEST', 'bla' )
2694        jobInfo = self.ns.getJob( 'TEST' )
2695        jobIDReceived = jobInfo[ 0 ]
2696        if jobID != jobIDReceived:
2697            raise Exception( "Inconsistency detected" )
2698
2699        self.ns.putJob( 'TEST', jobID, jobInfo[ 1 ], 0, "" )
2700        readJobID, \
2701        state, \
2702        passport = self.ns.getJobsForReading2( 'TEST', -1, '',
2703                                               'node', 'session' )
2704        time.sleep( 20 )
2705
2706        info = self.ns.getJobInfo( 'TEST', jobID )
2707        if info[ 'event' ] != 'ReadTimeout':
2708            raise Exception( "Unexpected event: " + info[ 'event' ] )
2709
2710        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
2711        status2 = self.ns.getJobStatus( 'TEST', jobID )
2712        status3 = info[ "status" ]
2713
2714        if status1 != "ReadFailed" or \
2715           status2 != "ReadFailed" or \
2716           status3 != "ReadFailed":
2717            return False
2718        return True
2719
2720class Scenario168( TestBase ):
2721    " Scenario 168 "
2722
2723    def __init__( self, netschedule ):
2724        TestBase.__init__( self, netschedule )
2725        return
2726
2727    @staticmethod
2728    def getScenario():
2729        " Provides the scenario "
2730        return "SUBMIT as anonymous, GET, PUT, READ as identified, CLRN, check history"
2731
2732    def execute( self ):
2733        " Should return True if the execution completed successfully "
2734        self.fromScratch( 3 )
2735
2736        jobID = self.ns.submitJob( 'TEST', 'bla' )
2737        jobInfo = self.ns.getJob( 'TEST' )
2738        jobIDReceived = jobInfo[ 0 ]
2739        if jobID != jobIDReceived:
2740            raise Exception( "Inconsistency detected" )
2741
2742        self.ns.putJob( 'TEST', jobID, jobInfo[ 1 ], 0, "" )
2743        readJobID, \
2744        state, \
2745        passport = self.ns.getJobsForReading2( 'TEST', -1, '',
2746                                               'node', 'session' )
2747
2748        ns_client = self.getNetScheduleService( 'TEST', 'scenario168' )
2749        ns_client.set_client_identification( 'node', 'session' )
2750        execAny( ns_client, 'CLRN' )
2751
2752        info = self.ns.getJobInfo( 'TEST', jobID )
2753        if info[ 'event' ] != 'Clear':
2754            raise Exception( "Unexpected event: " + info[ 'event' ] )
2755
2756        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
2757        status2 = self.ns.getJobStatus( 'TEST', jobID )
2758        status3 = info[ "status" ]
2759
2760        if status1 != "ReadFailed" or \
2761           status2 != "ReadFailed" or \
2762           status3 != "ReadFailed":
2763            return False
2764        return True
2765
2766class Scenario169( TestBase ):
2767    " Scenario 169 "
2768
2769    def __init__( self, netschedule ):
2770        TestBase.__init__( self, netschedule )
2771        self.jobID = None
2772        return
2773
2774    @staticmethod
2775    def getScenario():
2776        " Provides the scenario "
2777        return " SUBMIT, GET, RETURN, GET as the same identified client"
2778
2779    def execute( self ):
2780        " Should return True if the execution completed successfully "
2781        self.fromScratch()
2782
2783        jobID = self.ns.submitJob( 'TEST', 'bla' )
2784        jobInfo = self.ns.getJob( 'TEST', -1, '', "",
2785                                        'scenario169', 'default' )
2786        jobIDReceived = jobInfo[ 0 ]
2787        if jobID != jobIDReceived:
2788            raise Exception( "Inconsistency detected" )
2789
2790        self.ns.returnJob( 'TEST', jobID, jobInfo[ 1 ], 'scenario169', 'default' )
2791        if self.ns.getJob( 'TEST', -1, '', "", 'scenario169', 'default' ):
2792            raise Exception( "No jobs expected, however one was received" )
2793
2794        ns_client = self.getNetScheduleService( 'TEST', 'scenario169' )
2795        client = getClientInfo( ns_client, 'scenario169' )
2796        if len( client[ 'blacklisted_jobs' ] ) != 1 or \
2797           client[ 'blacklisted_jobs' ][ 0 ].split()[0] != jobID:
2798            raise Exception( "Wrong job in the client blacklist" )
2799        return True
2800
2801class Scenario170( TestBase ):
2802    " Scenario 170 "
2803
2804    def __init__( self, netschedule ):
2805        TestBase.__init__( self, netschedule )
2806        self.jobID = None
2807        return
2808
2809    @staticmethod
2810    def getScenario():
2811        " Provides the scenario "
2812        return " SUBMIT, GET, FAIL, GET as the same identified client"
2813
2814    def execute( self ):
2815        " Should return True if the execution completed successfully "
2816        self.fromScratch()
2817
2818        jobID = self.ns.submitJob( 'TEST', 'bla' )
2819        jobInfo = self.ns.getJob( 'TEST', -1, '', "",
2820                                        'scenario170', 'default' )
2821        jobIDReceived = jobInfo[ 0 ]
2822        if jobID != jobIDReceived:
2823            raise Exception( "Inconsistency detected" )
2824
2825        self.ns.failJob( 'TEST', jobID, jobInfo[ 1 ], 4, '', '',
2826                'scenario170', 'default' )
2827        if self.ns.getJob( 'TEST', -1, '', "", 'scenario170', 'default' ):
2828            raise Exception( "No jobs expected, however one was received" )
2829
2830        ns_client = self.getNetScheduleService( 'TEST', 'scenario170' )
2831        client = getClientInfo( ns_client, 'scenario170' )
2832        if len( client[ 'blacklisted_jobs' ] ) != 1 or \
2833           client[ 'blacklisted_jobs' ][ 0 ].split()[0] != jobID:
2834            raise Exception( "Wrong job in the client blacklist" )
2835        return True
2836
2837class Scenario171( TestBase ):
2838    " Scenario 171 "
2839
2840    def __init__( self, netschedule ):
2841        TestBase.__init__( self, netschedule )
2842        self.jobID = None
2843        return
2844
2845    @staticmethod
2846    def getScenario():
2847        " Provides the scenario "
2848        return " SUBMIT, GET, timeout till fail, " \
2849               "GET as the same identified client"
2850
2851    def execute( self ):
2852        " Should return True if the execution completed successfully "
2853        self.fromScratch()
2854
2855        jobID = self.ns.submitJob( 'TEST', 'bla' )
2856        jobIDReceived = self.ns.getJob( 'TEST', -1, '', "",
2857                                        'scenario171', 'default' )[ 0 ]
2858        if jobID != jobIDReceived:
2859            raise Exception( "Inconsistency detected" )
2860
2861        time.sleep( 15 )
2862        if self.ns.getJob( 'TEST', -1, '', "", 'scenario171', 'default' ):
2863            raise Exception( "No jobs expected, however one was received" )
2864
2865        ns_client = self.getNetScheduleService( 'TEST', 'scenario171' )
2866        client = getClientInfo( ns_client, 'scenario171' )
2867        if len( client[ 'blacklisted_jobs' ] ) != 1 or \
2868           client[ 'blacklisted_jobs' ][ 0 ].split()[0] != jobID:
2869            raise Exception( "Wrong job in the client blacklist" )
2870        return True
2871
2872class Scenario172( TestBase ):
2873    " Scenario 172 "
2874
2875    def __init__( self, netschedule ):
2876        TestBase.__init__( self, netschedule )
2877        return
2878
2879    @staticmethod
2880    def getScenario():
2881        " Provides the scenario "
2882        return "SUBMIT, GET, PUT, READ, RDRB as identified. " \
2883               "READ -> no jobs, STAT CLIENTS"
2884
2885    def execute( self ):
2886        " Should return True if the execution completed successfully "
2887        self.fromScratch()
2888
2889        jobID = self.ns.submitJob( 'TEST', 'bla' )
2890        jobInfo = self.ns.getJob( 'TEST', -1, '', "",
2891                                        'node', 'session' )
2892        jobIDReceived = jobInfo[ 0 ]
2893        if jobID != jobIDReceived:
2894            raise Exception( "Inconsistency detected" )
2895
2896        self.ns.putJob( 'TEST', jobID, jobInfo[ 1 ], 0, "" )
2897        readJobID, \
2898        state, \
2899        passport = self.ns.getJobsForReading2( 'TEST', -1, '',
2900                                               'node', 'session' )
2901        if readJobID != jobID:
2902            raise Exception( "Inconsistency" )
2903        self.ns.rollbackRead2( 'TEST', readJobID, passport,
2904                               "node", "session" )
2905
2906        readJobID, \
2907        state, \
2908        passport = self.ns.getJobsForReading2( 'TEST', -1, '',
2909                                               'node', 'session' )
2910        if readJobID != "":
2911            raise Exception( "Expected no jobs but received one" )
2912
2913        ns_client = self.getNetScheduleService( 'TEST', 'scenario172' )
2914        client = getClientInfo( ns_client, 'node' )
2915        if 'blacklisted_jobs' in client:
2916            if len( client[ 'blacklisted_jobs' ] ) != 1 or \
2917               client[ 'blacklisted_jobs' ][ 0 ].split()[0] != jobID:
2918                raise Exception( "Wrong job in the client blacklist" )
2919        if 'read_blacklisted_jobs' in client:
2920            if len( client[ 'read_blacklisted_jobs' ] ) != 1 or \
2921               client[ 'read_blacklisted_jobs' ][ 0 ].split()[0] != jobID:
2922                raise Exception( "Wrong job in the client blacklist" )
2923        return True
2924
2925class Scenario173( TestBase ):
2926    " Scenario 173 "
2927
2928    def __init__( self, netschedule ):
2929        TestBase.__init__( self, netschedule )
2930        return
2931
2932    @staticmethod
2933    def getScenario():
2934        " Provides the scenario "
2935        return "SUBMIT, GET, PUT, READ, FRED as identified. " \
2936               "READ -> no jobs, STAT CLIENTS"
2937
2938    def execute( self ):
2939        " Should return True if the execution completed successfully "
2940        self.fromScratch()
2941
2942        jobID = self.ns.submitJob( 'TEST', 'bla' )
2943        jobInfo = self.ns.getJob( 'TEST', -1, '', "",
2944                                        'node', 'session' )
2945        jobIDReceived = jobInfo[ 0 ]
2946        if jobID != jobIDReceived:
2947            raise Exception( "Inconsistency detected" )
2948
2949        self.ns.putJob( 'TEST', jobID, jobInfo[ 1 ], 0, "" )
2950        readJobID, \
2951        state, \
2952        passport = self.ns.getJobsForReading2( 'TEST', -1, '',
2953                                               'node', 'session' )
2954        if readJobID != jobID:
2955            raise Exception( "Inconsistency" )
2956        self.ns.failRead2( 'TEST', readJobID, passport, "",
2957                           "node", "session" )
2958
2959        readJobID, \
2960        state, \
2961        passport = self.ns.getJobsForReading2( 'TEST', -1, '',
2962                                               'node', 'session' )
2963        if readJobID != "":
2964            raise Exception( "Expected no jobs but received one" )
2965
2966        ns_client = self.getNetScheduleService( 'TEST', 'scenario173' )
2967        client = getClientInfo( ns_client, 'node' )
2968        if 'blacklisted_jobs' in client:
2969            if len( client[ 'blacklisted_jobs' ] ) != 1 or \
2970               client[ 'blacklisted_jobs' ][ 0 ].split()[0] != jobID:
2971                raise Exception( "Wrong job in the client blacklist" )
2972        if 'read_blacklisted_jobs' in client:
2973            if len( client[ 'read_blacklisted_jobs' ] ) != 1 or \
2974               client[ 'read_blacklisted_jobs' ][ 0 ].split()[0] != jobID:
2975                raise Exception( "Wrong job in the client blacklist" )
2976        return True
2977
2978class Scenario174( TestBase ):
2979    " Scenario 174 "
2980
2981    def __init__( self, netschedule ):
2982        TestBase.__init__( self, netschedule )
2983        return
2984
2985    @staticmethod
2986    def getScenario():
2987        " Provides the scenario "
2988        return "SUBMIT, GET, PUT, READ, timeout. " \
2989               "READ -> no jobs, STAT CLIENTS"
2990
2991    def execute( self ):
2992        " Should return True if the execution completed successfully "
2993        self.fromScratch()
2994
2995        jobID = self.ns.submitJob( 'TEST', 'bla' )
2996        jobInfo = self.ns.getJob( 'TEST', -1, '', "",
2997                                        'node', 'session' )
2998        jobIDReceived = jobInfo[ 0 ]
2999        if jobID != jobIDReceived:
3000            raise Exception( "Inconsistency detected" )
3001
3002        self.ns.putJob( 'TEST', jobID, jobInfo[ 1 ], 0, "" )
3003        readJobID, \
3004        state, \
3005        passport = self.ns.getJobsForReading2( 'TEST', -1, '',
3006                                               'node', 'session' )
3007        if readJobID != jobID:
3008            raise Exception( "Inconsistency" )
3009        time.sleep( 15 )
3010
3011        readJobID, \
3012        state, \
3013        passport = self.ns.getJobsForReading2( 'TEST', -1, '',
3014                                               'node', 'session' )
3015        if readJobID != "":
3016            raise Exception( "Expected no jobs but received one" )
3017
3018        ns_client = self.getNetScheduleService( 'TEST', 'scenario173' )
3019        client = getClientInfo( ns_client, 'node' )
3020        if 'blacklisted_jobs' in client:
3021            if len( client[ 'blacklisted_jobs' ] ) != 1 or \
3022               client[ 'blacklisted_jobs' ][ 0 ].split()[0] != jobID:
3023                raise Exception( "Wrong job in the client blacklist" )
3024        if 'read_blacklisted_jobs' in client:
3025            if len( client[ 'read_blacklisted_jobs' ] ) != 1 or \
3026               client[ 'read_blacklisted_jobs' ][ 0 ].split()[0] != jobID:
3027                raise Exception( "Wrong job in the client blacklist" )
3028        return True
3029
3030class Scenario175( TestBase ):
3031    " Scenario 175 "
3032
3033    def __init__( self, netschedule ):
3034        TestBase.__init__( self, netschedule )
3035        return
3036
3037    @staticmethod
3038    def getScenario():
3039        " Provides the scenario "
3040        return "SUBMIT, GET, PUT, READ, PUT -> error message"
3041
3042    def execute( self ):
3043        " Should return True if the execution completed successfully "
3044        self.fromScratch()
3045
3046        jobID = self.ns.submitJob( 'TEST', 'bla' )
3047        jobInfo = self.ns.getJob( 'TEST', -1, '', "",
3048                                        'scenario175', 'default' )
3049        jobIDReceived = jobInfo[ 0 ]
3050        if jobID != jobIDReceived:
3051            raise Exception( "Inconsistency detected" )
3052
3053        self.ns.putJob( 'TEST', jobID, jobInfo[ 1 ], 0, "" )
3054        readJobID, \
3055        state, \
3056        passport = self.ns.getJobsForReading2( 'TEST', -1, '',
3057                                               'node', 'session' )
3058        if readJobID != jobID:
3059            raise Exception( "Inconsistency" )
3060
3061        try:
3062            self.ns.putJob( 'TEST', jobID, jobInfo[ 1 ], 0, "" )
3063        except Exception as excpt:
3064            if 'Cannot accept job results' in str( excpt ):
3065                return True
3066            raise
3067        return False
3068
3069class Scenario176( TestBase ):
3070    " Scenario 176 "
3071
3072    def __init__( self, netschedule ):
3073        TestBase.__init__( self, netschedule )
3074        return
3075
3076    @staticmethod
3077    def getScenario():
3078        " Provides the scenario "
3079        return " MGET for non-existed "
3080
3081    def execute( self ):
3082        " Should return True if the execution completed successfully "
3083        self.fromScratch()
3084
3085        try:
3086            self.ns.getJobProgressMessage( 'TEST', NON_EXISTED_JOB,
3087                                           'mynode', 'mysession' )
3088        except Exception as exc:
3089            if "Job not found" in str( exc ):
3090                return True
3091            raise
3092
3093        return False
3094
3095
3096class Scenario177( TestBase ):
3097    " Scenario 177 "
3098
3099    def __init__( self, netschedule ):
3100        TestBase.__init__( self, netschedule )
3101        return
3102
3103    @staticmethod
3104    def getScenario():
3105        " Provides the scenario "
3106        return " MPUT for non-existed "
3107
3108    def execute( self ):
3109        " Should return True if the execution completed successfully "
3110        self.fromScratch()
3111
3112        try:
3113            self.ns.setJobProgressMessage( 'TEST', NON_EXISTED_JOB, 'msg',
3114                                           'mynode', 'mysession' )
3115        except Exception as exc:
3116            if "Job not found" in str( exc ):
3117                return True
3118            raise
3119
3120        return False
3121
3122class Scenario178( TestBase ):
3123    " Scenario 178 "
3124
3125    def __init__( self, netschedule ):
3126        TestBase.__init__( self, netschedule )
3127        return
3128
3129    @staticmethod
3130    def getScenario():
3131        " Provides the scenario "
3132        return " PUT for non-existed "
3133
3134    def execute( self ):
3135        " Should return True if the execution completed successfully "
3136        self.fromScratch()
3137
3138        try:
3139            self.ns.putJob( 'TEST', NON_EXISTED_JOB, ANY_AUTH_TOKEN, 0, "",
3140                            'mynode', 'mysession' )
3141        except Exception as exc:
3142            if "Job not found" in str( exc ):
3143                return True
3144            raise
3145
3146        return False
3147
3148class Scenario179( TestBase ):
3149    " Scenario 179 "
3150
3151    def __init__( self, netschedule ):
3152        TestBase.__init__( self, netschedule )
3153        return
3154
3155    @staticmethod
3156    def getScenario():
3157        " Provides the scenario "
3158        return " RETURN for non-existed "
3159
3160    def execute( self ):
3161        " Should return True if the execution completed successfully "
3162        self.fromScratch()
3163
3164        try:
3165            self.ns.returnJob( 'TEST', NON_EXISTED_JOB, ANY_AUTH_TOKEN,
3166                               'mynode', 'mysession' )
3167        except Exception as exc:
3168            if "Job not found" in str( exc ):
3169                return True
3170            raise
3171
3172        return False
3173
3174class Scenario180( TestBase ):
3175    " Scenario 180 "
3176
3177    def __init__( self, netschedule ):
3178        TestBase.__init__( self, netschedule )
3179        return
3180
3181    @staticmethod
3182    def getScenario():
3183        " Provides the scenario "
3184        return " DUMP for non-existed "
3185
3186    def execute( self ):
3187        " Should return True if the execution completed successfully "
3188        self.fromScratch()
3189
3190        try:
3191            self.ns.getJobInfo( 'TEST', NON_EXISTED_JOB,
3192                                'mynode', 'mysession' )
3193        except Exception as exc:
3194            if "Job not found" in str( exc ):
3195                return True
3196            raise
3197
3198        return False
3199
3200class Scenario181( TestBase ):
3201    " Scenario 181 "
3202
3203    def __init__( self, netschedule ):
3204        TestBase.__init__( self, netschedule )
3205        return
3206
3207    @staticmethod
3208    def getScenario():
3209        " Provides the scenario "
3210        return "RDRB for non-existed "
3211
3212    def execute( self ):
3213        " Should return True if the execution completed successfully "
3214        self.fromScratch()
3215
3216        try:
3217            self.ns.rollbackRead2( 'TEST', NON_EXISTED_JOB, 'passport',
3218                                   'node', 'session' )
3219        except Exception as exc:
3220            if "Job not found" in str( exc ):
3221                return True
3222            raise
3223        return False
3224
3225class Scenario182( TestBase ):
3226    " Scenario 182 "
3227
3228    def __init__( self, netschedule ):
3229        TestBase.__init__( self, netschedule )
3230        return
3231
3232    @staticmethod
3233    def getScenario():
3234        " Provides the scenario "
3235        return "FRED for non-existed "
3236
3237    def execute( self ):
3238        " Should return True if the execution completed successfully "
3239        self.fromScratch()
3240
3241        try:
3242            self.ns.failRead2( 'TEST', NON_EXISTED_JOB, 'passport', "",
3243                               'node', 'session' )
3244        except Exception as exc:
3245            if "Job not found" in str( exc ):
3246                return True
3247            raise
3248        return False
3249
3250class Scenario183( TestBase ):
3251    " Scenario 183 "
3252
3253    def __init__( self, netschedule ):
3254        TestBase.__init__( self, netschedule )
3255        return
3256
3257    @staticmethod
3258    def getScenario():
3259        " Provides the scenario "
3260        return "CFRM for non-existed "
3261
3262    def execute( self ):
3263        " Should return True if the execution completed successfully "
3264        self.fromScratch()
3265
3266        try:
3267            self.ns.confirmRead2( 'TEST', NON_EXISTED_JOB, 'passport',
3268                                  "node", "session" )
3269        except Exception as exc:
3270            if "Job not found" in str( exc ):
3271                return True
3272            raise
3273        return False
3274
3275class Scenario184( TestBase ):
3276    " Scenario 184 "
3277
3278    def __init__( self, netschedule ):
3279        TestBase.__init__( self, netschedule )
3280        return
3281
3282    @staticmethod
3283    def getScenario():
3284        " Provides the scenario "
3285        return "SUBMIT with timeout and port, GET, PUT"
3286
3287    def execute( self ):
3288        " Should return True if the execution completed successfully "
3289        self.fromScratch()
3290
3291        # Spawn SUBMIT
3292        process = self.ns.spawnSubmitWait( 'TEST', 3,
3293                                           "", 'node', 'session' )
3294        time.sleep( 1 )
3295
3296        jobInfo = self.ns.getJob( 'TEST' )
3297        jobKey = jobInfo[ 0 ]
3298        self.ns.putJob( 'TEST', jobKey, jobInfo[ 1 ], 0, '' )
3299
3300        process.wait()
3301        if process.returncode != 0:
3302            raise Exception( "Error spawning SUBMIT" )
3303        processStdout = process.stdout.read().decode('utf-8')
3304        processStderr = process.stderr.read().decode('utf-8')       # analysis:ignore
3305
3306        if "job_key=" + jobKey in processStdout:
3307            return True
3308
3309        raise Exception( "Did not receive notifications when expected" )
3310
3311class Scenario185( TestBase ):
3312    " Scenario 185 "
3313
3314    def __init__( self, netschedule ):
3315        TestBase.__init__( self, netschedule )
3316        return
3317
3318    @staticmethod
3319    def getScenario():
3320        " Provides the scenario "
3321        return "SUBMIT with timeout and port, GET, FPUT"
3322
3323    def execute( self ):
3324        " Should return True if the execution completed successfully "
3325        self.fromScratch( 3 )
3326
3327        # Spawn SUBMIT
3328        process = self.ns.spawnSubmitWait( 'TEST', 3,
3329                                           "", 'node', 'session' )
3330
3331        jobInfo = self.ns.getJob( 'TEST' )
3332        jobKey = jobInfo[ 0 ]
3333        self.ns.failJob( 'TEST', jobKey, jobInfo[ 1 ], 3 )
3334
3335        process.wait()
3336        if process.returncode != 0:
3337            raise Exception( "Error spawning SUBMIT" )
3338        processStdout = process.stdout.read().decode('utf-8')
3339        processStderr = process.stderr.read().decode('utf-8')       # analysis:ignore
3340
3341        if "job_key=" + jobKey in processStdout:
3342            return True
3343
3344        raise Exception( "Did not receive notifications when expected" )
3345
3346class Scenario186( TestBase ):
3347    " Scenario 186 "
3348
3349    def __init__( self, netschedule ):
3350        TestBase.__init__( self, netschedule )
3351        return
3352
3353    @staticmethod
3354    def getScenario():
3355        " Provides the scenario "
3356        return "SUBMIT with timeout and port, GET, fail due to timeout"
3357
3358    def execute( self ):
3359        " Should return True if the execution completed successfully "
3360        self.fromScratch( 3 )
3361
3362        # Spawn SUBMIT
3363        process = self.ns.spawnSubmitWait( 'TEST', 20,
3364                                           "", 'node', 'session' )
3365
3366        jobKey = self.ns.getJob( 'TEST' )[ 0 ]
3367
3368        # The wait will have the pause till the job is timed out
3369        process.wait()
3370        if process.returncode != 0:
3371            raise Exception( "Error spawning SUBMIT" )
3372        processStdout = process.stdout.read().decode('utf-8')
3373        processStderr = process.stderr.read().decode('utf-8')       # analysis:ignore
3374
3375        if "job_key=" + jobKey in processStdout:
3376            return True
3377
3378        raise Exception( "Did not receive notifications when expected" )
3379
3380class Scenario187( TestBase ):
3381    " Scenario 187 "
3382
3383    def __init__( self, netschedule ):
3384        TestBase.__init__( self, netschedule )
3385        return
3386
3387    @staticmethod
3388    def getScenario():
3389        " Provides the scenario "
3390        return "SUBMIT with timeout and port, GET, CANCEL"
3391
3392    def execute( self ):
3393        " Should return True if the execution completed successfully "
3394        self.fromScratch( 3 )
3395
3396        # Spawn SUBMIT
3397        process = self.ns.spawnSubmitWait( 'TEST', 3,
3398                                           "", 'node', 'session' )
3399
3400        jobKey = self.ns.getJob( 'TEST' )[ 0 ]
3401        self.ns.cancelJob( 'TEST', jobKey )
3402
3403        process.wait()
3404        if process.returncode != 0:
3405            raise Exception( "Error spawning SUBMIT" )
3406        processStdout = process.stdout.read().decode('utf-8')
3407        processStderr = process.stderr.read().decode('utf-8')       # analysis:ignore
3408
3409        if "job_key=" + jobKey in processStdout:
3410            return True
3411
3412        raise Exception( "Did not receive notifications when expected" )
3413
3414class Scenario188( TestBase ):
3415    " Scenario 188 "
3416
3417    def __init__( self, netschedule ):
3418        TestBase.__init__( self, netschedule )
3419        return
3420
3421    @staticmethod
3422    def getScenario():
3423        " Provides the scenario "
3424        return "GET2 with timeout and port"
3425
3426    def execute( self ):
3427        " Should return True if the execution completed successfully "
3428        self.fromScratch()
3429
3430        safeMode = True
3431        if safeMode:
3432            ns_client = self.getNetScheduleService( 'TEST', 'scenario188' )
3433            ns_client.set_client_identification( 'node', 'session' )
3434
3435            notifSocket = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
3436            notifSocket.bind( ( "", 0 ) )
3437            notifPort = notifSocket.getsockname()[ 1 ]
3438
3439            execAny( ns_client,
3440                     'GET2 wnode_aff=0 any_aff=1 exclusive_new_aff=0 port=' + str( notifPort ) + ' timeout=3' )
3441
3442            # Submit a job
3443            self.ns.submitJob( 'TEST', 'input' )
3444
3445            time.sleep( 3 )
3446            result = self.getNotif( notifSocket )
3447            notifSocket.close()
3448            if result == 0:
3449                raise Exception( "Expected notification(s), received nothing" )
3450            return True
3451
3452
3453        # Spawn GET2 with waiting
3454        process = self.ns.spawnGet2Wait( 'TEST', 5,
3455                                         [], False, True,
3456                                         'node', 'session' )
3457
3458        # Sometimes it takes so long to spawn grid_cli that the next
3459        # command is sent before GET2 is sent. So, we have a sleep here
3460        time.sleep( 2 )
3461
3462        # Submit a job
3463        self.ns.submitJob( 'TEST', 'input' )
3464
3465        process.wait()
3466        if process.returncode != 0:
3467            raise Exception( "Error spawning GET2" )
3468        processStdout = process.stdout.read().decode('utf-8')
3469        processStderr = process.stderr.read().decode('utf-8')       # analysis:ignore
3470
3471        if "[valid" in processStdout:
3472            return True
3473
3474        raise Exception( "Did not receive notifications when expected" )
3475
3476    def getNotif( self, s ):
3477        " Retrieves notifications "
3478        try:
3479            data = s.recv( 8192, socket.MSG_DONTWAIT ).decode('utf-8')
3480            if "queue=TEST" not in data:
3481                raise Exception( "Unexpected notification in socket" )
3482            return 1
3483        except Exception as ex:
3484            if "Unexpected notification in socket" in str( ex ):
3485                raise
3486            pass
3487        return 0
3488
3489
3490
3491class Scenario189( TestBase ):
3492    " Scenario 189 "
3493
3494    def __init__( self, netschedule ):
3495        TestBase.__init__( self, netschedule )
3496        return
3497
3498    @staticmethod
3499    def getScenario():
3500        " Provides the scenario "
3501        return "GET2 with timeout and port and affinity a1"
3502
3503    def execute( self ):
3504        " Should return True if the execution completed successfully "
3505        self.fromScratch()
3506
3507        safeMode = True
3508        if safeMode:
3509            ns_client = self.getNetScheduleService( 'TEST', 'scenario189' )
3510            ns_client.set_client_identification( 'node', 'session' )
3511
3512            notifSocket = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
3513            notifSocket.bind( ( "", 0 ) )
3514            notifPort = notifSocket.getsockname()[ 1 ]
3515
3516            execAny( ns_client,
3517                     'GET2 wnode_aff=0 any_aff=0 exclusive_new_aff=0 aff=a1 port=' + str( notifPort ) +' timeout=3' )
3518
3519            # Submit a job
3520            self.ns.submitJob( 'TEST', 'input' )
3521
3522            time.sleep( 3 )
3523            result = self.getNotif( notifSocket )
3524            notifSocket.close()
3525            if result != 0:
3526                raise Exception( "Expect no notifications but received some" )
3527            return True
3528
3529
3530        # Spawn GET2 with waiting
3531        process = self.ns.spawnGet2Wait( 'TEST', 5,
3532                                         [ 'a1' ], False, False,
3533                                         'node', 'session' )
3534
3535        # Sometimes it takes so long to spawn grid_cli that the next
3536        # command is sent before GET2 is sent. So, we have a sleep here
3537        time.sleep( 2 )
3538
3539
3540        # Submit a job
3541        self.ns.submitJob( 'TEST', 'input' )
3542
3543        process.wait()
3544        if process.returncode != 0:
3545            raise Exception( "Error spawning GET2" )
3546        processStdout = process.stdout.read().decode('utf-8')
3547        processStderr = process.stderr.read().decode('utf-8')       # analysis:ignore
3548
3549        if "[valid" in processStdout:
3550            raise Exception( "Expect no notifications but received one" )
3551        return True
3552
3553    def getNotif( self, s ):
3554        " Retrieves notifications "
3555        try:
3556            data = s.recv( 8192, socket.MSG_DONTWAIT ).decode('utf-8')
3557            if "queue=TEST" not in data:
3558                raise Exception( "Unexpected notification in socket" )
3559            return 1
3560        except Exception as ex:
3561            if "Unexpected notification in socket" in str( ex ):
3562                raise
3563            pass
3564        return 0
3565
3566
3567class Scenario190( TestBase ):
3568    " Scenario 190 "
3569
3570    def __init__( self, netschedule ):
3571        TestBase.__init__( self, netschedule )
3572        return
3573
3574    @staticmethod
3575    def getScenario():
3576        " Provides the scenario "
3577        return "GET2 with timeout and port, and explicit aff a1"
3578
3579    def execute( self ):
3580        " Should return True if the execution completed successfully "
3581        self.fromScratch()
3582
3583        safeMode = True
3584        if safeMode:
3585            ns_client = self.getNetScheduleService( 'TEST', 'scenario190' )
3586            ns_client.set_client_identification( 'node', 'session' )
3587
3588            notifSocket = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
3589            notifSocket.bind( ( "", 0 ) )
3590            notifPort = notifSocket.getsockname()[ 1 ]
3591
3592            execAny( ns_client,
3593                     'GET2 wnode_aff=0 any_aff=0 exclusive_new_aff=0 aff=a1 port=' + str( notifPort ) + ' timeout=3' )
3594
3595            # Submit a job
3596            self.ns.submitJob( 'TEST', 'input', 'a1' )
3597
3598            time.sleep( 3 )
3599            result = self.getNotif( notifSocket )
3600            notifSocket.close()
3601            if result == 0:
3602                raise Exception( "Expected notification(s), received nothing" )
3603            return True
3604
3605        # Spawn GET2 with waiting
3606        process = self.ns.spawnGet2Wait( 'TEST', 5,
3607                                         [ 'a1' ], False, False,
3608                                         'node', 'session' )
3609
3610        # Sometimes it takes so long to spawn grid_cli that the next
3611        # command is sent before GET2 is sent. So, we have a sleep here
3612        time.sleep( 2 )
3613
3614        # Submit a job
3615        self.ns.submitJob( 'TEST', 'input', 'a1' )
3616
3617        process.wait()
3618        if process.returncode != 0:
3619            raise Exception( "Error spawning GET2" )
3620        processStdout = process.stdout.read().decode('utf-8')
3621        processStderr = process.stderr.read().decode('utf-8')       # analysis:ignore
3622
3623        if "[valid" in processStdout:
3624            return True
3625
3626        raise Exception( "Did not receive notifications when expected" )
3627
3628    def getNotif( self, s ):
3629        " Retrieves notifications "
3630        try:
3631            data = s.recv( 8192, socket.MSG_DONTWAIT ).decode('utf-8')
3632            if "queue=TEST" not in data:
3633                raise Exception( "Unexpected notification in socket" )
3634            return 1
3635        except Exception as ex:
3636            if "Unexpected notification in socket" in str( ex ):
3637                raise
3638            pass
3639        return 0
3640
3641
3642
3643class Scenario191( TestBase ):
3644    " Scenario 191 "
3645
3646    def __init__( self, netschedule ):
3647        TestBase.__init__( self, netschedule )
3648        return
3649
3650    @staticmethod
3651    def getScenario():
3652        " Provides the scenario "
3653        return "GET2 with timeout and port, and explicit aff a1, and any_aff=1"
3654
3655    def execute( self ):
3656        " Should return True if the execution completed successfully "
3657        self.fromScratch()
3658
3659        safeMode = True
3660        if safeMode:
3661            ns_client = self.getNetScheduleService( 'TEST', 'scenario191' )
3662            ns_client.set_client_identification( 'node', 'session' )
3663
3664            notifSocket = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
3665            notifSocket.bind( ( "", 0 ) )
3666            notifPort = notifSocket.getsockname()[ 1 ]
3667
3668            execAny( ns_client,
3669                     'GET2 wnode_aff=0 any_aff=1 exclusive_new_aff=0 aff=a1 port=' + str( notifPort ) + ' timeout=3' )
3670
3671            # Submit a job
3672            self.ns.submitJob( 'TEST', 'input', 'a2' )
3673
3674            time.sleep( 3 )
3675            result = self.getNotif( notifSocket )
3676            notifSocket.close()
3677            if result == 0:
3678                raise Exception( "Expected notification(s), received nothing" )
3679            return True
3680
3681
3682        # Spawn GET2 with waiting
3683        process = self.ns.spawnGet2Wait( 'TEST', 5,
3684                                         [ 'a1' ], False, True,
3685                                         'node', 'session' )
3686
3687        # Sometimes it takes so long to spawn grid_cli that the next
3688        # command is sent before GET2 is sent. So, we have a sleep here
3689        time.sleep( 2 )
3690
3691        # Submit a job
3692        self.ns.submitJob( 'TEST', 'input', 'a2' )
3693
3694        process.wait()
3695        if process.returncode != 0:
3696            raise Exception( "Error spawning GET2" )
3697        processStdout = process.stdout.read()
3698        processStderr = process.stderr.read()       # analysis:ignore
3699
3700        if "[valid" in processStdout:
3701            return True
3702
3703        raise Exception( "Did not receive notifications when expected" )
3704
3705    def getNotif( self, s ):
3706        " Retrieves notifications "
3707        try:
3708            data = s.recv( 8192, socket.MSG_DONTWAIT ).decode('utf-8')
3709            if "queue=TEST" not in data:
3710                raise Exception( "Unexpected notification in socket" )
3711            return 1
3712        except Exception as ex:
3713            if "Unexpected notification in socket" in str( ex ):
3714                raise
3715            pass
3716        return 0
3717
3718
3719
3720class Scenario192( TestBase ):
3721    " Scenario 192 "
3722
3723    def __init__( self, netschedule ):
3724        TestBase.__init__( self, netschedule )
3725        return
3726
3727    @staticmethod
3728    def getScenario():
3729        " Provides the scenario "
3730        return "CHAFF add=a3; GET2 with timeout and port, wnode_aff=1"
3731
3732    def execute( self ):
3733        " Should return True if the execution completed successfully "
3734        self.fromScratch()
3735
3736        safeMode = True
3737        if safeMode:
3738            ns_client = self.getNetScheduleService( 'TEST', 'scenario192' )
3739            ns_client.set_client_identification( 'node', 'session' )
3740            changeAffinity( ns_client, ['a3'], [] )
3741
3742            notifSocket = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
3743            notifSocket.bind( ( "", 0 ) )
3744            notifPort = notifSocket.getsockname()[ 1 ]
3745
3746            execAny( ns_client,
3747                     'GET2 wnode_aff=1 any_aff=0 exclusive_new_aff=1 port=' + str( notifPort ) + ' timeout=3' )
3748
3749            # Submit a job
3750            self.ns.submitJob( 'TEST', 'input', 'a3' )
3751
3752            time.sleep( 3 )
3753            result = self.getNotif( notifSocket )
3754            notifSocket.close()
3755            if result == 0:
3756                raise Exception( "Expected one notification, received nothing" )
3757            return True
3758
3759        # Unsafe mode: grid_cli has a bug which breaks the test
3760        # It's been way too long to wait till it is fixed, so there is a workaround
3761        # above to avoid using buggy part of grid_cli
3762        ns_client = self.getNetScheduleService( 'TEST', 'scenario192' )
3763        ns_client.set_client_identification( 'node', 'session' )
3764        changeAffinity( ns_client, ['a3'], [] )
3765
3766        # Spawn GET2 with waiting
3767        process = self.ns.spawnGet2Wait( 'TEST', 5,
3768                                         [], True, False,
3769                                         'node', 'session' )
3770
3771        # Sometimes it takes so long to spawn grid_cli that the next
3772        # command is sent before GET2 is sent. So, we have a sleep here
3773        time.sleep( 2 )
3774
3775        # Submit a job
3776        self.ns.submitJob( 'TEST', 'input', 'a3' )
3777
3778        process.wait()
3779        if process.returncode != 0:
3780            raise Exception( "Error spawning GET2" )
3781        processStdout = process.stdout.read()
3782        processStderr = process.stderr.read()       # analysis:ignore
3783
3784        if "[valid" in processStdout:
3785            return True
3786
3787        raise Exception( "Did not receive notifications when expected. "
3788                         "Received:\n'" + processStdout + "'" )
3789
3790    def getNotif( self, s ):
3791        " Retrieves notifications "
3792        try:
3793            data = s.recv( 8192, socket.MSG_DONTWAIT ).decode('utf-8')
3794            if "queue=TEST" not in data:
3795                raise Exception( "Unexpected notification in socket" )
3796            return 1
3797        except Exception as ex:
3798            if "Unexpected notification in socket" in str( ex ):
3799                raise
3800            pass
3801        return 0
3802
3803
3804class Scenario193( TestBase ):
3805    " Scenario 193 "
3806
3807    def __init__( self, netschedule ):
3808        TestBase.__init__( self, netschedule )
3809        return
3810
3811    @staticmethod
3812    def getScenario():
3813        " Provides the scenario "
3814        return "CHAFF add=a3; GET2 with timeout and port, wnode_aff=1"
3815
3816    def execute( self ):
3817        " Should return True if the execution completed successfully "
3818        self.fromScratch()
3819
3820        safeMode = True
3821        if safeMode:
3822            ns_client = self.getNetScheduleService( 'TEST', 'scenario193' )
3823            ns_client.set_client_identification( 'node', 'session' )
3824            changeAffinity( ns_client, ['a3'], [] )
3825
3826            notifSocket = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
3827            notifSocket.bind( ( "", 0 ) )
3828            notifPort = notifSocket.getsockname()[ 1 ]
3829
3830            execAny( ns_client,
3831                     'GET2 wnode_aff=1 any_aff=0 exclusive_new_aff=0 port=' + str( notifPort ) + ' timeout=3' )
3832
3833            # Submit a job
3834            self.ns.submitJob( 'TEST', 'input', 'a4' )
3835
3836            time.sleep( 3 )
3837            result = self.getNotif( notifSocket )
3838            notifSocket.close()
3839            if result != 0:
3840                raise Exception( "Received notifications when not expected" )
3841            return True
3842
3843        ns_client = self.getNetScheduleService( 'TEST', 'scenario193' )
3844        ns_client.set_client_identification( 'node', 'session' )
3845        changeAffinity( ns_client, ['a3'], [] )
3846
3847        # Spawn GET2 with waiting
3848        process = self.ns.spawnGet2Wait( 'TEST', 5,
3849                                         [], True, False,
3850                                         'node', 'session' )
3851
3852        # Sometimes it takes so long to spawn grid_cli that the next
3853        # command is sent before GET2 is sent. So, we have a sleep here
3854        time.sleep( 2 )
3855
3856        # Submit a job
3857        self.ns.submitJob( 'TEST', 'input', 'a4' )
3858
3859        process.wait()
3860        if process.returncode != 0:
3861            raise Exception( "Error spawning GET2" )
3862        processStdout = process.stdout.read()
3863        processStderr = process.stderr.read()       # analysis:ignore
3864
3865        if "[valid" in processStdout:
3866            raise Exception( "Received notifications when not expected" )
3867        return True
3868
3869    def getNotif( self, s ):
3870        " Retrieves notifications "
3871        try:
3872            data = s.recv( 8192, socket.MSG_DONTWAIT ).decode('utf-8')
3873            if "queue=TEST" not in data:
3874                raise Exception( "Unexpected notification in socket" )
3875            return 1
3876        except Exception as ex:
3877            if "Unexpected notification in socket" in str( ex ):
3878                raise
3879            pass
3880        return 0
3881
3882
3883
3884class Scenario194( TestBase ):
3885    " Scenario 194 "
3886
3887    def __init__( self, netschedule ):
3888        TestBase.__init__( self, netschedule )
3889        return
3890
3891    @staticmethod
3892    def getScenario():
3893        " Provides the scenario "
3894        return " SST as anonymous, SST as identified, check clients registry "
3895
3896    def execute( self ):
3897        " Should return True if the execution completed successfully "
3898        self.fromScratch()
3899
3900        ns_client = self.getNetScheduleService( 'TEST', 'scenario194' )
3901        try:
3902            ns_client.set_client_identification( '', '' )
3903        except:
3904            pass
3905
3906        self.ns.getFastJobStatus( 'TEST', NON_EXISTED_JOB )
3907        getClientInfo( ns_client, None, 0, 0 )
3908
3909        self.ns.getFastJobStatus( 'TEST', NON_EXISTED_JOB,
3910                                  'mynode', 'mysession')
3911        getClientInfo( ns_client, 'mynode', 1, 1 )
3912        return True
3913
3914class Scenario195( TestBase ):
3915    " Scenario 195 "
3916
3917    def __init__( self, netschedule ):
3918        TestBase.__init__( self, netschedule )
3919        return
3920
3921    @staticmethod
3922    def getScenario():
3923        " Provides the scenario "
3924        return " WST as anonymous, WST as identified, check clients registry "
3925
3926    def execute( self ):
3927        " Should return True if the execution completed successfully "
3928        self.fromScratch()
3929
3930        ns_client = self.getNetScheduleService( 'TEST', 'scenario195' )
3931        try:
3932            ns_client.set_client_identification( '', '' )
3933        except:
3934            pass
3935
3936        self.ns.getJobStatus( 'TEST', NON_EXISTED_JOB )
3937        getClientInfo( ns_client, None, 0, 0 )
3938
3939        self.ns.getJobStatus( 'TEST', NON_EXISTED_JOB,
3940                              'mynode', 'mysession')
3941        getClientInfo( ns_client, 'mynode', 1, 1 )
3942        return True
3943
3944class Scenario196( TestBase ):
3945    " Scenario 196 "
3946
3947    def __init__( self, netschedule ):
3948        TestBase.__init__( self, netschedule )
3949        return
3950
3951    @staticmethod
3952    def getScenario():
3953        " Provides the scenario "
3954        return " SUBMIT as anonymous, SUBMIT as identified, " \
3955               "check clients registry "
3956
3957    def execute( self ):
3958        " Should return True if the execution completed successfully "
3959        self.fromScratch()
3960
3961        ns_client = self.getNetScheduleService( 'TEST', 'scenario196' )
3962        try:
3963            ns_client.set_client_identification( '', '' )
3964        except:
3965            pass
3966
3967        self.ns.submitJob( 'TEST', 'input' )
3968        getClientInfo( ns_client, None, 0, 0 )
3969
3970        self.ns.submitJob( 'TEST', 'input', '', '',
3971                           'mynode', 'mysession')
3972        getClientInfo( ns_client, 'mynode', 1, 1 )
3973        return True
3974
3975class Scenario197( TestBase ):
3976    " Scenario 197 "
3977
3978    def __init__( self, netschedule ):
3979        TestBase.__init__( self, netschedule )
3980        return
3981
3982    @staticmethod
3983    def getScenario():
3984        " Provides the scenario "
3985        return " CANCEL as anonymous, CANCEL as identified, " \
3986               "check clients registry "
3987
3988    def execute( self ):
3989        " Should return True if the execution completed successfully "
3990        self.fromScratch()
3991
3992        ns_client = self.getNetScheduleService( 'TEST', 'scenario197' )
3993        try:
3994            ns_client.set_client_identification( '', '' )
3995        except:
3996            pass
3997
3998        self.ns.cancelJob( 'TEST', NON_EXISTED_JOB )
3999        getClientInfo( ns_client, None, 0, 0 )
4000
4001        self.ns.cancelJob( 'TEST', NON_EXISTED_JOB,
4002                           'mynode', 'mysession')
4003        getClientInfo( ns_client, 'mynode', 1, 1 )
4004        return True
4005
4006class Scenario198( TestBase ):
4007    " Scenario 198 "
4008
4009    def __init__( self, netschedule ):
4010        TestBase.__init__( self, netschedule )
4011        return
4012
4013    @staticmethod
4014    def getScenario():
4015        " Provides the scenario "
4016        return " STATUS as anonymous, STATUS as identified, " \
4017               "check clients registry "
4018
4019    def execute( self ):
4020        " Should return True if the execution completed successfully "
4021        self.fromScratch()
4022
4023        ns_client = self.getNetScheduleService( 'TEST', 'scenario198' )
4024        try:
4025            ns_client.set_client_identification( '', '' )
4026        except:
4027            pass
4028
4029        try:
4030            # This generates an exception for non existing job
4031            self.ns.getJobBriefStatus( 'TEST', NON_EXISTED_JOB )
4032        except:
4033            pass
4034        getClientInfo( ns_client, None, 0, 0 )
4035
4036        try:
4037            # This generates an exception for non existing job
4038            self.ns.getJobBriefStatus( 'TEST', NON_EXISTED_JOB,
4039                                    'mynode', 'mysession' )
4040        except:
4041            pass
4042        getClientInfo( ns_client, 'mynode', 1, 1 )
4043        return True
4044
4045class Scenario203( TestBase ):
4046    " Scenario 203 "
4047
4048    def __init__( self, netschedule ):
4049        TestBase.__init__( self, netschedule )
4050        return
4051
4052    @staticmethod
4053    def getScenario():
4054        " Provides the scenario "
4055        return " STAT as anonymous, STAT as identified, " \
4056               "check clients registry "
4057
4058    def execute( self ):
4059        " Should return True if the execution completed successfully "
4060        self.fromScratch()
4061
4062        ns_client = self.getNetScheduleService( 'TEST', 'scenario203' )
4063        try:
4064            ns_client.set_client_identification( '', '' )
4065        except:
4066            pass
4067
4068        self.ns.getBriefStat( 'TEST' )
4069        client = getClientInfo( ns_client, None, 0, 0 )     # analysis:ignore
4070
4071        self.ns.getBriefStat( 'TEST', 'mynode', 'mysession' )
4072        getClientInfo( ns_client, 'mynode', 1, 1 )
4073        return True
4074
4075class Scenario204( TestBase ):
4076    " Scenario 204 "
4077
4078    def __init__( self, netschedule ):
4079        TestBase.__init__( self, netschedule )
4080        return
4081
4082    @staticmethod
4083    def getScenario():
4084        " Provides the scenario "
4085        return " STAT as anonymous, STAT as identified, " \
4086               "check clients registry "
4087
4088    def execute( self ):
4089        " Should return True if the execution completed successfully "
4090        self.fromScratch()
4091
4092        ns_client = self.getNetScheduleService( 'TEST', 'scenario204' )
4093        try:
4094            ns_client.set_client_identification( '', '' )
4095        except:
4096            pass
4097
4098        self.ns.getAffinityStatus( 'TEST' )
4099        getClientInfo( ns_client, None, 0, 0 )
4100
4101        self.ns.getAffinityStatus( 'TEST',
4102                                   node = 'mynode', session = 'mysession' )
4103        getClientInfo( ns_client, 'mynode', 1, 1 )
4104        return True
4105
4106class Scenario206( TestBase ):
4107    " Scenario 206 "
4108
4109    def __init__( self, netschedule ):
4110        TestBase.__init__( self, netschedule )
4111        return
4112
4113    @staticmethod
4114    def getScenario():
4115        " Provides the scenario "
4116        return " MPUT as anonymous, MPUT as identified, " \
4117               "check clients registry "
4118
4119    def execute( self ):
4120        " Should return True if the execution completed successfully "
4121        self.fromScratch()
4122
4123        ns_client = self.getNetScheduleService( 'TEST', 'scenario206' )
4124        try:
4125            ns_client.set_client_identification( '', '' )
4126        except:
4127            pass
4128
4129        jobID = self.ns.submitJob( 'TEST', 'bla',
4130                                   node = 'prep', session = 'session' )
4131        self.ns.getJob( 'TEST', node = 'prep', session = 'session' )
4132
4133        self.ns.setJobProgressMessage( 'TEST', jobID, 'msg' )
4134
4135        getClientInfo( ns_client, None, 1, 1 )
4136
4137        self.ns.setJobProgressMessage( 'TEST', jobID,
4138                                           'msg', 'mynode', 'mysession' )
4139        getClientInfo( ns_client, 'mynode', 2, 2 )
4140        return True
4141
4142class Scenario207( TestBase ):
4143    " Scenario 207 "
4144
4145    def __init__( self, netschedule ):
4146        TestBase.__init__( self, netschedule )
4147        return
4148
4149    @staticmethod
4150    def getScenario():
4151        " Provides the scenario "
4152        return " MGET as anonymous, MGET as identified, " \
4153               "check clients registry "
4154
4155    def execute( self ):
4156        " Should return True if the execution completed successfully "
4157        self.fromScratch()
4158
4159        ns_client = self.getNetScheduleService( 'TEST', 'scenario207' )
4160        try:
4161            ns_client.set_client_identification( '', '' )
4162        except:
4163            pass
4164
4165        jobID = self.ns.submitJob( 'TEST', 'bla',
4166                                   node = 'prep', session = 'session' )
4167        self.ns.getJob( 'TEST', node = 'prep', session = 'session' )
4168
4169        self.ns.getJobProgressMessage( 'TEST', jobID )
4170        getClientInfo( ns_client, None, 1, 1 )
4171
4172        self.ns.getJobProgressMessage( 'TEST', jobID, 'mynode', 'mysession' )
4173        getClientInfo( ns_client, 'mynode', 2, 2 )
4174        return True
4175
4176class Scenario208( TestBase ):
4177    " Scenario 208 "
4178
4179    def __init__( self, netschedule ):
4180        TestBase.__init__( self, netschedule )
4181        return
4182
4183    @staticmethod
4184    def getScenario():
4185        " Provides the scenario "
4186        return " DUMP as anonymous, DUMP as identified, " \
4187               "check clients registry "
4188
4189    def execute( self ):
4190        " Should return True if the execution completed successfully "
4191        self.fromScratch()
4192
4193        ns_client = self.getNetScheduleService( 'TEST', 'scenario208' )
4194        try:
4195            ns_client.set_client_identification( '', '' )
4196        except:
4197            pass
4198
4199        self.ns.getQueueDump( 'TEST' )
4200        getClientInfo( ns_client, None, 0, 0 )
4201
4202        self.ns.getQueueDump( 'TEST', node = 'mynode', session = 'mysession' )
4203        getClientInfo( ns_client, 'mynode', 1, 1 )
4204        return True
4205
4206class Scenario212( TestBase ):
4207    " Scenario 212 "
4208
4209    def __init__( self, netschedule ):
4210        TestBase.__init__( self, netschedule )
4211        return
4212
4213    @staticmethod
4214    def getScenario():
4215        " Provides the scenario "
4216        return " JDEX as anonymous, JDEX as identified, " \
4217               "check clients registry "
4218
4219    def execute( self ):
4220        " Should return True if the execution completed successfully "
4221        self.fromScratch()
4222
4223        ns_client = self.getNetScheduleService( 'TEST', 'scenario212' )
4224        try:
4225            ns_client.set_client_identification( '', '' )
4226        except:
4227            pass
4228
4229        jobID = self.ns.submitJob( 'TEST', 'bla',
4230                                   node = 'prep', session = 'session' )
4231        self.ns.getJob( 'TEST', node = 'prep', session = 'session' )
4232        self.ns.extendJobExpiration( 'TEST', jobID, 5 )
4233
4234        getClientInfo( ns_client, None, 1, 1 )
4235
4236        self.ns.extendJobExpiration( 'TEST', jobID, 5, 'mynode', 'mysession' )
4237        getClientInfo( ns_client, 'mynode', 2, 2 )
4238        return True
4239
4240class Scenario213( TestBase ):
4241    " Scenario 213 "
4242
4243    def __init__( self, netschedule ):
4244        TestBase.__init__( self, netschedule )
4245        return
4246
4247    @staticmethod
4248    def getScenario():
4249        " Provides the scenario "
4250        return " STSN as anonymous, STSN as identified, " \
4251               "check clients registry "
4252
4253    def execute( self ):
4254        " Should return True if the execution completed successfully "
4255        self.fromScratch()
4256
4257        ns_client = self.getNetScheduleService( 'TEST', 'scenario213' )
4258        try:
4259            ns_client.set_client_identification( '', '' )
4260        except:
4261            pass
4262
4263        jobID = self.ns.submitJob( 'TEST', 'bla', affinity = 'myaff',   # analysis:ignore
4264                                   node = 'prep', session = 'session' )
4265        self.ns.getAffinityStatus( 'TEST', 'myaff' )
4266
4267        getClientInfo( ns_client, None, 1, 1 )
4268
4269        self.ns.getAffinityStatus( 'TEST', 'myaff', 'mynode', 'mysession' )
4270        getClientInfo( ns_client, 'mynode', 2, 2 )
4271        return True
4272
4273class Scenario214( TestBase ):
4274    " Scenario 214 "
4275
4276    def __init__( self, netschedule ):
4277        TestBase.__init__( self, netschedule )
4278        return
4279
4280    @staticmethod
4281    def getScenario():
4282        " Provides the scenario "
4283        return " GETP as anonymous, GETP as identified, " \
4284               "check clients registry "
4285
4286    def execute( self ):
4287        " Should return True if the execution completed successfully "
4288        self.fromScratch()
4289
4290        ns_client = self.getNetScheduleService( 'TEST', 'scenario214' )
4291        try:
4292            ns_client.set_client_identification( '', '' )
4293        except:
4294            pass
4295
4296        output = execAny( ns_client, 'GETP' )
4297        getClientInfo( ns_client, None, 0, 0 )
4298
4299        ns_client1 = self.getNetScheduleService( 'TEST', 'scenario214' )
4300        ns_client1.set_client_identification( 'mynode', 'mysession' )
4301        output = execAny( ns_client1, 'GETP' )      # analysis:ignore
4302        getClientInfo( ns_client, 'mynode', 1, 1 )
4303        return True
4304
4305class Scenario215( TestBase ):
4306    " Scenario 215 "
4307
4308    def __init__( self, netschedule ):
4309        TestBase.__init__( self, netschedule )
4310        return
4311
4312    @staticmethod
4313    def getScenario():
4314        " Provides the scenario "
4315        return " GETC as anonymous, GETC as identified, " \
4316               "check clients registry "
4317
4318    def execute( self ):
4319        " Should return True if the execution completed successfully "
4320        self.fromScratch()
4321
4322        ns_client = self.getNetScheduleService( 'TEST', 'scenario215' )
4323        try:
4324            ns_client.set_client_identification( '', '' )
4325        except:
4326            pass
4327
4328        output = execAny( ns_client, 'GETC' )
4329        getClientInfo( ns_client, None, 0, 0 )
4330
4331        ns_client1 = self.getNetScheduleService( 'TEST', 'scenario215' )
4332        ns_client1.set_client_identification( 'mynode', 'mysession' )
4333        output = execAny( ns_client1, 'GETC' )      # analysis:ignore
4334        getClientInfo( ns_client, 'mynode', 1, 1 )
4335        return True
4336
4337class Scenario216( TestBase ):
4338    " Scenario 216 "
4339
4340    def __init__( self, netschedule ):
4341        TestBase.__init__( self, netschedule )
4342        return
4343
4344    @staticmethod
4345    def getScenario():
4346        " Provides the scenario "
4347        return " READ as anonymous, READ as identified, " \
4348               "check clients registry "
4349
4350    def execute( self ):
4351        " Should return True if the execution completed successfully "
4352        self.fromScratch()
4353
4354        ns_client = self.getNetScheduleService( 'TEST', 'scenario216' )
4355        self.ns.getJobForReading( 'TEST' )
4356        client = getClientInfo( ns_client, False, 0 )
4357        if client is not None:
4358            raise Exception( "Expected no client. Received some." )
4359
4360        self.ns.getJobForReading( 'TEST', 'mynode', 'mysession' )
4361        client = getClientInfo( ns_client, False, 1, 0 )
4362        if client is None:
4363            raise Exception( "Expected a client. Received none." )
4364        return True
4365
4366class Scenario217( TestBase ):
4367    " Scenario 217 "
4368
4369    def __init__( self, netschedule ):
4370        TestBase.__init__( self, netschedule )
4371        return
4372
4373    @staticmethod
4374    def getScenario():
4375        " Provides the scenario "
4376        return "CFRM as anonymous, CFRM as identified, " \
4377               "check clients registry "
4378
4379    def execute( self ):
4380        " Should return True if the execution completed successfully "
4381        self.fromScratch()
4382
4383        ns_client = self.getNetScheduleService( 'TEST', 'scenario217' )
4384        try:
4385            self.ns.confirmReading( 'TEST', NON_EXISTED_JOB, 'passport' )
4386        except:
4387            pass
4388        client = getClientInfo( ns_client, False, 0 )
4389        if client is not None:
4390            raise Exception( "Expected no client. Received some." )
4391
4392        try:
4393            self.ns.confirmReading( 'TEST', NON_EXISTED_JOB, 'passport',
4394                                    'mynode', 'mysession' )
4395        except:
4396            pass
4397        client = getClientInfo( ns_client, False, 1, 0 )
4398        if client is None:
4399            raise Exception( "Expected a client. Received none." )
4400        return True
4401
4402class Scenario218( TestBase ):
4403    " Scenario 218 "
4404
4405    def __init__( self, netschedule ):
4406        TestBase.__init__( self, netschedule )
4407        return
4408
4409    @staticmethod
4410    def getScenario():
4411        " Provides the scenario "
4412        return "FRED as anonymous, FRED as identified, " \
4413               "check clients registry "
4414
4415    def execute( self ):
4416        " Should return True if the execution completed successfully "
4417        self.fromScratch()
4418
4419        ns_client = self.getNetScheduleService( 'TEST', 'scenario218' )
4420        try:
4421            self.ns.failReadingJob( 'TEST', NON_EXISTED_JOB, 'passport' )
4422        except:
4423            pass
4424        client = getClientInfo( ns_client, False, 0 )
4425        if client is not None:
4426            raise Exception( "Expected no client. Received some." )
4427
4428        try:
4429            self.ns.failReadingJob( 'TEST', NON_EXISTED_JOB, 'passport',
4430                                    'mynode', 'mysession' )
4431        except:
4432            pass
4433        client = getClientInfo( ns_client, False, 1, 0 )
4434        if client is None:
4435            raise Exception( "Expected a client. Received none." )
4436        return True
4437
4438class Scenario219( TestBase ):
4439    " Scenario 219 "
4440
4441    def __init__( self, netschedule ):
4442        TestBase.__init__( self, netschedule )
4443        return
4444
4445    @staticmethod
4446    def getScenario():
4447        " Provides the scenario "
4448        return "RDRB as anonymous, RDRB as identified, " \
4449               "check clients registry "
4450
4451    def execute( self ):
4452        " Should return True if the execution completed successfully "
4453        self.fromScratch()
4454
4455        ns_client = self.getNetScheduleService( 'TEST', 'scenario219' )
4456        try:
4457            self.ns.rollbackJob( 'TEST', NON_EXISTED_JOB, 'passport' )
4458        except:
4459            pass
4460        client = getClientInfo( ns_client, False, 0 )
4461        if client is not None:
4462            raise Exception( "Expected no client. Received some." )
4463
4464        try:
4465            self.ns.rollbackJob( 'TEST', NON_EXISTED_JOB, 'passport',
4466                                 'mynode', 'mysession' )
4467        except:
4468            pass
4469        client = getClientInfo( ns_client, False, 1, 0 )
4470        if client is None:
4471            raise Exception( "Expected a client. Received none." )
4472        return True
4473
4474class Scenario221( TestBase ):
4475    " Scenario 221 "
4476
4477    def __init__( self, netschedule ):
4478        TestBase.__init__( self, netschedule )
4479        return
4480
4481    @staticmethod
4482    def getScenario():
4483        " Provides the scenario "
4484        return "CWGET as anonymous"
4485
4486    def execute( self ):
4487        " Should return True if the execution completed successfully "
4488        self.fromScratch()
4489
4490        ns_client = self.getNetScheduleService( 'TEST', 'scenario221' )
4491        try:
4492            ns_client.set_client_identification( '', '' )
4493        except:
4494            pass
4495
4496        try:
4497            execAny( ns_client, 'CWGET' )
4498        except Exception as exc:
4499            if "no client_node and client_session at handshake" in str( exc ):
4500                return True
4501            raise
4502        raise Exception( "Expected auth exception, got nothing" )
4503
4504class Scenario222( TestBase ):
4505    " Scenario 222 "
4506
4507    def __init__( self, netschedule ):
4508        TestBase.__init__( self, netschedule )
4509        return
4510
4511    @staticmethod
4512    def getScenario():
4513        " Provides the scenario "
4514        return "CWGET as identified"
4515
4516    def execute( self ):
4517        " Should return True if the execution completed successfully "
4518        self.fromScratch()
4519
4520        ns_client = self.getNetScheduleService( 'TEST', 'scenario221' )
4521        ns_client.set_client_identification( 'mynode', 'mysession' )
4522        execAny( ns_client, 'CWGET' )
4523        return True
4524
4525class Scenario223( TestBase ):
4526    " Scenario 223 "
4527
4528    def __init__( self, netschedule ):
4529        TestBase.__init__( self, netschedule )
4530        return
4531
4532    @staticmethod
4533    def getScenario():
4534        " Provides the scenario "
4535        return "GET2, CWGET, SUBMIT -> no notifications"
4536
4537    def execute( self ):
4538        " Should return True if the execution completed successfully "
4539        self.fromScratch()
4540
4541        # Spawn GET2 with waiting
4542        process = self.ns.spawnGet2Wait( 'TEST', 7,
4543                                         [], True, True,
4544                                         'node', 'session' )
4545
4546        # Sometimes it takes so long to spawn grid_cli that the next
4547        # command is sent before GET2 is sent. So, we have a sleep here
4548        time.sleep( 2 )
4549
4550        # Cancel waiting
4551        ns_client = self.getNetScheduleService( 'TEST', 'scenario223' )
4552        ns_client.set_client_identification( 'node', 'session' )
4553        execAny( ns_client, 'CWGET' )
4554        time.sleep( 1 )
4555
4556        # Submit a job
4557        self.ns.submitJob( 'TEST', 'input' )
4558
4559        process.wait()
4560        if process.returncode != 0:
4561            raise Exception( "Error spawning GET2" )
4562        processStdout = process.stdout.read().decode('utf-8')
4563        processStderr = process.stderr.read().decode('utf-8')       # analysis:ignore
4564
4565        if "[valid" in processStdout:
4566            raise Exception( "Receive notifications when not expected: " +
4567                             processStdout)
4568        return True
4569
4570class Scenario224( TestBase ):
4571    " Scenario 224 "
4572
4573    def __init__( self, netschedule ):
4574        TestBase.__init__( self, netschedule )
4575        return
4576
4577    @staticmethod
4578    def getScenario():
4579        " Provides the scenario "
4580        return " Get affinites list "
4581
4582    def execute( self ):
4583        " Should return True if the execution completed successfully "
4584        self.fromScratch()
4585
4586        ns_client = self.getNetScheduleService( 'TEST', 'scenario224' )
4587        getNotificationInfo( ns_client, False, 0 )
4588        return True
4589
4590class Scenario225( TestBase ):
4591    " Scenario 225 "
4592
4593    def __init__( self, netschedule ):
4594        TestBase.__init__( self, netschedule )
4595        return
4596
4597    @staticmethod
4598    def getScenario():
4599        " Provides the scenario "
4600        return " WGET as anonymous, check notifications registry "
4601
4602    def execute( self ):
4603        " Should return True if the execution completed successfully "
4604        self.fromScratch()
4605
4606        ns_client = self.getNetScheduleService( 'TEST', 'scenario225' )
4607        execAny( ns_client, 'WGET 5000 15' )
4608        getNotificationInfo( ns_client, False, 1, 0 )
4609        return True
4610
4611class Scenario226( TestBase ):
4612    " Scenario 226 "
4613
4614    def __init__( self, netschedule ):
4615        TestBase.__init__( self, netschedule )
4616        return
4617
4618    @staticmethod
4619    def getScenario():
4620        " Provides the scenario "
4621        return " WGET as identified, check notifications registry "
4622
4623    def execute( self ):
4624        " Should return True if the execution completed successfully "
4625        self.fromScratch()
4626
4627        ns_client = self.getNetScheduleService( 'TEST', 'scenario226' )
4628        ns_client.set_client_identification( 'mynode', 'mysession' )
4629        execAny( ns_client, 'WGET 5000 15' )
4630        getNotificationInfo( ns_client, False, 1, 0 )
4631        return True
4632
4633class Scenario227( TestBase ):
4634    " Scenario 227 "
4635
4636    def __init__( self, netschedule ):
4637        TestBase.__init__( self, netschedule )
4638        return
4639
4640    @staticmethod
4641    def getScenario():
4642        " Provides the scenario "
4643        return "WGET as identified, check notifications registry, " \
4644               "wait till timeout exceeded, check notifications registry"
4645
4646    def execute( self ):
4647        " Should return True if the execution completed successfully "
4648        self.fromScratch()
4649
4650        ns_client = self.getNetScheduleService( 'TEST', 'scenario227' )
4651        ns_client.set_client_identification( 'mynode', 'mysession' )
4652        execAny( ns_client, 'WGET 5000 5' )
4653        getNotificationInfo( ns_client, False, 1, 0 )
4654        time.sleep( 10 )
4655        getNotificationInfo( ns_client, False, 0 )
4656        return True
4657
4658class Scenario228( TestBase ):
4659    " Scenario 228 "
4660
4661    def __init__( self, netschedule ):
4662        TestBase.__init__( self, netschedule )
4663        return
4664
4665    @staticmethod
4666    def getScenario():
4667        " Provides the scenario "
4668        return "WGET as identified with wnode_aff=1, " \
4669               "check notifications registry"
4670
4671    def execute( self ):
4672        " Should return True if the execution completed successfully "
4673        self.fromScratch()
4674
4675        ns_client = self.getNetScheduleService( 'TEST', 'scenario228' )
4676        ns_client.set_client_identification( 'mynode', 'mysession' )
4677        execAny( ns_client, 'WGET 5000 5' )
4678        info = getNotificationInfo( ns_client, False, 1, 0 )
4679        if info[ 'any_job' ] != True:
4680            raise Exception( "any_job expected True" )
4681        if info [ 'active' ] != False:
4682            raise Exception( "active expected False" )
4683        if info[ 'use_preferred_affinities' ] != False:
4684            raise Exception( "use_preferred_affinities expected False" )
4685        if info[ 'recepient_address' ] != 'localhost:5000':
4686            raise Exception( "recepient_address expected 'localhost:5000'" )
4687        return True
4688
4689class Scenario229( TestBase ):
4690    " Scenario 229 "
4691
4692    def __init__( self, netschedule ):
4693        TestBase.__init__( self, netschedule )
4694        return
4695
4696    @staticmethod
4697    def getScenario():
4698        " Provides the scenario "
4699        return "WGET as identified, " \
4700               "check notifications registry"
4701
4702    def execute( self ):
4703        " Should return True if the execution completed successfully "
4704        self.fromScratch()
4705
4706        ns_client = self.getNetScheduleService( 'TEST', 'scenario229' )
4707        ns_client.set_client_identification( 'mynode', 'mysession' )
4708        execAny( ns_client, 'WGET 5010 5' )
4709        info = getNotificationInfo( ns_client, False, 1, 0 )
4710        if info[ 'any_job' ] != True:
4711            raise Exception( "any_job expected True" )
4712        if info [ 'active' ] != False:
4713            raise Exception( "active expected False" )
4714        if info[ 'client_node' ] != 'mynode':
4715            raise Exception( "client node expected 'mynode'" )
4716        if info[ 'use_preferred_affinities' ] != False:
4717            raise Exception( "use_preferred_affinities expected False" )
4718        if info[ 'recepient_address' ] != 'localhost:5010':
4719            raise Exception( "recepient_address expected 'localhost:5010'" )
4720        return True
4721
4722class Scenario230( TestBase ):
4723    " Scenario 230 "
4724
4725    def __init__( self, netschedule ):
4726        TestBase.__init__( self, netschedule )
4727        return
4728
4729    @staticmethod
4730    def getScenario():
4731        " Provides the scenario "
4732        return "WGET as identified with affinities, " \
4733               "check notifications registry"
4734
4735    def execute( self ):
4736        " Should return True if the execution completed successfully "
4737        self.fromScratch()
4738
4739        ns_client = self.getNetScheduleService( 'TEST', 'scenario230' )
4740        ns_client.set_client_identification( 'mynode', 'mysession' )
4741        execAny( ns_client, 'WGET 5010 5 aff=a1,a2' )
4742        info = getNotificationInfo( ns_client, True, 1, 0 )
4743        if info[ 'any_job' ] != False:
4744            raise Exception( "any_job expected False" )
4745        if info [ 'active' ] != False:
4746            raise Exception( "active expected False" )
4747        if info[ 'client_node' ] != 'mynode':
4748            raise Exception( "client node expected 'mynode'" )
4749        if info[ 'use_preferred_affinities' ] != False:
4750            raise Exception( "use_preferred_affinities expected False" )
4751        if info[ 'recepient_address' ] != 'localhost:5010':
4752            raise Exception( "recepient_address expected 'localhost:5010'" )
4753        if len( info[ 'explicit_affinities' ] ) != 2:
4754            raise Exception( "Expected 2 explicit affinities, received: " + \
4755                             str( len( info[ 'explicit_affinities' ] ) ) )
4756        if "a1" not in info[ 'explicit_affinities' ]:
4757            raise Exception( "a1 not found in the explicit affinities list" )
4758        if "a2" not in info[ 'explicit_affinities' ]:
4759            raise Exception( "a2 not found in the explicit affinities list" )
4760        return True
4761
4762class Scenario231( TestBase ):
4763    " Scenario 231 "
4764
4765    def __init__( self, netschedule ):
4766        TestBase.__init__( self, netschedule )
4767        return
4768
4769    @staticmethod
4770    def getScenario():
4771        " Provides the scenario "
4772        return "WGET as identified with any_aff=1, " \
4773               "check notifications registry"
4774
4775    def execute( self ):
4776        " Should return True if the execution completed successfully "
4777        self.fromScratch()
4778
4779        ns_client = self.getNetScheduleService( 'TEST', 'scenario231' )
4780        ns_client.set_client_identification( 'mynode', 'mysession' )
4781        execAny( ns_client, 'WGET 5000 5' )
4782        info = getNotificationInfo( ns_client, False, 1, 0 )
4783        if info[ 'any_job' ] != True:
4784            raise Exception( "any_job expected True" )
4785        if info [ 'active' ] != False:
4786            raise Exception( "active expected False" )
4787        if info[ 'use_preferred_affinities' ] != False:
4788            raise Exception( "use_preferred_affinities expected False" )
4789        if info[ 'recepient_address' ] != 'localhost:5000':
4790            raise Exception( "recepient_address expected 'localhost:5000'" )
4791        return True
4792
4793class Scenario232( TestBase ):
4794    " Scenario 232 "
4795
4796    def __init__( self, netschedule ):
4797        TestBase.__init__( self, netschedule )
4798        return
4799
4800    @staticmethod
4801    def getScenario():
4802        " Provides the scenario "
4803        return "WGET as identified, SUBMIT as anonymous, " \
4804               "check notifications registry"
4805
4806    def execute( self ):
4807        " Should return True if the execution completed successfully "
4808        self.fromScratch()
4809
4810        ns_client = self.getNetScheduleService( 'TEST', 'scenario232' )
4811        ns_client.set_client_identification( 'mynode', 'mysession' )
4812        execAny( ns_client, 'WGET 5000 15' )
4813        self.ns.submitJob( 'TEST', 'bla' )
4814        time.sleep( 1 )
4815        info = getNotificationInfo( ns_client, True, 1, 0 )
4816        if info[ 'any_job' ] != True:
4817            raise Exception( "any_job expected True" )
4818        if info [ 'active' ] != True:
4819            raise Exception( "active expected True" )
4820        if info[ 'use_preferred_affinities' ] != False:
4821            raise Exception( "use_preferred_affinities expected False" )
4822        if info[ 'recepient_address' ] != 'localhost:5000':
4823            raise Exception( "recepient_address expected 'localhost:5000'" )
4824        return True
4825
4826class Scenario233( TestBase ):
4827    " Scenario 233 "
4828
4829    def __init__( self, netschedule ):
4830        TestBase.__init__( self, netschedule )
4831        self.jobID = None
4832        return
4833
4834    @staticmethod
4835    def getScenario():
4836        " Provides the scenario "
4837        return " DUMP 3 jobs after the first one "
4838
4839    def execute( self ):
4840        " Should return True if the execution completed successfully "
4841        self.fromScratch()
4842
4843        jobID1 = self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', 'mysession' )
4844        self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', 'mysession' )
4845        self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', 'mysession' )
4846        self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', 'mysession' )
4847
4848        dump = self.ns.getQueueDump( 'TEST', start_after = jobID1,
4849                                     node = 'mynode', session = 'mysession' )
4850        count = 0
4851        for line in dump:
4852            if line.startswith( "key: " ):
4853                count += 1
4854        if count != 3:
4855            raise Exception( "Unexpected number of jobs in the output. " \
4856                             "Expected: 3. Received: " + str( count ) )
4857        return True
4858
4859
4860class Scenario234( TestBase ):
4861    " Scenario 234 "
4862
4863    def __init__( self, netschedule ):
4864        TestBase.__init__( self, netschedule )
4865        self.jobID = None
4866        return
4867
4868    @staticmethod
4869    def getScenario():
4870        " Provides the scenario "
4871        return " DUMP 2 jobs after the first one "
4872
4873    def execute( self ):
4874        " Should return True if the execution completed successfully "
4875        self.fromScratch()
4876
4877        jobID1 = self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', 'mysession' )
4878        self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', 'mysession' )
4879        self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', 'mysession' )
4880        self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', 'mysession' )
4881
4882        dump = self.ns.getQueueDump( 'TEST', '', jobID1, 2, '',
4883                                     'mynode', 'mysession' )
4884        count = 0
4885        for line in dump:
4886            if line.startswith( "key: " ):
4887                count += 1
4888        if count != 2:
4889            raise Exception( "Unexpected number of jobs in the output. " \
4890                             "Expected: 2. Received: " + str( count ) )
4891        return True
4892
4893class Scenario235( TestBase ):
4894    " Scenario 235 "
4895
4896    def __init__( self, netschedule ):
4897        TestBase.__init__( self, netschedule )
4898        self.jobID = None
4899        return
4900
4901    @staticmethod
4902    def getScenario():
4903        " Provides the scenario "
4904        return " DUMP 1 jobs after the first one "
4905
4906    def execute( self ):
4907        " Should return True if the execution completed successfully "
4908        self.fromScratch()
4909
4910        jobID1 = self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', 'mysession' )
4911        self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', 'mysession' )
4912        self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', 'mysession' )
4913        self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', 'mysession' )
4914
4915        dump = self.ns.getQueueDump( 'TEST', '', '', 1, '',
4916                                     'mynode', 'mysession' )
4917        count = 0
4918        jobLine = ""
4919        for line in dump:
4920            if line.startswith( "key: " ):
4921                count += 1
4922                jobLine = line
4923        if count != 1:
4924            raise Exception( "Unexpected number of jobs in the output. " \
4925                             "Expected: 1. Received: " + str( count ) )
4926        if jobLine != "key: " + jobID1:
4927            raise Exception( "Unexpected job in the dump output. " \
4928                             "Expected: 'key: " + jobID1 + \
4929                             "' Received: '" + jobLine + "'" )
4930        return True
4931
4932class Scenario236( TestBase ):
4933    " Scenario 236 "
4934
4935    def __init__( self, netschedule ):
4936        TestBase.__init__( self, netschedule )
4937        return
4938
4939    @staticmethod
4940    def getScenario():
4941        " Provides the scenario "
4942        return " DUMP 50 jobs, expect to have 2 (2 submitted) "
4943
4944    def execute( self ):
4945        " Should return True if the execution completed successfully "
4946        self.fromScratch()
4947
4948        self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', 'mysession' )
4949        self.ns.submitJob( 'TEST', 'bla', '', '', 'mynode', 'mysession' )
4950
4951        dump = self.ns.getQueueDump( 'TEST', '', '', 50, '',
4952                                     'mynode', 'mysession' )
4953        count = 0
4954        for line in dump:
4955            if line.startswith( "key: " ):
4956                count += 1
4957        if count != 2:
4958            raise Exception( "Unexpected number of jobs in the output. " \
4959                             "Expected: 2. Received: " + str( count ) )
4960        return True
4961
4962class Scenario237( TestBase ):
4963    " Scenario 237 "
4964
4965    def __init__( self, netschedule ):
4966        TestBase.__init__( self, netschedule )
4967        return
4968
4969    @staticmethod
4970    def getScenario():
4971        " Provides the scenario "
4972        return "SUBMIT as c1, GET and RETURN as c2, GET and PUT as c3, " \
4973               "READ and CFRM as c4, CANCEL as c5, DUMP and check history"
4974
4975    def execute( self ):
4976        " Should return True if the execution completed successfully "
4977        self.fromScratch()
4978
4979        # c1
4980        jobID = self.ns.submitJob( 'TEST', 'bla', '', '', 'c1', 's1' )
4981
4982        # c2
4983        jobInfo = self.ns.getJob( 'TEST', -1, '', "",
4984                                        'c2', 's2' )
4985        receivedJobID = jobInfo[ 0 ]
4986        if receivedJobID != jobID:
4987            raise Exception( "Inconsistency" )
4988        self.ns.returnJob( 'TEST', jobID, jobInfo[ 1 ], 'c2', 's2' )
4989
4990        # c3
4991        jobInfo = self.ns.getJob( 'TEST', -1, '', "", 'c3', 's3' )
4992        receivedJobID = jobInfo[ 0 ]
4993        if receivedJobID != jobID:
4994            raise Exception( "Inconsistency" )
4995        self.ns.putJob( 'TEST', jobID, jobInfo[ 1 ], 0, "", 'c3', 's3' )
4996
4997        # c4
4998        readJobID, passport = self.ns.getJobForReading( 'TEST', 'c4', 's4' )
4999        if readJobID != jobID:
5000            raise Exception( "Inconsistency" )
5001        self.ns.confirmReading( 'TEST', jobID, passport, 'c4', 's4' )
5002
5003        # c5
5004        self.ns.cancelJob( 'TEST', jobID, 'c5', 's5')
5005
5006        raise Exception( "Not implemented" )
5007
5008
5009class Scenario238( TestBase ):
5010    " Scenario 238 "
5011
5012    def __init__( self, netschedule ):
5013        TestBase.__init__( self, netschedule )
5014        return
5015
5016    @staticmethod
5017    def getScenario():
5018        " Provides the scenario "
5019        return " Get affinites list "
5020
5021    def execute( self ):
5022        " Should return True if the execution completed successfully "
5023        self.fromScratch()
5024
5025        ns_client = self.getNetScheduleService( 'TEST', 'scenario238' )
5026        getAffinityInfo( ns_client, False, 0 )
5027        return True
5028
5029class Scenario239( TestBase ):
5030    " Scenario 239 "
5031
5032    def __init__( self, netschedule ):
5033        TestBase.__init__( self, netschedule )
5034        return
5035
5036    @staticmethod
5037    def getScenario():
5038        " Provides the scenario "
5039        return " Submit job with affinity a1, get affinites list "
5040
5041    def execute( self ):
5042        " Should return True if the execution completed successfully "
5043        self.fromScratch()
5044
5045        ns_client = self.getNetScheduleService( 'TEST', 'scenario239' )
5046        self.ns.submitJob( 'TEST', 'bla', 'a1', '', 'mynode', 'mysession' )
5047
5048        aff = getAffinityInfo( ns_client, False, 1, 0 )
5049        if aff[ 'number_of_jobs' ] != 1:
5050            raise Exception( "Expected 1 job, received: " + \
5051                             str( aff[ 'number_of_jobs' ] ) )
5052        if aff[ 'affinity_token' ] != 'a1':
5053            raise Exception( "Expected aff token: a1, received: " + \
5054                             aff[ 'affinity_token' ] )
5055        if 'number_of_clients__preferred' in aff:
5056            if aff[ 'number_of_clients__preferred' ] != 0:
5057                raise Exception( "Expected 0 preferred clients, received: " +
5058                                 str( aff[ 'number_of_clients__preferred' ] ) )
5059        if 'number_of_wn_clients__preferred' in aff:
5060            if aff[ 'number_of_wn_clients__preferred' ] != 0:
5061                raise Exception( "Expected 0 preferred clients, received: " +
5062                                 str( aff[ 'number_of_wn_clients__preferred' ] ) )
5063        if aff[ 'number_of_clients__explicit_wget' ] != 0:
5064            raise Exception( "Expected 0 WGET clients, received: " + \
5065                             str( aff[ 'number_of_clients__explicit_wget' ] ) )
5066        return True
5067
5068class Scenario240( TestBase ):
5069    " Scenario 240 "
5070
5071    def __init__( self, netschedule ):
5072        TestBase.__init__( self, netschedule )
5073        return
5074
5075    @staticmethod
5076    def getScenario():
5077        " Provides the scenario "
5078        return " Submit job with affinity a1, get affinites list "
5079
5080    def execute( self ):
5081        " Should return True if the execution completed successfully "
5082        self.fromScratch()
5083
5084        ns_client = self.getNetScheduleService( 'TEST', 'scenario240' )
5085        jobID = self.ns.submitJob( 'TEST', 'bla', 'a1', '', 'mynode', 'mysession' )
5086
5087        aff = getAffinityInfo( ns_client, True, 1, 0 )
5088        if len( aff[ 'jobs' ] ) != 1:
5089            raise Exception( "Expected 1 job, received: " + \
5090                             str( len( aff[ 'jobs' ] ) ) )
5091
5092        # Starting from NS 4.17.0 a job status is also provided
5093        if ' ' in aff[ 'jobs' ][ 0 ]:
5094            affJobID = aff[ 'jobs' ][ 0 ].split()[ 0 ]
5095        else:
5096            affJobID = aff[ 'jobs' ][ 0 ]
5097        if affJobID != jobID:
5098            raise Exception( "Unexpected job for affinity. Expected: " + \
5099                             jobID + ", received: " + affJobID )
5100
5101        if aff[ 'affinity_token' ] != 'a1':
5102            raise Exception( "Expected aff token: a1, received: " + \
5103                             aff[ 'affinity_token' ] )
5104        if aff[ 'clients__explicit_wget' ] is not None:
5105            raise Exception( "Expected 0 WGET clients, received: " +
5106                             str( len( aff[ 'clients__explicit_wget' ] ) ) )
5107        if 'clients__preferred' in aff:
5108            if aff[ 'clients__preferred' ] is not None:
5109                raise Exception( "Expected 0 preferred clients, received: " +
5110                                 str( len( aff[ 'clients__preferred' ] ) ) )
5111        if 'wn_clients__preferred' in aff:
5112            if aff[ 'wn_clients__preferred' ] is not None:
5113                raise Exception( "Expected 0 wn preferred clients, received: " +
5114                                 str( len( aff[ 'wn_clients__preferred' ] ) ) )
5115        return True
5116
5117class Scenario241( TestBase ):
5118    " Scenario 241 "
5119
5120    def __init__( self, netschedule ):
5121        TestBase.__init__( self, netschedule )
5122        return
5123
5124    @staticmethod
5125    def getScenario():
5126        " Provides the scenario "
5127        return "CHAFF add=a2, STAT AFFINITIES VERBOSE"
5128
5129    def execute( self ):
5130        " Should return True if the execution completed successfully "
5131        self.fromScratch()
5132
5133        ns_client = self.getNetScheduleService( 'TEST', 'scenario241' )
5134        ns_client.set_client_identification( 'mynode', 'mysession' )
5135        changeAffinity( ns_client, [ 'a2' ], [] )
5136
5137        aff = getAffinityInfo( ns_client, True, 1, 0 )
5138        if aff[ 'affinity_token' ] != 'a2':
5139            raise Exception( "Expected aff token: a2, received: " +
5140                             aff[ 'affinity_token' ] )
5141        if aff[ 'clients__explicit_wget' ] is not None:
5142            raise Exception( "Expected 0 WGET clients, received: " +
5143                             str( len( aff[ 'clients__explicit_wget' ] ) ) )
5144        if 'clients__preferred' in aff:
5145            if len( aff[ 'clients__preferred' ] ) != 1:
5146                raise Exception( "Expected 1 preferred client, received: " +
5147                                 str( len( aff[ 'clients__preferred' ] ) ) )
5148        if 'wn_clients__preferred' in aff:
5149            if len( aff[ 'wn_clients__preferred' ] ) != 1:
5150                raise Exception( "Expected 1 preferred client, received: " +
5151                                 str( len( aff[ 'wn_clients__preferred' ] ) ) )
5152
5153        if 'clients__preferred' in aff:
5154            if aff[ 'clients__preferred' ][ 0 ] != 'mynode':
5155                raise Exception( "Unexpected preferred client. "
5156                                 "Expected 'mynode', received: '" +
5157                                 aff[ 'clients__preferred' ][ 0 ] + "'" )
5158        if 'wn_clients__preferred' in aff:
5159            if aff[ 'wn_clients__preferred' ][ 0 ] != 'mynode':
5160                raise Exception( "Unexpected preferred client. "
5161                                 "Expected 'mynode', received: '" +
5162                                 aff[ 'wn_clients__preferred' ][ 0 ] + "'" )
5163        return True
5164
5165class Scenario242( TestBase ):
5166    " Scenario 242 "
5167
5168    def __init__( self, netschedule ):
5169        TestBase.__init__( self, netschedule )
5170        return
5171
5172    @staticmethod
5173    def getScenario():
5174        " Provides the scenario "
5175        return "CHAFF del=a3, STAT AFFINITIES VERBOSE"
5176
5177    def execute( self ):
5178        " Should return True if the execution completed successfully "
5179        self.fromScratch()
5180
5181        ns_client = self.getNetScheduleService( 'TEST', 'scenario242' )
5182        ns_client.set_client_identification( 'mynode', 'mysession' )
5183        ns_client.on_warning = None
5184
5185        changeAffinity( ns_client, [], [ 'a3' ] )
5186
5187        getAffinityInfo( ns_client, True, 0, 0 )
5188        return True
5189
5190class Scenario243( TestBase ):
5191    " Scenario 243 "
5192
5193    def __init__( self, netschedule ):
5194        TestBase.__init__( self, netschedule )
5195        return
5196
5197    @staticmethod
5198    def getScenario():
5199        " Provides the scenario "
5200        return "CHAFF add=a4, CHAFF del=a4, STAT AFFINITIES VERBOSE"
5201
5202    def execute( self ):
5203        " Should return True if the execution completed successfully "
5204        self.fromScratch()
5205
5206        ns_client = self.getNetScheduleService( 'TEST', 'scenario243' )
5207        ns_client.set_client_identification( 'mynode', 'mysession' )
5208        changeAffinity( ns_client, [ 'a4' ], [] )
5209        changeAffinity( ns_client, [], [ 'a4' ] )
5210
5211        aff = getAffinityInfo( ns_client, True, 1, 0 )
5212        if aff[ 'jobs' ] is not None:
5213            raise Exception( "Expected no jobs, received: " +
5214                             str( len( aff[ 'jobs' ] ) ) )
5215
5216        if aff[ 'affinity_token' ] != 'a4':
5217            raise Exception( "Expected aff token: a4, received: " +
5218                             aff[ 'affinity_token' ] )
5219        if aff[ 'clients__explicit_wget' ] is not None:
5220            raise Exception( "Expected 0 WGET clients, received: " +
5221                             str( len( aff[ 'clients__explicit_wget' ] ) ) )
5222        if 'clients__preferred' in aff:
5223            if aff[ 'clients__preferred' ] is not None:
5224                raise Exception( "Expected 0 preferred clients, received: " +
5225                                 str( len( aff[ 'clients__preferred' ] ) ) )
5226        if 'wn_clients__preferred' in aff:
5227            if aff[ 'wn_clients__preferred' ] is not None:
5228                raise Exception( "Expected 0 preferred clients, received: " +
5229                                 str( len( aff[ 'wn_clients__preferred' ] ) ) )
5230        return True
5231
5232class Scenario244( TestBase ):
5233    " Scenario 244 "
5234
5235    def __init__( self, netschedule ):
5236        TestBase.__init__( self, netschedule )
5237        return
5238
5239    @staticmethod
5240    def getScenario():
5241        " Provides the scenario "
5242        return " WGET a job with affinity a5, " \
5243               "get affinites list "
5244
5245    def execute( self ):
5246        " Should return True if the execution completed successfully "
5247        self.fromScratch()
5248
5249        ns_client = self.getNetScheduleService( 'TEST', 'scenario244' )
5250        ns_client.set_client_identification( 'mynode', 'mysession' )
5251
5252        execAny( ns_client, 'WGET 5000 10 aff=a5' )
5253        aff = getAffinityInfo( ns_client, True, 1, 0 )
5254        if aff[ 'affinity_token' ] != 'a5':
5255            raise Exception( "Expected aff token: a5, received: " +
5256                             aff[ 'affinity_token' ] )
5257        if aff[ 'jobs' ] is not None:
5258            raise Exception( "Expected 0 job, received: " +
5259                             str( len( aff[ 'jobs' ] ) ) )
5260        if len( aff[ 'clients__explicit_wget' ] ) != 1:
5261            raise Exception( "Expected 1 WGET clients, received: " +
5262                             str( len( aff[ 'clients__explicit_wget' ] ) ) )
5263        if aff[ 'clients__explicit_wget' ][ 0 ] != 'mynode':
5264            raise Exception( "Expected explicit client 'mynode', received: " +
5265                             aff[ 'clients__explicit_wget' ][ 0 ] )
5266        if 'clients__preferred' in aff:
5267            if aff[ 'clients__preferred' ] is not None:
5268                raise Exception( "Expected 0 preferred clients, received: " +
5269                                 str( len( aff[ 'clients__preferred' ] ) ) )
5270        if 'wn_clients__preferred' in aff:
5271            if aff[ 'wn_clients__preferred' ] is not None:
5272                raise Exception( "Expected 0 preferred clients, received: " +
5273                                 str( len( aff[ 'wn_clients__preferred' ] ) ) )
5274        return True
5275
5276class Scenario245( TestBase ):
5277    " Scenario 245 "
5278
5279    def __init__( self, netschedule ):
5280        TestBase.__init__( self, netschedule )
5281        return
5282
5283    @staticmethod
5284    def getScenario():
5285        " Provides the scenario "
5286        return " WGET a job with affinity a6, " \
5287               "wait till timeout, get affinites list "
5288
5289    def execute( self ):
5290        " Should return True if the execution completed successfully "
5291        self.fromScratch()
5292
5293        ns_client = self.getNetScheduleService( 'TEST', 'scenario245' )
5294
5295        self.ns.getJob( 'TEST', 10, 'a6', '', 'mynode', 'mysession' )
5296        time.sleep( 5 )
5297
5298        aff = getAffinityInfo( ns_client, True, 1, 0 )
5299        if aff[ 'affinity_token' ] != 'a6':
5300            raise Exception( "Expected aff token: a6, received: " +
5301                             aff[ 'affinity_token' ] )
5302        if aff[ 'jobs' ] is not None:
5303            raise Exception( "Expected 0 job, received: " +
5304                             str( len( aff[ 'jobs' ] ) ) )
5305        if aff[ 'clients__explicit_wget' ] is not None:
5306            raise Exception( "Expected 0 WGET clients, received: " +
5307                             str( len( aff[ 'clients__explicit_wget' ] ) ) )
5308        if 'clients__preferred' in aff:
5309            if aff[ 'clients__preferred' ] is not None:
5310                raise Exception( "Expected 0 preferred clients, received: " +
5311                                 str( len( aff[ 'clients__preferred' ] ) ) )
5312        if 'wn_clients__preferred' in aff:
5313            if aff[ 'wn_clients__preferred' ] is not None:
5314                raise Exception( "Expected 0 preferred clients, received: " +
5315                                 str( len( aff[ 'wn_clients__preferred' ] ) ) )
5316        return True
5317
5318class Scenario246( TestBase ):
5319    " Scenario 246 "
5320
5321    def __init__( self, netschedule ):
5322        TestBase.__init__( self, netschedule )
5323        return
5324
5325    @staticmethod
5326    def getScenario():
5327        " Provides the scenario "
5328        return "GET2 as anonymous"
5329
5330    def execute( self ):
5331        " Should return True if the execution completed successfully "
5332        self.fromScratch()
5333
5334        ns_client = self.getNetScheduleService( 'TEST', 'scenario246' )
5335        try:
5336            ns_client.set_client_identification( '', '' )
5337        except:
5338            pass
5339
5340        try:
5341            execAny( ns_client,
5342                     'GET2 wnode_aff=0 any_aff=1' )
5343        except Exception as exc:
5344            if "Anonymous client" in str( exc ):
5345                return True
5346            raise
5347        return False
5348
5349class Scenario247( TestBase ):
5350    " Scenario 247 "
5351
5352    def __init__( self, netschedule ):
5353        TestBase.__init__( self, netschedule )
5354        return
5355
5356    @staticmethod
5357    def getScenario():
5358        " Provides the scenario "
5359        return "PUT2 as anonymous"
5360
5361    def execute( self ):
5362        " Should return True if the execution completed successfully "
5363        self.fromScratch()
5364
5365        ns_client = self.getNetScheduleService( 'TEST', 'scenario247' )
5366        try:
5367            ns_client.set_client_identification( '', '' )
5368        except:
5369            pass
5370
5371        try:
5372            execAny( ns_client, 'PUT2 ' + NON_EXISTED_JOB + ' passport 0 77' )
5373        except Exception as exc:
5374            if "Anonymous client" in str( exc ):
5375                return True
5376            raise
5377        return False
5378
5379class Scenario248( TestBase ):
5380    " Scenario 248 "
5381
5382    def __init__( self, netschedule ):
5383        TestBase.__init__( self, netschedule )
5384        return
5385
5386    @staticmethod
5387    def getScenario():
5388        " Provides the scenario "
5389        return "FPUT2 as anonymous"
5390
5391    def execute( self ):
5392        " Should return True if the execution completed successfully "
5393        self.fromScratch()
5394
5395        ns_client = self.getNetScheduleService( 'TEST', 'scenario248' )
5396        try:
5397            ns_client.set_client_identification( '', '' )
5398        except:
5399            pass
5400
5401        try:
5402            execAny( ns_client, 'FPUT2 ' + NON_EXISTED_JOB + ' passport err_msg out 1' )
5403        except Exception as exc:
5404            if "Anonymous client" in str( exc ):
5405                return True
5406            raise
5407        return False
5408
5409class Scenario249( TestBase ):
5410    " Scenario 249 "
5411
5412    def __init__( self, netschedule ):
5413        TestBase.__init__( self, netschedule )
5414        return
5415
5416    @staticmethod
5417    def getScenario():
5418        " Provides the scenario "
5419        return "RETURN2 as anonymous"
5420
5421    def execute( self ):
5422        " Should return True if the execution completed successfully "
5423        self.fromScratch()
5424
5425        ns_client = self.getNetScheduleService( 'TEST', 'scenario249' )
5426        try:
5427            ns_client.set_client_identification( '', '' )
5428        except:
5429            pass
5430
5431        try:
5432            execAny( ns_client, 'RETURN2 ' + NON_EXISTED_JOB + ' passport' )
5433        except Exception as exc:
5434            if "Anonymous client" in str( exc ):
5435                return True
5436            raise
5437        return False
5438
5439class Scenario251( TestBase ):
5440    " Scenario 251 "
5441
5442    def __init__( self, netschedule ):
5443        TestBase.__init__( self, netschedule )
5444        return
5445
5446    @staticmethod
5447    def getScenario():
5448        " Provides the scenario "
5449        return "SUBMIT, GET2 as identified, check passport"
5450
5451    def execute( self ):
5452        " Should return True if the execution completed successfully "
5453        self.fromScratch()
5454
5455        jobID = self.ns.submitJob(  'TEST', 'bla', '', '', 'node', '000' )
5456        ns_client = self.getNetScheduleService( 'TEST', 'scenario251' )
5457        ns_client.set_client_identification( 'mynode', 'mysession' )
5458        output = execAny( ns_client,
5459                          'GET2 wnode_aff=0 any_aff=1' )
5460        if '&' in output:
5461            values = parse_qs( output, True, True )
5462            receivedJobID = values[ 'job_key' ][ 0 ]
5463            passport = values[ 'auth_token' ][ 0 ]
5464        else:
5465            receivedJobID = output.split()[ 0 ].strip()
5466            passport = output.split( '"' )[ -1 ].strip().split()[ -1 ].strip()
5467
5468        if jobID != receivedJobID:
5469            raise Exception( "Inconsistency" )
5470
5471        if passport == "" or '_' not in passport:
5472            raise Exception( "Unexpected passport - empty or wrong format" )
5473        return True
5474
5475class Scenario252( TestBase ):
5476    " Scenario 252 "
5477
5478    def __init__( self, netschedule ):
5479        TestBase.__init__( self, netschedule )
5480        return
5481
5482    @staticmethod
5483    def getScenario():
5484        " Provides the scenario "
5485        return "SUBMIT, GET2, PUT2 as identified, check the job status"
5486
5487    def execute( self ):
5488        " Should return True if the execution completed successfully "
5489        self.fromScratch()
5490
5491        jobID = self.ns.submitJob(  'TEST', 'bla', '', '', 'node', '000' )
5492        ns_client = self.getNetScheduleService( 'TEST', 'scenario252' )
5493        ns_client.set_client_identification( 'mynode', 'mysession' )
5494        output = execAny( ns_client,
5495                          'GET2 wnode_aff=0 any_aff=1' )
5496        if '&' in output:
5497            values = parse_qs( output, True, True )
5498            receivedJobID = values[ 'job_key' ][ 0 ]
5499            passport = values[ 'auth_token' ][ 0 ]
5500        else:
5501            receivedJobID = output.split()[ 0 ].strip()
5502            passport = output.split( '"' )[ -1 ].strip().split()[ -1 ].strip()
5503
5504        if jobID != receivedJobID:
5505            raise Exception( "Inconsistency" )
5506
5507        execAny( ns_client, 'PUT2 ' + jobID + ' ' + passport + ' 0 output' )
5508
5509        # Check the status
5510        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
5511        status2 = self.ns.getJobStatus( 'TEST', jobID )
5512
5513        info = self.ns.getJobInfo( 'TEST', jobID )
5514        status3 = info[ "status" ]
5515
5516        if status1 != "Done" or \
5517           status2 != "Done" or \
5518           status3 != "Done":
5519            return False
5520        return True
5521
5522class Scenario253( TestBase ):
5523    " Scenario 253 "
5524
5525    def __init__( self, netschedule ):
5526        TestBase.__init__( self, netschedule )
5527        return
5528
5529    @staticmethod
5530    def getScenario():
5531        " Provides the scenario "
5532        return "SUBMIT, GET2, FPUT2 as identified, check the job status"
5533
5534    def execute( self ):
5535        " Should return True if the execution completed successfully "
5536        self.fromScratch()
5537
5538        jobID = self.ns.submitJob(  'TEST', 'bla', '', '', 'node', '000' )
5539        ns_client = self.getNetScheduleService( 'TEST', 'scenario253' )
5540        ns_client.set_client_identification( 'mynode', 'mysession' )
5541        output = execAny( ns_client,
5542                          'GET2 wnode_aff=0 any_aff=1' )
5543        if '&' in output:
5544            values = parse_qs( output, True, True )
5545            receivedJobID = values[ 'job_key' ][ 0 ]
5546            passport = values[ 'auth_token' ][ 0 ]
5547        else:
5548            receivedJobID = output.split()[ 0 ].strip()
5549            passport = output.split( '"' )[ -1 ].strip().split()[ -1 ].strip()
5550
5551        if jobID != receivedJobID:
5552            raise Exception( "Inconsistency" )
5553
5554        execAny( ns_client, 'FPUT2 ' + jobID + ' ' + passport + ' ' + \
5555                            'ErrMsg Output 2' )
5556
5557        # Check the status
5558        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
5559        status2 = self.ns.getJobStatus( 'TEST', jobID )
5560
5561        info = self.ns.getJobInfo( 'TEST', jobID )
5562        status3 = info[ "status" ]
5563
5564        if status1 != "Pending" or \
5565           status2 != "Pending" or \
5566           status3 != "Pending":
5567            return False
5568        return True
5569
5570class Scenario254( TestBase ):
5571    " Scenario 254 "
5572
5573    def __init__( self, netschedule ):
5574        TestBase.__init__( self, netschedule )
5575        return
5576
5577    @staticmethod
5578    def getScenario():
5579        " Provides the scenario "
5580        return "SUBMIT, GET2, RETURN2 as identified, check the job status"
5581
5582    def execute( self ):
5583        " Should return True if the execution completed successfully "
5584        self.fromScratch()
5585
5586        jobID = self.ns.submitJob(  'TEST', 'bla', '', '', 'node', '000' )
5587        ns_client = self.getNetScheduleService( 'TEST', 'scenario254' )
5588        ns_client.set_client_identification( 'mynode', 'mysession' )
5589        output = execAny( ns_client,
5590                          'GET2 wnode_aff=0 any_aff=1' )
5591        if '&' in output:
5592            values = parse_qs( output, True, True )
5593            receivedJobID = values[ 'job_key' ][ 0 ]
5594            passport = values[ 'auth_token' ][ 0 ]
5595        else:
5596            receivedJobID = output.split()[ 0 ].strip()
5597            passport = output.split( '"' )[ -1 ].strip().split()[ -1 ].strip()
5598
5599        if jobID != receivedJobID:
5600            raise Exception( "Inconsistency" )
5601
5602        execAny( ns_client, 'RETURN2 ' + jobID + ' ' + passport )
5603
5604        # Check the status
5605        status1 = self.ns.getFastJobStatus( 'TEST', jobID )
5606        status2 = self.ns.getJobStatus( 'TEST', jobID )
5607
5608        info = self.ns.getJobInfo( 'TEST', jobID )
5609        status3 = info[ "status" ]
5610
5611        if status1 != "Pending" or \
5612           status2 != "Pending" or \
5613           status3 != "Pending":
5614            return False
5615        return True
5616
5617class Scenario256( TestBase ):
5618    " Scenario 256 "
5619
5620    def __init__( self, netschedule ):
5621        TestBase.__init__( self, netschedule )
5622        return
5623
5624    @staticmethod
5625    def getScenario():
5626        " Provides the scenario "
5627        return "GET2, STAT NOTIFICATIONS"
5628
5629    def execute( self ):
5630        " Should return True if the execution completed successfully "
5631        self.fromScratch()
5632
5633        # Spawn GET2 with waiting
5634        process = self.ns.spawnGet2Wait( 'TEST', 5,
5635                                         [], False, True,
5636                                         'node', 'session' )
5637
5638        # Sometimes it takes so long to spawn grid_cli that the next
5639        # command is sent before GET2 is sent. So, we have a sleep here
5640        time.sleep( 2 )
5641
5642        # STAT NOTIFICATIONS
5643        ns_client = self.getNetScheduleService( 'TEST', 'scenario227' )
5644        info = getNotificationInfo( ns_client, True, 1, 0 )
5645        process.wait()
5646
5647        if info[ "use_preferred_affinities" ] != False:
5648            raise Exception( "Unexpected use_preferred_affinities" )
5649        if info[ "any_job" ] != True:
5650            raise Exception( "Unexpected any_job" )
5651        if info[ "slow_rate_active" ] != False:
5652            raise Exception( "Unexpected slow_rate_active" )
5653        if info[ 'active' ] != False:
5654            raise Exception( "Unexpected active" )
5655
5656        return True
5657
5658class Scenario257( TestBase ):
5659    " Scenario 257 "
5660
5661    def __init__( self, netschedule ):
5662        TestBase.__init__( self, netschedule )
5663        return
5664
5665    @staticmethod
5666    def getScenario():
5667        " Provides the scenario "
5668        return "STAT GROUPS"
5669
5670    def execute( self ):
5671        " Should return True if the execution completed successfully "
5672        self.fromScratch()
5673
5674        ns_client = self.getNetScheduleService( 'TEST', 'scenario257' )
5675        output = execAny( ns_client, 'STAT GROUPS' ).strip()
5676        if output != "END":
5677            raise Exception( "Expected no groups, received some" )
5678        return True
5679
5680class Scenario258( TestBase ):
5681    " Scenario 258 "
5682
5683    def __init__( self, netschedule ):
5684        TestBase.__init__( self, netschedule )
5685        return
5686
5687    @staticmethod
5688    def getScenario():
5689        " Provides the scenario "
5690        return "SUBMIT with group=000, STAT GROUPS"
5691
5692    def execute( self ):
5693        " Should return True if the execution completed successfully "
5694        self.fromScratch()
5695
5696        self.ns.submitJob( 'TEST', 'bla', "", "000", "", "" )
5697        ns_client = self.getNetScheduleService( 'TEST', 'scenario258' )
5698        info = getGroupInfo( ns_client, False, 1, 0 )
5699        if info[ 'group' ] != '000':
5700            raise Exception( "Unexpected group" )
5701        if info[ 'number_of_jobs' ] != 1:
5702            raise Exception( "Unexpected number of jobs in the group" )
5703        return True
5704
5705class Scenario259( TestBase ):
5706    " Scenario 259 "
5707
5708    def __init__( self, netschedule ):
5709        TestBase.__init__( self, netschedule )
5710        return
5711
5712    @staticmethod
5713    def getScenario():
5714        " Provides the scenario "
5715        return "BSUB 2 jobs with group=kt312a, STAT GROUPS"
5716
5717    def execute( self ):
5718        " Should return True if the execution completed successfully "
5719        self.fromScratch()
5720
5721        self.ns.connect( 10 )
5722        self.ns.directLogin( 'TEST' )
5723        self.ns.directSendCmd( 'BSUB group=kt312a' )
5724        reply = self.ns.directReadSingleReply()
5725        if reply[ 0 ] != True or reply[ 1 ] != "Batch submit ready":
5726            self.ns.disconnect()
5727            raise Exception( "BSUB error" )
5728
5729        self.ns.directSendCmd( 'BTCH 2' )
5730        self.ns.directSendCmd( 'bla1' )
5731        self.ns.directSendCmd( 'bla2' )
5732        self.ns.directSendCmd( 'ENDB' )
5733        self.ns.directSendCmd( 'ENDS' )
5734        reply = self.ns.directReadSingleReply()
5735        self.ns.disconnect()
5736
5737        ns_client = self.getNetScheduleService( 'TEST', 'scenario259' )
5738        info = getGroupInfo( ns_client, False, 1, 0 )
5739        if info[ 'group' ] != 'kt312a':
5740            raise Exception( "Unexpected group" )
5741        if info[ 'number_of_jobs' ] != 2:
5742            raise Exception( "Unexpected number of jobs in the group" )
5743        return True
5744
5745class Scenario260( TestBase ):
5746    " Scenario 260 "
5747
5748    def __init__( self, netschedule ):
5749        TestBase.__init__( self, netschedule )
5750        return
5751
5752    @staticmethod
5753    def getScenario():
5754        " Provides the scenario "
5755        return "SUBMIT with group=gita, BSUB 2 jobs with group=gita, " \
5756               "STAT GROUPS"
5757
5758    def execute( self ):
5759        " Should return True if the execution completed successfully "
5760        self.fromScratch()
5761        jobID = self.ns.submitJob(  'TEST', 'bla', '', 'gita', '', '' )     # analysis:ignore
5762
5763        self.ns.connect( 10 )
5764        self.ns.directLogin( 'TEST' )
5765        self.ns.directSendCmd( 'BSUB group=gita' )
5766        reply = self.ns.directReadSingleReply()
5767        if reply[ 0 ] != True or reply[ 1 ] != "Batch submit ready":
5768            self.ns.disconnect()
5769            raise Exception( "BSUB error" )
5770
5771        self.ns.directSendCmd( 'BTCH 2' )
5772        self.ns.directSendCmd( 'bla1' )
5773        self.ns.directSendCmd( 'bla2' )
5774        self.ns.directSendCmd( 'ENDB' )
5775        self.ns.directSendCmd( 'ENDS' )
5776        reply = self.ns.directReadSingleReply()
5777        self.ns.disconnect()
5778
5779        ns_client = self.getNetScheduleService( 'TEST', 'scenario260' )
5780        info = getGroupInfo( ns_client, False, 1, 0 )
5781        if info[ 'group' ] != 'gita':
5782            raise Exception( "Unexpected group" )
5783        if info[ 'number_of_jobs' ] != 3:
5784            raise Exception( "Unexpected number of jobs in the group" )
5785        return True
5786
5787class Scenario261( TestBase ):
5788    " Scenario 261 "
5789
5790    def __init__( self, netschedule ):
5791        TestBase.__init__( self, netschedule )
5792        return
5793
5794    @staticmethod
5795    def getScenario():
5796        " Provides the scenario "
5797        return "SUBMIT with group=0xFF, CANCEL the job, " \
5798               "STAT GROUPS, wait till jobs are wiped out, STAT GROUPS"
5799
5800    def execute( self ):
5801        " Should return True if the execution completed successfully "
5802        self.fromScratch()
5803
5804        jobID = self.ns.submitJob(  'TEST', 'bla', '', '0xFF', '', '' )
5805        ns_client = self.getNetScheduleService( 'TEST', 'scenario261' )
5806        info = getGroupInfo( ns_client, False, 1, 0 )
5807        if info[ 'group' ] != '0xFF':
5808            raise Exception( "Unexpected group" )
5809        if info[ 'number_of_jobs' ] != 1:
5810            raise Exception( "Unexpected number of jobs in the group" )
5811
5812        self.ns.cancelJob( 'TEST', jobID )
5813        time.sleep( 40 )
5814
5815        info = getGroupInfo( ns_client, False, 0, 0 )
5816        return True
5817
5818class Scenario262( TestBase ):
5819    " Scenario 262 "
5820
5821    def __init__( self, netschedule ):
5822        TestBase.__init__( self, netschedule )
5823        return
5824
5825    @staticmethod
5826    def getScenario():
5827        " Provides the scenario "
5828        return "SUBMIT 3 jobs with group=111, GET 2 jobs, " \
5829               "PUT 1 job, STAT JOBS group=111"
5830
5831    def execute( self ):
5832        " Should return True if the execution completed successfully "
5833        self.fromScratch()
5834        jobID1 = self.ns.submitJob(  'TEST', 'bla', '', '111', '', '' ) # analysis:ignore
5835        jobID2 = self.ns.submitJob(  'TEST', 'bla', '', '111', '', '' ) # analysis:ignore
5836        jobID3 = self.ns.submitJob(  'TEST', 'bla', '', '111', '', '' ) # analysis:ignore
5837
5838        j1 = self.ns.getJob( 'TEST' )
5839        self.ns.getJob( 'TEST' )
5840
5841        self.ns.putJob( 'TEST', j1[ 0 ], j1[ 1 ], 0 )
5842
5843        ns_client = self.getNetScheduleService( 'TEST', 'scenario262' )
5844
5845        info = ns_client.get_job_counters( None, "111" )
5846        if info[ 'Confirmed' ] != 0:
5847            raise Exception( "Unexpected number of confirmed jobs" )
5848        if info[ 'Total' ] != 3:
5849            raise Exception( "Unexpected number of total jobs" )
5850        if info[ 'Failed' ] !=  0:
5851            raise Exception( "Unexpected number of failed jobs" )
5852        if info[ 'ReadFailed' ] != 0:
5853            raise Exception( "Unexpected number of read failed jobs" )
5854        if info[ 'Canceled' ] != 0:
5855            raise Exception( "Unexpected number of canceled jobs" )
5856        if info[ 'Running' ] != 1:
5857            raise Exception( "Unexpected number of running jobs" )
5858        if info[ 'Done' ] != 1:
5859            raise Exception( "Unexpected number of done jobs" )
5860        if info[ 'Reading' ] != 0:
5861            raise Exception( "Unexpected number of reading jobs" )
5862        if info[ 'Pending' ] != 1:
5863            raise Exception( "Unexpected number of pending jobs" )
5864        return True
5865
5866class Scenario263( TestBase ):
5867    " Scenario 263 "
5868
5869    def __init__( self, netschedule ):
5870        TestBase.__init__( self, netschedule )
5871        return
5872
5873    @staticmethod
5874    def getScenario():
5875        " Provides the scenario "
5876        return "SUBMIT 1 job with group=222, CANCEL group=222, " \
5877               "STAT JOBS group=222"
5878
5879    def execute( self ):
5880        " Should return True if the execution completed successfully "
5881        self.fromScratch()
5882        jobID = self.ns.submitJob(  'TEST', 'bla', '', '222', '', '' )  # analysis:ignore
5883        self.ns.cancelGroup( 'TEST', '222' )
5884
5885        ns_client = self.getNetScheduleService( 'TEST', 'scenario263' )
5886
5887        info = ns_client.get_job_counters( None, "222" )
5888        if info[ 'Confirmed' ] != 0:
5889            raise Exception( "Unexpected number of confirmed jobs" )
5890        if info[ 'Total' ] != 1:
5891            raise Exception( "Unexpected number of total jobs" )
5892        if info[ 'Failed' ] !=  0:
5893            raise Exception( "Unexpected number of failed jobs" )
5894        if info[ 'ReadFailed' ] != 0:
5895            raise Exception( "Unexpected number of read failed jobs" )
5896        if info[ 'Canceled' ] != 1:
5897            raise Exception( "Unexpected number of canceled jobs" )
5898        if info[ 'Running' ] != 0:
5899            raise Exception( "Unexpected number of running jobs" )
5900        if info[ 'Done' ] != 0:
5901            raise Exception( "Unexpected number of done jobs" )
5902        if info[ 'Reading' ] != 0:
5903            raise Exception( "Unexpected number of reading jobs" )
5904        if info[ 'Pending' ] != 0:
5905            raise Exception( "Unexpected number of pending jobs" )
5906        return True
5907
5908class Scenario264( TestBase ):
5909    " Scenario 264 "
5910
5911    def __init__( self, netschedule ):
5912        TestBase.__init__( self, netschedule )
5913        return
5914
5915    @staticmethod
5916    def getScenario():
5917        " Provides the scenario "
5918        return "SUBMIT 1 job with group=222, SUBMIT 1 job with group=333, " \
5919               "GET a job, PUT the job, READ group=333, READ group=222"
5920
5921    def report_warning( self, msg, server ):
5922        " Callback to report a warning "
5923        self.warning = msg
5924
5925    def execute( self ):
5926        " Should return True if the execution completed successfully "
5927        self.fromScratch()
5928        jobID1 = self.ns.submitJob(  'TEST', 'bla', '', '222', '', '' )
5929        self.ns.submitJob(  'TEST', 'bla', '', '333', '', '' )
5930
5931        j1 = self.ns.getJob( 'TEST' )
5932        self.ns.putJob( 'TEST', j1[ 0 ], j1[ 1 ], 0 )
5933
5934        ns_client = self.getNetScheduleService( 'TEST', 'scenario264' )
5935        ns_client.set_client_identification( 'node', 'session' )
5936        ns_client.on_warning = self.report_warning
5937
5938        output = execAny( ns_client, 'READ group=333' )
5939        if output != "" and output != "no_more_jobs=false":
5940            raise Exception( "Expected no job, received: " + output )
5941
5942        output = execAny( ns_client, 'READ group=222' )
5943        values = parse_qs( output, True, True )
5944        receivedJobID = values[ 'job_key' ][ 0 ]
5945        if receivedJobID != jobID1:
5946            raise Exception( "Expected: " + jobID1 + ", got: " + output )
5947        return True
5948
5949class Scenario265( TestBase ):
5950    " Scenario 265 "
5951
5952    def __init__( self, netschedule ):
5953        TestBase.__init__( self, netschedule )
5954        return
5955
5956    @staticmethod
5957    def getScenario():
5958        " Provides the scenario "
5959        return "SUBMIT 1 job with group=444, SUBMIT 1 job with group=555, " \
5960               "DUMP group=555"
5961
5962    def execute( self ):
5963        " Should return True if the execution completed successfully "
5964        self.fromScratch()
5965
5966        jobID1 = self.ns.submitJob(  'TEST', 'bla', '', '444', '', '' ) # analysis:ignore
5967        jobID2 = self.ns.submitJob(  'TEST', 'bla', '', '555', '', '' ) # analysis:ignore
5968
5969        dump = self.ns.getQueueDump( 'TEST', '', '', 0, '555', '', '' )
5970        if "group: 2 ('555')" in dump:
5971            return True
5972        raise Exception( "DUMP did not provide the expected group 555" )
5973
5974class Scenario266( TestBase ):
5975    " Scenario 266 "
5976
5977    def __init__( self, netschedule ):
5978        TestBase.__init__( self, netschedule )
5979        self.warning = ""
5980        return
5981
5982    @staticmethod
5983    def getScenario():
5984        " Provides the scenario "
5985        return "DUMP group=777"
5986
5987    def report_warning( self, msg, server ):
5988        " Just ignore it "
5989        self.warning = msg
5990        return
5991
5992    def execute( self ):
5993        " Should return True if the execution completed successfully "
5994        self.fromScratch()
5995
5996        ns_client = self.getNetScheduleService( 'TEST', 'scenario266' )
5997        ns_client.on_warning = self.report_warning
5998        output = execAny( ns_client, 'DUMP group=777', 0, True )
5999        if output:
6000            raise Exception( "Expected no output, received: " + str( output ) )
6001        return True
6002
6003class Scenario267( TestBase ):
6004    " Scenario 267 "
6005
6006    def __init__( self, netschedule ):
6007        TestBase.__init__( self, netschedule )
6008        return
6009
6010    @staticmethod
6011    def getScenario():
6012        " Provides the scenario "
6013        return "SUBMIT 4 jobs with all combinations of " \
6014               "aff a1,a2 and groups g1,g2, STAT JOBS aff=a2, " \
6015               "STAT JOBS aff=a2 group=g2"
6016
6017    def execute( self ):
6018        " Should return True if the execution completed successfully "
6019        self.fromScratch()
6020        jobID1 = self.ns.submitJob(  'TEST', 'bla', 'a1', 'g1', '', '' )    # analysis:ignore
6021        jobID2 = self.ns.submitJob(  'TEST', 'bla', 'a1', 'g2', '', '' )    # analysis:ignore
6022        jobID3 = self.ns.submitJob(  'TEST', 'bla', 'a2', 'g1', '', '' )    # analysis:ignore
6023        jobID4 = self.ns.submitJob(  'TEST', 'bla', 'a2', 'g2', '', '' )    # analysis:ignore
6024
6025        ns_client = self.getNetScheduleService( 'TEST', 'scenario267' )
6026
6027        info = ns_client.get_job_counters( 'a2', None )
6028        if info[ 'Confirmed' ] != 0:
6029            raise Exception( "Unexpected number of confirmed jobs" )
6030        if info[ 'Total' ] != 2:
6031            raise Exception( "Unexpected number of total jobs" )
6032        if info[ 'Failed' ] !=  0:
6033            raise Exception( "Unexpected number of failed jobs" )
6034        if info[ 'ReadFailed' ] != 0:
6035            raise Exception( "Unexpected number of read failed jobs" )
6036        if info[ 'Canceled' ] != 0:
6037            raise Exception( "Unexpected number of canceled jobs" )
6038        if info[ 'Running' ] != 0:
6039            raise Exception( "Unexpected number of running jobs" )
6040        if info[ 'Done' ] != 0:
6041            raise Exception( "Unexpected number of done jobs" )
6042        if info[ 'Reading' ] != 0:
6043            raise Exception( "Unexpected number of reading jobs" )
6044        if info[ 'Pending' ] != 2:
6045            raise Exception( "Unexpected number of pending jobs" )
6046
6047        info = ns_client.get_job_counters( 'a2', 'g2' )
6048        if info[ 'Confirmed' ] != 0:
6049            raise Exception( "Unexpected number of confirmed jobs" )
6050        if info[ 'Total' ] != 1:
6051            raise Exception( "Unexpected number of total jobs" )
6052        if info[ 'Failed' ] !=  0:
6053            raise Exception( "Unexpected number of failed jobs" )
6054        if info[ 'ReadFailed' ] != 0:
6055            raise Exception( "Unexpected number of read failed jobs" )
6056        if info[ 'Canceled' ] != 0:
6057            raise Exception( "Unexpected number of canceled jobs" )
6058        if info[ 'Running' ] != 0:
6059            raise Exception( "Unexpected number of running jobs" )
6060        if info[ 'Done' ] != 0:
6061            raise Exception( "Unexpected number of done jobs" )
6062        if info[ 'Reading' ] != 0:
6063            raise Exception( "Unexpected number of reading jobs" )
6064        if info[ 'Pending' ] != 1:
6065            raise Exception( "Unexpected number of pending jobs" )
6066        return True
6067