machines 0.5.4 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. data/.yardopts +7 -1
  2. data/CHANGELOG.md +16 -4
  3. data/INSTALL.md +3 -0
  4. data/LICENSE +1 -2
  5. data/README.md +47 -28
  6. data/Rakefile +0 -8
  7. data/TODO.md +66 -59
  8. data/bin/machines +1 -2
  9. data/lib/machines.rb +16 -1
  10. data/lib/machines/app_settings.rb +1 -1
  11. data/lib/machines/cloud_machine.rb +1 -1
  12. data/lib/machines/command.rb +0 -2
  13. data/lib/machines/commandline.rb +23 -29
  14. data/lib/machines/commands/checks.rb +67 -0
  15. data/lib/machines/commands/configuration.rb +50 -0
  16. data/lib/machines/commands/database.rb +18 -0
  17. data/lib/machines/commands/file_operations.rb +105 -0
  18. data/lib/machines/commands/installation.rb +184 -0
  19. data/lib/machines/commands/questions.rb +16 -0
  20. data/lib/machines/commands/services.rb +26 -0
  21. data/lib/machines/core.rb +55 -25
  22. data/lib/machines/logger.rb +0 -2
  23. data/lib/machines/named_buffer.rb +7 -6
  24. data/lib/machines/version.rb +1 -1
  25. data/lib/packages/awstats.rb +2 -2
  26. data/lib/packages/docky.rb +0 -1
  27. data/lib/packages/dwm.rb +5 -0
  28. data/lib/packages/nginx_logrotate.rb +2 -2
  29. data/lib/packages/timezone.rb +2 -4
  30. data/lib/template/Machinesfile +2 -1
  31. data/lib/template/config.yml +3 -0
  32. data/spec/lib/machines/app_settings_spec.rb +13 -12
  33. data/spec/lib/machines/cloud_machine_spec.rb +9 -8
  34. data/spec/lib/machines/commandline_spec.rb +69 -90
  35. data/spec/lib/machines/{checks_spec.rb → commands/checks_spec.rb} +1 -1
  36. data/spec/lib/machines/{configuration_spec.rb → commands/configuration_spec.rb} +2 -3
  37. data/spec/lib/machines/{database_spec.rb → commands/database_spec.rb} +4 -10
  38. data/spec/lib/machines/{file_operations_spec.rb → commands/file_operations_spec.rb} +3 -7
  39. data/spec/lib/machines/{installation_spec.rb → commands/installation_spec.rb} +10 -4
  40. data/spec/lib/machines/{questions_spec.rb → commands/questions_spec.rb} +1 -3
  41. data/spec/lib/machines/{services_spec.rb → commands/services_spec.rb} +1 -4
  42. data/spec/lib/machines/core_spec.rb +81 -65
  43. data/spec/lib/packages/abiword_spec.rb +1 -5
  44. data/spec/lib/packages/amazon_mp3_spec.rb +0 -4
  45. data/spec/lib/packages/awstats_spec.rb +3 -4
  46. data/spec/lib/packages/base_spec.rb +0 -1
  47. data/spec/lib/packages/chrome_spec.rb +0 -4
  48. data/spec/lib/packages/cruisecontrol_spec.rb +1 -2
  49. data/spec/lib/packages/dependencies_spec.rb +1 -2
  50. data/spec/lib/packages/docky_spec.rb +0 -4
  51. data/spec/lib/packages/dotfiles_spec.rb +5 -4
  52. data/spec/lib/packages/dwm_spec.rb +23 -0
  53. data/spec/lib/packages/file_roller_spec.rb +1 -5
  54. data/spec/lib/packages/firefox_spec.rb +0 -4
  55. data/spec/lib/packages/gedit_spec.rb +1 -5
  56. data/spec/lib/packages/git_spec.rb +0 -4
  57. data/spec/lib/packages/gmate_spec.rb +1 -5
  58. data/spec/lib/packages/gnome_spec.rb +0 -4
  59. data/spec/lib/packages/gnumeric_spec.rb +1 -5
  60. data/spec/lib/packages/hosts_spec.rb +0 -1
  61. data/spec/lib/packages/load_machines_spec.rb +16 -15
  62. data/spec/lib/packages/monit_spec.rb +0 -1
  63. data/spec/lib/packages/mysql_spec.rb +1 -3
  64. data/spec/lib/packages/nginx_logrotate_spec.rb +17 -18
  65. data/spec/lib/packages/nginx_spec.rb +0 -1
  66. data/spec/lib/packages/openbox_spec.rb +0 -4
  67. data/spec/lib/packages/passenger_nginx_spec.rb +0 -1
  68. data/spec/lib/packages/passenger_spec.rb +0 -1
  69. data/spec/lib/packages/postfix_spec.rb +1 -5
  70. data/spec/lib/packages/questions_spec.rb +3 -4
  71. data/spec/lib/packages/rbenv_spec.rb +1 -4
  72. data/spec/lib/packages/rvm_spec.rb +1 -4
  73. data/spec/lib/packages/save_machines_spec.rb +0 -1
  74. data/spec/lib/packages/slim_spec.rb +1 -2
  75. data/spec/lib/packages/sqlserver_spec.rb +0 -4
  76. data/spec/lib/packages/timezone_spec.rb +2 -3
  77. data/spec/lib/packages/unison_spec.rb +1 -2
  78. data/spec/lib/packages/virtualbox_guest_spec.rb +0 -4
  79. data/spec/lib/packages/virtualbox_spec.rb +1 -2
  80. data/spec/lib/packages/webapps_spec.rb +1 -3
  81. data/spec/spec_helper.rb +59 -61
  82. data/spec/support/minitest.rb +4 -62
  83. metadata +27 -28
  84. data/lib/machines/base.rb +0 -13
  85. data/lib/machines/checks.rb +0 -63
  86. data/lib/machines/configuration.rb +0 -49
  87. data/lib/machines/database.rb +0 -17
  88. data/lib/machines/file_operations.rb +0 -104
  89. data/lib/machines/installation.rb +0 -171
  90. data/lib/machines/machinesfile.rb +0 -25
  91. data/lib/machines/questions.rb +0 -15
  92. data/lib/machines/services.rb +0 -24
  93. data/spec/lib/machines/machinesfile_spec.rb +0 -34
