summaryrefslogtreecommitdiff
path: root/cloudinit/sources/tests/test_init.py
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2018-03-20 16:37:36 -0600
committerChad Smith <chad.smith@canonical.com>2018-03-20 16:37:36 -0600
commit685f9901b820a457912959bdd4f389835e965524 (patch)
treecde3672a93f9660515099e453e956746c4182719 /cloudinit/sources/tests/test_init.py
parent7deec7b6a1fce87dc2d9cd886053804bbc70380e (diff)
downloadvyos-cloud-init-685f9901b820a457912959bdd4f389835e965524.tar.gz
vyos-cloud-init-685f9901b820a457912959bdd4f389835e965524.zip
datasources: fix DataSource subclass get_hostname method signature
DataSource.get_hostname call signature changed to allow for metadata_only parameter. The metadata_only=True parameter is passed to get_hostname during init-local stage in order to set the system hostname if present in metadata prior to initial network bring up. Fix subclasses of DataSource which have overridden get_hostname to allow for metadata_only param. LP: #1757176
Diffstat (limited to 'cloudinit/sources/tests/test_init.py')
-rw-r--r--cloudinit/sources/tests/test_init.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/cloudinit/sources/tests/test_init.py b/cloudinit/sources/tests/test_init.py
index 5065083c..e7fda22a 100644
--- a/cloudinit/sources/tests/test_init.py
+++ b/cloudinit/sources/tests/test_init.py
@@ -1,10 +1,12 @@
# This file is part of cloud-init. See LICENSE file for license information.
+import inspect
import os
import six
import stat
from cloudinit.helpers import Paths
+from cloudinit import importer
from cloudinit.sources import (
INSTANCE_JSON_FILE, DataSource)
from cloudinit.tests.helpers import CiTestCase, skipIf, mock
@@ -268,3 +270,29 @@ class TestDataSource(CiTestCase):
"WARNING: Error persisting instance-data.json: 'utf8' codec can't"
" decode byte 0xaa in position 2: invalid start byte",
self.logs.getvalue())
+
+ def test_get_hostname_subclass_support(self):
+ """Validate get_hostname signature on all subclasses of DataSource."""
+ # Use inspect.getfullargspec when we drop py2.6 and py2.7
+ get_args = inspect.getargspec # pylint: disable=W1505
+ base_args = get_args(DataSource.get_hostname) # pylint: disable=W1505
+ # Import all DataSource subclasses so we can inspect them.
+ modules = util.find_modules(os.path.dirname(os.path.dirname(__file__)))
+ for loc, name in modules.items():
+ mod_locs, _ = importer.find_module(name, ['cloudinit.sources'], [])
+ if mod_locs:
+ importer.import_module(mod_locs[0])
+ for child in DataSource.__subclasses__():
+ if 'Test' in child.dsname:
+ continue
+ self.assertEqual(
+ base_args,
+ get_args(child.get_hostname), # pylint: disable=W1505
+ '%s does not implement DataSource.get_hostname params'
+ % child)
+ for grandchild in child.__subclasses__():
+ self.assertEqual(
+ base_args,
+ get_args(grandchild.get_hostname), # pylint: disable=W1505
+ '%s does not implement DataSource.get_hostname params'
+ % grandchild)