Changeset 79056 in vbox for trunk/src/VBox/ValidationKit/testdriver/vboxwrappers.py
- Timestamp:
- Jun 9, 2019 8:55:56 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/testdriver/vboxwrappers.py
r79045 r79056 3228 3228 return True; 3229 3229 3230 3231 3232 class AdditionsStatusTask(TdTaskBase): 3233 """ 3234 Class that takes care of waiting till the guest additions are in a given state. 3235 """ 3236 3237 class AdditionsStatusTaskCallback(vbox.EventHandlerBase): 3238 """ Class for looking for IPv4 address changes on interface 0.""" 3239 def __init__(self, dArgs): 3240 self.oParentTask = dArgs['oParentTask']; 3241 vbox.EventHandlerBase.__init__(self, dArgs, self.oParentTask.oSession.fpApiVer, 3242 'AdditionsStatusTaskCallback/%s' % (self.oParentTask.oSession.sName,)); 3243 3244 def handleEvent(self, oEvt): 3245 try: 3246 enmType = oEvt.type; 3247 except: 3248 reporter.errorXcpt(); 3249 else: 3250 reporter.log2('AdditionsStatusTaskCallback:handleEvent: enmType=%s' % (enmType,)); 3251 if enmType == vboxcon.VBoxEventType_OnGuestAdditionsStatusChanged: 3252 oParentTask = self.oParentTask; 3253 if oParentTask: 3254 oParentTask.pollTask(); 3255 3256 # end 3257 3258 3259 def __init__(self, oSession, oIGuest, cMsTimeout = 120000, aenmWaitForRunLevels = None, aenmWaitForActive = None, 3260 aenmWaitForInactive = None): 3261 """ 3262 aenmWaitForRunLevels - List of run level values to wait for (success if one matches). 3263 aenmWaitForActive - List facilities (type values) that must be active. 3264 aenmWaitForInactive - List facilities (type values) that must be inactive. 3265 3266 The default is to wait for AdditionsRunLevelType_Userland if all three lists 3267 are unspecified or empty. 3268 """ 3269 TdTaskBase.__init__(self, utils.getCallerName()); 3270 self.oSession = oSession # type: vboxwrappers.SessionWrapper 3271 self.oIGuest = oIGuest; 3272 self.cMsTimeout = cMsTimeout; 3273 self.fSucceeded = False; 3274 self.oVBoxEventHandler = None; 3275 self.aenmWaitForRunLevels = aenmWaitForRunLevels if aenmWaitForRunLevels else []; 3276 self.aenmWaitForActive = aenmWaitForActive if aenmWaitForActive else []; 3277 self.aenmWaitForInactive = aenmWaitForInactive if aenmWaitForInactive else []; 3278 3279 # Provide a sensible default if nothing is given. 3280 if not self.aenmWaitForRunLevels and not self.aenmWaitForActive and not self.aenmWaitForInactive: 3281 self.aenmWaitForRunLevels = [vboxcon.AdditionsRunLevelType_Userland,]; 3282 3283 # Register the event handler on hosts which has it: 3284 if oSession.fpApiVer >= 6.1 or hasattr(vboxcon, 'VBoxEventType_OnGuestAdditionsStatusChanged'): 3285 aenmEvents = (vboxcon.VBoxEventType_OnGuestAdditionsStatusChanged,); 3286 dArgs = { 3287 'oParentTask': self, 3288 }; 3289 self.oVBoxEventHandler = vbox.EventHandlerBase.registerDerivedEventHandler(oSession.oVBoxMgr, 3290 oSession.fpApiVer, 3291 self.AdditionsStatusTaskCallback, 3292 dArgs, 3293 oIGuest, 3294 'IGuest', 3295 'AdditionsStatusTaskCallback', 3296 aenmEvents = aenmEvents); 3297 reporter.log2('AdditionsStatusTask: %s' % (self.toString(), )); 3298 3299 def __del__(self): 3300 """ Make sure we deregister the callback. """ 3301 self._deregisterEventHandler(); 3302 self.oIGuest = None; 3303 return TdTaskBase.__del__(self); 3304 3305 def toString(self): 3306 return '<%s cMsTimeout=%s, fSucceeded=%s, aenmWaitForRunLevels=%s, aenmWaitForActive=%s, aenmWaitForInactive=%s, ' \ 3307 'oVBoxEventHandler=%s>' \ 3308 % (TdTaskBase.toString(self), self.cMsTimeout, self.fSucceeded, self.aenmWaitForRunLevels, self.aenmWaitForActive, 3309 self.aenmWaitForInactive, self.oVBoxEventHandler,); 3310 3311 def _deregisterEventHandler(self): 3312 """Deregisters the event handler.""" 3313 fRc = True; 3314 oVBoxEventHandler = self.oVBoxEventHandler; 3315 if oVBoxEventHandler is not None: 3316 self.oVBoxEventHandler = None; 3317 fRc = oVBoxEventHandler.unregister(); 3318 oVBoxEventHandler.oParentTask = None; # Try avoid cylic deps. 3319 return fRc; 3320 3321 def _poll(self): 3322 """ 3323 Internal worker for pollTask() that returns the new signalled state. 3324 """ 3325 3326 # 3327 # Check if any of the runlevels we wait for have been reached: 3328 # 3329 if self.aenmWaitForRunLevels: 3330 try: 3331 enmRunLevel = self.oIGuest.additionsRunLevel; 3332 except: 3333 reporter.errorXcpt(); 3334 return True; 3335 if enmRunLevel not in self.aenmWaitForRunLevels: 3336 reporter.log2('AdditionsStatusTask/poll: enmRunLevel=%s not in %s' % (enmRunLevel, self.aenmWaitForRunLevels,)); 3337 return False; 3338 reporter.log2('AdditionsStatusTask/poll: enmRunLevel=%s matched %s!' % (enmRunLevel, self.aenmWaitForRunLevels,)); 3339 3340 3341 # 3342 # Check for the facilities that must all be active. 3343 # 3344 for enmFacility in self.aenmWaitForActive: 3345 try: 3346 (enmStatus, _) = self.oIGuest.getFacilityStatus(enmFacility); 3347 except: 3348 reporter.errorXcpt('enmFacility=%s' % (enmFacility,)); 3349 return True; 3350 if enmStatus != vboxcon.AdditionsFacilityStatus_Active: 3351 reporter.log2('AdditionsStatusTask/poll: enmFacility=%s not active: %s' % (enmFacility, enmStatus,)); 3352 return False; 3353 3354 # 3355 # Check for the facilities that must all be inactive or terminated. 3356 # 3357 for enmFacility in self.aenmWaitForInactive: 3358 try: 3359 (enmStatus, _) = self.oIGuest.getFacilityStatus(enmFacility); 3360 except: 3361 reporter.errorXcpt('enmFacility=%s' % (enmFacility,)); 3362 return True; 3363 if enmStatus not in (vboxcon.AdditionsFacilityStatus_Inactive, 3364 vboxcon.AdditionsFacilityStatus_Terminated): 3365 reporter.log2('AdditionsStatusTask/poll: enmFacility=%s not inactive: %s' % (enmFacility, enmStatus,)); 3366 return False; 3367 3368 3369 reporter.log('AdditionsStatusTask: Poll succeeded, signalling...'); 3370 self.fSucceeded = True; 3371 return True; 3372 3373 3374 # 3375 # Task methods 3376 # 3377 3378 def pollTask(self, fLocked = False): 3379 """ 3380 Overridden pollTask method. 3381 """ 3382 if not fLocked: 3383 self.lockTask(); 3384 3385 fDeregister = False; 3386 fRc = self.fSignalled; 3387 if not fRc: 3388 fRc = self._poll(); 3389 if fRc or self.getAgeAsMs() >= self.cMsTimeout: 3390 self.signalTaskLocked(); 3391 fDeregister = True; 3392 3393 if not fLocked: 3394 self.unlockTask(); 3395 3396 # If we're done, deregister the event callback (w/o owning lock). 3397 if fDeregister: 3398 self._deregisterEventHandler(); 3399 return fRc; 3400 3401 def getResult(self): 3402 """ 3403 Returns true if the we succeeded. 3404 Returns false if not. If the task is signalled already, then we 3405 encountered a problem while polling. 3406 """ 3407 return self.fSucceeded; 3408 3409 def cancelTask(self): 3410 """ 3411 Cancels the task. 3412 Just to actively disengage the event handler. 3413 """ 3414 self._deregisterEventHandler(); 3415 return True; 3416
Note:
See TracChangeset
for help on using the changeset viewer.