vagrant-skytap 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/vagrant-skytap/action/compose_environment.rb +14 -9
- data/lib/vagrant-skytap/api/client.rb +5 -1
- data/lib/vagrant-skytap/version.rb +1 -1
- data/spec/unit/actions/compose_environment_spec.rb +72 -8
- data/spec/unit/api_client_spec.rb +44 -0
- data/spec/unit/support/shared/rest_api_context.rb +9 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba60765d51a7600c51ba087d57506e1f469c03dc
|
4
|
+
data.tar.gz: 1629dbd77eede4f26f948f1ed65e1e24416ac3ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8516f76818cee5c9cb7cebcc9a01b91a94f4be9de223bc21d8b48eb1e6385c0f233e8d4b2daf37e649aa0352069eef227e5c6f1f80896cc790c7d86819843b4
|
7
|
+
data.tar.gz: 701d24018b94c72f42c95d7829285ed60004cb2ddf111a063d02d907853c198948ab043fe2a50d0bc0702c29ae28f762af837e88a6eef23cce314fce48d08a6f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# 0.2.7 (February 19, 2016)
|
2
|
+
|
3
|
+
* Add User-Agent string with the plugin version and Vagrant version.
|
4
|
+
|
5
|
+
* Fix bug which coud cause machines to be mapped to the wrong VMs.
|
6
|
+
|
1
7
|
# 0.2.6 (February 16, 2016)
|
2
8
|
|
3
9
|
* Changes to support logging in to base boxes with the default `vagrant` user and
|
@@ -20,7 +20,6 @@
|
|
20
20
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
21
21
|
# DEALINGS IN THE SOFTWARE.
|
22
22
|
|
23
|
-
require 'log4r'
|
24
23
|
require 'vagrant-skytap/api/environment'
|
25
24
|
require 'vagrant-skytap/api/vm'
|
26
25
|
|
@@ -70,6 +69,7 @@ module VagrantPlugins
|
|
70
69
|
# @return [API::Environment] The new or existing environment
|
71
70
|
def add_vms(environment, machines)
|
72
71
|
source_vms_map = fetch_source_vms(machines)
|
72
|
+
names_to_vm_ids = {}
|
73
73
|
|
74
74
|
get_groupings(source_vms_map, parallel: @env[:parallel]).each do |names|
|
75
75
|
vms_for_pass = names.collect{|name| source_vms_map[name]}
|
@@ -84,9 +84,11 @@ module VagrantPlugins
|
|
84
84
|
vms = environment.add_vms(vms_for_pass)
|
85
85
|
end
|
86
86
|
|
87
|
-
|
88
|
-
|
89
|
-
|
87
|
+
vms.each_with_index {|vm, i| names_to_vm_ids[names[i]] = vm.id }
|
88
|
+
end
|
89
|
+
|
90
|
+
machines.each do |machine|
|
91
|
+
machine.id = names_to_vm_ids[machine.name]
|
90
92
|
end
|
91
93
|
|
92
94
|
environment
|
@@ -129,15 +131,18 @@ module VagrantPlugins
|
|
129
131
|
acc
|
130
132
|
end.values
|
131
133
|
|
132
|
-
# If the same source VM appears more than once, the API
|
133
|
-
# requires us to make multiple calls. For simplicity,
|
134
|
-
# if a particular grouping includes such, just create a single
|
135
|
-
# call for each vm in the group. (Could be optimized further)
|
136
134
|
groupings2 = []
|
137
135
|
groupings.each_with_index do |grouping, i|
|
138
136
|
if grouping.values.uniq.count == grouping.values.count
|
139
|
-
|
137
|
+
# The new VMs in the API response will be sorted
|
138
|
+
# by the source VM ids. Sort the machines within
|
139
|
+
# each group to match.
|
140
|
+
groupings2 << grouping.invert.sort.collect(&:last)
|
140
141
|
else
|
142
|
+
# If the same source VM appears more than once in a
|
143
|
+
# group, we have to make multiple API calls. For
|
144
|
+
# simplicity, handle this case by creating a single
|
145
|
+
# group for each machine.
|
141
146
|
groupings2.concat(grouping.keys.map{|v| [v]})
|
142
147
|
end
|
143
148
|
end
|
@@ -129,12 +129,16 @@ module VagrantPlugins
|
|
129
129
|
|
130
130
|
private
|
131
131
|
|
132
|
+
def user_agent_string
|
133
|
+
"Vagrant-Skytap/#{VERSION} Vagrant/#{Vagrant::VERSION}"
|
134
|
+
end
|
132
135
|
|
133
136
|
def default_headers
|
134
137
|
{
|
135
138
|
'Authorization' => auth_header,
|
136
139
|
'Content-Type' => 'application/json',
|
137
|
-
'Accept' => 'application/json'
|
140
|
+
'Accept' => 'application/json',
|
141
|
+
'User-Agent' => user_agent_string,
|
138
142
|
}
|
139
143
|
end
|
140
144
|
|
@@ -25,29 +25,45 @@ require File.expand_path("../../base", __FILE__)
|
|
25
25
|
describe VagrantPlugins::Skytap::Action::ComposeEnvironment do
|
26
26
|
include_context "rest_api"
|
27
27
|
|
28
|
+
let(:json_path) { File.join(File.expand_path('../..', __FILE__), 'support', 'api_responses') }
|
29
|
+
let(:vm1_attrs) { read_json(json_path, 'vm1.json').merge("id" => "1") }
|
30
|
+
let(:vm2_attrs) { vm1_attrs.merge("id" => "2") }
|
31
|
+
let(:environment_attrs) { read_json(json_path, 'empty_environment.json').merge('vms' => [vm1_attrs]) }
|
32
|
+
|
28
33
|
let(:app) { lambda { |env| } }
|
29
|
-
let(:env) { { machine: machine, machines:
|
34
|
+
let(:env) { { machine: machine, machines: machines, ui: ui, api_client: api_client, parallel: true } }
|
30
35
|
let(:provider_config) do
|
31
36
|
double(:provider_config, vm_url: "/vms/1", username: "jsmith", api_token: "123123", base_url: base_url)
|
32
37
|
end
|
33
38
|
let(:api_client) { API::Client.new(provider_config) }
|
34
39
|
|
35
40
|
let(:machine) { double(:machine, name: "vm1", id: nil, :id= => nil, provider_config: provider_config) }
|
36
|
-
let(:existing_machine) { double(:existing_machine, name: "vm2", id: 2) }
|
41
|
+
let(:existing_machine) { double(:existing_machine, name: "vm2", id: "2") }
|
42
|
+
let(:machines) { [machine] }
|
37
43
|
|
38
44
|
let(:environment) { double(:environment, url: "foo") }
|
39
45
|
let(:new_environment) { double(:environment, url: "foo", vms: [vm], properties: environment_properties) }
|
40
|
-
let(:vm) { double(:vm, id: 1, parent_url: "https://example.com/templates/1") }
|
46
|
+
let(:vm) { double(:vm, id: "1", parent_url: "https://example.com/templates/1", :stopped? => true) }
|
41
47
|
|
42
48
|
let(:environment_properties) { double(:environment_properties, read: nil, write: nil) }
|
43
49
|
|
44
|
-
let(:
|
50
|
+
let(:instance) { described_class.new(app, env) }
|
45
51
|
|
52
|
+
let(:get_vm_attrs) { vm1_attrs }
|
53
|
+
let(:post_config_attrs) { environment_attrs }
|
54
|
+
let(:put_config_attrs) { environment_attrs }
|
46
55
|
before do
|
47
|
-
|
56
|
+
allow_any_instance_of(API::Environment).to receive(:properties).and_return(environment_properties)
|
57
|
+
env[:environment] = environment
|
58
|
+
|
59
|
+
stub_get(%r{/vms/\d+}, get_vm_attrs)
|
60
|
+
stub_post(%r{/configurations$}, post_config_attrs)
|
61
|
+
stub_put(%r{/configurations/\d+}, put_config_attrs)
|
48
62
|
end
|
49
63
|
|
50
64
|
describe "#call" do
|
65
|
+
subject {instance}
|
66
|
+
|
51
67
|
it "does nothing if all machines exist" do
|
52
68
|
machine.stub(id: 1)
|
53
69
|
expect(app).to receive(:call).with(env)
|
@@ -59,7 +75,7 @@ describe VagrantPlugins::Skytap::Action::ComposeEnvironment do
|
|
59
75
|
subject.call(env)
|
60
76
|
end
|
61
77
|
|
62
|
-
it "makes a single create! call when creating an environment with 1 machine"
|
78
|
+
it "makes a single create! call when creating an environment with 1 machine" do
|
63
79
|
myenv = env.merge(environment: nil)
|
64
80
|
expect(app).to receive(:call).with(myenv)
|
65
81
|
|
@@ -82,7 +98,49 @@ describe VagrantPlugins::Skytap::Action::ComposeEnvironment do
|
|
82
98
|
end
|
83
99
|
end
|
84
100
|
|
101
|
+
describe "add_vms" do
|
102
|
+
subject {instance}
|
103
|
+
|
104
|
+
before do
|
105
|
+
stub_get(%r{/vms/1}, vm1_attrs)
|
106
|
+
stub_get(%r{/vms/2}, vm2_attrs)
|
107
|
+
# Hack so the region mismatch check always passes
|
108
|
+
stub_get(%r{/templates/\d+}, {"region" => environment_attrs["region"]})
|
109
|
+
end
|
110
|
+
|
111
|
+
context "when creating an environment from 2 vms with the same parent" do
|
112
|
+
let(:post_config_attrs) do
|
113
|
+
environment_attrs.merge('vms' => [vm1_attrs, vm2_attrs])
|
114
|
+
end
|
115
|
+
|
116
|
+
let(:provider_config2) do
|
117
|
+
double(:provider_config2, vm_url: "/vms/2", username: "jsmith", api_token: "123123", base_url: base_url)
|
118
|
+
end
|
119
|
+
let(:machine2) do
|
120
|
+
double(:machine2, name: "vm2", id: nil, :id= => nil, provider_config: provider_config2)
|
121
|
+
end
|
122
|
+
|
123
|
+
context "when machines are ordered by vm_id" do
|
124
|
+
it "maps the machines to the correct vms" do
|
125
|
+
expect(machine).to receive(:id=).with("1")
|
126
|
+
expect(machine2).to receive(:id=).with("2")
|
127
|
+
subject.add_vms(nil, [machine, machine2])
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context "when machines are not ordered by vm_id" do
|
132
|
+
it "maps the machines to the correct vms" do
|
133
|
+
expect(machine).to receive(:id=).with("1")
|
134
|
+
expect(machine2).to receive(:id=).with("2")
|
135
|
+
subject.add_vms(nil, [machine2, machine])
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
85
141
|
describe "fetch_source_vms" do
|
142
|
+
subject {instance}
|
143
|
+
|
86
144
|
it "fetches a vm and returns a mapping" do
|
87
145
|
vms = subject.fetch_source_vms([machine])
|
88
146
|
expect(a_request(:get, %r{/vms/\d+$})).to have_been_made.once
|
@@ -93,8 +151,10 @@ describe VagrantPlugins::Skytap::Action::ComposeEnvironment do
|
|
93
151
|
end
|
94
152
|
|
95
153
|
describe "get_groupings" do
|
96
|
-
let(:vm_in_same_template) { double(:vm_in_same_template, id: 2, parent_url: "https://example.com/templates/1")}
|
97
|
-
let(:vm_in_different_template) { double(:vm_in_different_template, id: 3, parent_url: "https://example.com/templates/2")}
|
154
|
+
let(:vm_in_same_template) { double(:vm_in_same_template, id: "2", parent_url: "https://example.com/templates/1")}
|
155
|
+
let(:vm_in_different_template) { double(:vm_in_different_template, id: "3", parent_url: "https://example.com/templates/2")}
|
156
|
+
|
157
|
+
subject {instance}
|
98
158
|
|
99
159
|
it "returns a single group for a single vm" do
|
100
160
|
expect(subject.get_groupings({"vm1" => vm})).to eq([ ["vm1"] ])
|
@@ -116,5 +176,9 @@ describe VagrantPlugins::Skytap::Action::ComposeEnvironment do
|
|
116
176
|
it "respects parallel flag" do
|
117
177
|
expect(subject.get_groupings({"vm1" => vm, "vm2" => vm_in_same_template}, parallel: false)).to eq([ ["vm1"], ["vm2"] ])
|
118
178
|
end
|
179
|
+
|
180
|
+
it "sorts machines in group by vm id" do
|
181
|
+
expect(subject.get_groupings({"vm1" => vm_in_same_template, "vm2" => vm})).to eq([ ["vm2", "vm1"] ])
|
182
|
+
end
|
119
183
|
end
|
120
184
|
end
|
@@ -0,0 +1,44 @@
|
|
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_relative 'base'
|
24
|
+
require "vagrant-skytap/api/client"
|
25
|
+
|
26
|
+
describe VagrantPlugins::Skytap::API::Client do
|
27
|
+
include_context "rest_api"
|
28
|
+
|
29
|
+
let(:provider_config) do
|
30
|
+
double(:provider_config, vm_url: "/vms/1", username: "jsmith", api_token: "123123", base_url: base_url)
|
31
|
+
end
|
32
|
+
let(:instance) { described_class.new(provider_config) }
|
33
|
+
|
34
|
+
before :each do
|
35
|
+
stub_request(:get, /.*/).to_return(body: "{}", status: 200)
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "user_agent_string" do
|
39
|
+
subject do
|
40
|
+
instance.send(:user_agent_string)
|
41
|
+
end
|
42
|
+
it {should match %r{^Vagrant-Skytap/.* Vagrant/.*}}
|
43
|
+
end
|
44
|
+
end
|
@@ -36,4 +36,13 @@ shared_context "rest_api" do
|
|
36
36
|
|
37
37
|
let(:base_url) {"http://example.com/"}
|
38
38
|
|
39
|
+
%i[get post put delete].each do |verb|
|
40
|
+
define_method("stub_#{verb}") do |url_matcher, response_attrs = nil|
|
41
|
+
stub_request(verb, url_matcher).to_return(body: JSON.dump(response_attrs), status: 200)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
before do
|
46
|
+
stub_request(:any, /.*/).to_return(body: "{}", status: 200)
|
47
|
+
end
|
39
48
|
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.2.
|
4
|
+
version: 0.2.7
|
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-02-
|
12
|
+
date: 2016-02-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json_pure
|
@@ -214,6 +214,7 @@ files:
|
|
214
214
|
- spec/spec_helper.rb
|
215
215
|
- spec/unit/actions/compose_environment_spec.rb
|
216
216
|
- spec/unit/actions/update_hardware_spec.rb
|
217
|
+
- spec/unit/api_client_spec.rb
|
217
218
|
- spec/unit/base.rb
|
218
219
|
- spec/unit/config_spec.rb
|
219
220
|
- spec/unit/credentials_spec.rb
|