blob: 558c4aac32dbd082c4cb6f6a19b04b5e20bd95fc [file] [log] [blame]
# Copyright 2015 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import logging
from autotest_lib.client.common_lib.cros import dbus_send
from autotest_lib.client.common_lib.cros import process_watcher
from autotest_lib.client.common_lib.cros.tendo import peerd_config
# In test images, we add a supplementary set of rules that expand the DBus
# access policy to tolerate us claiming this name and sending messages to
# these services.
TEST_SERVICE_NAME_PREFIX = 'org.chromium.peerd.test'
def get_nth_service_name(n):
"""Get the DBus service name for the Nth face of peerd.
@param n: int starting from 0 inclusive.
@return DBus service name for Nth instance as a string.
return '%s.TestInstance%d' % (TEST_SERVICE_NAME_PREFIX, n)
class NFacedPeerdHelper(object):
"""Helper object that knows how to start and stop NFacedPeerd."""
def __init__(self, num_instances, localhost_addr='', host=None):
"""Construct an NFacedPeerd instance (possibly on a remote host).
@param num_instances: int number of faces to include in our fake peerd.
@param localhost_addr: string ip address (e.g. ''). Each face
of peerd will be "discovered" by the other faces at this IP
address. This should be an IP address that makes sense for
daemons consuming it.
@param host: host object if we should start NFacedPeerd on a remote
self._process_watcher = process_watcher.ProcessWatcher(
args=['%d' % num_instances,
self._num_instances = num_instances
self._host = host
def get_face_identifier(self, instance_number):
"""Get the UUID for a given face of NFacedPeerd.
This will fail if we have not previously started an instance of
@param instance_number: int starting from 0 inclusive.
@return string UUID value.
return dbus_send.get_property(
def start(self):
"""Start an instance of NFacedPeerd on the host."""
logging.debug('Starting NFacedPeerd')
for i in range(self._num_instances):
service_name = get_nth_service_name(i)
def close(self):
"""Close all resources held by the helper."""
logging.debug('Stopping NFacedPeerd')
logging.debug('Finished stopping NFacedPeerd')