3
# Copyright 2014 Canonical Ltd.
5
# Author: Tony Espy <espy@canonical.com>
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.
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/>.
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.
32
if __name__ == '__main__':
36
with open('/home/phablet/boot-count', mode='r') as a_file:
37
boot_count_str = a_file.read()
40
boot_count = int(boot_count_str)
41
except ValueError as e:
44
output_file = '/home/phablet/boot.{0}'.format(boot_count_str)
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));
57
ps = subprocess.check_output('ps -ale | grep indicator-net', shell=True)
58
except subprocess.CalledProcessError as e:
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)
69
with open(output_file, mode='w') as out_file:
70
if online == b' Online = 1\n':
71
out_file.write('Online')
73
subprocess.check_output('reboot')
75
out_file.write('OFFLINE')