mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
make saltify to use standard boostrap procedure, therefore providing all options like master_sign_pub_file
This commit is contained in:
parent
8ec4fb2a73
commit
cba47f6856
4 changed files with 42 additions and 151 deletions
|
@ -13,8 +13,6 @@ file. However, profiles must still be configured, as described in the
|
|||
from __future__ import absolute_import
|
||||
|
||||
# Import python libs
|
||||
import os
|
||||
import copy
|
||||
import logging
|
||||
|
||||
# Import salt libs
|
||||
|
@ -23,7 +21,6 @@ import salt.utils
|
|||
# Import salt cloud libs
|
||||
import salt.utils.cloud
|
||||
import salt.config as config
|
||||
from salt.exceptions import SaltCloudConfigError
|
||||
|
||||
# Get logging started
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -64,157 +61,11 @@ def create(vm_):
|
|||
'''
|
||||
Provision a single machine
|
||||
'''
|
||||
if config.get_cloud_config_value('deploy', vm_, __opts__) is False:
|
||||
return {
|
||||
'Error': {
|
||||
'No Deploy': '\'deploy\' is not enabled. Not deploying.'
|
||||
}
|
||||
}
|
||||
|
||||
key_filename = config.get_cloud_config_value(
|
||||
'key_filename', vm_, __opts__, search_global=False, default=None
|
||||
)
|
||||
|
||||
if key_filename is not None and not os.path.isfile(key_filename):
|
||||
raise SaltCloudConfigError(
|
||||
'The defined ssh_keyfile {0!r} does not exist'.format(
|
||||
key_filename
|
||||
)
|
||||
)
|
||||
|
||||
ret = {}
|
||||
|
||||
log.info('Provisioning existing machine {0}'.format(vm_['name']))
|
||||
|
||||
ssh_username = config.get_cloud_config_value('ssh_username', vm_, __opts__)
|
||||
deploy_script = script(vm_)
|
||||
deploy_kwargs = {
|
||||
'opts': __opts__,
|
||||
'host': vm_['ssh_host'],
|
||||
'username': ssh_username,
|
||||
'script': deploy_script,
|
||||
'name': vm_['name'],
|
||||
'tmp_dir': config.get_cloud_config_value(
|
||||
'tmp_dir', vm_, __opts__, default='/tmp/.saltcloud'
|
||||
),
|
||||
'deploy_command': config.get_cloud_config_value(
|
||||
'deploy_command', vm_, __opts__,
|
||||
default='/tmp/.saltcloud/deploy.sh',
|
||||
),
|
||||
'start_action': __opts__['start_action'],
|
||||
'parallel': __opts__['parallel'],
|
||||
'sock_dir': __opts__['sock_dir'],
|
||||
'conf_file': __opts__['conf_file'],
|
||||
'minion_pem': vm_['priv_key'],
|
||||
'minion_pub': vm_['pub_key'],
|
||||
'keep_tmp': __opts__['keep_tmp'],
|
||||
'sudo': config.get_cloud_config_value(
|
||||
'sudo', vm_, __opts__, default=(ssh_username != 'root')
|
||||
),
|
||||
'sudo_password': config.get_cloud_config_value(
|
||||
'sudo_password', vm_, __opts__, default=None
|
||||
),
|
||||
'tty': config.get_cloud_config_value(
|
||||
'tty', vm_, __opts__, default=True
|
||||
),
|
||||
'password': config.get_cloud_config_value(
|
||||
'password', vm_, __opts__, search_global=False
|
||||
),
|
||||
'key_filename': key_filename,
|
||||
'script_args': config.get_cloud_config_value('script_args', vm_, __opts__),
|
||||
'script_env': config.get_cloud_config_value('script_env', vm_, __opts__),
|
||||
'minion_conf': salt.utils.cloud.minion_config(__opts__, vm_),
|
||||
'preseed_minion_keys': vm_.get('preseed_minion_keys', None),
|
||||
'display_ssh_output': config.get_cloud_config_value(
|
||||
'display_ssh_output', vm_, __opts__, default=True
|
||||
)
|
||||
}
|
||||
if 'ssh_port' in vm_:
|
||||
deploy_kwargs.update({'port': vm_['ssh_port']})
|
||||
if 'salt_host' in vm_:
|
||||
deploy_kwargs.update({'salt_host': vm_['salt_host']})
|
||||
ret = salt.utils.cloud.bootstrap(vm_, __opts__)
|
||||
|
||||
# forward any info about possible ssh gateway to deploy script
|
||||
# as some providers need also a 'gateway' configuration
|
||||
if 'gateway' in vm_:
|
||||
deploy_kwargs.update({'gateway': vm_['gateway']})
|
||||
|
||||
# Deploy salt-master files, if necessary
|
||||
if config.get_cloud_config_value('make_master', vm_, __opts__) is True:
|
||||
deploy_kwargs['make_master'] = True
|
||||
deploy_kwargs['master_pub'] = vm_['master_pub']
|
||||
deploy_kwargs['master_pem'] = vm_['master_pem']
|
||||
master_conf = salt.utils.cloud.master_config(__opts__, vm_)
|
||||
deploy_kwargs['master_conf'] = master_conf
|
||||
|
||||
if master_conf.get('syndic_master', None):
|
||||
deploy_kwargs['make_syndic'] = True
|
||||
|
||||
deploy_kwargs['make_minion'] = config.get_cloud_config_value(
|
||||
'make_minion', vm_, __opts__, default=True
|
||||
)
|
||||
|
||||
win_installer = config.get_cloud_config_value('win_installer', vm_, __opts__)
|
||||
if win_installer:
|
||||
deploy_kwargs['win_installer'] = win_installer
|
||||
minion = salt.utils.cloud.minion_config(__opts__, vm_)
|
||||
deploy_kwargs['master'] = minion['master']
|
||||
deploy_kwargs['username'] = config.get_cloud_config_value(
|
||||
'win_username', vm_, __opts__, default='Administrator'
|
||||
)
|
||||
deploy_kwargs['password'] = config.get_cloud_config_value(
|
||||
'win_password', vm_, __opts__, default=''
|
||||
)
|
||||
|
||||
# Store what was used to the deploy the VM
|
||||
event_kwargs = copy.deepcopy(deploy_kwargs)
|
||||
del event_kwargs['minion_pem']
|
||||
del event_kwargs['minion_pub']
|
||||
del event_kwargs['sudo_password']
|
||||
if 'password' in event_kwargs:
|
||||
del event_kwargs['password']
|
||||
ret['deploy_kwargs'] = event_kwargs
|
||||
|
||||
salt.utils.cloud.fire_event(
|
||||
'event',
|
||||
'executing deploy script',
|
||||
'salt/cloud/{0}/deploying'.format(vm_['name']),
|
||||
{'kwargs': event_kwargs},
|
||||
transport=__opts__['transport']
|
||||
)
|
||||
|
||||
if win_installer:
|
||||
deployed = salt.utils.cloud.deploy_windows(**deploy_kwargs)
|
||||
else:
|
||||
deployed = salt.utils.cloud.deploy_script(**deploy_kwargs)
|
||||
|
||||
if deployed:
|
||||
ret['deployed'] = deployed
|
||||
log.info('Salt installed on {0}'.format(vm_['name']))
|
||||
return ret
|
||||
|
||||
log.error('Failed to start Salt on host {0}'.format(vm_['name']))
|
||||
return {
|
||||
'Error': {
|
||||
'Not Deployed': 'Failed to start Salt on host {0}'.format(
|
||||
vm_['name']
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def script(vm_):
|
||||
'''
|
||||
Return the script deployment object
|
||||
'''
|
||||
return salt.utils.cloud.os_script(
|
||||
config.get_cloud_config_value('script', vm_, __opts__),
|
||||
vm_,
|
||||
__opts__,
|
||||
salt.utils.cloud.salt_config_to_yaml(
|
||||
salt.utils.cloud.minion_config(__opts__, vm_)
|
||||
)
|
||||
)
|
||||
return ret
|
||||
|
||||
|
||||
def get_configured_provider():
|
||||
|
|
1
tests/unit/cloud/__init__.py
Normal file
1
tests/unit/cloud/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
# -*- coding: utf-8 -*-
|
1
tests/unit/cloud/clouds/__init__.py
Normal file
1
tests/unit/cloud/clouds/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
# -*- coding: utf-8 -*-
|
38
tests/unit/cloud/clouds/saltify_test.py
Normal file
38
tests/unit/cloud/clouds/saltify_test.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
:codeauthor: :email:`Alexander Schwartz <alexander.schwartz@gmx.net>`
|
||||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from salttesting import TestCase
|
||||
|
||||
# Import Salt Libs
|
||||
from salt.cloud.clouds import saltify
|
||||
|
||||
# Globals
|
||||
saltify.__opts__ = {}
|
||||
saltify.__opts__['providers'] = {}
|
||||
|
||||
|
||||
class SaltifyTestCase(TestCase):
|
||||
'''
|
||||
Test cases for salt.cloud.clouds.saltify
|
||||
'''
|
||||
# 'create' function tests: 1
|
||||
|
||||
def test_create_no_deploy(self):
|
||||
'''
|
||||
Test if deployment fails. This is the most basic test as saltify doesn't contain much logic
|
||||
'''
|
||||
vm = {'deploy': False,
|
||||
'provider': 'saltify'
|
||||
}
|
||||
self.assertTrue(saltify.create(vm)['Error']['No Deploy'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
run_tests(SaltifyTestCase, needs_daemon=False)
|
Loading…
Add table
Reference in a new issue