summaryrefslogtreecommitdiffstats
path: root/testing/legion/examples/hello_world/host_test.py
blob: 77eca060384eb2dee1d3dca8ea0955daf062816f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""A simple host test module.

This module runs on the host machine and is responsible for creating 2
client machines, waiting for them, and running RPC calls on them.
"""

# Map the legion directory so we can import the host controller.
import sys
sys.path.append('../../')

import logging
import time

import host_controller


class ExampleController(host_controller.HostController):
  """A simple example controller for a test."""

  def __init__(self):
    super(ExampleController, self).__init__()
    self.client1 = None
    self.client2 = None

  def CreateClient(self):
    """Create a client object and set the proper values."""
    client = self.NewClient(
        isolate_file='client_test.isolate',
        config_vars={'multi_machine': '1'},
        dimensions={'os': 'Linux', 'pool': 'legion'}, priority=200,
        idle_timeout_secs=90, connection_timeout_secs=90,
        verbosity=logging.INFO)
    client.Create()
    return client

  def SetUp(self):
    """Create the client machines and wait until they connect.

    In this call the actual creation of the client machines is done in parallel
    by the system. The WaitForConnect calls are performed in series but will
    return as soon as the clients connect.
    """
    self.client1 = self.CreateClient()
    self.client2 = self.CreateClient()
    self.client1.WaitForConnection()
    self.client2.WaitForConnection()

  def Task(self):
    """Main method to run the task code."""
    self.CallEcho(self.client1)
    self.CallEcho(self.client2)
    self.CallClientTest(self.client1)
    self.CallClientTest(self.client2)

  def CallEcho(self, client):
    """Call rpc.Echo on a client."""
    logging.info('Calling Echo on %s', client.name)
    logging.info(self.client1.rpc.Echo(client.name))

  def CallClientTest(self, client):
    """Call client_test.py name on a client."""
    logging.info('Calling Subprocess to run "./client_test.py %s"', client.name)
    retcode, stdout, stderr = client.rpc.Subprocess(
        ['./client_test.py', client.name])
    logging.info('retcode: %s, stdout: %s, stderr: %s', retcode, stdout, stderr)


if __name__ == '__main__':
  ExampleController().RunController()