vcloud-launcher 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 0.5.0 (2014-10-14)
2
+
3
+ Features:
4
+
5
+ - Upgrade dependency on vCloud Core to 0.13.0. An error will now be raised if
6
+ your `FOG_CREDENTIAL` environment variable does not match the information
7
+ stored against a vCloud Director session referred to by `FOG_VCLOUD_TOKEN`,
8
+ so as to guard against accidental changes to the wrong vCloud Director
9
+ organization.
10
+
1
11
  ## 0.4.0 (2014-09-11)
2
12
 
3
13
  - Upgrade dependency on vCloud Core to 0.11.0 which prevents plaintext
@@ -11,6 +11,7 @@ module Vcloud
11
11
  "dont-power-on" => false,
12
12
  "continue-on-error" => false,
13
13
  "quiet" => false,
14
+ "post-launch-cmd" => false,
14
15
  "verbose" => false,
15
16
  }
16
17
 
@@ -68,6 +69,14 @@ Example configuration files can be found in:
68
69
  @options["quiet"] = true
69
70
  end
70
71
 
72
+ opts.on("-p COMMAND", "--post-launch-cmd COMMAND", "Executable to run when a VM is successfully provisioned") do |command|
73
+ if command.split().length() != 1
74
+ exit_error_usage("COMMAND only accepts an executable name, not a command with arguments")
75
+ else
76
+ @options["post-launch-cmd"] = command
77
+ end
78
+ end
79
+
71
80
  opts.on("-v", "--verbose", "Verbose output") do
72
81
  @options["verbose"] = true
73
82
  end
@@ -86,7 +95,7 @@ Example configuration files can be found in:
86
95
  @usage_text = opt_parser.to_s
87
96
  begin
88
97
  opt_parser.parse!(args)
89
- rescue OptionParser::InvalidOption => e
98
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
90
99
  exit_error_usage(e)
91
100
  end
92
101
 
@@ -23,6 +23,9 @@ module Vcloud
23
23
  begin
24
24
  vapp = ::Vcloud::Launcher::VappOrchestrator.provision(vapp_config)
25
25
  vapp.power_on unless cli_options["dont-power-on"]
26
+ if cli_options["post-launch-cmd"]
27
+ run_command(vapp_config, cli_options["post-launch-cmd"])
28
+ end
26
29
  Vcloud::Core.logger.info("Provisioned vApp #{vapp_config[:name]} successfully.")
27
30
  rescue RuntimeError => e
28
31
  Vcloud::Core.logger.error("Failure: Could not provision vApp: #{e.message}")
@@ -34,6 +37,34 @@ module Vcloud
34
37
 
35
38
  private
36
39
 
40
+ def run_command(vapp_definition, command)
41
+ command_path = File.expand_path(command)
42
+ if File.exist?(command_path)
43
+ begin
44
+ Vcloud::Core.logger.info("Running #{command_path} for #{vapp_definition[:name]}")
45
+ ENV['VAPP_DEFINITION'] = vapp_definition.to_s
46
+ exit_status = system(command_path)
47
+ exit_message = $?
48
+ if exit_status == false
49
+ # The command has returned a non-zero exit code
50
+ Vcloud::Core.logger.error("Failed to run #{command_path} for #{vapp_definition[:name]} exited with a non-zero response: #{exit_message}")
51
+ elsif exit_status == nil
52
+ # The call to system() has returned no exit code
53
+ Vcloud::Core.logger.error("Failed to run #{command_path} for #{vapp_definition[:name]} could not be run: #{exit_message}")
54
+ else
55
+ # The command has returned a zero exit code SUCCESS!
56
+ Vcloud::Core.logger.debug("Ran #{command_path} with VAPP_DEFINITION=#{vapp_definition}")
57
+ end
58
+ rescue
59
+ # Catch various errors including no permissions or unable to execute script
60
+ Vcloud::Core.logger.error("Failed to run #{command_path} for #{vapp_definition[:name]}")
61
+ end
62
+ else
63
+ # Catch specific case of a script that does not exist
64
+ Vcloud::Core.logger.error("#{command_path} does not exist")
65
+ end
66
+ end
67
+
37
68
  def set_logging_level
38
69
  if cli_options[:verbose]
39
70
  Vcloud::Core.logger.level = Logger::DEBUG
@@ -1,5 +1,5 @@
1
1
  module Vcloud
2
2
  module Launcher
3
- VERSION = '0.4.0'
3
+ VERSION = '0.5.0'
4
4
  end
5
5
  end
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ exit 1
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ exit 0
@@ -31,6 +31,53 @@ describe Vcloud::Launcher::Launch do
31
31
  end
32
32
  end
33
33
 
