vagrant-skytap 0.1.1a
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.hgignore +22 -0
- data/.project +11 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +85 -0
- data/Gemfile +29 -0
- data/LICENSE +8 -0
- data/README.md +292 -0
- data/Rakefile +31 -0
- data/Vagrantfile.orig +34 -0
- data/bar/checksums.yaml +7 -0
- data/bar/data.tar +0 -0
- data/bar/metadata +242 -0
- data/dummy.box +0 -0
- data/example_box/README.md +13 -0
- data/example_box/metadata.json +3 -0
- data/lib/vagrant-skytap/action/add_vm_to_environment.rb +35 -0
- data/lib/vagrant-skytap/action/create_environment.rb +44 -0
- data/lib/vagrant-skytap/action/delete_environment.rb +26 -0
- data/lib/vagrant-skytap/action/delete_vm.rb +27 -0
- data/lib/vagrant-skytap/action/existence_check.rb +35 -0
- data/lib/vagrant-skytap/action/fetch_environment.rb +32 -0
- data/lib/vagrant-skytap/action/initialize_api_client.rb +28 -0
- data/lib/vagrant-skytap/action/is_running.rb +19 -0
- data/lib/vagrant-skytap/action/is_stopped.rb +19 -0
- data/lib/vagrant-skytap/action/is_suspended.rb +19 -0
- data/lib/vagrant-skytap/action/message_already_created.rb +16 -0
- data/lib/vagrant-skytap/action/message_already_running.rb +16 -0
- data/lib/vagrant-skytap/action/message_environment_url.rb +16 -0
- data/lib/vagrant-skytap/action/message_not_created.rb +16 -0
- data/lib/vagrant-skytap/action/message_will_not_destroy.rb +16 -0
- data/lib/vagrant-skytap/action/mixin_machine_index.rb +22 -0
- data/lib/vagrant-skytap/action/prepare_nfs_settings.rb +46 -0
- data/lib/vagrant-skytap/action/prepare_nfs_valid_ids.rb +28 -0
- data/lib/vagrant-skytap/action/read_ssh_info.rb +23 -0
- data/lib/vagrant-skytap/action/read_state.rb +42 -0
- data/lib/vagrant-skytap/action/run_environment.rb +53 -0
- data/lib/vagrant-skytap/action/run_vm.rb +51 -0
- data/lib/vagrant-skytap/action/set_hostname.rb +31 -0
- data/lib/vagrant-skytap/action/set_up_vm.rb +21 -0
- data/lib/vagrant-skytap/action/stop_environment.rb +43 -0
- data/lib/vagrant-skytap/action/stop_vm.rb +43 -0
- data/lib/vagrant-skytap/action/store_extra_data.rb +35 -0
- data/lib/vagrant-skytap/action/suspend_environment.rb +32 -0
- data/lib/vagrant-skytap/action/suspend_vm.rb +32 -0
- data/lib/vagrant-skytap/action/timed_provision.rb +21 -0
- data/lib/vagrant-skytap/action/update_hardware.rb +37 -0
- data/lib/vagrant-skytap/action.rb +272 -0
- data/lib/vagrant-skytap/api/busyable.rb +37 -0
- data/lib/vagrant-skytap/api/client.rb +127 -0
- data/lib/vagrant-skytap/api/credentials.rb +41 -0
- data/lib/vagrant-skytap/api/environment.rb +99 -0
- data/lib/vagrant-skytap/api/interface.rb +123 -0
- data/lib/vagrant-skytap/api/network.rb +40 -0
- data/lib/vagrant-skytap/api/public_ip.rb +103 -0
- data/lib/vagrant-skytap/api/published_service.rb +90 -0
- data/lib/vagrant-skytap/api/resource.rb +44 -0
- data/lib/vagrant-skytap/api/runstate_operations.rb +63 -0
- data/lib/vagrant-skytap/api/specified_attributes.rb +27 -0
- data/lib/vagrant-skytap/api/vm.rb +88 -0
- data/lib/vagrant-skytap/api/vpn.rb +146 -0
- data/lib/vagrant-skytap/api/vpn_attachment.rb +57 -0
- data/lib/vagrant-skytap/config.rb +106 -0
- data/lib/vagrant-skytap/core_ext/object/blank.rb +82 -0
- data/lib/vagrant-skytap/core_ext/object/tap.rb +8 -0
- data/lib/vagrant-skytap/core_ext/try.rb +42 -0
- data/lib/vagrant-skytap/environment_properties.rb +11 -0
- data/lib/vagrant-skytap/errors.rb +59 -0
- data/lib/vagrant-skytap/plugin.rb +73 -0
- data/lib/vagrant-skytap/properties.rb +42 -0
- data/lib/vagrant-skytap/provider.rb +50 -0
- data/lib/vagrant-skytap/setup_helper.rb +193 -0
- data/lib/vagrant-skytap/util/ip_address.rb +69 -0
- data/lib/vagrant-skytap/util/subnet.rb +97 -0
- data/lib/vagrant-skytap/util/timer.rb +17 -0
- data/lib/vagrant-skytap/version.rb +5 -0
- data/lib/vagrant-skytap/version.rb.orig +5 -0
- data/lib/vagrant-skytap/vm_properties.rb +22 -0
- data/lib/vagrant-skytap.rb +23 -0
- data/locales/en.yml +127 -0
- data/skytap-dummy.box +0 -0
- data/spec/acceptance/base.rb +2 -0
- data/spec/acceptance/provider/halt_spec.rb +3 -0
- data/spec/acceptance/shared/context_skytap.rb +3 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/isolated_environment.rb +45 -0
- data/spec/unit/base.rb +57 -0
- data/spec/unit/config_spec.rb +73 -0
- data/spec/unit/environment_spec.rb +144 -0
- data/spec/unit/skeletons/empty_environment.json +19 -0
- data/spec/unit/skeletons/network1.json +36 -0
- data/spec/unit/skeletons/vm1.json +85 -0
- data/spec/unit/support/dummy_communicator.rb +83 -0
- data/spec/unit/support/dummy_provider.rb +41 -0
- data/spec/unit/support/isolated_environment.rb +217 -0
- data/spec/unit/support/shared/action_synced_folders_context.rb +15 -0
- data/spec/unit/support/shared/base_context.rb +116 -0
- data/spec/unit/support/shared/capability_helpers_context.rb +29 -0
- data/spec/unit/support/shared/plugin_command_context.rb +12 -0
- data/spec/unit/support/shared/skytap_context.rb +3 -0
- data/spec/unit/vm_spec.rb +118 -0
- data/tasks/acceptance.rake +22 -0
- data/tasks/bundler.rake +3 -0
- data/tasks/test.rake +14 -0
- data/vagrant-skytap.gemspec +62 -0
- data/vagrant-spec.config.rb +10 -0
- metadata +247 -0
@@ -0,0 +1,69 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Skytap
|
3
|
+
module Util
|
4
|
+
class IpAddress
|
5
|
+
class InvalidIp < RuntimeError; end
|
6
|
+
IP_REGEX = /^(0[0-7]*|0[x][0-9a-f]+|[1-9][0-9]*)\.(0[0-7]*|0[x][0-9a-f]+|[1-9][0-9]*)\.(0[0-7]*|0[x][0-9a-f]+|[1-9][0-9]*)\.(0[0-7]*|0[x][0-9a-f]+|[1-9][0-9]*)$/i
|
7
|
+
MAX_IP4_INT = 2**32 - 1
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def str_to_int(str)
|
11
|
+
raise InvalidIp.new("'#{str}' does not look like an IP") unless str =~ IP_REGEX
|
12
|
+
bytes = [Integer($1), Integer($2), Integer($3), Integer($4)]
|
13
|
+
raise InvalidIp.new("'#{str}' octet exceeds 255") if bytes.any?{|b| b > 255}
|
14
|
+
bytes.zip([24, 16, 8, 0]).collect{|n,shift| n << shift}.inject(&:+)
|
15
|
+
end
|
16
|
+
def int_to_str(i)
|
17
|
+
raise InvalidIp.new("#{i} exceeds maximum IPv4 address") if i > MAX_IP4_INT
|
18
|
+
[24, 16, 8, 0].collect{|shift| (i & (255 << shift)) >> shift}.join('.')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(str_or_int)
|
23
|
+
if str_or_int.is_a?(String)
|
24
|
+
@i = self.class.str_to_int(str_or_int)
|
25
|
+
elsif str_or_int.is_a?(Integer)
|
26
|
+
raise InvalidIp.new("IP #{str_or_int} is greater than the maximum IPv4 value") if str_or_int > MAX_IP4_INT
|
27
|
+
raise InvalidIp.new("IP value must be non-negative") if str_or_int < 0
|
28
|
+
@i = str_or_int
|
29
|
+
else
|
30
|
+
raise InvalidIp.new("Don't know how to make an IP out of #{str_or_int}")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_i
|
35
|
+
@i
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_s
|
39
|
+
self.class.int_to_str(@i)
|
40
|
+
end
|
41
|
+
|
42
|
+
MAX_IP4 = self.new(MAX_IP4_INT)
|
43
|
+
|
44
|
+
# IpAddress arithmetic ops result in new IP addresses
|
45
|
+
[:+, :-, :&, :|, :<<, :>>].each do |name|
|
46
|
+
define_method(name) do |other|
|
47
|
+
IpAddress.new(@i.send(name, other.to_i))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# IpAddress comparisons just proxy to the .to_i value
|
52
|
+
[:==, :<, :>, :>=, :<=, :<=>].each do |name|
|
53
|
+
define_method(name) do |other|
|
54
|
+
@i.send(name, other.to_i)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def inverse
|
59
|
+
MAX_IP4 - self
|
60
|
+
end
|
61
|
+
alias_method :~, :inverse
|
62
|
+
|
63
|
+
def succ
|
64
|
+
self + 1
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require_relative 'ip_address'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Skytap
|
5
|
+
module Util
|
6
|
+
class Subnet
|
7
|
+
class InvalidSubnet < RuntimeError ; end
|
8
|
+
|
9
|
+
attr_reader :size, :mask, :address
|
10
|
+
|
11
|
+
def initialize(cidr_block)
|
12
|
+
unless cidr_block =~ /^(.*)\/(.*)/
|
13
|
+
raise InvalidSubnet.new 'Not in CIDR block form (XX.XX.XX.XX/YY)'
|
14
|
+
end
|
15
|
+
|
16
|
+
network = $1
|
17
|
+
begin
|
18
|
+
@size = Integer($2)
|
19
|
+
rescue
|
20
|
+
raise InvalidSubnet.new 'Invalid size'
|
21
|
+
end
|
22
|
+
|
23
|
+
@address = IpAddress.new(network)
|
24
|
+
@mask = size_to_mask(@size)
|
25
|
+
end
|
26
|
+
|
27
|
+
def network_portion
|
28
|
+
@network_portion ||= (mask & address)
|
29
|
+
end
|
30
|
+
alias_method :min, :network_portion
|
31
|
+
|
32
|
+
def ==(other)
|
33
|
+
other.is_a?(Subnet) && \
|
34
|
+
(size == other.size) && \
|
35
|
+
network_portion == other.network_portion
|
36
|
+
end
|
37
|
+
|
38
|
+
def overlaps?(other)
|
39
|
+
min <= other.max && max >= other.min
|
40
|
+
end
|
41
|
+
|
42
|
+
def subsumes?(other)
|
43
|
+
min <= other.min && max >= other.max
|
44
|
+
end
|
45
|
+
|
46
|
+
def strictly_subsumes?(other)
|
47
|
+
subsumes?(other) && self != other
|
48
|
+
end
|
49
|
+
|
50
|
+
def max
|
51
|
+
@max ||= (mask.inverse | network_portion)
|
52
|
+
end
|
53
|
+
|
54
|
+
def each_address
|
55
|
+
(min.to_i..max.to_i).each{|i| yield IpAddress.new(i)}
|
56
|
+
end
|
57
|
+
|
58
|
+
def contains?(ip)
|
59
|
+
ip = IpAddress.new(ip) unless ip.is_a?(IpAddress)
|
60
|
+
(ip & mask) == network_portion
|
61
|
+
end
|
62
|
+
|
63
|
+
def num_addresses
|
64
|
+
2 ** (32-size)
|
65
|
+
end
|
66
|
+
|
67
|
+
def min_machine_ip
|
68
|
+
min + 1
|
69
|
+
end
|
70
|
+
|
71
|
+
def normalized?
|
72
|
+
address == network_portion
|
73
|
+
end
|
74
|
+
|
75
|
+
def normalize
|
76
|
+
Subnet.new("#{network_portion}/#{size}")
|
77
|
+
end
|
78
|
+
|
79
|
+
def to_s
|
80
|
+
"#{address}/#{size}"
|
81
|
+
end
|
82
|
+
|
83
|
+
def <=>(other)
|
84
|
+
to_s <=> other.to_s
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def size_to_mask(numbits)
|
90
|
+
raise InvalidSubnet.new("Subnet size in bits must be between 0 and 32") unless numbits >= 0 and numbits <= 32
|
91
|
+
IpAddress.new((2**numbits - 1) << (32 - numbits))
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Skytap
|
3
|
+
module Util
|
4
|
+
class Timer
|
5
|
+
# A basic utility method that times the execution of the given
|
6
|
+
# block and returns it.
|
7
|
+
def self.time
|
8
|
+
start_time = Time.now.to_f
|
9
|
+
yield
|
10
|
+
end_time = Time.now.to_f
|
11
|
+
|
12
|
+
end_time - start_time
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'vagrant-skytap/properties'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Skytap
|
5
|
+
class VmProperties < Properties
|
6
|
+
def self.filename
|
7
|
+
'vm'
|
8
|
+
end
|
9
|
+
|
10
|
+
def ssh_info
|
11
|
+
return {} unless properties
|
12
|
+
|
13
|
+
@ssh_info ||= {
|
14
|
+
username: properties['username'],
|
15
|
+
password: properties['password'],
|
16
|
+
host: properties['host'],
|
17
|
+
port: properties['port'],
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# TODO:NLA To add the box initially:
|
2
|
+
# $ bundle exec vagrant box add skytap-dummy.box --provider=skytap --name=skytap-dummy
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
require "vagrant-skytap/core_ext/object/blank"
|
6
|
+
require "vagrant-skytap/core_ext/object/tap"
|
7
|
+
require "vagrant-skytap/core_ext/try"
|
8
|
+
require "vagrant-skytap/plugin"
|
9
|
+
|
10
|
+
module VagrantPlugins
|
11
|
+
module Skytap
|
12
|
+
lib_path = Pathname.new(File.expand_path("../vagrant-skytap", __FILE__))
|
13
|
+
autoload :Action, lib_path.join("action")
|
14
|
+
autoload :Errors, lib_path.join("errors")
|
15
|
+
|
16
|
+
# This returns the path to the source of this plugin.
|
17
|
+
#
|
18
|
+
# @return [Pathname]
|
19
|
+
def self.source_root
|
20
|
+
@source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
en:
|
2
|
+
vagrant_skytap:
|
3
|
+
already_status: |-
|
4
|
+
The machine is already %{status}.
|
5
|
+
|
6
|
+
launching_instance: |-
|
7
|
+
Launching an instance with the following settings...
|
8
|
+
launching_vm: |-
|
9
|
+
Launching a VM with the following settings...
|
10
|
+
not_created: |-
|
11
|
+
Instance is not created. Please run `vagrant up` first.
|
12
|
+
ready: |-
|
13
|
+
Machine is booted and ready for use!
|
14
|
+
rsync_not_found_warning: |-
|
15
|
+
Warning! Folder sync disabled because the rsync binary is missing in the %{side}.
|
16
|
+
Make sure rsync is installed and the binary can be found in the PATH.
|
17
|
+
rsync_folder: |-
|
18
|
+
Rsyncing folder: %{hostpath} => %{guestpath}
|
19
|
+
starting: |-
|
20
|
+
Starting the instance...
|
21
|
+
stopping: |-
|
22
|
+
Stopping the instance...
|
23
|
+
terminating: |-
|
24
|
+
Terminating the instance...
|
25
|
+
waiting_for_ready: |-
|
26
|
+
Waiting for instance to become "ready"...
|
27
|
+
waiting_for_ssh: |-
|
28
|
+
Waiting for SSH to become available...
|
29
|
+
warn_networks: |-
|
30
|
+
Warning! The Skytap provider doesn't support any of the Vagrant
|
31
|
+
high-level network configurations (`config.vm.network`). They
|
32
|
+
will be silently ignored.
|
33
|
+
warn_ssh_access: |-
|
34
|
+
Warning! Vagrant might not be able to SSH into the instance.
|
35
|
+
Please check your security groups settings.
|
36
|
+
will_not_destroy: |-
|
37
|
+
The instance '%{name}' will not be destroyed, since the confirmation
|
38
|
+
was declined.
|
39
|
+
environment_url: |-
|
40
|
+
New Skytap environment created: %{url}
|
41
|
+
graceful_halt_environment_failed: |-
|
42
|
+
The environment could not be halted gracefully. Forcing halt.
|
43
|
+
graceful_halt_vm_failed: |-
|
44
|
+
The VM could not be halted gracefully. Forcing halt.
|
45
|
+
|
46
|
+
config:
|
47
|
+
username_required:
|
48
|
+
A Skytap username must be specified via "username" or in the
|
49
|
+
VAGRANT_SKYTAP_USERNAME environment variable.
|
50
|
+
api_token_required:
|
51
|
+
A Skytap API token must be specified via "api_token" or in the
|
52
|
+
VAGRANT_SKYTAP_API_TOKEN environment variable.
|
53
|
+
vm_url_required:
|
54
|
+
The URL of a Skytap VM must be specified via "vm_url"
|
55
|
+
|
56
|
+
errors:
|
57
|
+
instance_ready_timeout: |-
|
58
|
+
The instance never became "ready" in Skytap. The timeout currently
|
59
|
+
set waiting for the instance to become ready is %{timeout} seconds.
|
60
|
+
Please verify that the machine properly boots. If you need more time
|
61
|
+
set the `instance_ready_timeout` configuration on the Skytap provider.
|
62
|
+
rsync_error: |-
|
63
|
+
There was an error when attempting to rsync a shared folder.
|
64
|
+
Please inspect the error message below for more info.
|
65
|
+
|
66
|
+
Host path: %{hostpath}
|
67
|
+
Guest path: %{guestpath}
|
68
|
+
Error: %{stderr}
|
69
|
+
mkdir_error: |-
|
70
|
+
There was an error when attempting to create a shared host folder.
|
71
|
+
Please inspect the error message below for more info.
|
72
|
+
|
73
|
+
Host path: %{hostpath}
|
74
|
+
Error: %{err}
|
75
|
+
|
76
|
+
does_not_exist: |-
|
77
|
+
%{object_name} was not found.
|
78
|
+
|
79
|
+
operation_failed: |-
|
80
|
+
The operation failed: %{err}
|
81
|
+
|
82
|
+
vpn_connection_failed: |-
|
83
|
+
Could not connect to the VPN.
|
84
|
+
|
85
|
+
source_vm_not_stopped: |-
|
86
|
+
You cannot bring up the machine '%{name}' using the VM %{url} because the VM is running or suspended.
|
87
|
+
|
88
|
+
resource_busy: |-
|
89
|
+
This operation failed because the resource was busy: %{err}
|
90
|
+
|
91
|
+
rate_limited: |-
|
92
|
+
This operation failed due to rate limiting: %{err}
|
93
|
+
|
94
|
+
unprocessable_entity: |-
|
95
|
+
The operation failed: %{err}
|
96
|
+
|
97
|
+
no_connection_options: |-
|
98
|
+
There were no available options for connecting to the VM.
|
99
|
+
Currently, the provider supports connections over VPN only.
|
100
|
+
|
101
|
+
states:
|
102
|
+
short_not_created: |-
|
103
|
+
not created
|
104
|
+
long_not_created: |-
|
105
|
+
The Skytap instance is not created. Run `vagrant up` to create it.
|
106
|
+
|
107
|
+
short_stopped: |-
|
108
|
+
stopped
|
109
|
+
long_stopped: |-
|
110
|
+
The Skytap instance is stopped. Run `vagrant up` to start it.
|
111
|
+
|
112
|
+
short_suspended: |-
|
113
|
+
suspended
|
114
|
+
long_suspended: |-
|
115
|
+
The Skytap instance is suspended. Run `vagrant up` or `vagrant resume` to resume.
|
116
|
+
|
117
|
+
short_running: |-
|
118
|
+
running
|
119
|
+
long_running: |-
|
120
|
+
The Skytap instance is running. To stop this machine, you can run
|
121
|
+
`vagrant halt`. To destroy the machine, you can run `vagrant destroy`.
|
122
|
+
|
123
|
+
short_busy: |-
|
124
|
+
busy
|
125
|
+
long_busy: |-
|
126
|
+
The Skytap instance is busy. Wait for the current operation to complete.
|
127
|
+
|
data/skytap-dummy.box
ADDED
Binary file
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
require "pathname"
|
3
|
+
require "tmpdir"
|
4
|
+
|
5
|
+
require "log4r"
|
6
|
+
|
7
|
+
# This class manages an isolated environment for Vagrant to
|
8
|
+
# run in. It creates a temporary directory to act as the
|
9
|
+
# working directory as well as sets a custom home directory.
|
10
|
+
#
|
11
|
+
# This class also provides various helpers to create Vagrantfiles,
|
12
|
+
# boxes, etc.
|
13
|
+
class IsolatedEnvironment
|
14
|
+
attr_reader :homedir
|
15
|
+
attr_reader :workdir
|
16
|
+
|
17
|
+
# Initializes an isolated environment. You can pass in some
|
18
|
+
# options here to configure runing custom applications in place
|
19
|
+
# of others as well as specifying environmental variables.
|
20
|
+
#
|
21
|
+
# @param [Hash] apps A mapping of application name (such as "vagrant")
|
22
|
+
# to an alternate full path to the binary to run.
|
23
|
+
# @param [Hash] env Additional environmental variables to inject
|
24
|
+
# into the execution environments.
|
25
|
+
def initialize
|
26
|
+
@logger = Log4r::Logger.new("test::isolated_environment")
|
27
|
+
|
28
|
+
# Create a temporary directory for our work
|
29
|
+
@tempdir = Dir.mktmpdir("vagrant")
|
30
|
+
@logger.info("Initialize isolated environment: #{@tempdir}")
|
31
|
+
|
32
|
+
# Setup the home and working directories
|
33
|
+
@homedir = Pathname.new(File.join(@tempdir, "home"))
|
34
|
+
@workdir = Pathname.new(File.join(@tempdir, "work"))
|
35
|
+
|
36
|
+
@homedir.mkdir
|
37
|
+
@workdir.mkdir
|
38
|
+
end
|
39
|
+
|
40
|
+
# This closes the environment by cleaning it up.
|
41
|
+
def close
|
42
|
+
@logger.info("Removing isolated environment: #{@tempdir}")
|
43
|
+
FileUtils.rm_rf(@tempdir)
|
44
|
+
end
|
45
|
+
end
|
data/spec/unit/base.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require "tmpdir"
|
2
|
+
require "rubygems"
|
3
|
+
|
4
|
+
# Gems
|
5
|
+
require "checkpoint"
|
6
|
+
require "rspec/autorun"
|
7
|
+
require "webmock/rspec"
|
8
|
+
|
9
|
+
# Require Vagrant itself so we can reference the proper
|
10
|
+
# classes to test.
|
11
|
+
require "vagrant"
|
12
|
+
require "vagrant/util/platform"
|
13
|
+
|
14
|
+
# Add the test directory to the load path
|
15
|
+
$:.unshift File.expand_path("../../", __FILE__)
|
16
|
+
|
17
|
+
# Load in helpers
|
18
|
+
require "unit/support/dummy_communicator"
|
19
|
+
require "unit/support/dummy_provider"
|
20
|
+
require "unit/support/shared/base_context"
|
21
|
+
require "unit/support/shared/action_synced_folders_context"
|
22
|
+
require "unit/support/shared/capability_helpers_context"
|
23
|
+
require "unit/support/shared/plugin_command_context"
|
24
|
+
require "unit/support/shared/skytap_context"
|
25
|
+
|
26
|
+
# Do not buffer output
|
27
|
+
$stdout.sync = true
|
28
|
+
$stderr.sync = true
|
29
|
+
|
30
|
+
# Configure RSpec
|
31
|
+
RSpec.configure do |c|
|
32
|
+
c.treat_symbols_as_metadata_keys_with_true_values = true
|
33
|
+
|
34
|
+
if Vagrant::Util::Platform.windows?
|
35
|
+
c.filter_run_excluding :skip_windows
|
36
|
+
else
|
37
|
+
c.filter_run_excluding :windows
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Configure VAGRANT_CWD so that the tests never find an actual
|
42
|
+
# Vagrantfile anywhere, or at least this minimizes those chances.
|
43
|
+
ENV["VAGRANT_CWD"] = Dir.mktmpdir("vagrant")
|
44
|
+
|
45
|
+
# Set the dummy provider to the default for tests
|
46
|
+
ENV["VAGRANT_DEFAULT_PROVIDER"] = "dummy"
|
47
|
+
|
48
|
+
# Unset all host plugins so that we aren't executing subprocess things
|
49
|
+
# to detect a host for every test.
|
50
|
+
Vagrant.plugin("2").manager.registered.dup.each do |plugin|
|
51
|
+
if plugin.components.hosts.to_hash.length > 0
|
52
|
+
Vagrant.plugin("2").manager.unregister(plugin)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Disable checkpoint
|
57
|
+
Checkpoint.disable!
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require "vagrant-skytap/config"
|
2
|
+
|
3
|
+
describe VagrantPlugins::Skytap::Config do
|
4
|
+
let(:instance) { described_class.new }
|
5
|
+
|
6
|
+
# Ensure tests are not affected by Skytap credential environment variables
|
7
|
+
before :each do
|
8
|
+
ENV.stub(:[] => nil)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "defaults" do
|
12
|
+
subject do
|
13
|
+
instance.tap do |o|
|
14
|
+
o.finalize!
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
its("username") { should be_nil }
|
19
|
+
its("api_token") { should be_nil }
|
20
|
+
its("base_url") { should == "https://cloud.skytap.com/" }
|
21
|
+
its("vm_url") { should be_nil }
|
22
|
+
its("instance_ready_timeout") { should == 120 }
|
23
|
+
its("cpus") { should be_nil }
|
24
|
+
its("cpuspersocket") { should be_nil }
|
25
|
+
its("ram") { should be_nil }
|
26
|
+
its("guestos") { should be_nil }
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "overriding defaults" do
|
30
|
+
# I typically don't meta-program in tests, but this is a very
|
31
|
+
# simple boilerplate test, so I cut corners here. It just sets
|
32
|
+
# each of these attributes to "foo" in isolation, and reads the value
|
33
|
+
# and asserts the proper result comes back out.
|
34
|
+
[:username, :api_token, :base_url, :vm_url,
|
35
|
+
:instance_ready_timeout,
|
36
|
+
:cpus, :cpuspersocket, :ram, :guestos].each do |attribute|
|
37
|
+
it "should not default #{attribute} if overridden" do
|
38
|
+
instance.send("#{attribute}=".to_sym, "foo")
|
39
|
+
instance.finalize!
|
40
|
+
instance.send(attribute).should == "foo"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "getting credentials from environment" do
|
46
|
+
context "without Skytap credential environment variables" do
|
47
|
+
subject do
|
48
|
+
instance.tap do |o|
|
49
|
+
o.finalize!
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
its("username") { should be_nil }
|
54
|
+
its("api_token") { should be_nil }
|
55
|
+
end
|
56
|
+
|
57
|
+
context "with Skytap credential environment variables" do
|
58
|
+
before :each do
|
59
|
+
ENV.stub(:[]).with("VAGRANT_SKYTAP_USERNAME").and_return("username")
|
60
|
+
ENV.stub(:[]).with("VAGRANT_SKYTAP_API_TOKEN").and_return("api_token")
|
61
|
+
end
|
62
|
+
|
63
|
+
subject do
|
64
|
+
instance.tap do |o|
|
65
|
+
o.finalize!
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
its("username") { should == "username" }
|
70
|
+
its("api_token") { should == "api_token" }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|