vagrant-skytap 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a5a789108c848d82077b5a1d094a784603116ef
4
- data.tar.gz: abf71c4beeec288a9d6332dce9c788ef0f9cb957
3
+ metadata.gz: dae76ca9f326fc61d315aed14516cb4d62a03276
4
+ data.tar.gz: c26500f1f04d28b9325f3487369ea89106788437
5
5
  SHA512:
6
- metadata.gz: e90ed82be35afc441c0b84a7c270ad30d36ceb5a2010538df3b9fd800bf8cd8fdec755c2f035f34d3ac0a58cf12364c6c8ca1964ba340ef4581c51afcea02319
7
- data.tar.gz: f3a501db191b0fca564b7401e936854221f0adc77342cc0d153b851e56026204916d20bbe79dbb4ce4075a57410523007e7921a34184f39136e00b7328e67eda
6
+ metadata.gz: 1fc8c6e878f55c34c81e6475ad67dbd3a3c759c28eeb9ca678b1db2e8599061d79263787837fdc9217c2eff6bf738c2dd5d26d8c03a6b0c0d7ff3555110030ae
7
+ data.tar.gz: afa804091a15ffda3cf6478ef6def6d5527fb958dc7daf908109265f347f4c707792aa9a2cea147e046d3630cb3cfe7a537d2f7f27d8bd846ddaa7f7beb15459
data/.gitignore CHANGED
@@ -13,8 +13,7 @@ Gemfile.lock
13
13
 
14
14
  # Vagrant
15
15
  .vagrant
16
- Vagrantfile
17
- !example_box/Vagrantfile
16
+ /Vagrantfile
18
17
 
19
18
  # RVM files for gemset/ruby setting
20
19
  .ruby-*
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.3.1 (April 15, 2016)
2
+
3
+ * Add support for running in a Skytap VM when the VM's network is using a custom DNS.
4
+
1
5
  # 0.3.0 (April 13, 2016)
2
6
 
3
7
  * New functionality to support running Vagrant from within a Skytap VM. The connection between host and
data/boxes/Vagrantfile ADDED
@@ -0,0 +1,8 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure(2) do |config|
5
+ config.vm.provider :skytap do |skytap|
6
+ skytap.vm_url = "https://cloud.skytap.com/vms/3157858"
7
+ end
8
+ end
@@ -22,22 +22,63 @@
22
22
 
23
23
  require "socket"
24
24
  require "net/http"
25
+ require "log4r"
25
26
 
26
27
  module VagrantPlugins
27
28
  module Skytap
28
29
  module Cap
29
30
  module HostMetadata
31
+ METADATA_LINK_LOCAL_ADDRESS = '169.254.169.254'
32
+ OPEN_TIMEOUT = 2
33
+ READ_TIMEOUT = 5
30
34
 
31
- # Attempt to retrieve information about the Vagrant host
32
- # from the metadata service. If found, we're running in a
33
- # Skytap VM.
35
+ # If Vagrant is running in a Skytap VM, returns metadata from which an
36
+ # [API::Vm] can be constructed. Otherwise returns nil.
37
+ #
38
+ # @param [Vagrant::Machine] machine The guest machine (ignored).
39
+ # @return [Hash] or [NilClass]
34
40
  def self.host_metadata(machine)
35
- begin
36
- http = Net::HTTP.new("gw", 80)
37
- response = http.request(Net::HTTP::Get.new("/skytap"))
38
- JSON.parse(response.body) if response.is_a?(Net::HTTPOK)
39
- rescue SocketError, Net::HTTPNotFound => ex
41
+ logger = Log4r::Logger.new("vagrant_skytap::cap::host_metadata")
42
+
43
+ # There are two addresses to try for the metadata service. If using
44
+ # the default DNS, 'gw' will resolve to the endpoint address. If
45
+ # using custom DNS, be prepared to fall back to the hard-coded IP
46
+ # address.
47
+ ['gw', METADATA_LINK_LOCAL_ADDRESS].each do |host|
48
+ begin
49
+ http = Net::HTTP.new(host)
50
+ http.open_timeout = OPEN_TIMEOUT
51
+ http.read_timeout = READ_TIMEOUT
52
+
53
+ # Test for a working web server before actually hitting the
54
+ # metadata service. The response is expected to be 404.
55
+ http.request(Net::HTTP::Get.new("/"))
56
+
57
+ begin
58
+ response = http.request(Net::HTTP::Get.new("/skytap"))
59
+ rescue Timeout::Error => ex
60
+ raise Errors::MetadataServiceUnavailable
61
+ end
62
+
63
+ if response.is_a?(Net::HTTPServerError)
64
+ raise Errors::MetadataServiceUnavailable
65
+ elsif response.is_a?(Net::HTTPOK)
66
+ attrs = JSON.parse(response.body)
67
+ return attrs if attrs.key?('configuration_url')
68
+ logger.debug("The JSON retrieved was not VM metadata! Ignoring.")
69
+ end
70
+ rescue SocketError => ex
71
+ logger.debug("Could not resolve hostname '#{host}'.")
72
+ rescue Errno::ENETUNREACH => ex
73
+ logger.debug("No route exists for '#{host}'.")
74
+ rescue Timeout::Error => ex
75
+ logger.debug("Response timed out for '#{host}'.")
76
+ rescue JSON::ParserError
77
+ logger.debug("Response from '#{host}' was garbled.")
78
+ end
40
79
  end
