2013-07-24 21:46:20 -04:00
|
|
|
def test
|
|
|
|
connection = Fog::Compute.new({ :provider => "Google" })
|
|
|
|
|
2013-12-18 07:11:25 -05:00
|
|
|
name = "fog-smoke-test-#{Time.now.to_i}"
|
|
|
|
|
|
|
|
disk = connection.disks.create({
|
|
|
|
:name => name,
|
|
|
|
:size_gb => 10,
|
|
|
|
:zone_name => 'us-central1-a',
|
|
|
|
:source_image => 'debian-7-wheezy-v20131120',
|
|
|
|
})
|
|
|
|
|
|
|
|
disk.wait_for { disk.ready? }
|
|
|
|
|
2013-07-24 21:46:20 -04:00
|
|
|
server = connection.servers.create(defaults = {
|
|
|
|
:name => "fog-smoke-test-#{Time.now.to_i}",
|
2013-12-18 07:11:25 -05:00
|
|
|
:disks => [disk],
|
2013-07-25 15:22:12 -04:00
|
|
|
:machine_type => "n1-standard-1",
|
|
|
|
:zone_name => "us-central1-a",
|
|
|
|
:private_key_path => File.expand_path("~/.ssh/id_rsa"),
|
|
|
|
:public_key_path => File.expand_path("~/.ssh/id_rsa.pub"),
|
|
|
|
:user => ENV['USER'],
|
2013-11-07 14:45:03 -05:00
|
|
|
:tags => ["fog"]
|
2013-07-24 21:46:20 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
# My own wait_for because it hides errors
|
|
|
|
duration = 0
|
|
|
|
interval = 5
|
|
|
|
timeout = 600
|
|
|
|
start = Time.now
|
|
|
|
until server.sshable? || duration > timeout
|
|
|
|
# puts duration
|
|
|
|
# puts " ----- "
|
2013-07-25 15:22:12 -04:00
|
|
|
|
|
|
|
server.reload
|
|
|
|
|
2013-07-24 21:46:20 -04:00
|
|
|
# p "ready?: #{server.ready?}"
|
|
|
|
# p "public_ip_address: #{server.public_ip_address.inspect}"
|
|
|
|
# p "public_key: #{server.public_key.inspect}"
|
|
|
|
# p "metadata: #{server.metadata.inspect}"
|
|
|
|
# p "sshable?: #{server.sshable?}"
|
|
|
|
|
|
|
|
sleep(interval.to_f)
|
|
|
|
duration = Time.now - start
|
|
|
|
end
|
|
|
|
|
|
|
|
raise "Could not bootstrap sshable server." unless server.ssh("whoami")
|
2014-03-16 03:06:27 -04:00
|
|
|
raise "Could not delete server." unless server.destroy
|
2013-07-24 21:46:20 -04:00
|
|
|
end
|