fog-google 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +53 -0
- data/CONTRIBUTING.md +9 -1
- data/MIGRATING.md +11 -0
- data/README.md +16 -2
- data/ci/pipeline.yml +31 -1
- data/examples/bootstrap.rb +18 -9
- data/lib/fog/compute/google/models/server.rb +9 -0
- data/lib/fog/compute/google/models/servers.rb +21 -12
- data/lib/fog/compute/google/models/ssl_certificate.rb +1 -1
- data/lib/fog/google/models/sql/instance.rb +19 -4
- data/lib/fog/google/models/sql/user.rb +9 -3
- data/lib/fog/google/requests/sql/insert_instance.rb +2 -2
- data/lib/fog/google/version.rb +1 -1
- data/lib/fog/storage/google_xml/utils.rb +1 -1
- data/tasks/lint.rake +6 -0
- data/tasks/test.rake +21 -8
- data/test/helpers/integration_test_helper.rb +1 -1
- data/test/integration/compute/test_disk_types.rb +6 -11
- data/test/integration/compute/test_servers.rb +35 -1
- data/test/integration/factories/sql_v1_certs_factory.rb +20 -0
- data/test/integration/factories/sql_v1_instances_factory.rb +19 -0
- data/test/integration/factories/sql_v1_users_factory.rb +20 -0
- data/test/integration/factories/sql_v2_instances_factory.rb +19 -0
- data/test/integration/monitoring/test_timeseries.rb +6 -8
- data/test/integration/sql/{test_flags.rb → test_common_flags.rb} +1 -1
- data/test/integration/sql/{test_tiers.rb → test_common_tiers.rb} +5 -13
- data/test/integration/sql/test_v1_certs.rb +50 -0
- data/test/integration/sql/test_v1_instances.rb +31 -0
- data/test/integration/sql/test_v1_users.rb +37 -0
- data/test/integration/sql/test_v2_instances.rb +81 -0
- data/test/unit/compute/test_server.rb +28 -0
- data/test/unit/storage/test_xml_requests.rb +24 -0
- metadata +27 -12
- data/test/integration/sql/sql_instances_shared.rb +0 -57
- data/test/integration/sql/test_instances.rb +0 -97
- data/test/integration/sql/test_instances_second_gen.rb +0 -88
data/lib/fog/google/version.rb
CHANGED
@@ -30,7 +30,7 @@ module Fog
|
|
30
30
|
|
31
31
|
def host_path_query(params, expires)
|
32
32
|
params[:headers]["Date"] = expires.to_i
|
33
|
-
params[:path] =
|
33
|
+
params[:path] = Fog::Google.escape(params[:path]).gsub("%2F", "/")
|
34
34
|
query = [params[:query]].compact
|
35
35
|
query << "GoogleAccessId=#{@google_storage_access_key_id}"
|
36
36
|
query << "Signature=#{CGI.escape(signature(params))}"
|
data/tasks/lint.rake
CHANGED
data/tasks/test.rake
CHANGED
@@ -17,7 +17,8 @@ namespace :test do
|
|
17
17
|
multitask :parallel => ["test:compute",
|
18
18
|
"test:monitoring",
|
19
19
|
"test:pubsub",
|
20
|
-
"test:
|
20
|
+
"test:sqlv1",
|
21
|
+
"test:sqlv2",
|
21
22
|
"test:storage"]
|
22
23
|
|
23
24
|
Rake::TestTask.new do |t|
|
@@ -33,7 +34,7 @@ namespace :test do
|
|
33
34
|
t.name = "compute"
|
34
35
|
t.description = "Run Compute API tests"
|
35
36
|
t.libs << "test"
|
36
|
-
t.pattern = FileList[
|
37
|
+
t.pattern = FileList["test/integration/compute/test_*.rb"]
|
37
38
|
t.warning = false
|
38
39
|
t.verbose = true
|
39
40
|
end
|
@@ -42,7 +43,7 @@ namespace :test do
|
|
42
43
|
t.name = "monitoring"
|
43
44
|
t.description = "Run Monitoring API tests"
|
44
45
|
t.libs << "test"
|
45
|
-
t.pattern = FileList[
|
46
|
+
t.pattern = FileList["test/integration/monitoring/test_*.rb"]
|
46
47
|
t.warning = false
|
47
48
|
t.verbose = true
|
48
49
|
end
|
@@ -51,16 +52,28 @@ namespace :test do
|
|
51
52
|
t.name = "pubsub"
|
52
53
|
t.description = "Run PubSub API tests"
|
53
54
|
t.libs << "test"
|
54
|
-
t.pattern = FileList[
|
55
|
+
t.pattern = FileList["test/integration/pubsub/test_*.rb"]
|
56
|
+
t.warning = false
|
57
|
+
t.verbose = true
|
58
|
+
end
|
59
|
+
|
60
|
+
desc "Run all SQL API tests"
|
61
|
+
task :sql => [:sqlv1, :sqlv2]
|
62
|
+
|
63
|
+
Rake::TestTask.new do |t|
|
64
|
+
t.name = "sqlv1"
|
65
|
+
t.description = "Run SQLv1 API tests"
|
66
|
+
t.libs << "test"
|
67
|
+
t.pattern = FileList["test/integration/sql/test_common*.rb", "test/integration/sql/test_v1*.rb"]
|
55
68
|
t.warning = false
|
56
69
|
t.verbose = true
|
57
70
|
end
|
58
71
|
|
59
72
|
Rake::TestTask.new do |t|
|
60
|
-
t.name = "
|
61
|
-
t.description = "Run
|
73
|
+
t.name = "sqlv2"
|
74
|
+
t.description = "Run SQLv2 API tests"
|
62
75
|
t.libs << "test"
|
63
|
-
t.pattern = FileList[
|
76
|
+
t.pattern = FileList["test/integration/sql/test_v2*.rb"]
|
64
77
|
t.warning = false
|
65
78
|
t.verbose = true
|
66
79
|
end
|
@@ -69,7 +82,7 @@ namespace :test do
|
|
69
82
|
t.name = "storage"
|
70
83
|
t.description = "Run Storage API tests"
|
71
84
|
t.libs << "test"
|
72
|
-
t.pattern = FileList[
|
85
|
+
t.pattern = FileList["test/integration/storage/test_*.rb"]
|
73
86
|
t.warning = false
|
74
87
|
t.verbose = true
|
75
88
|
end
|
@@ -18,7 +18,7 @@ TEST_RAW_DISK_SOURCE = "http://storage.googleapis.com/fog-test-bucket/fog-test-r
|
|
18
18
|
TEST_SQL_TIER_FIRST = "D1".freeze
|
19
19
|
TEST_SQL_REGION_FIRST = "us-central".freeze
|
20
20
|
|
21
|
-
TEST_SQL_TIER_SECOND = "db-
|
21
|
+
TEST_SQL_TIER_SECOND = "db-n1-standard-1".freeze
|
22
22
|
TEST_SQL_REGION_SECOND = TEST_REGION
|
23
23
|
|
24
24
|
class FogIntegrationTest < MiniTest::Test
|
@@ -2,23 +2,18 @@ require "helpers/integration_test_helper"
|
|
2
2
|
|
3
3
|
class TestDiskTypes < FogIntegrationTest
|
4
4
|
NAMES = %w(local-ssd pd-ssd pd-standard).freeze
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
https://www.googleapis.com/compute/v1/projects/graphite-fog/zones/europe-west1-b
|
10
|
-
https://www.googleapis.com/compute/v1/projects/graphite-fog/zones/europe-west1-c
|
11
|
-
https://www.googleapis.com/compute/v1/projects/graphite-fog/zones/europe-west1-d
|
12
|
-
https://www.googleapis.com/compute/v1/projects/graphite-fog/zones/asia-east1-a
|
13
|
-
https://www.googleapis.com/compute/v1/projects/graphite-fog/zones/asia-east1-b
|
14
|
-
https://www.googleapis.com/compute/v1/projects/graphite-fog/zones/asia-east1-c).freeze
|
5
|
+
# Testing in one random zone per region (region list as of May 2018)
|
6
|
+
ZONES = %w(asia-east1-a asia-northeast1-b asia-south1-c asia-southeast1-a australia-southeast1-b
|
7
|
+
europe-west1-c europe-west2-a europe-west3-b europe-west4-c northamerica-northeast1-a
|
8
|
+
southamerica-east1-b us-central1-c us-east1-b us-east4-a us-west1-c).freeze
|
15
9
|
|
16
10
|
def setup
|
17
11
|
@subject = Fog::Compute[:google].disk_types
|
18
12
|
end
|
19
13
|
|
20
14
|
def test_all
|
21
|
-
assert_operator(@subject.all.size, :>=,
|
15
|
+
assert_operator(@subject.all.size, :>=, NAMES.size * ZONES.size,
|
16
|
+
"Number of all disk type references should be greater or equal to test zones * disk types")
|
22
17
|
end
|
23
18
|
|
24
19
|
def test_get
|
@@ -15,6 +15,40 @@ class TestServers < FogIntegrationTest
|
|
15
15
|
server.wait_for { ready? }
|
16
16
|
server.set_metadata({ "foo" => "bar", "baz" => "foo" }, false)
|
17
17
|
assert_equal [{ :key => "foo", :value => "bar" },
|
18
|
-
{ :key=>"baz", :value=>"foo" }], server.metadata[:items]
|
18
|
+
{ :key => "baz", :value => "foo" }], server.metadata[:items]
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_bootstrap
|
22
|
+
key = "ssh-rsa IAMNOTAREALSSHKEYAMA== user@host.subdomain.example.com"
|
23
|
+
user = "username"
|
24
|
+
|
25
|
+
File.stub :read, key do
|
26
|
+
# Name is set this way so it will be cleaned up by CollectionFactory
|
27
|
+
# Public_key_path is set to avoid stubbing out File.exist?
|
28
|
+
server = @subject.bootstrap(:name => "#{CollectionFactory::PREFIX}-#{Time.now.to_i}",
|
29
|
+
:username => user,
|
30
|
+
:public_key_path => "foo")
|
31
|
+
boot_disk = server.disks.detect { |disk| disk[:boot] }
|
32
|
+
|
33
|
+
assert_equal("RUNNING", server.status, "Bootstrapped server should be running")
|
34
|
+
assert_equal(key, server.public_key, "Bootstrapped server should have a public key set")
|
35
|
+
assert_equal(user, server.username, "Bootstrapped server should have user set to #{user}")
|
36
|
+
assert(boot_disk[:auto_delete], "Bootstrapped server should have disk set to autodelete")
|
37
|
+
|
38
|
+
network_adapter = server.network_interfaces.detect { |x| x.has_key?(:access_configs) }
|
39
|
+
|
40
|
+
refute_nil(network_adapter[:access_configs].detect { |x| x[:nat_ip] },
|
41
|
+
"Bootstrapped server should have an external ip by default")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_bootstrap_fail
|
46
|
+
# Pretend the ssh key does not exist
|
47
|
+
File.stub :exist?, nil do
|
48
|
+
assert_raises(Fog::Errors::Error) {
|
49
|
+
@subject.bootstrap(:name => "#{CollectionFactory::PREFIX}-#{Time.now.to_i}",
|
50
|
+
:public_key_path => nil)
|
51
|
+
}
|
52
|
+
end
|
19
53
|
end
|
20
54
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "integration/factories/collection_factory"
|
2
|
+
require "integration/factories/sql_v1_instances_factory"
|
3
|
+
|
4
|
+
class SqlV1CertsFactory < CollectionFactory
|
5
|
+
def initialize(example)
|
6
|
+
@instances = SqlV1InstancesFactory.new(example)
|
7
|
+
super(Fog::Google[:sql].ssl_certs, example)
|
8
|
+
end
|
9
|
+
|
10
|
+
def cleanup
|
11
|
+
# Certs will be cleaned up with the test instance.
|
12
|
+
@instances.cleanup
|
13
|
+
end
|
14
|
+
|
15
|
+
def params
|
16
|
+
# Certificate name should not be longer than 16 characters
|
17
|
+
{ :common_name => resource_name,
|
18
|
+
:instance => @instances.create.name }
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "integration/factories/collection_factory"
|
2
|
+
|
3
|
+
class SqlV1InstancesFactory < CollectionFactory
|
4
|
+
def initialize(example)
|
5
|
+
super(Fog::Google[:sql].instances, example)
|
6
|
+
end
|
7
|
+
|
8
|
+
def cleanup
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def params
|
13
|
+
# Name has a time suffix due to SQL resources API objects having
|
14
|
+
# a _very_ long life on the backend (n(days)) after deletion.
|
15
|
+
{ :name => "#{resource_name}-#{Time.now.to_i}",
|
16
|
+
:region => TEST_SQL_REGION_FIRST,
|
17
|
+
:tier => TEST_SQL_TIER_FIRST }
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "integration/factories/collection_factory"
|
2
|
+
require "integration/factories/sql_v1_instances_factory"
|
3
|
+
|
4
|
+
class SqlV1UsersFactory < CollectionFactory
|
5
|
+
def initialize(example)
|
6
|
+
@instances = SqlV1InstancesFactory.new(example)
|
7
|
+
super(Fog::Google[:sql].users, example)
|
8
|
+
end
|
9
|
+
|
10
|
+
def cleanup
|
11
|
+
# Users will be cleaned up with the test instance.
|
12
|
+
@instances.cleanup
|
13
|
+
end
|
14
|
+
|
15
|
+
def params
|
16
|
+
# Username should not be longer than 16 characters
|
17
|
+
{ :name => resource_name[0..15],
|
18
|
+
:instance => @instances.create.name }
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "integration/factories/collection_factory"
|
2
|
+
|
3
|
+
class SqlV2InstancesFactory < CollectionFactory
|
4
|
+
def initialize(example)
|
5
|
+
super(Fog::Google[:sql].instances, example)
|
6
|
+
end
|
7
|
+
|
8
|
+
def cleanup
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def params
|
13
|
+
# Name has a time suffix due to SQL resources API objects having
|
14
|
+
# a _very_ long life on the backend (n(days)) after deletion.
|
15
|
+
{ :name => "#{resource_name}-#{Time.now.to_i}",
|
16
|
+
:region => TEST_SQL_REGION_SECOND,
|
17
|
+
:tier => TEST_SQL_TIER_SECOND }
|
18
|
+
end
|
19
|
+
end
|
@@ -5,7 +5,6 @@ class TestMetricDescriptors < FogIntegrationTest
|
|
5
5
|
# Retriable is used to wrap each request in this test due to Stackdriver API being slow with
|
6
6
|
# metric propagation (sometimes 80+ seconds) and client returning
|
7
7
|
# Google::Apis::ClientError: badRequest if the metric hasn't yet been created instead of a 404.
|
8
|
-
NOT_READY_REGEX = /The provided filter doesn't refer to any known metric./
|
9
8
|
RETRIABLE_TRIES = 3
|
10
9
|
RETRIABLE_BASE_INTERVAL = 30
|
11
10
|
TEST_METRIC_PREFIX = "custom.googleapis.com/fog-google-test/timeseries".freeze
|
@@ -52,7 +51,8 @@ class TestMetricDescriptors < FogIntegrationTest
|
|
52
51
|
assert_empty(resp.to_h)
|
53
52
|
|
54
53
|
# Wait for metric to be created
|
55
|
-
|
54
|
+
# TODO: Dedup retries into a helper method
|
55
|
+
Retriable.retriable(on: Google::Apis::ClientError,
|
56
56
|
tries: RETRIABLE_TRIES,
|
57
57
|
base_interval: RETRIABLE_BASE_INTERVAL) do
|
58
58
|
@client.list_timeseries(
|
@@ -67,7 +67,7 @@ class TestMetricDescriptors < FogIntegrationTest
|
|
67
67
|
).time_series
|
68
68
|
end
|
69
69
|
|
70
|
-
series = Retriable.retriable(on:
|
70
|
+
series = Retriable.retriable(on: Google::Apis::ClientError,
|
71
71
|
tries: RETRIABLE_TRIES,
|
72
72
|
base_interval: RETRIABLE_BASE_INTERVAL) do
|
73
73
|
@client.timeseries_collection.all(
|
@@ -132,7 +132,7 @@ class TestMetricDescriptors < FogIntegrationTest
|
|
132
132
|
# Wait for metric to be created
|
133
133
|
# Retriable is used instead of wait_for due to API client returning Google::Apis::ClientError: badRequest if the
|
134
134
|
# metric hasn't yet been created
|
135
|
-
Retriable.retriable(on:
|
135
|
+
Retriable.retriable(on: Google::Apis::ClientError,
|
136
136
|
tries: RETRIABLE_TRIES,
|
137
137
|
base_interval: RETRIABLE_BASE_INTERVAL) do
|
138
138
|
@client.list_timeseries(
|
@@ -142,7 +142,7 @@ class TestMetricDescriptors < FogIntegrationTest
|
|
142
142
|
end
|
143
143
|
|
144
144
|
# Test page size
|
145
|
-
resp = Retriable.retriable(on:
|
145
|
+
resp = Retriable.retriable(on: Google::Apis::ClientError,
|
146
146
|
tries: RETRIABLE_TRIES,
|
147
147
|
base_interval: RETRIABLE_BASE_INTERVAL) do
|
148
148
|
@client.list_timeseries(
|
@@ -168,7 +168,7 @@ class TestMetricDescriptors < FogIntegrationTest
|
|
168
168
|
"expected different timeseries when using page_token")
|
169
169
|
|
170
170
|
# Test filter
|
171
|
-
series = Retriable.retriable(on:
|
171
|
+
series = Retriable.retriable(on: Google::Apis::ClientError,
|
172
172
|
tries: RETRIABLE_TRIES,
|
173
173
|
base_interval: RETRIABLE_BASE_INTERVAL) do
|
174
174
|
@client.timeseries_collection.all(
|
@@ -191,9 +191,7 @@ class TestMetricDescriptors < FogIntegrationTest
|
|
191
191
|
filter: "metric.type = starts_with(\"#{TEST_METRIC_PREFIX}\")"
|
192
192
|
)
|
193
193
|
unless list_resp.metric_descriptors.nil?
|
194
|
-
puts "Found #{list_resp.metric_descriptors.size} test metric descriptors."
|
195
194
|
list_resp.metric_descriptors.each do |md|
|
196
|
-
puts "deleting #{md.type}..."
|
197
195
|
@client.monitoring.delete_project_metric_descriptor(md.name)
|
198
196
|
end
|
199
197
|
end
|
@@ -1,24 +1,16 @@
|
|
1
1
|
require "helpers/integration_test_helper"
|
2
2
|
|
3
|
-
class
|
3
|
+
class TestCommonTiers < FogIntegrationTest
|
4
4
|
def setup
|
5
|
-
@
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_list
|
9
|
-
resp = @client.list_tiers
|
10
|
-
|
11
|
-
assert_operator(resp.items.size, :>, 0,
|
12
|
-
"response tiers count should be positive")
|
13
|
-
_sanity_check_tier(resp.items.first)
|
5
|
+
@subject = Fog::Google[:sql].tiers
|
14
6
|
end
|
15
7
|
|
16
8
|
def test_all
|
17
|
-
|
9
|
+
tiers = @subject.all
|
18
10
|
|
19
|
-
assert_operator(
|
11
|
+
assert_operator(tiers.size, :>, 0,
|
20
12
|
"tier count should be positive")
|
21
|
-
_sanity_check_tier(
|
13
|
+
_sanity_check_tier(tiers.first)
|
22
14
|
end
|
23
15
|
|
24
16
|
def _sanity_check_tier(tier)
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "helpers/integration_test_helper"
|
2
|
+
require "integration/factories/sql_v1_certs_factory"
|
3
|
+
|
4
|
+
class TestSQLV1Certs < FogIntegrationTest
|
5
|
+
# This test doesn't include TestCollection as certs are not an independent resource.
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@subject = Fog::Google[:sql].ssl_certs
|
9
|
+
@factory = SqlV1CertsFactory.new(namespaced_name)
|
10
|
+
@client = Fog::Google::SQL.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
@factory.cleanup
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_ssl_certs
|
18
|
+
# Create an instance and an SSL cert
|
19
|
+
ssl_cert = @factory.create
|
20
|
+
instance_name = ssl_cert.instance
|
21
|
+
|
22
|
+
# Create a second cert and attach to the same instance
|
23
|
+
ssl_cert2 = @subject.new(:common_name => "#{ssl_cert.common_name}-2",
|
24
|
+
:instance => instance_name)
|
25
|
+
ssl_cert2.save
|
26
|
+
|
27
|
+
# Verify it can be retrieved
|
28
|
+
@subject.get(instance_name, ssl_cert2.sha1_fingerprint).tap do |result|
|
29
|
+
assert_equal(ssl_cert2.common_name, result.common_name)
|
30
|
+
assert_equal("sql#sslCert", result.kind)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Verify instance returns 2 certs
|
34
|
+
list_result = @subject.all(instance_name)
|
35
|
+
assert_equal(2, list_result.size,
|
36
|
+
"expected 2 SSL certs")
|
37
|
+
|
38
|
+
# Delete one cert
|
39
|
+
ssl_cert2.destroy(:async => false)
|
40
|
+
list_result = @subject.all(instance_name)
|
41
|
+
assert_equal(1, list_result.size,
|
42
|
+
"expected one less SSL cert after deletion")
|
43
|
+
|
44
|
+
# Test if SSL config is reset correctly
|
45
|
+
instance = @client.instances.get(instance_name)
|
46
|
+
instance.reset_ssl_config(:async => false)
|
47
|
+
assert_equal(0, @subject.all(instance_name).size,
|
48
|
+
"expected no SSL certs after reset")
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "helpers/integration_test_helper"
|
2
|
+
require "integration/factories/sql_v1_instances_factory"
|
3
|
+
|
4
|
+
class TestSQLV1Instances < FogIntegrationTest
|
5
|
+
include TestCollection
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@subject = Fog::Google[:sql].instances
|
9
|
+
@factory = SqlV1InstancesFactory.new(namespaced_name)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_update
|
13
|
+
instance = @factory.create
|
14
|
+
|
15
|
+
settings_version = instance.settings_version
|
16
|
+
labels = {
|
17
|
+
:foo => "bar"
|
18
|
+
}
|
19
|
+
instance.settings[:user_labels] = labels
|
20
|
+
instance.save
|
21
|
+
|
22
|
+
updated = @subject.get(instance.name)
|
23
|
+
assert_equal(labels, updated.settings[:user_labels])
|
24
|
+
assert_operator(updated.settings_version, :>, settings_version)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_default_settings
|
28
|
+
instance = @factory.create
|
29
|
+
assert_equal([], instance.ssl_certs, "new instance should have 0 initial ssl certs")
|
30
|
+
end
|
31
|
+
end
|