From 815839bf3cac2fcfd2d25a69395055397d55a8bb Mon Sep 17 00:00:00 2001 From: Marco Capitani Date: Fri, 30 Jun 2017 12:17:16 +0200 Subject: ssh & model-storyboard: changed ssh API, added node.execute* methods --- rumba/model.py | 123 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 90 insertions(+), 33 deletions(-) (limited to 'rumba/model.py') diff --git a/rumba/model.py b/rumba/model.py index ce4e938..d2f7567 100644 --- a/rumba/model.py +++ b/rumba/model.py @@ -164,10 +164,18 @@ class NormalDIF(DIF): # SSH Configuration # class SSHConfig: - def __init__(self, hostname, port=22, proxycommand=None): + def __init__(self, hostname, port=22, proxy_command=None): + self.username = None + self.password = None self.hostname = hostname self.port = port - self.proxycommand = proxycommand + self.proxy_command = proxy_command + + def set_username(self, username): + self.username = username + + def set_password(self, password): + self.password = password # A node in the experiment @@ -284,6 +292,74 @@ class Node: def get_policy(self, dif): return self.policies[dif] + def execute_commands(self, commands, time_out=3, use_proxy=False): + # Ssh_config is used twice since it doubles as testbed info + # (it holds fields username and password) + if use_proxy: + return ssh_support.execute_proxy_commands( + self.ssh_config, + self.ssh_config, + commands, + time_out + ) + # else: + return ssh_support.execute_commands( + self.ssh_config, + self.ssh_config, + commands, + time_out + ) + + def execute_command(self, command, time_out=3, use_proxy=False): + # Ssh_config is used twice since it doubles as testbed info + # (it holds fields username and password) + if use_proxy: + return ssh_support.execute_proxy_command( + self.ssh_config, + self.ssh_config, + command, + time_out + ) + # else: + return ssh_support.execute_command( + self.ssh_config, + self.ssh_config, + command, + time_out + ) + + def copy_file_to_testbed(self, text, file_name): + ssh_support.copy_file_to_testbed( + self.ssh_config, + self.ssh_config, + text, + file_name + ) + + def copy_path_to_testbed(self, path, destination): + ssh_support.copy_path_to_testbed( + self.ssh_config, + self.ssh_config, + path, + destination + ) + + def copy_paths_to_testbed(self, paths, destination): + ssh_support.copy_paths_to_testbed( + self.ssh_config, + self.ssh_config, + paths, + destination + ) + + def setup_vlan(self, vlan_id, int_name): + ssh_support.setup_vlan( + self.ssh_config, + self.ssh_config, + vlan_id, + int_name + ) + # Base class representing an IPC Process to be created in the experiment # @@ -649,7 +725,7 @@ class Experiment: self.testbed.username, node.ssh_config.hostname, node.ssh_config.port, - node.ssh_config.proxycommand)) + node.ssh_config.proxy_command)) f.close() # Examine the nodes and DIFs, compute the registration and enrollment @@ -690,26 +766,24 @@ class Experiment: # @options: Options to pass to the binary # class Client(object): - def __init__(self, ap, testbed, options=None): + def __init__(self, ap, options=None): self.ap = ap self.options = options - self.testbed = testbed def start_process(self, duration): - return ClientProcess(self.ap, duration, self.testbed, self.options) + return ClientProcess(self.ap, duration, self.options) # Base class for client processes # # @ap: Application Process binary -# @node: The node on which this process should run # @duration: The time (in seconds) this process should run # @start_time: The time at which this process is started. # @options: Options to pass to the binary # class ClientProcess(Client): - def __init__(self, ap, duration, testbed, options=None): - super(ClientProcess, self).__init__(ap, testbed, options=options) + def __init__(self, ap, duration, options=None): + super(ClientProcess, self).__init__(ap, options=options) self.duration = duration self.start_time = None self.running = False @@ -728,20 +802,14 @@ class ClientProcess(Client): opt_str = self.options if self.options is not None else "" cmd = "./startup.sh %s %s" % (self.ap, opt_str) self.running = True - self.pid = ssh_support.execute_command(self.testbed, - self.node.ssh_config, - cmd) + self.pid = self.node.execute_command(cmd) def stop(self): logger.debug( 'Killing client %s on node %s.', self.ap, self.node.name ) - ssh_support.execute_command( - self.testbed, - self.node.ssh_config, - "kill %s" % self.pid - ) + self.node.execute_command("kill %s" % self.pid) def check(self): """Check if the process should keep running, stop it if not, @@ -760,14 +828,13 @@ class ClientProcess(Client): # @ap: Application Process binary # @arrival_rate: Average requests/s to be received by this server # @mean_duration: Average duration of a client connection (in seconds) -# @testbed: the testbed for the experiment # @options: Options to pass to the binary # @max_clients: Maximum number of clients to serve # @clients: Client binaries that will use this server # @nodes: Specific nodes to start this server on # class Server: - def __init__(self, ap, arrival_rate, mean_duration, testbed, + def __init__(self, ap, arrival_rate, mean_duration, options=None, max_clients=float('inf'), clients=None, nodes=None): self.ap = ap @@ -779,7 +846,6 @@ class Server: self.nodes = nodes self.arrival_rate = arrival_rate # mean requests/s self.mean_duration = mean_duration # in seconds - self.testbed = testbed self.pids = {} def add_client(self, client): @@ -828,9 +894,7 @@ class Server: 'Starting server %s on node %s with logfile %s.', self.ap, node.name, logfile ) - self.pids[node] = (ssh_support.execute_commands(self.testbed, - node.ssh_config, - cmds)) + self.pids[node] = (node.execute_commands(cmds)) def stop(self): for node, pid in self.pids.items(): @@ -838,11 +902,7 @@ class Server: 'Killing server %s on node %s.', self.ap, node.name ) - ssh_support.execute_command( - self.testbed, - node.ssh_config, - "kill %s" % pid - ) + node.execute_command("kill %s" % pid) # Base class for ARCFIRE storyboards @@ -856,7 +916,7 @@ class StoryBoard: DEFAULT_INTERVAL = 2.5 # in seconds (may be a float) - def __init__(self, experiment, duration, testbed, servers=None): + def __init__(self, experiment, duration, servers=None): self.experiment = experiment self.duration = duration if servers is None: @@ -865,7 +925,6 @@ class StoryBoard: self.client_nodes = [c for c in experiment.nodes if c.client] self.active_clients = [] self.start_time = None - self.testbed = testbed def add_server(self, server): self.servers.append(server) @@ -878,9 +937,7 @@ class StoryBoard: script = r'nohup "$@" > /dev/null & echo "$!"' for node in self.client_nodes: logger.debug("Writing utility startup script on client nodes.") - ssh_support.execute_command( - self.testbed, - node.ssh_config, + node.execute_command( "echo '%s' > startup.sh && chmod a+x startup.sh" % (script,) ) try: -- cgit v1.2.3