Added empty metadata service: EmptyMetadataService
The empty metadata service can be used to run plugins that do not rely on metadata service information, like setting NTP, MTU, extending volumes, local scripts execution, licensing, etc. It can be used also as a fallback metadata service, in case no other previous metadata service could be loaded. EmptyMetadataService does not support the following plugins: * cloudbaseinit.plugins.windows.createuser.CreateUserPlugin * cloudbaseinit.plugins.common.setuserpassword.SetUserPasswordPlugin * cloudbaseinit.plugins.common.sshpublickeys.SetUserSSHPublicKeysPlugin * cloudbaseinit.plugins.windows.winrmcertificateauth.ConfigWinRMCertificateAuthPlugin If any of the plugins defined above are executed, they will fail with exception NotExistingMetadataException. The reason for the hardcoded failure is that these plugins rely on metadata to execute correctly. If metadata like username or password is not provided, these plugins can lock or misconfigure the user, leading to unwanted problems. Implements: blueprint empty-metadata-provider Change-Id: I5fb88a07bf72321d0f66b16d151bf6059b448580
This commit is contained in:
parent
31f49e52a0
commit
b5e3c42f39
@ -297,3 +297,32 @@ class BaseHTTPMetadataService(BaseMetadataService):
|
||||
raise
|
||||
|
||||
return response
|
||||
|
||||
|
||||
class EmptyMetadataService(BaseMetadataService):
|
||||
|
||||
"""Empty metadata service implementation.
|
||||
|
||||
The empty metadata service can be used to run plugins that do not
|
||||
rely on metadata service information, like setting ntp, mtu, etc.
|
||||
It can be used also as a fallback metadata service, in case no other
|
||||
previous metadata service could be loaded.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
super(EmptyMetadataService, self).__init__()
|
||||
|
||||
def _get_data(self, path):
|
||||
pass
|
||||
|
||||
def load(self):
|
||||
return True
|
||||
|
||||
def get_admin_username(self):
|
||||
raise NotExistingMetadataException()
|
||||
|
||||
def get_admin_password(self):
|
||||
raise NotExistingMetadataException()
|
||||
|
||||
def is_password_changed(self):
|
||||
raise NotExistingMetadataException()
|
||||
|
@ -183,3 +183,27 @@ class TestBaseHTTPMetadataService(unittest.TestCase):
|
||||
ssl_error = requests.exceptions.SSLError()
|
||||
self._test_get_data(expected_response=ssl_error,
|
||||
expected_value=exception.CertificateVerifyFailed)
|
||||
|
||||
|
||||
class TestEmptyMetadataService(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self._service = base.EmptyMetadataService()
|
||||
|
||||
def test_get_name(self):
|
||||
self.assertEqual(self._service.get_name(), 'EmptyMetadataService')
|
||||
|
||||
def test__get_data(self):
|
||||
self.assertFalse(self._service._get_data('fake_path'))
|
||||
|
||||
def test_get_admin_username(self):
|
||||
self.assertRaises(base.NotExistingMetadataException,
|
||||
self._service.get_admin_username)
|
||||
|
||||
def test_get_admin_password(self):
|
||||
self.assertRaises(base.NotExistingMetadataException,
|
||||
self._service.get_admin_password)
|
||||
|
||||
def test_is_password_changed(self):
|
||||
self.assertRaises(base.NotExistingMetadataException,
|
||||
self._service.is_password_changed)
|
||||
|
@ -338,3 +338,27 @@ Config options for `default` section:
|
||||
|
||||
* retry_count (integer: 5)
|
||||
* retry_count_interval (integer: 4)
|
||||
|
||||
EMPTY
|
||||
-----
|
||||
|
||||
.. class:: cloudbaseinit.metadata.services.base.EmptyMetadataService
|
||||
|
||||
The empty metadata service can be used to run plugins that do not
|
||||
rely on metadata service information, like setting NTP, MTU,
|
||||
extending volumes, local scripts execution, licensing, etc.
|
||||
|
||||
It can be used also as a fallback metadata service, in case no other
|
||||
previous metadata service could be loaded.
|
||||
|
||||
EmptyMetadataService does not support the following plugins:
|
||||
* cloudbaseinit.plugins.windows.createuser.CreateUserPlugin
|
||||
* cloudbaseinit.plugins.common.setuserpassword.SetUserPasswordPlugin
|
||||
* cloudbaseinit.plugins.common.sshpublickeys.SetUserSSHPublicKeysPlugin
|
||||
* cloudbaseinit.plugins.windows.winrmcertificateauth.ConfigWinRMCertificateAuthPlugin
|
||||
|
||||
If any of the plugins defined above are executed,
|
||||
they will fail with exception NotExistingMetadataException. The reason
|
||||
for the hardcoded failure is that these plugins rely on metadata to execute
|
||||
correctly. If metadata like username or password is not provided,
|
||||
these plugins can lock or misconfigure the user, leading to unwanted problems.
|
||||
|
5
tox.ini
5
tox.ini
@ -1,9 +1,10 @@
|
||||
[tox]
|
||||
minversion = 1.6
|
||||
envlist = py27,py33,pep8
|
||||
envlist = docs,py37,pep8
|
||||
skipsdist = True
|
||||
|
||||
[testenv]
|
||||
basepython = python3
|
||||
usedevelop = True
|
||||
install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} -U --force-reinstall {opts} {packages}
|
||||
setenv = VIRTUAL_ENV={envdir}
|
||||
@ -16,7 +17,7 @@ commands = python setup.py testr --testr-args='{posargs}'
|
||||
commands = flake8 {posargs}
|
||||
|
||||
[testenv:cover]
|
||||
basepython = python2.7
|
||||
basepython = python3
|
||||
setenv =
|
||||
{[testenv]setenv}
|
||||
PYTHON=coverage run --source cloudbaseinit --parallel-mode
|
||||
|
Loading…
x
Reference in New Issue
Block a user