vagrant-google 0.1.5 → 0.2.0.rc1

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -3
  3. data/.rubocop.yml +7 -0
  4. data/.rubocop_todo.yml +201 -0
  5. data/CHANGELOG.md +14 -0
  6. data/README.md +45 -22
  7. data/example_boxes/gce/Vagrantfile +23 -0
  8. data/example_boxes/gce-test/Vagrantfile +30 -0
  9. data/lib/vagrant-google/action/connect_google.rb +10 -14
  10. data/lib/vagrant-google/action/is_terminated.rb +31 -0
  11. data/lib/vagrant-google/action/run_instance.rb +58 -35
  12. data/lib/vagrant-google/action/start_instance.rb +90 -0
  13. data/lib/vagrant-google/action/stop_instance.rb +48 -0
  14. data/lib/vagrant-google/action/warn_networks.rb +2 -1
  15. data/lib/vagrant-google/action.rb +62 -12
  16. data/lib/vagrant-google/config.rb +56 -11
  17. data/lib/vagrant-google/errors.rb +13 -5
  18. data/lib/vagrant-google/version.rb +1 -1
  19. data/lib/vagrant-google.rb +3 -3
  20. data/locales/en.yml +33 -4
  21. data/tasks/acceptance.rake +20 -1
  22. data/tasks/lint.rake +3 -0
  23. data/tasks/test.rake +1 -0
  24. data/test/acceptance/provider/multi_instance_spec.rb +31 -0
  25. data/test/acceptance/provider/preemptible_spec.rb +26 -0
  26. data/test/acceptance/provider/scopes_spec.rb +29 -0
  27. data/test/acceptance/skeletons/multi_instance/Vagrantfile +29 -0
  28. data/test/acceptance/skeletons/preemptible/Vagrantfile +17 -0
  29. data/test/acceptance/skeletons/scopes/Vagrantfile +18 -0
  30. data/test/unit/base.rb +1 -1
  31. data/test/unit/common/config_test.rb +62 -13
  32. data/vagrant-google.gemspec +4 -3
  33. data/vagrant-spec.config.rb +2 -2
  34. data/vagrantfile_examples/Vagrantfile.multiple_machines +93 -0
  35. data/vagrantfile_examples/Vagrantfile.provision_single +48 -0
  36. data/vagrantfile_examples/Vagrantfile.simple +29 -0
  37. data/vagrantfile_examples/Vagrantfile.zone_config +40 -0
  38. metadata +39 -8
  39. data/lib/vagrant-google/action/sync_folders.rb +0 -104
