OLD | NEW |
1 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Module containing methods and classes to interact with a devserver instance. | 5 """Module containing methods and classes to interact with a devserver instance. |
6 """ | 6 """ |
7 | 7 |
| 8 import os |
8 import threading | 9 import threading |
9 | 10 |
10 import cros_build_lib as cros_lib | 11 import cros_build_lib as cros_lib |
11 | 12 |
12 def GenerateUpdateId(target, src, key): | 13 def GenerateUpdateId(target, src, key): |
13 """Returns a simple representation id of target and src paths.""" | 14 """Returns a simple representation id of target and src paths.""" |
14 update_id = target | 15 update_id = target |
15 if src: update_id = '->'.join([update_id, src]) | 16 if src: update_id = '->'.join([update_id, src]) |
16 if key: update_id = '+'.join([update_id, key]) | 17 if key: update_id = '+'.join([update_id, key]) |
17 return update_id | 18 return update_id |
18 | 19 |
19 class DevServerWrapper(threading.Thread): | 20 class DevServerWrapper(threading.Thread): |
20 """A Simple wrapper around a dev server instance.""" | 21 """A Simple wrapper around a dev server instance.""" |
21 | 22 |
22 def __init__(self): | 23 def __init__(self, test_root): |
23 self.proc = None | 24 self.proc = None |
| 25 self.test_root = test_root |
24 threading.Thread.__init__(self) | 26 threading.Thread.__init__(self) |
25 | 27 |
26 def run(self): | 28 def run(self): |
27 # Kill previous running instance of devserver if it exists. | 29 # Kill previous running instance of devserver if it exists. |
28 cros_lib.RunCommand(['sudo', 'pkill', '-f', 'devserver.py'], error_ok=True, | 30 cros_lib.RunCommand(['sudo', 'pkill', '-f', 'devserver.py'], error_ok=True, |
29 print_cmd=False) | 31 print_cmd=False) |
30 cros_lib.RunCommand(['sudo', | 32 cros_lib.RunCommand(['sudo', |
31 'start_devserver', | 33 'start_devserver', |
32 '--archive_dir=./static', | 34 '--archive_dir=./static', |
33 '--client_prefix=ChromeOSUpdateEngine', | 35 '--client_prefix=ChromeOSUpdateEngine', |
34 '--production', | 36 '--production', |
35 ], enter_chroot=True, print_cmd=False) | 37 ], enter_chroot=True, print_cmd=False, |
| 38 log_to_file=os.path.join(self.test_root, |
| 39 'dev_server.log')) |
36 | 40 |
37 def Stop(self): | 41 def Stop(self): |
38 """Kills the devserver instance.""" | 42 """Kills the devserver instance.""" |
39 cros_lib.RunCommand(['sudo', 'pkill', '-f', 'devserver.py'], error_ok=True, | 43 cros_lib.RunCommand(['sudo', 'pkill', '-f', 'devserver.py'], error_ok=True, |
40 print_cmd=False) | 44 print_cmd=False) |
41 | 45 |
42 @classmethod | 46 @classmethod |
43 def GetDevServerURL(cls, port, sub_dir): | 47 def GetDevServerURL(cls, port, sub_dir): |
44 """Returns the dev server url for a given port and sub directory.""" | 48 """Returns the dev server url for a given port and sub directory.""" |
45 ip_addr = cros_lib.GetIPAddress() | 49 ip_addr = cros_lib.GetIPAddress() |
46 if not port: port = 8080 | 50 if not port: port = 8080 |
47 url = 'http://%(ip)s:%(port)s/%(dir)s' % {'ip': ip_addr, | 51 url = 'http://%(ip)s:%(port)s/%(dir)s' % {'ip': ip_addr, |
48 'port': str(port), | 52 'port': str(port), |
49 'dir': sub_dir} | 53 'dir': sub_dir} |
50 return url | 54 return url |
OLD | NEW |