Commit 755aa5fe authored by Giorgos Korfiatis's avatar Giorgos Korfiatis Committed by Christos Stavrakakis
Browse files

cyclades: Resolve undecided serial in force mode

Reject a serial with pending=True only when we need to force a new
commission on a given resource.

Also improve handling of serial state: make sure pending is set to False
when we decide whether to accept or reject a serial. Mark a serial to
reject by setting accept=False.
parent 7c0efb7b
......@@ -32,6 +32,7 @@
from django.test import TransactionTestCase
#from snf_django.utils.testing import mocked_quotaholder
from synnefo.logic import servers
from synnefo import quotas
from synnefo.db import models_factory as mfactory, models
from mock import patch
......@@ -167,6 +168,8 @@ class ServerCommandTest(TransactionTestCase):
vm.task = None
vm.task_job_id = None
with mocked_quotaholder():
mrapi().RebootInstance.return_value = 1
with mocked_quotaholder():
servers.reboot(vm, "HARD")
......@@ -180,10 +183,8 @@ class ServerCommandTest(TransactionTestCase):
serial = vm.serial
mrapi().StartupInstance.return_value = 1
with mocked_quotaholder() as m:
with self.assertRaises(quotas.ResolveError):
# Not pending, rejct
vm.task = None
vm.serial = mfactory.QuotaHolderSerialFactory(serial=400,
......@@ -106,6 +106,7 @@ def issue_commission(user, source, provisions, name="",
if serial:
serial_info = {"serial": serial}
if auto_accept:
serial_info["pending"] = False
serial_info["accept"] = True
serial_info["resolved"] = True
return QuotaHolderSerial.objects.create(**serial_info)
......@@ -114,7 +115,9 @@ def issue_commission(user, source, provisions, name="",
def accept_serial(serial, strict=True):
assert serial.pending or serial.accept
response = resolve_commissions(accept=[serial.serial], strict=strict)
serial.pending = False
serial.accept = True
serial.resolved = True
......@@ -122,8 +125,10 @@ def accept_serial(serial, strict=True):
def reject_serial(serial, strict=True):
assert serial.pending or not serial.accept
response = resolve_commissions(reject=[serial.serial], strict=strict)
serial.reject = True
serial.pending = False
serial.accept = False
serial.resolved = True
return response
......@@ -238,16 +243,7 @@ def issue_and_accept_commission(resource, delete=False):
previous_serial = resource.serial
if previous_serial is not None and not previous_serial.resolved:
if previous_serial.pending:
msg = "Issuing commission for resource '%s' while previous serial"\
" '%s' is still pending." % (resource, previous_serial)
raise Exception(msg)
elif previous_serial.accept:
accept_serial(previous_serial, strict=False)
reject_serial(previous_serial, strict=False)
# Convert resources in the format expected by Quotaholder
......@@ -363,7 +359,7 @@ def handle_resource_commission(resource, action, commission_name,
# Try to resolve previous serial
resolve_commission(resource.serial, force=force)
# Check if action is quotable and issue the corresponding commission
serial = None
......@@ -382,9 +378,16 @@ def handle_resource_commission(resource, action, commission_name,
resource.serial = serial
def resolve_commission(serial):
class ResolveError(Exception):
def resolve_commission(serial, force=False):
if serial is None or serial.resolved:
if serial.pending and not force:
m = "Could not resolve commission: serial %s is undecided" % serial
raise ResolveError(m)
log.warning("Resolving pending commission: %s", serial)
if not serial.pending and serial.accept:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment