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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -0
  3. data/CHANGELOG.md +53 -0
  4. data/CONTRIBUTING.md +9 -1
  5. data/MIGRATING.md +11 -0
  6. data/README.md +16 -2
  7. data/ci/pipeline.yml +31 -1
  8. data/examples/bootstrap.rb +18 -9
  9. data/lib/fog/compute/google/models/server.rb +9 -0
  10. data/lib/fog/compute/google/models/servers.rb +21 -12
  11. data/lib/fog/compute/google/models/ssl_certificate.rb +1 -1
  12. data/lib/fog/google/models/sql/instance.rb +19 -4
  13. data/lib/fog/google/models/sql/user.rb +9 -3
  14. data/lib/fog/google/requests/sql/insert_instance.rb +2 -2
  15. data/lib/fog/google/version.rb +1 -1
  16. data/lib/fog/storage/google_xml/utils.rb +1 -1
  17. data/tasks/lint.rake +6 -0
  18. data/tasks/test.rake +21 -8
  19. data/test/helpers/integration_test_helper.rb +1 -1
  20. data/test/integration/compute/test_disk_types.rb +6 -11
  21. data/test/integration/compute/test_servers.rb +35 -1
  22. data/test/integration/factories/sql_v1_certs_factory.rb +20 -0
  23. data/test/integration/factories/sql_v1_instances_factory.rb +19 -0
  24. data/test/integration/factories/sql_v1_users_factory.rb +20 -0
  25. data/test/integration/factories/sql_v2_instances_factory.rb +19 -0
  26. data/test/integration/monitoring/test_timeseries.rb +6 -8
  27. data/test/integration/sql/{test_flags.rb → test_common_flags.rb} +1 -1
  28. data/test/integration/sql/{test_tiers.rb → test_common_tiers.rb} +5 -13
  29. data/test/integration/sql/test_v1_certs.rb +50 -0
  30. data/test/integration/sql/test_v1_instances.rb +31 -0
  31. data/test/integration/sql/test_v1_users.rb +37 -0
  32. data/test/integration/sql/test_v2_instances.rb +81 -0
  33. data/test/unit/compute/test_server.rb +28 -0
  34. data/test/unit/storage/test_xml_requests.rb +24 -0
  35. metadata +27 -12
  36. data/test/integration/sql/sql_instances_shared.rb +0 -57
  37. data/test/integration/sql/test_instances.rb +0 -97
  38. data/test/integration/sql/test_instances_second_gen.rb +0 -88
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 95802f48e4fa5a610c96521c65d0a9bb2b33ce54
4
- data.tar.gz: 6ae1e7e9a6c7ed8a5a05736857219a6144a4e443
3
+ metadata.gz: 44ebad93a3aba93d0c9c8465a085e52688d340f7
4
+ data.tar.gz: 2543bae22b7ad7cc12108b4173c8806f67a3b838
5
5
  SHA512:
6
- metadata.gz: 9b8f524b235aaf667a4ecaf256a19ca038de9ca6db80e486a29c805dabc73d0cc5b2b95f6a5b17198c268c193a3939825ba6182f6122946ef2ba0ff5bb617c62
7
- data.tar.gz: cfa889ab0a734fd5165447f4b7b8234c14287f0e87f2ebae833fa9b34d355f218dcdca6abc89923af196b79c6f6c7ce9ab8c641021699e2a296488e37d144d41
6
+ metadata.gz: b76ea9d006ba75403d8d7d24f9c42904062dd6a620e42a7cf6d742e6d1f59739a97150230ee246468c0d11db751a908177e62228a3d9cb34dd1ae839ef6c1765
7
+ data.tar.gz: 64b0fa489bb69896c2abb0130e9671188e22660c006a957f6e788a902b383cb53f6f183be418d4159f196425dddfcb873cc1728584e8654c5b1543d63f7bbb4f
data/.rubocop.yml CHANGED
@@ -19,6 +19,10 @@ Style/FrozenStringLiteralComment:
19
19
  Style/HashSyntax:
20
20
  EnforcedStyle: no_mixed_keys
21
21
 
22
+ # Do not enforce %i syntax
23
+ Style/SymbolArray:
24
+ Enabled: false
25
+
22
26
  # HoundCI config
23
27
 
24
28
  AllCops:
data/CHANGELOG.md CHANGED
@@ -2,6 +2,41 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  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).
4
4
 
