[Kimchi-devel] [PATCH 2/2] Kimchi: updating unit tests to use WoK /test/utils.py

dhbarboza82 at gmail.com dhbarboza82 at gmail.com
Wed Nov 18 20:32:21 UTC 2015


From: Daniel Henrique Barboza <dhbarboza82 at gmail.com>

This patch does the following Kimchi changes:

- tests/run_tests.sh.in: added WoK root dir to PYTHONPATH

- tests/utils.py: deleted.

- test_* files: all the files that were importing the former
tests/utils.py from Kimchi will now be using the one from WoK.

This patch solves Kimchi Github #760

Signed-off-by: Daniel Henrique Barboza <dhbarboza82 at gmail.com>
---
 src/wok/plugins/kimchi/tests/run_tests.sh.in       |   3 +-
 src/wok/plugins/kimchi/tests/test_authorization.py |   9 +-
 src/wok/plugins/kimchi/tests/test_host.py          |   4 +-
 src/wok/plugins/kimchi/tests/test_livemigration.py |  21 +-
 src/wok/plugins/kimchi/tests/test_mock_network.py  |   3 +-
 .../plugins/kimchi/tests/test_mock_storagepool.py  |   4 +-
 .../kimchi/tests/test_mock_storagevolume.py        |   3 +-
 src/wok/plugins/kimchi/tests/test_mockmodel.py     |   5 +-
 src/wok/plugins/kimchi/tests/test_model.py         |   3 +-
 src/wok/plugins/kimchi/tests/test_model_network.py |   6 +-
 .../plugins/kimchi/tests/test_model_storagepool.py |   4 +-
 .../kimchi/tests/test_model_storagevolume.py       |   7 +-
 src/wok/plugins/kimchi/tests/test_networkxml.py    |   7 +-
 src/wok/plugins/kimchi/tests/test_rest.py          |   5 +-
 src/wok/plugins/kimchi/tests/test_template.py      |   4 +-
 src/wok/plugins/kimchi/tests/utils.py              | 259 ---------------------
 16 files changed, 49 insertions(+), 298 deletions(-)
 delete mode 100644 src/wok/plugins/kimchi/tests/utils.py

