Revision bd87213f snf-cyclades-app/synnefo/db/tests.py

b/snf-cyclades-app/synnefo/db/tests.py
33 33

  
34 34
from django.test import TestCase
35 35

  
36
from synnefo import settings
36 37
# Import pool tests
37 38
from synnefo.db.pools.tests import *
38 39

  
......
42 43

  
43 44
from django.db import IntegrityError
44 45
from django.core.exceptions import MultipleObjectsReturned
46
from snf_django.utils.testing import override_settings
45 47
from mock import patch
46 48

  
47 49

  
......
120 122
        self.assertNotEqual(self.backend.password_hash, password_hash)
121 123
        self.assertEqual(self.backend.password, '123')
122 124

  
125
    def test_hypervisor(self):
126
        from synnefo.db.models import snf_settings
127
        kvm_backend = mfact.BackendFactory(hypervisor="kvm")
128
        xen_pvm_backend = mfact.BackendFactory(hypervisor="xen-pvm")
129
        xen_hvm_backend = mfact.BackendFactory(hypervisor="xen-hvm")
130
        with override_settings(snf_settings, GANETI_USE_HOTPLUG=True):
131
            self.assertTrue(kvm_backend.use_hotplug())
132
            self.assertFalse(xen_pvm_backend.use_hotplug())
133
            self.assertFalse(xen_hvm_backend.use_hotplug())
134
        with override_settings(snf_settings, GANETI_USE_HOTPLUG=False):
135
            self.assertFalse(kvm_backend.use_hotplug())
136
            self.assertFalse(xen_pvm_backend.use_hotplug())
137
            self.assertFalse(xen_hvm_backend.use_hotplug())
138
        kwargs = {"os": "snf-image+default",
139
                  "hvparams": {"kvm": {"foo1": "mpaz1"},
140
                               "xen-pvm": {"foo2": "mpaz2"},
141
                               "xen-hvm": {"foo3": "mpaz3"}}}
142
        with override_settings(snf_settings,
143
                               GANETI_CREATEINSTANCE_KWARGS=kwargs):
144
            self.assertEqual(kvm_backend.get_create_params(),
145
                    {"os": "snf-image+default",
146
                     "hvparams": {"foo1": "mpaz1"}})
147
            self.assertEqual(xen_pvm_backend.get_create_params(),
148
                    {"os": "snf-image+default",
149
                     "hvparams": {"foo2": "mpaz2"}})
150
            self.assertEqual(xen_hvm_backend.get_create_params(),
151
                    {"os": "snf-image+default",
152
                     "hvparams": {"foo3": "mpaz3"}})
153
        with override_settings(snf_settings, GANETI_CREATEINSTANCE_KWARGS={}):
154
            self.assertEqual(kvm_backend.get_create_params(), {"hvparams": {}})
155

  
123 156

  
124 157
class VirtualMachineTest(TestCase):
125 158
    def setUp(self):

Also available in: Unified diff