vagrant-skytap 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,7 @@
1
1
  require_relative 'base'
2
2
  require "vagrant-skytap/api/environment"
3
+ require "vagrant-skytap/api/vm"
4
+ require "vagrant-skytap/errors"
3
5
 
4
6
  describe VagrantPlugins::Skytap::API::Environment do
5
7
  include_context "unit"
@@ -7,13 +9,17 @@ describe VagrantPlugins::Skytap::API::Environment do
7
9
 
8
10
  let(:vm1_attrs) { JSON.load(File.read(File.join(File.expand_path('..', __FILE__), 'skeletons', 'vm1.json'))) }
9
11
  let(:vm2_attrs) { vm1_attrs.merge("id" => "6981851", "name" => "VM2") }
12
+ let(:config_vm_attrs) { vm1_attrs.merge("configuration_url" => "https://example.com/configurations/5570024", "template_url" => nil) }
10
13
  let(:network1_attrs) { JSON.load(File.read(File.join(File.expand_path('..', __FILE__), 'skeletons', 'network1.json'))) }
14
+ let(:vpn_attachment1_attrs) { JSON.load(File.read(File.join(File.expand_path('..', __FILE__), 'skeletons', 'vpn_attachment1.json'))) }
11
15
  let(:empty_environment_attrs) { JSON.load(File.read(File.join(File.expand_path('..', __FILE__), 'skeletons', 'empty_environment.json')))}
12
16
 
13
17
  let(:attrs_one_vm) do
14
18
  empty_environment_attrs.dup.tap do |ret|
15
19
  ret['vms'] = [vm1_attrs]
16
- ret['networks'] = [network1_attrs]
20
+ ret['networks'] = [network1_attrs.dup.tap do |ret|
21
+ ret['vpn_attachments'] = [vpn_attachment1_attrs]
22
+ end]
17
23
  end
18
24
  end
19
25
 
@@ -46,7 +52,11 @@ describe VagrantPlugins::Skytap::API::Environment do
46
52
  ENV.stub(:[] => nil)
47
53
  end
48
54
 
49
- describe "check_vm_before_adding" do
55
+ describe "check_vm_before_adding class method" do
56
+ after(:each) do
57
+ allow(subject).to receive(:runstate).and_call_original
58
+ end
59
+
50
60
  subject do
51
61
  instance.vms.first
52
62
  end
@@ -54,20 +64,49 @@ describe VagrantPlugins::Skytap::API::Environment do
54
64
  it "raises SourceVmNotStopped if the vm is running" do
55
65
  allow(subject).to receive(:runstate).and_return('running')
56
66
  expect {described_class.check_vm_before_adding(env, subject)}.to raise_error(Errors::SourceVmNotStopped)
57
- allow(subject).to receive(:runstate).and_call_original
58
67
  end
59
68
 
60
69
  it "raises SourceVmNotStopped if the vm is suspended" do
61
70
  allow(subject).to receive(:runstate).and_return('suspended')
62
71
  expect {described_class.check_vm_before_adding(env, subject)}.to raise_error(Errors::SourceVmNotStopped)
63
- allow(subject).to receive(:runstate).and_call_original
64
72
  end
65
73
 
66
74
  it "raises nothing if the vm is stopped" do
67
75
  allow(subject).to receive(:runstate).and_return('stopped')
68
76
  expect {described_class.check_vm_before_adding(env, subject)}.to_not raise_error
77
+ end
78
+
79
+ it "raises NotTemplateVm if the vm is not a template vm" do
80
+ vm = VagrantPlugins::Skytap::API::Vm.new(config_vm_attrs, nil, env)
81
+ expect {described_class.check_vm_before_adding(env, vm)}.to raise_error(Errors::NotTemplateVm)
82
+ end
83
+ end
84
+
85
+ describe "check_vm_before_adding instance method" do
86
+ after(:each) do
87
+ allow(subject).to receive(:region).and_call_original
69
88
  allow(subject).to receive(:runstate).and_call_original
70
89
  end
