2014-06-05 23:34:53 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
:codeauthor: :email:`Nicole Thomas <nicole@saltstack.com>`
|
|
|
|
'''
|
|
|
|
|
|
|
|
# Import Python Libs
|
2018-01-04 19:33:39 +00:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
2014-06-05 23:34:53 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
2017-04-03 16:04:09 +00:00
|
|
|
from tests.support.case import ShellCase
|
|
|
|
from tests.support.paths import FILES
|
2017-06-29 22:11:07 +00:00
|
|
|
from tests.support.helpers import expensiveTest, generate_random_name
|
2014-06-05 23:34:53 +00:00
|
|
|
|
2014-06-22 23:58:39 +00:00
|
|
|
# Import Salt Libs
|
|
|
|
from salt.config import cloud_providers_config
|
2014-09-05 15:23:40 +00:00
|
|
|
|
|
|
|
# Create the cloud instance name to be used throughout the tests
|
2017-06-29 22:11:07 +00:00
|
|
|
INSTANCE_NAME = generate_random_name('CLOUD-TEST-')
|
2015-06-19 16:55:12 +00:00
|
|
|
PROVIDER_NAME = 'linode'
|
2014-09-05 15:23:40 +00:00
|
|
|
|
|
|
|
|
2017-04-03 16:04:09 +00:00
|
|
|
class LinodeTest(ShellCase):
|
2014-06-05 23:34:53 +00:00
|
|
|
'''
|
|
|
|
Integration tests for the Linode cloud provider in Salt-Cloud
|
|
|
|
'''
|
|
|
|
|
2014-06-22 23:58:39 +00:00
|
|
|
@expensiveTest
|
2014-06-05 23:34:53 +00:00
|
|
|
def setUp(self):
|
|
|
|
'''
|
|
|
|
Sets up the test requirements
|
|
|
|
'''
|
|
|
|
super(LinodeTest, self).setUp()
|
|
|
|
|
|
|
|
# check if appropriate cloud provider and profile files are present
|
2015-06-19 16:55:12 +00:00
|
|
|
profile_str = 'linode-config'
|
2014-06-05 23:34:53 +00:00
|
|
|
providers = self.run_cloud('--list-providers')
|
2015-08-25 15:49:32 +00:00
|
|
|
if profile_str + ':' not in providers:
|
2014-06-05 23:34:53 +00:00
|
|
|
self.skipTest(
|
2014-06-05 23:42:16 +00:00
|
|
|
'Configuration file for {0} was not found. Check {0}.conf files '
|
|
|
|
'in tests/integration/files/conf/cloud.*.d/ to run these tests.'
|
2015-06-19 16:55:12 +00:00
|
|
|
.format(PROVIDER_NAME)
|
|
|
|
)
|
|
|
|
|
|
|
|
# check if personal access token, ssh_key_file, and ssh_key_names are present
|
|
|
|
config = cloud_providers_config(
|
|
|
|
os.path.join(
|
2017-04-03 16:04:09 +00:00
|
|
|
FILES,
|
2015-06-19 16:55:12 +00:00
|
|
|
'conf',
|
|
|
|
'cloud.providers.d',
|
|
|
|
PROVIDER_NAME + '.conf'
|
2014-06-05 23:34:53 +00:00
|
|
|
)
|
2015-06-19 16:55:12 +00:00
|
|
|
)
|
2014-06-05 23:34:53 +00:00
|
|
|
|
2015-06-19 16:55:12 +00:00
|
|
|
api = config[profile_str][PROVIDER_NAME]['apikey']
|
|
|
|
password = config[profile_str][PROVIDER_NAME]['password']
|
2014-06-05 23:34:53 +00:00
|
|
|
if api == '' or password == '':
|
|
|
|
self.skipTest(
|
|
|
|
'An api key and password must be provided to run these tests. Check '
|
|
|
|
'tests/integration/files/conf/cloud.providers.d/{0}.conf'.format(
|
2015-06-19 16:55:12 +00:00
|
|
|
PROVIDER_NAME
|
2014-06-05 23:34:53 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_instance(self):
|
|
|
|
'''
|
|
|
|
Test creating an instance on Linode
|
|
|
|
'''
|
|
|
|
# check if instance with salt installed returned
|
|
|
|
try:
|
2015-06-19 16:55:12 +00:00
|
|
|
self.assertIn(
|
|
|
|
INSTANCE_NAME,
|
2016-10-25 19:27:57 +00:00
|
|
|
[i.strip() for i in self.run_cloud('-p linode-test {0}'.format(INSTANCE_NAME), timeout=500)]
|
2015-06-19 16:55:12 +00:00
|
|
|
)
|
2014-06-05 23:34:53 +00:00
|
|
|
except AssertionError:
|
2016-10-25 19:27:57 +00:00
|
|
|
self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME), timeout=500)
|
2014-06-05 23:34:53 +00:00
|
|
|
raise
|
|
|
|
|
|
|
|
# delete the instance
|
|
|
|
try:
|
2015-06-19 16:55:12 +00:00
|
|
|
self.assertIn(
|
|
|
|
INSTANCE_NAME + ':',
|
2016-10-25 19:27:57 +00:00
|
|
|
[i.strip() for i in self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME), timeout=500)]
|
2015-06-19 16:55:12 +00:00
|
|
|
)
|
2014-06-05 23:34:53 +00:00
|
|
|
except AssertionError:
|
|
|
|
raise
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
'''
|
|
|
|
Clean up after tests
|
|
|
|
'''
|
|
|
|
query = self.run_cloud('--query')
|
2014-09-05 15:23:40 +00:00
|
|
|
ret_str = ' {0}:'.format(INSTANCE_NAME)
|
2014-06-05 23:34:53 +00:00
|
|
|
|
|
|
|
# if test instance is still present, delete it
|
2014-06-11 17:42:00 +00:00
|
|
|
if ret_str in query:
|
2016-10-25 19:27:57 +00:00
|
|
|
self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME), timeout=500)
|