]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Update/rewrite several functions to use paddles
authorZack Cerza <zack@cerza.org>
Fri, 16 May 2014 20:54:13 +0000 (15:54 -0500)
committerZack Cerza <zack.cerza@inktank.com>
Mon, 25 Aug 2014 17:14:36 +0000 (11:14 -0600)
Functions updated: lock.lock_one(), lock.unlock_one(),
lock.destroy_if_vm(), lockstatus.get_status()

Signed-off-by: Zack Cerza <zack.cerza@inktank.com>
teuthology/lock.py
teuthology/lockstatus.py
teuthology/orchestra/remote.py
teuthology/task/internal.py

index 20704d2f209db5ccf9caac5b32ea7a953d54aa67..74bea13b83781e280d3f13e33d79484622d68734 100644 (file)
@@ -9,6 +9,8 @@ import collections
 import tempfile
 import os
 import time
+import requests
+import json
 
 import teuthology
 from .config import config
@@ -56,38 +58,45 @@ def lock_many(ctx, num, machinetype, user=None, description=None):
     return []
 
 
-def lock_one(ctx, name, user=None, description=None):
+def lock_one(name, user=None, description=None):
     if user is None:
         user = misc.get_user()
-    success, _, _ = ls.send_request(
-        'POST',
-        config.lock_server + '/' + name,
-        urllib.urlencode(dict(user=user, desc=description)))
+    request = dict(name=name, locked=True, locked_by=user,
+                   description=description)
+    uri = os.path.join(config.lock_server, 'nodes', name, 'lock', '')
+    response = requests.put(uri, json.dumps(request))
+    success = response.ok
     if success:
         log.debug('locked %s as %s', name, user)
     else:
-        log.error('failed to lock %s', name)
-    return success
+        try:
+            reason = response.json().get('message')
+        except ValueError:
+            reason = str(response.status_code)
+        log.error('failed to lock {node}. reason: {reason}'.format(
+            node=name, reason=reason))
+    return response
 
 
 def unlock_one(ctx, name, user=None):
     if user is None:
         user = misc.get_user()
-    success, _, http_ret = ls.send_request(
-        'DELETE',
-        config.lock_server + '/' + name + '?' +
-        urllib.urlencode(dict(user=user)))
+    request = dict(name=name, locked=False, locked_by=user, description=None)
+    uri = os.path.join(config.lock_server, 'nodes', name, 'lock', '')
+    response = requests.put(uri, json.dumps(request))
+    success = response.ok
     if success:
         log.debug('unlocked %s', name)
         if not destroy_if_vm(ctx, name):
             log.error('downburst destroy failed for %s', name)
             log.info('%s is not locked' % name)
     else:
-        log.error('failed to unlock %s', name)
-        failure_types = {403: 'You do not have %s locked',
-                         404: '%s is an invalid host name'}
-        if http_ret in failure_types:
-            log.error(failure_types[http_ret], name)
+        try:
+            reason = response.json().get('message')
+        except ValueError:
+            reason = str(response.status_code)
+        log.error('failed to unlock {node}. reason: {reason}'.format(
+            node=name, reason=reason))
     return success
 
 
@@ -252,7 +261,7 @@ def main(ctx):
 
     elif ctx.lock:
         for machine in machines:
-            if not lock_one(ctx, machine, user):
+            if not lock_one(machine, user):
                 ret = 1
                 if not ctx.f:
                     return ret
@@ -502,8 +511,8 @@ def destroy_if_vm(ctx, machine_name):
     """
     Return False only on vm downburst failures.
     """
-    status_info = ls.get_status(ctx, machine_name)
-    phys_host = status_info['vpshost']
+    status_info = ls.get_status(machine_name)
+    phys_host = status_info['vm_host']
     if not phys_host:
         return True
     destroyMe = decanonicalize_hostname(machine_name)
index 44821cc4ca8ee7bd82a99ef786189dbfce0d4851..d2d90f79ff2612f5264097fea0eda3308860eb11 100644 (file)
@@ -1,5 +1,5 @@
-import json
 import httplib2
+import requests
 import logging
 import os
 from .config import config
@@ -17,8 +17,10 @@ def send_request(method, url, body=None, headers=None):
     return (False, None, resp.status)
 
 
-def get_status(ctx, name):
-    success, content, _ = send_request('GET', os.path.join(config.lock_server, name))
+def get_status(name):
+    uri = os.path.join(config.lock_server, 'nodes', name, '')
+    response = requests.get(uri)
+    success = response.ok
     if success:
-        return json.loads(content)
+        return response.json()
     return None
index 6e7792b80237eeb5f660e99d82d3f1315814a44f..000d30da6b909b7574f0625125b69ae30e323ce5 100644 (file)
@@ -429,7 +429,7 @@ class VirtualConsole():
             raise RuntimeError("libvirt not found")
 
         self.shortname = getShortName(name)
-        status_info = ls.get_status('', self.shortname)
+        status_info = ls.get_status(self.shortname)
         try:
             phys_host = status_info['vpshost']
         except TypeError:
index 024297b96e16983b4e604e76a8bbc3c5a5a83e66..dd8d8f558afd73fc31e77efef1f979f06669d755 100644 (file)
@@ -129,7 +129,7 @@ def lock_machines(ctx, config):
                     log.info("Error in virtual machine keys")
                 newscandict = {}
                 for dkey in newly_locked.iterkeys():
-                    stats = lockstatus.get_status(ctx, dkey)
+                    stats = lockstatus.get_status(dkey)
                     newscandict[dkey] = stats['sshpubkey']
                 ctx.config['targets'] = newscandict
             else:
@@ -169,7 +169,7 @@ def check_lock(ctx, config):
         return
     log.info('Checking locks...')
     for machine in ctx.config['targets'].iterkeys():
-        status = lockstatus.get_status(ctx, machine)
+        status = lockstatus.get_status(machine)
         log.debug('machine status is %s', repr(status))
         assert status is not None, \
             'could not read lock status for {name}'.format(name=machine)