From 148901f3e9694bb09231d36570dc1208af3cdb6d Mon Sep 17 00:00:00 2001 From: Artem Date: Fri, 22 Jun 2018 20:44:14 +1000 Subject: [PATCH 1/4] Fixing Fog::Server user/sshkey workflow For some reason those were abandoned in 1.0, so core examples no longer worked. E.g. the following no longer provisioned the keys properly: server = connection.servers.create( :name => "fog-smoke-test-#{Time.now.to_i}", :disks => [disk], :machine_type => "n1-standard-1", :private_key_path => File.expand_path("~/.ssh/id_rsa"), :public_key_path => File.expand_path("~/.ssh/id_rsa.pub"), :zone => "us-central1-f", :username => ENV["USER"], :tags => ["fog"], :service_accounts => { :scopes => %w(sql-admin bigquery https://www.googleapis.com/auth/compute) } ) --- lib/fog/compute/google/models/server.rb | 5 +++++ lib/fog/compute/google/models/servers.rb | 7 +++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/fog/compute/google/models/server.rb b/lib/fog/compute/google/models/server.rb index 5570e30794..be1da8c074 100644 --- a/lib/fog/compute/google/models/server.rb +++ b/lib/fog/compute/google/models/server.rb @@ -445,6 +445,11 @@ def save(username: nil, public_key: nil) requires :disks requires :zone + generate_ssh_key_metadata(self.username, self.public_key) if self.public_key + + # XXX HACK This is a relic of 1.0 change that for some reason added those arguments + # to `save` method. This is left in place to keep things backwards-compatible + # TODO(2.0): Remove arguments from save generate_ssh_key_metadata(username, public_key) if public_key options = attributes.reject { |_, v| v.nil? } diff --git a/lib/fog/compute/google/models/servers.rb b/lib/fog/compute/google/models/servers.rb index d9a03934ea..37383282b6 100644 --- a/lib/fog/compute/google/models/servers.rb +++ b/lib/fog/compute/google/models/servers.rb @@ -43,9 +43,6 @@ def get(identity, zone = nil) end def bootstrap(public_key_path: nil, **opts) - user = ENV["USER"] - public_key = get_public_key(public_key_path) - name = "fog-#{Time.now.to_i}" zone_name = "us-central1-f" @@ -69,7 +66,9 @@ def bootstrap(public_key_path: nil, **opts) data = opts.merge( :name => name, :zone => zone_name, - :disks => disks + :disks => disks, + :public_key_path => get_public_key(public_key_path), + :username => ENV["USER"] ) data[:machine_type] = "n1-standard-1" unless data[:machine_type] From b3894316543276438bb20033ba88a63e610431a1 Mon Sep 17 00:00:00 2001 From: Artem Date: Fri, 22 Jun 2018 20:59:23 +1000 Subject: [PATCH 2/4] Update changelog --- CHANGELOG.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d2fd4d615..4affde25f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,25 @@ All notable changes to this project will be documented in this file. The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## Next release (1.6.0) + +### User-facing + +#### Added + +- \#361 `Fog::Compute::Google::Server` now recognises `network_ip` attribute to specify internal IP [mattimatti] + +#### Fixed + +- \#359 Fix whitespace escaping in XML Storage methods [temikus] +- \#366 Fixing `Server` model to properly accept `:private_key_path` and `:public_key_path` attributes again. [temikus] + +### Development changes + +#### Fixed + +- \#363 Fixed flaky Monitoring tests [temikus] + ## 1.5.0 ### User-facing From c053a0abafdb1cf33e3d32f456f3952da445fb4f Mon Sep 17 00:00:00 2001 From: Artem Date: Sat, 23 Jun 2018 11:01:33 +1000 Subject: [PATCH 3/4] Add unit test for .public_key To make sure Fog::Compute::Google::Server properly processes ssh keys and responds to Fog::Compute::Server core methods. --- test/unit/compute/test_server.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/unit/compute/test_server.rb diff --git a/test/unit/compute/test_server.rb b/test/unit/compute/test_server.rb new file mode 100644 index 0000000000..425c3b0c47 --- /dev/null +++ b/test/unit/compute/test_server.rb @@ -0,0 +1,30 @@ +require "helpers/test_helper" +# require testing stuff + +class UnitTestServer < MiniTest::Test + + def setup + Fog.mock! + @client = Fog::Compute.new(:provider => "Google", :google_project => "foo") + end + + def teardown + Fog.unmock! + end + + def test_if_server_accepts_ssh_keys + key = "ssh-rsa IAMNOTAREALSSHKEYAMA== user@host.subdomain.example.com" + + File.stub :read, key do + server = Fog::Compute::Google::Server.new( + :name => "foo", + :machine_type => "bar", + :disks => ["baz"], + :zone => "foo", + :public_key_path => key + ) + assert_equal(server.public_key, key, + "Fog::Compute::Google::Server loads public_key properly") + end + end +end \ No newline at end of file From ee550ffdf053debcf494909bfbcf43a44e3ce959 Mon Sep 17 00:00:00 2001 From: Artem Date: Sat, 23 Jun 2018 11:02:34 +1000 Subject: [PATCH 4/4] Fix XML test class name --- test/unit/compute/test_server.rb | 14 ++++++-------- test/unit/storage/test_xml_requests.rb | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/test/unit/compute/test_server.rb b/test/unit/compute/test_server.rb index 425c3b0c47..4f6c02531a 100644 --- a/test/unit/compute/test_server.rb +++ b/test/unit/compute/test_server.rb @@ -1,8 +1,6 @@ require "helpers/test_helper" -# require testing stuff class UnitTestServer < MiniTest::Test - def setup Fog.mock! @client = Fog::Compute.new(:provider => "Google", :google_project => "foo") @@ -17,14 +15,14 @@ def test_if_server_accepts_ssh_keys File.stub :read, key do server = Fog::Compute::Google::Server.new( - :name => "foo", - :machine_type => "bar", - :disks => ["baz"], - :zone => "foo", - :public_key_path => key + :name => "foo", + :machine_type => "bar", + :disks => ["baz"], + :zone => "foo", + :public_key_path => key ) assert_equal(server.public_key, key, "Fog::Compute::Google::Server loads public_key properly") end end -end \ No newline at end of file +end diff --git a/test/unit/storage/test_xml_requests.rb b/test/unit/storage/test_xml_requests.rb index 6984e55c52..b56ab9167d 100644 --- a/test/unit/storage/test_xml_requests.rb +++ b/test/unit/storage/test_xml_requests.rb @@ -1,6 +1,6 @@ require "helpers/test_helper" -class UnitTestServer < MiniTest::Test +class UnitTestXMLRequests < MiniTest::Test def setup Fog.mock! @client = Fog::Storage.new(provider: "google",