5
+ ## 1.6.0
6
+
7
+ ### User-facing
8
+
9
+ #### Changed
10
+
11
+ - \#338 `Fog::Google::SQL` resources are now created and destroyed synchronously by default.
12
+ You can override it in a standard manner by passing a parameter to async method, e.g.:
13
+ `Fog::Google::SQL::Instance.create(true)` [temikus]
14
+ - \#367 `Fog::Compute::Google::Server.bootstrap` changes [temikus]
15
+ - Now creates instances with disks that automatically delete on instance shutdown.
16
+ - Now creates instances with a public IP address by default.
17
+
18
+ #### Added
19
+
20
+ - \#361 `Fog::Compute::Google::Server` now recognises `network_ip` attribute to specify internal IP. [mattimatti]
21
+
22
+ #### Fixed
23
+
24
+ - \#338 Fixed SQL Users model workflow [temikus]
25
+ - \#359 Fix whitespace escaping in XML Storage methods [temikus]
26
+ - \#366 Fixing `Server` model to properly accept `:private_key_path` and `:public_key_path` attributes again. [temikus]
27
+ - \#367 `Fog::Compute::Google::Server.bootstrap` parameters are now properly merged with default ones. [tesmikus]
28
+
29
+ ### Development changes
30
+
31
+ #### Added
32
+
33
+ - \#338 Major refactor of SQLv1 and SQLv2 tests + a lot of small test fixes/improvements
34
+ (see PR/commit messages for full set of changes) [temikus]
35
+
36
+ #### Fixed
37
+
38
+ - \#363 Fixed flaky Monitoring tests [temikus]
39
+
5
40
  ## 1.5.0
6
41
 
7
42
  ### User-facing
@@ -110,3 +145,21 @@ PRs that change functionality: #212, #215, #203, #198, #201, #221, #222, #216
110
145
 
111
146
  Rapid-releasing 0.5.2 due to regression fixed by #190 still present in v0.5.1
112
147
  We encourage people using 0.5.1 to upgrade.
148
+
149
+ ## Template to use
150
+
151
+ ## Next release
152
+
153
+ ### User-facing
154
+
155
+ #### Changed
156
+
157
+ #### Added
158
+
159
+ #### Fixed
160
+
161
+ ### Development changes
162
+
163
+ #### Added
164
+
165
+ #### Fixed
data/CONTRIBUTING.md CHANGED
@@ -65,6 +65,13 @@ Then you can run all the live tests:
65
65
  $ rake test
66
66
  ```
67
67
 
68
+ or just one API:
69
+
70
+ ```
71
+ $ rake test:compute
72
+ ```
73
+ (See `rake -T` for all available tasks)
74
+
68
75
  or just one file:
69
76
 
70
77
  ```shell
