summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2019-08-28 00:58:16 +0000
committerServer Team CI Bot <josh.powers+server-team-bot@canonical.com>2019-08-28 00:58:16 +0000
commitd1b022217a652c7a84d5430c9e571987864d3982 (patch)
treeabf5e52bd4ede444f074e3fc7a48bad5a79730f8
parenta3926bffc985e5d39056858f65259a4ac438c037 (diff)
downloadvyos-cloud-init-d1b022217a652c7a84d5430c9e571987864d3982.tar.gz
vyos-cloud-init-d1b022217a652c7a84d5430c9e571987864d3982.zip
exoscale: fix sysconfig cloud_config_modules overrides
Make sure Exoscale supplements or overrides existing system config setting cloud_config_modules instead of replacing it with a one item list set-passords LP: #1841454
-rw-r--r--cloudinit/sources/DataSourceExoscale.py26
-rw-r--r--tests/unittests/test_datasource/test_exoscale.py24
2 files changed, 33 insertions, 17 deletions
diff --git a/cloudinit/sources/DataSourceExoscale.py b/cloudinit/sources/DataSourceExoscale.py
index 52e7f6f6..fdfb4ed3 100644
--- a/cloudinit/sources/DataSourceExoscale.py
+++ b/cloudinit/sources/DataSourceExoscale.py
@@ -6,6 +6,7 @@
from cloudinit import ec2_utils as ec2
from cloudinit import log as logging
from cloudinit import sources
+from cloudinit import helpers
from cloudinit import url_helper
from cloudinit import util
@@ -20,13 +21,6 @@ URL_RETRIES = 6
EXOSCALE_DMI_NAME = "Exoscale"
-BUILTIN_DS_CONFIG = {
- # We run the set password config module on every boot in order to enable
- # resetting the instance's password via the exoscale console (and a
- # subsequent instance reboot).
- 'cloud_config_modules': [["set-passwords", "always"]]
-}
-
class DataSourceExoscale(sources.DataSource):
@@ -42,8 +36,22 @@ class DataSourceExoscale(sources.DataSource):
self.ds_cfg.get('password_server_port', PASSWORD_SERVER_PORT))
self.url_timeout = self.ds_cfg.get('timeout', URL_TIMEOUT)
self.url_retries = self.ds_cfg.get('retries', URL_RETRIES)
-
- self.extra_config = BUILTIN_DS_CONFIG
+ self.extra_config = {}
+
+ def activate(self, cfg, is_new_instance):
+ """Adjust set-passwords module to run 'always' during each boot"""
+ # We run the set password config module on every boot in order to
+ # enable resetting the instance's password via the exoscale console
+ # (and a subsequent instance reboot).
+ # Exoscale password server only provides set-passwords user-data if
+ # a user has triggered a password reset. So calling that password
+ # service generally results in no additional cloud-config.
+ # TODO(Create util functions for overriding merged sys_cfg module freq)
+ mod = 'set_passwords'
+ sem_path = self.paths.get_ipath_cur('sem')
+ sem_helper = helpers.FileSemaphores(sem_path)
+ if sem_helper.clear('config_' + mod, None):
+ LOG.debug('Overriding module set-passwords with frequency always')
def wait_for_metadata_service(self):
"""Wait for the metadata service to be reachable."""
diff --git a/tests/unittests/test_datasource/test_exoscale.py b/tests/unittests/test_datasource/test_exoscale.py
index 350c3304..f0061199 100644
--- a/tests/unittests/test_datasource/test_exoscale.py
+++ b/tests/unittests/test_datasource/test_exoscale.py
@@ -11,8 +11,10 @@ from cloudinit.sources.DataSourceExoscale import (
PASSWORD_SERVER_PORT,
read_metadata)
from cloudinit.tests.helpers import HttprettyTestCase, mock
+from cloudinit import util
import httpretty
+import os
import requests
@@ -63,6 +65,18 @@ class TestDatasourceExoscale(HttprettyTestCase):
password = get_password()
self.assertEqual(expected_password, password)
+ def test_activate_removes_set_passwords_semaphore(self):
+ """Allow set_passwords to run every boot by removing the semaphore."""
+ path = helpers.Paths({'cloud_dir': self.tmp})
+ sem_dir = self.tmp_path('instance/sem', dir=self.tmp)
+ util.ensure_dir(sem_dir)
+ sem_file = os.path.join(sem_dir, 'config_set_passwords')
+ with open(sem_file, 'w') as stream:
+ stream.write('')
+ ds = DataSourceExoscale({}, None, path)
+ ds.activate(None, None)
+ self.assertFalse(os.path.exists(sem_file))
+
def test_get_data(self):
"""The datasource conforms to expected behavior when supplied
full test data."""
@@ -95,8 +109,6 @@ class TestDatasourceExoscale(HttprettyTestCase):
self.assertEqual(ds.get_config_obj(),
{'ssh_pwauth': True,
'password': expected_password,
- 'cloud_config_modules': [
- ["set-passwords", "always"]],
'chpasswd': {
'expire': False,
}})
@@ -130,9 +142,7 @@ class TestDatasourceExoscale(HttprettyTestCase):
self.assertEqual(ds.userdata_raw.decode("utf-8"), "#cloud-config")
self.assertEqual(ds.metadata, {"instance-id": expected_id,
"local-hostname": expected_hostname})
- self.assertEqual(ds.get_config_obj(),
- {'cloud_config_modules': [
- ["set-passwords", "always"]]})
+ self.assertEqual(ds.get_config_obj(), {})
def test_get_data_no_password(self):
"""The datasource conforms to expected behavior when no password is
@@ -163,9 +173,7 @@ class TestDatasourceExoscale(HttprettyTestCase):
self.assertEqual(ds.userdata_raw.decode("utf-8"), "#cloud-config")
self.assertEqual(ds.metadata, {"instance-id": expected_id,
"local-hostname": expected_hostname})
- self.assertEqual(ds.get_config_obj(),
- {'cloud_config_modules': [
- ["set-passwords", "always"]]})
+ self.assertEqual(ds.get_config_obj(), {})
@mock.patch('cloudinit.sources.DataSourceExoscale.get_password')
def test_read_metadata_when_password_server_unreachable(self, m_password):