#NEWLINE# @ mock . patch ( 'time.sleep' ) #NEWLINE# @ mock . patch ( 'cloudbaseinit.plugins.windows.ntpclient.NTPClientPlugin._set_ntp_trigger_mode' ) #NEWLINE# def _test_check_w32time_svc_status( self , mock_set_ntp_trigger_mode , mock_sleep , start_mode , fail_service_start , patch_check_os_version = True ) : #NEWLINE# #INDENT# mock_osutils = mock . MagicMock ( ) #NEWLINE# mock_osutils . SERVICE_START_MODE_AUTOMATIC = 'Automatic' #NEWLINE# mock_osutils . SERVICE_STATUS_RUNNING = 'running' #NEWLINE# mock_osutils . SERVICE_STATUS_STOPPED = 'stopped' #NEWLINE# mock_osutils . get_service_start_mode . return_value = start_mode #NEWLINE# mock_osutils . check_os_version . return_value = patch_check_os_version #NEWLINE# if fail_service_start : #NEWLINE# #INDENT# mock_osutils . get_service_status . return_value = 'stopped' #NEWLINE# self . assertRaises ( exception . CloudbaseInitException , self . _ntpclient . verify_time_service , mock_osutils ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# mock_osutils . get_service_status . side_effect = [ 'stopped' , mock_osutils . SERVICE_STATUS_RUNNING ] #NEWLINE# self . _ntpclient . verify_time_service ( osutils = mock_osutils ) #NEWLINE# if ( mock_sleep != mock_osutils . SERVICE_START_MODE_AUTOMATIC ) : #NEWLINE# #INDENT# mock_osutils . set_service_start_mode . assert_called_once_with ( ntpclient . _W32TIME_SERVICE , mock_osutils . SERVICE_START_MODE_AUTOMATIC ) #NEWLINE# #UNINDENT# mock_sleep . assert_called_once_with ( 1 ) #NEWLINE# mock_osutils . start_service . assert_called_once_with ( ntpclient . _W32TIME_SERVICE ) #NEWLINE# #UNINDENT# mock_osutils . get_service_start_mode . assert_called_once_with ( ntpclient . _W32TIME_SERVICE ) #NEWLINE# mock_osutils . get_service_status . assert_called_with ( ntpclient . _W32TIME_SERVICE ) #NEWLINE# mock_osutils . check_os_version . assert_called_once_with ( 6 , 1 ) #NEWLINE# if patch_check_os_version : #NEWLINE# #INDENT# mock_set_ntp_trigger_mode . assert_called_once_with ( mock_osutils ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . assertFalse ( mock_set_ntp_trigger_mode . called )