Deployment from YAML file, added tests for haproxy

This commit is contained in:
Przemyslaw Kaminski
2015-04-20 19:11:28 +02:00
parent a3c5d5a0e6
commit 6bfc7fd1c0
6 changed files with 301 additions and 0 deletions

View File

@@ -0,0 +1 @@
__author__ = 'przemek'

View File

@@ -0,0 +1,50 @@
#!/usr/bin/env bash
# HAProxy deployment with Keystone and Nova
set -e
cd /vagrant
rm clients.json
rm -Rf rs/*
# Create resources
python cli.py resource create node1 x/resources/ro_node/ rs/ '{"ip":"10.0.0.3", "ssh_key" : "/vagrant/tmp/keys/ssh_private", "ssh_user":"vagrant"}'
python cli.py resource create node2 x/resources/ro_node/ rs/ '{"ip":"10.0.0.4", "ssh_key" : "/vagrant/tmp/keys/ssh_private", "ssh_user":"vagrant"}'
python cli.py resource create node3 x/resources/ro_node/ rs/ '{"ip":"10.0.0.5", "ssh_key" : "/vagrant/tmp/keys/ssh_private", "ssh_user":"vagrant"}'
python cli.py resource create node4 x/resources/ro_node/ rs/ '{"ip":"10.0.0.6", "ssh_key" : "/vagrant/tmp/keys/ssh_private", "ssh_user":"vagrant"}'
python cli.py resource create node5 x/resources/ro_node/ rs/ '{"ip":"10.0.0.7", "ssh_key" : "/vagrant/tmp/keys/ssh_private", "ssh_user":"vagrant"}'
python cli.py resource create mariadb_keystone1_data x/resources/data_container/ rs/ '{"image": "mariadb", "export_volumes" : ["/var/lib/mysql"], "ip": "", "ssh_user": "", "ssh_key": ""}'
python cli.py resource create mariadb_keystone2_data x/resources/data_container/ rs/ '{"image": "mariadb", "export_volumes" : ["/var/lib/mysql"], "ip": "", "ssh_user": "", "ssh_key": ""}'
python cli.py resource create keystone1 x/resources/keystone/ rs/ '{"ip": "", "ssh_user": "", "ssh_key": ""}'
python cli.py resource create keystone2 x/resources/keystone/ rs/ '{"ip": "", "ssh_user": "", "ssh_key": ""}'
python cli.py resource create haproxy_keystone_config x/resources/haproxy_config/ rs/ '{"servers": {}, "ssh_user": "", "ssh_key": ""}'
python cli.py resource create mariadb_nova1_data x/resources/data_container/ rs/ '{"image" : "mariadb", "export_volumes" : ["/var/lib/mysql"], "ip": "", "ssh_user": "", "ssh_key": ""}'
python cli.py resource create mariadb_nova2_data x/resources/data_container/ rs/ '{"image" : "mariadb", "export_volumes" : ["/var/lib/mysql"], "ip": "", "ssh_user": "", "ssh_key": ""}'
python cli.py resource create nova1 x/resources/nova/ rs/ '{"ip": "", "ssh_user": "", "ssh_key": ""}'
python cli.py resource create nova2 x/resources/nova/ rs/ '{"ip": "", "ssh_user": "", "ssh_key": ""}'
python cli.py resource create haproxy_nova_config x/resources/haproxy_config/ rs/ '{"ip": "", "servers": {}, "ssh_user": "", "ssh_key": ""}'
python cli.py resource create haproxy x/resources/haproxy/ rs/ '{"ip": "", "configs": {}, "ssh_user": "", "ssh_key": ""}'
# Connect resources
python cli.py connect rs/node1 rs/mariadb_keystone1_data
python cli.py connect rs/node2 rs/mariadb_keystone2_data
python cli.py connect rs/mariadb_keystone1_data rs/keystone1
python cli.py connect rs/mariadb_keystone2_data rs/keystone2
python cli.py connect rs/keystone1 rs/haproxy_keystone_config --mapping '{"ip": "servers"}'
python cli.py connect rs/keystone2 rs/haproxy_keystone_config --mapping '{"ip": "servers"}'
python cli.py connect rs/node3 rs/mariadb_nova1_data
python cli.py connect rs/node4 rs/mariadb_nova2_data
python cli.py connect rs/mariadb_nova1_data rs/nova1
python cli.py connect rs/mariadb_nova2_data rs/nova2
python cli.py connect rs/nova1 rs/haproxy_nova_config --mapping '{"ip": "servers"}'
python cli.py connect rs/nova2 rs/haproxy_nova_config --mapping '{"ip": "servers"}'
python cli.py connect rs/node5 rs/haproxy
python cli.py connect rs/haproxy_keystone_config rs/haproxy --mapping '{"server": "configs"}'
python cli.py connect rs/haproxy_nova_config rs/haproxy --mapping '{"server": "configs"}'

View File

@@ -0,0 +1,166 @@
# HAProxy deployment with MariaDB, Keystone and Nova
workdir: /vagrant
resource-save-path: rs/
test-suite: haproxy_deployment.haproxy_deployment
resources:
- name: node1
model: x/resources/ro_node/
args:
ip: 10.0.0.3
ssh_key: /vagrant/tmp/keys/ssh_private
ssh_user: vagrant
- name: node2
model: x/resources/ro_node/
args:
ip: 10.0.0.4
ssh_key: /vagrant/tmp/keys/ssh_private
ssh_user: vagrant
- name: node3
model: x/resources/ro_node/
args:
ip: 10.0.0.5
ssh_key: /vagrant/tmp/keys/ssh_private
ssh_user: vagrant
- name: node4
model: x/resources/ro_node/
args:
ip: 10.0.0.6
ssh_key: /vagrant/tmp/keys/ssh_private
ssh_user: vagrant
- name: node5
model: x/resources/ro_node/
args:
ip: 10.0.0.7
ssh_key: /vagrant/tmp/keys/ssh_private
ssh_user: vagrant
- name: mariadb_keystone1_data
model: x/resources/data_container/
args:
image: mariadb
export_volumes:
- /var/lib/mysql
ip:
ssh_user:
ssh_key:
- name: mariadb_keystone2_data
model: x/resources/data_container/
args:
image: mariadb
export_volumes:
- /var/lib/mysql
ip:
ssh_user:
ssh_key:
- name: keystone1
model: x/resources/keystone/
args:
ip:
ssh_user:
ssh_key:
- name: keystone2
model: x/resources/keystone/
args:
ip:
ssh_user:
ssh_key:
- name: haproxy_keystone_config
model: x/resources/haproxy_config/
args:
servers: {}
ssh_user:
ssh_key:
- name: mariadb_nova1_data
model: x/resources/data_container/
args:
image: mariadb
export_volumes:
- /var/lib/mysql
ip:
ssh_user:
ssh_key:
- name: mariadb_nova2_data
model: x/resources/data_container/
args:
image: mariadb
export_volumes:
- /var/lib/mysql
ip:
ssh_user:
ssh_key:
- name: nova1
model: x/resources/nova/
args:
ip:
ssh_user:
ssh_key:
- name: nova2
model: x/resources/nova/
args:
ip:
ssh_user:
ssh_key:
- name: haproxy_nova_config
model: x/resources/haproxy_config/
args:
servers: {}
ssh_user:
ssh_key:
- name: haproxy
model: x/resources/haproxy/
args:
ip:
configs: {}
ssh_user:
ssh_key:
connections:
- emitter: node1
receiver: mariadb_keystone1_data
- emitter: node2
receiver: mariadb_keystone2_data
- emitter: mariadb_keystone1_data
receiver: keystone1
- emitter: mariadb_keystone2_data
receiver: keystone2
- emitter: keystone1
receiver: haproxy_keystone_config
mapping:
ip: servers
- emitter: keystone2
receiver: haproxy_keystone_config
mapping:
ip: servers
- emitter: node3
receiver: mariadb_nova1_data
- emitter: node4
receiver: mariadb_nova2_data
- emitter: mariadb_nova1_data
receiver: nova1
- emitter: mariadb_nova2_data
receiver: nova2
- emitter: nova1
receiver: haproxy_nova_config
mapping:
ip: servers
- emitter: nova2
receiver: haproxy_nova_config
mapping:
ip: servers
- emitter: node5
receiver: haproxy
- emitter: haproxy_keystone_config
receiver: haproxy
mapping:
server: configs
- emitter: haproxy_nova_config
receiver: haproxy
mapping:
server: configs

View File

@@ -0,0 +1,61 @@
import unittest
from x import db
class TestHAProxyDeployment(unittest.TestCase):
def test_keystone_config(self):
node1 = db.get_resource('node1')
node2 = db.get_resource('node2')
keystone1 = db.get_resource('keystone1')
keystone2 = db.get_resource('keystone2')
self.assertEqual(keystone1.args['ip'], node1.args['ip'])
self.assertEqual(keystone2.args['ip'], node2.args['ip'])
def test_haproxy_keystone_config(self):
keystone1 = db.get_resource('keystone1')
keystone2 = db.get_resource('keystone2')
haproxy_keystone_config = db.get_resource('haproxy_keystone_config')
self.assertDictEqual(
haproxy_keystone_config.args['servers'],
{
'keystone1': keystone1.args['ip'],
'keystone2': keystone2.args['ip'],
}
)
def test_nova_config(self):
node3 = db.get_resource('node3')
node4 = db.get_resource('node4')
nova1 = db.get_resource('nova1')
nova2 = db.get_resource('nova2')
self.assertEqual(nova1.args['ip'], node3.args['ip'])
self.assertEqual(nova2.args['ip'], node4.args['ip'])
def test_haproxy_nova_config(self):
nova1 = db.get_resource('nova1')
nova2 = db.get_resource('nova2')
haproxy_nova_config = db.get_resource('haproxy_nova_config')
self.assertDictEqual(
haproxy_nova_config.args['servers'],
{
'nova1': nova1.args['ip'],
'nova2': nova2.args['ip'],
}
)
def test_haproxy(self):
node5 = db.get_resource('node5')
haproxy = db.get_resource('haproxy')
self.assertEqual(node5.args['ip'], haproxy.args['ip'])
def main():
loader = unittest.TestLoader()
suite = loader.loadTestsFromTestCase(TestHAProxyDeployment)
unittest.TextTestRunner().run(suite)