diff options
author | Nick Aerts <nick.aerts@ugent.be> | 2018-02-24 12:27:36 +0100 |
---|---|---|
committer | Nick Aerts <nick.aerts@ugent.be> | 2018-03-20 11:30:07 +0100 |
commit | a7cd88d752b72ea85ccefa5e1f3dceba13fb1fc2 (patch) | |
tree | 9c29f08693d577c81959c3194aec04e9bc1ba195 /rumba/model.py | |
parent | 24bed306b5a67fc682b04cae017b0d0f3ac55a00 (diff) | |
download | rumba-a7cd88d752b72ea85ccefa5e1f3dceba13fb1fc2.tar.gz rumba-a7cd88d752b72ea85ccefa5e1f3dceba13fb1fc2.zip |
testbeds: Add docker testbed
This adds support for a testbed based on Docker containers running on
the local host. Bridging the containers can be done using built-in
Linux bridging or using OpenVSwitch bridges.
A new resource 'executor' has been added to abstract away command
execution on nodes on the testbed. Executors have been created for
local command execution, docker exec based command execution and
SSH-based command execution. This has also been changed in the
prototypes to execute using the correct executor.
Diffstat (limited to 'rumba/model.py')
-rw-r--r-- | rumba/model.py | 130 |
1 files changed, 56 insertions, 74 deletions
diff --git a/rumba/model.py b/rumba/model.py index 39528be..20f8215 100644 --- a/rumba/model.py +++ b/rumba/model.py @@ -31,7 +31,6 @@ import time import shutil import rumba.log as log -from rumba import ssh_support logger = log.get_logger(__name__) @@ -88,7 +87,8 @@ class Testbed(object): @abc.abstractmethod def swap_in(self, experiment): - raise Exception('swap_in() not implemented') + for node in experiment.nodes: + node.executor = self.executor @abc.abstractmethod def swap_out(self, experiment): @@ -245,6 +245,9 @@ class Node(object): if hasattr(dif, 'policy'): # check if the dif supports policies self.policies[dif] = policies.get(dif, Policy(dif, self)) + self.executor = None # will be set by testbed on swap_in + self.startup_command = None # will be set by prototype + self._validate() def get_ipcp_by_dif(self, dif): @@ -328,88 +331,34 @@ class Node(object): 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, as_root=False): - # Ssh_config is used twice since it doubles as testbed info - # (it holds fields username and password) - if as_root: - if self.ssh_config.username != 'root': - command = "sudo %s" % command - - 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 execute_commands(self, commands, as_root=False, time_out=3, + use_proxy=False): + return self.executor.execute_commands(self, commands, as_root, time_out) + + def execute_command(self, command, as_root=False, time_out=3, + use_proxy=False): + return self.executor.execute_command(self, command, as_root, time_out) def write_text_to_file(self, text, file_name): - ssh_support.write_text_to_file( - self.ssh_config, - self.ssh_config, - text, - file_name - ) + # ssh_support.write_text_to_file( + # self.ssh_config, + # self.ssh_config, + # text, + # file_name + # ) + return def copy_file(self, path, destination): - ssh_support.copy_file_to_testbed( - self.ssh_config, - self.ssh_config, - path, - destination - ) + self.executor.copy_file(self, path, destination) def copy_files(self, paths, destination): - ssh_support.copy_files_to_testbed( - self.ssh_config, - self.ssh_config, - paths, - destination - ) + self.executor.copy_files(self, paths, destination) def fetch_files(self, paths, destination, sudo=False): - ssh_support.copy_files_from_testbed( - self.ssh_config, - self.ssh_config, - paths, - destination, - sudo=sudo - ) + self.executor.fetch_files(self, paths, destination, sudo) def fetch_file(self, path, destination, sudo=False): - ssh_support.copy_file_from_testbed( - self.ssh_config, - self.ssh_config, - path, - destination, - sudo=sudo - ) + self.executor.fetch_files(self, path, destination, sudo) def set_link_state(self, ipcp, state): self.execute_command('ip link set dev ' + ipcp.ifname + ' ' + state, @@ -869,6 +818,10 @@ class Experiment(object): end = time.time() logger.info("Install took %.2f seconds", end - start) + def set_startup_command(self, command): + for node in self.nodes: + node.startup_command = command + def bootstrap_prototype(self): start = time.time() self._bootstrap_prototype() @@ -912,3 +865,32 @@ class Experiment(object): self.testbed.swap_out(self) end = time.time() logger.info("Swap-out took %.2f seconds", end - start) + + +class Executor: + __metaclass__ = abc.ABCMeta + + @abc.abstractmethod + def execute_command(self, node, command, as_root=False, time_out=3): + # Execute command on a node + return + + def execute_commands(self, node, commands, as_root=False, time_out=3): + for command in commands: + self.execute_command(node, command, as_root, time_out) + + @abc.abstractmethod + def copy_file(self, node, path, destination): + return + + def copy_files(self, node, paths, destination): + for path in paths: + self.copy_file(node, path, destination) + + @abc.abstractmethod + def fetch_file(self, node, path, destination, sudo=False): + return + + def fetch_files(self, node, paths, destination, sudo=False): + for path in paths: + self.fetch_file(node, path, destination, sudo)
\ No newline at end of file |