Statistics
| Branch: | Tag: | Revision:

root / ganeti / tests.py @ bd29052f

History | View | Annotate | Download (2.7 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_TAGS': 'tag1 synnefo:network:0:protected tag2',
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
                {
59
                    'ip': '147.102.3.1', 'mac': '00:01:de:ad:be:ef',
60
                    'link': 'xen-br0', 'ipv6': '2001:db8::201:deff:fead:beef',
61
                    'firewall': 'protected'
62
                },
63
                { 'mac': '00:01:de:ad:ba:be' },
64
                { 'ip': '147.102.3.98', 'mac': '00:01:02:03:04:05' }
65
            ]
66
        }
67

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