Validation fixes

This commit is contained in:
Przemyslaw Kaminski 2015-05-27 17:06:19 +02:00
parent 394a24a821
commit 07e5d9845a
11 changed files with 54 additions and 36 deletions

View File

@ -1,6 +1,7 @@
import shutil
import os
import requests
import sys
import time
from solar.core import resource
@ -20,15 +21,15 @@ os.mkdir('rs')
node1 = resource.create('node1', 'resources/ro_node/', {'ip':'10.0.0.3', 'ssh_key' : '/vagrant/.vagrant/machines/solar-dev2/virtualbox/private_key', 'ssh_user':'vagrant'})
node2 = resource.create('node2', 'resources/ro_node/', {'ip':'10.0.0.4', 'ssh_key' : '/vagrant/.vagrant/machines/solar-dev3/virtualbox/private_key', 'ssh_user':'vagrant'})
mariadb_service1 = resource.create('mariadb_service1', 'resources/mariadb_service', {'image':'mariadb', 'root_password' : 'mariadb', 'port' : '3306', 'ip': '', 'ssh_user': '', 'ssh_key': ''})
mariadb_service1 = resource.create('mariadb_service1', 'resources/mariadb_service', {'image':'mariadb', 'root_password' : 'mariadb', 'port' : 3306, 'ip': '', 'ssh_user': '', 'ssh_key': ''})
keystone_db = resource.create('keystone_db', 'resources/mariadb_db/', {'db_name':'keystone_db', 'login_password':'', 'login_user':'root', 'login_port': '', 'ip':'', 'ssh_user':'', 'ssh_key':''})
keystone_db_user = resource.create('keystone_db_user', 'resources/mariadb_user/', {'new_user_name' : 'keystone', 'new_user_password' : 'keystone', 'db_name':'', 'login_password':'', 'login_user':'root', 'login_port': '', 'ip':'', 'ssh_user':'', 'ssh_key':''})
keystone_config1 = resource.create('keystone_config1', 'resources/keystone_config/', {'config_dir' : '/etc/solar/keystone', 'ip':'', 'ssh_user':'', 'ssh_key':'', 'admin_token':'admin', 'db_password':'', 'db_name':'', 'db_user':'', 'db_host':''})
keystone_service1 = resource.create('keystone_service1', 'resources/keystone_service/', {'port':'5001', 'admin_port':'35357', 'image': '', 'ip':'', 'ssh_key':'', 'ssh_user':'', 'config_dir':''})
keystone_service1 = resource.create('keystone_service1', 'resources/keystone_service/', {'port': 5001, 'admin_port': 35357, 'image': '', 'ip':'', 'ssh_key':'', 'ssh_user':'', 'config_dir':''})
keystone_config2 = resource.create('keystone_config2', 'resources/keystone_config/', {'config_dir' : '/etc/solar/keystone', 'ip':'', 'ssh_user':'', 'ssh_key':'', 'admin_token':'admin', 'db_password':'', 'db_name':'', 'db_user':'', 'db_host':''})
keystone_service2 = resource.create('keystone_service2', 'resources/keystone_service/', {'port':'5002', 'admin_port':'35357', 'image': '', 'ip':'', 'ssh_key':'', 'ssh_user':'', 'config_dir':''})
keystone_service2 = resource.create('keystone_service2', 'resources/keystone_service/', {'port': 5002, 'admin_port': 35357, 'image': '', 'ip':'', 'ssh_key':'', 'ssh_user':'', 'config_dir':''})
haproxy_keystone_config = resource.create('haproxy_keystone1_config', 'resources/haproxy_keystone_config/', {'name':'keystone_config', 'listen_port':'5000', 'servers':[], 'ports':[]})
@ -78,6 +79,7 @@ signals.connect(haproxy_config, haproxy_service, {'listen_ports':'ports', 'confi
from solar.core import validation
has_errors = False
for r in [node1,
node2,
mariadb_service1,
@ -90,7 +92,13 @@ for r in [node1,
haproxy_keystone_config,
haproxy_config,
haproxy_service]:
validation.validate_resource(r)
errors = validation.validate_resource(r)
if errors:
has_errors = True
print 'ERROR: %s: %s' % (r.name, errors)
if has_errors:
sys.exit(1)
#run

View File

@ -6,10 +6,13 @@
image: {{ image }}
state: running
net: host
{% if ports.value %}
ports:
{% for port in ports.value %}
- {{ port['value'] }}:{{ port['value'] }}
{% endfor %}
{% endif %}
{% if host_binds.value %}
volumes:
# TODO: host_binds might need more work
# Currently it's not that trivial to pass custom src: dst here
@ -17,4 +20,5 @@
# so we mount it to the same directory as on host
{% for bind in host_binds.value %}
- {{ bind['value']['src'] }}:{{ bind['value']['dst'] }}:{{ bind['value'].get('mode', 'ro') }}
{% endfor %}
{% endfor %}
{% endif %}

View File

@ -7,12 +7,15 @@
image: {{ image }}
state: running
net: host
{% if ports.value %}
ports:
{% for port in ports.value %}
{% for p in port['value'] %}
- {{ p['value'] }}:{{ p['value'] }}
{% endfor %}
{% endfor %}
{% endif %}
{% if host_binds.value %}
volumes:
# TODO: host_binds might need more work
# Currently it's not that trivial to pass custom src: dst here
@ -21,3 +24,4 @@
{% for bind in host_binds.value %}
- {{ bind['value']['src'] }}:{{ bind['value']['dst'] }}:{{ bind['value'].get('mode', 'ro') }}
{% endfor %}
{% endif %}

View File

@ -9,10 +9,10 @@ input:
schema: str!
value:
ports:
schema: [int]
schema: [{value: [{value: int}]}]
value: []
host_binds:
schema: [[int]]
schema: [{value: {src: str, dst: str}}]
value: []
volume_binds:
schema: [{src: str, dst: str}]

View File

@ -3,22 +3,22 @@ handler: ansible
version: 1.0.0
input:
ip:
schema: int!
schema: str!
value:
config_dir:
schema: {src: str!, dst: str!}
value: {src: /etc/solar/haproxy, dst: /etc/haproxy}
listen_ports:
schema: [int]
schema: [{value: int}]
value: []
configs:
schema: [[str]]
schema: [{value: [{value: str}]}]
value: []
configs_names:
schema: [str]
schema: [{value: str}]
value: []
configs_ports:
schema: [[int]]
schema: [{value: [{value: int}]}]
value: []
ssh_user:
schema: str!

View File

@ -9,10 +9,10 @@ input:
schema: int!
value: 9999
ports:
schema: [int]
schema: [{value: int}]
value:
servers:
schema: [str]
schema: [{value: str}]
value:
tags: [resources/haproxy, resource/haproxy_keystone_config]

View File

@ -3,9 +3,9 @@
tasks:
- name: mariadb db
mysql_db:
name: {{db_name}}
name: {{ db_name }}
state: present
login_user: root
login_password: {{login_password}}
login_port: {{login_port}}
login_password: {{ login_password }}
login_port: {{ login_port }}
login_host: 127.0.0.1

View File

@ -9,10 +9,10 @@ input:
schema: str!
value: password
port:
schema: str!
schema: int!
value: 3306
ip:
schema: int!
schema: str!
value:
ssh_key:
schema: str!

View File

@ -3,12 +3,12 @@
tasks:
- name: mariadb user
mysql_user:
name: {{new_user_name}}
password: {{new_user_password}}
priv: {{db_name}}.*:ALL
name: {{ new_user_name }}
password: {{ new_user_password }}
priv: {{ db_name }}.*:ALL
host: '%'
state: present
login_user: root
login_password: {{login_password}}
login_port: {{login_port}}
login_password: {{ login_password }}
login_port: {{ login_port }}
login_host: 127.0.0.1

View File

@ -24,22 +24,24 @@ class BaseHandler(object):
shutil.rmtree(self.dst)
def _compile_action_file(self, resource, action):
action_file = resource.metadata['actions'][action]
action_file = os.path.join(resource.metadata['actions_path'], action_file)
dir_path = self.dirs[resource.name]
dest_file = tempfile.mkstemp(text=True, prefix=action, dir=dir_path)[1]
args = self._make_args(resource)
self._compile_file(action_file, dest_file, args)
with open(dest_file, 'w') as f:
f.write(self._render_action(resource, action))
return dest_file
def _compile_file(self, template, dest_file, args):
print 'Rendering', template, args
with open(template) as f:
tpl = Template(f.read())
tpl = tpl.render(args, zip=zip)
def _render_action(self, resource, action):
print 'Rendering %s %s' % (resource.name, action)
with open(dest_file, 'w') as g:
g.write(tpl)
action_file = resource.metadata['actions'][action]
action_file = os.path.join(resource.metadata['actions_path'], action_file)
args = self._make_args(resource)
with open(action_file) as f:
tpl = Template(f.read())
return tpl.render(str=str, zip=zip, **args)
def _make_args(self, resource):
args = {'name': resource.name}

View File

@ -23,7 +23,7 @@ class BaseObserver(object):
return '[{}:{}] {}'.format(self.attached_to.name, self.name, self.value)
def __unicode__(self):
return self.value
return unicode(self.value)
def __eq__(self, other):
if isinstance(other, BaseObserver):