90
+
91
+ subject do
92
+ instance.vms.first
93
+ end
94
+
95
+ it "raises RegionMismatch if the vm is in a different region" do
96
+ allow(subject).to receive(:region).and_return('EMEA')
97
+ expect {subject.environment.check_vm_before_adding(env, subject)}.to raise_error(Errors::RegionMismatch)
98
+ end
99
+
100
+ it "raises SourceVmNotStopped if the vm is in the same region but running" do
101
+ allow(subject).to receive(:region).and_return('US-West')
102
+ allow(subject).to receive(:runstate).and_return('running')
103
+ expect {subject.environment.check_vm_before_adding(env, subject)}.to raise_error(Errors::SourceVmNotStopped)
104
+ end
105
+
106
+ it "raises nothing if the vm is in the same region" do
107
+ allow(subject).to receive(:region).and_return('US-West')
108
+ expect {subject.environment.check_vm_before_adding(env, subject)}.to_not raise_error
109
+ end
71
110
  end
72
111
 
73
112
  describe "vms" do
@@ -0,0 +1,128 @@
1
+ require_relative 'base'
2
+ require "vagrant-skytap/setup_helper"
3
+ require "vagrant-skytap/api/environment"
4
+ require "vagrant-skytap/api/vpn"
5
+ require "vagrant-skytap/api/vpn_attachment"
6
+
7
+ describe VagrantPlugins::Skytap::SetupHelper do
8
+ include_context "unit"
9
+
10
+ let(:instance) { described_class.new }
11
+
12
+ let(:vm1_attrs) { JSON.load(File.read(File.join(File.expand_path('..', __FILE__), 'skeletons', 'vm1.json'))) }
13
+ let(:network1_attrs) { JSON.load(File.read(File.join(File.expand_path('..', __FILE__), 'skeletons', 'network1.json'))) }
14
+ let(:vpn1_attrs) { JSON.load(File.read(File.join(File.expand_path('..', __FILE__), 'skeletons', 'vpn1.json'))) }
15
+ let(:vpn_attachment1_attrs) { JSON.load(File.read(File.join(File.expand_path('..', __FILE__), 'skeletons', 'vpn_attachment1.json'))) }
16
+ let(:empty_environment_attrs) { JSON.load(File.read(File.join(File.expand_path('..', __FILE__), 'skeletons', 'empty_environment.json')))}
17
+
18
+
19
+ let(:network_attrs) do
20
+ network1_attrs.dup.tap do |ret|
21
+ ret['vpn_attachments'] = [vpn_attachment1_attrs]
22
+ end
23
+ end
24
+
25
+ let(:vm_attrs) do
26
+ vm1_attrs.dup.tap do |ret|
27
+ ret['interfaces'].first['nat_addresses']['vpn_nat_addresses'] = {}
28
+ end
29
+ end
30
+
31
+ let(:environment_attrs) do
32
+ empty_environment_attrs.dup.tap do |ret|
33
+ ret['vms'] = [vm_attrs]
34
+ ret['networks'] = [network1_attrs]
35
+ end
36
+ end
37
+
38
+ let(:environment) { VagrantPlugins::Skytap::API::Environment.new(environment_attrs, env) }
39
+
40
+ let(:vpn_attrs) do
41
+ vpn1_attrs.dup.tap do |ret|
42
+ ret['network_attachments'] = [vpn_attachment1_attrs]
43
+ end
44
+ end
45
+
46
+ let(:vpn) {VagrantPlugins::Skytap::API::Vpn.new(vpn_attrs, env)}
47
+
48
+ let(:iso_env) do
49
+ # We have to create a Vagrantfile so there is a root path
50
+ env = isolated_environment
51
+ env.vagrantfile("")
52
+ env.create_vagrant_env
53
+ end
54
+
55
+ let(:machine) { iso_env.machine(iso_env.machine_names[0], :dummy) }
56
+ let(:env) {{ machine: machine, api_client: double(post: Net::HTTPOK) }}
57
+ let(:instance) { described_class.new(attrs, env) }
58
+
59
+ let(:api_client) do
60
+ # By default, all GET requests will return an environment with VM1, VM2, and 1 network
61
+ double('api_client',
62
+ get: double('resp', body: JSON.dump(attrs))
63
+ )
64
+ end
65
+
66
+ before :each do
67
+ # Ensure tests are not affected by Skytap credential environment variables
68
+ ENV.stub(:[] => nil)
69
+
70
+ machine.id = environment.vms.first.id
71
+ end
72
+
73
+ after(:each) do
74
+ allow(machine).to receive(:provider_config).and_call_original
75
+ end
76
+
77
+ describe "ask_routing" do
78
+ after(:each) do
79
+ allow_any_instance_of(VpnChoice).to receive(:choose).and_call_original
80
+ end
81
+
82
+ subject do
83
+ myenv = env.merge(
84
+ ui: double(ask: '')
85
+ )
86
+ described_class.new(myenv, environment).tap do |ret|
87
+ allow(ret).to receive(:vpns).and_return([vpn])
88
+ end
89
+ end
90
+
91
+ it "has connection_choices" do
92
+ interface = subject.current_vm.interfaces.first
93
+ choices = subject.send(:connection_choices, interface)
94
+ expect(choices.count).to eq 1
95
+ expect(choices.first.vpn).to_not be_nil
96
+ end
97
+
98
+ it "does not show choices if vpn_url specified" do
99
+ allow_any_instance_of(VpnChoice).to receive(:choose).and_return(['1.2.3.4', 22])
100
+
101
+ cfg = VagrantPlugins::Skytap::Config.new
102
+ cfg.vpn_url = vpn.url
103
+ cfg.finalize!
104
+ allow(machine).to receive(:provider_config).and_return cfg
105
+
106
+ expect(subject).not_to receive(:ask_from_list)
107
+ subject.send(:ask_routing)
108
+ end
109
+
110
+ it "raises DoesNotExist if non-existent vpn_url specified" do
111
+ cfg = VagrantPlugins::Skytap::Config.new
112
+ cfg.vpn_url = 'bogus'
113
+ cfg.finalize!
114
+ allow(machine).to receive(:provider_config).and_return cfg
115
+
116
+ expect{subject.send(:ask_routing)}.to raise_error(Errors::DoesNotExist)
117
+ end
118
+
119
+ it "shows choices if vpn_url unspecified" do
120
+ cfg = VagrantPlugins::Skytap::Config.new
121
+ cfg.finalize!
122
+ allow(machine).to receive(:provider_config).and_return cfg
123
+
124
+ expect(subject).to receive(:ask_from_list)
125
+ subject.send(:ask_routing)
126
+ end
127
+ end
128
+ end
@@ -11,26 +11,7 @@
11
11
  "secondary_nameserver": null,
