diff options
author | Wesley Wiedenmeier <wesley.wiedenmeier@gmail.com> | 2016-12-22 17:27:37 -0500 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2016-12-22 17:41:39 -0500 |
commit | f53fc46aa732e3b29991b3e5e39da31a722945ee (patch) | |
tree | a301733aa9991b58b218f61b187240d275e44968 /tests/cloud_tests/testcases/examples | |
parent | b2a9f33616c806ae6e052520a8589113308f567c (diff) | |
download | vyos-cloud-init-f53fc46aa732e3b29991b3e5e39da31a722945ee.tar.gz vyos-cloud-init-f53fc46aa732e3b29991b3e5e39da31a722945ee.zip |
integration test: initial commit of integration test framework
The adds in end-to-end testing of cloud-init. The framework utilizes
LXD and cloud images as a backend to test user-data passed in.
Arbitrary data is then captured from predefined commands specified
by the user. After collection, data verification is completed by
running a series of Python unit tests against the collected data.
Currently only the Ubuntu Trusty, Xenial, Yakkety, and Zesty
releases are supported. Test cases for 50% of the modules is
complete and available.
Additionally a Read the Docs file was created to guide test
writing and execution.
Diffstat (limited to 'tests/cloud_tests/testcases/examples')
11 files changed, 277 insertions, 0 deletions
diff --git a/tests/cloud_tests/testcases/examples/__init__.py b/tests/cloud_tests/testcases/examples/__init__.py new file mode 100644 index 00000000..b3af7f8a --- /dev/null +++ b/tests/cloud_tests/testcases/examples/__init__.py @@ -0,0 +1,8 @@ +# This file is part of cloud-init. See LICENSE file for license information. + +""" +Test verifiers for cloud-init examples +See configs/examples/README.md for more information +""" + +# vi: ts=4 expandtab diff --git a/tests/cloud_tests/testcases/examples/add_apt_repositories.py b/tests/cloud_tests/testcases/examples/add_apt_repositories.py new file mode 100644 index 00000000..15b8f01c --- /dev/null +++ b/tests/cloud_tests/testcases/examples/add_apt_repositories.py @@ -0,0 +1,20 @@ +# This file is part of cloud-init. See LICENSE file for license information. + +"""cloud-init Integration Test Verify Script""" +from tests.cloud_tests.testcases import base + + +class TestAptconfigurePrimary(base.CloudTestCase): + """Example cloud-config test""" + + def test_ubuntu_sources(self): + """Test no default Ubuntu entries exist""" + out = self.get_data_file('ubuntu.sources.list') + self.assertEqual(0, int(out)) + + def test_gatech_sources(self): + """Test GaTech entires exist""" + out = self.get_data_file('gatech.sources.list') + self.assertEqual(20, int(out)) + +# vi: ts=4 expandtab diff --git a/tests/cloud_tests/testcases/examples/alter_completion_message.py b/tests/cloud_tests/testcases/examples/alter_completion_message.py new file mode 100644 index 00000000..b06ad01b --- /dev/null +++ b/tests/cloud_tests/testcases/examples/alter_completion_message.py @@ -0,0 +1,49 @@ +# This file is part of cloud-init. See LICENSE file for license information. + +"""cloud-init Integration Test Verify Script""" +from tests.cloud_tests.testcases import base + + +class TestFinalMessage(base.CloudTestCase): + """ + test cloud init module `cc_final_message` + """ + subs_char = '$' + + def get_final_message_config(self): + """ + get config for final message + """ + self.assertIn('final_message', self.cloud_config) + return self.cloud_config['final_message'] + + def get_final_message(self): + """ + get final message from log + """ + out = self.get_data_file('cloud-init-output.log') + lines = len(self.get_final_message_config().splitlines()) + return '\n'.join(out.splitlines()[-1 * lines:]) + + def test_final_message_string(self): + """ + ensure final handles regular strings + """ + for actual, config in zip( + self.get_final_message().splitlines(), + self.get_final_message_config().splitlines()): + if self.subs_char not in config: + self.assertEqual(actual, config) + + def test_final_message_subs(self): + """ + test variable substitution in final message + """ + # TODO: add verification of other substitutions + patterns = {'$datasource': self.get_datasource()} + for key, expected in patterns.items(): + index = self.get_final_message_config().splitlines().index(key) + actual = self.get_final_message().splitlines()[index] + self.assertEqual(actual, expected) + +# vi: ts=4 expandtab diff --git a/tests/cloud_tests/testcases/examples/configure_instance_trusted_ca_certificates.py b/tests/cloud_tests/testcases/examples/configure_instance_trusted_ca_certificates.py new file mode 100644 index 00000000..8a4a0db0 --- /dev/null +++ b/tests/cloud_tests/testcases/examples/configure_instance_trusted_ca_certificates.py @@ -0,0 +1,27 @@ +# This file is part of cloud-init. See LICENSE file for license information. + +"""cloud-init Integration Test Verify Script""" +from tests.cloud_tests.testcases import base + + +class TestTrustedCA(base.CloudTestCase): + """Example cloud-config test""" + + def test_cert_count_ca(self): + """Test correct count of CAs in .crt""" + out = self.get_data_file('cert_count_ca') + self.assertIn('7 /etc/ssl/certs/ca-certificates.crt', out) + + def test_cert_count_cloudinit(self): + """Test correct count of CAs in .pem""" + out = self.get_data_file('cert_count_cloudinit') + self.assertIn('7 /etc/ssl/certs/cloud-init-ca-certs.pem', out) + + def test_cloudinit_certs(self): + """Test text of cert""" + out = self.get_data_file('cloudinit_certs') + self.assertIn('-----BEGIN CERTIFICATE-----', out) + self.assertIn('YOUR-ORGS-TRUSTED-CA-CERT-HERE', out) + self.assertIn('-----END CERTIFICATE-----', out) + +# vi: ts=4 expandtab diff --git a/tests/cloud_tests/testcases/examples/configure_instances_ssh_keys.py b/tests/cloud_tests/testcases/examples/configure_instances_ssh_keys.py new file mode 100644 index 00000000..4f651703 --- /dev/null +++ b/tests/cloud_tests/testcases/examples/configure_instances_ssh_keys.py @@ -0,0 +1,31 @@ +# This file is part of cloud-init. See LICENSE file for license information. + +"""cloud-init Integration Test Verify Script""" +from tests.cloud_tests.testcases import base + + +class TestSSHKeys(base.CloudTestCase): + """Example cloud-config test""" + + def test_cert_count(self): + """Test cert count""" + out = self.get_data_file('cert_count') + self.assertEqual(20, int(out)) + + def test_dsa_public(self): + """Test DSA key has ending""" + out = self.get_data_file('dsa_public') + self.assertIn('ZN4XnifuO5krqAybngIy66PMEoQ= smoser@localhost', out) + + def test_rsa_public(self): + """Test RSA key has specific ending""" + out = self.get_data_file('rsa_public') + self.assertIn('PemAWthxHO18QJvWPocKJtlsDNi3 smoser@localhost', out) + + def test_auth_keys(self): + """Test authorized keys has specific ending""" + out = self.get_data_file('auth_keys') + self.assertIn('QPOt5Q8zWd9qG7PBl9+eiH5qV7NZ mykey@host', out) + self.assertIn('Hj29SCmXp5Kt5/82cD/VN3NtHw== smoser@brickies', out) + +# vi: ts=4 expandtab diff --git a/tests/cloud_tests/testcases/examples/including_user_groups.py b/tests/cloud_tests/testcases/examples/including_user_groups.py new file mode 100644 index 00000000..e5732322 --- /dev/null +++ b/tests/cloud_tests/testcases/examples/including_user_groups.py @@ -0,0 +1,43 @@ +# This file is part of cloud-init. See LICENSE file for license information. + +"""cloud-init Integration Test Verify Script""" +from tests.cloud_tests.testcases import base + + +class TestUserGroups(base.CloudTestCase): + """Example cloud-config test""" + + def test_group_ubuntu(self): + """Test ubuntu group exists""" + out = self.get_data_file('group_ubuntu') + self.assertRegex(out, r'ubuntu:x:[0-9]{4}:') + + def test_group_cloud_users(self): + """Test cloud users group exists""" + out = self.get_data_file('group_cloud_users') + self.assertRegex(out, r'cloud-users:x:[0-9]{4}:barfoo') + + def test_user_ubuntu(self): + """Test ubuntu user exists""" + out = self.get_data_file('user_ubuntu') + self.assertRegex( + out, r'ubuntu:x:[0-9]{4}:[0-9]{4}:Ubuntu:/home/ubuntu:/bin/bash') + + def test_user_foobar(self): + """Test foobar user exists""" + out = self.get_data_file('user_foobar') + self.assertRegex( + out, r'foobar:x:[0-9]{4}:[0-9]{4}:Foo B. Bar:/home/foobar:') + + def test_user_barfoo(self): + """Test barfoo user exists""" + out = self.get_data_file('user_barfoo') + self.assertRegex( + out, r'barfoo:x:[0-9]{4}:[0-9]{4}:Bar B. Foo:/home/barfoo:') + + def test_user_cloudy(self): + """Test cloudy user exists""" + out = self.get_data_file('user_cloudy') + self.assertRegex(out, r'cloudy:x:[0-9]{3,4}:') + +# vi: ts=4 expandtab diff --git a/tests/cloud_tests/testcases/examples/install_arbitrary_packages.py b/tests/cloud_tests/testcases/examples/install_arbitrary_packages.py new file mode 100644 index 00000000..660d1aa3 --- /dev/null +++ b/tests/cloud_tests/testcases/examples/install_arbitrary_packages.py @@ -0,0 +1,20 @@ +# This file is part of cloud-init. See LICENSE file for license information. + +"""cloud-init Integration Test Verify Script""" +from tests.cloud_tests.testcases import base + + +class TestInstall(base.CloudTestCase): + """Example cloud-config test""" + + def test_htop(self): + """Verify htop installed""" + out = self.get_data_file('htop') + self.assertEqual(1, int(out)) + + def test_tree(self): + """Verify tree installed""" + out = self.get_data_file('treeutils') + self.assertEqual(1, int(out)) + +# vi: ts=4 expandtab diff --git a/tests/cloud_tests/testcases/examples/run_apt_upgrade.py b/tests/cloud_tests/testcases/examples/run_apt_upgrade.py new file mode 100644 index 00000000..4c04d315 --- /dev/null +++ b/tests/cloud_tests/testcases/examples/run_apt_upgrade.py @@ -0,0 +1,19 @@ +# This file is part of cloud-init. See LICENSE file for license information. + +"""cloud-init Integration Test Verify Script""" +from tests.cloud_tests.testcases import base + + +class TestUpgrade(base.CloudTestCase): + """Example cloud-config test""" + + def test_upgrade(self): + """Test upgrade exists in apt history""" + out = self.get_data_file('cloud-init.log') + self.assertIn( + '[CLOUDINIT] util.py[DEBUG]: apt-upgrade ' + '[eatmydata apt-get --option=Dpkg::Options::=--force-confold ' + '--option=Dpkg::options::=--force-unsafe-io --assume-yes --quiet ' + 'dist-upgrade] took', out) + +# vi: ts=4 expandtab diff --git a/tests/cloud_tests/testcases/examples/run_commands.py b/tests/cloud_tests/testcases/examples/run_commands.py new file mode 100644 index 00000000..0be21d0f --- /dev/null +++ b/tests/cloud_tests/testcases/examples/run_commands.py @@ -0,0 +1,15 @@ +# This file is part of cloud-init. See LICENSE file for license information. + +"""cloud-init Integration Test Verify Script""" +from tests.cloud_tests.testcases import base + + +class TestRunCmd(base.CloudTestCase): + """Example cloud-config test""" + + def test_run_cmd(self): + """Test run command worked""" + out = self.get_data_file('run_cmd') + self.assertIn('cloud-init run cmd test', out) + +# vi: ts=4 expandtab diff --git a/tests/cloud_tests/testcases/examples/run_commands_first_boot.py b/tests/cloud_tests/testcases/examples/run_commands_first_boot.py new file mode 100644 index 00000000..baa23130 --- /dev/null +++ b/tests/cloud_tests/testcases/examples/run_commands_first_boot.py @@ -0,0 +1,15 @@ +# This file is part of cloud-init. See LICENSE file for license information. + +"""cloud-init Integration Test Verify Script""" +from tests.cloud_tests.testcases import base + + +class TestBootCmd(base.CloudTestCase): + """Example cloud-config test""" + + def test_bootcmd_host(self): + """Test boot command worked""" + out = self.get_data_file('hosts') + self.assertIn('192.168.1.130 us.archive.ubuntu.com', out) + +# vi: ts=4 expandtab diff --git a/tests/cloud_tests/testcases/examples/writing_out_arbitrary_files.py b/tests/cloud_tests/testcases/examples/writing_out_arbitrary_files.py new file mode 100644 index 00000000..97dfeec3 --- /dev/null +++ b/tests/cloud_tests/testcases/examples/writing_out_arbitrary_files.py @@ -0,0 +1,30 @@ +# This file is part of cloud-init. See LICENSE file for license information. + +"""cloud-init Integration Test Verify Script""" +from tests.cloud_tests.testcases import base + + +class TestWriteFiles(base.CloudTestCase): + """Example cloud-config test""" + + def test_b64(self): + """Test b64 encoded file reads as ascii""" + out = self.get_data_file('file_b64') + self.assertIn('ASCII text', out) + + def test_binary(self): + """Test binary file reads as executable""" + out = self.get_data_file('file_binary') + self.assertIn('ELF 64-bit LSB executable, x86-64, version 1', out) + + def test_gzip(self): + """Test gzip file shows up as a shell script""" + out = self.get_data_file('file_gzip') + self.assertIn('POSIX shell script, ASCII text executable', out) + + def test_text(self): + """Test text shows up as ASCII text""" + out = self.get_data_file('file_text') + self.assertIn('ASCII text', out) + +# vi: ts=4 expandtab |