Statistics
| Branch: | Tag: | Revision:

root / ganeti / tests.py @ ff55193e

History | View | Annotate | Download (2.5 kB)

1
#
2
# Unit Tests for the Ganeti-specific interfaces
3
#
4
# Provides unit tests for the code implementing
5
# the Ganeti notification daemon and the Ganeti hook in Synnefo.
6
#
7
# Copyright 2011 Greek Research and Technology Network
8
#
9
import logging
10

    
11
from django.test import TestCase
12
from django.conf import settings
13

    
14
from ganeti.hooks import ganeti_net_status
15
from ganeti.hooks import post_start_hook
16

    
17
class GanetiHookTestCase(TestCase):
18
    def setUp(self):
19
        # Example Ganeti environment, based on from
20
        # http://docs.ganeti.org/ganeti/master/html/hooks.html?highlight=hooks#examples
21
        self.env = {
22
            'GANETI_CLUSTER': 'cluster1.example.com',
23
            'GANETI_DATA_DIR': '/var/lib/ganeti',
24
            'GANETI_FORCE': 'False',
25
            'GANETI_HOOKS_PATH': 'instance-start',
26
            'GANETI_HOOKS_PHASE': 'post',
27
            'GANETI_HOOKS_VERSION': '2',
28
            'GANETI_INSTANCE_DISK0_MODE': 'rw',
29
            'GANETI_INSTANCE_DISK0_SIZE': '128',
30
            'GANETI_INSTANCE_DISK_COUNT': '1',
31
            'GANETI_INSTANCE_DISK_TEMPLATE': 'drbd',
32
            'GANETI_INSTANCE_MEMORY': '128',
33
            'GANETI_INSTANCE_NAME': 'instance2.example.com',
34
            'GANETI_INSTANCE_NIC0_BRIDGE': 'xen-br0',
35
            'GANETI_INSTANCE_NIC0_IP': '147.102.3.1',
36
            'GANETI_INSTANCE_NIC0_MAC': '00:01:de:ad:be:ef',
37
            'GANETI_INSTANCE_NIC1_MAC': '00:01:de:ad:ba:be',
38
            'GANETI_INSTANCE_NIC2_MAC': '00:01:02:03:04:05',
39
            'GANETI_INSTANCE_NIC2_IP': '147.102.3.98',
40
            'GANETI_INSTANCE_NIC_COUNT': '3',
41
            'GANETI_INSTANCE_OS_TYPE': 'debootstrap',
42
            'GANETI_INSTANCE_PRIMARY': 'node3.example.com',
43
            'GANETI_INSTANCE_SECONDARY': 'node5.example.com',
44
            'GANETI_INSTANCE_STATUS': 'down',
45
            'GANETI_INSTANCE_VCPUS': '1',
46
            'GANETI_MASTER': 'node1.example.com',
47
            'GANETI_OBJECT_TYPE': 'INSTANCE',
48
            'GANETI_OP_CODE': 'OP_INSTANCE_STARTUP',
49
            'GANETI_OP_TARGET': 'instance2.example.com'
50
        }
51

    
52
    def test_ganeti_net_status(self):
53
        e = self.env
54
        expected = {
55
            'type': 'ganeti-net-status',
56
            'instance': 'instance2.example.com',
57
            'nics': [
58
                { 'ip': '147.102.3.1', 'mac': '00:01:de:ad:be:ef' },
59
                { 'mac': '00:01:de:ad:ba:be' },
60
                { 'ip': '147.102.3.98', 'mac': '00:01:02:03:04:05' }
61
            ]
62
        }
63

    
64
        self.assertEqual(ganeti_net_status(logging, e), expected)