@@ -0,0 +1,90 @@
1
+ # Copyright 2015 Google Inc. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ require 'log4r'
15
+ require 'vagrant/util/retryable'
16
+ require 'vagrant-google/util/timer'
17
+
18
+ module VagrantPlugins
19
+ module Google
20
+ module Action
21
+ # This starts a stopped instance.
22
+ class StartInstance
23
+ include Vagrant::Util::Retryable
24
+
25
+ def initialize(app, env)
26
+ @app = app
27
+ @logger = Log4r::Logger.new("vagrant_google::action::start_instance")
28
+ end
29
+
30
+ def call(env)
31
+ # Initialize metrics if they haven't been
32
+ env[:metrics] ||= {}
33
+
34
+ server = env[:google_compute].servers.get(env[:machine].id, env[:machine].provider_config.zone)
35
+
36
+ env[:ui].info(I18n.t("vagrant_google.starting"))
37
+
38
+ begin
39
+ server.start
40
+
41
+ # Wait for the instance to be ready first
42
+ env[:metrics]["instance_ready_time"] = Util::Timer.time do
43
+
44
+ tries = env[:machine].provider_config.instance_ready_timeout / 2
45
+
46
+ env[:ui].info(I18n.t("vagrant_google.waiting_for_ready"))
47
+ begin
48
+ retryable(:on => Fog::Errors::TimeoutError, :tries => tries) do
49
+ # If we're interrupted don't worry about waiting
50
+ next if env[:interrupted]
51
+
52
+ # Wait for the server to be ready
53
+ server.wait_for(2) { ready? }
54
+ end
55
+ rescue Fog::Errors::TimeoutError
56
+ # Notify the user
57
+ raise Errors::InstanceReadyTimeout,
58
+ timeout: env[:machine].provider_config.instance_ready_timeout
59
+ end
60
+ end
61
+ rescue Fog::Compute::Google::Error => e
62
+ raise Errors::FogError, :message => e.message
63
+ end
64
+
65
+ @logger.info("Time to instance ready: #{env[:metrics]["instance_ready_time"]}")
66
+
67
+ if !env[:interrupted]
68
+ env[:metrics]["instance_ssh_time"] = Util::Timer.time do
69
+ # Wait for SSH to be ready.
70
+ env[:ui].info(I18n.t("vagrant_google.waiting_for_ssh"))
71
+ while true
72
+ # If we're interrupted then just back out
73
+ break if env[:interrupted]
74
+ break if env[:machine].communicate.ready?
75
+ sleep 2
76
+ end
77
+ end
78
+
79
+ @logger.info("Time for SSH ready: #{env[:metrics]["instance_ssh_time"]}")
80
+
81
+ # Ready and booted!
82
+ env[:ui].info(I18n.t("vagrant_google.ready"))
83
+ end
84
+
85
+ @app.call(env)
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,48 @@
1
+ # Copyright 2015 Google Inc. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ require 'log4r'
15
+ require 'vagrant/util/retryable'
16
+ require 'vagrant-google/util/timer'
17
+
18
+ module VagrantPlugins
19
+ module Google
20
+ module Action
21
+
22
+ # This stops the running instance.
23
+ class StopInstance
24
+
25
+ include Vagrant::Util::Retryable
26
+
27
+ def initialize(app, env)
28
+ @app = app
29
+ @logger = Log4r::Logger.new("vagrant_google::action::stop_instance")
30
+ end
31
+
32
+ def call(env)
33
+ server = env[:google_compute].servers.get(env[:machine].id, env[:machine].provider_config.zone)
34
+
35
+ if env[:machine].state.id == :TERMINATED
36
+ env[:ui].info(I18n.t("vagrant_google.already_status", :status => env[:machine].state.id))
37
+ else
38
+ env[:ui].info(I18n.t("vagrant_google.stopping"))
39
+ operation = server.stop
40
+ operation.wait_for() { ready? }
41
+ end
42
+
43
+ @app.call(env)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -20,7 +20,8 @@ module VagrantPlugins
20
20
  end
21
21
 
22
22
  def call(env)
23
- if env[:machine].config.vm.networks.length > 0
23
+ # Default SSH forward always exists so "> 1"
24
+ if env[:machine].config.vm.networks.length > 1
24
25
  env[:ui].warn(I18n.t("vagrant_google.warn_networks"))
25
26
  end
26
27
 
@@ -19,14 +19,35 @@ module VagrantPlugins
19
19
  # Include the built-in modules so we can use them as top-level things.
20
20
  include Vagrant::Action::Builtin
21
21
 
22
+ # This action is called to halt the remote machine.
23
+ def self.action_halt
24
+ Vagrant::Action::Builder.new.tap do |b|
25
+ b.use ConfigValidate
26
+ b.use Call, IsCreated do |env, b2|
27
+ if !env[:result]
28
+ b2.use MessageNotCreated
29
+ next
30
+ end
31
+ b2.use ConnectGoogle
32
+ b2.use StopInstance
33
+ end
34
+ end
35
+ end
36
+
22
37
  # This action is called to terminate the remote machine.
23
38
  def self.action_destroy
24
39
  Vagrant::Action::Builder.new.tap do |b|
25
40
  b.use Call, DestroyConfirm do |env, b2|
26
41
  if env[:result]
27
42
  b2.use ConfigValidate
