Skip to content

Commit 1185ec1

Browse files
authored
Merge pull request #338 from Temikus/fix_sql
Fixing SQL
2 parents 7cc35b7 + 5af8e9f commit 1185ec1

28 files changed

+431
-292
lines changed

.rubocop.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Style/FrozenStringLiteralComment:
1919
Style/HashSyntax:
2020
EnforcedStyle: no_mixed_keys
2121

22+
# Do not enforce %i syntax
23+
Style/SymbolArray:
24+
Enabled: false
25+
2226
# HoundCI config
2327

2428
AllCops:

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,29 @@ The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1
66

77
### User-facing
88

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)`
14+
915
#### Added
1016

1117
- \#361 `Fog::Compute::Google::Server` now recognises `network_ip` attribute to specify internal IP [mattimatti]
1218

1319
#### Fixed
1420

21+
- \#338 Fixed SQL Users model workflow
1522
- \#359 Fix whitespace escaping in XML Storage methods [temikus]
1623
- \#366 Fixing `Server` model to properly accept `:private_key_path` and `:public_key_path` attributes again. [temikus]
1724

1825
### Development changes
1926

27+
#### Added
28+
29+
- \#338 Major refactor of SQLv1 and SQLv2 tests + a lot of small test fixes/improvements
30+
(see PR/commit messages for full set of changes) [temikus]
31+
2032
#### Fixed
2133

2234
- \#363 Fixed flaky Monitoring tests [temikus]

CONTRIBUTING.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ Then you can run all the live tests:
6565
$ rake test
6666
```
6767

68+
or just one API:
69+
70+
```
71+
$ rake test:compute
72+
```
73+
(See `rake -T` for all available tasks)
74+
6875
or just one file:
6976

7077
```shell
@@ -79,7 +86,8 @@ For more information on transition, read [#50](https://github.com/fog/fog-google
7986

8087
#### Continuous integration
8188

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.
8391

8492
For more information on the pipeline please refer to the [ci README](https://github.com/fog/fog-google/blob/master/ci/README.md).
8593

MIGRATING.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The main maintainers for the Google sections are @icco, @Temikus and @plribeiro3
88

99
**As of v1.0.0, fog-google includes google-api-client as a dependency**
1010

11+
**See [MIGRATING.md](MIGRATING.MD) for migration between major versions**
1112

1213
## Storage
1314

@@ -65,9 +66,22 @@ $ gem install fog-google
6566

6667
## Testing
6768

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.
6971

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.
7185

7286
## Setup
7387

ci/pipeline.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
jobs:
22
- name: integration-tests-compute
3+
serial: true
34
plan:
45
- get: fog-google-src
56
resource: pull-request
@@ -15,8 +16,14 @@ jobs:
1516
google_project: {{google_project}}
1617
google_json_key_data: {{google_json_key_data}}
1718
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+
1925
- name: integration-tests-monitoring
26+
serial: true
2027
plan:
2128
- get: fog-google-src
2229
resource: pull-request
@@ -32,8 +39,14 @@ jobs:
3239
google_project: {{google_project}}
3340
google_json_key_data: {{google_json_key_data}}
3441
google_client_email: {{google_client_email}}
42+
on_failure:
43+
put: pull-request
44+
params:
45+
path: fog-google-src
46+
status: failure
3547

3648
- name: integration-tests-pubsub
49+
serial: true
3750
plan:
3851
- get: fog-google-src
3952
resource: pull-request
@@ -49,8 +62,14 @@ jobs:
4962
google_project: {{google_project}}
5063
google_json_key_data: {{google_json_key_data}}
5164
google_client_email: {{google_client_email}}
65+
on_failure:
66+
put: pull-request
67+
params:
68+
path: fog-google-src
69+
status: failure
5270

5371
- name: integration-tests-sql
72+
serial: true
5473
plan:
5574
- get: fog-google-src
5675
resource: pull-request
@@ -66,8 +85,14 @@ jobs:
6685
google_project: {{google_project}}
6786
google_json_key_data: {{google_json_key_data}}
6887
google_client_email: {{google_client_email}}
88+
on_failure:
89+
put: pull-request
90+
params:
91+
path: fog-google-src
92+
status: failure
6993

7094
- name: integration-tests-storage
95+
serial: true
7196
plan:
7297
- get: fog-google-src
7398
resource: pull-request
@@ -83,6 +108,11 @@ jobs:
83108
google_project: {{google_project}}
84109
google_json_key_data: {{google_json_key_data}}
85110
google_client_email: {{google_client_email}}
111+
on_failure:
112+
put: pull-request
113+
params:
114+
path: fog-google-src
115+
status: failure
86116

87117
- name: github-pr-aggregator
88118
plan:

lib/fog/compute/google/models/ssl_certificate.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Fog
22
module Compute
33
class Google
44
##
5-
# Represents a Subnetwork resource
5+
# Represents a SslCertificate resource
66
#
77
# @see https://cloud.google.com/compute/docs/reference/latest/sslCertificates
88
class SslCertificate < Fog::Model

lib/fog/google/models/sql/instance.rb

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,21 @@ def clone(destination_name, async: true, log_filename: nil, log_position: nil)
8585

8686
##
8787
# 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)
8895
#
8996
# @return [Fog::Google::SQL::Instance] Instance resource
90-
def create
97+
def create(async = false)
9198
requires :identity
9299

93100
data = service.insert_instance(identity, attributes[:tier], attributes)
94101
operation = Fog::Google::SQL::Operations.new(:service => service).get(data.name)
95-
operation.wait_for { !pending? }
102+
operation.wait_for { ready? } unless async
96103
reload
97104
end
98105

@@ -107,11 +114,19 @@ def database_flags
107114
##
108115
# Deletes a Cloud SQL instance
109116
#
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+
#
111120
# @return [Fog::Google::SQL::Operation] A Operation resource
112-
def destroy(async: nil)
121+
def destroy(async = false)
113122
requires :identity
114123

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+
115130
data = service.delete_instance(identity)
116131
operation = Fog::Google::SQL::Operations.new(:service => service).get(data.name)
117132
operation.tap { |o| o.wait_for { ready? } unless async }

lib/fog/google/models/sql/user.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@ class User < Fog::Model
1515
attribute :kind
1616
attribute :project
1717

18-
def destroy(async: true)
18+
def destroy(async = true)
1919
requires :instance, :name, :host
2020

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+
2127
resp = service.delete_user(instance, host, name)
2228
operation = Fog::Google::SQL::Operations.new(:service => service).get(resp.name)
2329
operation.wait_for { ready? } unless async
@@ -30,9 +36,9 @@ def save(password: nil)
3036
data = attributes
3137
data[:password] = password unless password.nil?
3238
if etag.nil?
33-
resp = service.update_user(instance, data)
34-
else
3539
resp = service.insert_user(instance, data)
40+
else
41+
resp = service.update_user(instance, data)
3642
end
3743

3844
operation = Fog::Google::SQL::Operations.new(:service => service).get(resp.name)

lib/fog/google/requests/sql/insert_instance.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ class SQL
77
# @see https://cloud.google.com/sql/docs/mysql/admin-api/v1beta4/instances/insert
88

99
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)
1212
instance.name = name
1313
instance.settings = ::Google::Apis::SqladminV1beta4::Settings.new(instance.settings || {})
1414
instance.settings.tier = tier

0 commit comments

Comments
 (0)