Merge branch 'master' into jnowak/pluggable_transports

This commit is contained in:
Jedrzej Nowak
2015-09-04 15:00:19 +02:00
92 changed files with 1116 additions and 1308 deletions

View File

@@ -6,13 +6,27 @@ from ansible.playbook import PlayBook
from ansible import utils
from ansible import callbacks
import ansible.constants as C
from fabric import api as fabric_api
from solar.core.handlers import base
from solar import errors
from solar.core.provider import SVNProvider
ROLES_PATH = '/etc/ansible/roles'
class AnsiblePlaybook(base.BaseHandler):
def download_roles(self, urls):
if not os.path.exists(ROLES_PATH):
os.makedirs(ROLES_PATH)
for url in urls:
provider = SVNProvider(url)
provider.run()
fabric_api.local('cp -r {} {}'.format(
provider.directory, ROLES_PATH))
def action(self, resource, action):
# This would require to put this file to remote and execute it (mostly)
raise Exception("Not ported to pluggable transports")
@@ -24,6 +38,9 @@ class AnsiblePlaybook(base.BaseHandler):
runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=utils.VERBOSITY)
variables = resource.args_dict()
if 'roles' in variables:
self.download_roles(variables['roles'])
remote_user = variables.get('ssh_user') or C.DEFAULT_REMOTE_USER
private_key_file = variables.get('ssh_key') or C.DEFAULT_PRIVATE_KEY_FILE
if variables.get('ip'):
@@ -32,7 +49,7 @@ class AnsiblePlaybook(base.BaseHandler):
else:
host = 'localhost'
transport = 'local'
C.HOST_KEY_CHECKING = False
play = PlayBook(
playbook=action_file,
remote_user=remote_user,

View File

@@ -103,3 +103,29 @@ class RemoteZipProvider(BaseProvider):
self.directory = os.path.join(directory, path)
else:
self.directory = directory
class SVNProvider(BaseProvider):
"""With git you cant checkout only directory from repo,
but with svn you can
"""
def __init__(self, url, path='.', base_path=None):
self.url = url
self.path = path
self.base_path = base_path or utils.read_config()['resources-directory']
if path != '.':
self.repo_directory = os.path.join(self.base_path, path)
else:
self.repo_directory = self.base_path
self.directory = os.path.join(self.repo_directory, self.url.rsplit('/', 1)[-1])
def run(self):
if not os.path.exists(self.repo_directory):
os.makedirs(self.repo_directory)
if not os.path.exists(self.directory):
fabric_api.local(
'cd {dir} && svn checkout {url}'.format(
dir=self.repo_directory,
url=self.url))

View File

@@ -1,25 +1,28 @@
import imp
import networkx as nx
import os
import traceback
from log import log
from solar.core import resource
from solar.core import signals
def test_all():
results = {}
conn_graph = signals.detailed_connection_graph()
#srt = nx.topological_sort(conn_graph)
for name in conn_graph:
print 'Trying {}'.format(name)
log.debug('Trying {}'.format(name))
r = resource.load(name)
script_path = os.path.join(r.metadata['base_path'], 'test.py')
if not os.path.exists(script_path):
print 'WARNING: resource {} has no tests'.format(name)
log.warning('resource {} has no tests'.format(name))
continue
print 'File {} found'.format(script_path)
log.debug('File {} found'.format(script_path))
with open(script_path) as f:
module = imp.load_module(
@@ -29,4 +32,15 @@ def test_all():
('', 'r', imp.PY_SOURCE)
)
module.test(r)
try:
module.test(r)
results[name] = {
'status': 'ok',
}
except Exception:
results[name] = {
'status': 'error',
'message': traceback.format_exc(),
}
return results