summaryrefslogtreecommitdiff
path: root/tests/unittests/test_datasource
diff options
context:
space:
mode:
authorKiril Vladimiroff <kiril.vladimiroff@cloudsigma.com>2014-02-12 12:14:49 +0200
committerKiril Vladimiroff <kiril.vladimiroff@cloudsigma.com>2014-02-12 12:14:49 +0200
commit09f392693efeacc7ac17cdab51c7299e928e394d (patch)
tree49e2b507326dac59730139adae09e6f929c1f677 /tests/unittests/test_datasource
parent4d80411700ca70401cda401ee9bca799b9b8c55d (diff)
downloadvyos-cloud-init-09f392693efeacc7ac17cdab51c7299e928e394d.tar.gz
vyos-cloud-init-09f392693efeacc7ac17cdab51c7299e928e394d.zip
Add CloudSigma data source
Diffstat (limited to 'tests/unittests/test_datasource')
-rw-r--r--tests/unittests/test_datasource/test_cloudsigma.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/unittests/test_datasource/test_cloudsigma.py b/tests/unittests/test_datasource/test_cloudsigma.py
new file mode 100644
index 00000000..3245aba1
--- /dev/null
+++ b/tests/unittests/test_datasource/test_cloudsigma.py
@@ -0,0 +1,59 @@
+# coding: utf-8
+from unittest import TestCase
+
+from cloudinit.cs_utils import Cepko
+from cloudinit.sources import DataSourceCloudSigma
+
+
+SERVER_CONTEXT = {
+ "cpu": 1000,
+ "cpus_instead_of_cores": False,
+ "global_context": {"some_global_key": "some_global_val"},
+ "mem": 1073741824,
+ "meta": {
+ "ssh_public_key": "ssh-rsa AAAAB3NzaC1yc2E.../hQ5D5 john@doe",
+ "cloudinit-user-data": "#cloud-config\n\n...",
+ },
+ "name": "test_server",
+ "requirements": [],
+ "smp": 1,
+ "tags": ["much server", "very performance"],
+ "uuid": "65b2fb23-8c03-4187-a3ba-8b7c919e8890",
+ "vnc_password": "9e84d6cb49e46379"
+}
+
+
+class CepkoMock(Cepko):
+ result = SERVER_CONTEXT
+
+ def all(self):
+ return self
+
+
+class DataSourceCloudSigmaTest(TestCase):
+ def setUp(self):
+ self.datasource = DataSourceCloudSigma.DataSourceCloudSigma("", "", "")
+ self.datasource.cepko = CepkoMock()
+ self.datasource.get_data()
+
+ def test_get_hostname(self):
+ self.assertEqual("test_server", self.datasource.get_hostname())
+ self.datasource.metadata['name'] = ''
+ self.assertEqual("65b2fb23", self.datasource.get_hostname())
+ self.datasource.metadata['name'] = u'ั‚ะตัั‚'
+ self.assertEqual("65b2fb23", self.datasource.get_hostname())
+
+ def test_get_public_ssh_keys(self):
+ self.assertEqual([SERVER_CONTEXT['meta']['ssh_public_key']],
+ self.datasource.get_public_ssh_keys())
+
+ def test_get_instance_id(self):
+ self.assertEqual(SERVER_CONTEXT['uuid'],
+ self.datasource.get_instance_id())
+
+ def test_metadata(self):
+ self.assertEqual(self.datasource.metadata, SERVER_CONTEXT)
+
+ def test_user_data(self):
+ self.assertEqual(self.datasource.userdata_raw,
+ SERVER_CONTEXT['meta']['cloudinit-user-data'])