From 1127551369b92a98d8cb2d317b1918ae06d13a66 Mon Sep 17 00:00:00 2001 From: Raphael Randschau Date: Thu, 23 Feb 2012 17:24:08 +0100 Subject: [PATCH] rename supervisord base template to app add supervisord stub --- Gemfile.lock | 30 ++++---- .../{master.conf.erb => app.conf.erb} | 2 +- lib/foreman/export/supervisord.rb | 6 +- spec/foreman/export/supervisord_spec.rb | 75 +++++++++++++++++++ spec/resources/export/supervisord/app.conf | 10 +++ 5 files changed, 105 insertions(+), 18 deletions(-) rename data/export/supervisord/{master.conf.erb => app.conf.erb} (81%) create mode 100644 spec/foreman/export/supervisord_spec.rb create mode 100644 spec/resources/export/supervisord/app.conf diff --git a/Gemfile.lock b/Gemfile.lock index cec1000..da9b4de 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -13,28 +13,30 @@ GEM mime-types xml-simple builder (3.0.0) - crack (0.1.8) + crack (0.3.1) diff-lcs (1.1.3) fakefs (0.3.2) hpricot (0.8.6) hpricot (0.8.6-java) - mime-types (1.16) - multi_json (1.0.4) - mustache (0.11.2) - parka (0.6.2) - crack - rest-client - thor + mime-types (1.17.2) + multi_json (1.1.0) + mustache (0.99.4) + parka (0.8.0) + crack (~> 0.3.0) + psych (~> 1.2.1) + rest-client (~> 1.6.7) + thor (~> 0.14.6) posix-spawn (0.3.6) + psych (1.2.2) rake (0.9.2.2) - rdiscount (1.6.5) - rest-client (1.6.1) + rdiscount (1.6.8) + rest-client (1.6.7) mime-types (>= 1.16) ronn (0.7.3) hpricot (>= 0.8.2) mustache (>= 0.7.0) rdiscount (>= 1.5.8) - rr (1.0.2) + rr (1.0.4) rspec (2.8.0) rspec-core (~> 2.8.0) rspec-expectations (~> 2.8.0) @@ -43,14 +45,14 @@ GEM rspec-expectations (2.8.0) diff-lcs (~> 1.1.2) rspec-mocks (2.8.0) - simplecov (0.5.4) - multi_json (~> 1.0.3) + simplecov (0.6.0) + multi_json (~> 1.0) simplecov-html (~> 0.5.3) simplecov-html (0.5.3) term-ansicolor (1.0.7) thor (0.14.6) win32console (1.3.0-x86-mingw32) - xml-simple (1.0.15) + xml-simple (1.1.1) PLATFORMS java diff --git a/data/export/supervisord/master.conf.erb b/data/export/supervisord/app.conf.erb similarity index 81% rename from data/export/supervisord/master.conf.erb rename to data/export/supervisord/app.conf.erb index 4597f73..c56d327 100644 --- a/data/export/supervisord/master.conf.erb +++ b/data/export/supervisord/app.conf.erb @@ -13,7 +13,7 @@ stdout_logfile=<%= log_root %>/<%=process.name%>-<%=num%>.log stderr_logfile=<%= log_root %>/<%=process.name%>-<%=num%>err.log user=<%= user %> directory=<%= engine.directory %> -environment=<% engine.environment.each_pair { |var,env| "#{var.upcase}=#{env}" }.join(',') %>,<%= "PORT=#{port}" %> +environment=<% (engine.environment.each_pair { |var,env| "#{var.upcase}=#{env}" }.to_a + ["PORT=#{port}"]).join(',') %> <% end end diff --git a/lib/foreman/export/supervisord.rb b/lib/foreman/export/supervisord.rb index 4c4a13f..4afc4b4 100644 --- a/lib/foreman/export/supervisord.rb +++ b/lib/foreman/export/supervisord.rb @@ -18,9 +18,9 @@ class Foreman::Export::Supervisord < Foreman::Export::Base FileUtils.rm(file) end - master_template = export_template("supervisord", "master.conf.erb", template_root) - master_config = ERB.new(master_template).result(binding) - write_file "#{location}/#{app}.conf", master_config + app_template = export_template("supervisord", "app.conf.erb", template_root) + app_config = ERB.new(app_template).result(binding) + write_file "#{location}/#{app}.conf", app_config end end diff --git a/spec/foreman/export/supervisord_spec.rb b/spec/foreman/export/supervisord_spec.rb new file mode 100644 index 0000000..d921a23 --- /dev/null +++ b/spec/foreman/export/supervisord_spec.rb @@ -0,0 +1,75 @@ +require "spec_helper" +require "foreman/engine" +require "foreman/export/supervisord" +require "tmpdir" + +describe Foreman::Export::Supervisord, :fakefs do + let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") } + let(:engine) { Foreman::Engine.new(procfile) } + let(:options) { Hash.new } + let(:supervisord) { Foreman::Export::Supervisord.new("/tmp/init", engine, options) } + + before(:each) { load_export_templates_into_fakefs("supervisord") } + before(:each) { stub(supervisord).say } + + it "exports to the filesystem" do + supervisord.export + + File.read("/tmp/init/app.conf").should == example_export_file("supervisord/app.conf") + end + + it "cleans up if exporting into an existing dir" do + mock(FileUtils).rm("/tmp/init/app.conf") + + supervisord.export + supervisord.export + end + + context "with concurrency" do + let(:options) { Hash[:concurrency => "alpha=2"] } + + it "exports to the filesystem with concurrency" do + pending + end + end + + context "with alternate templates" do + let(:template_root) { "/tmp/alternate" } + let(:upstart) { Foreman::Export::Upstart.new("/tmp/init", engine, :template => template_root) } + + before do + FileUtils.mkdir_p template_root + File.open("#{template_root}/master.conf.erb", "w") { |f| f.puts "alternate_template" } + end + + it "can export with alternate template files" do + upstart.export + + File.read("/tmp/init/app.conf").should == "alternate_template\n" + pendign + end + end + + context "with alternate templates from home dir" do + let(:default_template_root) {File.expand_path("#{ENV['HOME']}/.foreman/templates")} + + before do + ENV['_FOREMAN_SPEC_HOME'] = ENV['HOME'] + ENV['HOME'] = "/home/appuser" + FileUtils.mkdir_p default_template_root + File.open("#{default_template_root}/master.conf.erb", "w") { |f| f.puts "default_alternate_template" } + end + + after do + ENV['HOME'] = ENV.delete('_FOREMAN_SPEC_HOME') + end + + it "can export with alternate template files" do + upstart.export + + File.read("/tmp/init/app.conf").should == "default_alternate_template\n" + pending + end + end + +end diff --git a/spec/resources/export/supervisord/app.conf b/spec/resources/export/supervisord/app.conf new file mode 100644 index 0000000..d757914 --- /dev/null +++ b/spec/resources/export/supervisord/app.conf @@ -0,0 +1,10 @@ +[program:app-alpha] +command=./alpha +autostart=true +autorestart=true +stopsignal=QUIT +stdout_logfile=/var/log/app/alpha-1.log +stderr_logfile=/var/log/app/alpha-1err.log +user=app +directory=/tmp/app +environment=PORT=5000 \ No newline at end of file