Skip to content

Commit 741d171

Browse files
author
Raúl Marín
authored
Merge pull request #392 from Algunenano/test_bionic
Test bionic
2 parents 4c15faf + 093e0bc commit 741d171

9 files changed

+78
-26
lines changed

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
dist: xenial
21
language: c
32
sudo: required
43

@@ -12,10 +11,15 @@ env:
1211
jobs:
1312
include:
1413
- env: POSTGRESQL_VERSION="9.6" POSTGIS_VERSION="2.5"
14+
dist: xenial
1515
- env: POSTGRESQL_VERSION="10" POSTGIS_VERSION="2.5"
16+
dist: xenial
1617
- env: POSTGRESQL_VERSION="11" POSTGIS_VERSION="2.5"
18+
dist: xenial
1719
- env: POSTGRESQL_VERSION="12" POSTGIS_VERSION="2.5"
20+
dist: bionic
1821
- env: POSTGRESQL_VERSION="12" POSTGIS_VERSION="3"
22+
dist: bionic
1923

2024
script:
2125
- sudo service postgresql stop;

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ $(EXTENSION)--$(EXTVERSION).sql: $(CDBSCRIPTS) cartodb_version.sql Makefile
150150
cat $(CDBSCRIPTS) | \
151151
$(SED) -e 's/@extschema@/cartodb/g' \
152152
-e 's/@postgisschema@/public/g' \
153-
-e 's/plpythonu/$(PLPYTHONU)/g' >> $@
153+
-e 's/@@plpythonu@@/$(PLPYTHONU)/g' >> $@
154154
echo "GRANT USAGE ON SCHEMA cartodb TO public;" >> $@
155155
cat cartodb_version.sql >> $@
156156

@@ -164,10 +164,10 @@ $(EXTENSION)--$(EXTVERSION)--$(EXTVERSION)next.sql: $(EXTENSION)--$(EXTVERSION).
164164
cp $< $@
165165

166166
$(EXTENSION).control: $(EXTENSION).control.in Makefile
167-
$(SED) -e 's/@@VERSION@@/$(EXTVERSION)/g' -e 's/plpythonu/$(PLPYTHONU)/g' $< > $@
167+
$(SED) -e 's/@@VERSION@@/$(EXTVERSION)/g' -e 's/@@plpythonu@@/$(PLPYTHONU)/g' $< > $@
168168

169169
cartodb_version.sql: cartodb_version.sql.in Makefile $(GITDIR)/index
170-
$(SED) -e 's/@@VERSION@@/$(EXTVERSION)/' -e 's/@extschema@/cartodb/g' -e "s/@postgisschema@/public/g" -e 's/plpythonu/$(PLPYTHONU)/g' $< > $@
170+
$(SED) -e 's/@@VERSION@@/$(EXTVERSION)/' -e 's/@extschema@/cartodb/g' -e "s/@postgisschema@/public/g" -e 's/@@plpythonu@@/$(PLPYTHONU)/g' $< > $@
171171

172172
# Needed for consistent `echo` results with backslashes
173173
SHELL = bash

cartodb.control.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ comment = 'Turn a database into a cartodb user database.'
33
superuser = true
44
relocatable = false
55
schema = cartodb
6-
requires = 'plpythonu, postgis'
6+
requires = '@@plpythonu@@, postgis'

scripts-available/CDB_FederatedServerDiagnostics.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ AS $$
191191
})
192192
return json.dumps(stats)
193193
$$
194-
LANGUAGE plpythonu VOLATILE PARALLEL UNSAFE;
194+
LANGUAGE @@plpythonu@@ VOLATILE PARALLEL UNSAFE;
195195

196196

197197
--

scripts-available/CDB_GhostTables.sql

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ AS $$
3232
client = redis.Redis(host=tis_host, port=tis_port, socket_timeout=tis_timeout)
3333
GD['invalidation'] = client
3434
except Exception as err:
35-
error = "client_error - %s" % str(err)
3635
# NOTE: no retries on connection error
3736
plpy.warning('Error trying to connect to Invalidation Service to link Ghost Tables: ' + str(err))
3837
break
@@ -41,13 +40,12 @@ AS $$
4140
client.execute_command('DBSCH', db_name, username, event_name)
4241
break
4342
except Exception as err:
44-
error = "request_error - %s" % str(err)
4543
client = GD['invalidation'] = None # force reconnect
4644
if not tis_retry:
4745
plpy.warning('Error calling Invalidation Service to link Ghost Tables: ' + str(err))
4846
break
4947
tis_retry -= 1 # try reconnecting
50-
$$ LANGUAGE 'plpythonu' VOLATILE PARALLEL UNSAFE;
48+
$$ LANGUAGE '@@plpythonu@@' VOLATILE PARALLEL UNSAFE;
5149

5250
-- Enqueues a job to run Ghost tables linking process for the current user
5351
CREATE OR REPLACE FUNCTION @[email protected]_LinkGhostTables(event_name text DEFAULT 'USER')
@@ -61,7 +59,7 @@ AS $$
6159
EXECUTE 'SELECT current_database();' INTO db_name;
6260

