Merge "Added empty metadata service: EmptyMetadataService"
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user