@@ -79,7 +86,8 @@ For more information on transition, read [#50](https://github.com/fog/fog-google
79
86
 
80
87
  #### Continuous integration
81
88
 
82
- Currently Google maintains a [Concourse CI](https://concourse-ci.org/) server, running a pipeline defined in `ci` folder. It automatically runs all integration tests against every pull-request marked with `integration` label.
89
+ Currently Google maintains a [Concourse CI](https://concourse-ci.org/) server, running a pipeline defined in `ci` folder.
90
+ It automatically runs all integration tests against every pull-request marked with `integration` label.
83
91
 
84
92
  For more information on the pipeline please refer to the [ci README](https://github.com/fog/fog-google/blob/master/ci/README.md).
85
93
 
data/MIGRATING.md ADDED
@@ -0,0 +1,11 @@
1
+ ## fog-google 2.0 -> 3.0:
2
+
3
+ ### SQL:
4
+ - `Fog::Google::SQL::Instance` resources are created synchronously by default.
5
+ You can override it with `Fog::Google::SQL::Instance.create(true)`
6
+
7
+ - `Fog::Google::SQL::Instance.destroy` - `async:` named parameter has been replaced with `async` positional parameter.
8
+ You should now call `Fog::Google::SQL::Instance.destroy(false)` to disable async flag, as with other Fog::Google models.
9
+
10
+ - `Fog::Google::SQL::User.destroy` - `async:` named parameter has been replaced with `async` positional parameter.
11
+ You should now call `Fog::Google::SQL::User.destroy(false)` to disable async flag, as with other Fog::Google models.
data/README.md CHANGED
@@ -8,6 +8,7 @@ The main maintainers for the Google sections are @icco, @Temikus and @plribeiro3
8
8
 
9
9
  **As of v1.0.0, fog-google includes google-api-client as a dependency**
10
10
 
11
+ **See [MIGRATING.md](MIGRATING.MD) for migration between major versions**
11
12
 
12
13
  ## Storage
13
14
 
@@ -65,9 +66,22 @@ $ gem install fog-google
65
66
 
66
67
  ## Testing
67
68
 
68
- The tests in `tests` are deprecated. We are currently working on a migration of tests to `minitest`.
69
+ Integration tests can be kicked off via following rake tasks.
70
+ **Important note:** As those tests are running against real API's YOU WILL BE BILLED.
69
71
 
70
- For your test to be tested with real credentials, a repo maintainer may add the label `integrate` to your PR to run integration tests.
72
+ ```
73
+ rake test # Run all integration tests
74
+ rake test:parallel # Run all integration tests in parallel
75
+
76
+ rake test:compute # Run Compute API tests
77
+ rake test:monitoring # Run Monitoring API tests
78
+ rake test:pubsub # Run PubSub API tests
79
+ rake test:sql # Run SQL API tests
80
+ rake test:storage # Run Storage API tests
81
+ ```
82
+
83
+ Since some resources can be expensive to test, we have a self-hosted CI server.
84
+ Due to security considerations a repo maintainer needs to add the label `integrate` to kick off the CI.
71
85
 
72
86
  ## Setup
73
87
 
data/ci/pipeline.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  jobs:
2
2
  - name: integration-tests-compute
3
+ serial: true
3
4
  plan:
4
5
  - get: fog-google-src
5
6
  resource: pull-request
@@ -15,8 +16,14 @@ jobs:
15
16
  google_project: {{google_project}}
16
17
  google_json_key_data: {{google_json_key_data}}
17
18
  google_client_email: {{google_client_email}}
18
-
19
+ on_failure:
20
+ put: pull-request
21
+ params:
22
+ path: fog-google-src
23
+ status: failure
24
+
19
25
  - name: integration-tests-monitoring
26
+ serial: true
20
27
  plan:
21
28
  - get: fog-google-src
22
29
  resource: pull-request
@@ -32,8 +39,14 @@ jobs:
32
39
  google_project: {{google_project}}
33
40
  google_json_key_data: {{google_json_key_data}}
34
41
  google_client_email: {{google_client_email}}
42
+ on_failure:
43
+ put: pull-request
44
+ params:
45
+ path: fog-google-src
46
+ status: failure
35
47
 
36
48
  - name: integration-tests-pubsub
49
+ serial: true
37
50
  plan:
38
51
  - get: fog-google-src
39
52
  resource: pull-request
@@ -49,8 +62,14 @@ jobs:
49
62
  google_project: {{google_project}}
50
63
  google_json_key_data: {{google_json_key_data}}
51
64
  google_client_email: {{google_client_email}}
65
+ on_failure:
66
+ put: pull-request
67
+ params:
68
+ path: fog-google-src
69
+ status: failure
52
70
 
53
71
  - name: integration-tests-sql
72
+ serial: true
54
73
  plan:
55
74
  - get: fog-google-src
56
75
  resource: pull-request
@@ -66,8 +85,14 @@ jobs:
66
85
  google_project: {{google_project}}
67
86
  google_json_key_data: {{google_json_key_data}}
68
87
  google_client_email: {{google_client_email}}
88
+ on_failure:
89
+ put: pull-request
90
+ params:
91
+ path: fog-google-src
92
+ status: failure
69
93
 
70
94
  - name: integration-tests-storage
95
+ serial: true
71
96
  plan:
72
97
  - get: fog-google-src
73
98
  resource: pull-request
@@ -83,6 +108,11 @@ jobs:
83
108
  google_project: {{google_project}}
84
109
  google_json_key_data: {{google_json_key_data}}
85
110
  google_client_email: {{google_client_email}}
111
+ on_failure:
112
+ put: pull-request
113
+ params:
114
+ path: fog-google-src
115
+ status: failure
86
116
 
87
117
  - name: github-pr-aggregator
88
118
  plan:
@@ -1,18 +1,27 @@
1
1
  # All examples presume that you have a ~/.fog credentials file set up.
2
2
  # More info on it can be found here: http://fog.io/about/getting_started.html
3
+ # Code can be ran by simply invoking `ruby bootstrap.rb`
4
+ # Note: this example will require 'net-ssh' gem to be installed
3
5
 
4
6
  require "bundler"
5
7
  Bundler.require(:default, :development)
6
- # Uncomment this if you want to make real requests to GCE (you _will_ be billed!)
7
- # WebMock.disable!
8
8
 
9
- def test
10
- connection = Fog::Compute.new(:provider => "Google")
9
+ p "Connecting to google..."
10
+ p "======================="
11
+ connection = Fog::Compute.new(:provider => "Google")
11
12
 
12
- server = connection.servers.bootstrap
13
+ p "Bootstrapping a server..."
14
+ p "========================="
15
+ server = connection.servers.bootstrap
13
16
 
14
- raise "Could not bootstrap sshable server." unless server.ssh("whoami")
15
- raise "Could not delete server." unless server.destroy
16
- end
17
+ p "Waiting for server to be sshable..."
18
+ p "==================================="
19
+ server.wait_for { sshable? }
17
20
 
18
- test
21
+ p "Trying to send an SSH command..."
22
+ p "================================"
23
+ raise "Could not bootstrap sshable server." unless server.ssh("whoami")
24
+
25
+ p "Deleting a server..."
26
+ p "===================="
27
+ raise "Could not delete server." unless server.destroy
@@ -445,6 +445,11 @@ module Fog
445
445
  requires :disks
446
446
  requires :zone
447
447
 
448
+ generate_ssh_key_metadata(self.username, self.public_key) if self.public_key
449
+
450
+ # XXX HACK This is a relic of 1.0 change that for some reason added those arguments
451
+ # to `save` method. This is left in place to keep things backwards-compatible
452
+ # TODO(2.0): Remove arguments from save
448
453
  generate_ssh_key_metadata(username, public_key) if public_key
449
454
 
450
455
  options = attributes.reject { |_, v| v.nil? }
@@ -473,6 +478,10 @@ module Fog
473
478
  ]
474
479
  end
475
480
 
481
+ if attributes[:network_ip]
482
+ options[:network_interfaces][0][:network_ip] = attributes[:network_ip]
483
+ end
484
+
476
485
  data = service.insert_server(name, zone_name, options)
477
486
 
478
487
  operation = Fog::Compute::Google::Operations
@@ -43,9 +43,6 @@ module Fog
43
43
  end
44
44
 
45
45
  def bootstrap(public_key_path: nil, **opts)
46
- user = ENV["USER"]
47
- public_key = get_public_key(public_key_path)
48
-
49
46
  name = "fog-#{Time.now.to_i}"
50
47
  zone_name = "us-central1-f"
51
48
 
@@ -66,17 +63,29 @@ module Fog
66
63
  disks = [disk]
67
64
  end
68
65
 
69
- data = opts.merge(
70
- :name => name,
71
- :zone => zone_name,
72
- :disks => disks
73
- )
66
+ # TODO: Remove the network init when #360 is fixed
67
+ network = { :network => "global/networks/default",
68
+ :access_configs => [{ :name => "External NAT",
69
+ :type => "ONE_TO_ONE_NAT" }] }
70
+
71
+ # Merge the options with the defaults, overwriting defaults
72
+ # if an option is provided
73
+ data = { :name => name,
74
+ :zone => zone_name,
75
+ :disks => disks,
76
+ :network_interfaces => [network],
77
+ :public_key => get_public_key(public_key_path),
78
+ :username => ENV["USER"] }.merge(opts)
79
+
74
80
  data[:machine_type] = "n1-standard-1" unless data[:machine_type]
75
81
 
76
82
  server = new(data)
77
- server.save(:username => user, :public_key => public_key)
78
- # TODO: sshable? was removed, needs to be fixed for tests
79
- # server.wait_for { sshable? }
83
+ server.save
84
+ server.wait_for { ready? }
85
+
86
+ # Set the disk to be autodeleted
87
+ server.set_disk_auto_delete(true)
88
+
80
89
  server
81
90
  end
82
91
 
@@ -100,7 +109,7 @@ module Fog
100
109
  end
101
110
 
102
111
  if public_key_path.nil? || public_key_path.empty?
103
- raise ArgumentError("cannot bootstrap instance without public key file")
112
+ raise Fog::Errors::Error.new("Cannot bootstrap instance without a public key")
104
113
  end
105
114
 
106
115
  File.read(File.expand_path(public_key_path))
@@ -2,7 +2,7 @@ module Fog
2
2
  module Compute
3
3
  class Google
4
4
  ##
5
- # Represents a Subnetwork resource
5
+ # Represents a SslCertificate resource
6
6
  #
7
7
  # @see https://cloud.google.com/compute/docs/reference/latest/sslCertificates
8
8
  class SslCertificate < Fog::Model
@@ -85,14 +85,21 @@ module Fog
85
85
 
86
86
  ##
87
87
  # Creates a Cloud SQL instance
88
+ # @param [Boolean] async If the operation must be performed asynchronously
89
+ #
90
+ # This is true by default since SQL instances return Google::Apis::ClientError: invalidState
91
+ # whenever an instance is in a transition process (creation, deletion, etc.) which makes it
92
+ # hard to operate unless one puts guard clauses on Google::Apis::ClientError everywhere.
93
+ #
94
+ # TODO: Rethink this when API graduates out of beta. (Written as of V1beta4)
88
95
  #
89
96
  # @return [Fog::Google::SQL::Instance] Instance resource
90
- def create
97
+ def create(async = false)
91
98
  requires :identity
92
99
 
93
100
  data = service.insert_instance(identity, attributes[:tier], attributes)
94
101
  operation = Fog::Google::SQL::Operations.new(:service => service).get(data.name)
95
- operation.wait_for { !pending? }
102
+ operation.wait_for { ready? } unless async
96
103
  reload
97
104
  end
98
105
 
@@ -107,11 +114,19 @@ module Fog
107
114
  ##
108
115
  # Deletes a Cloud SQL instance
109
116
  #
110
- # @param [Boolean] :async If the operation must be performed asynchronously (true by default)
117
+ # @param [Boolean] async If the operation must be performed asynchronously (false by default)
118
+ # See Fog::Google::SQL::Instance.create on details why default is set this way.
119
+ #
111
120
  # @return [Fog::Google::SQL::Operation] A Operation resource
112
- def destroy(async: nil)
121
+ def destroy(async = false)
113
122
  requires :identity
114
123
 
124
+ # TODO(2.0): Add a deprecation warning here, depending on the decision in #27
125
+ # This is a compatibility fix leftover from breaking named parameter change
126
+ if async.is_a?(Hash)
127
+ async = async[:async]
128
+ end
129
+
115
130
  data = service.delete_instance(identity)
116
131
  operation = Fog::Google::SQL::Operations.new(:service => service).get(data.name)
117
132
  operation.tap { |o| o.wait_for { ready? } unless async }
@@ -15,9 +15,15 @@ module Fog
15
15
  attribute :kind
16
16
  attribute :project
17
17
 
18
- def destroy(async: true)
18
+ def destroy(async = true)
19
19
  requires :instance, :name, :host
20
20
 
21
+ # TODO(2.0): Add a deprecation warning here, depending on the decision in #27
22
+ # This is a compatibility fix leftover from breaking named parameter change
23
+ if async.is_a?(Hash)
24
+ async = async[:async]
25
+ end
26
+
21
27
  resp = service.delete_user(instance, host, name)
22
28
  operation = Fog::Google::SQL::Operations.new(:service => service).get(resp.name)
23
29
  operation.wait_for { ready? } unless async
@@ -30,9 +36,9 @@ module Fog
30
36
  data = attributes
31
37
  data[:password] = password unless password.nil?
32
38
  if etag.nil?
33
- resp = service.update_user(instance, data)
34
- else
35
39
  resp = service.insert_user(instance, data)
40
+ else
41
+ resp = service.update_user(instance, data)
36
42
  end
37
43
 
38
44
  operation = Fog::Google::SQL::Operations.new(:service => service).get(resp.name)
@@ -7,8 +7,8 @@ module Fog
7
7
  # @see https://cloud.google.com/sql/docs/mysql/admin-api/v1beta4/instances/insert
8
8
 
9
9
  class Real
10
- def insert_instance(name, tier, instance = {})
11
- instance = ::Google::Apis::SqladminV1beta4::DatabaseInstance.new(instance)
10
+ def insert_instance(name, tier, options = {})
11
+ instance = ::Google::Apis::SqladminV1beta4::DatabaseInstance.new(options)
12
12
  instance.name = name
13
13
  instance.settings = ::Google::Apis::SqladminV1beta4::Settings.new(instance.settings || {})
14
14
  instance.settings.tier = tier