80
+
81
+ nil
41
82
  end
42
83
  end
43
84
  end
@@ -100,6 +100,10 @@ module VagrantPlugins
100
100
  class VmParentMismatch < VagrantSkytapError
101
101
  error_key(:vm_parent_mismatch)
102
102
  end
103
+
104
+ class MetadataServiceUnavailable < VagrantSkytapError
105
+ error_key(:metadata_service_unavailable)
106
+ end
103
107
  end
104
108
  end
105
109
  end
@@ -22,6 +22,6 @@
22
22
 
23
23
  module VagrantPlugins
24
24
  module Skytap
25
- VERSION = "0.3.0"
25
+ VERSION = "0.3.1"
26
26
  end
27
27
  end
data/locales/en.yml CHANGED
@@ -121,6 +121,10 @@ en:
121
121
  feature_not_supported_for_host_os: |-
122
122
  The %{feature_name} feature is currently not supported for your host operating system.
123
123
 
124
+ metadata_service_unavailable: |-
125
+ You appear to be running Vagrant in a Skytap VM. There was an error retrieving
126
+ information about this VM. Please retry later.
127
+
124
128
  states:
125
129
  short_not_created: |-
126
130
  not created
@@ -0,0 +1,25 @@
1
+ # Copyright (c) 2014-2016 Skytap, Inc.
2
+ #
3
+ # The MIT License (MIT)
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
+ # DEALINGS IN THE SOFTWARE.
22
+
23
+ require "vagrant-spec/acceptance"
24
+ require_relative "shared/context_skytap"
25
+
@@ -0,0 +1,25 @@
1
+ # Copyright (c) 2014-2016 Skytap, Inc.
2
+ #
3
+ # The MIT License (MIT)
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
+ # DEALINGS IN THE SOFTWARE.
22
+
23
+ shared_context "provider-context/skytap" do
24
+
25
+ end
@@ -0,0 +1,3 @@
1
+ Vagrant.configure("2") do |config|
2
+ config.vm.box = "skytap/ubuntu-1204-x64-us-west"
3
+ end
@@ -24,20 +24,99 @@ require File.expand_path("../../base", __FILE__)
24
24
  require "vagrant-skytap/cap/host_metadata"
25
25
 
26
26
  describe VagrantPlugins::Skytap::Cap::HostMetadata do
27
- let(:machine) { double("machine") }
27
+ include_context "skytap"
28
+
29
+ let(:machine) { double(:machine) }
30
+ let(:metadata) { {"id" => 1, "configuration_url" => "foo"} }
31
+ let(:metadata1) { metadata }
32
+ let(:metadata2) { metadata }
33
+ let(:status) { 200 }
34
+ let(:status1) { status }
35
+ let(:status2) { status }
28
36
 
29
37
  before do
