machines 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +11 -0
- data/EXAMPLES.md +18 -0
- data/Gemfile +4 -0
- data/Guardfile +14 -0
- data/INSTALL.md +25 -0
- data/LICENSE +23 -0
- data/README.md +271 -0
- data/Rakefile +60 -0
- data/TODO.md +92 -0
- data/bin/machines +6 -0
- data/lib/machines/app_settings.rb +54 -0
- data/lib/machines/base.rb +13 -0
- data/lib/machines/checks.rb +63 -0
- data/lib/machines/cloud_machine.rb +33 -0
- data/lib/machines/command.rb +86 -0
- data/lib/machines/commandline.rb +148 -0
- data/lib/machines/configuration.rb +49 -0
- data/lib/machines/core.rb +117 -0
- data/lib/machines/database.rb +17 -0
- data/lib/machines/file_operations.rb +104 -0
- data/lib/machines/help.rb +30 -0
- data/lib/machines/installation.rb +151 -0
- data/lib/machines/log_command.rb +22 -0
- data/lib/machines/logger.rb +65 -0
- data/lib/machines/machinesfile.rb +25 -0
- data/lib/machines/named_buffer.rb +9 -0
- data/lib/machines/questions.rb +15 -0
- data/lib/machines/services.rb +24 -0
- data/lib/machines/upload.rb +29 -0
- data/lib/machines/version.rb +4 -0
- data/lib/machines.rb +19 -0
- data/lib/packages/abiword.rb +11 -0
- data/lib/packages/amazon_mp3.rb +4 -0
- data/lib/packages/awstats.rb +16 -0
- data/lib/packages/base.rb +14 -0
- data/lib/packages/chrome.rb +12 -0
- data/lib/packages/cruisecontrol.rb +22 -0
- data/lib/packages/dependencies.rb +10 -0
- data/lib/packages/docky.rb +36 -0
- data/lib/packages/dotfiles.rb +26 -0
- data/lib/packages/file_roller.rb +12 -0
- data/lib/packages/finalise.rb +4 -0
- data/lib/packages/firefox.rb +4 -0
- data/lib/packages/gedit.rb +11 -0
- data/lib/packages/git.rb +4 -0
- data/lib/packages/gmate.rb +33 -0
- data/lib/packages/gnome.rb +10 -0
- data/lib/packages/gnumeric.rb +11 -0
- data/lib/packages/hosts.rb +13 -0
- data/lib/packages/load_machines.rb +38 -0
- data/lib/packages/monit.rb +10 -0
- data/lib/packages/mysql.rb +46 -0
- data/lib/packages/nginx.rb +22 -0
- data/lib/packages/nginx_logrotate.rb +26 -0
- data/lib/packages/openbox.rb +35 -0
- data/lib/packages/passenger.rb +14 -0
- data/lib/packages/passenger_nginx.rb +8 -0
- data/lib/packages/postfix.rb +10 -0
- data/lib/packages/questions.rb +5 -0
- data/lib/packages/rbenv.rb +27 -0
- data/lib/packages/rvm.rb +20 -0
- data/lib/packages/save_machines.rb +4 -0
- data/lib/packages/slim.rb +6 -0
- data/lib/packages/sqlserver.rb +5 -0
- data/lib/packages/subtle.rb +29 -0
- data/lib/packages/sudo_mods.rb +6 -0
- data/lib/packages/time.rb +6 -0
- data/lib/packages/time_daily.rb +5 -0
- data/lib/packages/timezone.rb +10 -0
- data/lib/packages/unison.rb +5 -0
- data/lib/packages/virtualbox.rb +11 -0
- data/lib/packages/virtualbox_guest.rb +7 -0
- data/lib/packages/webapps.rb +36 -0
- data/lib/template/Machinesfile +48 -0
- data/lib/template/certificates/example.com.crt +0 -0
- data/lib/template/certificates/example.com.key +0 -0
- data/lib/template/certificates/selfsigned.crt +14 -0
- data/lib/template/certificates/selfsigned.key +16 -0
- data/lib/template/config.yml +98 -0
- data/lib/template/logrotate/app.erb +10 -0
- data/lib/template/logrotate/nginx.erb +12 -0
- data/lib/template/machines.yml +179 -0
- data/lib/template/misc/awstats.conf.erb +7 -0
- data/lib/template/misc/ntp.conf +7 -0
- data/lib/template/monit/conf.d/delayed_job.erb +11 -0
- data/lib/template/monit/conf.d/mysql.erb +7 -0
- data/lib/template/monit/conf.d/nginx +5 -0
- data/lib/template/monit/conf.d/postfix +7 -0
- data/lib/template/monit/conf.d/ssh +6 -0
- data/lib/template/monit/conf.d/system.erb +14 -0
- data/lib/template/monit/monitrc.erb +10 -0
- data/lib/template/monit/upstart.conf +16 -0
- data/lib/template/mysql/dbmaster.cnf +7 -0
- data/lib/template/mysql/dbslave.cnf +3 -0
- data/lib/template/nginx/app_server.conf.erb +87 -0
- data/lib/template/nginx/nginx.conf.erb +46 -0
- data/lib/template/nginx/upstart.conf.erb +21 -0
- data/lib/template/packages/custom.rb +17 -0
- data/lib/template/packages/productivity.rb +18 -0
- data/lib/template/slim/themes/dark/background.jpg +0 -0
- data/lib/template/slim/themes/dark/panel.png +0 -0
- data/lib/template/slim/themes/dark/slim.theme +39 -0
- data/lib/template/users/phil/dotfiles/bash_aliases +45 -0
- data/lib/template/users/phil/dotfiles/config/Trolltech.conf +4 -0
- data/lib/template/users/phil/dotfiles/config/gtk-3.0/settings.ini +9 -0
- data/lib/template/users/phil/dotfiles/config/openbox/autostart.sh +14 -0
- data/lib/template/users/phil/dotfiles/config/openbox/rc.xml +482 -0
- data/lib/template/users/phil/dotfiles/config/terminator/config +10 -0
- data/lib/template/users/phil/dotfiles/fonts.conf +15 -0
- data/lib/template/users/phil/dotfiles/gitconfig +27 -0
- data/lib/template/users/phil/dotfiles/gtkrc-2.0 +16 -0
- data/lib/template/users/phil/dotfiles/local/share/applications/mimeapps.list +4 -0
- data/lib/template/users/phil/dotfiles/unison/default.prf +33 -0
- data/lib/template/users/www/authorized_keys +0 -0
- data/lib/template/users/www/dotfiles/bash_aliases +40 -0
- data/lib/template/webapps.yml +75 -0
- data/machines.gemspec +44 -0
- data/spec/acceptance/dev_machine_spec.rb +22 -0
- data/spec/lib/machines/app_settings_spec.rb +106 -0
- data/spec/lib/machines/checks_spec.rb +105 -0
- data/spec/lib/machines/cloud_machine_spec.rb +36 -0
- data/spec/lib/machines/command_spec.rb +184 -0
- data/spec/lib/machines/commandline_spec.rb +299 -0
- data/spec/lib/machines/configuration_spec.rb +61 -0
- data/spec/lib/machines/core_spec.rb +299 -0
- data/spec/lib/machines/database_spec.rb +51 -0
- data/spec/lib/machines/file_operations_spec.rb +124 -0
- data/spec/lib/machines/help_spec.rb +22 -0
- data/spec/lib/machines/installation_spec.rb +176 -0
- data/spec/lib/machines/log_command_spec.rb +16 -0
- data/spec/lib/machines/logger_spec.rb +70 -0
- data/spec/lib/machines/machinesfile_spec.rb +34 -0
- data/spec/lib/machines/questions_spec.rb +73 -0
- data/spec/lib/machines/services_spec.rb +26 -0
- data/spec/lib/machines/upload_spec.rb +86 -0
- data/spec/lib/packages/abiword_spec.rb +20 -0
- data/spec/lib/packages/amazon_mp3_spec.rb +17 -0
- data/spec/lib/packages/awstats_spec.rb +26 -0
- data/spec/lib/packages/base_spec.rb +21 -0
- data/spec/lib/packages/chrome_spec.rb +30 -0
- data/spec/lib/packages/cruisecontrol_spec.rb +33 -0
- data/spec/lib/packages/dependencies_spec.rb +20 -0
- data/spec/lib/packages/docky_spec.rb +32 -0
- data/spec/lib/packages/dotfiles_spec.rb +44 -0
- data/spec/lib/packages/file_roller_spec.rb +69 -0
- data/spec/lib/packages/firefox_spec.rb +16 -0
- data/spec/lib/packages/gedit_spec.rb +20 -0
- data/spec/lib/packages/git_spec.rb +16 -0
- data/spec/lib/packages/gmate_spec.rb +39 -0
- data/spec/lib/packages/gnome_spec.rb +22 -0
- data/spec/lib/packages/gnumeric_spec.rb +21 -0
- data/spec/lib/packages/hosts_spec.rb +41 -0
- data/spec/lib/packages/load_machines_spec.rb +118 -0
- data/spec/lib/packages/monit_spec.rb +34 -0
- data/spec/lib/packages/mysql_spec.rb +69 -0
- data/spec/lib/packages/nginx_logrotate_spec.rb +80 -0
- data/spec/lib/packages/nginx_spec.rb +46 -0
- data/spec/lib/packages/openbox_spec.rb +41 -0
- data/spec/lib/packages/passenger_nginx_spec.rb +20 -0
- data/spec/lib/packages/passenger_spec.rb +26 -0
- data/spec/lib/packages/postfix_spec.rb +19 -0
- data/spec/lib/packages/questions_spec.rb +29 -0
- data/spec/lib/packages/rbenv_spec.rb +32 -0
- data/spec/lib/packages/rvm_spec.rb +31 -0
- data/spec/lib/packages/save_machines_spec.rb +51 -0
- data/spec/lib/packages/slim_spec.rb +22 -0
- data/spec/lib/packages/sqlserver_spec.rb +17 -0
- data/spec/lib/packages/timezone_spec.rb +27 -0
- data/spec/lib/packages/unison_spec.rb +17 -0
- data/spec/lib/packages/virtualbox_guest_spec.rb +25 -0
- data/spec/lib/packages/virtualbox_spec.rb +23 -0
- data/spec/lib/packages/webapps_spec.rb +70 -0
- data/spec/spec_helper.rb +103 -0
- data/spec/support/coverage.rb +8 -0
- data/spec/support/fake_out.rb +22 -0
- data/spec/support/fakefs_additions.rb +10 -0
- data/spec/support/minitest.rb +69 -0
- data/spec/support/vm_control.rb +54 -0
- data/tmp/.gitkeep +0 -0
- metadata +581 -0
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'FileOperations' do
|
4
|
+
include Machines::FileOperations
|
5
|
+
include Machines::Core
|
6
|
+
|
7
|
+
describe 'append' do
|
8
|
+
it 'escapes backslashes (\\)' do
|
9
|
+
subject = append '\\', :to => 'file'
|
10
|
+
subject.command.must_match /"\\\\"/
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'escapes dollar sign ($)' do
|
14
|
+
subject = append '$', :to => 'file'
|
15
|
+
subject.command.must_match /"\\\$\"/
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'escapes double quotes (")' do
|
19
|
+
subject = append '"', :to => 'file'
|
20
|
+
subject.command.must_match /"\\""/
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'escapes backticks (`)' do
|
24
|
+
subject = append '`', :to => 'file'
|
25
|
+
subject.command.must_match /"\\`"/
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'appends to a file' do
|
29
|
+
subject = append 'string', :to => 'file'
|
30
|
+
subject.command.must_match /echo ".*" >> file/
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'adds to a file with specified content including escaped characters' do
|
34
|
+
subject = append '\\$"`', :to => 'file'
|
35
|
+
subject.command.must_equal 'grep "\\\\\\$\\"\\`" file || echo "\\\\\\$\\"\\`" >> file'
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'checks text was added' do
|
39
|
+
subject = append 'something', :to => 'file'
|
40
|
+
subject.check.must_equal "grep \"something\" file #{echo_result}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'chmod' do
|
45
|
+
subject { chmod(644, 'path') }
|
46
|
+
it { subject.command.must_equal 'chmod 644 path' }
|
47
|
+
|
48
|
+
describe 'when mode is a string' do
|
49
|
+
subject { chmod('644', 'path') }
|
50
|
+
it { subject.command.must_equal 'chmod 644 path' }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'chown' do
|
55
|
+
it { chown('owner', 'path').command.must_equal 'chown owner:owner path' }
|
56
|
+
it { chown('user:group', 'path').command.must_equal 'chown user:group path' }
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'copy' do
|
60
|
+
subject { copy('from', 'to') }
|
61
|
+
it { subject.command.must_equal 'cp -rf from to' }
|
62
|
+
end
|
63
|
+
|
64
|
+
describe 'create_from' do
|
65
|
+
include Machines::AppSettings
|
66
|
+
|
67
|
+
it 'loads ERB template, applies settings and writes to remote machine' do
|
68
|
+
File.expects(:read).with('erb_path').returns('<%= method_on_binding %>')
|
69
|
+
app_builder = AppBuilder.new(:method_on_binding => 'result')
|
70
|
+
expects(:write).with('result', {:settings => app_builder, :to => 'file', :name => 'erb_path'})
|
71
|
+
create_from('erb_path', :settings => app_builder, :to => 'file')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe 'link' do
|
76
|
+
subject { link 'target', 'link' }
|
77
|
+
it {subject.command.must_equal 'ln -sf target link'}
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'mkdir' do
|
81
|
+
it 'creates a mkdir command for a single path' do
|
82
|
+
mkdir('path').first.command.must_equal 'mkdir -p path'
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'creates a mkdir command for a multiple paths' do
|
86
|
+
mkdir('path1', 'path2').map(&:command).must_equal ['mkdir -p path1', 'mkdir -p path2']
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'creates a mkdir command for an array of paths' do
|
90
|
+
mkdir(['path1', 'path2']).map(&:command).must_equal ['mkdir -p path1', 'mkdir -p path2']
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe 'rename' do
|
95
|
+
subject { rename('oldname', 'newname') }
|
96
|
+
it { subject.command.must_equal 'mv -f oldname newname' }
|
97
|
+
end
|
98
|
+
|
99
|
+
describe 'remove' do
|
100
|
+
subject { remove 'file' }
|
101
|
+
it { subject.command.must_equal 'rm -rf file' }
|
102
|
+
end
|
103
|
+
|
104
|
+
describe 'remove_version_info' do
|
105
|
+
subject { remove_version_info 'name' }
|
106
|
+
it { subject.command.must_equal "find . -maxdepth 1 -name \"name*\" -a -type d | xargs -I xxx mv xxx name" }
|
107
|
+
end
|
108
|
+
|
109
|
+
describe 'replace' do
|
110
|
+
subject { replace('something', :with => 'some/path', :in => 'file') }
|
111
|
+
it { subject.command.must_equal "sed -i \"s/something/some\\/path/\" file" }
|
112
|
+
it { lambda{replace('something')}.must_raise ArgumentError }
|
113
|
+
end
|
114
|
+
|
115
|
+
describe 'write' do
|
116
|
+
it 'uploads from a buffer' do
|
117
|
+
mock_named_buffer = mock 'NamedBuffer'
|
118
|
+
NamedBuffer.expects(:new).with('name', 'something').returns mock_named_buffer
|
119
|
+
subject = write('something', :to => 'a_file', :name => 'name')
|
120
|
+
subject.local.must_equal mock_named_buffer
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Machines::Help do
|
4
|
+
subject { Machines::Help.new }
|
5
|
+
|
6
|
+
describe 'actions' do
|
7
|
+
it { subject.actions.must_equal ['htpasswd', 'new', 'dryrun', 'tasks', 'build', 'list', 'packages', 'override'] }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'syntax' do
|
11
|
+
it 'includes version' do
|
12
|
+
subject.syntax.must_match /machines v0\.[0-9]+\.[0-9]+ - Ubuntu\/Ruby configuration tool\./
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'includes syntax' do
|
16
|
+
subject.syntax.must_match /machines COMMAND/
|
17
|
+
subject.syntax.must_match /COMMAND can be:/
|
18
|
+
subject.syntax.must_match /build <machine> \[task\] Builds your chosen machine\. Optionally, build just one task/
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,176 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Installation' do
|
4
|
+
include Machines::Core
|
5
|
+
include Machines::Installation
|
6
|
+
include Machines::Configuration
|
7
|
+
|
8
|
+
describe 'add_ppa' do
|
9
|
+
it 'adds a ppa' do
|
10
|
+
subject = add_ppa 'user/name', 'key'
|
11
|
+
subject.map(&:command).must_equal ['add-apt-repository ppa:user/name', 'apt-get -q -y update > /tmp/apt-update.log']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'deb' do
|
16
|
+
it 'adds to /etc/apt/sources and add a key' do
|
17
|
+
subject = deb 'source', :key => 'gpg', :name => 'name'
|
18
|
+
subject.map(&:command).must_equal [
|
19
|
+
"echo deb source >> /etc/apt/sources.list",
|
20
|
+
"wget -q gpg -O - | apt-key add -",
|
21
|
+
"apt-get -q -y update > /tmp/apt-update.log"
|
22
|
+
]
|
23
|
+
subject.map(&:check).must_equal [
|
24
|
+
"grep \"source\" /etc/apt/sources.list #{echo_result}",
|
25
|
+
"apt-key list | grep -i name #{echo_result}",
|
26
|
+
"grep \"Reading package lists\" /tmp/apt-update.log #{echo_result}"
|
27
|
+
]
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'modifies echo command to grab the distribution name to be used in the source' do
|
31
|
+
subject = deb 'source YOUR_UBUNTU_VERSION_HERE', :key => 'gpg', :name => 'name'
|
32
|
+
subject.first.command.must_equal 'expr substr `cat /etc/lsb-release | grep DISTRIB_CODENAME` 18 20 | xargs -I YOUR_UBUNTU_VERSION_HERE echo deb source YOUR_UBUNTU_VERSION_HERE >> /etc/apt/sources.list'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'debconf' do
|
37
|
+
it 'sends args to debconf-set-selections' do
|
38
|
+
subject = debconf 'app', 'setting', 'boolean', true
|
39
|
+
subject.command.must_equal 'echo app setting boolean true | debconf-set-selections'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'extract' do
|
44
|
+
it 'instaniates commands to download, extract and remove a tar archive' do
|
45
|
+
subject = extract 'http://url/package.tar'
|
46
|
+
subject.command.must_equal 'cd /usr/local/src && wget http://url/package.tar && tar -zxf package.tar && rm package.tar && cd -'
|
47
|
+
subject.check.must_equal 'test -d /usr/local/src/package && echo CHECK PASSED || echo CHECK FAILED'
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'instaniates commands to download, extract and remove a zip archive' do
|
51
|
+
subject = extract 'http://url/package.zip'
|
52
|
+
subject.command.must_equal 'cd /usr/local/src && wget http://url/package.zip && unzip -qq package.zip && rm package.zip && cd -'
|
53
|
+
subject.check.must_equal 'test -d /usr/local/src/package && echo CHECK PASSED || echo CHECK FAILED'
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'moves extracted contents to specified folder' do
|
57
|
+
subject = extract 'http://url/package-1.0.tar.gz', :to => '/opt'
|
58
|
+
subject.command.must_equal 'cd /opt && wget http://url/package-1.0.tar.gz && tar -zxf package-1.0.tar.gz && rm package-1.0.tar.gz && cd -'
|
59
|
+
subject.check.must_equal 'test -d /opt/package-1.0 && echo CHECK PASSED || echo CHECK FAILED'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'gem' do
|
64
|
+
it 'instaniates a command to install a gem' do
|
65
|
+
subject = gem 'package'
|
66
|
+
subject.command.must_equal 'gem install package'
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'instaniates a command to install a gem with a specified version' do
|
70
|
+
subject = gem 'package', :version => '1'
|
71
|
+
subject.command.must_equal "gem install package -v \"1\""
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe 'gem_update' do
|
76
|
+
it 'instaniates a command to update gems' do
|
77
|
+
subject = gem_update 'gem'
|
78
|
+
subject.command.must_equal 'gem update gem'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe 'git_clone' do
|
83
|
+
it 'instaniates a command to clone a git repository' do
|
84
|
+
subject = git_clone 'http://git_url.git'
|
85
|
+
subject.command.must_equal 'git clone --quiet http://git_url.git'
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'instaniates a command to clone a git repository to a specified folder' do
|
89
|
+
subject = git_clone 'http://git_url.git', :to => 'dir'
|
90
|
+
subject.command.must_equal 'git clone --quiet http://git_url.git dir'
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'raises when no url supplied' do
|
94
|
+
lambda { git_clone '' }.must_raise ArgumentError
|
95
|
+
lambda { git_clone nil }.must_raise ArgumentError
|
96
|
+
end
|
97
|
+
|
98
|
+
describe ':branch option' do
|
99
|
+
it 'clones to a specific branch' do
|
100
|
+
subject = git_clone 'http://git_url.git', :branch => 'other'
|
101
|
+
subject.command.must_equal 'git clone --quiet --branch other http://git_url.git'
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe ':tag option' do
|
106
|
+
it 'checks out a specific tag' do
|
107
|
+
subject = git_clone 'http://git_url.git', :to => 'dir', :tag => 'v1.0'
|
108
|
+
subject.map(&:command).must_equal [
|
109
|
+
'git clone --quiet http://git_url.git dir',
|
110
|
+
'cd dir && git checkout v1.0'
|
111
|
+
]
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'raises when no dir' do
|
115
|
+
lambda { git_clone 'http://git_url.git', :tag => 'v1.0' }.must_raise ArgumentError
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe 'install' do
|
121
|
+
it 'instaniates commands to download, install and remove a DEB package ' do
|
122
|
+
subject = install "http://some.url/package_name.deb"
|
123
|
+
subject.map(&:command).must_equal [
|
124
|
+
'cd /tmp && wget http://some.url/package_name.deb && dpkg -i --force-architecture package_name.deb && rm package_name.deb && cd -'
|
125
|
+
]
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'instaniates commands to download, extract, install and remove a group of DEB packages ' do
|
129
|
+
subject = install "http://some.url/package_name.tar.gz"
|
130
|
+
subject.map(&:command).must_equal [
|
131
|
+
'cd /tmp && wget http://some.url/package_name.tar.gz && tar -zxf package_name.tar.gz && rm package_name.tar.gz && cd -',
|
132
|
+
'cd /tmp/package_name && dpkg -i --force-architecture *.deb && cd - && rm -rf /tmp/package_name'
|
133
|
+
]
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'instaniates a command to install a single apt package' do
|
137
|
+
subject = install 'package1'
|
138
|
+
subject.map(&:command).must_equal ['apt-get -q -y install package1']
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'instaniates a command to install multiple apt packages' do
|
142
|
+
subject = install %w(package1 package2)
|
143
|
+
subject.map(&:command).must_equal [
|
144
|
+
'apt-get -q -y install package1',
|
145
|
+
'apt-get -q -y install package2'
|
146
|
+
]
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe 'uninstall' do
|
151
|
+
it 'instaniates a command to uninstall a package' do
|
152
|
+
subject = uninstall %w(apackage)
|
153
|
+
subject.map(&:command).must_equal ['apt-get -q -y purge apackage']
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe 'update' do
|
158
|
+
it 'instaniates a command to update apt' do
|
159
|
+
subject = update
|
160
|
+
subject.command.must_equal 'apt-get -q -y update > /tmp/apt-update.log'
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe 'upgrade' do
|
165
|
+
it 'instaniates a command to upgrade apt' do
|
166
|
+
subject = upgrade
|
167
|
+
subject.map(&:command).must_equal [
|
168
|
+
'apt-get -q -y update',
|
169
|
+
'apt-get -q -y upgrade',
|
170
|
+
'apt-get -q -y autoremove',
|
171
|
+
'apt-get -q -y autoclean'
|
172
|
+
]
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Machines::LogCommand do
|
4
|
+
subject {Machines::LogCommand.new :name, 'description'}
|
5
|
+
|
6
|
+
it 'logs the name and description' do
|
7
|
+
$conf.commands = [subject]
|
8
|
+
subject.run
|
9
|
+
$console.next.must_equal "\n"
|
10
|
+
$console.next.must_equal colored(" TASK name - description\n", :info)
|
11
|
+
|
12
|
+
$file.next.must_equal "\n"
|
13
|
+
$file.next.must_equal colored("TASK name - description\n", :info)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Machines::Logger do
|
4
|
+
before(:each) do
|
5
|
+
$conf.machine = AppConf.new
|
6
|
+
$conf.machine.user = 'www'
|
7
|
+
$conf.commands = [1,2,3]
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'logging to screen' do
|
11
|
+
it 'logs first line only' do
|
12
|
+
Machines::Command.console.log %(something with "some text\nsome more\nand "lets quote" this one" > and some output)
|
13
|
+
$console.next.must_equal %(something with "some text..." > and some output\n)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'truncates lines longer than screen width' do
|
17
|
+
$terminal.stubs(:output_cols).returns 10
|
18
|
+
Machines::Command.console.log "A line that's longer than the screen width", :newline => false
|
19
|
+
$console.next.must_equal "A line...\r"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'logging to file' do
|
24
|
+
it 'logs all lines' do
|
25
|
+
Machines::Command.file.log %(something with "some text\nsome more\nand "lets quote" this one" > and some output)
|
26
|
+
$file.next.must_equal %(something with "some text\nsome more\nand "lets quote" this one" > and some output\n)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'log' do
|
31
|
+
it 'does not error when no message' do
|
32
|
+
Machines::Command.file.log nil
|
33
|
+
$file.next.must_equal "(no message)\n"
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'returns to the beginning of the line when no newline' do
|
37
|
+
Machines::Command.console.log 'message', :newline => false
|
38
|
+
$console.next.must_equal "message\r"
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'sends the command and line number' do
|
42
|
+
Machines::Command.file.log 'command'
|
43
|
+
$file.next.must_equal "command\n"
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'displays message in specified color' do
|
47
|
+
Machines::Command.file.log 'command', :color => :yellow
|
48
|
+
$file.next.must_equal colored("command\n", :yellow)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'does not show passwords' do
|
52
|
+
$conf.passwords = ['a_password', 'another password']
|
53
|
+
Machines::Command.file.log 'something with a_password and another password in'
|
54
|
+
$file.next.must_equal "something with ***** and ***** in\n"
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'displays newline when empty message' do
|
58
|
+
Machines::Command.file.log ''
|
59
|
+
$file.next.must_equal "\n"
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'flushes the file' do
|
63
|
+
mock_file = mock 'File'
|
64
|
+
subject = Machines::Logger.new(mock_file)
|
65
|
+
mock_file.expects(:flush)
|
66
|
+
subject.flush
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Machinesfile' do
|
4
|
+
include Machines::Machinesfile
|
5
|
+
|
6
|
+
describe 'package' do
|
7
|
+
it 'raises specific error when failing to load Machinesfile' do
|
8
|
+
File.expects(:read).never
|
9
|
+
lambda{ package 'Machinesfile' }.must_raise LoadError, /Cannot find Machinesfile/
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'loads custom package when it exists' do
|
13
|
+
custom_package = "packages/custom_package.rb"
|
14
|
+
FileUtils.mkdir_p File.dirname(custom_package)
|
15
|
+
FileUtils.touch custom_package
|
16
|
+
File.expects(:read).with(custom_package).returns ''
|
17
|
+
package :custom_package
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'loads built-in package when no custom package' do
|
21
|
+
builtin_package = "#{$conf.application_dir}/packages/builtin_package.rb"
|
22
|
+
FileUtils.mkdir_p File.dirname(builtin_package)
|
23
|
+
FileUtils.touch builtin_package
|
24
|
+
File.expects(:read).with(builtin_package).returns ''
|
25
|
+
package :builtin_package
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'raises when no custom and no built-in package' do
|
29
|
+
File.expects(:read).never
|
30
|
+
lambda { package :builtin_package}.must_raise LoadError, /Cannot find .* package builtin_package/
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Questions' do
|
4
|
+
include Machines::Questions
|
5
|
+
|
6
|
+
describe 'enter_password' do
|
7
|
+
before(:each) do
|
8
|
+
stubs(:ask).returns 'pa55word'
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'does not echo output' do
|
12
|
+
mock_question = mock 'HighLine::Question'
|
13
|
+
mock_question.expects(:echo=).with(false).twice
|
14
|
+
stubs(:ask).yields(mock_question).returns 'pa55word'
|
15
|
+
enter_password 'type'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'prompts for a password' do
|
19
|
+
expects(:ask).with('Enter type password: ').once.returns 'pa55word'
|
20
|
+
enter_password('type')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns password' do
|
24
|
+
enter_password('type').must_equal 'pa55word'
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'adds to password list' do
|
28
|
+
enter_password('type')
|
29
|
+
$conf.passwords.must_equal ['pa55word']
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'does not add password less than 5 characters to password list' do
|
33
|
+
stubs(:ask).returns 'pass'
|
34
|
+
enter_password('type')
|
35
|
+
$conf.passwords.must_equal []
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'does not add password if it is "password"' do
|
39
|
+
stubs(:ask).returns 'password'
|
40
|
+
enter_password('type')
|
41
|
+
$conf.passwords.must_equal []
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'repeats until password and confirmation match' do
|
45
|
+
expects(:ask).with('Enter type password: ').twice.returns 'pa55word'
|
46
|
+
expects(:ask).with('Confirm the password: ').twice.returns 'pas', 'pa55word'
|
47
|
+
expects(:say).with('Passwords do not match, please re-enter')
|
48
|
+
enter_password('type').must_equal 'pa55word'
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'only asks once when confirm set to false' do
|
52
|
+
expects(:ask).with('Enter type password: ').once.returns 'pa55word'
|
53
|
+
expects(:ask).with('Confirm the password: ').never
|
54
|
+
enter_password('type', false)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'password still added to list when not confirming' do
|
58
|
+
enter_password('type', false)
|
59
|
+
$conf.passwords.must_equal ['pa55word']
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'password still returned when not confirming' do
|
63
|
+
enter_password('type', false).must_equal 'pa55word'
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'do not add to passwords list if not available' do
|
67
|
+
$conf.passwords = nil
|
68
|
+
enter_password('type')
|
69
|
+
$conf.passwords.must_equal nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Services' do
|
4
|
+
include Machines::Core
|
5
|
+
include Machines::FileOperations
|
6
|
+
include Machines::Services
|
7
|
+
|
8
|
+
describe 'restart' do
|
9
|
+
subject { restart 'daemon' }
|
10
|
+
it { subject.command.must_equal 'service daemon restart' }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'start' do
|
14
|
+
it 'start daemon and check it runs' do
|
15
|
+
subject = start 'daemon'
|
16
|
+
subject.command.must_equal 'service daemon start'
|
17
|
+
subject.check.must_equal 'ps aux | grep daemon | grep -v grep && echo CHECK PASSED || echo CHECK FAILED'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'start daemon with custom check' do
|
21
|
+
subject = start 'daemon', :check => 'check'
|
22
|
+
subject.check.must_equal 'check'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Machines::Upload do
|
4
|
+
subject { Machines::Upload.new('local', 'remote', 'check') }
|
5
|
+
|
6
|
+
describe 'initialize' do
|
7
|
+
it 'sets line, local, remote and check' do
|
8
|
+
subject.command.must_equal nil
|
9
|
+
subject.local.must_equal 'local'
|
10
|
+
subject.remote.must_equal 'remote'
|
11
|
+
subject.check.must_equal 'check'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'run' do
|
16
|
+
before(:each) do
|
17
|
+
$conf.commands = [subject]
|
18
|
+
$conf.log_only = false
|
19
|
+
@mock_ssh = mock 'Net::SSH'
|
20
|
+
@mock_scp = stub 'Net::SCP'
|
21
|
+
Machines::Command.ssh = @mock_ssh
|
22
|
+
Machines::Command.scp = @mock_scp
|
23
|
+
@mock_ssh.stubs(:exec!).with('export TERM=linux && check').returns "CHECK PASSED"
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'uploads local to remote with logging' do
|
27
|
+
@mock_scp.expects(:upload!).with('local', 'remote', {:recursive => false})
|
28
|
+
subject.run
|
29
|
+
|
30
|
+
$file.next.must_equal colored("UPLOAD local to remote\n", :highlight)
|
31
|
+
$file.next.must_equal colored("CHECK PASSED\n", :success)
|
32
|
+
$console.next.must_equal "100% UPLOAD local to remote\r"
|
33
|
+
$console.next.must_equal colored("100% UPLOAD local to remote\n", :success)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'logs with newline when logging only' do
|
37
|
+
@mock_scp.stubs(:upload!)
|
38
|
+
$conf.log_only = true
|
39
|
+
subject.run
|
40
|
+
|
41
|
+
$console.next.must_equal "100% UPLOAD local to remote\n"
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'logs with return when log_only not specified' do
|
45
|
+
@mock_scp.stubs(:upload!)
|
46
|
+
$conf.log_only = nil
|
47
|
+
subject.run
|
48
|
+
|
49
|
+
$console.next.must_equal "100% UPLOAD local to remote\r"
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'uploads a folder source' do
|
53
|
+
FileUtils.mkdir_p('local')
|
54
|
+
@mock_scp.expects(:upload!).with('local', 'remote', {:recursive => true})
|
55
|
+
|
56
|
+
subject.run
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'uploads an in memory buffer' do
|
60
|
+
buffer = NamedBuffer.new('name', 'a buffer')
|
61
|
+
subject = Machines::Upload.new(buffer, 'remote', 'check')
|
62
|
+
$conf.commands = [subject]
|
63
|
+
@mock_scp.expects(:upload!).with(buffer, 'remote', {:recursive => false})
|
64
|
+
subject.run
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'info' do
|
69
|
+
it 'contains source and destination paths and UPLOAD' do
|
70
|
+
subject.info.must_equal 'UPLOAD local to remote'
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'when local is a buffer' do
|
74
|
+
subject { Machines::Upload.new(NamedBuffer.new('name', 'a buffer'), 'remote', 'check') }
|
75
|
+
it 'contains name of the buffer' do
|
76
|
+
subject.info.must_equal 'UPLOAD buffer from name to remote'
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'handles nil names' do
|
80
|
+
subject = Machines::Upload.new(NamedBuffer.new(nil, 'a buffer'), 'remote', 'check')
|
81
|
+
subject.info.must_equal "UPLOAD unnamed buffer to remote"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'packages/apps' do
|
4
|
+
before(:each) do
|
5
|
+
load_package('abiword')
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'adds the following commands' do
|
9
|
+
eval_package
|
10
|
+
$conf.commands.map(&:info).must_equal [
|
11
|
+
"TASK abiword - Install a lightweight word processor",
|
12
|
+
"SUDO apt-get -q -y install abiword",
|
13
|
+
"TASK abiword_associations - Setup file associations for Abiword",
|
14
|
+
"RUN grep \"application/x-abiword=abiword.desktop\" .local/share/applications/mimeapps.list || echo \"application/x-abiword=abiword.desktop\" >> .local/share/applications/mimeapps.list",
|
15
|
+
"RUN grep \"application/msword=abiword.desktop\" .local/share/applications/mimeapps.list || echo \"application/msword=abiword.desktop\" >> .local/share/applications/mimeapps.list",
|
16
|
+
"RUN grep \"application/rtf=abiword.desktop\" .local/share/applications/mimeapps.list || echo \"application/rtf=abiword.desktop\" >> .local/share/applications/mimeapps.list"
|
17
|
+
]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'packages/amazon_mp3' do
|
4
|
+
before(:each) do
|
5
|
+
load_package('amazon_mp3')
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'adds the following commands' do
|
9
|
+
eval_package
|
10
|
+
$conf.commands.map(&:info).must_equal [
|
11
|
+
"TASK amazon_mp3 - Download and install MP3 downloader from Amazon",
|
12
|
+
"SUDO cd /tmp && wget http://www.hilltopyodeler.com/packages/AmazonMP3-InstallerForUbuntuNewerThan-9.04.tar.gz && tar -zxf AmazonMP3-InstallerForUbuntuNewerThan-9.04.tar.gz && rm AmazonMP3-InstallerForUbuntuNewerThan-9.04.tar.gz && cd -",
|
13
|
+
"SUDO cd /tmp/AmazonMP3-InstallerForUbuntuNewerThan-9.04 && dpkg -i --force-architecture *.deb && cd - && rm -rf /tmp/AmazonMP3-InstallerForUbuntuNewerThan-9.04"
|
14
|
+
]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|