12
12
  "region": "US-West",
13
13
  "domain": "skytap.example",
14
- "vpn_attachments": [
15
- {
16
- "id": "3288116-vpn-711360",
17
- "connected": true,
18
- "network": {
19
- "id": "3288116",
20
- "subnet": "10.0.0.0/24",
21
- "network_name": "Default Network",
22
- "configuration_id": "5570024"
23
- },
24
- "vpn": {
25
- "id": "vpn-711360",
26
- "name": "Skytap sea9 NAT VPN",
27
- "enabled": true,
28
- "nat_enabled": true,
29
- "remote_subnets": "10.1.0.0/24, 10.1.1.0/24, 10.1.2.0/24, 10.1.4.0/24, 10.1.6.0/24, 10.1.8.0/24, 10.1.16.0/24, 172.16.89.0/24, 192.168.0.0/16",
30
- "remote_peer_ip": "66.193.98.66"
31
- }
32
- }
33
- ],
14
+ "vpn_attachments": [],
34
15
  "tunnelable": false,
35
16
  "tunnels": []
36
17
  }
@@ -50,10 +50,10 @@
50
50
  "network_nat_addresses": [],
51
51
  "vpn_nat_addresses": [
52
52
  {
53
- "ip_address": "10.1.130.104",
54
- "vpn_id": "vpn-711360",
55
- "vpn_name": "Skytap sea9 NAT VPN",
56
- "vpn_url": "https://example.com/vpns/vpn-711360"
53
+ "ip_address": "3.4.5.6",
54
+ "vpn_id": "vpn-123",
55
+ "vpn_name": "my VPN",
56
+ "vpn_url": "https://example.com/vpns/vpn-123"
57
57
  }
58
58
  ]
59
59
  },
@@ -72,7 +72,7 @@
72
72
  "credentials": [
73
73
  {
74
74
  "id": "5695620",
75
- "text": "skytap / ChangeMe!"
75
+ "text": "xxx / yyy"
76
76
  }
77
77
  ],
78
78
  "desktop_resizable": true,
