salt/tests/integration/cloud/providers/joyent.py
Colton Myers 274464a85b Merge remote-tracking branch 'upstream/2015.5' into merge-forward-2015.8
Conflicts:
    doc/topics/reactor/index.rst
    salt/cloud/clouds/digital_ocean_v2.py
    salt/modules/groupadd.py
    salt/modules/localemod.py
    salt/modules/mysql.py
    salt/modules/useradd.py
    salt/modules/win_pkg.py
    salt/modules/win_useradd.py
    salt/netapi/rest_cherrypy/app.py
    salt/pillar/s3.py
    salt/returners/local_cache.py
    salt/states/htpasswd.py
    salt/states/user.py
2015-09-14 14:39:03 -06:00

119 lines
3.5 KiB
Python

# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Nicole Thomas <nicole@saltstack.com>`
'''
# Import Python Libs
from __future__ import absolute_import
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
from salt.ext.six.moves import range # pylint: disable=redefined-builtin
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()
PROVIDER_NAME = 'joyent'
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'
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_NAME)
)
# check if user, password, private_key, and keyname are present
config = cloud_providers_config(
os.path.join(
integration.FILES,
'conf',
'cloud.providers.d',
PROVIDER_NAME + '.conf'
)
)
user = config[profile_str][PROVIDER_NAME]['user']
password = config[profile_str][PROVIDER_NAME]['password']
private_key = config[profile_str][PROVIDER_NAME]['private_key']
keyname = config[profile_str][PROVIDER_NAME]['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_NAME)
)
def test_instance(self):
'''
Test creating and deleting instance on Joyent
'''
try:
self.assertIn(
INSTANCE_NAME,
[i.strip() for i in self.run_cloud('-p joyent-test {0}'.format(INSTANCE_NAME))]
)
except AssertionError:
self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME))
raise
# delete the instance
try:
self.assertIn(
INSTANCE_NAME + ':',
[i.strip() for i in self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME))]
)
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)