root / snf-cyclades-gtools / test / synnefo.ganeti_unittest.py @ 0e1f3323
History | View | Annotate | Download (3.9 kB)
1 |
#!/usr/bin/env python
|
---|---|
2 |
# -*- coding: utf-8 -*-
|
3 |
#
|
4 |
# Copyright 2013 GRNET S.A. All rights reserved.
|
5 |
#
|
6 |
# Redistribution and use in source and binary forms, with or
|
7 |
# without modification, are permitted provided that the following
|
8 |
# conditions are met:
|
9 |
#
|
10 |
# 1. Redistributions of source code must retain the above
|
11 |
# copyright notice, this list of conditions and the following
|
12 |
# disclaimer.
|
13 |
#
|
14 |
# 2. Redistributions in binary form must reproduce the above
|
15 |
# copyright notice, this list of conditions and the following
|
16 |
# disclaimer in the documentation and/or other materials
|
17 |
# provided with the distribution.
|
18 |
#
|
19 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
20 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
21 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
22 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
23 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
25 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
26 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
27 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
28 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
29 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30 |
# POSSIBILITY OF SUCH DAMAGE.
|
31 |
#
|
32 |
# The views and conclusions contained in the software and
|
33 |
# documentation are those of the authors and should not be
|
34 |
# interpreted as representing official policies, either expressed
|
35 |
# or implied, of GRNET S.A.
|
36 |
#
|
37 |
|
38 |
import sys |
39 |
import logging |
40 |
from synnefo.ganeti.eventd import get_instance_nics |
41 |
from mock import patch |
42 |
|
43 |
log = logging.getLogger() |
44 |
|
45 |
# Use backported unittest functionality if Python < 2.7
|
46 |
try:
|
47 |
import unittest2 as unittest |
48 |
except ImportError: |
49 |
if sys.version_info < (2, 7): |
50 |
raise Exception("The unittest2 package is required for Python < 2.7") |
51 |
import unittest |
52 |
|
53 |
|
54 |
@patch("ganeti.cli.GetClient") |
55 |
class GanetiNICTestCase(unittest.TestCase): |
56 |
def test_no_nics(self, client): |
57 |
ret = [[[], [], [], [], [], []]] |
58 |
client.return_value.QueryInstances.return_value = ret |
59 |
self.assertEqual(get_instance_nics('test', log), []) |
60 |
|
61 |
def test_one_nic(self, client): |
62 |
ret = [[["network"], ["ip"], ["mac"], ["mode"], ["link"], |
63 |
["tag1", "tag2"]]] |
64 |
client.return_value.QueryInstances.return_value = ret |
65 |
nics0 = get_instance_nics("test", log)
|
66 |
nics1 = [{"network": "network", |
67 |
"ip": "ip", |
68 |
"mac": "mac", |
69 |
"mode": "mode", |
70 |
"link": "link"}] |
71 |
self.assertEqual(nics0, nics1)
|
72 |
|
73 |
def test_two_nics(self, client): |
74 |
ret = [[["network1", "network2"], ["ip1", "ip2"], ["mac1", "mac2"], |
75 |
["mode1", "mode2"], ["link1", "link2"], ["tag1", "tag2"]]] |
76 |
client.return_value.QueryInstances.return_value = ret |
77 |
nics0 = get_instance_nics("test", log)
|
78 |
nics1 = [{"network": "network1", |
79 |
"ip": "ip1", |
80 |
"mac": "mac1", |
81 |
"mode": "mode1", |
82 |
"link": "link1"}, |
83 |
{"network": "network2", |
84 |
"ip": "ip2", |
85 |
"mac": "mac2", |
86 |
"mode": "mode2", |
87 |
"link": "link2"}] |
88 |
self.assertEqual(nics0, nics1)
|
89 |
|
90 |
def test_firewall(self, client): |
91 |
ret = [[["network"], ["ip"], ["mac"], ["mode"], ["link"], |
92 |
["tag1", "synnefo:network:0:protected"]]] |
93 |
client.return_value.QueryInstances.return_value = ret |
94 |
nics0 = get_instance_nics("test", log)
|
95 |
nics1 = [{"network": "network", |
96 |
"ip": "ip", |
97 |
"mac": "mac", |
98 |
"mode": "mode", |
99 |
"link": "link", |
100 |
"firewall": "protected"}] |
101 |
self.assertEqual(nics0, nics1)
|
102 |
|
103 |
|
104 |
if __name__ == '__main__': |
105 |
unittest.main() |