6361
PERFORM @extschema@._CDB_LinkGhostTables(username, db_name, event_name);
64-
RAISE NOTICE '_CDB_LinkGhostTables() called with username=%, event_name=%', username, event_name;
62+
RAISE INFO '_CDB_LinkGhostTables() called with username=%, event_name=%', username, event_name;
6563
END;
6664
$$ LANGUAGE plpgsql
6765
VOLATILE

scripts-available/CDB_Groups_API.sql

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ $$
2121
body = '{ "name": "%s", "database_role": "%s" }' % (group_name, group_role)
2222
query = "select @extschema@._CDB_Group_API_Request('POST', '%s', '%s', '{200, 409}') as response_status" % (url, body)
2323
plpy.execute(query)
24-
$$ LANGUAGE 'plpythonu'
24+
$$ LANGUAGE '@@plpythonu@@'
2525
VOLATILE
2626
PARALLEL UNSAFE
2727
SECURITY DEFINER
@@ -41,7 +41,7 @@ $$
4141

4242
query = "select @extschema@._CDB_Group_API_Request('DELETE', '%s', '', '{204, 404}') as response_status" % url
4343
plpy.execute(query)
44-
$$ LANGUAGE 'plpythonu'
44+
$$ LANGUAGE '@@plpythonu@@'
4545
VOLATILE
4646
PARALLEL UNSAFE
4747
SECURITY DEFINER
@@ -61,7 +61,7 @@ $$
6161
body = '{ "name": "%s", "database_role": "%s" }' % (new_group_name, new_group_role)
6262
query = "select @extschema@._CDB_Group_API_Request('PUT', '%s', '%s', '{200, 409}') as response_status" % (url, body)
6363
plpy.execute(query)
64-
$$ LANGUAGE 'plpythonu'
64+
$$ LANGUAGE '@@plpythonu@@'
6565
VOLATILE
6666
PARALLEL UNSAFE
6767
SECURITY DEFINER
@@ -81,7 +81,7 @@ $$
8181
body = "{ \"users\": [\"%s\"] }" % "\",\"".join(usernames)
8282
query = "select @extschema@._CDB_Group_API_Request('POST', '%s', '%s', '{200, 409}') as response_status" % (url, body)
8383
plpy.execute(query)
84-
$$ LANGUAGE 'plpythonu'
84+
$$ LANGUAGE '@@plpythonu@@'
8585
VOLATILE
8686
PARALLEL UNSAFE
8787
SECURITY DEFINER
@@ -101,7 +101,7 @@ $$
101101
body = "{ \"users\": [\"%s\"] }" % "\",\"".join(usernames)
102102
query = "select @extschema@._CDB_Group_API_Request('DELETE', '%s', '%s', '{200, 404}') as response_status" % (url, body)
103103
plpy.execute(query)
104-
$$ LANGUAGE 'plpythonu'
104+
$$ LANGUAGE '@@plpythonu@@'
105105
VOLATILE
106106
PARALLEL UNSAFE
107107
SECURITY DEFINER
@@ -129,7 +129,7 @@ $$
129129
body = '{ "access": "%s" }' % access
130130
query = "select @extschema@._CDB_Group_API_Request('PUT', '%s', '%s', '{200, 409}') as response_status" % (url, body)
131131
plpy.execute(query)
132-
$$ LANGUAGE 'plpythonu'
132+
$$ LANGUAGE '@@plpythonu@@'
133133
VOLATILE
134134
PARALLEL UNSAFE
135135
SECURITY DEFINER
@@ -156,7 +156,7 @@ $$
156156
url = '/api/v1/databases/{0}/groups/%s/permission/%s/tables/%s' % (pathname2url(group_name), username, table_name)
157157
query = "select @extschema@._CDB_Group_API_Request('DELETE', '%s', '', '{200, 404}') as response_status" % url
158158
plpy.execute(query)
159-
$$ LANGUAGE 'plpythonu'
159+
$$ LANGUAGE '@@plpythonu@@'
160160
VOLATILE
161161
PARALLEL UNSAFE
162162
SECURITY DEFINER
@@ -191,15 +191,15 @@ $$
191191
params = json.loads(conf)
192192
auth = 'Basic %s' % plpy.execute("SELECT @extschema@._CDB_Group_API_Auth('%s', '%s') as auth" % (params['username'], params['password']))[0]['auth']
193193
return { "host": params['host'], "port": params['port'], 'timeout': params['timeout'], 'auth': auth }
194-
$$ LANGUAGE 'plpythonu' VOLATILE PARALLEL UNSAFE;
194+
$$ LANGUAGE '@@plpythonu@@' VOLATILE PARALLEL UNSAFE;
195195

