diff options
author | Chad Smith <chad.smith@canonical.com> | 2017-11-21 11:43:26 -0700 |
---|---|---|
committer | Chad Smith <chad.smith@canonical.com> | 2017-11-21 11:43:26 -0700 |
commit | 5b974bbab161e6cd73751bf27b7741f6b0d19051 (patch) | |
tree | f634411a9b12b2e36ff8beefbec39dad21cd45ea /tests/cloud_tests/instances/base.py | |
parent | c9c7ff70f55ee024dd54336f07ba52acec1f6929 (diff) | |
parent | 7624348712b4502f0085d30c05b34dce3f2ceeae (diff) | |
download | vyos-cloud-init-5b974bbab161e6cd73751bf27b7741f6b0d19051.tar.gz vyos-cloud-init-5b974bbab161e6cd73751bf27b7741f6b0d19051.zip |
merge from 7624348712b4502f0085d30c05b34dce3f2ceeae at 17.1-41-g76243487
Diffstat (limited to 'tests/cloud_tests/instances/base.py')
-rw-r--r-- | tests/cloud_tests/instances/base.py | 81 |
1 files changed, 4 insertions, 77 deletions
diff --git a/tests/cloud_tests/instances/base.py b/tests/cloud_tests/instances/base.py index 9bdda608..8c59d62c 100644 --- a/tests/cloud_tests/instances/base.py +++ b/tests/cloud_tests/instances/base.py @@ -2,8 +2,10 @@ """Base instance.""" +from ..util import TargetBase -class Instance(object): + +class Instance(TargetBase): """Base instance object.""" platform_name = None @@ -22,82 +24,7 @@ class Instance(object): self.properties = properties self.config = config self.features = features - - def execute(self, command, stdout=None, stderr=None, env=None, - rcs=None, description=None): - """Execute command in instance, recording output, error and exit code. - - Assumes functional networking and execution as root with the - target filesystem being available at /. - - @param command: the command to execute as root inside the image - if command is a string, then it will be executed as: - ['sh', '-c', command] - @param stdout, stderr: file handles to write output and error to - @param env: environment variables - @param rcs: allowed return codes from command - @param description: purpose of command - @return_value: tuple containing stdout data, stderr data, exit code - """ - raise NotImplementedError - - def read_data(self, remote_path, decode=False): - """Read data from instance filesystem. - - @param remote_path: path in instance - @param decode: return as string - @return_value: data as str or bytes - """ - raise NotImplementedError - - def write_data(self, remote_path, data): - """Write data to instance filesystem. - - @param remote_path: path in instance - @param data: data to write, either str or bytes - """ - raise NotImplementedError - - def pull_file(self, remote_path, local_path): - """Copy file at 'remote_path', from instance to 'local_path'. - - @param remote_path: path on remote instance - @param local_path: path on local instance - """ - with open(local_path, 'wb') as fp: - fp.write(self.read_data(remote_path)) - - def push_file(self, local_path, remote_path): - """Copy file at 'local_path' to instance at 'remote_path'. - - @param local_path: path on local instance - @param remote_path: path on remote instance - """ - with open(local_path, 'rb') as fp: - self.write_data(remote_path, fp.read()) - - def run_script(self, script, rcs=None, description=None): - """Run script in target and return stdout. - - @param script: script contents - @param rcs: allowed return codes from script - @param description: purpose of script - @return_value: stdout from script - """ - script_path = self.tmpfile() - try: - self.write_data(script_path, script) - return self.execute( - ['/bin/bash', script_path], rcs=rcs, description=description) - finally: - self.execute(['rm', '-f', script_path], rcs=rcs) - - def tmpfile(self): - """Get a tmp file in the target. - - @return_value: path to new file in target - """ - return self.execute(['mktemp'])[0].strip() + self._tmp_count = 0 def console_log(self): """Instance console. |