diff options
author | Kiril Vladimiroff <kiril.vladimiroff@cloudsigma.com> | 2014-02-12 12:14:49 +0200 |
---|---|---|
committer | Kiril Vladimiroff <kiril.vladimiroff@cloudsigma.com> | 2014-02-12 12:14:49 +0200 |
commit | 09f392693efeacc7ac17cdab51c7299e928e394d (patch) | |
tree | 49e2b507326dac59730139adae09e6f929c1f677 /tests | |
parent | 4d80411700ca70401cda401ee9bca799b9b8c55d (diff) | |
download | vyos-cloud-init-09f392693efeacc7ac17cdab51c7299e928e394d.tar.gz vyos-cloud-init-09f392693efeacc7ac17cdab51c7299e928e394d.zip |
Add CloudSigma data source
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unittests/test_cs_util.py | 65 | ||||
-rw-r--r-- | tests/unittests/test_datasource/test_cloudsigma.py | 59 |
2 files changed, 124 insertions, 0 deletions
diff --git a/tests/unittests/test_cs_util.py b/tests/unittests/test_cs_util.py new file mode 100644 index 00000000..7d59222b --- /dev/null +++ b/tests/unittests/test_cs_util.py @@ -0,0 +1,65 @@ +from mocker import MockerTestCase + +from cloudinit.cs_utils import Cepko + + +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"}, + "name": "test_server", + "requirements": [], + "smp": 1, + "tags": ["much server", "very performance"], + "uuid": "65b2fb23-8c03-4187-a3ba-8b7c919e889", + "vnc_password": "9e84d6cb49e46379" +} + + +class CepkoMock(Cepko): + def all(self): + return SERVER_CONTEXT + + def get(self, key="", request_pattern=None): + return SERVER_CONTEXT['tags'] + + +class CepkoResultTests(MockerTestCase): + def setUp(self): + self.mocked = self.mocker.replace("cloudinit.cs_utils.Cepko", + spec=CepkoMock, + count=False, + passthrough=False) + self.mocked() + self.mocker.result(CepkoMock()) + self.mocker.replay() + self.c = Cepko() + + def test_getitem(self): + result = self.c.all() + self.assertEqual("65b2fb23-8c03-4187-a3ba-8b7c919e889", result['uuid']) + self.assertEqual([], result['requirements']) + self.assertEqual("much server", result['tags'][0]) + self.assertEqual(1, result['smp']) + + def test_len(self): + self.assertEqual(len(SERVER_CONTEXT), len(self.c.all())) + + def test_contains(self): + result = self.c.all() + self.assertTrue('uuid' in result) + self.assertFalse('uid' in result) + self.assertTrue('meta' in result) + self.assertFalse('ssh_public_key' in result) + + def test_iter(self): + self.assertEqual(sorted(SERVER_CONTEXT.keys()), + sorted([key for key in self.c.all()])) + + def test_with_list_as_result(self): + result = self.c.get('tags') + self.assertEqual('much server', result[0]) + self.assertTrue('very performance' in result) + self.assertEqual(2, len(result)) 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']) |