summaryrefslogtreecommitdiff
path: root/tests/cloud_tests
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2020-06-08 12:49:12 -0400
committerGitHub <noreply@github.com>2020-06-08 10:49:12 -0600
commit3c551f6ebc12f7729a2755c89b19b9000e27cc88 (patch)
tree0f7cd7ae6161791e7361e2bdffd38f414857f0c3 /tests/cloud_tests
parent30aa1197c4c4d35d4ccf77d5d8854a40aa21219f (diff)
downloadvyos-cloud-init-3c551f6ebc12f7729a2755c89b19b9000e27cc88.tar.gz
vyos-cloud-init-3c551f6ebc12f7729a2755c89b19b9000e27cc88.zip
Move subp into its own module. (#416)
This was painful, but it finishes a TODO from cloudinit/subp.py. It moves the following from util to subp: ProcessExecutionError subp which target_path I moved subp_blob_in_tempfile into cc_chef, which is its only caller. That saved us from having to deal with it using write_file and temp_utils from subp (which does not import any cloudinit things now). It is arguable that 'target_path' could be moved to a 'path_utils' or something, but in order to use it from subp and also from utils, we had to get it out of utils.
Diffstat (limited to 'tests/cloud_tests')
-rw-r--r--tests/cloud_tests/bddeb.py6
-rw-r--r--tests/cloud_tests/platforms/lxd/image.py9
-rw-r--r--tests/cloud_tests/platforms/lxd/instance.py3
-rw-r--r--tests/cloud_tests/platforms/nocloudkvm/image.py12
-rw-r--r--tests/cloud_tests/platforms/nocloudkvm/instance.py10
-rw-r--r--tests/cloud_tests/platforms/nocloudkvm/platform.py5
-rw-r--r--tests/cloud_tests/platforms/platforms.py9
-rw-r--r--tests/cloud_tests/util.py7
8 files changed, 33 insertions, 28 deletions
diff --git a/tests/cloud_tests/bddeb.py b/tests/cloud_tests/bddeb.py
index f04d0cd4..6f74436d 100644
--- a/tests/cloud_tests/bddeb.py
+++ b/tests/cloud_tests/bddeb.py
@@ -6,7 +6,7 @@ from functools import partial
import os
import tempfile
-from cloudinit import util as c_util
+from cloudinit import subp
from tests.cloud_tests import (config, LOG)
from tests.cloud_tests import platforms
from tests.cloud_tests.stage import (PlatformComponent, run_stage, run_single)
@@ -42,8 +42,8 @@ def build_deb(args, instance):
'GIT_WORK_TREE': extract_dir}
LOG.debug('creating tarball of cloud-init at: %s', local_tarball)
- c_util.subp(['tar', 'cf', local_tarball, '--owner', 'root',
- '--group', 'root', '-C', args.cloud_init, '.'])
+ subp.subp(['tar', 'cf', local_tarball, '--owner', 'root',
+ '--group', 'root', '-C', args.cloud_init, '.'])
LOG.debug('copying to remote system at: %s', remote_tarball)
instance.push_file(local_tarball, remote_tarball)
diff --git a/tests/cloud_tests/platforms/lxd/image.py b/tests/cloud_tests/platforms/lxd/image.py
index b5de1f52..8934fb74 100644
--- a/tests/cloud_tests/platforms/lxd/image.py
+++ b/tests/cloud_tests/platforms/lxd/image.py
@@ -8,6 +8,7 @@ import tempfile
from ..images import Image
from .snapshot import LXDSnapshot
+from cloudinit import subp
from cloudinit import util as c_util
from tests.cloud_tests import util
@@ -81,8 +82,8 @@ class LXDImage(Image):
@return_value: tuple of path to metadata tarball and rootfs tarball
"""
# pylxd's image export feature doesn't do split exports, so use cmdline
- c_util.subp(['lxc', 'image', 'export', self.pylxd_image.fingerprint,
- output_dir], capture=True)
+ subp.subp(['lxc', 'image', 'export', self.pylxd_image.fingerprint,
+ output_dir], capture=True)
tarballs = [p for p in os.listdir(output_dir) if p.endswith('tar.xz')]
metadata = os.path.join(
output_dir, next(p for p in tarballs if p.startswith('meta-')))
@@ -101,8 +102,8 @@ class LXDImage(Image):
"""
alias = util.gen_instance_name(
image_desc=str(self), use_desc='update-metadata')
- c_util.subp(['lxc', 'image', 'import', metadata, rootfs,
- '--alias', alias], capture=True)
+ subp.subp(['lxc', 'image', 'import', metadata, rootfs,
+ '--alias', alias], capture=True)
self.pylxd_image = self.platform.query_image_by_alias(alias)
return self.pylxd_image.fingerprint
diff --git a/tests/cloud_tests/platforms/lxd/instance.py b/tests/cloud_tests/platforms/lxd/instance.py
index 2b804a62..b27b9848 100644
--- a/tests/cloud_tests/platforms/lxd/instance.py
+++ b/tests/cloud_tests/platforms/lxd/instance.py
@@ -7,7 +7,8 @@ import shutil
import time
from tempfile import mkdtemp
-from cloudinit.util import load_yaml, subp, ProcessExecutionError, which
+from cloudinit.subp import subp, ProcessExecutionError, which
+from cloudinit.util import load_yaml
from tests.cloud_tests import LOG
from tests.cloud_tests.util import PlatformError
diff --git a/tests/cloud_tests/platforms/nocloudkvm/image.py b/tests/cloud_tests/platforms/nocloudkvm/image.py
index bc2b6e75..ff5b6ad7 100644
--- a/tests/cloud_tests/platforms/nocloudkvm/image.py
+++ b/tests/cloud_tests/platforms/nocloudkvm/image.py
@@ -2,7 +2,7 @@
"""NoCloud KVM Image Base Class."""
-from cloudinit import util as c_util
+from cloudinit import subp
import os
import shutil
@@ -30,8 +30,8 @@ class NoCloudKVMImage(Image):
self._img_path = os.path.join(self._workd,
os.path.basename(self._orig_img_path))
- c_util.subp(['qemu-img', 'create', '-f', 'qcow2',
- '-b', orig_img_path, self._img_path])
+ subp.subp(['qemu-img', 'create', '-f', 'qcow2',
+ '-b', orig_img_path, self._img_path])
super(NoCloudKVMImage, self).__init__(platform, config)
@@ -50,10 +50,10 @@ class NoCloudKVMImage(Image):
'--system-resolvconf', self._img_path,
'--', 'chroot', '_MOUNTPOINT_']
try:
- out, err = c_util.subp(mic_chroot + env_args + list(command),
- data=stdin, decode=False)
+ out, err = subp.subp(mic_chroot + env_args + list(command),
+ data=stdin, decode=False)
return (out, err, 0)
- except c_util.ProcessExecutionError as e:
+ except subp.ProcessExecutionError as e:
return (e.stdout, e.stderr, e.exit_code)
def snapshot(self):
diff --git a/tests/cloud_tests/platforms/nocloudkvm/instance.py b/tests/cloud_tests/platforms/nocloudkvm/instance.py
index 96185b75..5140a11c 100644
--- a/tests/cloud_tests/platforms/nocloudkvm/instance.py
+++ b/tests/cloud_tests/platforms/nocloudkvm/instance.py
@@ -11,7 +11,7 @@ import uuid
from ..instances import Instance
from cloudinit.atomic_helper import write_json
-from cloudinit import util as c_util
+from cloudinit import subp
from tests.cloud_tests import LOG, util
# This domain contains reverse lookups for hostnames that are used.
@@ -110,8 +110,8 @@ class NoCloudKVMInstance(Instance):
"""Clean up instance."""
if self.pid:
try:
- c_util.subp(['kill', '-9', self.pid])
- except c_util.ProcessExecutionError:
+ subp.subp(['kill', '-9', self.pid])
+ except subp.ProcessExecutionError:
pass
if self.pid_file:
@@ -143,8 +143,8 @@ class NoCloudKVMInstance(Instance):
# meta-data can be yaml, but more easily pretty printed with json
write_json(meta_data_file, self.meta_data)
- c_util.subp(['cloud-localds', seed_file, user_data_file,
- meta_data_file])
+ subp.subp(['cloud-localds', seed_file, user_data_file,
+ meta_data_file])
return seed_file
diff --git a/tests/cloud_tests/platforms/nocloudkvm/platform.py b/tests/cloud_tests/platforms/nocloudkvm/platform.py
index 2d1480f5..53c8ebf2 100644
--- a/tests/cloud_tests/platforms/nocloudkvm/platform.py
+++ b/tests/cloud_tests/platforms/nocloudkvm/platform.py
@@ -12,6 +12,7 @@ from simplestreams import util as s_util
from ..platforms import Platform
from .image import NoCloudKVMImage
from .instance import NoCloudKVMInstance
+from cloudinit import subp
from cloudinit import util as c_util
from tests.cloud_tests import util
@@ -84,8 +85,8 @@ class NoCloudKVMPlatform(Platform):
"""
name = util.gen_instance_name(image_desc=image_desc, use_desc=use_desc)
img_path = os.path.join(self.config['data_dir'], name + '.qcow2')
- c_util.subp(['qemu-img', 'create', '-f', 'qcow2',
- '-b', src_img_path, img_path])
+ subp.subp(['qemu-img', 'create', '-f', 'qcow2',
+ '-b', src_img_path, img_path])
return NoCloudKVMInstance(self, name, img_path, properties, config,
features, user_data, meta_data)
diff --git a/tests/cloud_tests/platforms/platforms.py b/tests/cloud_tests/platforms/platforms.py
index bebdf1c6..58f65e52 100644
--- a/tests/cloud_tests/platforms/platforms.py
+++ b/tests/cloud_tests/platforms/platforms.py
@@ -7,6 +7,7 @@ import shutil
from simplestreams import filters, mirrors
from simplestreams import util as s_util
+from cloudinit import subp
from cloudinit import util as c_util
from tests.cloud_tests import util
@@ -48,10 +49,10 @@ class Platform(object):
if os.path.exists(filename):
c_util.del_file(filename)
- c_util.subp(['ssh-keygen', '-m', 'PEM', '-t', 'rsa', '-b', '4096',
- '-f', filename, '-P', '',
- '-C', 'ubuntu@cloud_test'],
- capture=True)
+ subp.subp(['ssh-keygen', '-m', 'PEM', '-t', 'rsa', '-b', '4096',
+ '-f', filename, '-P', '',
+ '-C', 'ubuntu@cloud_test'],
+ capture=True)
@staticmethod
def _query_streams(img_conf, img_filter):
diff --git a/tests/cloud_tests/util.py b/tests/cloud_tests/util.py
index e65771b1..7dcccbdd 100644
--- a/tests/cloud_tests/util.py
+++ b/tests/cloud_tests/util.py
@@ -17,6 +17,7 @@ import time
import yaml
from contextlib import contextmanager
+from cloudinit import subp
from cloudinit import util as c_util
from tests.cloud_tests import LOG
@@ -232,8 +233,8 @@ def flat_tar(output, basedir, owner='root', group='root'):
@param group: group archive files belong to
@return_value: none
"""
- c_util.subp(['tar', 'cf', output, '--owner', owner, '--group', group,
- '-C', basedir] + rel_files(basedir), capture=True)
+ subp.subp(['tar', 'cf', output, '--owner', owner, '--group', group,
+ '-C', basedir] + rel_files(basedir), capture=True)
def parse_conf_list(entries, valid=None, boolean=False):
@@ -465,7 +466,7 @@ class TargetBase(object):
return path
-class InTargetExecuteError(c_util.ProcessExecutionError):
+class InTargetExecuteError(subp.ProcessExecutionError):
"""Error type for in target commands that fail."""
default_desc = 'Unexpected error while running command.'