Skip to content

Commit

Permalink
Haproxy to use consul for service discovery
Browse files Browse the repository at this point in the history
Setup Haproxy to use consul for service discovery.
Earlier it was using etcd.

Also, update the tests.

1. Have the openrc file used for testing use the
   lb.keystone.service.consul address.

2. Be way more aggressive about the test used to
   validate a functional haproxy instance. Ensure
   that it is forwarding traffic to both keystone
   as well as glance explicitly.
  • Loading branch information
hkumarmk authored and bodepd committed Oct 20, 2014
1 parent f2b8ec6 commit 4af0bbb
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 57 deletions.
2 changes: 0 additions & 2 deletions files/maybe-upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ rv=$?

run_puppet() {
# ensure that our service catalog hiera data is available
python -m jiocloud.orchestrate --host=etcd.service.consul cache_services
# now run puppet
puppet apply --detailed-exitcodes --logdest=syslog `puppet config print manifestdir`/site.pp
# publish the results of that run
ret_code=$?
python -m jiocloud.orchestrate --host=etcd.service.consul publish_service
python -m jiocloud.orchestrate --host=etcd.service.consul update_own_status puppet $ret_code
if [[ $ret_code = 1 || $ret_code = 4 || $ret_code = 6 ]]; then
echo "Puppet failed with return code ${ret_code}"
Expand Down
2 changes: 1 addition & 1 deletion hiera/data/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ rjil::keystone::test_user::password: test_password
openstack_extras::auth_file::admin_password: "%{hiera('rjil::keystone::test_user::password')}"
openstack_extras::auth_file::admin_user: test_user
openstack_extras::auth_file::admin_tenant: test_tenant
openstack_extras::auth_file::controller_node: "keystone.service.consul"
openstack_extras::auth_file::controller_node: "lb.keystone.service.consul"

########### glance config
###################################
Expand Down
4 changes: 0 additions & 4 deletions hiera/data/env/at.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ glance::bind_host: "%{ipaddress_eth0}"
rjil::jiocloud::etcd::addr: "%{ipaddress_eth0}:4001"
rjil::jiocloud::etcd::peer_addr: "%{ipaddress_eth0}:7001"

rjil::haproxy::openstack::keystone_ips: "%{lookup_array('services::keystone::eth0')}"
rjil::haproxy::openstack::keystone_internal_ips: "%{lookup_array('services::keystone::eth0')}"
rjil::haproxy::openstack::glance_ips: "%{lookup_array('services::glance::eth0')}"

rjil::keystone::public_address: "%{ipaddress_eth0}"

rjil::ceph::storage_cluster_if: eth0
Expand Down
4 changes: 0 additions & 4 deletions hiera/data/env/production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ cinder_internal_address: "volume-beta.jiocloud.com"
rjil::jiocloud::etcd::addr: "%{ipaddress_eth0}:4001"
rjil::jiocloud::etcd::peer_addr: "%{ipaddress_eth0}:7001"

rjil::haproxy::openstack::keystone_ips: "%{lookup_array('services::keystone::eth0')}"
rjil::haproxy::openstack::keystone_internal_ips: "%{lookup_array('services::keystone::eth0')}"
rjil::haproxy::openstack::glance_ips: "%{lookup_array('services::glance::eth0')}"

rjil::keystone::public_address: "%{ipaddress_eth0}"

# Don't let Jenkins log in in production
Expand Down
4 changes: 0 additions & 4 deletions hiera/data/env/staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ glance::bind_host: "%{ipaddress_eth2}"
rjil::jiocloud::etcd::addr: "%{ipaddress_eth2}:4001"
rjil::jiocloud::etcd::peer_addr: "%{ipaddress_eth2}:7001"

rjil::haproxy::openstack::keystone_ips: "%{lookup_array('services::keystone::eth2')}"
rjil::haproxy::openstack::keystone_internal_ips: "%{lookup_array('services::keystone::eth2')}"
rjil::haproxy::openstack::glance_ips: "%{lookup_array('services::glance::eth2')}"

rjil::keystone::public_address: "%{ipaddress_eth2}"

rjil::ceph::storage_cluster_if: eth2
Expand Down
4 changes: 0 additions & 4 deletions hiera/data/env/vagrant-vbox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ rjil::jiocloud::consul::server::bind_addr: "%{ipaddress_eth1}"
rjil::jiocloud::consul::bootstrapserver::bind_addr: "%{ipaddress_eth1}"
rjil::jiocloud::consul::agent::bind_addr: "%{ipaddress_eth1}"

rjil::haproxy::openstack::keystone_ips: "%{lookup_array('services::keystone::eth1')}"
rjil::haproxy::openstack::keystone_internal_ips: "%{lookup_array('services::keystone::eth1')}"
rjil::haproxy::openstack::glance_ips: "%{lookup_array('services::glance::eth1')}"

rjil::keystone::public_address: "%{ipaddress_eth1}"

rjil::ceph::storage_cluster_if: eth1
Expand Down
4 changes: 0 additions & 4 deletions hiera/data/env/vagrantlxc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@ glance::bind_host: "%{ipaddress_eth0}"
rjil::jiocloud::etcd::addr: "%{ipaddress_eth0}:4001"
rjil::jiocloud::etcd::peer_addr: "%{ipaddress_eth0}:7001"

rjil::haproxy::openstack::keystone_ips: "%{lookup_array('services::keystone::eth0')}"
rjil::haproxy::openstack::keystone_internal_ips: "%{lookup_array('services::keystone::eth0')}"
rjil::haproxy::openstack::glance_ips: "%{lookup_array('services::glance::eth0')}"

rjil::keystone::public_address: "%{ipaddress_eth0}"
1 change: 0 additions & 1 deletion hiera/data/role_env/ocdb-at.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
rjil::db::bind_address: "%{ipaddress_eth0}"
services::db::eth0: ["%{ipaddress_eth0}"]
1 change: 0 additions & 1 deletion hiera/data/role_env/ocdb-staging.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
rjil::db::bind_address: "%{ipaddress_eth2}"
services::db::eth0: ["%{ipaddress_eth2}"]
1 change: 0 additions & 1 deletion hiera/data/role_env/ocdb-vagrant-vbox.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
rjil::db::bind_address: "%{ipaddress_eth1}"
services::db::eth1: ["%{ipaddress_eth1}"]
37 changes: 37 additions & 0 deletions lib/puppet/parser/functions/service_discover_consul.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'net/http'
require 'uri'
require 'json'

module Puppet::Parser::Functions
newfunction(
:service_discover_consul,
:type => :rvalue,
:doc => <<-'EOS'
Given the name of a service and optionally, a tag, this function
returns a hash of the form:
(name => ip_address)
for each host that registered that service in consul
EOS
) do |args|
name = args.shift
tag = args.shift
raise(ArgumentError, "name must be specified") unless name
consul_host = args.shift || '127.0.0.1'
consul_port = args.shift || '8500'
tag_query = tag ? "?tag=#{tag}" : ''
uri = URI("http://#{consul_host}:#{consul_port}/v1/catalog/service/#{name}#{tag_query}")
res = Net::HTTP.get_response(uri)
if res.code == '200'
results = JSON.parse(res.body)
ret_hash = {}
results.each do |node|
ret_hash[node['Node']] = node['Address']
end
ret_hash
else
raise(Puppet::Error, "Uri: #{uri.to_s}, returned code #{res.code}")
end
end
end
2 changes: 0 additions & 2 deletions manifests/db.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

rjil::test { 'mysql.sh': }

rjil::profile { 'db': }

## Call db_def to create databases, users and grants
create_resources('rjil::db::instance', $dbs)
## setup mysql server
Expand Down
2 changes: 0 additions & 2 deletions manifests/glance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
## Add tests for glance api and registry
include rjil::test::glance

rjil::profile { 'glance': }

# ensure that we don't even try to configure the
# database connection until the service is up
ensure_resource( 'rjil::service_blocker', 'mysql', {})
Expand Down
18 changes: 10 additions & 8 deletions manifests/haproxy/openstack.pp
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#
# Class: rjil::haproxy::openstack
# Setup openstack services in haproxy.
#
class rjil::haproxy::openstack(
$horizon_ips = [],
$keystone_ips = [],
$keystone_internal_ips = [],
$glance_ips = [],
$cinder_ips = [],
$nova_ips = [],
$horizon_ips = values(service_discover_consul('horizon', 'real')),
$keystone_ips = values(service_discover_consul('keystone', 'real')),
$keystone_internal_ips = values(service_discover_consul('keystone-admin', 'real')),
$glance_ips = values(service_discover_consul('glance', 'real')),
$cinder_ips = values(service_discover_consul('cinder', 'real')),
$nova_ips = values(service_discover_consul('nova', 'real')),
$horizon_port = '80',
$horizon_https_port = '443',
$novncproxy_port = '6080',
Expand All @@ -18,8 +22,6 @@
$nova_ec2_port = '8773',
) {

rjil::profile { 'controller_load_balancer': }

class { 'rjil::test::haproxy_openstack':
horizon_ips => $horizon_ips,
keystone_ips => $keystone_ips,
Expand Down
2 changes: 0 additions & 2 deletions manifests/keystone.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

include rjil::test::keystone

rjil::profile { 'keystone': }

if $public_address == '0.0.0.0' {
$address = '127.0.0.1'
} else {
Expand Down
12 changes: 0 additions & 12 deletions manifests/profile.pp

This file was deleted.

5 changes: 2 additions & 3 deletions manifests/test/haproxy_openstack.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@

include rjil::test::base

if ($keystone_ips != [] or $keystone_internal_ips != []) {
include keystone::client
}
include keystone::client
include glance::client

file { "/usr/lib/jiocloud/tests/haproxy_openstack.sh":
content => template('rjil/tests/haproxy_openstack.sh.erb'),
Expand Down
3 changes: 1 addition & 2 deletions templates/tests/haproxy_openstack.sh.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
set -e
test -f /root/openrc
source /root/openrc
<% if @keystone_ips != [] -%>
keystone catalog
<% end %>
glance image-list

0 comments on commit 4af0bbb

Please sign in to comment.