summaryrefslogtreecommitdiff
path: root/tests/unittests/test_datasource
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2012-08-22 14:12:32 -0400
committerScott Moser <smoser@ubuntu.com>2012-08-22 14:12:32 -0400
commit451e48732ff7885502db2f8296777fa58b670f3b (patch)
treecf2578bd0ba2849525e44b58b0bfce49f40ec2fe /tests/unittests/test_datasource
parent49242c2a2e7e0ab6812de741b4ac2e8d1888ad08 (diff)
downloadvyos-cloud-init-451e48732ff7885502db2f8296777fa58b670f3b.tar.gz
vyos-cloud-init-451e48732ff7885502db2f8296777fa58b670f3b.zip
fix pep8 complaints.
make pep8 now is silent on precise's pep8 ( 0.6.1-2ubuntu2).
Diffstat (limited to 'tests/unittests/test_datasource')
-rw-r--r--tests/unittests/test_datasource/test_altcloud.py99
-rw-r--r--tests/unittests/test_datasource/test_maas.py22
2 files changed, 65 insertions, 56 deletions
diff --git a/tests/unittests/test_datasource/test_altcloud.py b/tests/unittests/test_datasource/test_altcloud.py
index 54e152e9..bda61c7e 100644
--- a/tests/unittests/test_datasource/test_altcloud.py
+++ b/tests/unittests/test_datasource/test_altcloud.py
@@ -25,14 +25,15 @@ import os
import shutil
import tempfile
-from unittest import TestCase
from cloudinit import helpers
+from unittest import TestCase
# Get the cloudinit.sources.DataSourceAltCloud import items needed.
import cloudinit.sources.DataSourceAltCloud
from cloudinit.sources.DataSourceAltCloud import DataSourceAltCloud
from cloudinit.sources.DataSourceAltCloud import read_user_data_callback
+
def _write_cloud_info_file(value):
'''
Populate the CLOUD_INFO_FILE which would be populated
@@ -44,12 +45,14 @@ def _write_cloud_info_file(value):
cifile.close()
os.chmod(cloudinit.sources.DataSourceAltCloud.CLOUD_INFO_FILE, 0664)
+
def _remove_cloud_info_file():
'''
Remove the test CLOUD_INFO_FILE
'''
os.remove(cloudinit.sources.DataSourceAltCloud.CLOUD_INFO_FILE)
+
def _write_user_data_files(mount_dir, value):
'''
Populate the deltacloud_user_data_file the user_data_file
@@ -68,6 +71,7 @@ def _write_user_data_files(mount_dir, value):
udfile.close()
os.chmod(user_data_file, 0664)
+
def _remove_user_data_files(mount_dir,
dc_file=True,
non_dc_file=True):
@@ -91,14 +95,15 @@ def _remove_user_data_files(mount_dir,
except OSError:
pass
+
class TestGetCloudType(TestCase):
'''
- Test to exercise method: DataSourceAltCloud.get_cloud_type()
+ Test to exercise method: DataSourceAltCloud.get_cloud_type()
'''
def setUp(self):
- ''' Set up '''
- self.paths = helpers.Paths({ 'cloud_dir': '/tmp' })
+ '''Set up.'''
+ self.paths = helpers.Paths({'cloud_dir': '/tmp'})
def tearDown(self):
# Reset
@@ -158,14 +163,15 @@ class TestGetCloudType(TestCase):
self.assertEquals('UNKNOWN', \
dsrc.get_cloud_type())
+
class TestGetDataCloudInfoFile(TestCase):
'''
- Test to exercise method: DataSourceAltCloud.get_data()
+ Test to exercise method: DataSourceAltCloud.get_data()
With a contrived CLOUD_INFO_FILE
'''
def setUp(self):
- ''' Set up '''
- self.paths = helpers.Paths({ 'cloud_dir': '/tmp' })
+ '''Set up.'''
+ self.paths = helpers.Paths({'cloud_dir': '/tmp'})
self.cloud_info_file = tempfile.mkstemp()[1]
cloudinit.sources.DataSourceAltCloud.CLOUD_INFO_FILE = \
self.cloud_info_file
@@ -183,52 +189,53 @@ class TestGetDataCloudInfoFile(TestCase):
'/etc/sysconfig/cloud-info'
def test_rhev(self):
- '''Success Test module get_data() forcing RHEV '''
+ '''Success Test module get_data() forcing RHEV.'''
_write_cloud_info_file('RHEV')
dsrc = DataSourceAltCloud({}, None, self.paths)
- dsrc.user_data_rhevm = lambda : True
+ dsrc.user_data_rhevm = lambda: True
self.assertEquals(True, dsrc.get_data())
def test_vsphere(self):
- '''Success Test module get_data() forcing VSPHERE '''
+ '''Success Test module get_data() forcing VSPHERE.'''
_write_cloud_info_file('VSPHERE')
dsrc = DataSourceAltCloud({}, None, self.paths)
- dsrc.user_data_vsphere = lambda : True
+ dsrc.user_data_vsphere = lambda: True
self.assertEquals(True, dsrc.get_data())
def test_fail_rhev(self):
- '''Failure Test module get_data() forcing RHEV '''
+ '''Failure Test module get_data() forcing RHEV.'''
_write_cloud_info_file('RHEV')
dsrc = DataSourceAltCloud({}, None, self.paths)
- dsrc.user_data_rhevm = lambda : False
+ dsrc.user_data_rhevm = lambda: False
self.assertEquals(False, dsrc.get_data())
def test_fail_vsphere(self):
- '''Failure Test module get_data() forcing VSPHERE '''
+ '''Failure Test module get_data() forcing VSPHERE.'''
_write_cloud_info_file('VSPHERE')
dsrc = DataSourceAltCloud({}, None, self.paths)
- dsrc.user_data_vsphere = lambda : False
+ dsrc.user_data_vsphere = lambda: False
self.assertEquals(False, dsrc.get_data())
def test_unrecognized(self):
- '''Failure Test module get_data() forcing unrecognized '''
+ '''Failure Test module get_data() forcing unrecognized.'''
_write_cloud_info_file('unrecognized')
dsrc = DataSourceAltCloud({}, None, self.paths)
self.assertEquals(False, dsrc.get_data())
+
class TestGetDataNoCloudInfoFile(TestCase):
'''
- Test to exercise method: DataSourceAltCloud.get_data()
+ Test to exercise method: DataSourceAltCloud.get_data()
Without a CLOUD_INFO_FILE
'''
def setUp(self):
- ''' Set up '''
- self.paths = helpers.Paths({ 'cloud_dir': '/tmp' })
+ '''Set up.'''
+ self.paths = helpers.Paths({'cloud_dir': '/tmp'})
cloudinit.sources.DataSourceAltCloud.CLOUD_INFO_FILE = \
'no such file'
@@ -240,38 +247,39 @@ class TestGetDataNoCloudInfoFile(TestCase):
['dmidecode', '--string', 'system-product-name']
def test_rhev_no_cloud_file(self):
- '''Test No cloud info file module get_data() forcing RHEV '''
+ '''Test No cloud info file module get_data() forcing RHEV.'''
cloudinit.sources.DataSourceAltCloud.CMD_DMI_SYSTEM = \
['echo', 'RHEV Hypervisor']
dsrc = DataSourceAltCloud({}, None, self.paths)
- dsrc.user_data_rhevm = lambda : True
+ dsrc.user_data_rhevm = lambda: True
self.assertEquals(True, dsrc.get_data())
def test_vsphere_no_cloud_file(self):
- '''Test No cloud info file module get_data() forcing VSPHERE '''
+ '''Test No cloud info file module get_data() forcing VSPHERE.'''
cloudinit.sources.DataSourceAltCloud.CMD_DMI_SYSTEM = \
['echo', 'VMware Virtual Platform']
dsrc = DataSourceAltCloud({}, None, self.paths)
- dsrc.user_data_vsphere = lambda : True
+ dsrc.user_data_vsphere = lambda: True
self.assertEquals(True, dsrc.get_data())
def test_failure_no_cloud_file(self):
- '''Test No cloud info file module get_data() forcing unrecognized '''
+ '''Test No cloud info file module get_data() forcing unrecognized.'''
cloudinit.sources.DataSourceAltCloud.CMD_DMI_SYSTEM = \
['echo', 'Unrecognized Platform']
dsrc = DataSourceAltCloud({}, None, self.paths)
self.assertEquals(False, dsrc.get_data())
+
class TestUserDataRhevm(TestCase):
'''
- Test to exercise method: DataSourceAltCloud.user_data_rhevm()
+ Test to exercise method: DataSourceAltCloud.user_data_rhevm()
'''
def setUp(self):
- ''' Set up '''
- self.paths = helpers.Paths({ 'cloud_dir': '/tmp' })
+ '''Set up.'''
+ self.paths = helpers.Paths({'cloud_dir': '/tmp'})
self.mount_dir = tempfile.mkdtemp()
_write_user_data_files(self.mount_dir, 'test user data')
@@ -295,7 +303,7 @@ class TestUserDataRhevm(TestCase):
['/sbin/udevadm', 'settle', '--quiet', '--timeout=5']
def test_mount_cb_fails(self):
- '''Test user_data_rhevm() where mount_cb fails'''
+ '''Test user_data_rhevm() where mount_cb fails.'''
cloudinit.sources.DataSourceAltCloud.CMD_PROBE_FLOPPY = \
['echo', 'modprobe floppy']
@@ -305,7 +313,7 @@ class TestUserDataRhevm(TestCase):
self.assertEquals(False, dsrc.user_data_rhevm())
def test_modprobe_fails(self):
- '''Test user_data_rhevm() where modprobe fails. '''
+ '''Test user_data_rhevm() where modprobe fails.'''
cloudinit.sources.DataSourceAltCloud.CMD_PROBE_FLOPPY = \
['ls', 'modprobe floppy']
@@ -315,7 +323,7 @@ class TestUserDataRhevm(TestCase):
self.assertEquals(False, dsrc.user_data_rhevm())
def test_no_modprobe_cmd(self):
- '''Test user_data_rhevm() with no modprobe command. '''
+ '''Test user_data_rhevm() with no modprobe command.'''
cloudinit.sources.DataSourceAltCloud.CMD_PROBE_FLOPPY = \
['bad command', 'modprobe floppy']
@@ -325,7 +333,7 @@ class TestUserDataRhevm(TestCase):
self.assertEquals(False, dsrc.user_data_rhevm())
def test_udevadm_fails(self):
- '''Test user_data_rhevm() where udevadm fails. '''
+ '''Test user_data_rhevm() where udevadm fails.'''
cloudinit.sources.DataSourceAltCloud.CMD_UDEVADM_SETTLE = \
['ls', 'udevadm floppy']
@@ -335,7 +343,7 @@ class TestUserDataRhevm(TestCase):
self.assertEquals(False, dsrc.user_data_rhevm())
def test_no_udevadm_cmd(self):
- '''Test user_data_rhevm() with no udevadm command. '''
+ '''Test user_data_rhevm() with no udevadm command.'''
cloudinit.sources.DataSourceAltCloud.CMD_UDEVADM_SETTLE = \
['bad command', 'udevadm floppy']
@@ -344,13 +352,14 @@ class TestUserDataRhevm(TestCase):
self.assertEquals(False, dsrc.user_data_rhevm())
+
class TestUserDataVsphere(TestCase):
'''
- Test to exercise method: DataSourceAltCloud.user_data_vsphere()
+ Test to exercise method: DataSourceAltCloud.user_data_vsphere()
'''
def setUp(self):
- ''' Set up '''
- self.paths = helpers.Paths({ 'cloud_dir': '/tmp' })
+ '''Set up.'''
+ self.paths = helpers.Paths({'cloud_dir': '/tmp'})
self.mount_dir = tempfile.mkdtemp()
_write_user_data_files(self.mount_dir, 'test user data')
@@ -370,7 +379,7 @@ class TestUserDataVsphere(TestCase):
'/etc/sysconfig/cloud-info'
def test_user_data_vsphere(self):
- '''Test user_data_vsphere() where mount_cb fails'''
+ '''Test user_data_vsphere() where mount_cb fails.'''
cloudinit.sources.DataSourceAltCloud.MEDIA_DIR = self.mount_dir
@@ -378,13 +387,14 @@ class TestUserDataVsphere(TestCase):
self.assertEquals(False, dsrc.user_data_vsphere())
+
class TestReadUserDataCallback(TestCase):
'''
- Test to exercise method: DataSourceAltCloud.read_user_data_callback()
+ Test to exercise method: DataSourceAltCloud.read_user_data_callback()
'''
def setUp(self):
- ''' Set up '''
- self.paths = helpers.Paths({ 'cloud_dir': '/tmp' })
+ '''Set up.'''
+ self.paths = helpers.Paths({'cloud_dir': '/tmp'})
self.mount_dir = tempfile.mkdtemp()
_write_user_data_files(self.mount_dir, 'test user data')
@@ -400,15 +410,14 @@ class TestReadUserDataCallback(TestCase):
except OSError:
pass
-
def test_callback_both(self):
- '''Test read_user_data_callback() with both files'''
+ '''Test read_user_data_callback() with both files.'''
self.assertEquals('test user data',
read_user_data_callback(self.mount_dir))
def test_callback_dc(self):
- '''Test read_user_data_callback() with only DC file'''
+ '''Test read_user_data_callback() with only DC file.'''
_remove_user_data_files(self.mount_dir,
dc_file=False,
@@ -418,7 +427,7 @@ class TestReadUserDataCallback(TestCase):
read_user_data_callback(self.mount_dir))
def test_callback_non_dc(self):
- '''Test read_user_data_callback() with only non-DC file'''
+ '''Test read_user_data_callback() with only non-DC file.'''
_remove_user_data_files(self.mount_dir,
dc_file=True,
@@ -428,9 +437,9 @@ class TestReadUserDataCallback(TestCase):
read_user_data_callback(self.mount_dir))
def test_callback_none(self):
- '''Test read_user_data_callback() no files are found'''
+ '''Test read_user_data_callback() no files are found.'''
- _remove_user_data_files(self.mount_dir)
+ _remove_user_data_files(self.mount_dir)
self.assertEquals(None, read_user_data_callback(self.mount_dir))
# vi: ts=4 expandtab
diff --git a/tests/unittests/test_datasource/test_maas.py b/tests/unittests/test_datasource/test_maas.py
index 8a155f39..85e6add0 100644
--- a/tests/unittests/test_datasource/test_maas.py
+++ b/tests/unittests/test_datasource/test_maas.py
@@ -1,8 +1,8 @@
-import os
from copy import copy
+import os
-from cloudinit import url_helper
from cloudinit.sources import DataSourceMAAS
+from cloudinit import url_helper
from mocker import MockerTestCase
@@ -15,7 +15,7 @@ class TestMAASDataSource(MockerTestCase):
self.tmp = self.makeDir()
def test_seed_dir_valid(self):
- """Verify a valid seeddir is read as such"""
+ """Verify a valid seeddir is read as such."""
data = {'instance-id': 'i-valid01',
'local-hostname': 'valid01-hostname',
@@ -35,7 +35,7 @@ class TestMAASDataSource(MockerTestCase):
self.assertFalse(('user-data' in metadata))
def test_seed_dir_valid_extra(self):
- """Verify extra files do not affect seed_dir validity """
+ """Verify extra files do not affect seed_dir validity."""
data = {'instance-id': 'i-valid-extra',
'local-hostname': 'valid-extra-hostname',
@@ -54,7 +54,7 @@ class TestMAASDataSource(MockerTestCase):
self.assertFalse(('foo' in metadata))
def test_seed_dir_invalid(self):
- """Verify that invalid seed_dir raises MAASSeedDirMalformed"""
+ """Verify that invalid seed_dir raises MAASSeedDirMalformed."""
valid = {'instance-id': 'i-instanceid',
'local-hostname': 'test-hostname', 'user-data': ''}
@@ -78,20 +78,20 @@ class TestMAASDataSource(MockerTestCase):
DataSourceMAAS.read_maas_seed_dir, my_d)
def test_seed_dir_none(self):
- """Verify that empty seed_dir raises MAASSeedDirNone"""
+ """Verify that empty seed_dir raises MAASSeedDirNone."""
my_d = os.path.join(self.tmp, "valid_empty")
self.assertRaises(DataSourceMAAS.MAASSeedDirNone,
DataSourceMAAS.read_maas_seed_dir, my_d)
def test_seed_dir_missing(self):
- """Verify that missing seed_dir raises MAASSeedDirNone"""
- self.assertRaises(DataSourceMAAS.MAASSeedDirNone,
+ """Verify that missing seed_dir raises MAASSeedDirNone."""
+ self.assertRaises(DataSourceMAAS.MAASSeedDirNone,
DataSourceMAAS.read_maas_seed_dir,
os.path.join(self.tmp, "nonexistantdirectory"))
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',
'meta-data/local-hostname': 'test-hostname',
'meta-data/public-keys': 'test-hostname',
@@ -129,11 +129,11 @@ class TestMAASDataSource(MockerTestCase):
valid['meta-data/local-hostname'])
def test_seed_url_invalid(self):
- """Verify that invalid seed_url raises MAASSeedDirMalformed"""
+ """Verify that invalid seed_url raises MAASSeedDirMalformed."""
pass
def test_seed_url_missing(self):
- """Verify seed_url with no found entries raises MAASSeedDirNone"""
+ """Verify seed_url with no found entries raises MAASSeedDirNone."""
pass