Return 404 if not enough ready in pool

This changes the behavior to prevent locking a node that does not match
the requested pool. Currently using a pool locks a node in that pool if
there is one ready, as expected. If there is not one ready from the
pool but there is any other node ready, it will lock a node outside the
pool, not expected and breaking behavior. Also update to handle PyYAML 6.0.0

Change-Id: I285256037e16f94c79cc7d813235460b4032393d
This commit is contained in:
erbarr 2021-10-25 17:08:14 -05:00
parent 5cf167d567
commit 0e2f2a987b
14 changed files with 19 additions and 14 deletions

View File

@ -83,7 +83,7 @@ if __name__ == "__main__":
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
conf = yaml.load(fobj, Loader=yaml.SafeLoader)
mi.setup_conf(conf)
mi.setup_parser(parser)

View File

@ -77,7 +77,7 @@ def moltenirond_main():
"""This is the main routine for the MoltenIron server."""
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
conf = yaml.load(fobj, Loader=yaml.SafeLoader)
moltenirond.listener(conf)

View File

@ -507,6 +507,11 @@ class DataBase(object):
if node_pool != "Default":
count_with_pool = session.query(Nodes).filter_by(
status="ready", node_pool=node_pool).count()
if count_with_pool < how_many:
fmt = "Not enough available nodes found."
fmt += " Found %d, requested %d"
return {'status': 404,
'message': fmt % (count_with_pool, how_many, )}
# If we don't have enough nodes return an error
if count < how_many:
fmt = "Not enough available nodes found."
@ -1357,6 +1362,6 @@ if __name__ == "__main__":
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
conf = yaml.load(fobj, Loader=yaml.SafeLoader)
listener(conf)

View File

@ -53,7 +53,7 @@ if __name__ == "__main__":
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
conf = yaml.load(fobj, Loader=yaml.SafeLoader)
request1 = {
"name": "pkvmci816",

View File

@ -94,7 +94,7 @@ if __name__ == "__main__":
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
conf = yaml.load(fobj, Loader=yaml.SafeLoader)
request1 = {
"name": "pkvmci816",

View File

@ -93,7 +93,7 @@ if __name__ == "__main__":
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
conf = yaml.load(fobj, Loader=yaml.SafeLoader)
request1 = {
"name": "pkvmci816",

View File

@ -94,7 +94,7 @@ if __name__ == "__main__":
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
conf = yaml.load(fobj, Loader=yaml.SafeLoader)
request1 = {
"name": "pkvmci816",

View File

@ -94,7 +94,7 @@ if __name__ == "__main__":
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
conf = yaml.load(fobj, Loader=yaml.SafeLoader)
request1 = {
"name": "pkvmci816",

View File

@ -53,7 +53,7 @@ if __name__ == "__main__":
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
conf = yaml.load(fobj, Loader=yaml.SafeLoader)
request1 = {
"name": "pkvmci816",

View File

@ -53,7 +53,7 @@ if __name__ == "__main__":
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
conf = yaml.load(fobj, Loader=yaml.SafeLoader)
request1 = {
"name": "pkvmci816",

View File

@ -53,7 +53,7 @@ if __name__ == "__main__":
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
conf = yaml.load(fobj, Loader=yaml.SafeLoader)
request1 = {
"name": "pkvmci816",

View File

@ -53,7 +53,7 @@ if __name__ == "__main__":
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
conf = yaml.load(fobj, Loader=yaml.SafeLoader)
request1 = {
"name": "pkvmci816",

View File

@ -40,7 +40,7 @@ def main():
# The conf.yaml is located in the molteniron/ directory.
newPath = "/".join(dirs[:-2]) + "/"
fobj = open(newPath + "molteniron/conf.yaml", "r")
conf = yaml.load(fobj)
conf = yaml.load(fobj, Loader=yaml.SafeLoader)
# Create the SQL User
SQL("CREATE USER '"

View File

@ -83,7 +83,7 @@ if __name__ == "__main__":
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
conf = yaml.load(fobj, Loader=yaml.SafeLoader)
mi.setup_conf(conf)
mi.setup_parser(parser)