~pwlars/ubuntu-test-cases/auto-offline-devices

« back to all changes in this revision

Viewing changes to scripts/ncd_usb.py

  • Committer: Andy Doan
  • Date: 2014-04-23 19:21:18 UTC
  • mto: This revision was merged to the branch mainline in revision 221.
  • Revision ID: andy.doan@canonical.com-20140423192118-pc37rpziylei3nni
add bootchart test

In order to comply with the qa-dashboard expectations, this test
produces a "boot.json" file that re-labels steps to things it
expects like xorg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/python
2
 
 
3
 
"""A utility to control the USB relay's in the QA lab."""
4
 
 
5
 
import argparse
6
 
import sys
7
 
import urllib2
8
 
 
9
 
 
10
 
def set_relay(urlbase, bank, relay, on):
11
 
    # the values 100/108 came from the JavaScript of our web-based management
12
 
    # system for the relays. The meaning of the values isn't documented.
13
 
    if on:
14
 
        relay += 108
15
 
    else:
16
 
        relay += 100
17
 
    cmd = '254,{},{}'.format(relay, bank + 1)
18
 
    url = '{}/cgi-bin/runcommand.sh?1:cmd={}'.format(urlbase, cmd)
19
 
    resp = urllib2.urlopen(url)
20
 
    resp = resp.read()
21
 
    if 'OK' not in resp:
22
 
        print('ERROR: bad response: {}'.format(resp))
23
 
        sys.exit(1)
24
 
 
25
 
 
26
 
def _get_parser():
27
 
    parser = argparse.ArgumentParser(
28
 
        description='Toggles an NCD relay connected to a USB cable on/off')
29
 
    parser.add_argument('-u', '--url',
30
 
                        default='http://qa-relay-control.ubuntu-ci',
31
 
                        help='NCD relay URL. default=%(default)s')
32
 
    parser.add_argument('-b', '--bank', type=int, required=True,
33
 
                        help='NCD relay 0-based bank ID.')
34
 
    parser.add_argument('-r', '--relay', type=int, required=True,
35
 
                        help='NCD relay 0-based relay ID.')
36
 
    parser.add_argument('action', metavar='action',
37
 
                        choices=('on', 'off'),
38
 
                        help='action to perform on|off')
39
 
    return parser
40
 
 
41
 
 
42
 
if __name__ == '__main__':
43
 
    args = _get_parser().parse_args()
44
 
 
45
 
    # NOTE: when the relay is ON usb is actually OFF. ie the logic
46
 
    # is backwards between them, thus action=off actually turns
47
 
    # the relay on
48
 
    set_relay(args.url, args.bank, args.relay, args.action == 'off')