From b51492486fc5a3b3fafc5d55fe9cc920da508121 Mon Sep 17 00:00:00 2001 From: rallytime Date: Fri, 20 Feb 2015 17:25:07 -0700 Subject: [PATCH 1/2] Add Joyent cloud provider tests --- .../cloud/providers/digital_ocean.py | 3 +- tests/integration/cloud/providers/joyent.py | 114 ++++++++++++++++++ .../files/conf/cloud.profiles.d/joyent.conf | 5 + .../files/conf/cloud.providers.d/joyent.conf | 6 + 4 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 tests/integration/cloud/providers/joyent.py create mode 100644 tests/integration/files/conf/cloud.profiles.d/joyent.conf create mode 100644 tests/integration/files/conf/cloud.providers.d/joyent.conf diff --git a/tests/integration/cloud/providers/digital_ocean.py b/tests/integration/cloud/providers/digital_ocean.py index 5d54548ed0..462e3944cd 100644 --- a/tests/integration/cloud/providers/digital_ocean.py +++ b/tests/integration/cloud/providers/digital_ocean.py @@ -12,6 +12,7 @@ import string from salttesting.helpers import ensure_in_syspath, expensiveTest ensure_in_syspath('../../../') + # Import Salt Libs import integration from salt.config import cloud_providers_config @@ -53,7 +54,7 @@ class DigitalOceanTest(integration.ShellCase): .format(provider) ) - # check if client_key and api_key are present + # check if client_key, api_key, ssh_key_file, and ssh_key_name are present path = os.path.join(integration.FILES, 'conf', 'cloud.providers.d', diff --git a/tests/integration/cloud/providers/joyent.py b/tests/integration/cloud/providers/joyent.py new file mode 100644 index 0000000000..011cc5e1da --- /dev/null +++ b/tests/integration/cloud/providers/joyent.py @@ -0,0 +1,114 @@ +# -*- coding: utf-8 -*- +''' + :codeauthor: :email:`Nicole Thomas ` +''' + +# Import Python Libs +import os +import random +import string + +# Import Salt Testing Libs +from salttesting.helpers import ensure_in_syspath, expensiveTest + +ensure_in_syspath('../../../') + +# Import Salt Libs +import integration +from salt.config import cloud_providers_config + +def __random_name(size=6): + ''' + Generates a random cloud instance name + ''' + return 'CLOUD-TEST-' + ''.join( + random.choice(string.ascii_uppercase + string.digits) + for x in range(size) + ) + +# Create the cloud instance name to be used throughout the tests +INSTANCE_NAME = __random_name() + + +class JoyentTest(integration.ShellCase): + ''' + Integration tests for the Joyent cloud provider in Salt-Cloud + ''' + + @expensiveTest + def setUp(self): + ''' + Sets up the test requirements + ''' + super(JoyentTest, self).setUp() + + # check if appropriate cloud provider and profile files are present + profile_str = 'joyent-config:' + provider = 'joyent' + providers = self.run_cloud('--list-providers') + if profile_str not in providers: + self.skipTest( + 'Configuration file for {0} was not found. Check {0}.conf files ' + 'in tests/integration/files/conf/cloud.*.d/ to run these tests.' + .format(provider) + ) + + # check if user, password, private_key, and keyname are present + path = os.path.join(integration.FILES, + 'conf', + 'cloud.providers.d', + provider + '.conf') + config = cloud_providers_config(path) + + user = config['joyent-config'][provider]['user'] + password = config['joyent-config'][provider]['password'] + private_key = config['joyent-config'][provider]['private_key'] + keyname = config['joyent-config'][provider]['keyname'] + + if user == '' or password == '' or private_key == '' or keyname == '': + self.skipTest( + 'A user name, password, private_key file path, and a key name ' + 'must be provided to run these tests. Check ' + 'tests/integration/files/conf/cloud.providers.d/{0}.conf' + .format(provider) + ) + + def test_instance(self): + ''' + Test creating and deleting instance on Joyent + ''' + + # create the instance + instance = self.run_cloud('-p joyent-test {0}'.format(INSTANCE_NAME)) + ret_str = ' {0}'.format(INSTANCE_NAME) + + # check if instance with salt installed returned + try: + self.assertIn(ret_str, instance) + except AssertionError: + self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME)) + raise + + # delete the instance + delete = self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME)) + ret_str = ' True' + try: + self.assertIn(ret_str, delete) + except AssertionError: + raise + + def tearDown(self): + ''' + Clean up after tests + ''' + query = self.run_cloud('--query') + ret_str = ' {0}:'.format(INSTANCE_NAME) + + # if test instance is still present, delete it + if ret_str in query: + self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME)) + + +if __name__ == '__main__': + from integration import run_tests + run_tests(JoyentTest) diff --git a/tests/integration/files/conf/cloud.profiles.d/joyent.conf b/tests/integration/files/conf/cloud.profiles.d/joyent.conf new file mode 100644 index 0000000000..f5bba52bb8 --- /dev/null +++ b/tests/integration/files/conf/cloud.profiles.d/joyent.conf @@ -0,0 +1,5 @@ +joyent-test: + provider: joyent-config + size: Extra Small 512 MB + image: ubuntu-certified-14.04 + location: us-east-1 diff --git a/tests/integration/files/conf/cloud.providers.d/joyent.conf b/tests/integration/files/conf/cloud.providers.d/joyent.conf new file mode 100644 index 0000000000..2e7848a139 --- /dev/null +++ b/tests/integration/files/conf/cloud.providers.d/joyent.conf @@ -0,0 +1,6 @@ +joyent-config: + provider: joyent + user: '' + password: '' + private_key: '' + keyname: '' From e26cac459989c5910b029da530179e834a0a10fe Mon Sep 17 00:00:00 2001 From: rallytime Date: Tue, 24 Feb 2015 10:58:39 -0700 Subject: [PATCH 2/2] Pylint fix --- tests/integration/cloud/providers/joyent.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integration/cloud/providers/joyent.py b/tests/integration/cloud/providers/joyent.py index 011cc5e1da..535e8c2f66 100644 --- a/tests/integration/cloud/providers/joyent.py +++ b/tests/integration/cloud/providers/joyent.py @@ -17,6 +17,7 @@ ensure_in_syspath('../../../') import integration from salt.config import cloud_providers_config + def __random_name(size=6): ''' Generates a random cloud instance name