~awe/+junk/touch-test-tools

« back to all changes in this revision

Viewing changes to touch-reboot-online-test

  • Committer: Tony Espy
  • Date: 2014-06-24 14:20:14 UTC
  • Revision ID: espy@canonical.com-20140624142014-3mzh65s86khvzwod
Initial version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python3
 
2
#
 
3
# Copyright 2014 Canonical Ltd.
 
4
#
 
5
# Author: Tony Espy <espy@canonical.com>
 
6
#
 
7
# This is free software; you can redistribute it and/or modify
 
8
# it under the terms of the GNU General Public License as published by
 
9
# the Free Software Foundation; version 3.
 
10
# touch-reboot-online-test is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
#
 
18
# Description - this test script is meant to be executed by a post-script
 
19
# command in ofono's system upstart job.  It reads a current boot number
 
20
# from a local file, then attempts to determine if indicator-network is
 
21
# running, which rough indicator that the unity has started.  It next checks
 
22
# the status of the modem.  If Online, the status is written to the local
 
23
# file boot.#, and the device rebooted.  If Offline, the status is written
 
24
# to the same file, and the test stops.  Note, the upper bounds of the number
 
25
# of reboots is hard-coded in the script.
 
26
#
 
27
#
 
28
 
 
29
import subprocess
 
30
import time
 
31
 
 
32
if __name__ == '__main__':
 
33
 
 
34
    boot_count = 0
 
35
 
 
36
    with open('/home/phablet/boot-count', mode='r') as a_file:
 
37
        boot_count_str = a_file.read()
 
38
 
 
39
        try:
 
40
            boot_count = int(boot_count_str)
 
41
        except ValueError as e:
 
42
            exit
 
43
 
 
44
    output_file = '/home/phablet/boot.{0}'.format(boot_count_str)
 
45
 
 
46
    with open('/home/phablet/boot-count', mode='w') as a_file:
 
47
        boot_count = boot_count + 1
 
48
        boot_count_str = str(boot_count)
 
49
        a_file.write(str(boot_count_str));
 
50
 
 
51
    while True:
 
52
        time.sleep(5)
 
53
 
 
54
        ps = ''
 
55
 
 
56
        try:
 
57
            ps = subprocess.check_output('ps -ale | grep indicator-net', shell=True)
 
58
        except subprocess.CalledProcessError as e:
 
59
            ps = ''
 
60
 
 
61
        if ps == '':
 
62
            continue
 
63
 
 
64
 
 
65
        online = subprocess.check_output('/usr/share/ofono/scripts/list-modems | grep Online', shell=True)
 
66
#    online = subprocess.check_output('ls | grep reboot2', shell=True)
 
67
        print(online)
 
68
 
 
69
        with open(output_file, mode='w') as out_file:
 
70
            if online == b'    Online = 1\n':
 
71
                out_file.write('Online')
 
72
                if boot_count < 100:
 
73
                    subprocess.check_output('reboot')
 
74
            else:
 
75
                out_file.write('OFFLINE')
 
76
                break
 
77
 
 
78
        exit()
 
79
 
 
80
 
 
81