28
- b2.use ConnectGoogle
29
- b2.use TerminateInstance
43
+ b2.use Call, IsCreated do |env2, b3|
44
+ if !env2[:result]
45
+ b3.use MessageNotCreated
46
+ next
47
+ end
48
+ b3.use ConnectGoogle
49
+ b3.use TerminateInstance
50
+ end
30
51
  else
31
52
  b2.use MessageWillNotDestroy
32
53
  end
@@ -45,7 +66,7 @@ module VagrantPlugins
45
66
  end
46
67
 
47
68
  b2.use Provision
48
- b2.use SyncFolders
69
+ b2.use SyncedFolders
49
70
  end
50
71
  end
51
72
  end
@@ -106,17 +127,44 @@ module VagrantPlugins
106
127
  Vagrant::Action::Builder.new.tap do |b|
107
128
  b.use HandleBox
108
129
  b.use ConfigValidate
130
+ b.use BoxCheckOutdated
109
131
  b.use ConnectGoogle
110
- b.use Call, IsCreated do |env, b2|
111
- if env[:result]
112
- b2.use MessageAlreadyCreated
132
+ b.use Call, IsCreated do |env1, b1|
133
+ if env1[:result]
134
+ b1.use Call, IsTerminated do |env2, b2|
135
+ if env2[:result]
136
+ b2.use Provision
137
+ b2.use SyncedFolders
138
+ b2.use WarnNetworks
139
+ b2.use StartInstance
140
+ else
141
+ # TODO: Impement better messages for different states
142
+ b2.use MessageAlreadyCreated
143
+ end
144
+ end
145
+ else
146
+ b1.use Provision
147
+ b1.use SyncedFolders
148
+ b1.use WarnNetworks
149
+ b1.use RunInstance
150
+ end
151
+ end
152
+ end
153
+ end
154
+
155
+ def self.action_reload
156
+ Vagrant::Action::Builder.new.tap do |b|
157
+ b.use ConfigValidate
158
+ b.use ConnectGoogle
159
+ b.use Call, IsCreated do |env1, b1|
160
+ if !env1[:result]
161
+ b1.use MessageNotCreated
113
162
  next
114
163
  end
115
164
 
116
- b2.use Provision
117
- b2.use SyncFolders
118
- b2.use WarnNetworks
119
- b2.use RunInstance
165
+ # TODO: Think about implementing through server.reboot
166
+ b1.use action_halt
167
+ b1.use action_up
120
168
  end
121
169
  end
122
170
  end
@@ -125,16 +173,18 @@ module VagrantPlugins
125
173
  action_root = Pathname.new(File.expand_path("../action", __FILE__))
126
174
  autoload :ConnectGoogle, action_root.join("connect_google")
127
175
  autoload :IsCreated, action_root.join("is_created")
176
+ autoload :IsTerminated, action_root.join("is_terminated")
128
177
  autoload :MessageAlreadyCreated, action_root.join("message_already_created")
129
178
  autoload :MessageNotCreated, action_root.join("message_not_created")
130
179
  autoload :MessageWillNotDestroy, action_root.join("message_will_not_destroy")
131
180
  autoload :ReadSSHInfo, action_root.join("read_ssh_info")
132
181
  autoload :ReadState, action_root.join("read_state")
133
182
  autoload :RunInstance, action_root.join("run_instance")
134
- autoload :SyncFolders, action_root.join("sync_folders")
183
+ autoload :StartInstance, action_root.join("start_instance")
184
+ autoload :StopInstance, action_root.join("stop_instance")
185
+ autoload :TerminateInstance, action_root.join("terminate_instance")
135
186
  autoload :TimedProvision, action_root.join("timed_provision")
136
187
  autoload :WarnNetworks, action_root.join("warn_networks")
137
- autoload :TerminateInstance, action_root.join("terminate_instance")
138
188
  end
139
189
  end
140
190
  end
@@ -12,6 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  require "vagrant"
15
+ require "securerandom"
15
16
 
16
17
  module VagrantPlugins
17
18
  module Google
@@ -81,7 +82,7 @@ module VagrantPlugins
81
82
  # @return [Array]