@@ -0,0 +1,26 @@
1
+ {
2
+ "id": "vpn-123",
3
+ "url": "https://example.com/vpns/123",
4
+ "name": "my VPN",
5
+ "status": "active",
6
+ "enabled": true,
7
+ "remote_subnets": [
8
+ {
9
+ "id": "10.1.0.0/24",
10
+ "cidr_block": "10.1.0.0/24",
11
+ "excluded": false
12
+ }
13
+ ],
14
+ "local_subnet": "10.1.128.0/19",
15
+ "nat_local_subnet": true,
16
+ "route_based": false,
17
+ "error": null,
18
+ "local_peer_ip": "2.3.4.5",
19
+ "remote_peer_ip": "1.2.3.4",
20
+ "attached_network_count": 264,
21
+ "connected_network_count": 1,
22
+ "network_attachments": [],
23
+ "test_results": {},
24
+ "region": "US-West",
25
+ "region_backend": "skytap"
26
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "id": "1-vpn-1",
3
+ "connected": true,
4
+ "network": {
5
+ "id": "3288116",
6
+ "subnet": "10.0.0.0/24",
7
+ "network_name": "Default Network",
8
+ "configuration_id": "5570024"
9
+ },
10
+ "vpn": {
11
+ "id": "vpn-123",
12
+ "name": "my VPN",
13
+ "enabled": true,
14
+ "nat_enabled": true,
15
+ "remote_subnets": "10.1.0.0/24",
16
+ "remote_peer_ip": "1.2.3.4"
17
+ }
18
+ }
data/spec/unit/vm_spec.rb CHANGED
@@ -115,4 +115,16 @@ describe VagrantPlugins::Skytap::API::Vm do
115
115
  allow(subject).to receive(:runstate).and_call_original
116
116
  end
117
117
  end
118
+
119
+ describe "region" do
120
+ subject do
121
+ fake_template_attrs = {'id' => '5570024', 'region' => 'EMEA'}
122
+ client = double('api_client',
123
+ get: double('resp', body: JSON.dump(fake_template_attrs))
124
+ )
125
+ myenv = env.merge(api_client: client)
126
+ described_class.new(attrs, environment, myenv)
127
+ end
128
+ its("region") { should == 'EMEA' }
129
+ end
118
130
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-skytap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Astete
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-07 00:00:00.000000000 Z
11
+ date: 2015-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_pure
@@ -118,16 +118,15 @@ files:
118
118
  - ".hgignore"
119
119
  - ".project"
120
120
  - ".rspec"
121
- - 1-2.diff
122
121
  - CHANGELOG.md
123
122
  - Gemfile
124
123
  - LICENSE
125
124
  - README.md
126
125
  - Rakefile
127
- - dummy.box
128
- - example_box/README.md
129
- - example_box/metadata.json
130
- - f.diff
126
+ - boxes/README.md
127
+ - boxes/empty.box
128
+ - boxes/metadata.json
129
+ - eng-10369.diff
131
130
  - lib/vagrant-skytap.rb
132
131
  - lib/vagrant-skytap/action.rb
133
132
  - lib/vagrant-skytap/action/add_vm_to_environment.rb
@@ -161,6 +160,7 @@ files:
161
160
  - lib/vagrant-skytap/action/suspend_vm.rb
162
161
  - lib/vagrant-skytap/action/timed_provision.rb
163
162
  - lib/vagrant-skytap/action/update_hardware.rb
163
+ - lib/vagrant-skytap/action/wait_for_communicator.rb
164
164
  - lib/vagrant-skytap/api/busyable.rb
165
165
  - lib/vagrant-skytap/api/client.rb
166
166
  - lib/vagrant-skytap/api/credentials.rb
@@ -191,7 +191,6 @@ files:
191
191
  - lib/vagrant-skytap/version.rb
192
192
  - lib/vagrant-skytap/vm_properties.rb
193
193
  - locales/en.yml
194
- - skytap-dummy.box
195
194
  - spec/acceptance/base.rb
196
195
  - spec/acceptance/provider/halt_spec.rb
197
196
  - spec/acceptance/shared/context_skytap.rb
@@ -200,9 +199,12 @@ files:
200
199
  - spec/unit/base.rb
201
200
  - spec/unit/config_spec.rb
202
201
  - spec/unit/environment_spec.rb
202
+ - spec/unit/setup_helper_spec.rb
203
203
  - spec/unit/skeletons/empty_environment.json
204
204
  - spec/unit/skeletons/network1.json
205
205
  - spec/unit/skeletons/vm1.json
206
+ - spec/unit/skeletons/vpn1.json
207
+ - spec/unit/skeletons/vpn_attachment1.json
206
208
  - spec/unit/support/dummy_communicator.rb
207
209
  - spec/unit/support/dummy_provider.rb
208
210
  - spec/unit/support/isolated_environment.rb