34
+ context "when running successful post-launch commands" do
35
+ it 'should log that it ran the command' do
36
+ @test_data = define_test_data
37
+ @config_yaml = ErbHelper.convert_erb_template_to_yaml(@test_data, File.join(File.dirname(__FILE__), 'data/minimum_data_setup.yaml.erb'))
38
+
39
+ # Stub out other debug messages to prevent expectation failing to match
40
+ Vcloud::Core.logger.stub(:debug).with(anything())
41
+
42
+ # Expectation must be set before first use of Vcloud::Core.logger
43
+ expect(Vcloud::Core.logger).to receive(:debug).with(/Ran.*with VAPP_DEFINITION/)
44
+
45
+ @api_interface = Vcloud::Core::ApiInterface.new
46
+
47
+ Vcloud::Launcher::Launch.new(@config_yaml, { "continue-on-error" => false, "dont-power-on" => true, "post-launch-cmd" => File.join(File.dirname(__FILE__), 'data/true_cmd') }).run
48
+
49
+ @vapp_query_result = @api_interface.get_vapp_by_name_and_vdc_name(@test_data[:vapp_name], @test_data[:vdc_name])
50
+ @vapp_id = @vapp_query_result[:href].split('/').last
51
+
52
+ unless ENV['VCLOUD_TOOLS_RSPEC_NO_DELETE_VAPP']
53
+ File.delete @config_yaml
54
+ expect(@api_interface.delete_vapp(@vapp_id)).to eq(true)
55
+ end
56
+ end
57
+ end
58
+
59
+ context "When running unsuccessful post-launch commands" do
60
+ it 'should give an appropriate error message' do
61
+ @test_data = define_test_data
62
+ @config_yaml = ErbHelper.convert_erb_template_to_yaml(@test_data, File.join(File.dirname(__FILE__), 'data/minimum_data_setup.yaml.erb'))
63
+
64
+ # Expectation must be set before first use of Vcloud::Core.logger
65
+ expect(Vcloud::Core.logger).to receive(:error).with(/Failed to run/)
66
+
67
+ @api_interface = Vcloud::Core::ApiInterface.new
68
+
69
+ Vcloud::Launcher::Launch.new(@config_yaml, { "continue-on-error" => false, "dont-power-on" => true, "post-launch-cmd" => File.join(File.dirname(__FILE__), 'data/false_cmd') }).run
70
+
71
+ @vapp_query_result = @api_interface.get_vapp_by_name_and_vdc_name(@test_data[:vapp_name], @test_data[:vdc_name])
72
+ @vapp_id = @vapp_query_result[:href].split('/').last
73
+
74
+ unless ENV['VCLOUD_TOOLS_RSPEC_NO_DELETE_VAPP']
75
+ File.delete @config_yaml
76
+ expect(@api_interface.delete_vapp(@vapp_id)).to eq(true)
77
+ end
78
+ end
79
+ end
80
+
34
81
  context "happy path" do
35
82
  before(:all) do
36
83
  @test_data = define_test_data
@@ -51,6 +51,7 @@ describe Vcloud::Launcher::Cli do
51
51
  "dont-power-on" => false,
52
52
  "continue-on-error" => false,
53
53
  "quiet" => false,
54
+ "post-launch-cmd" => false,
54
55
  "verbose" => false,
55
56
  }
56
57
  }
@@ -65,6 +66,7 @@ describe Vcloud::Launcher::Cli do
65
66
  "dont-power-on" => true,
66
67
  "continue-on-error" => false,
67
68
  "quiet" => false,
69
+ "post-launch-cmd" => false,
68
70
  "verbose" => false,
69
71
  }
70
72
  }
@@ -79,6 +81,7 @@ describe Vcloud::Launcher::Cli do
79
81
  "dont-power-on" => false,
80
82
  "continue-on-error" => true,
81
83
  "quiet" => false,
84
+ "post-launch-cmd" => false,
82
85
  "verbose" => false,
83
86
  }
84
87
  }
@@ -93,6 +96,7 @@ describe Vcloud::Launcher::Cli do
93
96
  "dont-power-on" => false,
94
97
  "continue-on-error" => false,
95
98
  "quiet" => true,
99
+ "post-launch-cmd" => false,
96
100
  "verbose" => false,
97
101
  }
98
102
  }
@@ -107,6 +111,7 @@ describe Vcloud::Launcher::Cli do
107
111
  "dont-power-on" => false,
108
112
  "continue-on-error" => false,
109
113
  "quiet" => false,
114
+ "post-launch-cmd" => false,
110
115
  "verbose" => true,
111
116
  }
112
117
  }
@@ -121,6 +126,7 @@ describe Vcloud::Launcher::Cli do
121
126
  "dont-power-on" => false,
122
127
  "continue-on-error" => true,
123
128
  "quiet" => false,
129
+ "post-launch-cmd" => false,
124
130
  "verbose" => true,
125
131
  }
126
132
  }
@@ -128,6 +134,37 @@ describe Vcloud::Launcher::Cli do
128
134
  it_behaves_like "a good CLI command"
129
135
  end
130
136
 