82
83
  attr_accessor :tags
83
84
 
84
- # wether to enable ip forwarding
85
+ # whether to enable ip forwarding
85
86
  #
86
87
  # @return Boolean
87
88
  attr_accessor :can_ip_forward
@@ -91,28 +92,49 @@ module VagrantPlugins
91
92
  # @return String
92
93
  attr_accessor :external_ip
93
94
 
94
- # wether to autodelete disk on instance delete
95
+ # whether to autodelete disk on instance delete
95
96
  #
96
97
  # @return Boolean
97
98
  attr_accessor :autodelete_disk
98
99
 
100
+ # Availability policy
101
+ # whether to run instance as preemptible
102
+ #
103
+ # @return Boolean
104
+ attr_accessor :preemptible
105
+
106
+ # Availability policy
107
+ # whether to have instance restart on failures
108
+ #
109
+ # @return Boolean
110
+ attr_accessor :auto_restart
111
+
112
+ # Availability policy
113
+ # specify what to do when infrastructure maintenance events occur
114
+ # Options: MIGRATE, TERMINATE
115
+ # The default is MIGRATE.
116
+ #
117
+ # @return String
118
+ attr_accessor :on_host_maintenance
119
+
99
120
  # The timeout value waiting for instance ready
100
121
  #
101
122
  # @return [Int]
102
123
  attr_accessor :instance_ready_timeout
103
124
 
104
- # The tags for the machine.
105
- # TODO(erjohnso): not supported in fog
106
- #
107
- # @return [Hash<String, String>]
108
- #attr_accessor :tags
109
-
110
125
  # The zone to launch the instance into. If nil, it will
111
126
  # use the default us-central1-f.
112
127
  #
113
128
  # @return [String]
114
129
  attr_accessor :zone
115
130
 
131
+ # The list of access controls for service accounts.
132
+ #
133
+ # @return [Array]
134
+ attr_accessor :service_accounts
135
+ alias_method :scopes, :service_accounts
136
+ alias_method :scopes=, :service_accounts=
137
+
116
138
  def initialize(zone_specific=false)
117
139
  @google_client_email = UNSET_VALUE
118
140
  @google_key_location = UNSET_VALUE
@@ -130,8 +152,12 @@ module VagrantPlugins
130
152
  @can_ip_forward = UNSET_VALUE
131
153
  @external_ip = UNSET_VALUE
132
154
  @autodelete_disk = UNSET_VALUE
155
+ @preemptible = UNSET_VALUE
156
+ @auto_restart = UNSET_VALUE
157
+ @on_host_maintenance = UNSET_VALUE
133
158
  @instance_ready_timeout = UNSET_VALUE
134
159
  @zone = UNSET_VALUE
160
+ @service_accounts = UNSET_VALUE
135
161
 
136
162
  # Internal state (prefix with __ so they aren't automatically
137
163
  # merged)
@@ -225,9 +251,10 @@ module VagrantPlugins
225
251
  @disk_type = "pd-standard" if @disk_type == UNSET_VALUE
226
252
 
227
253
  # Instance name defaults to a new datetime value (hour granularity)
228
- t = Time.now
229
- @name = "i-#{t.year}#{t.month.to_s.rjust(2,'0')}#{t.day.to_s.rjust(2,'0')}#{t.hour.to_s.rjust(2,'0')}" if @name == UNSET_VALUE
230
-
254
+ if @name == UNSET_VALUE
255
+ t = Time.now
256
+ @name = "i-#{t.strftime("%Y%m%d%H")}-" + SecureRandom.hex(4)
257
+ end
231
258
  # Network defaults to 'default'
232
259
  @network = "default" if @network == UNSET_VALUE
233
260
 
@@ -243,9 +270,21 @@ module VagrantPlugins
243
270
  # external_ip defaults to nil
244
271
  @external_ip = nil if @external_ip == UNSET_VALUE
245
272
 
