Add RE-SQL tests for Roles and Resource Groups. Fixes #4415

This commit is contained in:
Murtuza Zabuawala
2019-07-03 14:38:29 +01:00
committed by Dave Page
parent f4bc4475cd
commit 588e3814d1
33 changed files with 612 additions and 27 deletions

View File

@@ -226,8 +226,9 @@ class ResourceGroupView(NodeView):
"Connection to the server has been lost."
)
)
self.template_path = 'resource_groups/sql'
self.sql_path = 'resource_groups/sql/#{0}#'.format(
self.manager.version
)
return f(*args, **kwargs)
return wrap
@@ -242,7 +243,7 @@ class ResourceGroupView(NodeView):
gid: Server Group ID
sid: Server ID
"""
sql = render_template("/".join([self.template_path, 'properties.sql']))
sql = render_template("/".join([self.sql_path, 'properties.sql']))
status, res = self.conn.execute_dict(sql)
if not status:
@@ -263,7 +264,7 @@ class ResourceGroupView(NodeView):
sid: Server ID
"""
sql = render_template("/".join([self.template_path, 'nodes.sql']),
sql = render_template("/".join([self.sql_path, 'nodes.sql']),
rgid=rg_id)
status, result = self.conn.execute_2darray(sql)
if not status:
@@ -295,7 +296,7 @@ class ResourceGroupView(NodeView):
sid: Server ID
"""
res = []
sql = render_template("/".join([self.template_path, 'nodes.sql']))
sql = render_template("/".join([self.sql_path, 'nodes.sql']))
status, result = self.conn.execute_2darray(sql)
if not status:
return internal_server_error(errormsg=result)
@@ -326,7 +327,7 @@ class ResourceGroupView(NodeView):
rg_id: Resource Group ID
"""
sql = render_template(
"/".join([self.template_path, 'properties.sql']), rgid=rg_id)
"/".join([self.sql_path, 'properties.sql']), rgid=rg_id)
status, res = self.conn.execute_dict(sql)
if not status:
@@ -368,7 +369,7 @@ class ResourceGroupView(NodeView):
try:
# Below logic will create new resource group
sql = render_template(
"/".join([self.template_path, 'create.sql']),
"/".join([self.sql_path, 'create.sql']),
rgname=data['name'], conn=self.conn
)
if sql and sql.strip('\n') and sql.strip(' '):
@@ -380,7 +381,7 @@ class ResourceGroupView(NodeView):
# resource group you can't run multiple commands in one
# transaction.
sql = render_template(
"/".join([self.template_path, 'update.sql']),
"/".join([self.sql_path, 'update.sql']),
data=data, conn=self.conn
)
# Checking if we are not executing empty query
@@ -391,7 +392,7 @@ class ResourceGroupView(NodeView):
# Below logic is used to fetch the oid of the newly created
# resource group
sql = render_template(
"/".join([self.template_path, 'getoid.sql']),
"/".join([self.sql_path, 'getoid.sql']),
rgname=data['name']
)
# Checking if we are not executing empty query
@@ -431,7 +432,7 @@ class ResourceGroupView(NodeView):
try:
sql = render_template(
"/".join([self.template_path, 'properties.sql']), rgid=rg_id)
"/".join([self.sql_path, 'properties.sql']), rgid=rg_id)
status, res = self.conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=res)
@@ -442,7 +443,7 @@ class ResourceGroupView(NodeView):
if data['name'] != old_data['name']:
sql = render_template(
"/".join([self.template_path, 'update.sql']),
"/".join([self.sql_path, 'update.sql']),
oldname=old_data['name'], newname=data['name'],
conn=self.conn
)
@@ -458,7 +459,7 @@ class ResourceGroupView(NodeView):
if data['cpu_rate_limit'] != old_data['cpu_rate_limit'] or \
data['dirty_rate_limit'] != old_data['dirty_rate_limit']:
sql = render_template(
"/".join([self.template_path, 'update.sql']),
"/".join([self.sql_path, 'update.sql']),
data=data, conn=self.conn
)
if sql and sql.strip('\n') and sql.strip(' '):
@@ -499,7 +500,7 @@ class ResourceGroupView(NodeView):
for rg_id in data['ids']:
# Get name for resource group from rg_id
sql = render_template(
"/".join([self.template_path, 'delete.sql']),
"/".join([self.sql_path, 'delete.sql']),
rgid=rg_id, conn=self.conn
)
status, rgname = self.conn.execute_scalar(sql)
@@ -520,7 +521,7 @@ class ResourceGroupView(NodeView):
# drop resource group
sql = render_template(
"/".join([self.template_path, 'delete.sql']),
"/".join([self.sql_path, 'delete.sql']),
rgname=rgname, conn=self.conn
)
status, res = self.conn.execute_scalar(sql)
@@ -580,7 +581,7 @@ class ResourceGroupView(NodeView):
]
if rg_id is not None:
sql = render_template(
"/".join([self.template_path, 'properties.sql']), rgid=rg_id)
"/".join([self.sql_path, 'properties.sql']), rgid=rg_id)
status, res = self.conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=res)
@@ -599,7 +600,7 @@ class ResourceGroupView(NodeView):
if data['name'] != old_data['name']:
name_changed = True
sql = render_template(
"/".join([self.template_path, 'update.sql']),
"/".join([self.sql_path, 'update.sql']),
oldname=old_data['name'], newname=data['name'],
conn=self.conn
)
@@ -609,12 +610,12 @@ class ResourceGroupView(NodeView):
sql += "\n-- Following query will be executed in a " \
"separate transaction\n"
sql += render_template(
"/".join([self.template_path, 'update.sql']),
"/".join([self.sql_path, 'update.sql']),
data=data, conn=self.conn
)
else:
sql = render_template(
"/".join([self.template_path, 'create.sql']),
"/".join([self.sql_path, 'create.sql']),
rgname=data['name'], conn=self.conn
)
@@ -630,7 +631,7 @@ class ResourceGroupView(NodeView):
sql += "\n-- Following query will be executed in a " \
"separate transaction\n"
sql += render_template(
"/".join([self.template_path, 'update.sql']),
"/".join([self.sql_path, 'update.sql']),
data=data, conn=self.conn
)
@@ -647,7 +648,7 @@ class ResourceGroupView(NodeView):
rg_id: Resource Group ID
"""
sql = render_template(
"/".join([self.template_path, 'properties.sql']), rgid=rg_id
"/".join([self.sql_path, 'properties.sql']), rgid=rg_id
)
status, res = self.conn.execute_dict(sql)
if not status:
@@ -661,13 +662,13 @@ class ResourceGroupView(NodeView):
old_data = dict(res['rows'][0])
sql = render_template(
"/".join([self.template_path, 'create.sql']),
"/".join([self.sql_path, 'create.sql']),
display_comments=True,
rgname=old_data['name'], conn=self.conn
)
sql += "\n"
sql += render_template(
"/".join([self.template_path, 'update.sql']),
"/".join([self.sql_path, 'update.sql']),
data=old_data, conn=self.conn
)

View File

@@ -6,4 +6,4 @@ ALTER RESOURCE GROUP {{ conn|qtIdent(oldname) }} RENAME TO {{ conn|qtIdent(newna
{% if data %}
ALTER RESOURCE GROUP {{ conn|qtIdent(data.name) }}
SET cpu_rate_limit = {{data.cpu_rate_limit|default(0)}}, dirty_rate_limit = {{data.dirty_rate_limit|default(0)}};
{% endif %}
{% endif %}

View File

@@ -0,0 +1,8 @@
-- RESOURCE GROUP: new_test_resql_resource_group
-- DROP RESOURCE GROUP new_test_resql_resource_group
CREATE RESOURCE GROUP new_test_resql_resource_group;
ALTER RESOURCE GROUP new_test_resql_resource_group
SET cpu_rate_limit = 0, dirty_rate_limit = 0;

View File

@@ -0,0 +1,8 @@
-- RESOURCE GROUP: new_test_resql_resource_group
-- DROP RESOURCE GROUP new_test_resql_resource_group
CREATE RESOURCE GROUP new_test_resql_resource_group;
ALTER RESOURCE GROUP new_test_resql_resource_group
SET cpu_rate_limit = 1, dirty_rate_limit = 5;

View File

@@ -0,0 +1,8 @@
-- RESOURCE GROUP: test_resql_resource_group
-- DROP RESOURCE GROUP test_resql_resource_group
CREATE RESOURCE GROUP test_resql_resource_group;
ALTER RESOURCE GROUP test_resql_resource_group
SET cpu_rate_limit = 0, dirty_rate_limit = 0;

View File

@@ -0,0 +1,48 @@
{
"prerequisite": {
"minVer": 90400,
"maxVer": null,
"type": "ppas"
},
"scenarios": [
{
"type": "create",
"name": "Create Resource groups",
"endpoint": "NODE-resource_group.obj",
"sql_endpoint": "NODE-resource_group.sql_id",
"data": {
"name": "test_resql_resource_group",
"cpu_rate_limit": 0,
"dirty_rate_limit": 0
},
"expected_sql_file": "create_resource_group.sql"
},
{
"type": "alter",
"name": "Alter Resource groups name",
"endpoint": "NODE-resource_group.obj_id",
"sql_endpoint": "NODE-resource_group.sql_id",
"data": {
"name": "new_test_resql_resource_group"
},
"expected_sql_file": "alter_resource_group_name.sql"
},
{
"type": "alter",
"name": "Alter Resource groups options",
"endpoint": "NODE-resource_group.obj_id",
"sql_endpoint": "NODE-resource_group.sql_id",
"data": {
"cpu_rate_limit": 1,
"dirty_rate_limit": 5
},
"expected_sql_file": "alter_resource_group_options.sql"
},
{
"type": "delete",
"name": "Drop Resource groups",
"endpoint": "NODE-resource_group.obj_id",
"data": {}
}
]
}

View File

@@ -0,0 +1,12 @@
-- Role: test_resql_role_pg91
-- DROP ROLE test_resql_role_pg91;
CREATE ROLE test_resql_role_pg91 WITH
NOLOGIN
NOSUPERUSER
INHERIT
NOCREATEDB
NOCREATEROLE
NOREPLICATION;
COMMENT ON ROLE test_resql_role_pg91 IS 'This is detailed description';

View File

@@ -0,0 +1,12 @@
-- Role: new_test_resql_role_pg91
-- DROP ROLE new_test_resql_role_pg91;
CREATE ROLE new_test_resql_role_pg91 WITH
NOLOGIN
NOSUPERUSER
INHERIT
NOCREATEDB
NOCREATEROLE
NOREPLICATION;
COMMENT ON ROLE new_test_resql_role_pg91 IS 'This is detailed description';

View File

@@ -0,0 +1,15 @@
-- Role: new_test_resql_role_pg91
-- DROP ROLE new_test_resql_role_pg91;
CREATE ROLE new_test_resql_role_pg91 WITH
NOLOGIN
SUPERUSER
INHERIT
CREATEDB
NOCREATEROLE
NOREPLICATION;
UPDATE pg_authid SET rolcatupdate=false WHERE rolname = new_test_resql_role_pg91;
COMMENT ON ROLE new_test_resql_role_pg91 IS 'This is detailed description';

View File

@@ -0,0 +1,15 @@
-- User: test_resql_user_pg91
-- DROP USER test_resql_user_pg91;
CREATE USER test_resql_user_pg91 WITH
LOGIN
SUPERUSER
INHERIT
CREATEDB
CREATEROLE
REPLICATION;
UPDATE pg_authid SET rolcatupdate=false WHERE rolname = test_resql_user_pg91;
COMMENT ON ROLE test_resql_user_pg91 IS 'This is detailed description';

View File

@@ -0,0 +1,15 @@
-- User: new_test_resql_user_pg91
-- DROP USER new_test_resql_user_pg91;
CREATE USER new_test_resql_user_pg91 WITH
LOGIN
SUPERUSER
INHERIT
CREATEDB
CREATEROLE
REPLICATION;
UPDATE pg_authid SET rolcatupdate=false WHERE rolname = new_test_resql_user_pg91;
COMMENT ON ROLE new_test_resql_user_pg91 IS 'This is detailed description';

View File

@@ -0,0 +1,12 @@
-- User: new_test_resql_user_pg91
-- DROP USER new_test_resql_user_pg91;
CREATE USER new_test_resql_user_pg91 WITH
LOGIN
NOSUPERUSER
INHERIT
NOCREATEDB
CREATEROLE
REPLICATION;
COMMENT ON ROLE new_test_resql_user_pg91 IS 'This is detailed description';

View File

@@ -0,0 +1,10 @@
-- Role: test_resql_role_pg91
-- DROP ROLE test_resql_role_pg91;
CREATE ROLE test_resql_role_pg91 WITH
NOLOGIN
NOSUPERUSER
INHERIT
NOCREATEDB
NOCREATEROLE
NOREPLICATION;

View File

@@ -0,0 +1,13 @@
-- User: test_resql_user_pg91
-- DROP USER test_resql_user_pg91;
CREATE USER test_resql_user_pg91 WITH
LOGIN
SUPERUSER
INHERIT
CREATEDB
CREATEROLE
REPLICATION;
UPDATE pg_authid SET rolcatupdate=false WHERE rolname = test_resql_user_pg91;

View File

@@ -0,0 +1,124 @@
{
"scenarios": [
{
"type": "create",
"name": "Create Role",
"endpoint": "NODE-role.obj",
"sql_endpoint": "NODE-role.sql_id",
"data": {
"rolname": "test_resql_role_pg91",
"rolcanlogin": false,
"rolpassword": null,
"rolconnlimit": -1,
"rolsuper": false,
"rolcreaterole": false,
"rolcreatedb": false,
"rolinherit": true,
"rolcatupdate": false,
"rolreplication": false,
"rolmembership": [],
"rolvaliduntil": null,
"seclabels": [],
"variables": []
},
"expected_sql_file": "create_role.sql"
},
{
"type": "alter",
"name": "Alter Role description",
"endpoint": "NODE-role.obj_id",
"sql_endpoint": "NODE-role.sql_id",
"data": {
"description": "This is detailed description"
},
"expected_sql_file": "alter_role_description.sql"
},
{
"type": "alter",
"name": "Alter Role name",
"endpoint": "NODE-role.obj_id",
"sql_endpoint": "NODE-role.sql_id",
"data": {
"rolname": "new_test_resql_role_pg91"
},
"expected_sql_file": "alter_role_name.sql"
},
{
"type": "alter",
"name": "Alter Role superuser, createdb etc options",
"endpoint": "NODE-role.obj_id",
"sql_endpoint": "NODE-role.sql_id",
"data": {
"rolsuper": true,
"rolcreatedb": true
},
"expected_sql_file": "alter_role_options.sql"
},
{
"type": "delete",
"name": "Drop Role",
"endpoint": "NODE-role.obj_id",
"data": {}
},
{
"type": "create",
"name": "Create User",
"endpoint": "NODE-role.obj",
"sql_endpoint": "NODE-role.sql_id",
"data": {
"rolname": "test_resql_user_pg91",
"rolcanlogin": true,
"rolpassword": null,
"rolconnlimit": -1,
"rolsuper": true,
"rolcreaterole": true,
"rolcreatedb": true,
"rolinherit": true,
"rolcatupdate": true,
"rolreplication": true,
"rolmembership": [],
"rolvaliduntil": null,
"seclabels": [],
"variables": []
},
"expected_sql_file": "create_user.sql"
},
{
"type": "alter",
"name": "Alter User description",
"endpoint": "NODE-role.obj_id",
"sql_endpoint": "NODE-role.sql_id",
"data": {
"description": "This is detailed description"
},
"expected_sql_file": "alter_user_description.sql"
},
{
"type": "alter",
"name": "Alter User name",
"endpoint": "NODE-role.obj_id",
"sql_endpoint": "NODE-role.sql_id",
"data": {
"rolname": "new_test_resql_user_pg91"
},
"expected_sql_file": "alter_user_name.sql"
},
{
"type": "alter",
"name": "Alter User superuser, createdb etc options",
"endpoint": "NODE-role.obj_id",
"sql_endpoint": "NODE-role.sql_id",
"data": {
"rolsuper": false,
"rolcreatedb": false
},
"expected_sql_file": "alter_user_options.sql"
},
{
"type": "delete",
"name": "Drop User",
"endpoint": "NODE-role.obj_id",
"data": {}
}
]
}

View File

@@ -0,0 +1,12 @@
-- Role: test_resql_role_pg95
-- DROP ROLE test_resql_role_pg95;
CREATE ROLE test_resql_role_pg95 WITH
NOLOGIN
NOSUPERUSER
INHERIT
NOCREATEDB
NOCREATEROLE
NOREPLICATION;
COMMENT ON ROLE test_resql_role_pg95 IS 'This is detailed description';

View File

@@ -0,0 +1,12 @@
-- Role: new_test_resql_role_pg95
-- DROP ROLE new_test_resql_role_pg95;
CREATE ROLE new_test_resql_role_pg95 WITH
NOLOGIN
NOSUPERUSER
INHERIT
NOCREATEDB
NOCREATEROLE
NOREPLICATION;
COMMENT ON ROLE new_test_resql_role_pg95 IS 'This is detailed description';

View File

@@ -0,0 +1,12 @@
-- Role: new_test_resql_role_pg95
-- DROP ROLE new_test_resql_role_pg95;
CREATE ROLE new_test_resql_role_pg95 WITH
NOLOGIN
SUPERUSER
INHERIT
CREATEDB
NOCREATEROLE
NOREPLICATION;
COMMENT ON ROLE new_test_resql_role_pg95 IS 'This is detailed description';

View File

@@ -0,0 +1,12 @@
-- User: test_resql_user_pg95
-- DROP USER test_resql_user_pg95;
CREATE USER test_resql_user_pg95 WITH
LOGIN
SUPERUSER
INHERIT
CREATEDB
CREATEROLE
REPLICATION;
COMMENT ON ROLE test_resql_user_pg95 IS 'This is detailed description';

View File

@@ -0,0 +1,12 @@
-- User: new_test_resql_user_pg95
-- DROP USER new_test_resql_user_pg95;
CREATE USER new_test_resql_user_pg95 WITH
LOGIN
SUPERUSER
INHERIT
CREATEDB
CREATEROLE
REPLICATION;
COMMENT ON ROLE new_test_resql_user_pg95 IS 'This is detailed description';

View File

@@ -0,0 +1,12 @@
-- User: new_test_resql_user_pg95
-- DROP USER new_test_resql_user_pg95;
CREATE USER new_test_resql_user_pg95 WITH
LOGIN
NOSUPERUSER
INHERIT
NOCREATEDB
CREATEROLE
REPLICATION;
COMMENT ON ROLE new_test_resql_user_pg95 IS 'This is detailed description';

View File

@@ -0,0 +1,10 @@
-- Role: test_resql_role_pg95
-- DROP ROLE test_resql_role_pg95;
CREATE ROLE test_resql_role_pg95 WITH
NOLOGIN
NOSUPERUSER
INHERIT
NOCREATEDB
NOCREATEROLE
NOREPLICATION;

View File

@@ -0,0 +1,10 @@
-- User: test_resql_user_pg95
-- DROP USER test_resql_user_pg95;
CREATE USER test_resql_user_pg95 WITH
LOGIN
SUPERUSER
INHERIT
CREATEDB
CREATEROLE
REPLICATION;

View File

@@ -0,0 +1,124 @@
{
"scenarios": [
{
"type": "create",
"name": "Create Role",
"endpoint": "NODE-role.obj",
"sql_endpoint": "NODE-role.sql_id",
"data": {
"rolname": "test_resql_role_pg95",
"rolcanlogin": false,
"rolpassword": null,
"rolconnlimit": -1,
"rolsuper": false,
"rolcreaterole": false,
"rolcreatedb": false,
"rolinherit": true,
"rolcatupdate": false,
"rolreplication": false,
"rolmembership": [],
"rolvaliduntil": null,
"seclabels": [],
"variables": []
},
"expected_sql_file": "create_role.sql"
},
{
"type": "alter",
"name": "Alter Role description",
"endpoint": "NODE-role.obj_id",
"sql_endpoint": "NODE-role.sql_id",
"data": {
"description": "This is detailed description"
},
"expected_sql_file": "alter_role_description.sql"
},
{
"type": "alter",
"name": "Alter Role name",
"endpoint": "NODE-role.obj_id",
"sql_endpoint": "NODE-role.sql_id",
"data": {
"rolname": "new_test_resql_role_pg95"
},
"expected_sql_file": "alter_role_name.sql"
},
{
"type": "alter",
"name": "Alter Role superuser, createdb etc options",
"endpoint": "NODE-role.obj_id",
"sql_endpoint": "NODE-role.sql_id",
"data": {
"rolsuper": true,
"rolcreatedb": true
},
"expected_sql_file": "alter_role_options.sql"
},
{
"type": "delete",
"name": "Drop Role",
"endpoint": "NODE-role.obj_id",
"data": {}
},
{
"type": "create",
"name": "Create User",
"endpoint": "NODE-role.obj",
"sql_endpoint": "NODE-role.sql_id",
"data": {
"rolname": "test_resql_user_pg95",
"rolcanlogin": true,
"rolpassword": null,
"rolconnlimit": -1,
"rolsuper": true,
"rolcreaterole": true,
"rolcreatedb": true,
"rolinherit": true,
"rolcatupdate": true,
"rolreplication": true,
"rolmembership": [],
"rolvaliduntil": null,
"seclabels": [],
"variables": []
},
"expected_sql_file": "create_user.sql"
},
{
"type": "alter",
"name": "Alter User description",
"endpoint": "NODE-role.obj_id",
"sql_endpoint": "NODE-role.sql_id",
"data": {
"description": "This is detailed description"
},
"expected_sql_file": "alter_user_description.sql"
},
{
"type": "alter",
"name": "Alter User name",
"endpoint": "NODE-role.obj_id",
"sql_endpoint": "NODE-role.sql_id",
"data": {
"rolname": "new_test_resql_user_pg95"
},
"expected_sql_file": "alter_user_name.sql"
},
{
"type": "alter",
"name": "Alter User superuser, createdb etc options",
"endpoint": "NODE-role.obj_id",
"sql_endpoint": "NODE-role.sql_id",
"data": {
"rolsuper": false,
"rolcreatedb": false
},
"expected_sql_file": "alter_user_options.sql"
},
{
"type": "delete",
"name": "Drop User",
"endpoint": "NODE-role.obj_id",
"data": {}
}
]
}