Statistics
| Branch: | Tag: | Revision:

root / ganeti / tests.py @ 9cb903f9

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

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

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

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