forked from tecstack/forward
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestMainClass.py
More file actions
99 lines (91 loc) · 3.47 KB
/
Copy pathtestMainClass.py
File metadata and controls
99 lines (91 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# (c) 2015-2018, Wang Zhe <[email protected]>, Zhang Qi Chuan <[email protected]>
#
# This file is part of Ansible
#
# Forward is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Forward is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import unittest
import importlib
from forward import Forward
from forward.utils.forwardError import ForwardError
class TestMainForward(unittest.TestCase):
def test_init(self):
# new blank instance
new_blank = Forward()
self.assertEquals(new_blank.targets, [])
self.assertEquals(new_blank.instances, {})
self.assertTrue(isinstance(new_blank, Forward))
# new success instance
new_success = Forward(targets=[
['192.168.1.1', 'vlb', 'admin', 'admin_pw', {'port': 22, 'timeout': 30}],
['192.168.1.1', 'vlb', 'admin', 'admin_pw']
])
self.assertEquals(new_success.targets, [
['192.168.1.1', 'vlb', 'admin', 'admin_pw', {'port': 22, 'timeout': 30}],
['192.168.1.1', 'vlb', 'admin', 'admin_pw']
])
self.assertTrue(isinstance(new_success, Forward))
# new fail instance
with self.assertRaises(ForwardError):
new_fail = Forward(targets=[['192.168.1.1', 'vlb', 'admin', 234]])
def test_add_targets(self):
new_blank = Forward()
new_blank.addTargets(
['192.168.113.123'],
'bclinux7',
'north_king',
'wolf_spirit',
timeout=40,
port=25
)
new_blank.addTargets(
['192.168.113.124-192.168.113.126'],
'vlb',
'south_king',
'fish_spirit'
)
self.assertEquals(new_blank.targets, [
['192.168.113.123', 'bclinux7', 'north_king', 'wolf_spirit', {'timeout': 40, 'port': 25}],
['192.168.113.124', 'vlb', 'south_king', 'fish_spirit', {}],
['192.168.113.125', 'vlb', 'south_king', 'fish_spirit', {}],
['192.168.113.126', 'vlb', 'south_king', 'fish_spirit', {}]
])
def test_get_instances(self):
new_blank = Forward()
new_blank.addTargets(
['192.168.113.123'],
'bclinux7',
'north_king',
'wolf_spirit',
timeout=40,
port=25
)
new_blank.addTargets(
['192.168.113.124-192.168.113.126'],
'vlb',
'south_king',
'fish_spirit'
)
instances = new_blank.getInstances(preLogin=False)
node123 = instances['192.168.113.123']
node124 = instances['192.168.113.124']
node125 = instances['192.168.113.125']
node126 = instances['192.168.113.126']
self.assertTrue(isinstance(node123, getattr(
importlib.import_module('forward.devclass.%s' % 'bclinux7'),
'BCLINUX7'
)))
self.assertTrue(isinstance(node125, getattr(
importlib.import_module('forward.devclass.%s' % 'vlb'),
'VLB'
)))