Skip to content

Commit

Permalink
Documenting curry
Browse files Browse the repository at this point in the history
  • Loading branch information
hamiltonleemark committed Dec 24, 2016
1 parent cfe3302 commit 0f1d03b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-Figure out best way to connect to KVM, ssh password is cumbersome.
-Make sure disks get cleaned up
-Add kibana support
-Add Graphana support
-Create a style for the web pages
Expand Down
14 changes: 14 additions & 0 deletions testpool/core/coding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class curry:
def __init__(self, fun, *args, **kwargs):
self.fun = fun
self.pending = args[:]
self.kwargs = kwargs.copy()

def __call__(self, *args, **kwargs):
if kwargs and self.kwargs:
kw = self.kwargs.copy()
kw.update(kwargs)
else:
kw = kwargs or self.kwargs

return self.fun(*(self.pending + args), **kw)
38 changes: 21 additions & 17 deletions testpool/core/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import datetime
import os
import unittest
# import logging
import time
import testpool.settings
from testpool.core import ext
Expand All @@ -39,6 +38,8 @@
from testpool.core import logger
from testpool.core import commands
from testpool.core import profile
from testpool.core import exceptions
from testpool.core import coding
from testpooldb import models

FOREVER = None
Expand Down Expand Up @@ -250,6 +251,24 @@ def events_show(banner):
vmh.action_time.strftime("%Y-%m-%d %H:%M:%S"))


def action_vm(vmh):
""" Handle VM actions. """

exts = ext.api_ext_list()
LOGGER.info("%s: status %s action %s at %s", vmh.name,
models.VM.status_to_str(vmh.status), vmh.action,
vmh.action_time.strftime("%Y-%m-%d %H:%M:%S"))

if vmh.action == algo.ACTION_DESTROY:
action_destroy(exts, vmh)
elif vmh.action == algo.ACTION_CLONE:
action_clone(exts, vmh)
elif vmh.action == algo.ACTION_ATTR:
action_attr(exts, vmh)
elif vmh.action == algo.ACTION_NONE:
pass


def main(args):
""" Main entry point for server. """

Expand Down Expand Up @@ -283,21 +302,7 @@ def main(args):
args.max_sleep_time)
time.sleep(args.max_sleep_time)
elif vmh.action_time < current or args.max_sleep_time == 0:
exts = ext.api_ext_list()
LOGGER.info("%s: status %s action %s at %s", vmh.name,
models.VM.status_to_str(vmh.status), vmh.action,
vmh.action_time.strftime("%Y-%m-%d %H:%M:%S"))

if vmh.action == algo.ACTION_DESTROY:
action_destroy(exts, vmh)
elif vmh.action == algo.ACTION_CLONE:
action_clone(exts, vmh)
elif vmh.action == algo.ACTION_ATTR:
action_attr(exts, vmh)
elif vmh.action == algo.ACTION_NONE:
pass
else:
LOGGER.error("%s: unknown action %s", vmh.name, vmh.action)
exceptions.try_catch(coding.curry(action_vm, vmh))
else:
action_delay = abs(vmh.action_time - current).seconds

Expand Down Expand Up @@ -430,7 +435,6 @@ def test_expiration(self):
# Acquire for 3 seconds.
vmh.transition(models.VM.RESERVED, algo.ACTION_DESTROY, 3)
time.sleep(5)
# LOGGER.setLevel(logging.DEBUG)
args.setup = False
args.count = 2
args.sleep_time = 1
Expand Down

0 comments on commit 0f1d03b

Please sign in to comment.