@@ -502,20 +502,111 @@ def test_generate_multi_disk(self):
502502 self .assertTrue (data .get ('blockDevices' ))
503503 self .assertEqual (data ['blockDevices' ], assert_data ['blockDevices' ])
504504
505+ @patch ('SoftLayer.managers.cci.CCIManager.wait_for_ready' )
506+ def test_wait (self , ready ):
507+ # verify interface to wait_for_ready is intact
508+ self .cci .wait_for_transaction (1 , 1 )
509+ ready .assert_called_once_with (1 , 1 , delay = 1 , pending = True )
510+
511+ def test_ready_permutations (self ):
512+ guestObject = self .client ['Virtual_Guest' ].getObject
513+
514+ # active transaction and no provision date should be false
515+ guestObject .side_effect = [
516+ {'activeTransaction' : {'id' : 1 }},
517+ ]
518+ value = self .cci .wait_for_ready (1 , 1 )
519+ self .assertFalse (value )
520+ guestObject .reset_mock ()
521+
522+ # active transaction and provision date should be True
523+ guestObject .side_effect = [
524+ {'activeTransaction' : {'id' : 1 },
525+ 'provisionDate' : 'aaa' },
526+ ]
527+ value = self .cci .wait_for_ready (1 , 1 )
528+ self .assertTrue (value )
529+ guestObject .reset_mock ()
530+
531+ # active transaction and provision date
532+ # and pending should be false
533+ guestObject .side_effect = [
534+ {'activeTransaction' : {'id' : 1 },
535+ 'provisionDate' : 'aaa' },
536+ ]
537+ value = self .cci .wait_for_ready (1 , 1 , pending = True )
538+ self .assertFalse (value )
539+ guestObject .reset_mock ()
540+
541+ # actively running reload
542+ guestObject .side_effect = [
543+ {
544+ 'activeTransaction' : {'id' : 1 },
545+ 'provisionDate' : 'aaa' ,
546+ 'lastOperatingSystemReload' : {'id' : 1 },
547+ },
548+ ]
549+ value = self .cci .wait_for_ready (1 , 1 )
550+ self .assertFalse (value )
551+ guestObject .reset_mock ()
552+
553+ # reload complete, maintance transactions
554+ guestObject .side_effect = [
555+ {
556+ 'activeTransaction' : {'id' : 2 },
557+ 'provisionDate' : 'aaa' ,
558+ 'lastOperatingSystemReload' : {'id' : 1 },
559+ },
560+ ]
561+ value = self .cci .wait_for_ready (1 , 1 )
562+ self .assertTrue (value )
563+ guestObject .reset_mock ()
564+
565+ # reload complete, pending maintance transactions
566+ guestObject .side_effect = [
567+ {
568+ 'activeTransaction' : {'id' : 2 },
569+ 'provisionDate' : 'aaa' ,
570+ 'lastOperatingSystemReload' : {'id' : 1 },
571+ },
572+ ]
573+ value = self .cci .wait_for_ready (1 , 1 , pending = True )
574+ self .assertFalse (value )
575+ guestObject .reset_mock ()
576+
505577 @patch ('SoftLayer.managers.cci.sleep' )
506- def test_wait (self , _sleep ):
578+ def test_ready_delay_iterations (self , _sleep ):
507579 guestObject = self .client ['Virtual_Guest' ].getObject
508580
581+ # no iteration, false
582+ guestObject .side_effect = [
583+ {'activeTransaction' : {'id' : 1 }},
584+ ]
585+ value = self .cci .wait_for_ready (1 , 1 )
586+ self .assertFalse (value )
587+ self .assertFalse (_sleep .called )
588+ _sleep .reset_mock ()
589+ guestObject .reset_mock ()
590+
591+ # no iteration, true
592+ guestObject .side_effect = [
593+ {'provisionDate' : 'aaa' },
594+ ]
595+ value = self .cci .wait_for_ready (1 , 1 )
596+ self .assertTrue (value )
597+ self .assertFalse (_sleep .called )
598+ _sleep .reset_mock ()
599+ guestObject .reset_mock ()
600+
509601 # test 4 iterations with positive match
510602 guestObject .side_effect = [
511603 {'activeTransaction' : {'id' : 1 }},
512604 {'activeTransaction' : {'id' : 1 }},
513605 {'activeTransaction' : {'id' : 1 }},
514606 {'provisionDate' : 'aaa' },
515- {'provisionDate' : 'aaa' }
516607 ]
517608
518- value = self .cci .wait_for_transaction (1 , 4 )
609+ value = self .cci .wait_for_ready (1 , 4 )
519610 self .assertTrue (value )
520611 _sleep .assert_has_calls ([call (1 ), call (1 ), call (1 )])
521612 guestObject .assert_has_calls ([
@@ -528,17 +619,15 @@ def test_wait(self, _sleep):
528619 guestObject .reset_mock ()
529620
530621 guestObject .side_effect = [
531- {'activeTransaction' : {'id' : 1 }},
532622 {'activeTransaction' : {'id' : 1 }},
533623 {'activeTransaction' : {'id' : 1 }},
534624 {'provisionDate' : 'aaa' }
535625 ]
536- value = self .cci .wait_for_transaction (1 , 2 )
626+ value = self .cci .wait_for_ready (1 , 2 )
537627 self .assertFalse (value )
538- _sleep .assert_has_calls ([ call ( 1 ), call ( 1 )] )
628+ _sleep .assert_called_once_with ( 1 )
539629 guestObject .assert_has_calls ([
540630 call (id = 1 , mask = ANY ), call (id = 1 , mask = ANY ),
541- call (id = 1 , mask = ANY )
542631 ])
543632
544633 # 10 iterations at 10 second sleeps with no
@@ -556,21 +645,21 @@ def test_wait(self, _sleep):
556645 {'activeTransaction' : {'id' : 1 }},
557646 {'activeTransaction' : {'id' : 1 }},
558647 {'activeTransaction' : {'id' : 1 }},
559- {'activeTransaction' : {'id' : 1 }}
560648 ]
561- value = self .cci .wait_for_transaction (1 , 10 , 10 )
649+ value = self .cci .wait_for_ready (1 , 10 , 10 )
562650 self .assertFalse (value )
563651 guestObject .assert_has_calls ([
564652 call (id = 1 , mask = ANY ), call (id = 1 , mask = ANY ),
565653 call (id = 1 , mask = ANY ), call (id = 1 , mask = ANY ),
566654 call (id = 1 , mask = ANY ), call (id = 1 , mask = ANY ),
567655 call (id = 1 , mask = ANY ), call (id = 1 , mask = ANY ),
568656 call (id = 1 , mask = ANY ), call (id = 1 , mask = ANY ),
569- call (id = 1 , mask = ANY )
570657 ])
658+ # should only be 9 calls to sleep, last iteration
659+ # should return a value and skip the sleep
571660 _sleep .assert_has_calls ([
572661 call (10 ), call (10 ), call (10 ), call (10 ), call (10 ),
573- call (10 ), call (10 ), call (10 ), call (10 ), call ( 10 ) ])
662+ call (10 ), call (10 ), call (10 ), call (10 )])
574663
575664 def test_change_port_speed_public (self ):
576665 cci_id = 1
0 commit comments