rconf 0.7.5 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,124 @@
1
+ # Copyright (C) 2011 RightScale, Inc, All Rights Reserved Worldwide.
2
+ #
3
+ # THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE
4
+ # AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use,
5
+ # reproduction, modification, or disclosure of this program is
6
+ # strictly prohibited. Any use of this program by an authorized
7
+ # licensee is strictly subject to the terms and conditions,
8
+ # including confidentiality obligations, set forth in the applicable
9
+ # License Agreement between RightScale.com, Inc. and
10
+ # the licensee
11
+
12
+ module RightConf
13
+
14
+ class CassandraConfigurator
15
+
16
+ SOURCE_BASE_URL = 'http://mirror.metrocast.net/apache//cassandra/VERSION/apache-cassandra-VERSION-bin.tar.gz'
17
+ DEFAULT_CASSANDRA_INSTALL = ['/opt/cassandra', File.join(ENV['HOME'], 'cassandra')]
18
+
19
+ include Configurator
20
+
21
+ register :cassandra
22
+
23
+ description 'Installs Cassandra'
24
+
25
+ settings :version => 'Cassandra version to install',
26
+ :install_path => 'Path to Cassandra installation directory, uses /opt/cassandra if it ' +
27
+ 'is writable by the current user or ~/cassandra otherwise by default',
28
+ :abort_on_failure => 'Whether to abort if Cassandra failed to install (false by default)'
29
+
30
+ validate_has_settings :version
31
+
32
+ # Install Linux Mercurial package
33
+ #
34
+ # === Return
35
+ # true:: Always return true
36
+ def run
37
+ install_path(default_install_path) if install_path.nil?
38
+ abort_on_failure(false) if abort_on_failure.nil?
39
+ unless cassandra_installed
40
+ report_check('Installing Cassandra')
41
+ url = SOURCE_BASE_URL.gsub('VERSION', version)
42
+ FileUtils.mv(install_path, "#{install_path}_old") if File.exist?(install_path)
43
+ FileUtils.mkdir_p(install_path)
44
+ Dir.chdir(install_path) do
45
+ Command.execute('curl', '-O', '-f', url, abort_option('Failed to download Cassandra'))
46
+ Command.execute('unzip', File.basename(url), abort_option('Failed to unzip Cassandra'))
47
+ end
48
+ bin_path = File.join(install_path, "apache-cassandra-#{version}", 'bin')
49
+ if EnvironmentUpdater.update("PATH=$PATH:#{bin_path}", ['PATH'])
50
+ post_note 'Cassandra was installed, please reload your shell to activate it and re-run rconf'
51
+ aborting(true)
52
+ end
53
+ report_success
54
+ end
55
+ end
56
+
57
+ # Install Windows software
58
+ #
59
+ # === Return
60
+ # true:: Always return true
61
+ def run_windows
62
+ # TBD
63
+ end
64
+
65
+ protected
66
+
67
+ # Check whether Cassandra is installed
68
+ #
69
+ # === Return
70
+ # true:: If Mercurial is installed
71
+ # false:: Otherwise
72
+ def cassandra_installed
73
+ report_check("Checking for Cassandra")
74
+ installed = Command.execute('cassandra', '-h').success?
75
+ report_result(installed)
76
+ installed
77
+ end
78
+
79
+ # Retrieve default install path
80
+ # Try /opt/cassandra and revert to ~/cassandra if not writable
81
+ #
82
+ # === Return
83
+ # path:: Default cassandra install path
84
+ def default_install_path
85
+ path = if File.exist?('/opt')
86
+ if File.exist?('/opt/cassandra')
87
+ pick_default_path(File.writable?('/opt/cassandra'))
88
+ else
89
+ res = Command.execute('mkdir', '/opt/cassandra')
90
+ pick_default_path(res.success?)
91
+ end
92
+ else
93
+ res = Command.execute('mkdir', '-p', '/opt/cassandra')
94
+ pick_default_path(res.success?)
95
+ end
96
+ end
97
+
98
+ # First or second choice nginx install path
99
+ #
100
+ # === Parameter
101
+ # first_choice(TrueClass|FalseClass):: Whether to use first or second choice path
102
+ #
103
+ # === Return
104
+ # path(String):: Path
105
+ def pick_default_path(first_choice)
106
+ path = DEFAULT_CASSANDRA_INSTALL[first_choice && 0 || 1]
107
+ end
108
+
109
+ # Produce abort on failure option
110
+ #
111
+ # === Parameters
112
+ # message(String):: Abort message to be used in case abort option should be set
113
+ #
114
+ # === Return
115
+ # {}:: Empty hash if 'abort_on_failure' is notset
116
+ # opts(Hash):: Abort option with give message otherwise
117
+ def abort_option(message)
118
+ opts = abort_on_failure && { :abort_on_failure => message } || {}
119
+ end
120
+
121
+ end
122
+ end
123
+
124
+
@@ -0,0 +1,73 @@
1
+ # Copyright (C) 2011 RightScale, Inc, All Rights Reserved Worldwide.
2
+ #
3
+ # THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE
4
+ # AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use,
5
+ # reproduction, modification, or disclosure of this program is
6
+ # strictly prohibited. Any use of this program by an authorized
7
+ # licensee is strictly subject to the terms and conditions,
8
+ # including confidentiality obligations, set forth in the applicable
9
+ # License Agreement between RightScale.com, Inc. and
10
+ # the licensee
11
+
12
+ module RightConf
13
+
14
+ class GitRepoConfigurator
15
+
16
+ include Configurator
17
+
18
+ register :git_repo
19
+
20
+ description 'Clone git repository and build if needed'
21
+
22
+ settings :repo => 'git repo URL',
23
+ :tag => 'git tag or branch or sha that should be checked out',
24
+ :install_path => 'Path where git repo should be cloned to',
25
+ :build_commands => 'Comma separated list of commands to run in repo after clone',
26
+ :only_if => 'Ruby lambda expression that should return true to proceed ' +
27
+ 'with the cloning / build if defined'
28
+
29
+ validate_has_settings :repo, :install_path
30
+
31
+ # Clone git repo and run build commands if given
32
+ #
33
+ # === Return
34
+ # true:: Always return true
35
+ def run
36
+ if only_if.nil? || only_if.call
37
+ report_check("Cloning #{repo} into #{install_path}")
38
+ if File.exist?(install_path)
39
+ FileUtils.mv(install_path, "#{install_path}_old")
40
+ post_note "Had to move pre-existing #{install_path} to #{install_path}_old"
41
+ end
42
+ Command.execute('git', 'clone', repo, install_path,
43
+ :abort_on_failure => "Failed to clone #{repo} into #{install_path}")
44
+ Command.execute('git', 'checkout', tag) if tag
45
+ report_success
46
+ if build_commands
47
+ report_check "Building"
48
+ Dir.chdir(install_path) do
49
+ build_commands.split(',').each do |c|
50
+ c.lstrip!
51
+ args = c.split(' ') + [ { :abort_on_failure => "#{c} failed" } ]
52
+ Command.execute(*args)
53
+ end
54
+ end
55
+ report_success
56
+ end
57
+ end
58
+ true
59
+ end
60
+
61
+ # Clone on Windows
62
+ #
63
+ # === Return
64
+ # true:: Always return true
65
+ def run_windows
66
+ # TBD
67
+ end
68
+
69
+ end
70
+ end
71
+
72
+
73
+
@@ -0,0 +1,72 @@
1
+ # Copyright (C) 2011 RightScale, Inc, All Rights Reserved Worldwide.
2
+ #
3
+ # THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE
4
+ # AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use,
5
+ # reproduction, modification, or disclosure of this program is
6
+ # strictly prohibited. Any use of this program by an authorized
7
+ # licensee is strictly subject to the terms and conditions,
8
+ # including confidentiality obligations, set forth in the applicable
9
+ # License Agreement between RightScale.com, Inc. and
10
+ # the licensee
11
+
12
+ module RightConf
13
+
14
+ class EnvironmentUpdater
15
+
16
+ include ProgressReporter
17
+
18
+ # Update bash resource or profile file to define given environment variable
19
+ # or append to existing environment variable
20
+ #
21
+ # === Parameters
22
+ # code(String):: Code to be inserted in bash resource file
23
+ # dependencies(Array):: List of environment variables that code will update
24
+ # (Use to put code after these env var are set in the
25
+ # existing bash resource file)
26
+ #
27
+ # === Return
28
+ # true:: If bash resource or profile file was updated
29
+ # false:: Otherwise
30
+ def self.update(code, dependencies=[])
31
+ candidates = ['.bashrc', '.bash_profile']
32
+ candidates.map! { |c| File.join(ENV['HOME'], c) }
33
+ bashrc_path = candidates.detect { |c| File.exist?(c) }
34
+ updated = false
35
+ if bashrc_path
36
+ content = IO.read(bashrc_path)
37
+ unless content.include?(code)
38
+ i = dependencies.inject(nil) do |m, d|
39
+ index = content.index(/^\s*#{d}=/)
40
+ m = if m.nil?
41
+ index
42
+ else
43
+ if index.nil?
44
+ m
45
+ else
46
+ [ index, m ].max
47
+ end
48
+ end
49
+ end
50
+ if i
51
+ next_line = content.index("\n", i + 1)
52
+ if next_line
53
+ content.insert(next_line + 1, code + "\n")
54
+ else
55
+ content += "\n" + code
56
+ end
57
+ else
58
+ content = code + "\n" + content
59
+ end
60
+ FileUtils.mv(bashrc_path, bashrc_path + '.old')
61
+ File.open(bashrc_path, 'w') { |f| f.puts content }
62
+ end
63
+ updated = true
64
+ else
65
+ report_error "Failed to update bash resource or profile: file not found"
66
+ end
67
+ end
68
+
69
+ end
70
+ end
71
+
72
+
@@ -13,7 +13,7 @@ module RightConf
13
13
 
14
14
  MAJOR = 0
15
15
  MINOR = 7
16
- BUILD = 5
16
+ BUILD = 6
17
17
 
18
18
  VERSION = [MAJOR, MINOR, BUILD].map(&:to_s).join('.')
19
19
 
@@ -0,0 +1,47 @@
1
+ # Copyright (C) 2011 RightScale, Inc, All Rights Reserved Worldwide.
2
+ #
3
+ # THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE
4
+ # AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use,
5
+ # reproduction, modification, or disclosure of this program is
6
+ # strictly prohibited. Any use of this program by an authorized
7
+ # licensee is strictly subject to the terms and conditions,
8
+ # including confidentiality obligations, set forth in the applicable
9
+ # License Agreement between RightScale.com, Inc. and
10
+ # the licensee
11
+
12
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
13
+
14
+ describe RightConf::GitRepoConfigurator do
15
+
16
+ before(:each) do
17
+ lang = RightConf::Language.parse('git_repo { repo "git"; install_path "./git" }')
18
+ @configurator = lang.configurators.first
19
+ [:report_check, :report_result, :report_success].each do |meth|
20
+ flexmock(@configurator).should_receive(meth)
21
+ end
22
+ flexmock(@configurator).should_receive(:report_fatal).and_return { |*args| raise args.join(' ') }
23
+ @abf = { :abort_on_failure => 'Failed to clone git into ./git' }
24
+ end
25
+
26
+ it 'should clone' do
27
+ flexmock(RightConf::Command.instance).should_receive(:execute).with('git', 'clone', 'git', './git', @abf).once
28
+ @configurator.run
29
+ end
30
+
31
+ it 'run the build commands' do
32
+ @configurator.instance_eval { build_commands('do one, do two') }
33
+ flexmock(RightConf::Command.instance).should_receive(:execute).with('git', 'clone', 'git', './git', @abf).once
34
+ flexmock(Dir).should_receive(:chdir).with('./git', Proc).once.and_yield
35
+ flexmock(RightConf::Command.instance).should_receive(:execute).with('do', 'one', :abort_on_failure => 'do one failed').once
36
+ flexmock(RightConf::Command.instance).should_receive(:execute).with('do', 'two', :abort_on_failure => 'do two failed').once
37
+ @configurator.run
38
+ end
39
+
40
+ it 'should honor only_if' do
41
+ @configurator.instance_eval { only_if(lambda { false }) }
42
+ flexmock(RightConf::Command.instance).should_receive(:execute).and_return { raise "Command should not execute" }
43
+ @configurator.run
44
+ end
45
+
46
+ end
47
+
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rconf
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.7.5
5
+ version: 0.7.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Raphael Simon
@@ -75,6 +75,8 @@ files:
75
75
  - lib/rconf/configurator.rb
76
76
  - lib/rconf/configurator_registry.rb
77
77
  - lib/rconf/configurators/bundler_configurator.rb
78
+ - lib/rconf/configurators/cassandra_configurator.rb
79
+ - lib/rconf/configurators/git_repo_configurator.rb
78
80
  - lib/rconf/configurators/mercurial_configurator.rb
79
81
  - lib/rconf/configurators/packages_configurator.rb
80
82
  - lib/rconf/configurators/passenger_configurator.rb
@@ -91,6 +93,7 @@ files:
91
93
  - lib/rconf/progress_reporters/stdout_reporter.rb
92
94
  - lib/rconf/ruby_extensions.rb
93
95
  - lib/rconf/support/brew_installer.rb
96
+ - lib/rconf/support/environment_updater.rb
94
97
  - lib/rconf/support/package_installer.rb
95
98
  - lib/rconf/trollop.rb
96
99
  - lib/rconf/version.rb
@@ -99,6 +102,7 @@ files:
99
102
  - spec/command_spec.rb
100
103
  - spec/configurator_spec.rb
101
104
  - spec/configurators/bundler_configurator_spec.rb
105
+ - spec/configurators/git_repo_configurator_spec.rb
102
106
  - spec/configurators/packages_configurator_spec.rb
103
107
  - spec/configurators/passenger_configurator_spec.rb
104
108
  - spec/configurators/ruby_configurator_spec.rb
@@ -143,6 +147,7 @@ test_files:
143
147
  - spec/command_spec.rb
144
148
  - spec/configurator_spec.rb
145
149
  - spec/configurators/bundler_configurator_spec.rb
150
+ - spec/configurators/git_repo_configurator_spec.rb
146
151
  - spec/configurators/packages_configurator_spec.rb
147
152
  - spec/configurators/passenger_configurator_spec.rb
148
153
  - spec/configurators/ruby_configurator_spec.rb