196196
CREATE OR REPLACE
197197
FUNCTION @extschema@._CDB_Group_API_Auth(username text, password text)
198198
RETURNS TEXT AS
199199
$$
200200
import base64
201201
return base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
202-
$$ LANGUAGE 'plpythonu' VOLATILE PARALLEL UNSAFE;
202+
$$ LANGUAGE '@@plpythonu@@' VOLATILE PARALLEL UNSAFE;
203203

204204
-- url must contain a '%s' placeholder that will be replaced by current_database, for security reasons.
205205
CREATE OR REPLACE
@@ -239,5 +239,5 @@ $$
239239
raise last_err
240240

241241
return None
242-
$$ LANGUAGE 'plpythonu' VOLATILE PARALLEL UNSAFE;
242+
$$ LANGUAGE '@@plpythonu@@' VOLATILE PARALLEL UNSAFE;
243243
revoke all on function @extschema@._CDB_Group_API_Request(text, text, text, int[]) from public;

scripts-available/CDB_QueryStatements.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ RETURNS SETOF TEXT AS $$
1111
cleaned = match[0].strip()
1212
if ( cleaned ):
1313
yield cleaned
14-
$$ language 'plpythonu' IMMUTABLE STRICT PARALLEL SAFE;
14+
$$ language '@@plpythonu@@' IMMUTABLE STRICT PARALLEL SAFE;

test/CDB_GhostTables.sql

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,56 @@
11
-- Create user and enable Ghost tables trigger
22
\set QUIET on
33
SET client_min_messages TO error;
4+
5+
-- Recreate the function without extra error messages as it changes depending on the python-redis version
6+
CREATE OR REPLACE FUNCTION cartodb._CDB_LinkGhostTables(username text, db_name text, event_name text)
7+
RETURNS void
8+
AS $$
9+
if not username:
10+
return
11+
12+
if 'json' not in GD:
13+
import json
14+
GD['json'] = json
15+
else:
16+
json = GD['json']
17+
18+
tis_config = plpy.execute("select cartodb.CDB_Conf_GetConf('invalidation_service');")[0]['cdb_conf_getconf']
19+
if not tis_config:
20+
plpy.warning('Invalidation service configuration not found. Skipping Ghost Tables linking.')
21+
return
22+
23+
tis_config_dict = json.loads(tis_config)
24+
tis_host = tis_config_dict.get('host')
25+
tis_port = tis_config_dict.get('port')
26+
tis_timeout = tis_config_dict.get('timeout', 5)
27+
tis_retry = tis_config_dict.get('retry', 5)
28+
29+
client = GD.get('invalidation', None)
30+
31+
while True:
32+
33+
if not client:
34+
try:
35+
import redis
36+
client = redis.Redis(host=tis_host, port=tis_port, socket_timeout=tis_timeout)
37+
GD['invalidation'] = client
38+
except Exception as err:
39+
# NOTE: no retries on connection error
40+
plpy.warning('Error trying to connect to Invalidation Service to link Ghost Tables')
41+
break
42+
43+
try:
44+
client.execute_command('DBSCH', db_name, username, event_name)
45+
break
46+
except Exception as err:
47+
client = GD['invalidation'] = None # force reconnect
48+
if not tis_retry:
49+
plpy.warning('Error calling Invalidation Service to link Ghost Tables')
50+
break
51+
tis_retry -= 1 # try reconnecting
52+
$$ LANGUAGE '@@plpythonu@@' VOLATILE PARALLEL UNSAFE;
53+
454
SELECT CDB_EnableGhostTablesTrigger();
555
CREATE ROLE "fulano" LOGIN;
656
GRANT ALL ON SCHEMA cartodb TO "fulano";

test/CDB_GhostTables_expect

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11

22

33
WARNING: Invalidation service configuration not found. Skipping Ghost Tables linking.
4-
NOTICE: _CDB_LinkGhostTables() called with username=fulanito, event_name=USER
4+
INFO: _CDB_LinkGhostTables() called with username=fulanito, event_name=USER
55

66

7-
WARNING: Error calling Invalidation Service to link Ghost Tables: Error -2 connecting to fake-tis-host:3142. Name or service not known.
8-
NOTICE: _CDB_LinkGhostTables() called with username=fulanito, event_name=USER
7+
WARNING: Error calling Invalidation Service to link Ghost Tables
8+
INFO: _CDB_LinkGhostTables() called with username=fulanito, event_name=USER
99

1010
BEGIN
1111
cdb_ddl_execution
1212
0
1313
CREATE TABLE
1414
1
15-
WARNING: Error calling Invalidation Service to link Ghost Tables: Error -2 connecting to fake-tis-host:3142. Name or service not known.
16-
NOTICE: _CDB_LinkGhostTables() called with username=fulanito, event_name=CREATE TABLE
15+
WARNING: Error calling Invalidation Service to link Ghost Tables
16+
INFO: _CDB_LinkGhostTables() called with username=fulanito, event_name=CREATE TABLE
1717
COMMIT
1818

1919

0 commit comments

Comments
 (0)