137
+ context "when asked to run a command on launch" do
138
+ let(:args) { [ config_file, "--post-launch-cmd", "GIRAFFE" ] }
139
+ let(:cli_options) {
140
+ {
141
+ "dont-power-on" => false,
142
+ "continue-on-error" => false,
143
+ "quiet" => false,
144
+ "post-launch-cmd" => 'GIRAFFE',
145
+ "verbose" => false,
146
+ }
147
+ }
148
+
149
+ it_behaves_like "a good CLI command"
150
+ end
151
+
152
+ context "specifying a command with arguments to run on launch" do
153
+ let(:args) { [ config_file, "--post-launch-cmd", "GIRAFFE LION" ] }
154
+ let(:cli_options) {
155
+ {
156
+ "dont-power-on" => false,
157
+ "continue-on-error" => false,
158
+ "quiet" => false,
159
+ "post-launch-cmd" => 'GIRAFFE LION',
160
+ "verbose" => false,
161
+ }
162
+ }
163
+ it "exits with a error code, because this is not supported" do
164
+ expect(subject.exitstatus).not_to eq(0)
165
+ end
166
+ end
167
+
131
168
  context "when asked to display version" do
132
169
  let(:args) { %w{--version} }
133
170
 
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.required_ruby_version = '>= 1.9.3'
22
22
 
23
- s.add_runtime_dependency 'vcloud-core', '~> 0.11.0'
23
+ s.add_runtime_dependency 'vcloud-core', '~> 0.13.0'
24
24
  s.add_development_dependency 'gem_publisher', '1.2.0'
25
25
  s.add_development_dependency 'pry'
26
26
  s.add_development_dependency 'rake'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vcloud-launcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-11 00:00:00.000000000 Z
12
+ date: 2014-10-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: vcloud-core
16
- requirement: &5183540 !ruby/object:Gem::Requirement
16
+ requirement: &17683740 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.11.0
21
+ version: 0.13.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *5183540
24
+ version_requirements: *17683740
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: gem_publisher
27
- requirement: &5182780 !ruby/object:Gem::Requirement
27
+ requirement: &17682540 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - =
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.2.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *5182780
35
+ version_requirements: *17682540
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: pry
38
- requirement: &5182260 !ruby/object:Gem::Requirement
38
+ requirement: &17681740 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *5182260
46
+ version_requirements: *17681740
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &5181560 !ruby/object:Gem::Requirement
49
+ requirement: &17680220 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *5181560
57
+ version_requirements: *17680220
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
- requirement: &5180780 !ruby/object:Gem::Requirement
60
+ requirement: &17694840 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 2.14.1
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *5180780
68
+ version_requirements: *17694840
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rubocop
71
- requirement: &5179260 !ruby/object:Gem::Requirement
71
+ requirement: &17693740 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.23.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *5179260
79
+ version_requirements: *17693740
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: simplecov
82
- requirement: &5177520 !ruby/object:Gem::Requirement
82
+ requirement: &17692940 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 0.7.1
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *5177520
90
+ version_requirements: *17692940
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: vcloud-tools-tester
93
- requirement: &5192280 !ruby/object:Gem::Requirement
93
+ requirement: &17690820 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: 0.2.0
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *5192280
101
+ version_requirements: *17690820
102
102
  description:
103
103
  email:
104
104
  - anna.shipman@digital.cabinet-office.gov.uk
@@ -137,9 +137,11 @@ files:
137
137
  - spec/erb_helper.rb
138
138
  - spec/integration/README.md
139
139
  - spec/integration/launcher/data/basic_preamble_test.erb
140
+ - spec/integration/launcher/data/false_cmd
140
141
  - spec/integration/launcher/data/happy_path.yaml.erb
141
142
  - spec/integration/launcher/data/minimum_data_setup.yaml.erb
142
143
  - spec/integration/launcher/data/storage_profile.yaml.erb
144
+ - spec/integration/launcher/data/true_cmd
143
145
  - spec/integration/launcher/launch_spec.rb
144
146
  - spec/integration/launcher/storage_profile_integration_spec.rb
145
147
  - spec/integration/vcloud_tools_testing_config.yaml.template
@@ -171,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
173
  version: '0'
172
174
  segments:
173
175
  - 0
174
- hash: -1721812803548595572
176
+ hash: 4391896427205100494
175
177
  requirements: []
176
178
  rubyforge_project:
177
179
  rubygems_version: 1.8.11
@@ -182,9 +184,11 @@ test_files:
182
184
  - spec/erb_helper.rb
183
185
  - spec/integration/README.md
184
186
  - spec/integration/launcher/data/basic_preamble_test.erb
187
+ - spec/integration/launcher/data/false_cmd
185
188
  - spec/integration/launcher/data/happy_path.yaml.erb
186
189
  - spec/integration/launcher/data/minimum_data_setup.yaml.erb
187
190
  - spec/integration/launcher/data/storage_profile.yaml.erb
191
+ - spec/integration/launcher/data/true_cmd
188
192
  - spec/integration/launcher/launch_spec.rb
189
193
  - spec/integration/launcher/storage_profile_integration_spec.rb
190
194
  - spec/integration/vcloud_tools_testing_config.yaml.template