Skip to content

Commit 1db04b5

Browse files
committed
view db transaction errors
1 parent 2718a12 commit 1db04b5

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

HACKING/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
volume/
22
volume/*
3+
.env.local
34
.env
5+
.env.ignore
46
ssh_key

HACKING/docker-compose.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ services:
1010
context: ./proxstar-postgres
1111
environment:
1212
POSTGRES_PASSWORD: changeme
13+
ports:
14+
- "5432:5432"
1315
volumes:
1416
- ./proxstar-postgres/volume:/var/lib/postgresql/data:Z
1517
networks:
@@ -19,7 +21,7 @@ services:
1921
proxstar-rq-scheduler:
2022
build:
2123
context: ..
22-
env_file: .env
24+
env_file: .env.local
2325
entrypoint: ./start_scheduler.sh
2426
networks:
2527
- proxstar
@@ -28,7 +30,7 @@ services:
2830
proxstar-rq:
2931
build:
3032
context: ..
31-
env_file: .env
33+
env_file: .env.local
3234
entrypoint: ./start_worker.sh
3335
networks:
3436
- proxstar
@@ -40,7 +42,7 @@ services:
4042
ports:
4143
- "8000:8000"
4244
- "8001:8001"
43-
env_file: .env
45+
env_file: .env.local
4446
entrypoint: ["gunicorn", "proxstar:app", "--bind=0.0.0.0:8000"]
4547
networks:
4648
- proxstar

proxstar/starrs.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ def get_next_ip(starrs, range_name):
99
c.callproc('api.get_address_from_range', (range_name,))
1010
results = c.fetchall()
1111
c.execute('COMMIT')
12+
except Exception as e:
13+
print(e)
14+
starrs.rollback()
1215
finally:
1316
c.close()
1417
return results[0][0]
@@ -22,6 +25,9 @@ def get_ip_for_mac(starrs, mac):
2225
c.callproc('api.get_system_interface_addresses', (mac.lower(),))
2326
results = c.fetchall()
2427
c.execute('COMMIT')
28+
except Exception as e:
29+
print(e)
30+
starrs.rollback()
2531
finally:
2632
c.close()
2733
if not results:
@@ -37,6 +43,9 @@ def renew_ip(starrs, addr):
3743
c.callproc('api.renew_interface_address', (addr,))
3844
results = c.fetchall()
3945
c.execute('COMMIT')
46+
except Exception as e:
47+
print(e)
48+
starrs.rollback()
4049
finally:
4150
c.close()
4251
return results
@@ -72,9 +81,11 @@ def check_hostname(starrs, hostname):
7281
if c.fetchall():
7382
available = False
7483
c.execute('COMMIT')
75-
except psycopg2.InternalError:
84+
except Exception as e:
85+
print(e)
7686
valid = False
7787
available = False
88+
starrs.rollback()
7889
finally:
7990
c.close()
8091
return valid, available
@@ -95,6 +106,9 @@ def register_starrs(starrs, name, owner, mac, addr):
95106
c.callproc('api.initialize', ('root',))
96107
c.callproc('api.modify_system', (name, 'comment', f'Owned by {owner}'))
97108
c.execute('COMMIT')
109+
except Exception as e:
110+
print(e)
111+
starrs.rollback()
98112
finally:
99113
c.close()
100114
return results
@@ -108,6 +122,9 @@ def delete_starrs(starrs, name):
108122
c.callproc('api.remove_system', (name,))
109123
results = c.fetchall()
110124
c.execute('COMMIT')
125+
except Exception as e:
126+
print(e)
127+
starrs.rollback()
111128
finally:
112129
c.close()
113130
return results

0 commit comments

Comments
 (0)