273
+ # preemptible defaults to false
274
+ @preemptible = false if @preemptible == UNSET_VALUE
275
+
276
+ # auto_restart defaults to true
277
+ @auto_restart = true if @auto_restart == UNSET_VALUE
278
+
279
+ # on_host_maintenance defaults to MIGRATE
280
+ @on_host_maintenance = "MIGRATE" if @on_host_maintenance == UNSET_VALUE
281
+
246
282
  # Default instance_ready_timeout
247
283
  @instance_ready_timeout = 20 if @instance_ready_timeout == UNSET_VALUE
248
284
 
285
+ # Default service_accounts
286
+ @service_accounts = nil if @service_accounts == UNSET_VALUE
287
+
249
288
  # Compile our zone specific configurations only within
250
289
  # NON-zone-SPECIFIC configurations.
251
290
  if !@__zone_specific
@@ -288,6 +327,12 @@ module VagrantPlugins
288
327
  errors << I18n.t("vagrant_google.config.google_key_location_required") if \
289
328
  config.google_key_location.nil? and config.google_json_key_location.nil?
290
329
 
330
+ if config.preemptible
331
+ errors << I18n.t("vagrant_google.config.auto_restart_invalid_on_preemptible") if \
332
+ config.auto_restart
333
+ errors << I18n.t("vagrant_google.config.on_host_maintenance_invalid_on_preemptible") unless \
334
+ config.on_host_maintenance == "TERMINATE"
335
+ end
291
336
  end
292
337
 
293
338
  errors << I18n.t("vagrant_google.config.image_required") if config.image.nil?
@@ -20,11 +20,7 @@ module VagrantPlugins
20
20
  error_namespace("vagrant_google.errors")
21
21
  end
22
22
 
23
- class ExternalIpError < VagrantGoogleError
24
- error_key(:external_ip_error)
25
- end
26
-
27
- class DiskTypeError <VagrantGoogleError
23
+ class DiskTypeError < VagrantGoogleError
28
24
  error_key(:disk_type_error)
29
25
  end
30
26
 
@@ -32,6 +28,18 @@ module VagrantPlugins
32
28
  error_key(:fog_error)
33
29
  end
34
30
 
31
+ class ExternalIpInUseError < VagrantGoogleError
32
+ error_key(:external_ip_error)
33
+ end
34
+
35
+ class ExternalIpDoesNotExistError < VagrantGoogleError
36
+ error_key(:external_ip_does_not_exist_error)
37
+ end
38
+
39
+ class InstanceReadyTimeout < VagrantGoogleError
40
+ error_key(:instance_ready_timeout)
41
+ end
42
+
35
43
  class RsyncError < VagrantGoogleError
36
44
  error_key(:rsync_error)
37
45
  end
@@ -13,6 +13,6 @@
13
13
  # limitations under the License.
14
14
  module VagrantPlugins
15
15
  module Google
16
- VERSION = "0.1.5"
16
+ VERSION = "0.2.0.rc1"
17
17
  end
18
18
  end
@@ -1,11 +1,11 @@
1
1
  # Copyright 2013 Google Inc. All Rights Reserved.
2
- #
2
+ #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
5
5
  # You may obtain a copy of the License at
6
- #
6
+ #
7
7
  # http://www.apache.org/licenses/LICENSE-2.0
8
- #
8
+ #
9
9
  # Unless required by applicable law or agreed to in writing, software
10
10
  # distributed under the License is distributed on an "AS IS" BASIS,
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
data/locales/en.yml CHANGED
@@ -2,6 +2,8 @@ en:
2
2
  vagrant_google:
3
3
  already_created: |-
4
4
  The machine is already created.
5
+ already_status: |-
6
+ The machine is already in %{status} status.
5
7
  launching_instance: |-
6
8
  Launching an instance with the following settings...
7
9
  not_created: |-
@@ -15,16 +17,30 @@ en:
15
17
  Make sure rsync is installed and the binary can be found in the PATH.
16
18
  rsync_folder: |-
17
19
  Rsyncing folder: %{hostpath} => %{guestpath}
