More test ports from mocker to mock.
This commit is contained in:
parent
f4cf5c2618
commit
0cf30251e8
@ -1,6 +1,13 @@
|
|||||||
"""Tests of the built-in user data handlers."""
|
"""Tests of the built-in user data handlers."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
try:
|
||||||
|
from unittest import mock
|
||||||
|
except ImportError:
|
||||||
|
import mock
|
||||||
|
|
||||||
from . import helpers as test_helpers
|
from . import helpers as test_helpers
|
||||||
|
|
||||||
@ -16,8 +23,10 @@ from cloudinit.settings import (PER_ALWAYS, PER_INSTANCE)
|
|||||||
class TestBuiltins(test_helpers.FilesystemMockingTestCase):
|
class TestBuiltins(test_helpers.FilesystemMockingTestCase):
|
||||||
|
|
||||||
def test_upstart_frequency_no_out(self):
|
def test_upstart_frequency_no_out(self):
|
||||||
c_root = self.makeDir()
|
c_root = tempfile.mkdtemp()
|
||||||
up_root = self.makeDir()
|
self.addCleanup(shutil.rmtree, c_root)
|
||||||
|
up_root = tempfile.mkdtemp()
|
||||||
|
self.addCleanup(shutil.rmtree, up_root)
|
||||||
paths = helpers.Paths({
|
paths = helpers.Paths({
|
||||||
'cloud_dir': c_root,
|
'cloud_dir': c_root,
|
||||||
'upstart_dir': up_root,
|
'upstart_dir': up_root,
|
||||||
@ -36,7 +45,8 @@ class TestBuiltins(test_helpers.FilesystemMockingTestCase):
|
|||||||
|
|
||||||
def test_upstart_frequency_single(self):
|
def test_upstart_frequency_single(self):
|
||||||
# files should be written out when frequency is ! per-instance
|
# files should be written out when frequency is ! per-instance
|
||||||
new_root = self.makeDir()
|
new_root = tempfile.mkdtemp()
|
||||||
|
self.addCleanup(shutil.rmtree, new_root)
|
||||||
freq = PER_INSTANCE
|
freq = PER_INSTANCE
|
||||||
|
|
||||||
self.patchOS(new_root)
|
self.patchOS(new_root)
|
||||||
@ -49,16 +59,16 @@ class TestBuiltins(test_helpers.FilesystemMockingTestCase):
|
|||||||
util.ensure_dir("/run")
|
util.ensure_dir("/run")
|
||||||
util.ensure_dir("/etc/upstart")
|
util.ensure_dir("/etc/upstart")
|
||||||
|
|
||||||
mock_subp = self.mocker.replace(util.subp, passthrough=False)
|
with mock.patch.object(util, 'subp') as mockobj:
|
||||||
mock_subp(["initctl", "reload-configuration"], capture=False)
|
h = upstart_job.UpstartJobPartHandler(paths)
|
||||||
self.mocker.replay()
|
h.handle_part('', handlers.CONTENT_START,
|
||||||
|
None, None, None)
|
||||||
|
h.handle_part('blah', 'text/upstart-job',
|
||||||
|
'test.conf', 'blah', freq)
|
||||||
|
h.handle_part('', handlers.CONTENT_END,
|
||||||
|
None, None, None)
|
||||||
|
|
||||||
h = upstart_job.UpstartJobPartHandler(paths)
|
self.assertEquals(len(os.listdir('/etc/upstart')), 1)
|
||||||
h.handle_part('', handlers.CONTENT_START,
|
|
||||||
None, None, None)
|
|
||||||
h.handle_part('blah', 'text/upstart-job',
|
|
||||||
'test.conf', 'blah', freq)
|
|
||||||
h.handle_part('', handlers.CONTENT_END,
|
|
||||||
None, None, None)
|
|
||||||
|
|
||||||
self.assertEquals(1, len(os.listdir('/etc/upstart')))
|
mockobj.assert_called_once_with(
|
||||||
|
['initctl', 'reload-configuration'], capture=False)
|
||||||
|
@ -55,7 +55,6 @@ class TestConsumeUserData(helpers.FilesystemMockingTestCase):
|
|||||||
helpers.FilesystemMockingTestCase.tearDown(self)
|
helpers.FilesystemMockingTestCase.tearDown(self)
|
||||||
|
|
||||||
def _patchIn(self, root):
|
def _patchIn(self, root):
|
||||||
self.restore()
|
|
||||||
self.patchOS(root)
|
self.patchOS(root)
|
||||||
self.patchUtils(root)
|
self.patchUtils(root)
|
||||||
|
|
||||||
@ -349,17 +348,17 @@ p: 1
|
|||||||
data = "arbitrary text\n"
|
data = "arbitrary text\n"
|
||||||
ci.datasource = FakeDataSource(data)
|
ci.datasource = FakeDataSource(data)
|
||||||
|
|
||||||
mock_write = self.mocker.replace("cloudinit.util.write_file",
|
with mock.patch('cloudinit.util.write_file') as mockobj:
|
||||||
passthrough=False)
|
log_file = self.capture_log(logging.WARNING)
|
||||||
mock_write(ci.paths.get_ipath("cloud_config"), "", 0o600)
|
ci.fetch()
|
||||||
self.mocker.replay()
|
ci.consume_data()
|
||||||
|
self.assertIn(
|
||||||
|
"Unhandled non-multipart (text/x-not-multipart) userdata:",
|
||||||
|
log_file.getvalue())
|
||||||
|
|
||||||
|
mockobj.assert_called_once_with(
|
||||||
|
ci.paths.get_ipath("cloud_config"), "", 0o600)
|
||||||
|
|
||||||
log_file = self.capture_log(logging.WARNING)
|
|
||||||
ci.fetch()
|
|
||||||
ci.consume_data()
|
|
||||||
self.assertIn(
|
|
||||||
"Unhandled non-multipart (text/x-not-multipart) userdata:",
|
|
||||||
log_file.getvalue())
|
|
||||||
|
|
||||||
def test_mime_gzip_compressed(self):
|
def test_mime_gzip_compressed(self):
|
||||||
"""Tests that individual message gzip encoding works."""
|
"""Tests that individual message gzip encoding works."""
|
||||||
|
@ -1,10 +1,18 @@
|
|||||||
from copy import copy
|
from copy import copy
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import os.path
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
import unittest
|
||||||
|
|
||||||
import mocker
|
try:
|
||||||
from mocker import MockerTestCase
|
from unittest import mock
|
||||||
|
except ImportError:
|
||||||
|
import mock
|
||||||
|
try:
|
||||||
|
from contextlib import ExitStack
|
||||||
|
except ImportError:
|
||||||
|
from contextlib2 import ExitStack
|
||||||
|
|
||||||
from cloudinit import helpers
|
from cloudinit import helpers
|
||||||
from cloudinit import settings
|
from cloudinit import settings
|
||||||
@ -12,8 +20,6 @@ from cloudinit.sources import DataSourceConfigDrive as ds
|
|||||||
from cloudinit.sources.helpers import openstack
|
from cloudinit.sources.helpers import openstack
|
||||||
from cloudinit import util
|
from cloudinit import util
|
||||||
|
|
||||||
from .. import helpers as unit_helpers
|
|
||||||
|
|
||||||
PUBKEY = u'ssh-rsa AAAAB3NzaC1....sIkJhq8wdX+4I3A4cYbYP ubuntu@server-460\n'
|
PUBKEY = u'ssh-rsa AAAAB3NzaC1....sIkJhq8wdX+4I3A4cYbYP ubuntu@server-460\n'
|
||||||
EC2_META = {
|
EC2_META = {
|
||||||
'ami-id': 'ami-00000001',
|
'ami-id': 'ami-00000001',
|
||||||
@ -64,11 +70,12 @@ CFG_DRIVE_FILES_V2 = {
|
|||||||
'openstack/latest/user_data': USER_DATA}
|
'openstack/latest/user_data': USER_DATA}
|
||||||
|
|
||||||
|
|
||||||
class TestConfigDriveDataSource(MockerTestCase):
|
class TestConfigDriveDataSource(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestConfigDriveDataSource, self).setUp()
|
super(TestConfigDriveDataSource, self).setUp()
|
||||||
self.tmp = self.makeDir()
|
self.tmp = tempfile.mkdtemp()
|
||||||
|
self.addCleanup(shutil.rmtree, self.tmp)
|
||||||
|
|
||||||
def test_ec2_metadata(self):
|
def test_ec2_metadata(self):
|
||||||
populate_dir(self.tmp, CFG_DRIVE_FILES_V2)
|
populate_dir(self.tmp, CFG_DRIVE_FILES_V2)
|
||||||
@ -91,23 +98,28 @@ class TestConfigDriveDataSource(MockerTestCase):
|
|||||||
'swap': '/dev/vda3',
|
'swap': '/dev/vda3',
|
||||||
}
|
}
|
||||||
for name, dev_name in name_tests.items():
|
for name, dev_name in name_tests.items():
|
||||||
with unit_helpers.mocker() as my_mock:
|
with ExitStack() as mocks:
|
||||||
find_mock = my_mock.replace(util.find_devs_with,
|
|
||||||
spec=False, passthrough=False)
|
|
||||||
provided_name = dev_name[len('/dev/'):]
|
provided_name = dev_name[len('/dev/'):]
|
||||||
provided_name = "s" + provided_name[1:]
|
provided_name = "s" + provided_name[1:]
|
||||||
find_mock(mocker.ARGS)
|
find_mock = mocks.enter_context(
|
||||||
my_mock.result([provided_name])
|
mock.patch.object(util, 'find_devs_with',
|
||||||
exists_mock = my_mock.replace(os.path.exists,
|
return_value=[provided_name]))
|
||||||
spec=False, passthrough=False)
|
# We want os.path.exists() to return False on its first call,
|
||||||
exists_mock(mocker.ARGS)
|
# and True on its second call. We use a handy generator as
|
||||||
my_mock.result(False)
|
# the mock side effect for this. The mocked function returns
|
||||||
exists_mock(mocker.ARGS)
|
# what the side effect returns.
|
||||||
my_mock.result(True)
|
def exists_side_effect():
|
||||||
my_mock.replay()
|
yield False
|
||||||
|
yield True
|
||||||
|
exists_mock = mocks.enter_context(
|
||||||
|
mock.patch.object(os.path, 'exists',
|
||||||
|
side_effect=exists_side_effect()))
|
||||||
device = cfg_ds.device_name_to_device(name)
|
device = cfg_ds.device_name_to_device(name)
|
||||||
self.assertEquals(dev_name, device)
|
self.assertEquals(dev_name, device)
|
||||||
|
|
||||||
|
find_mock.assert_called_once_with(mock.ANY)
|
||||||
|
self.assertEqual(exists_mock.call_count, 2)
|
||||||
|
|
||||||
def test_dev_os_map(self):
|
def test_dev_os_map(self):
|
||||||
populate_dir(self.tmp, CFG_DRIVE_FILES_V2)
|
populate_dir(self.tmp, CFG_DRIVE_FILES_V2)
|
||||||
cfg_ds = ds.DataSourceConfigDrive(settings.CFG_BUILTIN,
|
cfg_ds = ds.DataSourceConfigDrive(settings.CFG_BUILTIN,
|
||||||
@ -123,19 +135,19 @@ class TestConfigDriveDataSource(MockerTestCase):
|
|||||||
'swap': '/dev/vda3',
|
'swap': '/dev/vda3',
|
||||||
}
|
}
|
||||||
for name, dev_name in name_tests.items():
|
for name, dev_name in name_tests.items():
|
||||||
with unit_helpers.mocker() as my_mock:
|
with ExitStack() as mocks:
|
||||||
find_mock = my_mock.replace(util.find_devs_with,
|
find_mock = mocks.enter_context(
|
||||||
spec=False, passthrough=False)
|
mock.patch.object(util, 'find_devs_with',
|
||||||
find_mock(mocker.ARGS)
|
return_value=[dev_name]))
|
||||||
my_mock.result([dev_name])
|
exists_mock = mocks.enter_context(
|
||||||
exists_mock = my_mock.replace(os.path.exists,
|
mock.patch.object(os.path, 'exists',
|
||||||
spec=False, passthrough=False)
|
return_value=True))
|
||||||
exists_mock(mocker.ARGS)
|
|
||||||
my_mock.result(True)
|
|
||||||
my_mock.replay()
|
|
||||||
device = cfg_ds.device_name_to_device(name)
|
device = cfg_ds.device_name_to_device(name)
|
||||||
self.assertEquals(dev_name, device)
|
self.assertEquals(dev_name, device)
|
||||||
|
|
||||||
|
find_mock.assert_called_once_with(mock.ANY)
|
||||||
|
exists_mock.assert_called_once_with(mock.ANY)
|
||||||
|
|
||||||
def test_dev_ec2_remap(self):
|
def test_dev_ec2_remap(self):
|
||||||
populate_dir(self.tmp, CFG_DRIVE_FILES_V2)
|
populate_dir(self.tmp, CFG_DRIVE_FILES_V2)
|
||||||
cfg_ds = ds.DataSourceConfigDrive(settings.CFG_BUILTIN,
|
cfg_ds = ds.DataSourceConfigDrive(settings.CFG_BUILTIN,
|
||||||
@ -156,16 +168,21 @@ class TestConfigDriveDataSource(MockerTestCase):
|
|||||||
'root2k': None,
|
'root2k': None,
|
||||||
}
|
}
|
||||||
for name, dev_name in name_tests.items():
|
for name, dev_name in name_tests.items():
|
||||||
with unit_helpers.mocker(verify_calls=False) as my_mock:
|
# We want os.path.exists() to return False on its first call,
|
||||||
exists_mock = my_mock.replace(os.path.exists,
|
# and True on its second call. We use a handy generator as
|
||||||
spec=False, passthrough=False)
|
# the mock side effect for this. The mocked function returns
|
||||||
exists_mock(mocker.ARGS)
|
# what the side effect returns.
|
||||||
my_mock.result(False)
|
def exists_side_effect():
|
||||||
exists_mock(mocker.ARGS)
|
yield False
|
||||||
my_mock.result(True)
|
yield True
|
||||||
my_mock.replay()
|
with mock.patch.object(os.path, 'exists',
|
||||||
|
side_effect=exists_side_effect()):
|
||||||
device = cfg_ds.device_name_to_device(name)
|
device = cfg_ds.device_name_to_device(name)
|
||||||
self.assertEquals(dev_name, device)
|
self.assertEquals(dev_name, device)
|
||||||
|
# We don't assert the call count for os.path.exists() because
|
||||||
|
# not all of the entries in name_tests results in two calls to
|
||||||
|
# that function. Specifically, 'root2k' doesn't seem to call
|
||||||
|
# it at all.
|
||||||
|
|
||||||
def test_dev_ec2_map(self):
|
def test_dev_ec2_map(self):
|
||||||
populate_dir(self.tmp, CFG_DRIVE_FILES_V2)
|
populate_dir(self.tmp, CFG_DRIVE_FILES_V2)
|
||||||
@ -173,12 +190,6 @@ class TestConfigDriveDataSource(MockerTestCase):
|
|||||||
None,
|
None,
|
||||||
helpers.Paths({}))
|
helpers.Paths({}))
|
||||||
found = ds.read_config_drive(self.tmp)
|
found = ds.read_config_drive(self.tmp)
|
||||||
exists_mock = self.mocker.replace(os.path.exists,
|
|
||||||
spec=False, passthrough=False)
|
|
||||||
exists_mock(mocker.ARGS)
|
|
||||||
self.mocker.count(0, None)
|
|
||||||
self.mocker.result(True)
|
|
||||||
self.mocker.replay()
|
|
||||||
ec2_md = found['ec2-metadata']
|
ec2_md = found['ec2-metadata']
|
||||||
os_md = found['metadata']
|
os_md = found['metadata']
|
||||||
cfg_ds.ec2_metadata = ec2_md
|
cfg_ds.ec2_metadata = ec2_md
|
||||||
@ -193,8 +204,9 @@ class TestConfigDriveDataSource(MockerTestCase):
|
|||||||
'root2k': None,
|
'root2k': None,
|
||||||
}
|
}
|
||||||
for name, dev_name in name_tests.items():
|
for name, dev_name in name_tests.items():
|
||||||
device = cfg_ds.device_name_to_device(name)
|
with mock.patch.object(os.path, 'exists', return_value=True):
|
||||||
self.assertEquals(dev_name, device)
|
device = cfg_ds.device_name_to_device(name)
|
||||||
|
self.assertEquals(dev_name, device)
|
||||||
|
|
||||||
def test_dir_valid(self):
|
def test_dir_valid(self):
|
||||||
"""Verify a dir is read as such."""
|
"""Verify a dir is read as such."""
|
||||||
|
@ -1,19 +1,26 @@
|
|||||||
from copy import copy
|
from copy import copy
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
import unittest
|
||||||
|
|
||||||
from cloudinit.sources import DataSourceMAAS
|
from cloudinit.sources import DataSourceMAAS
|
||||||
from cloudinit import url_helper
|
from cloudinit import url_helper
|
||||||
from ..helpers import populate_dir
|
from ..helpers import populate_dir
|
||||||
|
|
||||||
import mocker
|
try:
|
||||||
|
from unittest import mock
|
||||||
|
except ImportError:
|
||||||
|
import mock
|
||||||
|
|
||||||
|
|
||||||
class TestMAASDataSource(mocker.MockerTestCase):
|
class TestMAASDataSource(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestMAASDataSource, self).setUp()
|
super(TestMAASDataSource, self).setUp()
|
||||||
# Make a temp directoy for tests to use.
|
# Make a temp directoy for tests to use.
|
||||||
self.tmp = self.makeDir()
|
self.tmp = tempfile.mkdtemp()
|
||||||
|
self.addCleanup(shutil.rmtree, self.tmp)
|
||||||
|
|
||||||
def test_seed_dir_valid(self):
|
def test_seed_dir_valid(self):
|
||||||
"""Verify a valid seeddir is read as such."""
|
"""Verify a valid seeddir is read as such."""
|
||||||
@ -93,16 +100,18 @@ class TestMAASDataSource(mocker.MockerTestCase):
|
|||||||
|
|
||||||
def test_seed_url_valid(self):
|
def test_seed_url_valid(self):
|
||||||
"""Verify that valid seed_url is read as such."""
|
"""Verify that valid seed_url is read as such."""
|
||||||
valid = {'meta-data/instance-id': 'i-instanceid',
|
valid = {
|
||||||
|
'meta-data/instance-id': 'i-instanceid',
|
||||||
'meta-data/local-hostname': 'test-hostname',
|
'meta-data/local-hostname': 'test-hostname',
|
||||||
'meta-data/public-keys': 'test-hostname',
|
'meta-data/public-keys': 'test-hostname',
|
||||||
'user-data': 'foodata'}
|
'user-data': 'foodata',
|
||||||
|
}
|
||||||
valid_order = [
|
valid_order = [
|
||||||
'meta-data/local-hostname',
|
'meta-data/local-hostname',
|
||||||
'meta-data/instance-id',
|
'meta-data/instance-id',
|
||||||
'meta-data/public-keys',
|
'meta-data/public-keys',
|
||||||
'user-data',
|
'user-data',
|
||||||
]
|
]
|
||||||
my_seed = "http://example.com/xmeta"
|
my_seed = "http://example.com/xmeta"
|
||||||
my_ver = "1999-99-99"
|
my_ver = "1999-99-99"
|
||||||
my_headers = {'header1': 'value1', 'header2': 'value2'}
|
my_headers = {'header1': 'value1', 'header2': 'value2'}
|
||||||
@ -110,28 +119,38 @@ class TestMAASDataSource(mocker.MockerTestCase):
|
|||||||
def my_headers_cb(url):
|
def my_headers_cb(url):
|
||||||
return my_headers
|
return my_headers
|
||||||
|
|
||||||
mock_request = self.mocker.replace(url_helper.readurl,
|
# Each time url_helper.readurl() is called, something different is
|
||||||
passthrough=False)
|
# returned based on the canned data above. We need to build up a list
|
||||||
|
# of side effect return values, which the mock will return. At the
|
||||||
|
# same time, we'll build up a list of expected call arguments for
|
||||||
|
# asserting after the code under test is run.
|
||||||
|
calls = []
|
||||||
|
|
||||||
for key in valid_order:
|
def side_effect():
|
||||||
url = "%s/%s/%s" % (my_seed, my_ver, key)
|
for key in valid_order:
|
||||||
mock_request(url, headers=None, timeout=mocker.ANY,
|
resp = valid.get(key)
|
||||||
data=mocker.ANY, sec_between=mocker.ANY,
|
url = "%s/%s/%s" % (my_seed, my_ver, key)
|
||||||
ssl_details=mocker.ANY, retries=mocker.ANY,
|
calls.append(
|
||||||
headers_cb=my_headers_cb,
|
mock.call(url, headers=None, timeout=mock.ANY,
|
||||||
exception_cb=mocker.ANY)
|
data=mock.ANY, sec_between=mock.ANY,
|
||||||
resp = valid.get(key)
|
ssl_details=mock.ANY, retries=mock.ANY,
|
||||||
self.mocker.result(url_helper.StringResponse(resp))
|
headers_cb=my_headers_cb,
|
||||||
self.mocker.replay()
|
exception_cb=mock.ANY))
|
||||||
|
yield url_helper.StringResponse(resp)
|
||||||
|
|
||||||
(userdata, metadata) = DataSourceMAAS.read_maas_seed_url(my_seed,
|
# Now do the actual call of the code under test.
|
||||||
header_cb=my_headers_cb, version=my_ver)
|
with mock.patch.object(url_helper, 'readurl',
|
||||||
|
side_effect=side_effect()) as mockobj:
|
||||||
|
userdata, metadata = DataSourceMAAS.read_maas_seed_url(
|
||||||
|
my_seed, header_cb=my_headers_cb, version=my_ver)
|
||||||
|
|
||||||
self.assertEqual("foodata", userdata)
|
self.assertEqual("foodata", userdata)
|
||||||
self.assertEqual(metadata['instance-id'],
|
self.assertEqual(metadata['instance-id'],
|
||||||
valid['meta-data/instance-id'])
|
valid['meta-data/instance-id'])
|
||||||
self.assertEqual(metadata['local-hostname'],
|
self.assertEqual(metadata['local-hostname'],
|
||||||
valid['meta-data/local-hostname'])
|
valid['meta-data/local-hostname'])
|
||||||
|
|
||||||
|
mockobj.has_calls(calls)
|
||||||
|
|
||||||
def test_seed_url_invalid(self):
|
def test_seed_url_invalid(self):
|
||||||
"""Verify that invalid seed_url raises MAASSeedDirMalformed."""
|
"""Verify that invalid seed_url raises MAASSeedDirMalformed."""
|
||||||
|
@ -29,9 +29,12 @@ from .. import helpers
|
|||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import re
|
import re
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
import stat
|
import stat
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
|
||||||
MOCK_RETURNS = {
|
MOCK_RETURNS = {
|
||||||
'hostname': 'test-host',
|
'hostname': 'test-host',
|
||||||
'root_authorized_keys': 'ssh-rsa AAAAB3Nz...aC1yc2E= keyname',
|
'root_authorized_keys': 'ssh-rsa AAAAB3Nz...aC1yc2E= keyname',
|
||||||
@ -109,9 +112,10 @@ class TestSmartOSDataSource(helpers.FilesystemMockingTestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
helpers.FilesystemMockingTestCase.setUp(self)
|
helpers.FilesystemMockingTestCase.setUp(self)
|
||||||
|
|
||||||
# makeDir comes from MockerTestCase
|
self.tmp = tempfile.mkdtemp()
|
||||||
self.tmp = self.makeDir()
|
self.addCleanup(shutil.rmtree, self.tmp)
|
||||||
self.legacy_user_d = self.makeDir()
|
self.legacy_user_d = tempfile.mkdtemp()
|
||||||
|
self.addCleanup(shutil.rmtree, self.legacy_user_d)
|
||||||
|
|
||||||
# If you should want to watch the logs...
|
# If you should want to watch the logs...
|
||||||
self._log = None
|
self._log = None
|
||||||
|
@ -4,6 +4,8 @@ from cloudinit import util
|
|||||||
from .. import helpers
|
from .. import helpers
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
|
||||||
unknown_arch_info = {
|
unknown_arch_info = {
|
||||||
'arches': ['default'],
|
'arches': ['default'],
|
||||||
@ -53,7 +55,8 @@ class TestGenericDistro(helpers.FilesystemMockingTestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestGenericDistro, self).setUp()
|
super(TestGenericDistro, self).setUp()
|
||||||
# Make a temp directoy for tests to use.
|
# Make a temp directoy for tests to use.
|
||||||
self.tmp = self.makeDir()
|
self.tmp = tempfile.mkdtemp()
|
||||||
|
self.addCleanup(shutil.rmtree, self.tmp)
|
||||||
|
|
||||||
def _write_load_sudoers(self, _user, rules):
|
def _write_load_sudoers(self, _user, rules):
|
||||||
cls = distros.fetch("ubuntu")
|
cls = distros.fetch("ubuntu")
|
||||||
|
@ -12,6 +12,8 @@ from cloudinit.sources import DataSourceNone
|
|||||||
from .. import helpers as t_help
|
from .. import helpers as t_help
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -19,7 +21,8 @@ LOG = logging.getLogger(__name__)
|
|||||||
class TestChef(t_help.FilesystemMockingTestCase):
|
class TestChef(t_help.FilesystemMockingTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestChef, self).setUp()
|
super(TestChef, self).setUp()
|
||||||
self.tmp = self.makeDir(prefix="unittest_")
|
self.tmp = tempfile.mkdtemp()
|
||||||
|
self.addCleanup(shutil.rmtree, self.tmp)
|
||||||
|
|
||||||
def fetch_cloud(self, distro_kind):
|
def fetch_cloud(self, distro_kind):
|
||||||
cls = distros.fetch(distro_kind)
|
cls = distros.fetch(distro_kind)
|
||||||
|
@ -26,6 +26,8 @@ from cloudinit.sources import DataSourceNone
|
|||||||
from .. import helpers as t_help
|
from .. import helpers as t_help
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -33,7 +35,8 @@ LOG = logging.getLogger(__name__)
|
|||||||
class TestDebug(t_help.FilesystemMockingTestCase):
|
class TestDebug(t_help.FilesystemMockingTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestDebug, self).setUp()
|
super(TestDebug, self).setUp()
|
||||||
self.new_root = self.makeDir(prefix="unittest_")
|
self.new_root = tempfile.mkdtemp()
|
||||||
|
self.addCleanup(shutil.rmtree, self.new_root)
|
||||||
|
|
||||||
def _get_cloud(self, distro, metadata=None):
|
def _get_cloud(self, distro, metadata=None):
|
||||||
self.patchUtils(self.new_root)
|
self.patchUtils(self.new_root)
|
||||||
|
@ -32,6 +32,8 @@ from configobj import ConfigObj
|
|||||||
from six import BytesIO
|
from six import BytesIO
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -39,7 +41,8 @@ LOG = logging.getLogger(__name__)
|
|||||||
class TestLocale(t_help.FilesystemMockingTestCase):
|
class TestLocale(t_help.FilesystemMockingTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestLocale, self).setUp()
|
super(TestLocale, self).setUp()
|
||||||
self.new_root = self.makeDir(prefix="unittest_")
|
self.new_root = tempfile.mkdtemp()
|
||||||
|
self.addCleanup(shutil.rmtree, self.new_root)
|
||||||
|
|
||||||
def _get_cloud(self, distro):
|
def _get_cloud(self, distro):
|
||||||
self.patchUtils(self.new_root)
|
self.patchUtils(self.new_root)
|
||||||
|
@ -7,6 +7,8 @@ from cloudinit import util
|
|||||||
|
|
||||||
from .. import helpers as t_help
|
from .. import helpers as t_help
|
||||||
|
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from six import BytesIO
|
from six import BytesIO
|
||||||
@ -19,7 +21,8 @@ LOG = logging.getLogger(__name__)
|
|||||||
class TestHostname(t_help.FilesystemMockingTestCase):
|
class TestHostname(t_help.FilesystemMockingTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestHostname, self).setUp()
|
super(TestHostname, self).setUp()
|
||||||
self.tmp = self.makeDir(prefix="unittest_")
|
self.tmp = tempfile.mkdtemp()
|
||||||
|
self.addCleanup(shutil.rmtree, self.tmp)
|
||||||
|
|
||||||
def _fetch_distro(self, kind):
|
def _fetch_distro(self, kind):
|
||||||
cls = distros.fetch(kind)
|
cls = distros.fetch(kind)
|
||||||
|
@ -31,6 +31,8 @@ from configobj import ConfigObj
|
|||||||
|
|
||||||
from six import BytesIO
|
from six import BytesIO
|
||||||
|
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
@ -39,7 +41,8 @@ LOG = logging.getLogger(__name__)
|
|||||||
class TestTimezone(t_help.FilesystemMockingTestCase):
|
class TestTimezone(t_help.FilesystemMockingTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestTimezone, self).setUp()
|
super(TestTimezone, self).setUp()
|
||||||
self.new_root = self.makeDir(prefix="unittest_")
|
self.new_root = tempfile.mkdtemp()
|
||||||
|
self.addCleanup(shutil.rmtree, self.new_root)
|
||||||
|
|
||||||
def _get_cloud(self, distro):
|
def _get_cloud(self, distro):
|
||||||
self.patchUtils(self.new_root)
|
self.patchUtils(self.new_root)
|
||||||
|
@ -4,6 +4,8 @@ from cloudinit.config import cc_yum_add_repo
|
|||||||
|
|
||||||
from .. import helpers
|
from .. import helpers
|
||||||
|
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from six import BytesIO
|
from six import BytesIO
|
||||||
@ -16,7 +18,8 @@ LOG = logging.getLogger(__name__)
|
|||||||
class TestConfig(helpers.FilesystemMockingTestCase):
|
class TestConfig(helpers.FilesystemMockingTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestConfig, self).setUp()
|
super(TestConfig, self).setUp()
|
||||||
self.tmp = self.makeDir(prefix="unittest_")
|
self.tmp = tempfile.mkdtemp()
|
||||||
|
self.addCleanup(shutil.rmtree, self.tmp)
|
||||||
|
|
||||||
def test_bad_config(self):
|
def test_bad_config(self):
|
||||||
cfg = {
|
cfg = {
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
|
||||||
from .. import helpers
|
from .. import helpers
|
||||||
|
|
||||||
@ -14,7 +16,8 @@ class TestMergeRun(helpers.FilesystemMockingTestCase):
|
|||||||
self.patchUtils(root)
|
self.patchUtils(root)
|
||||||
|
|
||||||
def test_none_ds(self):
|
def test_none_ds(self):
|
||||||
new_root = self.makeDir()
|
new_root = tempfile.mkdtemp()
|
||||||
|
self.addCleanup(shutil.rmtree, new_root)
|
||||||
self.replicateTestRoot('simple_ubuntu', new_root)
|
self.replicateTestRoot('simple_ubuntu', new_root)
|
||||||
cfg = {
|
cfg = {
|
||||||
'datasource_list': ['None'],
|
'datasource_list': ['None'],
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
|
||||||
from .. import helpers
|
from .. import helpers
|
||||||
|
|
||||||
@ -33,7 +35,8 @@ class TestSimpleRun(helpers.FilesystemMockingTestCase):
|
|||||||
self._patchIn(root)
|
self._patchIn(root)
|
||||||
|
|
||||||
def test_none_ds(self):
|
def test_none_ds(self):
|
||||||
new_root = self.makeDir()
|
new_root = tempfile.mkdtemp()
|
||||||
|
self.addCleanup(shutil.rmtree, new_root)
|
||||||
self.replicateTestRoot('simple_ubuntu', new_root)
|
self.replicateTestRoot('simple_ubuntu', new_root)
|
||||||
cfg = {
|
cfg = {
|
||||||
'datasource_list': ['None'],
|
'datasource_list': ['None'],
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
import stat
|
import stat
|
||||||
import yaml
|
import yaml
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
|
||||||
from . import helpers
|
from . import helpers
|
||||||
import unittest
|
import unittest
|
||||||
@ -63,7 +65,8 @@ class TestGetCfgOptionListOrStr(unittest.TestCase):
|
|||||||
class TestWriteFile(unittest.TestCase):
|
class TestWriteFile(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestWriteFile, self).setUp()
|
super(TestWriteFile, self).setUp()
|
||||||
self.tmp = self.makeDir(prefix="unittest_")
|
self.tmp = tempfile.mkdtemp()
|
||||||
|
self.addCleanup(shutil.rmtree, self.tmp)
|
||||||
|
|
||||||
def test_basic_usage(self):
|
def test_basic_usage(self):
|
||||||
"""Verify basic usage with default args."""
|
"""Verify basic usage with default args."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user