@@ -2,7 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe 'packages/nginx' do
4
4
  before(:each) do
5
- load_package('nginx')
6
5
  $conf.from_hash(webserver: {name: 'nginx', version: '1.2.3',
7
6
  path: 'nginx_path', conf_path: 'conf', modules: '--with-http_ssl_module'})
8
7
  $conf.from_hash(:passenger => {:nginx => '/passenger/path/ext/nginx'})
@@ -1,10 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'packages/openbox' do
4
- before(:each) do
5
- load_package('openbox')
6
- end
7
-
8
4
  it 'adds the following commands' do
9
5
  eval_package
10
6
  $conf.commands.map(&:info).join("\n").must_equal [
@@ -2,7 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe 'packages/passenger_nginx' do
4
4
  before(:each) do
5
- load_package('passenger_nginx')
6
5
  $conf.from_hash(:webserver => {:path => 'nginx_dest', :version => '1.0.2'})
7
6
  $conf.password = 'pass'
8
7
  $conf.from_hash(:passenger => {:root => '/home/user/gems/passenger-1.2.3'})
@@ -2,7 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe 'packages/passenger' do
4
4
  before(:each) do
5
- load_package('passenger')
6
5
  $conf.user_home = '/home/user'
7
6
  $conf.from_hash(:passenger => {:version => '3.0.7'})
8
7
  $conf.from_hash(:ruby => {:gems_path => 'ruby/gems', :executable => 'bin/ruby'})
@@ -1,12 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'packages/postfix' do
4
- before(:each) do
5
- load_package('postfix')
6
- $conf.from_hash(:mail => {:domain => 'domain'})
7
- end
8
-
9
4
  it 'adds the following commands' do
5
+ $conf.from_hash(:mail => {:domain => 'domain'})
10
6
  eval_package
11
7
  $conf.commands.map(&:info).must_equal [
12
8
  "TASK postfix - Install postfix mail",
@@ -2,24 +2,23 @@ require 'spec_helper'
2
2
 
3
3
  describe 'packages/questions' do
4
4
  before(:each) do
5
- load_package('questions')
6
5
  $conf.machine = AppConf.new
7
6
  end
8
7
 
9
8
  it 'asks for a password' do
10
- expects(:enter_password).with('users', false)
9
+ Core.any_instance.expects(:enter_password).with('users', false)
11
10
  eval_package
12
11
  end
13
12
 
14
13
  it 'does not ask for a password when machine is EC2' do
15
14
  $conf.machine.ec2 = {}
16
- expects(:enter_password).never
15
+ Core.any_instance.expects(:enter_password).never
17
16
  eval_package
18
17
  end
19
18
 
20
19
  it 'sets password when logging' do
21
20
  $conf.log_only = true
22
- expects(:enter_password).never
21
+ Core.any_instance.expects(:enter_password).never
23
22
  eval_package
24
23
  $conf.passwords.must_equal ['pa55word']
25
24
  $conf.password.must_equal 'pa55word'
@@ -2,24 +2,21 @@ require 'spec_helper'
2
2
 
3
3
  describe 'packages/rbenv' do
4
4
  before(:each) do
5
- load_package('rbenv')
6
5
  $conf.ruby = AppConf.new
7
6
  $conf.ruby.version = '1.9.2'
8
7
  $conf.ruby.build = 'p290'
8
+ eval_package
9
9
  end
10
10
 
11
11
  it 'sets gems_path' do
12
- eval_package
13
12
  $conf.ruby.gems_path.must_equal '.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems'
14
13
  end
15
14
 
16
15
  it 'sets executable' do
17
- eval_package
18
16
  $conf.ruby.executable.must_equal '.rbenv/versions/1.9.2-p290/bin/ruby'
19
17
  end
20
18
 
21
19
  it 'adds the following commands' do
22
- eval_package
23
20
  $conf.commands.map(&:info).join("\n").must_equal [
24
21
  'TASK rbenv - Install ruby-build, rbenv, ruby 1.9.2-p290 and Bundler',
25
22
  "SUDO apt-get -q -y install git-core",
@@ -2,23 +2,20 @@ require 'spec_helper'
2
2
 
3
3
  describe 'packages/rvm' do
4
4
  before(:each) do
5
- load_package('rvm')
6
5
  $conf.from_hash(ruby: {version: '1.9.2', build: 'p290'})
7
6
  $conf.from_hash(rvm: {version: '1.0'})
7
+ eval_package
8
8
  end
9
9
 
10
10
  it 'sets gems_path' do
11
- eval_package
12
11
  $conf.ruby.gems_path.must_equal '.rvm/gems/1.9.2-p290/@global/gems'
13
12
  end
14
13
 
15
14
  it 'sets executable' do
16
- eval_package
17
15
  $conf.ruby.executable.must_equal '.rvm/wrappers/1.9.2-p290@global/ruby'
18
16
  end
19
17
 
20
18
  it 'adds the following commands' do
21
- eval_package
22
19
  $conf.commands.map(&:info).join("\n").must_equal [
23
20
  "TASK rvm - Install RVM",
24
21
  "SUDO apt-get -q -y install git-core",
@@ -2,7 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe 'packages/save_machines' do
4
4
  before(:each) do
5
- load_package('save_machines')
6
5
  $conf.machines_changed = true
7
6
  $conf.from_hash({'machines' => {'a_machine' => {'hostname' => 'something', 'environment' => 'development'}}})
8
7
  end
@@ -3,12 +3,11 @@ require 'spec_helper'
3
3
  describe 'packages/slim' do
4
4
  before(:each) do
5
5
  $conf.login_theme = 'custom'
6
- load_package('slim')
7
6
  FileUtils.mkdir_p 'slim/themes'
7
+ eval_package
8
8
  end
9
9
 
10
10
  it 'adds the following commands' do
11
- eval_package
12
11
  $conf.commands.map(&:info).must_equal [
13
12
  "TASK slim - Install SLiM desktop manager",
14
13
  "SUDO apt-get -q -y install slim",
@@ -1,10 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'packages/sqlserver' do
4
- before(:each) do
5
- load_package('sqlserver')
6
- end
7
-
8
4
  it 'adds the following commands' do
9
5
  eval_package
10
6
  $conf.commands.map(&:info).must_equal [
@@ -2,7 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe 'packages/timezone' do
4
4
  before(:each) do
5
- load_package('timezone')
6
5
  $conf.timezone = 'GB'
7
6
  end
8
7
 
@@ -10,7 +9,7 @@ describe 'packages/timezone' do
10
9
  eval_package
11
10
  $conf.commands.map(&:info).must_equal [
12
11
  "TASK timezone - Set timezone from config.yml",
13
- "SUDO ln -sf /etc/localtime /usr/share/zoneinfo/GB"
12
+ "SUDO ln -sf /usr/share/zoneinfo/GB /etc/localtime"
14
13
  ]
15
14
  end
16
15
 
@@ -19,7 +18,7 @@ describe 'packages/timezone' do
19
18
  eval_package
20
19
  $conf.commands.map(&:info).must_equal [
21
20
  "TASK timezone - Set timezone from config.yml",
22
- "SUDO ln -sf /etc/localtime /usr/share/zoneinfo/GB",
21
+ "SUDO ln -sf /usr/share/zoneinfo/GB /etc/localtime",
23
22
  "SUDO sed -i \"s/UTC=no/UTC=yes/\" /etc/default/rcS"
24
23
  ]
25
24
  end
@@ -2,13 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  describe 'packages/unison' do
4
4
  before(:each) do
5
- load_package('unison')
6
5
  $conf.machine = AppConf.new
7
6
  $conf.machine.user = 'username'
7
+ eval_package
8
8
  end
9
9
 
10
10
  it 'adds the following commands' do
11
- eval_package
12
11
  $conf.commands.map(&:info).must_equal [
13
12
  "TASK unison - Install and configure Unison (users/username/.unison/default.prf)",
14
13
  "SUDO apt-get -q -y install unison",
@@ -1,10 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'packages/virtualbox_guest' do
4
- before(:each) do
5
- load_package('virtualbox_guest')
6
- end
7
-
8
4
  it 'adds the following commands' do
9
5
  eval_package
10
6
  $conf.commands.map(&:info).must_equal [
@@ -2,12 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  describe 'packages/virtualbox' do
4
4
  before(:each) do
5
- load_package('virtualbox')
6
5
  $conf.user = 'phil'
6
+ eval_package
7
7
  end
8
8
 
9
9
  it 'adds the following commands' do
10
- eval_package
11
10
  $conf.commands.map(&:info).join("\n").must_equal [
12
11
  "TASK virtualbox - Install VirtualBox",
13
12
  "SUDO apt-get -q -y install dkms",
@@ -2,11 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  describe 'packages/webapps' do
4
4
  before(:each) do
5
- load_package('webapps')
6
-
7
5
  $conf.from_hash(:user => {:name => 'username', :home => 'home_dir'}, :ruby => {:version => 'ruby_version'})
8
6
  $conf.webapps = {'application' =>
9
- AppBuilder.new(
7
+ AppSettings::AppBuilder.new(
10
8
  'scm' => 'github.com/project',
11
9
  'branch' => 'master',
12
10
  'name' => 'application',
@@ -1,55 +1,52 @@
1
1
  $LOAD_PATH << 'lib'
2
2
 
3
3
  require 'bundler/setup'
4
- require 'minitest/spec'
5
- require 'mocha'
4
+ require 'minitest/autorun'
5
+ require 'mocha/setup'
6
6
  require 'stringio'
7
7
  require 'fakefs/safe'
8
8
 
9
9
  Dir['spec/support/*.rb'].each {|file| require File.join('./spec', 'support', File.basename(file)) }
10
10
  require 'machines'
11
- application_dir = $conf.application_dir
12
-
13
- include Machines::AppSettings
14
-
15
- # This is done so that Machines::Core.run doesn't collide with MiniTest::Unit::TestCase.run when included
16
- module Machines::Core
17
- alias :run_command :run
18
- remove_method :run
19
- end
20
- MiniTest::Spec.add_setup_hook do |klass|
21
- klass.instance_eval do
22
- alias :run :run_command if respond_to?(:run_command)
11
+ $application_dir = $conf.application_dir
12
+
13
+ include Machines
14
+ modules = %w(Checks Configuration Database FileOperations Installation Questions Services)
15
+ modules.each { |m| include eval("Machines::Commands::#{m}") }
16
+
17
+ module MiniTestSetup
18
+ def before_setup
19
+ super
20
+ $conf.clear
21
+ $conf.passwords = []
22
+ $conf.commands = []
23
+ $conf.tasks = {}
24
+ $conf.application_dir = $application_dir
25
+
26
+ $input = StringIO.new
27
+ $output = StringIO.new
28
+ $terminal = HighLine.new($input, $output)
29
+
30
+ $debug = FakeOut.new
31
+ $file = FakeOut.new
32
+ $console = FakeOut.new
33
+ Machines::Command.debug = Machines::Logger.new $debug
34
+ Machines::Command.file = Machines::Logger.new $file
35
+ Machines::Command.console = Machines::Logger.new $console, :truncate => true
36
+
37
+ FakeFS.activate!
38
+ FileUtils.mkdir_p 'tmp'
23
39
  end
24
- end
25
-
26
- MiniTest::Spec.add_setup_hook do
27
- include Machines::Checks
28
40
 
29
- $conf.clear
30
- $conf.passwords = []
31
- $conf.commands = []
32
- $conf.tasks = {}
33
- $conf.application_dir = application_dir
34
-
35
- $input = StringIO.new
36
- $output = StringIO.new
37
- $terminal = HighLine.new($input, $output)
38
-
39
- $debug = FakeOut.new
40
- $file = FakeOut.new
41
- $console = FakeOut.new
42
- Machines::Command.debug = Machines::Logger.new $debug
43
- Machines::Command.file = Machines::Logger.new $file
44
- Machines::Command.console = Machines::Logger.new $console, :truncate => true
45
-
46
- FakeFS.activate!
47
- FileUtils.mkdir_p 'tmp'
41
+ def after_teardown
42
+ FakeFS.deactivate!
43
+ FakeFS::FileSystem.clear
44
+ super
45
+ end
48
46
  end
49
47
 
50
- MiniTest::Spec.add_teardown_hook do
51
- FakeFS.deactivate!
52
- FakeFS::FileSystem.clear
48
+ class MiniTest::Test
49
+ include MiniTestSetup
53
50
  end
54
51
 
55
52
  module MiniTest
@@ -61,32 +58,36 @@ module MiniTest
61
58
  end
62
59
  end
63
60
 
64
- class MiniTest::Spec::Package < MiniTest::Spec
65
- include Machines
66
- include AppSettings, CloudMachine, Commandline, Configuration, Core, Database
67
- include FileOperations, Installation, Machinesfile, Questions, Services
61
+ class Machines::Core
62
+ def eval_package content, name
63
+ eval content, nil, "eval: #{name}"
64
+ end
68
65
  end
69
66
 
70
- MiniTest::Spec.register_spec_type(/packages\//, MiniTest::Spec::Package)
67
+ class MiniTest::Spec::Package < MiniTest::Spec
68
+ def core
69
+ @core ||= Core.new
70
+ end
71
71
 
72
- def RealFS &block
73
- FakeFS.deactivate!
74
- yield block
75
- ensure
76
- FakeFS.activate!
77
- end
72
+ def load_package
73
+ FakeFS.deactivate!
74
+ @package_name = File.basename(self.class.name).split('::').first
75
+ @package = File.read File.join($conf.application_dir, 'packages', "#{@package_name}.rb")
76
+ FakeFS.activate!
77
+ end
78
78
 
79
- def load_package name
80
- RealFS do
81
- @package_path = File.join($conf.application_dir, File.join('packages', "#{name}.rb"))
82
- @package = File.read(@package_path)
79
+ def eval_package
80
+ core.eval_package(@package, @package_name)
83
81
  end
84
- end
85
82
 
86
- def eval_package
87
- eval @package, nil, @package_path
83
+ def before_setup
84
+ super
85
+ load_package
86
+ end
88
87
  end
89
88
 
89
+ MiniTest::Spec.register_spec_type(/packages\//, MiniTest::Spec::Package)
90
+
90
91
  def save_yaml contents, path
91
92
  File.open(path, 'w') do |f|
92
93
  YAML.dump(contents, f)
@@ -98,6 +99,3 @@ def colored string, color
98
99
  string.sub!(/(\n|\r)$/, '')
99
100
  $terminal.color(string, color.to_sym) + ending.to_s
100
101
  end
101
-
102
- require 'minitest/autorun'
103
-
@@ -1,69 +1,11 @@
1
- # Standard minitest diff calls the OS's diff command. FakeFS breaks diff because
2
- # diff is looking for the files on disk but the files are written by Tempfile
3
- # while FakeFS is still active. The following modules provide a pure ruby diff
4
- # and override MiniTest::Assertions::diff to utilitize it.
5
-
6
- module Diff
7
- attr_accessor :diffs, :sequences
8
-
9
- def self.diffs(old, new)
10
- new, old, @diffs = new.lines.to_a, old.lines.to_a, []
11
- build_sequences(old, new)
12
- find_diffs(old, new, old.size, new.size)
13
- end
14
-
15
- private
16
-
17
- def self.find_diffs(old, new, row, col)
18
- if row > 0 && col > 0 && old[row-1] == new[col-1]
19
- find_diffs(old, new, row-1, col-1)
20
- @diffs << { :line => row, :change => :same, :string => old[row-1].strip }
21
- elsif col > 0 && (row == 0 || @sequences[row][col-1] >= @sequences[row-1][col])
22
- find_diffs(old, new, row, col-1)
23
- @diffs << { :line => col, :change => :add, :string => new[col-1].strip }
24
- elsif row > 0 && (col == 0 || @sequences[row][col-1] < @sequences[row-1][col])
25
- find_diffs(old, new, row-1, col)
26
- @diffs << { :line => row, :change => :delete, :string => old[row-1].strip }
27
- end
28
- end
29
-
30
- def self.build_sequences(old, new)
31
- rows, cols = old.size+1, new.size+1
32
- @sequences = rows.times.map{|x|[0]*(x+1)}
33
- rows.times.each do |row|
34
- cols.times.each do |col|
35
- @sequences[row][col] = if old[row-1] == new[col-1]
36
- @sequences[row-1][col-1] + 1
37
- else
38
- [@sequences[row][col-1].to_i, @sequences[row-1][col].to_i].max
39
- end
40
- end
41
- end
42
- end
43
- end
44
-
45
1
  module MiniTest
46
2
  module Assertions
47
- SYMBOLS = {:add => '+', :delete => '-', :same => ' '}
3
+ alias :actual_diff :diff
48
4
 
49
5
  def diff exp, act
50
- expect = mu_pp_for_diff exp
51
- butwas = mu_pp_for_diff act
52
- result = nil
53
-
54
- need_to_diff =
55
- (expect.include?("\n") ||
56
- butwas.include?("\n") ||
57
- expect.size > 30 ||
58
- butwas.size > 30 ||
59
- expect == butwas)
60
-
61
- return "Expected: #{mu_pp exp}\n Actual: #{mu_pp act}" unless need_to_diff
62
-
63
- Diff.diffs(expect, butwas).map do |diff|
64
- SYMBOLS[diff[:change]] + diff[:string]
65
- end.join("\n")
6
+ FakeFS.without do
7
+ actual_diff exp, act
8
+ end
66
9
  end
67
10
  end
68
11
  end
69
-