def __init__(self, ip, appInfoPath, dryRun): """ Constructs an instance of Remote environment :param ip: Name or ip address of the host where target application is running :type ip: str :param appInfoPath: Path to appInfo file of the target process :type appInfoPath: str :param dryRun: Flag to enable simlulation of target application :type dryRun: bool """ Environment.__init__(self, ip, appInfoPath, dryRun) LOGGER.debug('Registered rpyc channel to %s ', ip) from xpedite.util import makeLogPath self.remote = Remote(ip, makeLogPath('remote'), chdir=False)
def setTestParameters(hostname, transactions, multithreaded, workspace, rundir, apps, scenarioTypes, recordPMC): """ A method run at the beginning of tests to create and enter a REMOTE environment and at the end of tests to exit the REMOTE environment @param hostname: An option added to the pytest parser to accept a REMOTE host Defaults to 127.0.0.1 @type hostname: C{str} """ from xpedite.util import makeLogPath from xpedite.transport.net import isIpLocal from xpedite.transport.remote import Remote from xpedite.util.probeFactory import ProbeIndexFactory remote = None global CONTEXT, CAN_RECORD_PMC # pylint: disable=global-statement ProbeIndexFactory.reset() if not isIpLocal(hostname): remote = Remote(hostname, makeLogPath('remote')) remote.__enter__() CAN_RECORD_PMC = recordPMC CONTEXT = Context(transactions, multithreaded, workspace) SCENARIO_LOADER.loadScenarios(rundir, apps, scenarioTypes, remote) yield if remote: remote.__exit__(None, None, None)
def set_hostname(hostname): """ A method run at the beginning of tests to create and enter a remote environment and at the end of tests to exit the remote environment @param hostname: An option added to the pytest parser to accept a remote host Defaults to 127.0.0.1 @type hostname: C{str} """ from xpedite.util import makeLogPath from xpedite.transport.net import isIpLocal from xpedite.transport.remote import Remote global remote if not isIpLocal(hostname): remote = Remote(hostname, makeLogPath('remote')) remote.__enter__() yield if remote: remote.__exit__(None, None, None)
def setTestParameters(hostname, transactions, multithreaded, workspace, tempdir): """ A method run at the beginning of tests to create and enter a REMOTE environment and at the end of tests to exit the REMOTE environment @param hostname: An option added to the pytest parser to accept a REMOTE host Defaults to 127.0.0.1 @type hostname: C{str} """ from xpedite.util import makeLogPath from xpedite.transport.net import isIpLocal from xpedite.transport.remote import Remote global DATA_DIR, REMOTE, TXN_COUNT, THREAD_COUNT, WORKSPACE # pylint: disable=global-statement if not isIpLocal(hostname): REMOTE = Remote(hostname, makeLogPath('remote')) REMOTE.__enter__() TXN_COUNT = transactions THREAD_COUNT = multithreaded WORKSPACE = workspace DATA_DIR = os.path.join(tempdir, 'slowFixDecoder') yield if REMOTE: REMOTE.__exit__(None, None, None)
class RemoteEnvironment(Environment): """ Provides logic to interact with target process running in a remote host This class uses rpyc connection to provide the following services 1. Gathers environment info from a remote machine 2. Copies appInfo and sample files from remote host to local host """ def __init__(self, ip, appInfoPath, dryRun): """ Constructs an instance of Remote environment :param ip: Name or ip address of the host where target application is running :type ip: str :param appInfoPath: Path to appInfo file of the target process :type appInfoPath: str :param dryRun: Flag to enable simlulation of target application :type dryRun: bool """ Environment.__init__(self, ip, appInfoPath, dryRun) LOGGER.debug('Registered rpyc channel to %s ', ip) from xpedite.util import makeLogPath self.remote = Remote(ip, makeLogPath('remote'), chdir=False) def __enter__(self): """ Instantiates a tcp client and connects to target application The methods executes the following actions 1. Builds a rpyc connection to the target host 2. Copies appInfo file from remote host to a temporary filesystem path in localhost 3. Loads AppInfo object from the copied file 4. Establishes a tcp connection to the target application """ from xpedite.transport.remote import deliver self.remote.__enter__() self.proxy = deliver(self.remote.connection, self.proxy) result = self.gatherFiles(self.appInfo.path) if len(result) != 1: errmsg = 'Failed to gather app info file {} from remote host {} - got {}'.format( self.appInfo.path, self.ip, result) LOGGER.error(errmsg) raise Exception(errmsg) self.appInfo = AppInfo(result[0]) LOGGER.debug('Copied appinfo files from remote host to %s', self.appInfo.path) Environment.__enter__(self) LOGGER.debug( 'initializing remote environment - delivered proxy to %s ', self.ip) return self def __exit__(self, objType, value, traceback): """Disconnects tcp connection to the target app and terminates rpyc session""" Environment.__exit__(self, None, None, None) self.remote.__exit__(None, None, None) def gatherFiles(self, pattern): """ Copies files matching pattern from remote host to a temp filesystem path in localhost :param pattern: Wild card pattern for files to be collected """ remotePaths = self.proxy.gatherFiles(pattern) tmpRoot = tempfile.mkdtemp(prefix='xpedite', suffix='Remote', dir='/tmp') files = [] for remotePath in remotePaths: localPath = tmpRoot + os.path.abspath(remotePath) if os.path.exists(localPath): if not os.path.isdir(localPath): os.remove(localPath) else: os.makedirs(localPath) filePath = os.path.join(localPath, os.path.basename(remotePath)) import rpyc rpyc.utils.classic.download(self.remote.connection, remotePath, filePath) files.append(filePath) return files