30
- stub_request(:get, %r{http://gw/skytap}).to_return(body: '', status: 404)
38
+ stub_request(:any, /.*/).to_return(body: "", status: 404)
39
+ stub_request(:get, "http://gw/skytap").to_return(body: JSON.dump(metadata1), status: status1)
40
+ stub_request(:get, "http://169.254.169.254/skytap").to_return(body: JSON.dump(metadata2), status: status2)
41
+ end
42
+
43
+ def assert_fallback_to_ip
44
+ expect(a_request(:get, "http://169.254.169.254/")).to have_been_made
45
+ end
46
+
47
+ def assert_no_fallback_to_ip
48
+ expect(a_request(:get, "http://169.254.169.254/")).not_to have_been_made
31
49
  end
32
50
 
33
51
  describe "host_metadata" do
34
- it "returns nil if the metadata is not found" do
35
- expect(described_class.host_metadata(machine)).to be nil
52
+ subject do
53
+ described_class.host_metadata(machine)
54
+ end
55
+
56
+ context "when default DNS is in use" do
57
+ it "should get the metadata from gw" do
58
+ expect(subject).to eq metadata
59
+ assert_no_fallback_to_ip
60
+ end
61
+
62
+ context "when metadata service is down" do
63
+ before do
64
+ stub_request(:get, "http://gw/skytap").to_timeout
65
+ end
66
+ it "should raise an exception without retrying" do
67
+ expect{subject}.to raise_error(Errors::MetadataServiceUnavailable)
68
+ assert_no_fallback_to_ip
69
+ end
70
+ end
71
+
72
+ context "when metadata service returns an error" do
73
+ let(:status1) { 500 }
74
+ it "should raise an exception without retrying" do
75
+ expect{subject}.to raise_error(Errors::MetadataServiceUnavailable)
76
+ assert_no_fallback_to_ip
77
+ end
78
+ end
36
79
  end
37
80
 
38
- it "returns the metadata if found" do
39
- stub_request(:get, %r{http://gw/skytap}).to_return(body: '{"id": 1}', status: 200)
40
- expect(described_class.host_metadata(machine)).to eq({"id" => 1})
81
+ context "when custom DNS is in use" do
82
+ context "when gw resolves to some random web server" do
83
+ let(:metadata1) { 'hello' }
84
+ it "should fall back to the fixed IP address" do
85
+ expect(subject).to eq metadata
86
+ assert_fallback_to_ip
87
+ end
88
+ end
89
+
90
+ context "when gw times out" do
91
+ before do
92
+ stub_request(:get, "http://gw/").to_timeout
93
+ end
94
+ it "should fall back to the fixed IP address" do
95
+ expect(subject).to eq metadata
96
+ assert_fallback_to_ip
97
+ end
98
+ end
99
+
100
+ context "when gw cannot be resolved" do
101
+ before do
102
+ stub_request(:get, "http://gw/").to_raise(SocketError)
103
+ end
104
+ it "should fall back to the fixed IP address" do
105
+ expect(subject).to eq metadata
106
+ assert_fallback_to_ip
107
+ end
108
+
109
+ # Or maybe this isn't a Skytap VM.
110
+ context "when fixed IP address is unreachable" do
111
+ before do
112
+ stub_request(:get, "http://169.254.169.254/").to_raise(Errno::ENETUNREACH)
113
+ end
114
+ it "should return nil" do
115
+ expect(subject).to eq nil
116
+ assert_fallback_to_ip
117
+ end
118
+ end
119
+ end
41
120
  end
42
121
  end
43
122
  end
@@ -0,0 +1,10 @@
1
+ require_relative "spec/acceptance/base"
2
+
3
+ Vagrant::Spec::Acceptance.configure do |c|
4
+ c.component_paths << File.expand_path("../spec/acceptance", __FILE__)
5
+ c.skeleton_paths << File.expand_path("../spec/acceptance/skeletons", __FILE__)
6
+
7
+ c.provider "skytap",
8
+ box: File.expand_path("../skytap-test.box", __FILE__),
9
+ contexts: ["provider-context/skytap"]
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-skytap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric True
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-04-14 00:00:00.000000000 Z
12
+ date: 2016-04-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json_pure
@@ -120,6 +120,7 @@ files:
120
120
  - boxes/empty.box
121
121
  - boxes/metadata.json
122
122
  - boxes/README.md
123
+ - boxes/Vagrantfile
123
124
  - CHANGELOG.md
124
125
  - Gemfile
125
126
  - lib/vagrant-skytap/action/action_helpers.rb
@@ -222,6 +223,9 @@ files:
222
223
  - locales/en.yml
223
224
  - Rakefile
224
225
  - README.md
226
+ - spec/acceptance/base.rb
227
+ - spec/acceptance/shared/context_skytap.rb
228
+ - spec/acceptance/skeletons/generic/Vagrantfile
225
229
  - spec/spec_helper.rb
226
230
  - spec/unit/actions/compose_environment_spec.rb
227
231
  - spec/unit/actions/prepare_nfs_settings_spec.rb
@@ -268,6 +272,7 @@ files:
268
272
  - tasks/bundler.rake
269
273
  - tasks/test.rake
270
274
  - vagrant-skytap.gemspec
275
+ - vagrant-spec.config.rb
271
276
  - .gitignore
272
277
  homepage: http://www.skytap.com
273
278
  licenses: