mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
PEP8 fixes. Fixes #3156
This commit is contained in:
parent
f5afd5fdb4
commit
cca6504d54
@ -32,12 +32,14 @@ class ResourceGroupModule(CollectionNodeModule):
|
||||
"""
|
||||
class ResourceGroupModule(CollectionNodeModule)
|
||||
|
||||
A module class for Resource Group node derived from CollectionNodeModule.
|
||||
A module class for Resource Group node derived from
|
||||
CollectionNodeModule.
|
||||
|
||||
Methods:
|
||||
-------
|
||||
* __init__(*args, **kwargs)
|
||||
- Method is used to initialize the ResourceGroupModule and it's base module.
|
||||
- Method is used to initialize the ResourceGroupModule and it's
|
||||
base module.
|
||||
|
||||
* BackendSupported(manager, **kwargs)
|
||||
- This function is used to check the database server type and version.
|
||||
@ -50,8 +52,8 @@ class ResourceGroupModule(CollectionNodeModule):
|
||||
- Method is overridden from its base class to make the node as leaf node.
|
||||
|
||||
* script_load()
|
||||
- Load the module script for resource group, when any of the server node is
|
||||
initialized.
|
||||
- Load the module script for resource group, when any of the server
|
||||
node is initialized.
|
||||
"""
|
||||
|
||||
NODE_TYPE = 'resource_group'
|
||||
@ -59,7 +61,8 @@ class ResourceGroupModule(CollectionNodeModule):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""
|
||||
Method is used to initialize the ResourceGroupModule and it's base module.
|
||||
Method is used to initialize the ResourceGroupModule and
|
||||
it's base module.
|
||||
|
||||
Args:
|
||||
*args:
|
||||
@ -93,13 +96,13 @@ class ResourceGroupModule(CollectionNodeModule):
|
||||
@property
|
||||
def script_load(self):
|
||||
"""
|
||||
Load the module script for resource group, when any of the server node is initialized.
|
||||
Load the module script for resource group, when any of the server
|
||||
node is initialized.
|
||||
|
||||
Returns: node type of the server module.
|
||||
"""
|
||||
return servers.ServerModule.NODE_TYPE
|
||||
|
||||
|
||||
@property
|
||||
def module_use_template_javascript(self):
|
||||
"""
|
||||
@ -116,9 +119,10 @@ class ResourceGroupView(NodeView):
|
||||
"""
|
||||
class ResourceGroupView(NodeView)
|
||||
|
||||
A view class for resource group node derived from NodeView. This class is
|
||||
responsible for all the stuff related to view like create/update/delete resource group,
|
||||
showing properties of resource group node, showing sql in sql pane.
|
||||
A view class for resource group node derived from NodeView.
|
||||
This class is responsible for all the stuff related to view like
|
||||
create/update/delete resource group, showing properties of resource
|
||||
group node, showing sql in sql pane.
|
||||
|
||||
Methods:
|
||||
-------
|
||||
@ -135,14 +139,16 @@ class ResourceGroupView(NodeView):
|
||||
manager,conn & template_path properties to self
|
||||
|
||||
* list()
|
||||
- This function is used to list all the resource group nodes within that collection.
|
||||
- This function is used to list all the resource group nodes within
|
||||
that collection.
|
||||
|
||||
* nodes()
|
||||
- This function will used to create all the child node within that collection.
|
||||
Here it will create all the resource group node.
|
||||
- This function will used to create all the child node within that
|
||||
collection. Here it will create all the resource group node.
|
||||
|
||||
* properties(gid, sid, did, rg_id)
|
||||
- This function will show the properties of the selected resource group node
|
||||
- This function will show the properties of the selected resource
|
||||
group node
|
||||
|
||||
* create(gid, sid, did, rg_id)
|
||||
- This function will create the new resource group object
|
||||
@ -154,13 +160,15 @@ class ResourceGroupView(NodeView):
|
||||
- This function will drop the resource group object
|
||||
|
||||
* msql(gid, sid, did, rg_id)
|
||||
- This function is used to return modified SQL for the selected resource group node
|
||||
- This function is used to return modified SQL for the selected
|
||||
resource group node
|
||||
|
||||
* get_sql(data, rg_id)
|
||||
- This function will generate sql from model data
|
||||
|
||||
* sql(gid, sid, did, rg_id):
|
||||
- This function will generate sql to show it in sql pane for the selected resource group node.
|
||||
- This function will generate sql to show it in sql pane for the
|
||||
selected resource group node.
|
||||
"""
|
||||
|
||||
node_type = blueprint.node_type
|
||||
@ -190,7 +198,8 @@ class ResourceGroupView(NodeView):
|
||||
def __init__(self, **kwargs):
|
||||
"""
|
||||
Method is used to initialize the ResourceGroupView and it's base view.
|
||||
Also initialize all the variables create/used dynamically like conn, template_path.
|
||||
Also initialize all the variables create/used dynamically like conn,
|
||||
template_path.
|
||||
|
||||
Args:
|
||||
**kwargs:
|
||||
@ -244,7 +253,8 @@ class ResourceGroupView(NodeView):
|
||||
@check_precondition
|
||||
def list(self, gid, sid):
|
||||
"""
|
||||
This function is used to list all the resource group nodes within that collection.
|
||||
This function is used to list all the resource group nodes within
|
||||
that collection.
|
||||
|
||||
Args:
|
||||
gid: Server Group ID
|
||||
@ -263,8 +273,8 @@ class ResourceGroupView(NodeView):
|
||||
@check_precondition
|
||||
def node(self, gid, sid, rg_id):
|
||||
"""
|
||||
This function will used to create all the child node within that collection.
|
||||
Here it will create all the resource group node.
|
||||
This function will used to create all the child node within that
|
||||
collection. Here it will create all the resource group node.
|
||||
|
||||
Args:
|
||||
gid: Server Group ID
|
||||
@ -281,11 +291,11 @@ class ResourceGroupView(NodeView):
|
||||
return gone(gettext("""Could not find the resource group."""))
|
||||
|
||||
res = self.blueprint.generate_browser_node(
|
||||
result['rows'][0]['oid'],
|
||||
sid,
|
||||
result['rows'][0]['name'],
|
||||
icon="icon-resource_group"
|
||||
)
|
||||
result['rows'][0]['oid'],
|
||||
sid,
|
||||
result['rows'][0]['name'],
|
||||
icon="icon-resource_group"
|
||||
)
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
@ -295,8 +305,8 @@ class ResourceGroupView(NodeView):
|
||||
@check_precondition
|
||||
def nodes(self, gid, sid):
|
||||
"""
|
||||
This function will used to create all the child node within that collection.
|
||||
Here it will create all the resource group node.
|
||||
This function will used to create all the child node within that
|
||||
collection. Here it will create all the resource group node.
|
||||
|
||||
Args:
|
||||
gid: Server Group ID
|
||||
@ -325,14 +335,16 @@ class ResourceGroupView(NodeView):
|
||||
@check_precondition
|
||||
def properties(self, gid, sid, rg_id):
|
||||
"""
|
||||
This function will show the properties of the selected resource group node.
|
||||
This function will show the properties of the selected resource
|
||||
group node.
|
||||
|
||||
Args:
|
||||
gid: Server Group ID
|
||||
sid: Server ID
|
||||
rg_id: Resource Group ID
|
||||
"""
|
||||
sql = render_template("/".join([self.template_path, 'properties.sql']), rgid=rg_id)
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'properties.sql']), rgid=rg_id)
|
||||
status, res = self.conn.execute_dict(sql)
|
||||
|
||||
if not status:
|
||||
@ -373,21 +385,33 @@ class ResourceGroupView(NodeView):
|
||||
)
|
||||
try:
|
||||
# Below logic will create new resource group
|
||||
sql = render_template("/".join([self.template_path, 'create.sql']), rgname=data['name'], conn=self.conn)
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'create.sql']),
|
||||
rgname=data['name'], conn=self.conn
|
||||
)
|
||||
if sql and sql.strip('\n') and sql.strip(' '):
|
||||
status, res = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
# Below logic will update the cpu_rate_limit and dirty_rate_limit for resource group
|
||||
# we need to add this logic because in resource group you can't run multiple commands in one transaction.
|
||||
sql = render_template("/".join([self.template_path, 'update.sql']), data=data, conn=self.conn)
|
||||
# Below logic will update the cpu_rate_limit and dirty_rate_limit
|
||||
# for resource group, we need to add this logic because in
|
||||
# resource group you can't run multiple commands in one
|
||||
# transaction.
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'update.sql']),
|
||||
data=data, conn=self.conn
|
||||
)
|
||||
# Checking if we are not executing empty query
|
||||
if sql and sql.strip('\n') and sql.strip(' '):
|
||||
status, res = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
# Below logic is used to fetch the oid of the newly created resource group
|
||||
sql = render_template("/".join([self.template_path, 'getoid.sql']), rgname=data['name'])
|
||||
# Below logic is used to fetch the oid of the newly created
|
||||
# resource group
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'getoid.sql']),
|
||||
rgname=data['name']
|
||||
)
|
||||
# Checking if we are not executing empty query
|
||||
rg_id = 0
|
||||
if sql and sql.strip('\n') and sql.strip(' '):
|
||||
@ -424,7 +448,8 @@ class ResourceGroupView(NodeView):
|
||||
)
|
||||
|
||||
try:
|
||||
sql = render_template("/".join([self.template_path, 'properties.sql']), rgid=rg_id)
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'properties.sql']), rgid=rg_id)
|
||||
status, res = self.conn.execute_dict(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@ -434,19 +459,26 @@ class ResourceGroupView(NodeView):
|
||||
data[arg] = old_data[arg]
|
||||
|
||||
if data['name'] != old_data['name']:
|
||||
sql = render_template("/".join([self.template_path, 'update.sql']),
|
||||
oldname=old_data['name'], newname=data['name'], conn=self.conn)
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'update.sql']),
|
||||
oldname=old_data['name'], newname=data['name'],
|
||||
conn=self.conn
|
||||
)
|
||||
if sql and sql.strip('\n') and sql.strip(' '):
|
||||
status, res = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
# Below logic will update the cpu_rate_limit and dirty_rate_limit for resource group
|
||||
# we need to add this logic because in resource group you can't run multiple commands
|
||||
# in one transaction.
|
||||
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']), data=data, conn=self.conn)
|
||||
# Below logic will update the cpu_rate_limit and dirty_rate_limit
|
||||
# for resource group we need to add this logic because in
|
||||
# resource group you can't run multiple commands in one
|
||||
# transaction.
|
||||
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']),
|
||||
data=data, conn=self.conn
|
||||
)
|
||||
if sql and sql.strip('\n') and sql.strip(' '):
|
||||
status, res = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
@ -476,7 +508,10 @@ class ResourceGroupView(NodeView):
|
||||
"""
|
||||
try:
|
||||
# Get name for resource group from rg_id
|
||||
sql = render_template("/".join([self.template_path, 'delete.sql']), rgid=rg_id, conn=self.conn)
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'delete.sql']),
|
||||
rgid=rg_id, conn=self.conn
|
||||
)
|
||||
status, rgname = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=rgname)
|
||||
@ -493,7 +528,10 @@ class ResourceGroupView(NodeView):
|
||||
)
|
||||
|
||||
# drop resource group
|
||||
sql = render_template("/".join([self.template_path, 'delete.sql']), rgname=rgname, conn=self.conn)
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'delete.sql']),
|
||||
rgname=rgname, conn=self.conn
|
||||
)
|
||||
status, res = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@ -514,7 +552,8 @@ class ResourceGroupView(NodeView):
|
||||
@check_precondition
|
||||
def msql(self, gid, sid, rg_id=None):
|
||||
"""
|
||||
This function is used to return modified SQL for the selected resource group node
|
||||
This function is used to return modified SQL for the selected
|
||||
resource group node
|
||||
|
||||
Args:
|
||||
gid: Server Group ID
|
||||
@ -554,7 +593,8 @@ class ResourceGroupView(NodeView):
|
||||
'name', 'cpu_rate_limit', 'dirty_rate_limit'
|
||||
]
|
||||
if rg_id is not None:
|
||||
sql = render_template("/".join([self.template_path, 'properties.sql']), rgid=rg_id)
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'properties.sql']), rgid=rg_id)
|
||||
status, res = self.conn.execute_dict(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@ -572,19 +612,41 @@ class ResourceGroupView(NodeView):
|
||||
name_changed = False
|
||||
if data['name'] != old_data['name']:
|
||||
name_changed = True
|
||||
sql = render_template("/".join([self.template_path, 'update.sql']),
|
||||
oldname=old_data['name'], newname=data['name'], conn=self.conn)
|
||||
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']),
|
||||
oldname=old_data['name'], newname=data['name'],
|
||||
conn=self.conn
|
||||
)
|
||||
if data['cpu_rate_limit'] != old_data['cpu_rate_limit'] or \
|
||||
data['dirty_rate_limit'] != old_data['dirty_rate_limit']:
|
||||
if name_changed:
|
||||
sql += "\n-- Following query will be executed in a separate transaction\n"
|
||||
sql += render_template("/".join([self.template_path, 'update.sql']), data=data, conn=self.conn)
|
||||
sql += "\n-- Following query will be executed in a " \
|
||||
"separate transaction\n"
|
||||
sql += render_template(
|
||||
"/".join([self.template_path, 'update.sql']),
|
||||
data=data, conn=self.conn
|
||||
)
|
||||
else:
|
||||
sql = render_template("/".join([self.template_path, 'create.sql']), rgname=data['name'], conn=self.conn)
|
||||
if ('cpu_rate_limit' in data and data['cpu_rate_limit'] > 0) \
|
||||
or ('dirty_rate_limit' in data and data['dirty_rate_limit'] > 0):
|
||||
sql += "\n-- Following query will be executed in a separate transaction\n"
|
||||
sql += render_template("/".join([self.template_path, 'update.sql']), data=data, conn=self.conn)
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'create.sql']),
|
||||
rgname=data['name'], conn=self.conn
|
||||
)
|
||||
|
||||
cpu_rate_limit_flag = False
|
||||
dirty_rate_limit_flag = False
|
||||
if 'cpu_rate_limit' in data and data['cpu_rate_limit'] > 0:
|
||||
cpu_rate_limit_flag = True
|
||||
|
||||
if 'dirty_rate_limit' in data and data['dirty_rate_limit'] > 0:
|
||||
dirty_rate_limit_flag = True
|
||||
|
||||
if cpu_rate_limit_flag or dirty_rate_limit_flag:
|
||||
sql += "\n-- Following query will be executed in a " \
|
||||
"separate transaction\n"
|
||||
sql += render_template(
|
||||
"/".join([self.template_path, 'update.sql']),
|
||||
data=data, conn=self.conn
|
||||
)
|
||||
|
||||
return sql, data['name'] if 'name' in data else old_data['name']
|
||||
|
||||
@ -598,7 +660,9 @@ class ResourceGroupView(NodeView):
|
||||
sid: Server ID
|
||||
rg_id: Resource Group ID
|
||||
"""
|
||||
sql = render_template("/".join([self.template_path, 'properties.sql']), rgid=rg_id)
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'properties.sql']), rgid=rg_id
|
||||
)
|
||||
status, res = self.conn.execute_dict(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@ -610,10 +674,16 @@ class ResourceGroupView(NodeView):
|
||||
# Making copy of output for future use
|
||||
old_data = dict(res['rows'][0])
|
||||
|
||||
sql = render_template("/".join([self.template_path, 'create.sql']), display_comments=True,
|
||||
rgname=old_data['name'], conn=self.conn)
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'create.sql']),
|
||||
display_comments=True,
|
||||
rgname=old_data['name'], conn=self.conn
|
||||
)
|
||||
sql += "\n"
|
||||
sql += render_template("/".join([self.template_path, 'update.sql']), data=old_data, conn=self.conn)
|
||||
sql += render_template(
|
||||
"/".join([self.template_path, 'update.sql']),
|
||||
data=old_data, conn=self.conn
|
||||
)
|
||||
|
||||
return ajax_response(response=sql)
|
||||
|
||||
|
@ -34,8 +34,8 @@ class ResourceGroupsDeleteTestCase(BaseTestGenerator):
|
||||
self.skipTest(message)
|
||||
else:
|
||||
if server_response["data"]["version"] < 90400:
|
||||
message = "Resource groups are not supported by PPAS 9.3 " \
|
||||
"and below."
|
||||
message = "Resource groups are not supported by PPAS " \
|
||||
"9.3 and below."
|
||||
self.skipTest(message)
|
||||
self.resource_group = "test_resource_group_delete%s" % \
|
||||
str(uuid.uuid4())[1:8]
|
||||
|
@ -38,7 +38,7 @@ class ResourceGroupsGetTestCase(BaseTestGenerator):
|
||||
" and below."
|
||||
self.skipTest(message)
|
||||
self.resource_group = "test_resource_group_get%s" % \
|
||||
str(uuid.uuid4())[1:8]
|
||||
str(uuid.uuid4())[1:8]
|
||||
self.resource_group_id = resource_groups_utils.create_resource_groups(
|
||||
self.server, self.resource_group)
|
||||
|
||||
|
@ -148,8 +148,8 @@ class RoleView(PGChildNodeView):
|
||||
# postgres database datestyle format
|
||||
try:
|
||||
if data[u'rolvaliduntil'] is not None and \
|
||||
data[u'rolvaliduntil'] != '' and \
|
||||
len(data[u'rolvaliduntil']) > 0:
|
||||
data[u'rolvaliduntil'] != '' and \
|
||||
len(data[u'rolvaliduntil']) > 0:
|
||||
data[u'rolvaliduntil'] = dateutil_parser.parse(
|
||||
data[u'rolvaliduntil']
|
||||
).isoformat()
|
||||
@ -161,9 +161,11 @@ class RoleView(PGChildNodeView):
|
||||
if u'rolconnlimit' in data:
|
||||
if data[u'rolconnlimit'] is not None:
|
||||
data[u'rolconnlimit'] = int(data[u'rolconnlimit'])
|
||||
if type(data[u'rolconnlimit']) != int or data[u'rolconnlimit'] < -1:
|
||||
if type(data[u'rolconnlimit']) != int or \
|
||||
data[u'rolconnlimit'] < -1:
|
||||
return precondition_required(
|
||||
_("Connection limit must be an integer value or equal to -1.")
|
||||
_("Connection limit must be an integer value "
|
||||
"or equal to -1.")
|
||||
)
|
||||
|
||||
if u'rolmembership' in data:
|
||||
@ -185,7 +187,8 @@ rolmembership:[{
|
||||
data[u'admins'] = []
|
||||
|
||||
for r in data[u'rolmembership']:
|
||||
if type(r) != dict or u'role' not in r or u'admin' not in r:
|
||||
if type(r) != dict or u'role' not in r or \
|
||||
u'admin' not in r:
|
||||
return precondition_required(msg)
|
||||
else:
|
||||
if r[u'admin']:
|
||||
@ -231,8 +234,9 @@ rolmembership:{
|
||||
return precondition_required(msg)
|
||||
|
||||
for r in roles:
|
||||
if (type(r) != dict or u'role' not in r or
|
||||
u'admin' not in r):
|
||||
if type(r) != dict or \
|
||||
u'role' not in r or \
|
||||
u'admin' not in r:
|
||||
return precondition_required(msg)
|
||||
|
||||
if r[u'admin']:
|
||||
@ -259,8 +263,9 @@ rolmembership:{
|
||||
return precondition_required(msg)
|
||||
|
||||
for r in roles:
|
||||
if (type(r) != dict or u'role' not in r or
|
||||
u'admin' not in r):
|
||||
if type(r) != dict or \
|
||||
u'role' not in r or \
|
||||
u'admin' not in r:
|
||||
return precondition_required(msg)
|
||||
|
||||
if not r[u'admin']:
|
||||
@ -284,8 +289,9 @@ seclabels:[{
|
||||
return precondition_required(msg)
|
||||
|
||||
for s in data[u'seclabels']:
|
||||
if (type(s) != dict or u'provider' not in s or
|
||||
u'label' not in s):
|
||||
if type(s) != dict or \
|
||||
u'provider' not in s or \
|
||||
u'label' not in s:
|
||||
return precondition_required(msg)
|
||||
else:
|
||||
msg = _("""
|
||||
@ -322,8 +328,9 @@ seclabels:{
|
||||
return precondition_required(msg)
|
||||
|
||||
for s in new_seclabels:
|
||||
if (type(s) != dict or u'provider' not in s or
|
||||
u'label' not in s):
|
||||
if type(s) != dict or \
|
||||
u'provider' not in s or \
|
||||
u'label' not in s:
|
||||
return precondition_required(msg)
|
||||
|
||||
if u'deleted' in seclabels:
|
||||
@ -343,15 +350,16 @@ seclabels:{
|
||||
return precondition_required(msg)
|
||||
|
||||
for s in changed_seclabels:
|
||||
if (type(s) != dict or u'provider' not in s
|
||||
and u'label' not in s):
|
||||
if type(s) != dict or \
|
||||
u'provider' not in s and \
|
||||
u'label' not in s:
|
||||
return precondition_required(msg)
|
||||
|
||||
if u'variables' in data:
|
||||
if u'rid' not in kwargs or kwargs['rid'] == -1:
|
||||
msg = _("""
|
||||
Configuration parameters/variables must be passed as an array of JSON objects in
|
||||
the following format in create mode:
|
||||
Configuration parameters/variables must be passed as an array of JSON objects
|
||||
in the following format in create mode:
|
||||
variables:[{
|
||||
database: <database> or null,
|
||||
name: <configuration>,
|
||||
@ -363,14 +371,13 @@ variables:[{
|
||||
return precondition_required(msg)
|
||||
|
||||
for r in data[u'variables']:
|
||||
if (type(r) != dict or
|
||||
u'name' not in r or
|
||||
u'value' not in r):
|
||||
if type(r) != dict or u'name' not in r or \
|
||||
u'value' not in r:
|
||||
return precondition_required(msg)
|
||||
else:
|
||||
msg = _("""
|
||||
Configuration parameters/variables must be passed as an array of JSON objects in
|
||||
the following format in update mode:
|
||||
Configuration parameters/variables must be passed as an array of JSON objects
|
||||
in the following format in update mode:
|
||||
rolmembership:{
|
||||
'added': [{
|
||||
database: <database> or null,
|
||||
@ -405,8 +412,8 @@ rolmembership:{
|
||||
return precondition_required(msg)
|
||||
|
||||
for v in new_vars:
|
||||
if (type(v) != dict or u'name' not in v or
|
||||
u'value' not in v):
|
||||
if type(v) != dict or u'name' not in v or \
|
||||
u'value' not in v:
|
||||
return precondition_required(msg)
|
||||
|
||||
if u'deleted' in variables:
|
||||
@ -426,8 +433,8 @@ rolmembership:{
|
||||
return precondition_required(msg)
|
||||
|
||||
for v in new_vars:
|
||||
if (type(v) != dict or u'name' not in v or
|
||||
u'value' not in v):
|
||||
if type(v) != dict or u'name' not in v or \
|
||||
u'value' not in v:
|
||||
return precondition_required(msg)
|
||||
|
||||
self.request = data
|
||||
@ -466,10 +473,10 @@ rolmembership:{
|
||||
ver = self.manager.version
|
||||
|
||||
self.sql_path = 'role/sql/{0}/'.format(
|
||||
'post9_4' if ver >= 90500 else \
|
||||
'post9_1' if ver >= 90200 else \
|
||||
'post9_0' if ver >= 90100 else \
|
||||
'post8_4'
|
||||
'post9_4' if ver >= 90500 else
|
||||
'post9_1' if ver >= 90200 else
|
||||
'post9_0' if ver >= 90100 else
|
||||
'post8_4'
|
||||
)
|
||||
|
||||
self.alterKeys = [
|
||||
@ -491,19 +498,22 @@ rolmembership:{
|
||||
fetch_name = True
|
||||
if action == 'drop':
|
||||
forbidden_msg = _(
|
||||
"The current user does not have permission to drop the role."
|
||||
"The current user does not have permission to drop"
|
||||
" the role."
|
||||
)
|
||||
else:
|
||||
forbidden_msg = _(
|
||||
"The current user does not have permission to update the role."
|
||||
"The current user does not have permission to "
|
||||
"update the role."
|
||||
)
|
||||
elif action == 'create':
|
||||
check_permission = True
|
||||
forbidden_msg = _(
|
||||
"The current user does not have permission to create the role."
|
||||
"The current user does not have permission to create "
|
||||
"the role."
|
||||
)
|
||||
elif (action == 'msql' and
|
||||
'rid' in kwargs and kwargs['rid'] != -1):
|
||||
elif action == 'msql' and 'rid' in kwargs and \
|
||||
kwargs['rid'] != -1:
|
||||
fetch_name = True
|
||||
|
||||
if check_permission:
|
||||
@ -511,13 +521,12 @@ rolmembership:{
|
||||
|
||||
if not user['is_superuser'] and \
|
||||
not user['can_create_role']:
|
||||
if (action != 'update' or
|
||||
'rid' in kwargs and kwargs['rid'] != -1 and
|
||||
user['id'] != kwargs['rid']):
|
||||
return forbidden(forbidden_msg)
|
||||
if action != 'update' or 'rid' in kwargs:
|
||||
if kwargs['rid'] != -1:
|
||||
if user['id'] != kwargs['rid']:
|
||||
return forbidden(forbidden_msg)
|
||||
|
||||
if fetch_name:
|
||||
|
||||
status, res = self.conn.execute_dict(
|
||||
render_template(
|
||||
self.sql_path + 'permission.sql',
|
||||
@ -535,7 +544,8 @@ rolmembership:{
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return gone(
|
||||
_("Could not find the role on the database server.")
|
||||
_("Could not find the role on the database "
|
||||
"server.")
|
||||
)
|
||||
|
||||
row = res['rows'][0]
|
||||
@ -583,7 +593,8 @@ rolmembership:{
|
||||
if not status:
|
||||
return internal_server_error(
|
||||
_(
|
||||
"Error fetching role information from the database server.\n{0}"
|
||||
"Error fetching role information from the database "
|
||||
"server.\n{0}"
|
||||
).format(rset)
|
||||
)
|
||||
|
||||
@ -617,7 +628,8 @@ rolmembership:{
|
||||
if not status:
|
||||
return internal_server_error(
|
||||
_(
|
||||
"Error fetching role information from the database server.\n{0}"
|
||||
"Error fetching role information from the database "
|
||||
"server.\n{0}"
|
||||
).format(rset)
|
||||
)
|
||||
|
||||
@ -707,7 +719,8 @@ rolmembership:{
|
||||
|
||||
if not status:
|
||||
return internal_server_error(
|
||||
_("Could not generate reversed engineered query for the role.\n{0}").format(
|
||||
_("Could not generate reversed engineered query for the "
|
||||
"role.\n{0}").format(
|
||||
res
|
||||
)
|
||||
)
|
||||
@ -756,7 +769,8 @@ rolmembership:{
|
||||
if not status:
|
||||
return internal_server_error(
|
||||
_(
|
||||
"Error fetching role information from the database server.\n{0}"
|
||||
"Error fetching role information from the database "
|
||||
"server.\n{0}"
|
||||
).format(rset)
|
||||
)
|
||||
for row in rset['rows']:
|
||||
@ -803,7 +817,8 @@ rolmembership:{
|
||||
if not status:
|
||||
return internal_server_error(
|
||||
_(
|
||||
"Error fetching role information from the database server.\n{0}"
|
||||
"Error fetching role information from the database "
|
||||
"server.\n{0}"
|
||||
).format(rset)
|
||||
)
|
||||
|
||||
@ -925,9 +940,21 @@ rolmembership:{
|
||||
oid = db_row['datdba']
|
||||
if db_row['type'] == 'd':
|
||||
if rid == oid:
|
||||
dependents.append({'type': 'database', 'name': '', 'field': db_row['datname']})
|
||||
dependents.append(
|
||||
{
|
||||
'type': 'database',
|
||||
'name': '',
|
||||
'field': db_row['datname']
|
||||
}
|
||||
)
|
||||
else:
|
||||
dependents.append({'type': 'tablespace', 'name': db_row['datname'], 'field': ''})
|
||||
dependents.append(
|
||||
{
|
||||
'type': 'tablespace',
|
||||
'name': db_row['datname'],
|
||||
'field': ''
|
||||
}
|
||||
)
|
||||
|
||||
# If connection to the database is not allowed then continue
|
||||
# with the next database
|
||||
@ -947,8 +974,11 @@ rolmembership:{
|
||||
current_app.logger.exception(e)
|
||||
|
||||
if temp_conn.connected():
|
||||
query = render_template("/".join([self.sql_path, 'dependents.sql']),
|
||||
fetch_dependents=True, rid=rid, lastsysoid=db_row['datlastsysoid'])
|
||||
query = render_template(
|
||||
"/".join([self.sql_path, 'dependents.sql']),
|
||||
fetch_dependents=True, rid=rid,
|
||||
lastsysoid=db_row['datlastsysoid']
|
||||
)
|
||||
|
||||
status, result = temp_conn.execute_dict(query)
|
||||
if not status:
|
||||
@ -985,7 +1015,13 @@ rolmembership:{
|
||||
else:
|
||||
continue
|
||||
|
||||
dependents.append({'type': type_name, 'name': rel_name, 'field': db_row['datname']})
|
||||
dependents.append(
|
||||
{
|
||||
'type': type_name,
|
||||
'name': rel_name,
|
||||
'field': db_row['datname']
|
||||
}
|
||||
)
|
||||
|
||||
# Release only those connections which we have created above.
|
||||
if not is_connected:
|
||||
@ -1027,7 +1063,8 @@ SELECT
|
||||
NULL AS min_val, NULL AS max_val, NULL::text[] AS enumvals
|
||||
UNION ALL
|
||||
SELECT
|
||||
name, vartype, min_val::numeric AS min_val, max_val::numeric AS max_val, enumvals
|
||||
name, vartype, min_val::numeric AS min_val, max_val::numeric AS max_val,
|
||||
enumvals
|
||||
FROM
|
||||
pg_settings
|
||||
WHERE
|
||||
|
@ -36,10 +36,11 @@ class LoginRoleAddTestCase(BaseTestGenerator):
|
||||
|
||||
data = roles_utils.get_role_data(self.server['db_password'])
|
||||
self.role_name = data['rolname']
|
||||
response = self.tester.post(self.url + str(utils.SERVER_GROUP) + '/'
|
||||
+ str(server_id) + '/',
|
||||
data=json.dumps(data),
|
||||
content_type='html/json')
|
||||
response = self.tester.post(
|
||||
self.url + str(utils.SERVER_GROUP) + '/' + str(server_id) + '/',
|
||||
data=json.dumps(data),
|
||||
content_type='html/json'
|
||||
)
|
||||
self.assertEquals(response.status_code, 200)
|
||||
response_data = json.loads(response.data.decode('utf-8'))
|
||||
role_id = response_data['node']['_id']
|
||||
|
@ -47,4 +47,3 @@ class LoginRoleDeleteTestCase(BaseTestGenerator):
|
||||
self.server['port'],
|
||||
self.server['sslmode'])
|
||||
roles_utils.delete_role(connection, self.role_name)
|
||||
|
||||
|
@ -56,4 +56,3 @@ class LoginRolePutTestCase(BaseTestGenerator):
|
||||
self.server['port'],
|
||||
self.server['sslmode'])
|
||||
roles_utils.delete_role(connection, self.role_name)
|
||||
|
||||
|
@ -119,7 +119,11 @@ class TablespaceView(PGChildNodeView):
|
||||
def wrap(*args, **kwargs):
|
||||
# Here args[0] will hold self & kwargs will hold gid,sid,tsid
|
||||
self = args[0]
|
||||
self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(kwargs['sid'])
|
||||
self.manager = get_driver(
|
||||
PG_DEFAULT_DRIVER
|
||||
).connection_manager(
|
||||
kwargs['sid']
|
||||
)
|
||||
self.conn = self.manager.connection()
|
||||
|
||||
# If DB not connected then return error to browser
|
||||
@ -133,7 +137,9 @@ class TablespaceView(PGChildNodeView):
|
||||
)
|
||||
)
|
||||
|
||||
self.template_path = 'tablespaces/sql/#{0}#'.format(self.manager.version)
|
||||
self.template_path = 'tablespaces/sql/#{0}#'.format(
|
||||
self.manager.version
|
||||
)
|
||||
current_app.logger.debug(
|
||||
"Using the template path: %s", self.template_path
|
||||
)
|
||||
@ -173,11 +179,11 @@ class TablespaceView(PGChildNodeView):
|
||||
return gone(gettext("""Could not find the tablespace."""))
|
||||
|
||||
res = self.blueprint.generate_browser_node(
|
||||
rset['rows'][0]['oid'],
|
||||
sid,
|
||||
rset['rows'][0]['name'],
|
||||
icon="icon-tablespace"
|
||||
)
|
||||
rset['rows'][0]['oid'],
|
||||
sid,
|
||||
rset['rows'][0]['name'],
|
||||
icon="icon-tablespace"
|
||||
)
|
||||
|
||||
return make_json_response(
|
||||
data=res,
|
||||
@ -269,7 +275,9 @@ class TablespaceView(PGChildNodeView):
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return gone(gettext("""Could not find the tablespace information."""))
|
||||
return gone(
|
||||
gettext("""Could not find the tablespace information.""")
|
||||
)
|
||||
|
||||
# Making copy of output for future use
|
||||
copy_data = dict(res['rows'][0])
|
||||
@ -494,11 +502,17 @@ class TablespaceView(PGChildNodeView):
|
||||
for key in ['spcacl']:
|
||||
if key in data and data[key] is not None:
|
||||
if 'added' in data[key]:
|
||||
data[key]['added'] = parse_priv_to_db(data[key]['added'], self.acl)
|
||||
data[key]['added'] = parse_priv_to_db(
|
||||
data[key]['added'], self.acl
|
||||
)
|
||||
if 'changed' in data[key]:
|
||||
data[key]['changed'] = parse_priv_to_db(data[key]['changed'], self.acl)
|
||||
data[key]['changed'] = parse_priv_to_db(
|
||||
data[key]['changed'], self.acl
|
||||
)
|
||||
if 'deleted' in data[key]:
|
||||
data[key]['deleted'] = parse_priv_to_db(data[key]['deleted'], self.acl)
|
||||
data[key]['deleted'] = parse_priv_to_db(
|
||||
data[key]['deleted'], self.acl
|
||||
)
|
||||
|
||||
# If name is not present with in update data then copy it
|
||||
# from old data
|
||||
@ -689,7 +703,10 @@ class TablespaceView(PGChildNodeView):
|
||||
}
|
||||
|
||||
# Fetching databases with CONNECT privileges status.
|
||||
query = render_template("/".join([self.template_path, 'dependents.sql']), fetch_database=True)
|
||||
query = render_template(
|
||||
"/".join([self.template_path, 'dependents.sql']),
|
||||
fetch_database=True
|
||||
)
|
||||
status, db_result = self.conn.execute_dict(query)
|
||||
if not status:
|
||||
current_app.logger.error(db_result)
|
||||
@ -726,8 +743,10 @@ class TablespaceView(PGChildNodeView):
|
||||
current_app.logger.exception(e)
|
||||
|
||||
if temp_conn.connected():
|
||||
query = render_template("/".join([self.template_path, 'dependents.sql']),
|
||||
fetch_dependents=True, tsid=tsid)
|
||||
query = render_template(
|
||||
"/".join([self.template_path, 'dependents.sql']),
|
||||
fetch_dependents=True, tsid=tsid
|
||||
)
|
||||
status, result = temp_conn.execute_dict(query)
|
||||
if not status:
|
||||
current_app.logger.error(result)
|
||||
@ -763,7 +782,13 @@ class TablespaceView(PGChildNodeView):
|
||||
else:
|
||||
continue
|
||||
|
||||
dependents.append({'type': type_name, 'name': rel_name, 'field': db_row['datname']})
|
||||
dependents.append(
|
||||
{
|
||||
'type': type_name,
|
||||
'name': rel_name,
|
||||
'field': db_row['datname']
|
||||
}
|
||||
)
|
||||
|
||||
# Release only those connections which we have created above.
|
||||
if not is_connected:
|
||||
|
@ -37,6 +37,7 @@ class BackendSupportedTestCase(BaseTestGenerator):
|
||||
expected_result=False
|
||||
))
|
||||
]
|
||||
|
||||
class LocalManager:
|
||||
def __init__(self, properties):
|
||||
self.sversion = properties['sversion']
|
||||
|
@ -47,10 +47,10 @@ class TableSpaceAddTestCase(BaseTestGenerator):
|
||||
table_space_path, db_owner)
|
||||
self.tablespace_name = data['name']
|
||||
response = self.tester.post(
|
||||
self.url + str(utils.SERVER_GROUP) + '/'
|
||||
+ str(server_id) + '/',
|
||||
self.url + str(utils.SERVER_GROUP) + '/' + str(server_id) + '/',
|
||||
data=json.dumps(data),
|
||||
content_type='html/json')
|
||||
content_type='html/json'
|
||||
)
|
||||
self.assertEquals(response.status_code, 200)
|
||||
response_data = json.loads(response.data.decode('utf-8'))
|
||||
tablespace_id = response_data['node']['_id']
|
||||
|
@ -36,9 +36,11 @@ class TableSpaceDeleteTestCase(BaseTestGenerator):
|
||||
self.server_id = parent_node_dict["server"][-1]["server_id"]
|
||||
self.tablespace_id = tablespace_utils.create_tablespace(
|
||||
self.server, self.tablespace_name)
|
||||
tablespace_dict = {"tablespace_id": self.tablespace_id,
|
||||
"tablespace_name": self.tablespace_name,
|
||||
"server_id": self.server_id}
|
||||
tablespace_dict = {
|
||||
"tablespace_id": self.tablespace_id,
|
||||
"tablespace_name": self.tablespace_name,
|
||||
"server_id": self.server_id
|
||||
}
|
||||
utils.write_node_info("tsid", tablespace_dict)
|
||||
|
||||
def runTest(self):
|
||||
@ -48,10 +50,11 @@ class TableSpaceDeleteTestCase(BaseTestGenerator):
|
||||
if tablespace_count == 0:
|
||||
raise Exception("No tablespace(s) to delete!!!")
|
||||
|
||||
response = self.tester.delete(self.url + str(utils.SERVER_GROUP)
|
||||
+ '/' + str(self.server_id) + '/'
|
||||
+ str(self.tablespace_id),
|
||||
follow_redirects=True)
|
||||
response = self.tester.delete(
|
||||
self.url + str(utils.SERVER_GROUP) +
|
||||
'/' + str(self.server_id) + '/' + str(self.tablespace_id),
|
||||
follow_redirects=True
|
||||
)
|
||||
self.assertEquals(response.status_code, 200)
|
||||
delete_response_data = json.loads(response.data.decode('utf-8'))
|
||||
self.assertEquals(delete_response_data['success'], 1)
|
||||
@ -65,4 +68,3 @@ class TableSpaceDeleteTestCase(BaseTestGenerator):
|
||||
self.server['port'],
|
||||
self.server['sslmode'])
|
||||
tablespace_utils.delete_tablespace(connection, self.tablespace_name)
|
||||
|
||||
|
@ -50,11 +50,13 @@ class TableSpaceUpdateTestCase(BaseTestGenerator):
|
||||
data = {
|
||||
"description": "This is test description.",
|
||||
"table_space_id": self.tablespace_id
|
||||
}
|
||||
}
|
||||
put_response = self.tester.put(
|
||||
self.url + str(utils.SERVER_GROUP) + '/' + str(self.server_id) + '/'
|
||||
+ str(self.tablespace_id), data=json.dumps(data),
|
||||
follow_redirects=True)
|
||||
self.url + str(utils.SERVER_GROUP) +
|
||||
'/' + str(self.server_id) + '/' + str(self.tablespace_id),
|
||||
data=json.dumps(data),
|
||||
follow_redirects=True
|
||||
)
|
||||
self.assertEquals(put_response.status_code, 200)
|
||||
|
||||
def tearDown(self):
|
||||
|
Loading…
Reference in New Issue
Block a user