20
+ starting: |-
21
+ Starting the instance...
22
+ stopping: |-
23
+ Stopping the instance...
18
24
  terminating: |-
19
25
  Terminating the instance...
20
26
  waiting_for_ready: |-
21
27
  Waiting for instance to become "ready"...
28
+ waiting_for_stop: |-
29
+ Waiting for instance to become terminated...
22
30
  waiting_for_ssh: |-
23
31
  Waiting for SSH to become available...
24
32
  warn_networks: |-
25
33
  Warning! The Google provider doesn't support any of the Vagrant
26
34
  high-level network configurations (`config.vm.network`). They
27
35
  will be silently ignored.
36
+ warn_ssh_vagrant_user: |-
37
+ Warning! SSH credentials are not set (`ssh.username`, `ssh.private_key`).
38
+ Unless Vagrant's default insecure private key is added to GCE metadata,
39
+ "vagrant up" will timeout while trying to estabilish an ssh connection
40
+ to the instance.
41
+ NOTE! Adding Vagrant private key to GCE metadata is heavily discouraged,
42
+ since it potentially allows anyone to connect to your instances,
43
+ including those not managed by Vagrant.
28
44
  will_not_destroy: |-
29
45
  The instance '%{name}' will not be destroyed, since the confirmation
30
46
  was declined.
@@ -50,6 +66,11 @@ en:
50
66
  Config must specify only one key location.
51
67
  google_project_id_required: |-
52
68
  A Google Cloud Project ID is required via "google_project_id"
69
+ auto_restart_invalid_on_preemptible: |-
70
+ "auto_restart" option must be set to "false" for preemptible instances.
71
+ on_host_maintenance_invalid_on_preemptible: |-
72
+ "on_host_maintenance" option must be set to "TERMINATE" for preemptible
73
+ instances.
53
74
  #-------------------------------------------------------------------------------
54
75
  # Translations for exception classes
55
76
  #-------------------------------------------------------------------------------
@@ -72,7 +93,10 @@ en:
72
93
  Guest path: %{guestpath}
73
94
  Error: %{stderr}
74
95
  external_ip_error: |-
75
- Specified external IP address is invalid or already in use.
96
+ Specified external IP address is already in use.
97
+ IP address requested: %{externalip}
98
+ external_ip_does_not_exist_error: |-
99
+ Specified external IP address is invalid or does not exist.
76
100
  IP address requested: %{externalip}
77
101
  disk_type_error: |-
78
102
  Specified disk type is not available in the region selected.
@@ -98,6 +122,12 @@ en:
98
122
  Resources have been acquired and the instance is being prepared for
99
123
  launch and should be in the RUNNING state soon.
100
124
 
125
+ short_STOPPING: |-
126
+ stopping
127
+ long_STOPPING: |-
128
+ The GCE instance is stopping. Wait until is completely stopped to
129
+ run `vagrant up` and start it.
130
+
101
131
  short_RUNNING: |-
102
132
  running
103
133
  long_RUNNING: |-
@@ -114,6 +144,5 @@ en:
114
144
  short_TERMINATED: |-
115
145
  terminated
116
146
  long_TERMINATED: |-
117
- The Google instance failed for some reason or was shutdown. This is
118
- a permanent status, and the only way to repair the instance is to
119
- delete it with `vagrant destroy`.
147
+ The Google instance was halted or failed for some reason. You can
148
+ attempt to restart the instance by running `vagrant up`.
@@ -1,3 +1,17 @@
1
+ def colorize(text, color_code)
2
+ puts "\033[#{color_code}m#{text}\033[0m"
3
+ end
4
+
5
+ {
6
+ :red => 31,
7
+ :green => 32,
8
+ :yellow => 33
9
+ }.each do |key, color_code|
10
+ define_method key do |text|
11
+ colorize(text, color_code)
12
+ end
13
+ end
14
+
1
15
  namespace :acceptance do
2
16
 
3
17
  desc "shows components that can be tested separately"
@@ -8,7 +22,7 @@ namespace :acceptance do
8
22
  desc "runs acceptance tests using vagrant-spec"
