diff --git a/lib/fog/google/Rakefile b/lib/fog/google/Rakefile new file mode 100644 index 000000000..f20391122 --- /dev/null +++ b/lib/fog/google/Rakefile @@ -0,0 +1,17 @@ +namespace :google do + namespace :smoke do + + desc "Smoke tests for Google Compute Engine." + task :compute do + require 'fog' + + puts "These smoke tests assume you have a file at ~/.fog which has your credentials for connecting to GCE." + + Dir.glob("./examples/*.rb").each do |file| + puts "Running #{file}:" + require file + test() + end + end + end +end diff --git a/lib/fog/google/examples/bootstrap.rb b/lib/fog/google/examples/bootstrap.rb new file mode 100755 index 000000000..521ac32eb --- /dev/null +++ b/lib/fog/google/examples/bootstrap.rb @@ -0,0 +1,9 @@ +def test + connection = Fog::Compute.new({ :provider => "Google" }) + + server = connection.servers.bootstrap + server.wait_for { sshable? } + + raise "Could not bootstrap sshable server." unless server.ssh("whoami") + raise "Cloud note delete server." unless server.destroy +end diff --git a/lib/fog/google/examples/create.rb b/lib/fog/google/examples/create.rb new file mode 100755 index 000000000..0ce176ff6 --- /dev/null +++ b/lib/fog/google/examples/create.rb @@ -0,0 +1,35 @@ +def test + connection = Fog::Compute.new({ :provider => "Google" }) + + server = connection.servers.create(defaults = { + :name => "fog-smoke-test-#{Time.now.to_i}", + :image_name => "debian-7-wheezy-v20130522", + :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'], + }) + + # 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 " ----- " + # p server.reload + # 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") + raise "Cloud note delete server." unless server.destroy +end diff --git a/lib/fog/google/examples/eric-fail.rb b/lib/fog/google/examples/eric-fail.rb new file mode 100755 index 000000000..bfaa8624b --- /dev/null +++ b/lib/fog/google/examples/eric-fail.rb @@ -0,0 +1,19 @@ +def test + connection = Fog::Compute.new({ :provider => "Google" }) + + server = connection.servers.create(defaults = { + :name => "fog-smoke-test-#{Time.now.to_i}", + :image_name => "debian-7-wheezy-v20130617", + :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"), + :username => 'root', + :metadata => {'foo' => 'bar'} + }) + sleep(30) + + raise "Could not reload created server." unless server.reload + raise "Could not create sshable server." unless server.ssh("whoami") + raise "Cloud note delete server." unless server.destroy +end diff --git a/lib/fog/google/examples/launch_micro_instance.rb b/lib/fog/google/examples/launch_micro_instance.rb new file mode 100755 index 000000000..5ff8ca183 --- /dev/null +++ b/lib/fog/google/examples/launch_micro_instance.rb @@ -0,0 +1,23 @@ +def test + connection = Fog::Compute.new({ :provider => "Google" }) + time = Time.now.utc.to_i + disk = CONNECTION.disks.create({:name => 'foggydisk', :size => 10, :zone_name => 'us-central1-a', :image_name => 'centos-6-v20130522'}) + + disk.wait_for { disk.ready? } + puts 'disk ready' + disk = disk.get_as_boot_disk(true) + params = { + :name => "fog-smoke-test-#{Time.now.to_i}", + :machine_type => "f1-micro", + :zone_name => "us-central1-a", + :disks => [ disk ], + :kernel => 'gce-v20130522', + :user => ENV['USER'] + } + + server = CONNECTION.servers.bootstrap params + + raise "Could not bootstrap sshable server." unless server.ssh("whoami") + raise "Could not delete server." unless server.destroy + raise "Could not delete disk." unless disk.destroy +end diff --git a/lib/fog/google/examples/metadata.rb b/lib/fog/google/examples/metadata.rb new file mode 100755 index 000000000..c8680cedb --- /dev/null +++ b/lib/fog/google/examples/metadata.rb @@ -0,0 +1,19 @@ +def test + connection = Fog::Compute.new({ :provider => "Google" }) + server = connection.servers.create(defaults = { + :name => "fog-#{Time.now.to_i}", + :image_name => "debian-7-wheezy-v20130522", + :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"), + }) + + server.wait_for { ready? } + + server.metadata["test"] = "foo" + + raise "Metadata was not set." unless server.metadata["test"] == "foo" + raise "Could not delete server." unless server.destroy + raise "Could not delete disk." unless disk.destroy +end