vcloud-net_launcher 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/lib/vcloud/net_launcher/cli.rb +9 -8
- data/lib/vcloud/net_launcher/net_launch.rb +8 -5
- data/lib/vcloud/net_launcher/version.rb +1 -1
- data/spec/spec_helper.rb +8 -0
- data/spec/vcloud/net_launcher/cli_spec.rb +1 -17
- data/spec/vcloud/net_launcher/net_launch_spec.rb +3 -20
- metadata +3 -3
data/CHANGELOG.md
CHANGED
@@ -4,19 +4,24 @@ module Vcloud
|
|
4
4
|
module NetLauncher
|
5
5
|
class Cli
|
6
6
|
|
7
|
+
# Initiates parsing of the command-line arguments.
|
8
|
+
#
|
9
|
+
# @param argv_array [Array] Command-line arguments
|
10
|
+
# @return [void]
|
7
11
|
def initialize(argv_array)
|
8
12
|
@usage_text = nil
|
9
13
|
@config_file = nil
|
10
|
-
@options = {
|
11
|
-
"mock" => false,
|
12
|
-
}
|
13
14
|
|
14
15
|
parse(argv_array)
|
15
16
|
end
|
16
17
|
|
18
|
+
# Runs +Vcloud::NetLauncher::NetLaunch#run+ to create networks defined
|
19
|
+
# in +@config_file+, catching any exceptions to prevent printing a backtrace.
|
20
|
+
#
|
21
|
+
# @return [void]
|
17
22
|
def run
|
18
23
|
begin
|
19
|
-
Vcloud::NetLauncher::NetLaunch.new.run(@config_file
|
24
|
+
Vcloud::NetLauncher::NetLaunch.new.run(@config_file)
|
20
25
|
rescue => error_msg
|
21
26
|
$stderr.puts(error_msg)
|
22
27
|
exit 1
|
@@ -52,10 +57,6 @@ Example configuration files can be found in:
|
|
52
57
|
opts.separator ""
|
53
58
|
opts.separator "Options:"
|
54
59
|
|
55
|
-
opts.on("-m", "--mock", "Fog Mock mode enabled") do
|
56
|
-
@options["mock"] = true
|
57
|
-
end
|
58
|
-
|
59
60
|
opts.on("-h", "--help", "Print usage and exit") do
|
60
61
|
$stderr.puts opts
|
61
62
|
exit
|
@@ -4,17 +4,20 @@ module Vcloud
|
|
4
4
|
module NetLauncher
|
5
5
|
class NetLaunch
|
6
6
|
|
7
|
+
# Initializes instance variables.
|
8
|
+
#
|
9
|
+
# @return [void]
|
7
10
|
def initialize
|
8
11
|
@config_loader = Vcloud::Core::ConfigLoader.new
|
9
12
|
end
|
10
13
|
|
11
|
-
|
14
|
+
# Parses a configuration file and provisions the networks it defines.
|
15
|
+
#
|
16
|
+
# @param config_file [String] Path to a YAML or JSON-formatted configuration file
|
17
|
+
# @return [void]
|
18
|
+
def run(config_file = nil)
|
12
19
|
config = @config_loader.load_config(config_file, Vcloud::NetLauncher::Schema::NET_LAUNCH)
|
13
20
|
|
14
|
-
if options[:mock] || ENV['FOG_MOCK']
|
15
|
-
::Fog.mock!
|
16
|
-
end
|
17
|
-
|
18
21
|
config[:org_vdc_networks].each do |net_config|
|
19
22
|
net_config[:fence_mode] ||= 'isolated'
|
20
23
|
Vcloud::Core.logger.info("Provisioning orgVdcNetwork #{net_config[:name]}.")
|
data/spec/spec_helper.rb
CHANGED
@@ -31,3 +31,11 @@ RSpec.configure do |config|
|
|
31
31
|
c.syntax = :expect
|
32
32
|
end
|
33
33
|
end
|
34
|
+
|
35
|
+
# To enable Fog Mock mode use FOG_CREDENTIAL=fog_mock and FOG_MOCK=true
|
36
|
+
# If you do not have configuration for fog_mock in your vcloud_tools_testing_config.yaml,
|
37
|
+
# the test data is defined here: https://github.com/fog/fog/blob/master/lib/fog/vcloud_director/compute.rb#L483-L733
|
38
|
+
#
|
39
|
+
if ENV['FOG_MOCK']
|
40
|
+
Fog.mock!
|
41
|
+
end
|
@@ -40,29 +40,13 @@ describe Vcloud::NetLauncher::Cli do
|
|
40
40
|
expect(Vcloud::NetLauncher::NetLaunch).to receive(:new).
|
41
41
|
and_return(mock_net_launch)
|
42
42
|
expect(mock_net_launch).to receive(:run).
|
43
|
-
with(config_file
|
43
|
+
with(config_file)
|
44
44
|
expect(subject.exitstatus).to eq(0)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
context "when given a single config file" do
|
49
49
|
let(:args) { [ config_file ] }
|
50
|
-
let(:cli_options) {
|
51
|
-
{
|
52
|
-
"mock" => false,
|
53
|
-
}
|
54
|
-
}
|
55
|
-
|
56
|
-
it_behaves_like "a good CLI command"
|
57
|
-
end
|
58
|
-
|
59
|
-
context "when asked to use mock mode" do
|
60
|
-
let(:args) { [ config_file, "--mock" ] }
|
61
|
-
let(:cli_options) {
|
62
|
-
{
|
63
|
-
"mock" => true,
|
64
|
-
}
|
65
|
-
}
|
66
50
|
|
67
51
|
it_behaves_like "a good CLI command"
|
68
52
|
end
|
@@ -48,7 +48,7 @@ describe Vcloud::NetLauncher::NetLaunch do
|
|
48
48
|
expect(Vcloud::Core::OrgVdcNetwork).to receive(:provision).with(network2)
|
49
49
|
expect(Vcloud::Core::OrgVdcNetwork).to receive(:provision).with(network3)
|
50
50
|
|
51
|
-
subject.run('input_config_yaml'
|
51
|
+
subject.run('input_config_yaml')
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should abort on errors from Vcloud::Core" do
|
@@ -58,27 +58,10 @@ describe Vcloud::NetLauncher::NetLaunch do
|
|
58
58
|
expect(Vcloud::Core::OrgVdcNetwork).not_to receive(:provision).with(network3)
|
59
59
|
|
60
60
|
expect {
|
61
|
-
Vcloud::NetLauncher::NetLaunch.new.run('input_config_yaml'
|
61
|
+
Vcloud::NetLauncher::NetLaunch.new.run('input_config_yaml')
|
62
62
|
}.to raise_error(RuntimeError, 'Did not successfully create orgVdcNetwork')
|
63
63
|
end
|
64
64
|
|
65
|
-
describe "fog mocking" do
|
66
|
-
it "should not mock fog by default" do
|
67
|
-
expect(Fog).to_not receive(:mock!)
|
68
|
-
expect(Vcloud::Core::OrgVdcNetwork).to receive(:provision).exactly(3).times
|
69
|
-
|
70
|
-
subject.run('input_config_yaml', cli_options)
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should mock fog when passed option" do
|
74
|
-
expect(Fog).to receive(:mock!)
|
75
|
-
expect(Vcloud::Core::OrgVdcNetwork).to receive(:provision).exactly(3).times
|
76
|
-
|
77
|
-
cli_options = { :mock => true }
|
78
|
-
subject.run('input_config_yaml', cli_options)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
65
|
end
|
83
66
|
|
84
67
|
context "ConfigLoader returns one network without :fence_mode set" do
|
@@ -108,7 +91,7 @@ describe Vcloud::NetLauncher::NetLaunch do
|
|
108
91
|
expect(network_without_fence_mode).not_to have_key(:fence_mode)
|
109
92
|
expect(Vcloud::Core::OrgVdcNetwork).to receive(:provision).with(network_with_fence_mode)
|
110
93
|
|
111
|
-
subject.run('input_config_yaml'
|
94
|
+
subject.run('input_config_yaml')
|
112
95
|
end
|
113
96
|
end
|
114
97
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vcloud-net_launcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-07-
|
12
|
+
date: 2014-07-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: vcloud-core
|
@@ -198,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
198
|
version: '0'
|
199
199
|
segments:
|
200
200
|
- 0
|
201
|
-
hash:
|
201
|
+
hash: 792051475262227984
|
202
202
|
requirements: []
|
203
203
|
rubyforge_project:
|
204
204
|
rubygems_version: 1.8.23
|