Skip to content
Snippets Groups Projects

Remove truncate and add on conflict clause instead

Merged Jonah Husson requested to merge hotfix/remove-truncate into master
All threads resolved!
Compare and Show latest version
1 file
+ 24
17
Compare changes
  • Side-by-side
  • Inline
+ 24
17
@@ -71,7 +71,7 @@ def main():
@@ -71,7 +71,7 @@ def main():
auth_nids = set()
auth_nids = set()
current_bins = []
current_bins = []
current_chain_conf = {}
current_chain_conf = {}
init_auth = get_authorizer_nodes()
init_auth = get_authorizer_nodes(auth_conn)
for i in init_auth:
for i in init_auth:
auth_nids.add(i[0])
auth_nids.add(i[0])
while True:
while True:
@@ -103,9 +103,9 @@ def main():
@@ -103,9 +103,9 @@ def main():
new_auth_set = set(new_auth_nids)
new_auth_set = set(new_auth_nids)
to_add = new_auth_set.difference(auth_nids)
to_add = new_auth_set.difference(auth_nids)
to_delete = auth_nids.difference(new_auth_set)
to_delete = auth_nids.difference(new_auth_set)
set_authorizer_nodes(auth_conn, to_add, to_delete)
to_revoke = set_authorizer_nodes(auth_conn, to_add, to_delete)
auth_nids = new_auth_nids
auth_nids = new_auth_set
revoke_auth(to_delete)
revoke_auth(to_revoke)
# Pass a copy because the dict will be mutated
# Pass a copy because the dict will be mutated
set_active_nodes(conn, copy.deepcopy(new_dict))
set_active_nodes(conn, copy.deepcopy(new_dict))
@@ -225,16 +225,19 @@ def get_substrate_provider():
@@ -225,16 +225,19 @@ def get_substrate_provider():
def revoke_auth(to_revoke):
def revoke_auth(to_revoke):
"""
"""
revoke_auth accepts a list of node IDs to revoke auth from
revoke_auth accepts a list of node IP addresses to revoke auth from
:param to_revoke: list of node IDs
:param to_revoke: list of node IP addresses
"""
"""
 
log.info(f"Revoking access to {len(to_revoke)} nodes...")
for nid in to_revoke:
for nid in to_revoke:
cmd = f"sudo nft -a list chain inet filter input | grep '{nid}' | awk -F'handle ' '{{print $2}}' | xargs -Ixxx sudo nft delete rule inet filter input handle xxx"
cmd = f"sudo nft -a list chain inet filter input | grep '{nid}' | awk -F'handle ' '{{print $2}}' | xargs -Ixxx sudo nft delete rule inet filter input handle xxx"
 
log.debug(cmd)
p = subprocess.Popen(cmd.split())
p = subprocess.Popen(cmd.split())
output, error = p.communicate()
output, error = p.communicate()
log.debug(output)
if output:
 
log.debug(output)
if error:
if error:
log.error(error)
raise IOError(error)
def id_to_reg_code(cmix_id):
def id_to_reg_code(cmix_id):
@@ -699,21 +702,24 @@ def set_authorizer_nodes(conn, to_add, to_delete):
@@ -699,21 +702,24 @@ def set_authorizer_nodes(conn, to_add, to_delete):
:param conn: database connection object
:param conn: database connection object
:param to_add: list of node IDs to add
:param to_add: list of node IDs to add
:param to_delete: list of node IDs to delete
:param to_delete: list of node IDs to delete
:return:
:return list[ip_address]: list of IPs to revoke auth
"""
"""
cur = conn.cursor()
cur = conn.cursor()
# Convert Node information into authorizer insert command
# Convert Node information into authorizer insert command
node_list = get_authorizer_nodes(conn)
node_list = get_authorizer_nodes(conn)
 
to_revoke = []
delete_command = "DELETE FROM nodes WHERE id = ?;"
delete_command = "DELETE FROM nodes WHERE id = %s;"
for n in to_delete:
for row in node_list:
try:
if row[0] in to_delete:
cur.execute(delete_command, (n,))
try:
log.debug(cur.query)
cur.execute(delete_command, (row[0],))
except Exception as e:
log.debug(cur.query)
log.error(f"Failed to remove node from authorizer DB: {cur.query}")
except Exception as e:
raise e
log.error(f"Failed to remove node from authorizer DB: {cur.query}")
 
raise e
 
to_revoke.append(row[1])
insert_list = [(i, None, None) for i in to_add]
insert_list = [(i, None, None) for i in to_add]
# Insert Node information into authorizer db
# Insert Node information into authorizer db
@@ -729,6 +735,7 @@ def set_authorizer_nodes(conn, to_add, to_delete):
@@ -729,6 +735,7 @@ def set_authorizer_nodes(conn, to_add, to_delete):
raise e
raise e
finally:
finally:
cur.close()
cur.close()
 
return to_revoke
def check_table(conn, table_name):
def check_table(conn, table_name):
Loading