OLD | NEW |
(Empty) | |
| 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 |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import logging, re, time |
| 6 from autotest_lib.client.common_lib import error |
| 7 |
| 8 class LinuxServer(object): |
| 9 """ |
| 10 Linux Server: A machine which hosts network services. |
| 11 |
| 12 """ |
| 13 |
| 14 def __init__(self, server, params): |
| 15 self.server = server # Server host. |
| 16 self.vpn_kind = None |
| 17 self.conf = {} |
| 18 |
| 19 def vpn_server_config(self, params): |
| 20 """ Configure & launch the server side of the VPN. |
| 21 |
| 22 Parameters, in 'params': |
| 23 |
| 24 kind : required |
| 25 |
| 26 The kind of VPN which should be configured and |
| 27 launched. |
| 28 |
| 29 Valid values: |
| 30 |
| 31 openvpn |
| 32 |
| 33 config: required |
| 34 |
| 35 The configuration information associated with |
| 36 the VPN server. |
| 37 |
| 38 This is a dict which contains key/value pairs |
| 39 representing the VPN's configuration. |
| 40 |
| 41 The values stored in the 'config' param must all be |
| 42 supported by the specified VPN kind. |
| 43 """ |
| 44 self.vpn_server_kill({}) # Must be first. Relies on self.vpn_kind. |
| 45 |
| 46 self.vpn_kind = params.get('kind', None) |
| 47 |
| 48 # Read configuration information & create server configuration file. |
| 49 # |
| 50 # As VPN kinds other than 'openvpn' are supported, and |
| 51 # since 'self.conf' is cummulative, perhaps there should be |
| 52 # a method which will clear 'self.conf'; different types of |
| 53 # VPN will likely not have the same configuration |
| 54 # parameters. This is only really needed if a test is |
| 55 # written to switch between two differents kinds of VPN. |
| 56 for k, v in params.get('config', {}).iteritems(): |
| 57 self.conf[k] = v |
| 58 self.server.run("cat <<EOF >%s\n%s\nEOF\n" % |
| 59 ('/tmp/vpn-server.conf', '\n'.join( |
| 60 "%s %s" % kv for kv in self.conf.iteritems()))) |
| 61 |
| 62 # Launch specified VPN server. |
| 63 if self.vpn_kind is None: |
| 64 raise error.TestFail('No VPN kind specified for this test.'); |
| 65 elif self.vpn_kind == 'openvpn': |
| 66 self.server.run("/usr/sbin/openvpn --config /tmp/vpn-server.conf &") |
| 67 else: |
| 68 raise error.TestFail('(internal error): No config case ' |
| 69 'for VPN kind (%s)' % self.vpn_kind) |
| 70 |
| 71 def vpn_server_kill(self, params): |
| 72 """ Kill the VPN server. """ |
| 73 if self.vpn_kind is not None: |
| 74 if self.vpn_kind == 'openvpn': |
| 75 self.server.run("pkill /usr/sbin/openvpn") |
| 76 else: |
| 77 raise error.TestFail('(internal error): No kill case ' |
| 78 'for VPN kind (%s)' % self.vpn_kind) |
| 79 self.vpn_kind = None; |
OLD | NEW |