HAProxy deployment

- Added ports mapping to Docker container
- tests refactored
This commit is contained in:
Przemyslaw Kaminski 2015-04-22 09:13:17 +02:00
parent 98e5b3375b
commit a8ae9cdf26
6 changed files with 81 additions and 57 deletions

View File

@ -116,13 +116,6 @@ resources:
ssh_user:
ssh_key:
#- name: haproxy-config-container
# model: x/resources/data_container/
# args:
# ip:
# image: haproxy-config
# export_volumes:
# - haproxy-config
- name: haproxy-config
model: x/resources/haproxy/
args:
@ -136,6 +129,7 @@ resources:
args:
ip:
image: tutum/haproxy
ports: {}
ssh_user:
ssh_key:
host_binds: {}
@ -185,10 +179,6 @@ connections:
- emitter: node5
receiver: haproxy-config
#- emitter: node5
# receiver: haproxy-config-container
#- emitter: haproxy-config-container
# receiver: haproxy-config
- emitter: haproxy_keystone_config
receiver: haproxy-config
mapping:
@ -204,15 +194,7 @@ connections:
receiver: haproxy
mapping:
ip: ip
configs_ports: ports
ssh_user: ssh_user
ssh_key: ssh_key
config_dir: host_binds
# HAProxy service
#- emitter: node5
# receiver: haproxy
#- emitter: haproxy-config
# receiver: haproxy
# mapping:

View File

@ -92,6 +92,10 @@ class TestHAProxyDeployment(unittest.TestCase):
},
haproxy.args['host_binds']
)
self.assertItemsEqual(
haproxy.args['ports'],
haproxy_config.args['configs_ports'],
)
def main():

View File

@ -9,11 +9,17 @@
name: {{ name }}
image: {{ image }}
state: running
ports:
{% for name, ports_dict in ports.items() %}
# TODO: this is ugly
# {{ name }}
- {{ ports_dict.values()[0] }}:{{ ports_dict.values()[0] }}
{% endfor %}
volumes:
# TODO: host_binds might need more work
# Currently it's not that trivial to pass custom src: dst here
# (when a config variable is passed here from other resource)
# so we mount it to the same directory as on host
{% for emitter, bind in host_binds.items() %}
- {{ bind }}:{{ bind }}
{% endfor %}
# TODO: host_binds might need more work
# Currently it's not that trivial to pass custom src: dst here
# (when a config variable is passed here from other resource)
# so we mount it to the same directory as on host
{% for emitter, bind in host_binds.items() %}
- {{ bind }}:{{ bind }}
{% endfor %}

View File

@ -3,11 +3,13 @@ handler: ansible
version: 1.0.0
input:
ip:
image:
image:
ports:
host_binds:
volume_binds:
ssh_user:
ssh_key:
input-types:
ports:
host_binds: list
volume_binds: list

36
x/test/base.py Normal file
View File

@ -0,0 +1,36 @@
import os
import shutil
import tempfile
import unittest
import yaml
from x import db
from x import resource as xr
from x import signals as xs
class BaseResourceTest(unittest.TestCase):
def setUp(self):
self.storage_dir = tempfile.mkdtemp()
def tearDown(self):
shutil.rmtree(self.storage_dir)
db.clear()
xs.clear()
def make_resource_meta(self, meta_yaml):
meta = yaml.load(meta_yaml)
path = os.path.join(self.storage_dir, meta['id'])
os.makedirs(path)
with open(os.path.join(path, 'meta.yaml'), 'w') as f:
f.write(meta_yaml)
return path
def create_resource(self, name, src, args):
dst = os.path.join(self.storage_dir, 'rs', name)
os.makedirs(dst)
return xr.create(name, src, dst, args)

View File

@ -1,39 +1,34 @@
import os
import shutil
import tempfile
import unittest
import yaml
from x import db
from x import resource as xr
import base
from x import signals as xs
class TestListInput(unittest.TestCase):
def setUp(self):
self.storage_dir = tempfile.mkdtemp()
class TestBaseInput(base.BaseResourceTest):
def test_input_dict_type(self):
sample_meta_dir = self.make_resource_meta("""
id: sample
handler: ansible
version: 1.0.0
input:
values: {}
""")
def tearDown(self):
shutil.rmtree(self.storage_dir)
db.clear()
xs.clear()
sample1 = self.create_resource(
'sample1', sample_meta_dir, {'values': {'a': 1, 'b': 2}}
)
sample2 = self.create_resource(
'sample2', sample_meta_dir, {'values': None}
)
xs.connect(sample1, sample2)
self.assertItemsEqual(
sample1.args['values'],
sample2.args['values'],
)
def make_resource_meta(self, meta_yaml):
meta = yaml.load(meta_yaml)
path = os.path.join(self.storage_dir, meta['id'])
os.makedirs(path)
with open(os.path.join(path, 'meta.yaml'), 'w') as f:
f.write(meta_yaml)
return path
def create_resource(self, name, src, args):
dst = os.path.join(self.storage_dir, 'rs', name)
os.makedirs(dst)
return xr.create(name, src, dst, args)
class TestListInput(base.BaseResourceTest):
def test_list_input_single(self):
sample_meta_dir = self.make_resource_meta("""
id: sample
@ -79,7 +74,6 @@ input-types:
}
)
def test_list_input_multi(self):
sample_meta_dir = self.make_resource_meta("""
id: sample