Statistics
| Branch: | Tag: | Revision:

root / ganeti / tests.py @ c0f6fb49

History | View | Annotate | Download (2.7 kB)

1 06a0e098 Vassilios Karakoidas
#
2 ff55193e Vangelis Koukis
# Unit Tests for the Ganeti-specific interfaces
3 06a0e098 Vassilios Karakoidas
#
4 ff55193e Vangelis Koukis
# Provides unit tests for the code implementing
5 ff55193e Vangelis Koukis
# the Ganeti notification daemon and the Ganeti hook in Synnefo.
6 06a0e098 Vassilios Karakoidas
#
7 ff55193e Vangelis Koukis
# Copyright 2011 Greek Research and Technology Network
8 06a0e098 Vassilios Karakoidas
#
9 ff55193e Vangelis Koukis
import logging
10 06a0e098 Vassilios Karakoidas
11 ff55193e Vangelis Koukis
from django.test import TestCase
12 ff55193e Vangelis Koukis
from django.conf import settings
13 06a0e098 Vassilios Karakoidas
14 ff55193e Vangelis Koukis
from ganeti.hooks import ganeti_net_status
15 ff55193e Vangelis Koukis
16 ff55193e Vangelis Koukis
class GanetiHookTestCase(TestCase):
17 ff55193e Vangelis Koukis
    def setUp(self):
18 ff55193e Vangelis Koukis
        # Example Ganeti environment, based on from
19 ff55193e Vangelis Koukis
        # http://docs.ganeti.org/ganeti/master/html/hooks.html?highlight=hooks#examples
20 ff55193e Vangelis Koukis
        self.env = {
21 ff55193e Vangelis Koukis
            'GANETI_CLUSTER': 'cluster1.example.com',
22 ff55193e Vangelis Koukis
            'GANETI_DATA_DIR': '/var/lib/ganeti',
23 ff55193e Vangelis Koukis
            'GANETI_FORCE': 'False',
24 ff55193e Vangelis Koukis
            'GANETI_HOOKS_PATH': 'instance-start',
25 ff55193e Vangelis Koukis
            'GANETI_HOOKS_PHASE': 'post',
26 ff55193e Vangelis Koukis
            'GANETI_HOOKS_VERSION': '2',
27 ff55193e Vangelis Koukis
            'GANETI_INSTANCE_DISK0_MODE': 'rw',
28 ff55193e Vangelis Koukis
            'GANETI_INSTANCE_DISK0_SIZE': '128',
29 ff55193e Vangelis Koukis
            'GANETI_INSTANCE_DISK_COUNT': '1',
30 ff55193e Vangelis Koukis
            'GANETI_INSTANCE_DISK_TEMPLATE': 'drbd',
31 ff55193e Vangelis Koukis
            'GANETI_INSTANCE_MEMORY': '128',
32 eab0602e Vangelis Koukis
            'GANETI_INSTANCE_TAGS': 'tag1 synnefo:network:0:protected tag2',
33 ff55193e Vangelis Koukis
            'GANETI_INSTANCE_NAME': 'instance2.example.com',
34 ff55193e Vangelis Koukis
            'GANETI_INSTANCE_NIC0_BRIDGE': 'xen-br0',
35 ff55193e Vangelis Koukis
            'GANETI_INSTANCE_NIC0_IP': '147.102.3.1',
36 ff55193e Vangelis Koukis
            'GANETI_INSTANCE_NIC0_MAC': '00:01:de:ad:be:ef',
37 ff55193e Vangelis Koukis
            'GANETI_INSTANCE_NIC1_MAC': '00:01:de:ad:ba:be',
38 ff55193e Vangelis Koukis
            'GANETI_INSTANCE_NIC2_MAC': '00:01:02:03:04:05',
39 ff55193e Vangelis Koukis
            'GANETI_INSTANCE_NIC2_IP': '147.102.3.98',
40 ff55193e Vangelis Koukis
            'GANETI_INSTANCE_NIC_COUNT': '3',
41 ff55193e Vangelis Koukis
            'GANETI_INSTANCE_OS_TYPE': 'debootstrap',
42 ff55193e Vangelis Koukis
            'GANETI_INSTANCE_PRIMARY': 'node3.example.com',
43 ff55193e Vangelis Koukis
            'GANETI_INSTANCE_SECONDARY': 'node5.example.com',
44 ff55193e Vangelis Koukis
            'GANETI_INSTANCE_STATUS': 'down',
45 ff55193e Vangelis Koukis
            'GANETI_INSTANCE_VCPUS': '1',
46 ff55193e Vangelis Koukis
            'GANETI_MASTER': 'node1.example.com',
47 ff55193e Vangelis Koukis
            'GANETI_OBJECT_TYPE': 'INSTANCE',
48 ff55193e Vangelis Koukis
            'GANETI_OP_CODE': 'OP_INSTANCE_STARTUP',
49 ff55193e Vangelis Koukis
            'GANETI_OP_TARGET': 'instance2.example.com'
50 ff55193e Vangelis Koukis
        }
51 ff55193e Vangelis Koukis
52 ff55193e Vangelis Koukis
    def test_ganeti_net_status(self):
53 ff55193e Vangelis Koukis
        e = self.env
54 ff55193e Vangelis Koukis
        expected = {
55 ff55193e Vangelis Koukis
            'type': 'ganeti-net-status',
56 ff55193e Vangelis Koukis
            'instance': 'instance2.example.com',
57 ff55193e Vangelis Koukis
            'nics': [
58 746c6bf4 Vangelis Koukis
                {
59 746c6bf4 Vangelis Koukis
                    'ip': '147.102.3.1', 'mac': '00:01:de:ad:be:ef',
60 eab0602e Vangelis Koukis
                    'link': 'xen-br0', 'ipv6': '2001:db8::201:deff:fead:beef',
61 eab0602e Vangelis Koukis
                    'firewall': 'protected'
62 746c6bf4 Vangelis Koukis
                },
63 ff55193e Vangelis Koukis
                { 'mac': '00:01:de:ad:ba:be' },
64 ff55193e Vangelis Koukis
                { 'ip': '147.102.3.98', 'mac': '00:01:02:03:04:05' }
65 ff55193e Vangelis Koukis
            ]
66 ff55193e Vangelis Koukis
        }
67 ff55193e Vangelis Koukis
68 ff55193e Vangelis Koukis
        self.assertEqual(ganeti_net_status(logging, e), expected)