diff --git a/src/wok/plugins/kimchi/tests/run_tests.sh.in b/src/wok/plugins/kimchi/tests/run_tests.sh.in
index 0e848c8..048f986 100644
--- a/src/wok/plugins/kimchi/tests/run_tests.sh.in
+++ b/src/wok/plugins/kimchi/tests/run_tests.sh.in
@@ -52,6 +52,7 @@ for ((i=0;i<${#LIST[@]};i++)); do
     fi
 done
 
+# ../../../../../ refers to the project root
 # ../../../../ refers to wok directory
 # ../../../ refers to plugins directory
-PYTHONPATH=../../../../:../../../ $CMD $OPTS ${MODEL_LIST[@]} ${MOCK_LIST[@]}
+PYTHONPATH=../../../../../:../../../../:../../../ $CMD $OPTS ${MODEL_LIST[@]} ${MOCK_LIST[@]}
diff --git a/src/wok/plugins/kimchi/tests/test_authorization.py b/src/wok/plugins/kimchi/tests/test_authorization.py
index cfc1715..325f878 100644
--- a/src/wok/plugins/kimchi/tests/test_authorization.py
+++ b/src/wok/plugins/kimchi/tests/test_authorization.py
@@ -22,11 +22,12 @@ import os
 import unittest
 from functools import partial
 
+from tests.utils import get_fake_user, get_free_port, patch_auth
+from tests.utils import request, run_server, wait_task
+
 from wok.plugins.kimchi import mockmodel
 
 from iso_gen import construct_fake_iso
-from utils import get_free_port, patch_auth, request
-from utils import run_server, wait_task
 
 
 test_server = None
@@ -107,8 +108,10 @@ class AuthorizationTests(unittest.TestCase):
         })
         wait_task(model.task_lookup, task_info['id'])
 
+        fake_user = get_fake_user()
+
         model.vm_update(u'test-me',
-                        {'users': [mockmodel.fake_user.keys()[0]],
+                        {'users': [fake_user.keys()[0]],
                          'groups': []})
 
         task_info = model.vms_create({
diff --git a/src/wok/plugins/kimchi/tests/test_host.py b/src/wok/plugins/kimchi/tests/test_host.py
index 4416bed..2ce338f 100644
--- a/src/wok/plugins/kimchi/tests/test_host.py
+++ b/src/wok/plugins/kimchi/tests/test_host.py
@@ -24,9 +24,9 @@ import tempfile
 import unittest
 from functools import partial
 
-from wok.plugins.kimchi.mockmodel import MockModel
+from tests.utils import get_free_port, patch_auth, request, run_server
 
-from utils import get_free_port, patch_auth, request, run_server
+from wok.plugins.kimchi.mockmodel import MockModel
 
 
 test_server = None
diff --git a/src/wok/plugins/kimchi/tests/test_livemigration.py b/src/wok/plugins/kimchi/tests/test_livemigration.py
index 34c0b7e..a26bb4e 100644
--- a/src/wok/plugins/kimchi/tests/test_livemigration.py
+++ b/src/wok/plugins/kimchi/tests/test_livemigration.py
@@ -25,6 +25,8 @@ import socket
 import unittest
 from functools import partial
 
+from tests.utils import get_free_port, patch_auth, request, rollback_wrapper
+from tests.utils import run_server, running_as_root, wait_task
 
 from wok.basemodel import Singleton
 from wok.exception import OperationFailed
@@ -38,9 +40,6 @@ from wok.plugins.kimchi.model.vms import VMModel
 
 
 import iso_gen
-import utils
-from utils import get_free_port, patch_auth, request
-from utils import run_server, wait_task
 
 
 ISO_DIR = '/var/lib/libvirt/images/'
@@ -72,7 +71,7 @@ def remoteserver_environment_defined():
 
 
 def running_root_and_remoteserver_defined():
-    return utils.running_as_root() and remoteserver_environment_defined()
+    return running_as_root() and remoteserver_environment_defined()
 
 
 def check_if_vm_migration_test_possible():
@@ -134,7 +133,7 @@ class LiveMigrationTests(unittest.TestCase):
     def test_vm_migrate_fails_if_remote_is_localhost(self):
         with RollbackContext() as rollback:
             self.create_vm_test()
-            rollback.prependDefer(utils.rollback_wrapper, self.inst.vm_delete,
+            rollback.prependDefer(rollback_wrapper, self.inst.vm_delete,
                                   u'test_vm_migrate')
 
             self.assertRaises(OperationFailed,
@@ -157,7 +156,7 @@ class LiveMigrationTests(unittest.TestCase):
     def test_vm_migrate_fails_if_remotehost_unreachable(self):
         with RollbackContext() as rollback:
             self.create_vm_test()
-            rollback.prependDefer(utils.rollback_wrapper, self.inst.vm_delete,
+            rollback.prependDefer(rollback_wrapper, self.inst.vm_delete,
                                   u'test_vm_migrate')
 
             self.assertRaises(OperationFailed,
@@ -168,7 +167,7 @@ class LiveMigrationTests(unittest.TestCase):
     def test_vm_migrate_fails_if_not_passwordless_login(self):
         with RollbackContext() as rollback:
             self.create_vm_test()
-            rollback.prependDefer(utils.rollback_wrapper, self.inst.vm_delete,
+            rollback.prependDefer(rollback_wrapper, self.inst.vm_delete,
                                   u'test_vm_migrate')
 
             self.assertRaises(OperationFailed,
@@ -245,7 +244,7 @@ class LiveMigrationTests(unittest.TestCase):
 
         with RollbackContext() as rollback:
             self.create_vm_test()
-            rollback.prependDefer(utils.rollback_wrapper, self.inst.vm_delete,
+            rollback.prependDefer(rollback_wrapper, self.inst.vm_delete,
                                   u'test_vm_migrate')
 
             # removing cdrom because it is not shared storage and will make
@@ -326,7 +325,7 @@ class LiveMigrationTests(unittest.TestCase):
     def test_vm_coldmigrate(self):
         with RollbackContext() as rollback:
             self.create_vm_test()
-            rollback.prependDefer(utils.rollback_wrapper, self.inst.vm_delete,
+            rollback.prependDefer(rollback_wrapper, self.inst.vm_delete,
                                   u'test_vm_migrate')
 
             # removing cdrom because it is not shared storage and will make
@@ -367,7 +366,7 @@ class LiveMigrationTests(unittest.TestCase):
 
         with RollbackContext() as rollback:
             self.create_vm_test(non_shared_storage=True)
-            rollback.prependDefer(utils.rollback_wrapper, self.inst.vm_delete,
+            rollback.prependDefer(rollback_wrapper, self.inst.vm_delete,
                                   u'test_vm_migrate')
 
             # getting disk path info to clean it up later
@@ -428,7 +427,7 @@ class LiveMigrationTests(unittest.TestCase):
             self.request = partial(request, host, ssl_port)
 
             self.create_vm_test()
-            rollback.prependDefer(utils.rollback_wrapper, self.inst.vm_delete,
+            rollback.prependDefer(rollback_wrapper, self.inst.vm_delete,
                                   u'test_vm_migrate')
 
             # removing cdrom because it is not shared storage and will make
diff --git a/src/wok/plugins/kimchi/tests/test_mock_network.py b/src/wok/plugins/kimchi/tests/test_mock_network.py
index 4e2a939..8368ced 100644
--- a/src/wok/plugins/kimchi/tests/test_mock_network.py
+++ b/src/wok/plugins/kimchi/tests/test_mock_network.py
@@ -23,10 +23,11 @@ import os
 import unittest
 from functools import partial
 
+from tests.utils import get_free_port, patch_auth, request, run_server
+
 from wok.plugins.kimchi.mockmodel import MockModel
 
 from test_model_network import _do_network_test
-from utils import get_free_port, patch_auth, request, run_server
 
 
 model = None
diff --git a/src/wok/plugins/kimchi/tests/test_mock_storagepool.py b/src/wok/plugins/kimchi/tests/test_mock_storagepool.py
index ea9843b..29488b8 100644
--- a/src/wok/plugins/kimchi/tests/test_mock_storagepool.py
+++ b/src/wok/plugins/kimchi/tests/test_mock_storagepool.py
@@ -23,9 +23,9 @@ import os
 import unittest
 from functools import partial
 
-from wok.plugins.kimchi.mockmodel import MockModel
+from tests.utils import get_free_port, patch_auth, request, run_server
 
-from utils import get_free_port, patch_auth, request, run_server
+from wok.plugins.kimchi.mockmodel import MockModel
 
 
 model = None
diff --git a/src/wok/plugins/kimchi/tests/test_mock_storagevolume.py b/src/wok/plugins/kimchi/tests/test_mock_storagevolume.py
index 9d0a5ad..f132a62 100644
--- a/src/wok/plugins/kimchi/tests/test_mock_storagevolume.py
+++ b/src/wok/plugins/kimchi/tests/test_mock_storagevolume.py
@@ -23,10 +23,11 @@ import os
 import unittest
 from functools import partial
 
+from tests.utils import get_free_port, patch_auth, request, run_server
+
 from wok.plugins.kimchi.mockmodel import MockModel
 
 from test_model_storagevolume import _do_volume_test
-from utils import get_free_port, patch_auth, request, run_server
 
 
 model = None
diff --git a/src/wok/plugins/kimchi/tests/test_mockmodel.py b/src/wok/plugins/kimchi/tests/test_mockmodel.py
index 7c914b8..ce6e837 100644
--- a/src/wok/plugins/kimchi/tests/test_mockmodel.py
+++ b/src/wok/plugins/kimchi/tests/test_mockmodel.py
@@ -23,11 +23,12 @@ import os
 import time
 import unittest
 
+from tests.utils import get_free_port, patch_auth, request, run_server
+from tests.utils import wait_task
+
 from wok.plugins.kimchi import mockmodel
 from wok.plugins.kimchi.osinfo import get_template_default
 
-from utils import get_free_port, patch_auth, request, run_server, wait_task
-
 
 test_server = None
 model = None
diff --git a/src/wok/plugins/kimchi/tests/test_model.py b/src/wok/plugins/kimchi/tests/test_model.py
index dc9fa8c..65d97f2 100644
--- a/src/wok/plugins/kimchi/tests/test_model.py
+++ b/src/wok/plugins/kimchi/tests/test_model.py
@@ -26,6 +26,8 @@ import shutil
 import time
 import unittest
 
+import tests.utils as utils
+
 import wok.objectstore
 from wok.basemodel import Singleton
 from wok.config import config
@@ -44,7 +46,6 @@ from wok.plugins.kimchi.model.libvirtconnection import LibvirtConnection
 from wok.plugins.kimchi.model.vms import VMModel
 
 import iso_gen
-import utils
 
 
 invalid_repository_urls = ['www.fedora.org',       # missing protocol
diff --git a/src/wok/plugins/kimchi/tests/test_model_network.py b/src/wok/plugins/kimchi/tests/test_model_network.py
index e4cf5ef..6be2d39 100644
--- a/src/wok/plugins/kimchi/tests/test_model_network.py
+++ b/src/wok/plugins/kimchi/tests/test_model_network.py
@@ -23,13 +23,13 @@ import os
 import unittest
 from functools import partial
 
+from tests.utils import get_free_port, patch_auth, request, rollback_wrapper
+from tests.utils import run_server
+
 from wok.rollbackcontext import RollbackContext
 
 from wok.plugins.kimchi.model.model import Model
 
-from utils import get_free_port, patch_auth, request, rollback_wrapper
-from utils import run_server
-
 
 model = None
 test_server = None
diff --git a/src/wok/plugins/kimchi/tests/test_model_storagepool.py b/src/wok/plugins/kimchi/tests/test_model_storagepool.py
index ef28bda..73dd8c0 100644
--- a/src/wok/plugins/kimchi/tests/test_model_storagepool.py
+++ b/src/wok/plugins/kimchi/tests/test_model_storagepool.py
@@ -29,8 +29,8 @@ from wok.rollbackcontext import RollbackContext
 
 from wok.plugins.kimchi.model.model import Model
 
-from utils import get_free_port, patch_auth, request
-from utils import run_server
+from tests.utils import get_free_port, patch_auth, request
+from tests.utils import run_server
 
 
 model = None
diff --git a/src/wok/plugins/kimchi/tests/test_model_storagevolume.py b/src/wok/plugins/kimchi/tests/test_model_storagevolume.py
index b387c31..49e56d3 100644
--- a/src/wok/plugins/kimchi/tests/test_model_storagevolume.py
+++ b/src/wok/plugins/kimchi/tests/test_model_storagevolume.py
@@ -24,15 +24,16 @@ import requests
 import unittest
 from functools import partial
 
+
+from tests.utils import fake_auth_header, get_free_port, patch_auth, request
+from tests.utils import rollback_wrapper, run_server, wait_task
+
 from wok.config import paths
 from wok.rollbackcontext import RollbackContext
 
 from wok.plugins.kimchi.config import READONLY_POOL_TYPE
 from wok.plugins.kimchi.model.model import Model
 
-from utils import fake_auth_header, get_free_port, patch_auth, request
-from utils import rollback_wrapper, run_server, wait_task
-
 
 model = None
 test_server = None
diff --git a/src/wok/plugins/kimchi/tests/test_networkxml.py b/src/wok/plugins/kimchi/tests/test_networkxml.py
index a64b6c2..69965e6 100644
--- a/src/wok/plugins/kimchi/tests/test_networkxml.py
+++ b/src/wok/plugins/kimchi/tests/test_networkxml.py
@@ -21,12 +21,13 @@ import ipaddr
 import lxml.etree as ET
 import unittest
 
+
+from tests.utils import normalize_xml
+
 from wok.xmlutils.utils import xpath_get_text
 
 from wok.plugins.kimchi.xmlutils import network as nxml
 
-import utils
-
 
 class NetworkXmlTests(unittest.TestCase):
     def test_dhcp_xml(self):
@@ -169,4 +170,4 @@ class InterfaceXmlTests(unittest.TestCase):
             </interface>
             """
         actual_xml = nxml.create_vlan_tagged_bridge_xml('br10', 'em1', '10')
-        self.assertEquals(actual_xml, utils.normalize_xml(expected_xml))
+        self.assertEquals(actual_xml, normalize_xml(expected_xml))
diff --git a/src/wok/plugins/kimchi/tests/test_rest.py b/src/wok/plugins/kimchi/tests/test_rest.py
index 977a255..544f2e6 100644
--- a/src/wok/plugins/kimchi/tests/test_rest.py
+++ b/src/wok/plugins/kimchi/tests/test_rest.py
@@ -27,6 +27,9 @@ import urllib2
 import urlparse
 from functools import partial
 
+from tests.utils import get_free_port, patch_auth, request
+from tests.utils import run_server, wait_task
+
 from wok.rollbackcontext import RollbackContext
 from wok.utils import add_task
 
@@ -34,8 +37,6 @@ from wok.plugins.kimchi import mockmodel
 from wok.plugins.kimchi.osinfo import get_template_default
 
 import iso_gen
-from utils import get_free_port, patch_auth, request
-from utils import run_server, wait_task
 
 
 test_server = None
diff --git a/src/wok/plugins/kimchi/tests/test_template.py b/src/wok/plugins/kimchi/tests/test_template.py
index c8f29f0..5e89d22 100644
--- a/src/wok/plugins/kimchi/tests/test_template.py
+++ b/src/wok/plugins/kimchi/tests/test_template.py
@@ -23,12 +23,12 @@ import os
 import unittest
 from functools import partial
 
+from tests.utils import get_free_port, patch_auth, request, run_server
+
 from wok.plugins.kimchi import osinfo
 from wok.plugins.kimchi.config import READONLY_POOL_TYPE
 from wok.plugins.kimchi.mockmodel import MockModel
 
-from utils import get_free_port, patch_auth, request, run_server
-
 
 model = None
 test_server = None
diff --git a/src/wok/plugins/kimchi/tests/utils.py b/src/wok/plugins/kimchi/tests/utils.py
deleted file mode 100644
index 5329324..0000000
--- a/src/wok/plugins/kimchi/tests/utils.py
+++ /dev/null
@@ -1,259 +0,0 @@
-#
-# Project Kimchi
-#
-# Copyright IBM, Corp. 2013-2015
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
-#
-
-import base64
-import cherrypy
-import grp
-import httplib
-import inspect
-import json
-import os
-import socket
-import ssl
-import sys
-import threading
-import time
-import unittest
-from contextlib import closing
-from lxml import etree
-
-import wok.server
-from wok.config import config, PluginPaths
-from wok.auth import User, USER_NAME, USER_GROUPS, USER_ROLES, tabs
-from wok.exception import NotFoundError
-from wok.utils import wok_log
-
-from wok.plugins.kimchi import mockmodel
-
-
-_ports = {}
-
-# provide missing unittest decorators and API for python 2.6; these decorators
-# do not actually work, just avoid the syntax failure
-if sys.version_info[:2] == (2, 6):
-    def skipUnless(condition, reason):
-        if not condition:
-            sys.stderr.write('[expected failure] ')
-            raise Exception(reason)
-        return lambda obj: obj
-
-    unittest.skipUnless = skipUnless
-    unittest.expectedFailure = lambda obj: obj
-
-    def assertGreater(self, a, b, msg=None):
-        if not a > b:
-            self.fail('%s not greater than %s' % (repr(a), repr(b)))
-
-    def assertGreaterEqual(self, a, b, msg=None):
-        if not a >= b:
-            self.fail('%s not greater than or equal to %s'
-                      % (repr(a), repr(b)))
-
-    def assertIsInstance(self, obj, cls, msg=None):
-        if not isinstance(obj, cls):
-            self.fail('%s is not an instance of %r' % (repr(obj), cls))
-
-    def assertIn(self, a, b, msg=None):
-        if a not in b:
-            self.fail("%s is not in %b" % (repr(a), repr(b)))
-
-    def assertNotIn(self, a, b, msg=None):
-        if a in b:
-            self.fail("%s is in %b" % (repr(a), repr(b)))
-
-    unittest.TestCase.assertGreaterEqual = assertGreaterEqual
-    unittest.TestCase.assertGreater = assertGreater
-    unittest.TestCase.assertIsInstance = assertIsInstance
-    unittest.TestCase.assertIn = assertIn
-    unittest.TestCase.assertNotIn = assertNotIn
-
-
-def get_free_port(name='http'):
-    global _ports
-    if _ports.get(name) is not None:
-        return _ports[name]
-    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-    with closing(sock):
-        try:
-            sock.bind(("0.0.0.0", 0))
-        except:
-            raise Exception("Could not find a free port")
-        _ports[name] = sock.getsockname()[1]
-        return _ports[name]
-
-
-def run_server(host, port, ssl_port, test_mode, cherrypy_port=None,
-               model=None, environment='development'):
-
-    if cherrypy_port is None:
-        cherrypy_port = get_free_port('cherrypy_port')
-
-    if ssl_port is None:
-        ssl_port = get_free_port('https')
-
-    args = type('_', (object,),
-                {'host': host, 'port': port, 'ssl_port': ssl_port,
-                 'cherrypy_port': cherrypy_port, 'max_body_size': '4*1024',
-                 'ssl_cert': '', 'ssl_key': '',
-                 'test': test_mode, 'access_log': '/dev/null',
-                 'error_log': '/dev/null', 'environment': environment,
-                 'log_level': 'debug'})()
-    if model is not None:
-        setattr(args, 'model', model)
-
-    s = wok.server.Server(args)
-    t = threading.Thread(target=s.start)
-    t.setDaemon(True)
-    t.start()
-    cherrypy.engine.wait(cherrypy.engine.states.STARTED)
-    return s
-
-
-def silence_server():
-    """
-    Silence server status messages on stdout
-    """
-    cherrypy.config.update({"environment": "embedded"})
-
-
-def running_as_root():
-    return os.geteuid() == 0
-
-
-def _request(conn, path, data, method, headers):
-    if headers is None:
-        headers = {'Content-Type': 'application/json',
-                   'Accept': 'application/json'}
-    if 'AUTHORIZATION' not in headers.keys():
-        user, pw = mockmodel.fake_user.items()[0]
-        hdr = "Basic " + base64.b64encode("%s:%s" % (user, pw))
-        headers['AUTHORIZATION'] = hdr
-    conn.request(method, path, data, headers)
-    return conn.getresponse()
-
-
-def request(host, port, path, data=None, method='GET', headers=None):
-    # verify if HTTPSConnection has context parameter
-    if "context" in inspect.getargspec(httplib.HTTPSConnection.__init__).args:
-        context = ssl._create_unverified_context()
-        conn = httplib.HTTPSConnection(host, port, context=context)
-    else:
-        conn = httplib.HTTPSConnection(host, port)
-
-    return _request(conn, path, data, method, headers)
-
-
-def get_remote_iso_path():
-    """
-    Get a remote iso with the right arch from the distro files shipped
-    with kimchi.
-    """
-    host_arch = os.uname()[4]
-    remote_path = ''
-    with open(os.path.join(PluginPaths('kimchi').conf_dir, 'distros.d',
-              'fedora.json')) as fedora_isos:
-        # Get a list of dicts
-        json_isos_list = json.load(fedora_isos)
-        for iso in json_isos_list:
-            if (iso.get('os_arch')) == host_arch:
-                remote_path = iso.get('path')
-                break
-
-    return remote_path
-
-
-class FakeUser(User):
-    auth_type = "fake"
-    sudo = True
-
-    def __init__(self, username):
-        self.user = {}
-        self.user[USER_NAME] = username
-        self.user[USER_GROUPS] = None
-        self.user[USER_ROLES] = dict.fromkeys(tabs, 'user')
-
-    def get_groups(self):
-        return sorted([group.gr_name for group in grp.getgrall()])[0:3]
-
-    def get_roles(self):
-        if self.sudo:
-            self.user[USER_ROLES] = dict.fromkeys(tabs, 'admin')
-        return self.user[USER_ROLES]
-
-    def get_user(self):
-        return self.user
-
-    @staticmethod
-    def authenticate(username, password, service="passwd"):
-        try:
-            return mockmodel.fake_user[username] == password
-        except KeyError:
-            raise cherrypy.HTTPError(500, "Authentication failed")
-
-
-def patch_auth(sudo=True):
-    """
-    Override the authenticate function with a simple test against an
-    internal dict of users and passwords.
-    """
-    config.set("authentication", "method", "fake")
-    FakeUser.sudo = sudo
-
-
-def normalize_xml(xml_str):
-    return etree.tostring(etree.fromstring(xml_str,
-                          etree.XMLParser(remove_blank_text=True)))
-
-
-def wait_task(task_lookup, taskid, timeout=10):
-    for i in range(0, timeout):
-        task_info = task_lookup(taskid)
-        if task_info['status'] == "running":
-            wok_log.info("Waiting task %s, message: %s",
-                         taskid, task_info['message'])
-            time.sleep(1)
-        else:
-            return
-    wok_log.error("Timeout while process long-run task, "
-                  "try to increase timeout value.")
-
-
-# The action functions in model backend raise NotFoundError exception if the
-# element is not found. But in some tests, these functions are called after
-# the element has been deleted if test finishes correctly, then NofFoundError
-# exception is raised and rollback breaks. To avoid it, this wrapper ignores
-# the NotFoundError.
-def rollback_wrapper(func, resource, *args):
-    try:
-        func(resource, *args)
-    except NotFoundError:
-        # VM has been deleted already
-        return
-
-
-# This function is used to test storage volume upload.
-# If we use self.request, we may encode multipart formdata by ourselves
-# requests lib take care of encode part, so use this lib instead
-def fake_auth_header():
-    headers = {'Accept': 'application/json'}
-    user, pw = mockmodel.fake_user.items()[0]
-    hdr = "Basic " + base64.b64encode("%s:%s" % (user, pw))
-    headers['AUTHORIZATION'] = hdr
-    return headers
-- 
2.4.3




More information about the Kimchi-devel mailing list