example.py fixes, tests added

This commit is contained in:
Przemyslaw Kaminski 2015-05-27 15:50:40 +02:00
parent d8ed61cfa4
commit 0181408291
8 changed files with 48 additions and 17 deletions

8
cli.py
View File

@ -7,10 +7,10 @@ import networkx as nx
import os
import subprocess
from x import actions as xa
from x import deployment as xd
from x import resource as xr
from x import signals as xs
from solar.core import actions as xa
from solar.core import deployment as xd
from solar.core import resource as xr
from solar.core import signals as xs
@click.group()

View File

@ -1,5 +1,6 @@
import shutil
import os
import requests
import time
from solar.core import resource
@ -12,22 +13,22 @@ if os.path.exists('rs'):
shutil.rmtree('rs')
os.mkdir('rs')
node1 = resource.create('node1', 'resources/ro_node/', 'rs/', {'ip':'10.0.0.3', 'ssh_key' : '/vagrant/tmp/keys/ssh_private', 'ssh_user':'vagrant'})
node2 = resource.create('node2', 'resources/ro_node/', 'rs/', {'ip':'10.0.0.4', 'ssh_key' : '/vagrant/tmp/keys/ssh_private', 'ssh_user':'vagrant'})
node1 = resource.create('node1', 'resources/ro_node/', 'rs/', {'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/', 'rs/', {'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', 'rs/', {'image':'mariadb', 'root_password' : 'mariadb', 'port' : '3306', 'ip': '', 'ssh_user': '', 'ssh_key': ''})
keystone_db = resource.create('keystone_db', 'resources/mariadb_db/', 'rs/', {'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/', 'rs/', {'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/', 'rs/', {'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/', 'rs/', {'port':'5001', 'admin_port':'35357', 'ip':'', 'ssh_key':'', 'ssh_user':'', 'config_dir':'', 'config_dir':''})
keystone_service1 = resource.create('keystone_service1', 'resources/keystone_service/', 'rs/', {'port':'5001', 'admin_port':'35357', 'image': '', 'ip':'', 'ssh_key':'', 'ssh_user':'', 'config_dir':''})
keystone_config2 = resource.create('keystone_config2', 'resources/keystone_config/', 'rs/', {'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/', 'rs/', {'port':'5002', 'admin_port':'35357', 'ip':'', 'ssh_key':'', 'ssh_user':'', 'config_dir':'', 'config_dir':''})
keystone_service2 = resource.create('keystone_service2', 'resources/keystone_service/', 'rs/', {'port':'5002', 'admin_port':'35357', 'image': '', 'ip':'', 'ssh_key':'', 'ssh_user':'', 'config_dir':''})
haproxy_keystone_config = resource.create('haproxy_keystone1_config', 'resources/haproxy_config/', 'rs/', {'name':'keystone_config', 'listen_port':'5000', 'servers':[], 'ports':[]})
haproxy_config = resource.create('haproxy_config', 'resources/haproxy', 'rs/', {'ip':'', 'ssh_key':'', 'ssh_user':'', 'configs_names':[], 'configs_ports':[], 'listen_ports':[], 'configs':[]})
haproxy_config = resource.create('haproxy_config', 'resources/haproxy', 'rs/', {'ip':'', 'ssh_key':'', 'ssh_user':'', 'configs_names':[], 'configs_ports':[], 'listen_ports':[], 'configs':[], 'config_dir': ''})
haproxy_service = resource.create('haproxy_service', 'resources/docker_container/', 'rs/', {'image' : 'tutum/haproxy', 'ports': [], 'host_binds': [], 'volume_binds':[], 'ip':'', 'ssh_key':'', 'ssh_user':''})
@ -71,6 +72,23 @@ signals.connect(node2, haproxy_service)
signals.connect(haproxy_config, haproxy_service, {'listen_ports':'ports', 'config_dir':'host_binds'})
from solar.core import validation
for r in [node1,
node2,
mariadb_service1,
keystone_db,
keystone_db_user,
keystone_config1,
keystone_service1,
keystone_config2,
keystone_service2,
haproxy_keystone_config,
haproxy_config,
haproxy_service]:
validation.validate_resource(r)
#run
from solar.core import actions
@ -80,6 +98,7 @@ actions.resource_action(keystone_db, 'run')
actions.resource_action(keystone_db_user, 'run')
actions.resource_action(keystone_config1, 'run')
actions.resource_action(keystone_service1, 'run')
actions.resource_action(keystone_config2, 'run')
actions.resource_action(keystone_service2, 'run')
actions.resource_action(haproxy_config, 'run')
actions.resource_action(haproxy_service, 'run')
@ -93,3 +112,9 @@ actions.resource_action(haproxy_service, 'run')
#actions.resource_action(keystone_db_user, 'remove')
#actions.resource_action(keystone_db, 'remove')
#actions.resource_action(mariadb_service1, 'remove')
# test working configuration
requests.get('http://%s:%s' % (keystone_service1.args['ip'].value, keystone_service1.args['port'].value))
requests.get('http://%s:%s' % (keystone_service2.args['ip'].value, keystone_service2.args['port'].value))
requests.get('http://%s:%s' % (haproxy_service.args['ip'].value, haproxy_service.args['ports'].value[0]['value'][0]['value']))

View File

@ -3,3 +3,4 @@ jinja2==2.7.3
networkx==1.9.1
PyYAML==3.11
jsonschema==2.4.0
requests==2.7.0

View File

@ -9,7 +9,9 @@
net: host
ports:
{% for port in ports.value %}
- {{ port['value'] }}:{{ port['value'] }}
{% for p in port['value'] %}
- {{ p['value'] }}:{{ p['value'] }}
{% endfor %}
{% endfor %}
volumes:
# TODO: host_binds might need more work

View File

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

View File

@ -4,9 +4,9 @@ import os
import shutil
import yaml
from x import db
from x import resource as xr
from x import signals as xs
from solar.core import db
from solar.core import resource as xr
from solar.core import signals as xs
def deploy(filename):

View File

@ -27,7 +27,11 @@ class Resource(object):
metadata_arg = self.metadata['input'][arg_name]
type_ = validation.schema_input_type(metadata_arg.get('schema', 'str'))
self.args[arg_name] = observer.create(type_, self, arg_name, arg_value)
value = arg_value
if not value and metadata_arg['value']:
value = metadata_arg['value']
self.args[arg_name] = observer.create(type_, self, arg_name, value)
self.changed = []
self.tags = tags or []

View File

@ -38,7 +38,6 @@ input:
errors = sv.validate_resource(r)
self.assertListEqual(errors.keys(), ['value-required'])
def test_input_int_type(self):
sample_meta_dir = self.make_resource_meta("""
id: sample