2015-11-13 18:25:26 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
:codeauthor: :email:`Ethan Devenport <ethand@stackpointcloud.com>`
|
|
|
|
'''
|
|
|
|
|
|
|
|
# Import Python Libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
import os
|
|
|
|
import random
|
|
|
|
import string
|
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
2017-02-27 15:59:04 +00:00
|
|
|
import tests.integration as integration
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import skipIf
|
2017-02-27 15:59:04 +00:00
|
|
|
from tests.support.helpers import expensiveTest
|
2015-11-13 18:25:26 +00:00
|
|
|
|
|
|
|
# Import Salt Libs
|
|
|
|
from salt.config import cloud_providers_config
|
|
|
|
from salt.ext.six.moves import range
|
|
|
|
|
|
|
|
# Import Third-Party Libs
|
|
|
|
try:
|
2016-01-21 21:42:59 +00:00
|
|
|
from profitbricks.client import ProfitBricksService # pylint: disable=unused-import
|
|
|
|
HAS_PROFITBRICKS = True
|
2015-11-13 18:25:26 +00:00
|
|
|
except ImportError:
|
2016-01-21 21:42:59 +00:00
|
|
|
HAS_PROFITBRICKS = False
|
|
|
|
|
2015-11-13 18:25:26 +00:00
|
|
|
|
|
|
|
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 = 'profitbricks'
|
|
|
|
DRIVER_NAME = 'profitbricks'
|
|
|
|
|
2016-01-21 21:42:59 +00:00
|
|
|
|
|
|
|
@skipIf(HAS_PROFITBRICKS is False, 'salt-cloud requires >= profitbricks 2.3.0')
|
2015-11-13 18:25:26 +00:00
|
|
|
class ProfitBricksTest(integration.ShellCase):
|
|
|
|
'''
|
|
|
|
Integration tests for the ProfitBricks cloud provider
|
|
|
|
'''
|
|
|
|
|
|
|
|
@expensiveTest
|
|
|
|
def setUp(self):
|
|
|
|
'''
|
|
|
|
Sets up the test requirements
|
|
|
|
'''
|
|
|
|
super(ProfitBricksTest, self).setUp()
|
|
|
|
|
|
|
|
# check if appropriate cloud provider and profile files are present
|
|
|
|
profile_str = 'profitbricks-config'
|
|
|
|
providers = self.run_cloud('--list-providers')
|
|
|
|
if profile_str + ':' not in providers:
|
|
|
|
self.skipTest(
|
2016-01-21 21:42:59 +00:00
|
|
|
'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)
|
2015-11-13 18:25:26 +00:00
|
|
|
)
|
|
|
|
|
2016-01-21 21:42:59 +00:00
|
|
|
# check if credentials and datacenter_id present
|
2015-11-13 18:25:26 +00:00
|
|
|
config = cloud_providers_config(
|
|
|
|
os.path.join(
|
|
|
|
integration.FILES,
|
|
|
|
'conf',
|
|
|
|
'cloud.providers.d',
|
|
|
|
PROVIDER_NAME + '.conf'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
username = config[profile_str][DRIVER_NAME]['username']
|
|
|
|
password = config[profile_str][DRIVER_NAME]['password']
|
|
|
|
datacenter_id = config[profile_str][DRIVER_NAME]['datacenter_id']
|
|
|
|
if username == '' or password == '' or datacenter_id == '':
|
|
|
|
self.skipTest(
|
2016-01-21 21:42:59 +00:00
|
|
|
'A username, password, and an datacenter must be provided to '
|
|
|
|
'run these tests. Check '
|
|
|
|
'tests/integration/files/conf/cloud.providers.d/{0}.conf'
|
2015-11-13 18:25:26 +00:00
|
|
|
.format(PROVIDER_NAME)
|
|
|
|
)
|
|
|
|
|
2016-11-01 01:22:28 +00:00
|
|
|
def test_list_images(self):
|
|
|
|
'''
|
|
|
|
Tests the return of running the --list-images command for ProfitBricks
|
|
|
|
'''
|
|
|
|
image_list = self.run_cloud('--list-images {0}'.format(PROVIDER_NAME))
|
|
|
|
self.assertIn(
|
|
|
|
'Ubuntu-16.04-LTS-server-2016-10-06',
|
|
|
|
[i.strip() for i in image_list]
|
|
|
|
)
|
|
|
|
|
2015-11-13 18:25:26 +00:00
|
|
|
def test_instance(self):
|
|
|
|
'''
|
|
|
|
Test creating an instance on ProfitBricks
|
|
|
|
'''
|
|
|
|
# check if instance with salt installed returned
|
|
|
|
try:
|
|
|
|
self.assertIn(
|
|
|
|
INSTANCE_NAME,
|
2016-01-21 21:42:59 +00:00
|
|
|
[i.strip() for i in self.run_cloud(
|
2016-10-25 19:27:57 +00:00
|
|
|
'-p profitbricks-test {0}'.format(INSTANCE_NAME), timeout=500
|
2016-01-21 21:42:59 +00:00
|
|
|
)]
|
2015-11-13 18:25:26 +00:00
|
|
|
)
|
|
|
|
except AssertionError:
|
2016-10-25 19:27:57 +00:00
|
|
|
self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME), timeout=500)
|
2015-11-13 18:25:26 +00:00
|
|
|
raise
|
|
|
|
|
|
|
|
# delete the instance
|
|
|
|
try:
|
|
|
|
self.assertIn(
|
|
|
|
INSTANCE_NAME + ':',
|
2016-01-21 21:42:59 +00:00
|
|
|
[i.strip() for i in self.run_cloud(
|
2016-10-25 19:27:57 +00:00
|
|
|
'-d {0} --assume-yes'.format(INSTANCE_NAME), timeout=500
|
2016-01-21 21:42:59 +00:00
|
|
|
)]
|
2015-11-13 18:25:26 +00:00
|
|
|
)
|
|
|
|
except AssertionError:
|
|
|
|
raise
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
'''
|
|
|
|
Clean up after tests
|
|
|
|
'''
|
|
|
|
query = self.run_cloud('--query')
|
|
|
|
ret = ' {0}:'.format(INSTANCE_NAME)
|
|
|
|
|
|
|
|
# if test instance is still present, delete it
|
|
|
|
if ret in query:
|
2016-10-25 19:27:57 +00:00
|
|
|
self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME), timeout=500)
|