root / snf-cyclades-gtools / test / synnefo.ganeti_unittest.py @ a31e427d
History | View | Annotate | Download (4.4 kB)
1 |
#!/usr/bin/env python
|
---|---|
2 |
#
|
3 |
# -*- coding: utf-8 -*-
|
4 |
#
|
5 |
# Copyright 2011 GRNET S.A. All rights reserved.
|
6 |
#
|
7 |
# Redistribution and use in source and binary forms, with or
|
8 |
# without modification, are permitted provided that the following
|
9 |
# conditions are met:
|
10 |
#
|
11 |
# 1. Redistributions of source code must retain the above
|
12 |
# copyright notice, this list of conditions and the following
|
13 |
# disclaimer.
|
14 |
#
|
15 |
# 2. Redistributions in binary form must reproduce the above
|
16 |
# copyright notice, this list of conditions and the following
|
17 |
# disclaimer in the documentation and/or other materials
|
18 |
# provided with the distribution.
|
19 |
#
|
20 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
21 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
23 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
24 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
27 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
28 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
29 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
30 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31 |
# POSSIBILITY OF SUCH DAMAGE.
|
32 |
#
|
33 |
# The views and conclusions contained in the software and
|
34 |
# documentation are those of the authors and should not be
|
35 |
# interpreted as representing official policies, either expressed
|
36 |
# or implied, of GRNET S.A.
|
37 |
#
|
38 |
#
|
39 |
|
40 |
"""Unit Tests for the Ganeti-specific interfaces in synnefo.ganeti
|
41 |
|
42 |
Provides unit tests for the code implementing
|
43 |
the Ganeti notification daemon and the Ganeti hook in Synnefo.
|
44 |
|
45 |
"""
|
46 |
|
47 |
# This assumes a test-specific configuration file
|
48 |
# is in the same directory as the unit test script
|
49 |
import os |
50 |
os.environ["SYNNEFO_CONFIG_DIR"] = os.path.dirname(__file__)
|
51 |
|
52 |
import logging |
53 |
import unittest |
54 |
|
55 |
from synnefo.ganeti.hook import ganeti_net_status |
56 |
|
57 |
|
58 |
class GanetiHookTestCase(unittest.TestCase): |
59 |
|
60 |
def setUp(self): |
61 |
# Example Ganeti environment, based on from
|
62 |
# http://docs.ganeti.org/ganeti/master/html/hooks.html?highlight=hooks#examples
|
63 |
self.env = {
|
64 |
'GANETI_CLUSTER': 'cluster1.example.com', |
65 |
'GANETI_DATA_DIR': '/var/lib/ganeti', |
66 |
'GANETI_FORCE': 'False', |
67 |
'GANETI_HOOKS_PATH': 'instance-start', |
68 |
'GANETI_HOOKS_PHASE': 'post', |
69 |
'GANETI_HOOKS_VERSION': '2', |
70 |
'GANETI_INSTANCE_DISK0_MODE': 'rw', |
71 |
'GANETI_INSTANCE_DISK0_SIZE': '128', |
72 |
'GANETI_INSTANCE_DISK_COUNT': '1', |
73 |
'GANETI_INSTANCE_DISK_TEMPLATE': 'drbd', |
74 |
'GANETI_INSTANCE_MEMORY': '128', |
75 |
'GANETI_INSTANCE_TAGS': 'tag1 synnefo:network:0:protected tag2', |
76 |
'GANETI_INSTANCE_NAME': 'instance2.example.com', |
77 |
'GANETI_INSTANCE_NIC0_BRIDGE': 'xen-br0', |
78 |
'GANETI_INSTANCE_NIC0_IP': '147.102.3.1', |
79 |
'GANETI_INSTANCE_NIC0_MAC': '00:01:de:ad:be:ef', |
80 |
'GANETI_INSTANCE_NIC1_MAC': '00:01:de:ad:ba:be', |
81 |
'GANETI_INSTANCE_NIC2_MAC': '00:01:02:03:04:05', |
82 |
'GANETI_INSTANCE_NIC2_IP': '147.102.3.98', |
83 |
'GANETI_INSTANCE_NIC_COUNT': '3', |
84 |
'GANETI_INSTANCE_OS_TYPE': 'debootstrap', |
85 |
'GANETI_INSTANCE_PRIMARY': 'node3.example.com', |
86 |
'GANETI_INSTANCE_SECONDARY': 'node5.example.com', |
87 |
'GANETI_INSTANCE_STATUS': 'down', |
88 |
'GANETI_INSTANCE_VCPUS': '1', |
89 |
'GANETI_MASTER': 'node1.example.com', |
90 |
'GANETI_OBJECT_TYPE': 'INSTANCE', |
91 |
'GANETI_OP_CODE': 'OP_INSTANCE_STARTUP', |
92 |
'GANETI_OP_TARGET': 'instance2.example.com' |
93 |
} |
94 |
|
95 |
def test_ganeti_net_status(self): |
96 |
e = self.env
|
97 |
expected = { |
98 |
'type': 'ganeti-net-status', |
99 |
'instance': 'instance2.example.com', |
100 |
'nics': [
|
101 |
{ |
102 |
'ip': '147.102.3.1', 'mac': '00:01:de:ad:be:ef', |
103 |
'link': 'xen-br0', 'ipv6': '2001:db8::201:deff:fead:beef', |
104 |
'firewall': 'protected' |
105 |
}, |
106 |
{ 'mac': '00:01:de:ad:ba:be' }, |
107 |
{ 'ip': '147.102.3.98', 'mac': '00:01:02:03:04:05' } |
108 |
] |
109 |
} |
110 |
|
111 |
self.assertEqual(ganeti_net_status(logging, e), expected)
|
112 |
|
113 |
|
114 |
if __name__ == '__main__': |
115 |
unittest.main() |
116 |
|