vcloud-net_launcher 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1 +1,3 @@
1
1
  /Gemfile.lock
2
+ /coverage/
3
+ spec/integration/vcloud_tools_testing_config.yaml
data/.travis.yml CHANGED
@@ -2,8 +2,7 @@
2
2
  language: ruby
3
3
  rvm:
4
4
  - 1.9.3
5
- branches:
6
- except:
7
- - master
5
+ - 2.0.0
6
+ - 2.1.2
8
7
  notifications:
9
8
  email: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 0.3.0 (2014-07-14)
2
+
3
+ Features:
4
+
5
+ - `vcloud-net-launch --version` now only returns the version string
6
+ and no usage information.
7
+
1
8
  ## 0.2.0 (2014-05-14)
2
9
 
3
10
  Features:
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,66 @@
1
+ # Contributing to vCloud Net Launcher
2
+
3
+ We really welcome contributions.
4
+
5
+ ## A quick guide on how to contribute
6
+
7
+ 1. Clone the repo:
8
+
9
+ git clone git@github.com:gds-operations/vcloud-net_launcher.git
10
+
11
+ 2. Run `bundle` to get the required dependecies
12
+
13
+ 3. Run the tests. Pull requests that add features must include unit tests,
14
+ so it is good to ensure you've got them passing to begin with.
15
+
16
+ bundle exec rake
17
+
18
+ If you have access to a live environment for testing, it would be great
19
+ if you could run the integration tests too - for more details on the
20
+ set-up for that, please see the [integration tests README]
21
+ (https://github.com/gds-operations/vcloud-net_launcher/blob/master/spec/integration/README.md)
22
+
23
+ 4. Add your functionality or bug fix and a test for your change. Only refactoring and
24
+ documentation changes do not require tests. If the functionality is at all complicated
25
+ then it is likely that more than one test will be required. If you would like help
26
+ with writing tests please do ask us.
27
+
28
+ 5. Make sure all the tests pass, including the integration tests if possible.
29
+
30
+ 6. Update the [CHANGELOG](https://github.com/gds-operations/vcloud-net_launcher/blob/master/CHANGELOG.md)
31
+ with a short description of what the change is. This may be a feature, a bugfix, or an
32
+ API change. If your change is documenation or refactoring, you do not need to add a line
33
+ to the CHANGELOG.
34
+
35
+ 7. Fork the repo, push to your fork, and submit a pull request.
36
+
37
+ ## How soon will we respond?
38
+
39
+ We will comment on your pull request within two working days. However, we might not be able to review it immediately.
40
+
41
+ We may come back to you with comments and suggestions, and if we would like you to make changes, we will close the pull request as well as adding details of the changes we'd like you to make.
42
+
43
+ If you feel your pull request has been outstanding too long, please feel free to bump it by making a comment on it.
44
+
45
+ ## Guidelines for making a pull request
46
+
47
+ The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
48
+ "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be
49
+ interpreted as described in RFC 2119.
50
+
51
+ ## In order for a pull request to be accepted, it MUST
52
+
53
+ - Include at least one test (unless it is documentation or refactoring). If you have any questions about how to write tests, please ask us, we will be happy to help
54
+ - Follow our [Git style guide](https://github.com/alphagov/styleguides/blob/master/git.md)
55
+ - Include a clear summary in the pull request comments as to what the change is and why
56
+ you are making it
57
+ - Be readable - we might ask you to change unclear variable names or obscure syntactic sugar
58
+ - Have [good commit messages](http://robots.thoughtbot.com/5-useful-tips-for-a-better-commit-message)
59
+ that explain the change being made in that commit. Don't be afraid to write a lot in the
60
+ detail.
61
+
62
+ ## In order for a pull request to be accepted, it SHOULD
63
+
64
+ - Include a line in the CHANGELOG unless it is a refactoring or documentation change
65
+ - If it is code, follow our [Ruby style guide](https://github.com/alphagov/styleguides/blob/master/ruby.md)
66
+ - If it is documentation, follow the [GDS content style guide](https://www.gov.uk/design-principles/style-guide/style-points)
data/Gemfile CHANGED
@@ -1,9 +1,9 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
5
  if ENV['VCLOUD_CORE_DEV_MASTER']
6
- gem 'vcloud-core', :git => 'git@github.com:alphagov/vcloud-core.git', :branch => 'master'
6
+ gem 'vcloud-core', :git => 'git@github.com:gds-operations/vcloud-core.git', :branch => 'master'
7
7
  elsif ENV['VCLOUD_CORE_DEV_LOCAL']
8
8
  gem 'vcloud-core', :path => '../vcloud-core'
9
9
  end
data/README.md CHANGED
@@ -74,13 +74,12 @@ Limitations
74
74
  * Not currently reentrant - if the process errors part of the way through, the previously applied network config
75
75
  will need to be removed from the file before it is corrected and run again.
76
76
 
77
+ * No support for deleting networks. If you need to reconfigure a network, delete it first using the vCloud Director
78
+ GUI and re-run `vcloud-net-launch`.
79
+
77
80
  ## Contributing
78
81
 
79
- 1. Fork it
80
- 2. Create your feature branch (`git checkout -b my-new-feature`)
81
- 3. Commit your changes (`git commit -am 'Add some feature'`)
82
- 4. Push to the branch (`git push origin my-new-feature`)
83
- 5. Create new Pull Request
82
+ We welcome contributions. Please see the [contributing guidelines](/CONTRIBUTING.md).
84
83
 
85
84
  ## Other settings
86
85
 
@@ -113,25 +112,4 @@ Run the integration tests (slower and requires a real environment):
113
112
  bundle exec rake integration
114
113
 
115
114
  You need access to a suitable vCloud Director organization to run the
116
- integration tests. It is not necessarily safe to run them against an existing
117
- environment, unless care is taken with the entities being tested.
118
-
119
- The easiest thing to do is create a local shell script called
120
- `vcloud_env.sh` and set the contents:
121
-
122
- export FOG\_CREDENTIAL=test
123
- export VCLOUD\_VDC\_NAME="Name of the VDC"
124
- export VCLOUD\_CATALOG\_NAME="catalog-name"
125
- export VCLOUD\_TEMPLATE\_NAME="name-of-template"
126
- export VCLOUD\_NETWORK1\_NAME="name-of-primary-network"
127
- export VCLOUD\_NETWORK2\_NAME="name-of-secondary-network"
128
- export VCLOUD\_NETWORK1\_IP="ip-on-primary-network"
129
- export VCLOUD\_NETWORK2\_IP="ip-on-secondary-network"
130
- export VCLOUD\_TEST\_STORAGE\_PROFILE="storage-profile-name"
131
- export VCLOUD\_EDGE\_GATEWAY="name-of-edge-gateway-in-vdc"
132
-
133
- Then run this before you run the integration tests.
134
-
135
- [example_yaml]: ../examples/vcloud-net-launch/
136
- [fog]: http://fog.io/
137
-
115
+ integration tests. See the [integration tests README](/spec/integration/README.md) for further details.
data/Rakefile CHANGED
@@ -1,8 +1,7 @@
1
- require 'cucumber/rake/task'
2
1
  require 'rspec/core/rake_task'
3
2
  require 'gem_publisher'
4
3
 
5
- task :default => [:rubocop, :spec, :features]
4
+ task :default => [:rubocop, :spec]
6
5
 
7
6
  RSpec::Core::RakeTask.new(:spec) do |task|
8
7
  # Set a bogus Fog credential, otherwise it's possible for the unit
@@ -12,11 +11,6 @@ RSpec::Core::RakeTask.new(:spec) do |task|
12
11
  task.pattern = FileList['spec/vcloud/**/*_spec.rb']
13
12
  end
14
13
 
15
- Cucumber::Rake::Task.new(:features) do |t|
16
- t.cucumber_opts = "--format pretty --no-source"
17
- t.fork = false
18
- end
19
-
20
14
  RSpec::Core::RakeTask.new(:integration) do |t|
21
15
  t.pattern = FileList['spec/integration/**/*_spec.rb']
22
16
  end
@@ -27,6 +21,6 @@ task :publish_gem do
27
21
  end
28
22
 
29
23
  require 'rubocop/rake_task'
30
- Rubocop::RakeTask.new(:rubocop) do |task|
24
+ RuboCop::RakeTask.new(:rubocop) do |task|
31
25
  task.options = ['--lint']
32
26
  end
@@ -1,44 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'rubygems'
4
- require 'bundler/setup'
5
- require 'optparse'
6
- require 'methadone'
7
-
8
3
  require 'vcloud/net_launcher'
9
4
 
10
- class App
11
- include Methadone::Main
12
- include Methadone::CLILogging
13
- include Vcloud
14
-
15
- main do |net_config_file|
16
- NetLauncher::NetLaunch.new.run(net_config_file, options)
17
- end
18
-
19
- on("-m", "--mock", "Fog Mock mode enabled")
20
-
21
- arg :net_config_file
22
-
23
- examples_dir = File.absolute_path(
24
- File.join(
25
- File.dirname(__FILE__),
26
- "..",
27
- "examples",
28
- File.basename(__FILE__),
29
- ))
30
-
31
- description "
32
- vcloud-net-launch takes a configuration describing a vCloud network,
33
- and tries to make it a reality.
34
-
35
- See https://github.com/alphagov/vcloud-tools for more info
36
-
37
- Example configuration files can be found in:
38
- #{examples_dir}
39
- "
40
-
41
- version Vcloud::NetLauncher::VERSION
42
-
43
- go!
44
- end
5
+ Vcloud::NetLauncher::Cli.new(ARGV).run
data/jenkins.sh CHANGED
@@ -1,9 +1,14 @@
1
1
  #!/bin/bash -x
2
2
  set -e
3
+
4
+ git clean -ffdx
3
5
  bundle install --path "${HOME}/bundles/${JOB_NAME}"
4
- # commented out for now as there are no unit tests
5
- # and rake aefault is currently integration test
6
- # bundle exec rake
6
+ bundle exec rake
7
+
8
+ # Obtain the integration test parameters
9
+ git clone git@github.gds:gds/vcloud-tools-testing-config.git
10
+ mv vcloud-tools-testing-config/vcloud_tools_testing_config.yaml spec/integration/
11
+ rm -rf vcloud-tools-testing-config
7
12
 
8
13
  RUBYOPT="-r ./tools/fog_credentials" bundle exec rake integration
9
14
 
@@ -1,5 +1,12 @@
1
1
  #!/bin/bash -x
2
2
  set -e
3
+
4
+ git clean -ffdx
3
5
  bundle install --path "${HOME}/bundles/${JOB_NAME}"
4
6
 
7
+ # Obtain the integration test parameters
8
+ git clone git@github.gds:gds/vcloud-tools-testing-config.git
9
+ mv vcloud-tools-testing-config/vcloud_tools_testing_config.yaml spec/integration/
10
+ rm -rf vcloud-tools-testing-config
11
+
5
12
  RUBYOPT="-r ./tools/fog_credentials" bundle exec rake integration
@@ -11,5 +11,6 @@ require 'vcloud/net_launcher/version'
11
11
  require 'vcloud/fog'
12
12
  require 'vcloud/core'
13
13
 
14
+ require 'vcloud/net_launcher/cli'
14
15
  require 'vcloud/net_launcher/net_launch'
15
-
16
+ require 'vcloud/net_launcher/schema/net_launch'
@@ -0,0 +1,88 @@
1
+ require 'optparse'
2
+
3
+ module Vcloud
4
+ module NetLauncher
5
+ class Cli
6
+
7
+ def initialize(argv_array)
8
+ @usage_text = nil
9
+ @config_file = nil
10
+ @options = {
11
+ "mock" => false,
12
+ }
13
+
14
+ parse(argv_array)
15
+ end
16
+
17
+ def run
18
+ begin
19
+ Vcloud::NetLauncher::NetLaunch.new.run(@config_file, @options)
20
+ rescue => error_msg
21
+ $stderr.puts(error_msg)
22
+ exit 1
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def parse(args)
29
+ opt_parser = OptionParser.new do |opts|
30
+ examples_dir = File.absolute_path(
31
+ File.join(
32
+ File.dirname(__FILE__),
33
+ "..",
34
+ "..",
35
+ "..",
36
+ "examples",
37
+ File.basename($0),
38
+ ))
39
+
40
+ opts.banner = <<-EOS
41
+ Usage: #{$0} [options] config_file
42
+
43
+ vcloud-net-launch takes a configuration describing a vCloud network,
44
+ and tries to make it a reality.
45
+
46
+ See https://github.com/gds-operations/vcloud-tools for more info
47
+
48
+ Example configuration files can be found in:
49
+ #{examples_dir}
50
+ EOS
51
+
52
+ opts.separator ""
53
+ opts.separator "Options:"
54
+
55
+ opts.on("-m", "--mock", "Fog Mock mode enabled") do
56
+ @options["mock"] = true
57
+ end
58
+
59
+ opts.on("-h", "--help", "Print usage and exit") do
60
+ $stderr.puts opts
61
+ exit
62
+ end
63
+
64
+ opts.on("--version", "Display version and exit") do
65
+ puts Vcloud::NetLauncher::VERSION
66
+ exit
67
+ end
68
+ end
69
+
70
+ @usage_text = opt_parser.to_s
71
+ begin
72
+ opt_parser.parse!(args)
73
+ rescue OptionParser::InvalidOption => e
74
+ exit_error_usage(e)
75
+ end
76
+
77
+ exit_error_usage("must supply config_file") unless args.size == 1
78
+ @config_file = args.first
79
+ end
80
+
81
+ def exit_error_usage(error)
82
+ $stderr.puts "#{$0}: #{error}"
83
+ $stderr.puts @usage_text
84
+ exit 2
85
+ end
86
+ end
87
+ end
88
+ end
@@ -9,7 +9,7 @@ module Vcloud
9
9
  end
10
10
 
11
11
  def run(config_file = nil, options = {})
12
- config = @config_loader.load_config(config_file)
12
+ config = @config_loader.load_config(config_file, Vcloud::NetLauncher::Schema::NET_LAUNCH)
13
13
 
14
14
  if options[:mock] || ENV['FOG_MOCK']
15
15
  ::Fog.mock!
@@ -0,0 +1,81 @@
1
+ module Vcloud
2
+ module NetLauncher
3
+ module Schema
4
+
5
+ NET_LAUNCH = {
6
+ type: 'hash',
7
+ internals: {
8
+ org_vdc_networks: {
9
+ type: 'array',
10
+ required: true,
11
+ each_element_is: {
12
+ type: 'hash',
13
+ internals: {
14
+ name: {
15
+ type: 'string',
16
+ required: true,
17
+ },
18
+ edge_gateway: {
19
+ type: 'string',
20
+ required: false,
21
+ },
22
+ vdc_name: {
23
+ type: 'string',
24
+ required: true,
25
+ },
26
+ fence_mode: {
27
+ type: 'enum',
28
+ required: false,
29
+ acceptable_values: %w{ isolated natRouted },
30
+ },
31
+ is_inherited: {
32
+ type: 'boolean',
33
+ required: false,
34
+ },
35
+ is_enabled: {
36
+ type: 'boolean',
37
+ required: false,
38
+ },
39
+ gateway: {
40
+ type: 'ip_address',
41
+ required: false,
42
+ },
43
+ netmask: {
44
+ type: 'ip_address',
45
+ required: false,
46
+ },
47
+ dns1: {
48
+ type: 'ip_address',
49
+ required: false,
50
+ },
51
+ dns2: {
52
+ type: 'ip_address',
53
+ required: false,
54
+ },
55
+ ip_ranges: {
56
+ type: 'array',
57
+ required: false,
58
+ each_element_is: {
59
+ type: 'hash',
60
+ required: true,
61
+ internals: {
62
+ start_address: {
63
+ type: 'ip_address',
64
+ required: true,
65
+ },
66
+ end_address: {
67
+ type: 'ip_address',
68
+ required: true,
69
+ },
70
+ },
71
+ },
72
+ },
73
+ },
74
+ },
75
+ },
76
+ },
77
+ }
78
+
79
+ end
80
+ end
81
+ end
@@ -1,5 +1,5 @@
1
1
  module Vcloud
2
2
  module NetLauncher
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
@@ -0,0 +1,33 @@
1
+ # Running vCloud Net Launcher Integration Tests
2
+
3
+ ## Prerequisites
4
+
5
+ - Access to a suitable vCloud Director organisation.
6
+
7
+ **NB** It is not safe to run them against an environment that is in use
8
+ (e.g. production, preview) as many of the tests clear down all config at
9
+ the beginning and/or end to ensure the environment is as the tests expect.
10
+
11
+ - A config file with the settings configured.
12
+
13
+ There is a [template file](spec/integration/vcloud_tools_testing_config.yaml.template) to
14
+ help with this. Copy the template file to `spec/integration/vcloud_tools_testing_config.yaml`
15
+ and update with parameters suitable for your environment.
16
+
17
+ - You need to include the set-up for your testing environment in your
18
+ [fog file](https://github.com/gds-operations/vcloud-core#credentials).
19
+
20
+ - The tests use the [vCloud Tools Tester](http://rubygems.org/gems/vcloud-tools-tester) gem.
21
+ You do not need to install this, `bundler` will do this for you.
22
+
23
+ ## Parameters
24
+
25
+ ````
26
+ default: # This is the fog credential that refers to your testing environment, e.g. `test_credential`
27
+ vdc_1_name: # The name of a VDC
28
+ edge_gateway: # The name of the edge gateway
29
+ ````
30
+
31
+ ## To run the tests
32
+
33
+ `FOG_CREDENTIAL=test_credential bundle exec integration`
@@ -6,4 +6,4 @@ org_vdc_networks:
6
6
  fence_mode: <%= fence_mode %>
7
7
  netmask: <%= netmask %>
8
8
  gateway: <%= gateway %>
9
- edge_gateway: <%= edgeGateway %>
9
+ edge_gateway: <%= edge_gateway %>
@@ -15,27 +15,26 @@ module Vcloud
15
15
  Vcloud::NetLauncher::NetLaunch.new.run(@minimum_data_yaml)
16
16
 
17
17
  @found_networks = find_network(test_data[:network_name])
18
- @found_networks.length.should eq(1)
18
+ expect(@found_networks.length).to eq(1)
19
19
  provisioned_network = @found_networks[0]
20
- provisioned_network[:gateway].should eq(test_data[:gateway])
21
- provisioned_network[:netmask].should eq(test_data[:netmask])
22
- provisioned_network[:isLinked].should eq('false')
20
+ expect(provisioned_network[:gateway]).to eq(test_data[:gateway])
21
+ expect(provisioned_network[:netmask]).to eq(test_data[:netmask])
22
+ expect(provisioned_network[:isLinked]).to eq('false')
23
23
  end
24
24
 
25
- it 'should create an nat routed network' do
25
+ it 'should create a nat routed network' do
26
26
  test_data = default_test_data('natRouted')
27
- test_data[:edgeGateway] = ENV['VCLOUD_EDGE_GATEWAY'] #only needed for natRouted networks
28
27
  @minimum_data_yaml = generate_data_file(test_data)
29
28
 
30
29
  Vcloud::NetLauncher::NetLaunch.new.run(@minimum_data_yaml)
31
30
 
32
31
  @found_networks = find_network(test_data[:network_name])
33
32
 
34
- @found_networks.length.should eq(1)
33
+ expect(@found_networks.length).to eq(1)
35
34
  provisioned_network = @found_networks[0]
36
- provisioned_network[:gateway].should eq(test_data[:gateway])
37
- provisioned_network[:netmask].should eq(test_data[:netmask])
38
- provisioned_network[:isLinked].should eq('true')
35
+ expect(provisioned_network[:gateway]).to eq(test_data[:gateway])
36
+ expect(provisioned_network[:netmask]).to eq(test_data[:netmask])
37
+ expect(provisioned_network[:isLinked]).to eq('true')
39
38
  end
40
39
 
41
40
  after(:each) do
@@ -43,16 +42,21 @@ module Vcloud
43
42
  File.delete @minimum_data_yaml
44
43
  fog_interface = Vcloud::Fog::ServiceInterface.new
45
44
  provisioned_network_id = @found_networks[0][:href].split('/').last
46
- fog_interface.delete_network(provisioned_network_id).should be(true)
45
+ expect(fog_interface.delete_network(provisioned_network_id)).to be(true)
47
46
  end
48
47
  end
49
48
 
50
49
  end
51
50
 
52
51
  def default_test_data(type)
52
+ config_file = File.join(File.dirname(__FILE__), "../vcloud_tools_testing_config.yaml")
53
+ required_user_params = %w{ vdc_1_name edge_gateway }
54
+
55
+ parameters = Vcloud::Tools::Tester::TestSetup.new(config_file, required_user_params).test_params
53
56
  {
54
57
  network_name: "vapp-vcloud-tools-tests-#{Time.now.strftime('%s')}",
55
- vdc_name: ENV['VCLOUD_VDC_NAME'],
58
+ vdc_name: parameters.vdc_1_name,
59
+ edge_gateway: parameters.edge_gateway,
56
60
  fence_mode: type,
57
61
  netmask: '255.255.255.0',
58
62
  gateway: '192.0.2.1',
@@ -147,13 +147,14 @@ describe Vcloud::Core::OrgVdcNetwork do
147
147
  end
148
148
 
149
149
  def define_test_data
150
- [ 'VCLOUD_VDC_NAME', 'VCLOUD_EDGE_GATEWAY' ].each do |n|
151
- raise "Need #{n} set" unless ENV[n]
152
- end
150
+ config_file = File.join(File.dirname(__FILE__), "../vcloud_tools_testing_config.yaml")
151
+ required_user_params = %w{ vdc_1_name edge_gateway }
152
+
153
+ parameters = Vcloud::Tools::Tester::TestSetup.new(config_file, required_user_params).test_params
153
154
  {
154
155
  :name => "orgVdcNetwork-vcloud-tools-tests #{Time.now.strftime('%s')}",
155
- :vdc_name => ENV['VCLOUD_VDC_NAME'],
156
- :edge_gateway_name => ENV['VCLOUD_EDGE_GATEWAY'],
156
+ :vdc_name => parameters.vdc_1_name,
157
+ :edge_gateway_name => parameters.edge_gateway,
157
158
  }
158
159
  end
159
160
 
@@ -0,0 +1,3 @@
1
+ default:
2
+ vdc_1_name:
3
+ edge_gateway:
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,33 @@
1
+ # SimpleCov must run _first_ according to its README
2
+ if ENV['COVERAGE']
3
+ require 'simplecov'
4
+
5
+ # monkey-patch to prevent SimpleCov from reporting coverage percentage
6
+ class SimpleCov::Formatter::HTMLFormatter
7
+ def output_message(_message)
8
+ nil
9
+ end
10
+ end
11
+
12
+ SimpleCov.adapters.define 'gem' do
13
+ add_filter '/spec/'
14
+ add_filter '/features/'
15
+ add_filter '/vendor/'
16
+
17
+ add_group 'Libraries', '/lib/'
18
+ end
19
+
20
+ SimpleCov.minimum_coverage(100)
21
+ SimpleCov.start 'gem'
22
+ end
23
+
1
24
  require 'erb_helper'
2
25
  require 'bundler/setup'
3
26
  require 'vcloud/net_launcher'
27
+ require 'vcloud/tools/tester'
28
+
29
+ RSpec.configure do |config|
30
+ config.expect_with :rspec do |c|
31
+ c.syntax = :expect
32
+ end
33
+ end
@@ -0,0 +1,153 @@
1
+ require 'spec_helper'
2
+
3
+ class CommandRun
4
+ attr_accessor :stdout, :stderr, :exitstatus
5
+
6
+ def initialize(args)
7
+ out = StringIO.new
8
+ err = StringIO.new
9
+
10
+ $stdout = out
11
+ $stderr = err
12
+
13
+ begin
14
+ Vcloud::NetLauncher::Cli.new(args).run
15
+ @exitstatus = 0
16
+ rescue SystemExit => e
17
+ # Capture exit(n) value.
18
+ @exitstatus = e.status
19
+ end
20
+
21
+ @stdout = out.string.strip
22
+ @stderr = err.string.strip
23
+
24
+ $stdout = STDOUT
25
+ $stderr = STDERR
26
+ end
27
+ end
28
+
29
+ describe Vcloud::NetLauncher::Cli do
30
+ subject { CommandRun.new(args) }
31
+
32
+ let(:mock_net_launch) {
33
+ double(:net_launch, :run => true)
34
+ }
35
+ let(:config_file) { 'config.yaml' }
36
+
37
+ describe "under normal usage" do
38
+ shared_examples "a good CLI command" do
39
+ it "passes the right CLI options and exits normally" do
40
+ expect(Vcloud::NetLauncher::NetLaunch).to receive(:new).
41
+ and_return(mock_net_launch)
42
+ expect(mock_net_launch).to receive(:run).
43
+ with(config_file, cli_options)
44
+ expect(subject.exitstatus).to eq(0)
45
+ end
46
+ end
47
+
48
+ context "when given a single config file" do
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
+
67
+ it_behaves_like "a good CLI command"
68
+ end
69
+
70
+ context "when asked to display version" do
71
+ let(:args) { %w{--version} }
72
+
73
+ it "does not call NetLaunch" do
74
+ expect(Vcloud::NetLauncher::NetLaunch).not_to receive(:new)
75
+ end
76
+
77
+ it "prints version and exits normally" do
78
+ expect(subject.stdout).to eq(Vcloud::NetLauncher::VERSION)
79
+ expect(subject.exitstatus).to eq(0)
80
+ end
81
+ end
82
+
83
+ context "when asked to display help" do
84
+ let(:args) { %w{--help} }
85
+
86
+ it "does not call NetLaunch" do
87
+ expect(Vcloud::NetLauncher::NetLaunch).not_to receive(:new)
88
+ end
89
+
90
+ it "prints usage and exits normally" do
91
+ expect(subject.stderr).to match(/\AUsage: \S+ \[options\] config_file\n/)
92
+ expect(subject.exitstatus).to eq(0)
93
+ end
94
+ end
95
+ end
96
+
97
+ describe "incorrect usage" do
98
+ shared_examples "print usage and exit abnormally" do |error|
99
+ it "does not call NetLaunch" do
100
+ expect(Vcloud::NetLauncher::NetLaunch).not_to receive(:new)
101
+ end
102
+
103
+ it "prints error message and usage" do
104
+ expect(subject.stderr).to match(/\A\S+: #{error}\nUsage: \S+/)
105
+ end
106
+
107
+ it "exits abnormally for incorrect usage" do
108
+ expect(subject.exitstatus).to eq(2)
109
+ end
110
+ end
111
+
112
+ context "when run without any arguments" do
113
+ let(:args) { %w{} }
114
+
115
+ it_behaves_like "print usage and exit abnormally", "must supply config_file"
116
+ end
117
+
118
+ context "when given multiple config files" do
119
+ let(:args) { %w{one.yaml two.yaml} }
120
+
121
+ it_behaves_like "print usage and exit abnormally", "must supply config_file"
122
+ end
123
+
124
+ context "when given an unrecognised argument" do
125
+ let(:args) { %w{--this-is-garbage} }
126
+
127
+ it_behaves_like "print usage and exit abnormally", "invalid option: --this-is-garbage"
128
+ end
129
+ end
130
+
131
+ describe "error handling" do
132
+ context "when underlying code raises an exception" do
133
+ let(:args) { %w{test.yaml} }
134
+
135
+ it "should print error without backtrace and exit abnormally" do
136
+ expect(Vcloud::NetLauncher::NetLaunch).to receive(:new).
137
+ and_raise("something went horribly wrong")
138
+ expect(subject.stderr).to eq("something went horribly wrong")
139
+ expect(subject.exitstatus).to eq(1)
140
+ end
141
+ end
142
+
143
+ context "when passed an non-existent configuration file" do
144
+ let(:args) { %w{non-existent.yaml} }
145
+
146
+ it "raises a descriptive error" do
147
+ # Use a regex match as a workaround to https://bugs.ruby-lang.org/issues/9285
148
+ expect(subject.stderr).to match(/\ANo such file or directory/)
149
+ expect(subject.exitstatus).to eq(1)
150
+ end
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vcloud::NetLauncher do
4
+ context "NetLaunch schema validation" do
5
+ it "validates a legal schema" do
6
+ test_config = {
7
+ :org_vdc_networks => [
8
+ :name => "Valid network",
9
+ :vdc_name => "Some vDC"
10
+ ]
11
+ }
12
+
13
+ validator = Vcloud::Core::ConfigValidator.validate(:base, test_config, Vcloud::NetLauncher::Schema::NET_LAUNCH)
14
+ expect(validator.valid?).to be_true
15
+ expect(validator.errors).to be_empty
16
+ end
17
+
18
+ it "does not validate an illegal schema" do
19
+ test_config = {
20
+ :no_networks_here => {
21
+ :name => "I am not valid"
22
+ }
23
+ }
24
+
25
+ validator = Vcloud::Core::ConfigValidator.validate(:base, test_config, Vcloud::NetLauncher::Schema::NET_LAUNCH)
26
+ expect(validator.valid?).to be_false
27
+ expect(validator.errors).to eq(["base: parameter 'no_networks_here' is invalid", "base: missing 'org_vdc_networks' parameter"])
28
+ end
29
+
30
+ it "allows multiple IP ranges" do
31
+ test_config = {
32
+ :org_vdc_networks => [
33
+ :name => "Valid network",
34
+ :vdc_name => "Some vDC",
35
+ :ip_ranges => [
36
+ {
37
+ :start_address => "192.168.1.2",
38
+ :end_address => "192.168.1.3",
39
+ },
40
+ {
41
+ :start_address => "192.168.1.4",
42
+ :end_address => "192.168.1.5",
43
+ }
44
+ ]
45
+ ]
46
+ }
47
+
48
+ validator = Vcloud::Core::ConfigValidator.validate(:base, test_config, Vcloud::NetLauncher::Schema::NET_LAUNCH)
49
+ expect(validator.valid?).to be_true
50
+ expect(validator.errors).to be_empty
51
+ end
52
+
53
+ it "checks for an end address in an IP address range" do
54
+ test_config = {
55
+ :org_vdc_networks => [
56
+ :name => "Valid network",
57
+ :vdc_name => "Some vDC",
58
+ :ip_ranges => [
59
+ {
60
+ :start_address => "192.168.1.2",
61
+ }
62
+ ]
63
+ ]
64
+ }
65
+
66
+ validator = Vcloud::Core::ConfigValidator.validate(:base, test_config, Vcloud::NetLauncher::Schema::NET_LAUNCH)
67
+ expect(validator.valid?).to be_false
68
+ expect(validator.errors).to eq(["ip_ranges: missing 'end_address' parameter"])
69
+ end
70
+ end
71
+ end
@@ -1,8 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Vcloud::NetLauncher::NetLaunch do
4
+ let(:cli_options) { {} }
5
+
4
6
  context "ConfigLoader returns three different networks" do
5
- let!(:network1) {
7
+ let(:network1) {
6
8
  {
7
9
  :name => 'Network 1',
8
10
  :vdc_name => 'TestVDC',
@@ -12,7 +14,7 @@ describe Vcloud::NetLauncher::NetLaunch do
12
14
  :edge_gateway => 'TestVSE',
13
15
  }
14
16
  }
15
- let!(:network2) {
17
+ let(:network2) {
16
18
  {
17
19
  :name => 'Network 2',
18
20
  :vdc_name => 'TestVDC',
@@ -22,7 +24,7 @@ describe Vcloud::NetLauncher::NetLaunch do
22
24
  :edge_gateway => 'TestVSE',
23
25
  }
24
26
  }
25
- let!(:network3) {
27
+ let(:network3) {
26
28
  {
27
29
  :name => 'Network 3',
28
30
  :vdc_name => 'TestVDC',
@@ -46,7 +48,6 @@ describe Vcloud::NetLauncher::NetLaunch do
46
48
  expect(Vcloud::Core::OrgVdcNetwork).to receive(:provision).with(network2)
47
49
  expect(Vcloud::Core::OrgVdcNetwork).to receive(:provision).with(network3)
48
50
 
49
- cli_options = {}
50
51
  subject.run('input_config_yaml', cli_options)
51
52
  end
52
53
 
@@ -56,7 +57,6 @@ describe Vcloud::NetLauncher::NetLaunch do
56
57
  and_raise(RuntimeError.new('Did not successfully create orgVdcNetwork'))
57
58
  expect(Vcloud::Core::OrgVdcNetwork).not_to receive(:provision).with(network3)
58
59
 
59
- cli_options = {}
60
60
  expect {
61
61
  Vcloud::NetLauncher::NetLaunch.new.run('input_config_yaml', cli_options)
62
62
  }.to raise_error(RuntimeError, 'Did not successfully create orgVdcNetwork')
@@ -67,7 +67,6 @@ describe Vcloud::NetLauncher::NetLaunch do
67
67
  expect(Fog).to_not receive(:mock!)
68
68
  expect(Vcloud::Core::OrgVdcNetwork).to receive(:provision).exactly(3).times
69
69
 
70
- cli_options = {}
71
70
  subject.run('input_config_yaml', cli_options)
72
71
  end
73
72
 
@@ -83,7 +82,7 @@ describe Vcloud::NetLauncher::NetLaunch do
83
82
  end
84
83
 
85
84
  context "ConfigLoader returns one network without :fence_mode set" do
86
- let!(:network_without_fence_mode) {
85
+ let(:network_without_fence_mode) {
87
86
  {
88
87
  :name => 'Network w/o fence_mode',
89
88
  :vdc_name => 'TestVDC',
@@ -106,10 +105,9 @@ describe Vcloud::NetLauncher::NetLaunch do
106
105
  :fence_mode => 'isolated',
107
106
  })
108
107
 
109
- network_without_fence_mode.should_not have_key(:fence_mode)
108
+ expect(network_without_fence_mode).not_to have_key(:fence_mode)
110
109
  expect(Vcloud::Core::OrgVdcNetwork).to receive(:provision).with(network_with_fence_mode)
111
110
 
112
- cli_options = {}
113
111
  subject.run('input_config_yaml', cli_options)
114
112
  end
115
113
  end
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.email = ['anna.shipman@digital.cabinet-office.gov.uk']
13
13
  s.summary = 'Tool to launch and configure vCloud networks'
14
14
  s.description = 'Tool to launch and configure vCloud networks. Uses vcloud-core.'
15
- s.homepage = 'http://github.com/alphagov/vcloud-net_launcher'
15
+ s.homepage = 'http://github.com/gds-operations/vcloud-net_launcher'
16
16
  s.license = 'MIT'
17
17
 
18
18
  s.files = `git ls-files`.split($/)
@@ -20,15 +20,17 @@ Gem::Specification.new do |s|
20
20
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
21
21
  s.require_paths = ['lib']
22
22
 
23
- s.required_ruby_version = '>= 1.9.2'
23
+ s.required_ruby_version = '>= 1.9.3'
24
24
 
25
- s.add_runtime_dependency 'methadone'
26
- s.add_runtime_dependency 'vcloud-core', '~> 0.3.0'
27
- s.add_development_dependency 'aruba', '~> 0.5.3'
28
- s.add_development_dependency 'cucumber', '~> 1.3.10'
25
+ s.add_runtime_dependency 'vcloud-core', '~> 0.6.0'
29
26
  s.add_development_dependency 'gem_publisher', '1.2.0'
27
+ s.add_development_dependency 'pry'
30
28
  s.add_development_dependency 'rake'
31
29
  s.add_development_dependency 'rspec', '~> 2.14.1'
32
- s.add_development_dependency 'rubocop'
30
+ s.add_development_dependency 'rubocop', '~> 0.23.0'
31
+ # Pin SimpleCov to < 0.8.x until this issue is resolved:
32
+ # https://github.com/colszowka/simplecov/issues/281
33
+ s.add_development_dependency 'simplecov', '~> 0.7.1'
34
+ s.add_development_dependency 'vcloud-tools-tester', '~> 0.1.0'
33
35
  end
34
36
 
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.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,112 +9,112 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-14 00:00:00.000000000 Z
12
+ date: 2014-07-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: methadone
15
+ name: vcloud-core
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 0.6.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
29
+ version: 0.6.0
30
30
  - !ruby/object:Gem::Dependency
31
- name: vcloud-core
31
+ name: gem_publisher
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - ~>
35
+ - - '='
36
36
  - !ruby/object:Gem::Version
37
- version: 0.3.0
38
- type: :runtime
37
+ version: 1.2.0
38
+ type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ~>
43
+ - - '='
44
44
  - !ruby/object:Gem::Version
45
- version: 0.3.0
45
+ version: 1.2.0
46
46
  - !ruby/object:Gem::Dependency
47
- name: aruba
47
+ name: pry
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ~>
51
+ - - ! '>='
52
52
  - !ruby/object:Gem::Version
53
- version: 0.5.3
53
+ version: '0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - ~>
59
+ - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
- version: 0.5.3
61
+ version: '0'
62
62
  - !ruby/object:Gem::Dependency
63
- name: cucumber
63
+ name: rake
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
- - - ~>
67
+ - - ! '>='
68
68
  - !ruby/object:Gem::Version
69
- version: 1.3.10
69
+ version: '0'
70
70
  type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
- - - ~>
75
+ - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
- version: 1.3.10
77
+ version: '0'
78
78
  - !ruby/object:Gem::Dependency
79
- name: gem_publisher
79
+ name: rspec
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
- - - '='
83
+ - - ~>
84
84
  - !ruby/object:Gem::Version
85
- version: 1.2.0
85
+ version: 2.14.1
86
86
  type: :development
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
91
- - - '='
91
+ - - ~>
92
92
  - !ruby/object:Gem::Version
93
- version: 1.2.0
93
+ version: 2.14.1
94
94
  - !ruby/object:Gem::Dependency
95
- name: rake
95
+ name: rubocop
96
96
  requirement: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
- - - ! '>='
99
+ - - ~>
100
100
  - !ruby/object:Gem::Version
101
- version: '0'
101
+ version: 0.23.0
102
102
  type: :development
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
- - - ! '>='
107
+ - - ~>
108
108
  - !ruby/object:Gem::Version
109
- version: '0'
109
+ version: 0.23.0
110
110
  - !ruby/object:Gem::Dependency
111
- name: rspec
111
+ name: simplecov
112
112
  requirement: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements:
115
115
  - - ~>
116
116
  - !ruby/object:Gem::Version
117
- version: 2.14.1
117
+ version: 0.7.1
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
@@ -122,23 +122,23 @@ dependencies:
122
122
  requirements:
123
123
  - - ~>
124
124
  - !ruby/object:Gem::Version
125
- version: 2.14.1
125
+ version: 0.7.1
126
126
  - !ruby/object:Gem::Dependency
127
- name: rubocop
127
+ name: vcloud-tools-tester
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  none: false
130
130
  requirements:
131
- - - ! '>='
131
+ - - ~>
132
132
  - !ruby/object:Gem::Version
133
- version: '0'
133
+ version: 0.1.0
134
134
  type: :development
135
135
  prerelease: false
136
136
  version_requirements: !ruby/object:Gem::Requirement
137
137
  none: false
138
138
  requirements:
139
- - - ! '>='
139
+ - - ~>
140
140
  - !ruby/object:Gem::Version
141
- version: '0'
141
+ version: 0.1.0
142
142
  description: Tool to launch and configure vCloud networks. Uses vcloud-core.
143
143
  email:
144
144
  - anna.shipman@digital.cabinet-office.gov.uk
@@ -150,30 +150,34 @@ files:
150
150
  - .gitignore
151
151
  - .travis.yml
152
152
  - CHANGELOG.md
153
+ - CONTRIBUTING.md
153
154
  - Gemfile
154
155
  - LICENSE.txt
155
156
  - README.md
156
157
  - Rakefile
157
158
  - bin/vcloud-net-launch
158
159
  - examples/vcloud-net-launch/example-config.yaml
159
- - features/step_definitions/vcloud-launch_steps.rb
160
- - features/support/env.rb
161
- - features/vcloud-net-launch.feature
162
160
  - jenkins.sh
163
161
  - jenkins_integration_tests.sh
164
162
  - lib/vcloud/net_launcher.rb
163
+ - lib/vcloud/net_launcher/cli.rb
165
164
  - lib/vcloud/net_launcher/net_launch.rb
165
+ - lib/vcloud/net_launcher/schema/net_launch.rb
166
166
  - lib/vcloud/net_launcher/version.rb
167
167
  - scripts/basic.erb
168
168
  - spec/erb_helper.rb
169
+ - spec/integration/README.md
169
170
  - spec/integration/net_launcher/data/minimum_data_setup.yaml.erb
171
+ - spec/integration/net_launcher/net_launch_spec.rb
170
172
  - spec/integration/net_launcher/org_vdc_network_spec.rb
171
- - spec/integration/net_launcher/vcloud_net_launcher_spec.rb
173
+ - spec/integration/vcloud_tools_testing_config.yaml.template
172
174
  - spec/spec_helper.rb
175
+ - spec/vcloud/net_launcher/cli_spec.rb
176
+ - spec/vcloud/net_launcher/net_launch_schema_spec.rb
173
177
  - spec/vcloud/net_launcher/net_launch_spec.rb
174
178
  - tools/fog_credentials.rb
175
179
  - vcloud-net_launcher.gemspec
176
- homepage: http://github.com/alphagov/vcloud-net_launcher
180
+ homepage: http://github.com/gds-operations/vcloud-net_launcher
177
181
  licenses:
178
182
  - MIT
179
183
  post_install_message:
@@ -185,7 +189,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
189
  requirements:
186
190
  - - ! '>='
187
191
  - !ruby/object:Gem::Version
188
- version: 1.9.2
192
+ version: 1.9.3
189
193
  required_rubygems_version: !ruby/object:Gem::Requirement
190
194
  none: false
191
195
  requirements:
@@ -194,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
198
  version: '0'
195
199
  segments:
196
200
  - 0
197
- hash: -3237069924497883805
201
+ hash: 3723490288944592179
198
202
  requirements: []
199
203
  rubyforge_project:
200
204
  rubygems_version: 1.8.23
@@ -202,12 +206,13 @@ signing_key:
202
206
  specification_version: 3
203
207
  summary: Tool to launch and configure vCloud networks
204
208
  test_files:
205
- - features/step_definitions/vcloud-launch_steps.rb
206
- - features/support/env.rb
207
- - features/vcloud-net-launch.feature
208
209
  - spec/erb_helper.rb
210
+ - spec/integration/README.md
209
211
  - spec/integration/net_launcher/data/minimum_data_setup.yaml.erb
212
+ - spec/integration/net_launcher/net_launch_spec.rb
210
213
  - spec/integration/net_launcher/org_vdc_network_spec.rb
211
- - spec/integration/net_launcher/vcloud_net_launcher_spec.rb
214
+ - spec/integration/vcloud_tools_testing_config.yaml.template
212
215
  - spec/spec_helper.rb
216
+ - spec/vcloud/net_launcher/cli_spec.rb
217
+ - spec/vcloud/net_launcher/net_launch_schema_spec.rb
213
218
  - spec/vcloud/net_launcher/net_launch_spec.rb
@@ -1,3 +0,0 @@
1
- Then(/^the banner should document that this app takes (\d+) argument$/) do
2
- pending # express the regexp above with the code you wish you had
3
- end
@@ -1,16 +0,0 @@
1
- require 'aruba/cucumber'
2
- require 'methadone/cucumber'
3
-
4
- ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
5
- LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
6
-
7
- Before do
8
- # Using "announce" causes massive warnings on 1.9.2
9
- @puts = true
10
- @original_rubylib = ENV['RUBYLIB']
11
- ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
12
- end
13
-
14
- After do
15
- ENV['RUBYLIB'] = @original_rubylib
16
- end
@@ -1,15 +0,0 @@
1
- Feature: "vcloud-net-launch" works as a useful command-line tool
2
- In order to use "vcloud-net-launch" from the CLI
3
- I want to have it behave like a typical Unix tool
4
- So I don't get surpised
5
-
6
- Scenario: Common arguments work
7
- When I get help for "vcloud-net-launch"
8
- Then the exit status should be 0
9
- And the banner should be present
10
- And the banner should document that this app takes options
11
- And the following options should be documented:
12
- |--version|
13
- |--mock|
14
- And the banner should document that this app's arguments are:
15
- |net_config_file|