From 39dd110a74fcb2e0e92e7e7afffec07f35972b6c Mon Sep 17 00:00:00 2001 From: Shane Sveller Date: Mon, 23 Feb 2015 19:16:56 -0600 Subject: [PATCH] Add simple Atlas support --- .kitchen.yml | 8 +++++++ README.md | 24 +++++++++++++++++++ attributes/default.rb | 5 ++++ recipes/_service.rb | 11 +++++++++ .../atlas/serverspec/localhost/atlas_spec.rb | 22 +++++++++++++++++ .../atlas/serverspec/spec_helper.rb | 7 ++++++ 6 files changed, 77 insertions(+) create mode 100644 test/integration/atlas/serverspec/localhost/atlas_spec.rb create mode 100644 test/integration/atlas/serverspec/spec_helper.rb diff --git a/.kitchen.yml b/.kitchen.yml index a1453734..abb90499 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -49,3 +49,11 @@ suites: consul: service_mode: cluster bootstrap_expect: 1 + - name: atlas + run_list: + - recipe[consul::default] + attributes: + consul: + atlas_autojoin: true + atlas_cluster: <%= ENV.fetch('ATLAS_CLUSTER', 'example/cluster') %> + atlas_token: <%= ENV.fetch('ATLAS_TOKEN', 'NOT_REAL') %> \ No newline at end of file diff --git a/README.md b/README.md index 392f9e69..b9511739 100644 --- a/README.md +++ b/README.md @@ -254,6 +254,30 @@ Installs and configures [Consul][1] client, server and UI. This provides the address of a statsd instance (UDP). nil + + ['consul']['atlas_autojoin'] + Boolean + + Determines whether Consul attempts to auto-join the cluster provided by atlas_cluster using the value of atlas_token + + false + + + ['consul']['atlas_cluster'] + String + + Name of Atlas cluster to auto-join + + nil + + + ['consul']['atlas_token'] + String + + API token used for Atlas integration + + nil + ### Databag Attributes (optional) diff --git a/attributes/default.rb b/attributes/default.rb index 5b15ab31..a3bf2e61 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -113,3 +113,8 @@ default['consul']['client_addr'] = '0.0.0.0' default['consul']['serve_ui'] = false default['consul']['extra_params'] = {} + +# Atlas support +default['consul']['atlas_autojoin'] = false +default['consul']['atlas_cluster'] = nil +default['consul']['atlas_token'] = nil diff --git a/recipes/_service.rb b/recipes/_service.rb index d45ee70c..f70b7df1 100644 --- a/recipes/_service.rb +++ b/recipes/_service.rb @@ -177,6 +177,17 @@ end end +# Atlas integration +if node.consul.atlas_autojoin or node.consul.atlas_token + cluster = node.consul.atlas_cluster + token = node.consul.atlas_token + raise "atlas_cluster is empty or nil" if cluster.empty? or cluster.nil? + raise "atlas_token is empty or nil" if token.empty? or token.nil? + service_config['atlas_infrastructure'] = cluster + service_config['atlas_join'] = node.consul.atlas_autojoin + service_config['atlas_token'] = token +end + consul_config_filename = File.join(node['consul']['config_dir'], 'default.json') file consul_config_filename do diff --git a/test/integration/atlas/serverspec/localhost/atlas_spec.rb b/test/integration/atlas/serverspec/localhost/atlas_spec.rb new file mode 100644 index 00000000..0da40b2b --- /dev/null +++ b/test/integration/atlas/serverspec/localhost/atlas_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +describe command('which consul') do + its(:exit_status) { should eq 0 } + its(:stdout) { should match '/usr/local/bin/consul' } +end + +describe service('consul') do + it { should be_enabled } + it { should be_running } +end + +describe file('/etc/consul.d') do + it { should be_directory } +end + +describe command('grep atlas /etc/consul.d/default.json') do + its(:exit_status) { should eq 0 } + its(:stdout) { should match %r{"atlas_infrastructure":\s"([^"]*)"} } + its(:stdout) { should match %r{"atlas_join":\s(true|false)} } + its(:stdout) { should match %r{"atlas_token":\s"([^"]*)"} } +end diff --git a/test/integration/atlas/serverspec/spec_helper.rb b/test/integration/atlas/serverspec/spec_helper.rb new file mode 100644 index 00000000..c0925118 --- /dev/null +++ b/test/integration/atlas/serverspec/spec_helper.rb @@ -0,0 +1,7 @@ +require 'serverspec' + +set :backend, :exec + +RSpec.configure do |c| + c.path = '/usr/local/bin:/sbin:/bin:/usr/bin' +end