summaryrefslogtreecommitdiff
path: root/tests/unittests/test_datasource/test_hetzner.py
diff options
context:
space:
mode:
authorMarkus Schade <markus.schade@hetzner.com>2020-10-29 15:45:47 +0100
committerGitHub <noreply@github.com>2020-10-29 10:45:47 -0400
commit1431c8a1bddaabf85e1bbb32bf316a3aef20036e (patch)
tree098c9b77663c134c114795c0c94b48b5aab0abe7 /tests/unittests/test_datasource/test_hetzner.py
parentb46e4a8cff667c8441622089cf7d57aeb88220cd (diff)
downloadvyos-cloud-init-1431c8a1bddaabf85e1bbb32bf316a3aef20036e.tar.gz
vyos-cloud-init-1431c8a1bddaabf85e1bbb32bf316a3aef20036e.zip
Hetzner: initialize instance_id from system-serial-number (#630)
Hetzner Cloud also provides the instance ID in SMBIOS information. Use it to locally check_instance_id and to compared with instance_id from metadata service. LP: #1885527
Diffstat (limited to 'tests/unittests/test_datasource/test_hetzner.py')
-rw-r--r--tests/unittests/test_datasource/test_hetzner.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/tests/unittests/test_datasource/test_hetzner.py b/tests/unittests/test_datasource/test_hetzner.py
index d0879545..fc3649a4 100644
--- a/tests/unittests/test_datasource/test_hetzner.py
+++ b/tests/unittests/test_datasource/test_hetzner.py
@@ -77,10 +77,10 @@ class TestDataSourceHetzner(CiTestCase):
@mock.patch('cloudinit.net.find_fallback_nic')
@mock.patch('cloudinit.sources.helpers.hetzner.read_metadata')
@mock.patch('cloudinit.sources.helpers.hetzner.read_userdata')
- @mock.patch('cloudinit.sources.DataSourceHetzner.on_hetzner')
- def test_read_data(self, m_on_hetzner, m_usermd, m_readmd, m_fallback_nic,
- m_net):
- m_on_hetzner.return_value = True
+ @mock.patch('cloudinit.sources.DataSourceHetzner.get_hcloud_data')
+ def test_read_data(self, m_get_hcloud_data, m_usermd, m_readmd,
+ m_fallback_nic, m_net):
+ m_get_hcloud_data.return_value = (True, METADATA.get('instance-id'))
m_readmd.return_value = METADATA.copy()
m_usermd.return_value = USERDATA
m_fallback_nic.return_value = 'eth0'
@@ -107,11 +107,12 @@ class TestDataSourceHetzner(CiTestCase):
@mock.patch('cloudinit.sources.helpers.hetzner.read_metadata')
@mock.patch('cloudinit.net.find_fallback_nic')
- @mock.patch('cloudinit.sources.DataSourceHetzner.on_hetzner')
- def test_not_on_hetzner_returns_false(self, m_on_hetzner, m_find_fallback,
- m_read_md):
- """If helper 'on_hetzner' returns False, return False from get_data."""
- m_on_hetzner.return_value = False
+ @mock.patch('cloudinit.sources.DataSourceHetzner.get_hcloud_data')
+ def test_not_on_hetzner_returns_false(self, m_get_hcloud_data,
+ m_find_fallback, m_read_md):
+ """If helper 'get_hcloud_data' returns False,
+ return False from get_data."""
+ m_get_hcloud_data.return_value = (False, None)
ds = self.get_ds()
ret = ds.get_data()