9
23
  task :run do
10
24
 
11
- puts "NOTE: For acceptance tests to be functional, correct ssh key needs to be added to GCE metadata."
25
+ yellow "NOTE: For acceptance tests to be functional, correct ssh key needs to be added to GCE metadata."
12
26
 
13
27
  if !ENV["GOOGLE_JSON_KEY_LOCATION"] && !ENV["GOOGLE_KEY_LOCATION"]
14
28
  abort ("Environment variables GOOGLE_JSON_KEY_LOCATION or GOOGLE_KEY_LOCATION are not set. Aborting.")
@@ -27,7 +41,12 @@ namespace :acceptance do
27
41
  end
28
42
 
29
43
  components = %w(
44
+ multi_instance
45
+ preemptible
46
+ scopes
47
+ synced_folder/rsync
30
48
  provisioner/shell
49
+ provisioner/chef-solo
31
50
  ).map{ |s| "provider/google/#{s}" }
32
51
 
33
52
  command = "bundle exec vagrant-spec test --components=#{components.join(" ")}"
data/tasks/lint.rake ADDED
@@ -0,0 +1,3 @@
1
+ require 'rubocop/rake_task'
2
+
3
+ RuboCop::RakeTask.new(:lint)
data/tasks/test.rake CHANGED
@@ -4,5 +4,6 @@ require 'rspec/core/rake_task'
4
4
  namespace :test do
5
5
  RSpec::Core::RakeTask.new(:unit) do |t|
6
6
  t.pattern = "test/unit/**/*_test.rb"
7
+ t.rspec_opts = "--color"
7
8
  end
8
9
  end
@@ -0,0 +1,31 @@
1
+ # This tests that multiple instances can be brought up correctly
2
+ shared_examples 'provider/multi_instance' do |provider, options|
3
+ if !options[:box]
4
+ raise ArgumentError,
5
+ "box option must be specified for provider: #{provider}"
6
+ end
7
+
8
+ include_context 'acceptance'
9
+
10
+ before do
11
+ environment.skeleton('multi_instance')
12
+ assert_execute('vagrant', 'box', 'add', 'basic', options[:box])
13
+ assert_execute('vagrant', 'up', "--provider=#{provider}")
14
+ end
15
+
16
+ after do
17
+ assert_execute('vagrant', 'destroy', '--force')
18
+ end
19
+
20
+ it 'should bring up 2 machines in different zones' do
21
+ status("Test: both machines are running after up")
22
+ status("Test: machine1 is running after up")
23
+ result1 = execute("vagrant", "ssh", "z1a", "-c", "echo foo")
24
+ expect(result1).to exit_with(0)
25
+ expect(result1.stdout).to match(/foo\n$/)
26
+ status("Test: machine2 is running after up")
27
+ result1 = execute("vagrant", "ssh", "z1b", "-c", "echo foo")
28
+ expect(result1).to exit_with(0)
29
+ expect(result1.stdout).to match(/foo\n$/)
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ # This tests that a preemptible instance can be brought up correctly
2
+ shared_examples 'provider/preemptible' do |provider, options|
3
+ if !options[:box]
4
+ raise ArgumentError,
5
+ "box option must be specified for provider: #{provider}"
6
+ end
7
+
8
+ include_context 'acceptance'
9
+
10
+ before do
11
+ environment.skeleton('preemptible')
12
+ assert_execute('vagrant', 'box', 'add', 'basic', options[:box])
13
+ assert_execute('vagrant', 'up', "--provider=#{provider}")
14
+ end
15
+
16
+ after do
17
+ assert_execute('vagrant', 'destroy', '--force')
18
+ end
19
+
20
+ it 'should bring up machine with preemptible option' do
21
+ status("Test: machine is running after up")
22
+ result = execute("vagrant", "ssh", "-c", "echo foo")
23
+ expect(result).to exit_with(0)
24
+ expect(result.stdout).to match(/foo\n$/)
25
+ end
26
+ end