~cr3/ubuntu/oneiric/checkbox/0.12.4

« back to all changes in this revision

Viewing changes to scripts/sleep_test

  • Committer: Marc Tardif
  • Date: 2011-08-10 20:31:34 UTC
  • Revision ID: marc.tardif@canonical.com-20110810203134-r4ry90vnggl31qk1
[Brendan Donegan]
* Refactored job definition files.
* Fixed dependencies and test naming.
* Added Online CPU before/after suspend test.
* Automated wireless tests.
* Removed redundant sru_suite.txt, updated dependencies accordingly.
* Automated bluetooth_obex tests.

[Daniel Manrique]
* Further improvements to make frontend/backend communication more reliable.
  Prevents stuck backends, failure to close the GUI due to lack of reply
  from the backend, and test specifying "user" not being run.
* scripts/keyboard_test modified to account for pygi-related GTK API
  changes. (LP: #804369)
* scripts/sleep_test: improve handling of NetworkManager DBus API
  changes. (LP: #808423)
* scripts/cdimage_resource: properly handle releases with "LTS" in their
  name (LP: #814085)
* Updated minimum_resolution test as per latest system requirements, leaving
  just one unified test. (LP: #767166)

[Javier Collado]
* Checkbox exits with EX_NOINPUT if a whitelist or blacklist file is
  specified and cannot be found.
* Deselect a test suite automatically when none of its children is selected,
  in the GTK interface. (LP: #651878)
* Make the "Next" button the default action when Enter is pressed, to 
  streamline testing with the GTK interface.

[Marc Tardif]
* Fixed udevam not being found because /sbin not in PATH (LP: #597305)
* Fixed hardware attachments for udev and dmi (LP: #822682)

[Sylvain Pineau]
* Expose the message store to other plugins, via firing an expose-msgstore
  event.

[Andrew Faulkner]
* Fix description for nautilus_file_create job (LP: #821141) 

[Kenneth Wimer]
* New header image that follows brand guidelines (LP: #554202)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
'''
3
3
Program to automate system entering and resuming from sleep states
4
4
 
5
 
Copyright (C) 2010 Canonical Ltd.
 
5
Copyright (C) 2010,2011 Canonical Ltd.
6
6
 
7
7
Author:
8
8
    Jeff Lane <jeffrey.lane@canonical.com>
44
44
TO DO:
45
45
* remove workaround once we get a fix for the pm scripts issue that causes the
46
46
  wakealarm and alarm_IRQ entries to not be reset after resume from S4
47
 
* Add in post-resume check to determine of network has resumed
48
47
* Add in checks to factor in the consumer-test hibernate/suspend test cases
49
48
 
50
49
Changelog:
 
50
v1.2:   Removed NetworkManager class and replaced with simple call to nmcli
 
51
v1.1:   Added handling of NetworkManager 0.9 status codes. 
51
52
v1.0:   Added code to support Hibernate (S4) and allow choice between S3 and S4
52
53
        at run-time.
53
54
        Created mechanism in SuspendTest() class to check /proc/driver/rtc as a
74
75
 
75
76
import sys
76
77
import logging
77
 
from subprocess import call
 
78
from subprocess import call,check_output
78
79
from optparse import OptionParser
79
80
 
80
81
from datetime import datetime, timedelta
276
277
            return False
277
278
 
278
279
 
279
 
class NetworkManagerException(Exception):
280
 
 
281
 
    pass
282
 
 
283
 
 
284
 
class NetworkManager(object):
285
 
 
286
 
    NM_SERVICE = "org.freedesktop.NetworkManager"
287
 
    NM_PATH = "/org/freedesktop/NetworkManager"
288
 
    NM_INTERFACE = NM_SERVICE
289
 
 
290
 
    NM_PATH_DEVICES = "/org/freedesktop/NetworkManager/Devices"
291
 
    NM_INTERFACE_DEVICES = "org.freedesktop.NetworkManager.Devices"
292
 
 
293
 
    NMI_SERVICE = "org.freedesktop.NetworkManagerInfo"
294
 
    NMI_PATH = "/org/freedesktop/NetworkManagerInfo"
295
 
    NMI_INTERFACE = NMI_SERVICE
296
 
 
297
 
    HAL_SERVICE = "org.freedesktop.Hal"
298
 
    HAL_PATH = "/org/freedesktop/Hal/Manager"
299
 
    HAL_INTERFACE = "org.freedesktop.Hal.Manager"
300
 
    HAL_INTERFACE_DEVICE = "org.freedesktop.Hal.Device"
301
 
 
302
 
    STATE_UNKNOWN = "unknown"
303
 
    STATE_ASLEEP = "asleep"
304
 
    STATE_CONNECTING = "connecting"
305
 
    STATE_CONNECTED = "connected"
306
 
    STATE_DISCONNECTED = "disconnected"
307
 
 
308
 
    _state_table = [
309
 
        STATE_UNKNOWN,
310
 
        STATE_ASLEEP,
311
 
        STATE_CONNECTING,
312
 
        STATE_CONNECTED,
313
 
        STATE_DISCONNECTED]
314
 
 
315
 
    def __init__(self):
316
 
        try:
317
 
            import dbus
318
 
        except ImportError:
319
 
            raise NetworkManagerException, "Python module not found: dbus"
320
 
 
321
 
        try:
322
 
            self._bus = dbus.SystemBus()
323
 
            self.nm_object  = self._bus.get_object(self.NM_SERVICE, self.NM_PATH)
324
 
            self.nm_service = dbus.Interface(self.nm_object, self.NM_INTERFACE)
325
 
        except dbus.exceptions.DBusException:
326
 
            raise NetworkManagerException, "Failed to connect to dbus service"
327
 
 
328
 
    def get_state(self):
329
 
        state = self.nm_service.state()
330
 
        return self._state_table[state]
331
 
 
332
 
 
333
280
def check_network():
334
 
    try:
335
 
        nm = NetworkManager()
336
 
    except NetworkManagerException:
337
 
        return True
338
 
 
339
281
    start = datetime.now()
340
282
    logging.debug("Waiting 60 seconds for NetworkManager to reconnect.")
341
283
    while True:
342
 
        if nm.get_state() == nm.STATE_CONNECTED:
343
 
            return True
344
 
        # give 60 seconds to NetworkManager to get to a CONNECTED state, then give up
345
 
        if datetime.now() - start > timedelta(seconds=60):
 
284
        try:
 
285
            if check_output(["/usr/bin/nmcli", "-t", "-f", 
 
286
                "STATE", "nm"]).strip() == "connected":
 
287
                return True
 
288
            # give 60 seconds to NetworkManager to get to a CONNECTED state, then give up
 
289
            if datetime.now() - start > timedelta(seconds=60):
 
290
                return False
 
291
            sleep(5)
 
292
        except OSError as err:
 
293
            logging.error("Unable to verify network status: %s" % err)
346
294
            return False
347
 
        sleep(5)
348
295
            
349
296
def main():
350
297
    usage = 'Usage: %prog [OPTIONS]'