Revision 95aee02c logic/tests.py

b/logic/tests.py
34 34
from synnefo.logic import backend
35 35
from synnefo.logic import credits
36 36
from synnefo.logic import users
37
from synnefo.logic.utils import get_rsapi_state
38

  
37 39
from django.test import TestCase
38
import time
40
from django.conf import settings
39 41

  
42
import time
40 43
import hashlib
41 44

  
42 45
class CostsTestCase(TestCase):
......
127 130

  
128 131
        self.assertEqual(0, s_user.credit, 'SynnefoUser (pk=30000) should have zero credits (%d)' % ( s_user.credit, ))
129 132

  
133

  
130 134
class AuthTestCase(TestCase):
131 135
    fixtures = [ 'db_test_data' ]
132 136

  
......
156 160
        
157 161
        users.delete_user(self.user)
158 162

  
159
        self.assertRaises(SynnefoUser.DoesNotExist, SynnefoUser.objects.get, name = "jpage")
163
        self.assertRaises(SynnefoUser.DoesNotExist, SynnefoUser.objects.get,
164
                          name = "jpage")
165

  
166

  
167
class ProcessOpStatusTestCase(TestCase):
168
    fixtures = ['db_test_data']
169
    msg_op = {
170
        'instance': 'instance-name',
171
        'type': 'ganeti-op-status',
172
        'operation': 'OP_INSTANCE_STARTUP',
173
        'jobId': 0,
174
        'status': 'success',
175
        'logmsg': 'unittest - simulated message'
176
    }
177

  
178
    def test_op_startup_success(self):
179
        """Test notification for successful OP_INSTANCE_START"""
180
        msg = self.msg_op
181
        msg['operation'] = 'OP_INSTANCE_STARTUP'
182
        msg['status'] = 'success'
183

  
184
        # This machine is initially in BUILD
185
        vm = VirtualMachine.objects.get(pk=30002)
186
        backend.process_op_status(vm, msg["jobId"], msg["operation"],
187
                                  msg["status"], msg["logmsg"])
188
        self.assertEquals(get_rsapi_state(vm), 'ACTIVE')
189

  
190
    def test_op_shutdown_success(self):
191
        """Test notification for successful OP_INSTANCE_SHUTDOWN"""
192
        msg = self.msg_op
193
        msg['operation'] = 'OP_INSTANCE_SHUTDOWN'
194
        msg['status'] = 'success'
195

  
196
        # This machine is initially in BUILD
197
        vm = VirtualMachine.objects.get(pk=30002)
198
        backend.process_op_status(vm, msg["jobId"], msg["operation"],
199
                                  msg["status"], msg["logmsg"])
200
        self.assertEquals(get_rsapi_state(vm), 'STOPPED')
201

  
202
    def test_op_reboot_success(self):
203
        """Test notification for successful OP_INSTANCE_REBOOT"""
204
        msg = self.msg_op
205
        msg['operation'] = 'OP_INSTANCE_REBOOT'
206
        msg['status'] = 'success'
207

  
208
        # This machine is initially in BUILD
209
        vm = VirtualMachine.objects.get(pk=30002)
210
        backend.process_op_status(vm, msg["jobId"], msg["operation"],
211
                                  msg["status"], msg["logmsg"])
212
        self.assertEquals(get_rsapi_state(vm), 'ACTIVE')
213

  
214
    def test_op_create_success(self):
215
        """Test notification for successful OP_INSTANCE_CREATE"""
216
        msg = self.msg_op
217
        msg['operation'] = 'OP_INSTANCE_CREATE'
218
        msg['status'] = 'success'
219

  
220
        # This machine is initially in BUILD
221
        vm = VirtualMachine.objects.get(pk=30002)
222
        backend.process_op_status(vm, msg["jobId"], msg["operation"],
223
                                  msg["status"], msg["logmsg"])
224
        self.assertEquals(get_rsapi_state(vm), 'ACTIVE')
225

  
226
    def test_op_remove_success(self):
227
        """Test notification for successful OP_INSTANCE_REMOVE"""
228
        msg = self.msg_op
229
        msg['operation'] = 'OP_INSTANCE_REMOVE'
230
        msg['status'] = 'success'
231

  
232
        # This machine is initially in BUILD
233
        vm = VirtualMachine.objects.get(pk=30002)
234
        backend.process_op_status(vm, msg["jobId"], msg["operation"],
235
                                  msg["status"], msg["logmsg"])
236
        self.assertEquals(get_rsapi_state(vm), 'DELETED')
237
        self.assertTrue(vm.deleted)
238

  
239
    def test_unknown_op(self):
240
        """Test notification for unknown Ganeti op raises exception"""
241
        msg = self.msg_op
242
        msg['operation'] = 'OP_INSTANCE_SOMETHING_ELSE'
243
        msg['status'] = 'success'
244

  
245
        # This machine is initially in BUILD
246
        vm = VirtualMachine.objects.get(pk=30002)
247
        self.assertRaises(VirtualMachine.InvalidBackendMsgError,
248
                          backend.process_op_status,
249
                          vm, msg["jobId"], msg["operation"],
250
                          msg["status"], msg["logmsg"])
251

  
252
    def test_op_create_error(self):
253
        """Test notification for failed OP_INSTANCE_CREATE"""
254
        msg = self.msg_op
255
        msg['operation'] = 'OP_INSTANCE_CREATE'
256
        msg['status'] = 'error'
257

  
258
        # This machine is initially in BUILD
259
        vm = VirtualMachine.objects.get(pk=30002)
260
        backend.process_op_status(vm, msg["jobId"], msg["operation"],
261
                                  msg["status"], msg["logmsg"])
262
        self.assertEquals(get_rsapi_state(vm), 'ERROR')
263
        self.assertFalse(vm.deleted)
264

  
265
    def test_remove_machine_in_error(self):
266
        """Test notification for failed OP_INSTANCE_REMOVE, server in ERROR"""
267
        msg = self.msg_op
268
        msg['operation'] = 'OP_INSTANCE_REMOVE'
269
        msg['status'] = 'error'
270

  
271
        # This machine is initially in BUILD
272
        vm = VirtualMachine.objects.get(pk=30002)
273
        backend.process_op_status(vm, 0, "OP_INSTANCE_CREATE", "error", "test")
274
        self.assertEquals(get_rsapi_state(vm), 'ERROR')
275

  
276
        backend.process_op_status(vm, msg["jobId"], msg["operation"],
277
                                  msg["status"], msg["logmsg"])
278
        self.assertEquals(get_rsapi_state(vm), 'DELETED')
279
        self.assertTrue(vm.deleted)
160 280

  
161 281

  
162 282
class ProcessNetStatusTestCase(TestCase):

Also available in: Unified diff