forked from akevinieron/proxmox_client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
149 lines (118 loc) · 5.14 KB
/
test.py
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import unittest
from main import ProxmoxClient
CONFIG = {
"base_url": "192.168.1.21",
"verify_ssl": False,
"password": "010203",
"username": "root@pam"
}
# Requirement for run this file:
# 1. Vm or container for clonning and set vmid in setUp method
# 2. Vm or container for template and set vmid in setUp method
# 3. Vm or container for remove and set vmid in setUp method
# 4. Vm or container for other and set vmid in setUp method
# 5. Change node name in setUp method
class ProxmoxClientTest(unittest.TestCase):
def setUp(self):
self.client = ProxmoxClient(CONFIG)
self.type_list = type([])
self.type_dict = type({})
self.success_result = { "message": 'Success!!' }
self.node = "eddy"
#nodes
self.vm_for_clonning = 100
self.vm_for_template = 101
self.vm_for_remove = 102
self.vm_for_other = 103
self.nextid = self.client.get_nextid()
def test_get_ticket(self):
try:
client = ProxmoxClient(CONFIG)
except:
self.fail("Error to get ticket")
self.assertTrue(True)
def test_get_cluster_tasks(self):
result = self.client.get_cluster_tasks()
self.assertTrue(type(result) is self.type_list)
def test_get_cluster_status(self):
result = self.client.get_cluster_status()
self.assertTrue(type(result) is self.type_list)
def test_get_cluster_resources(self):
result = self.client.get_cluster_resources()
self.assertTrue(type(result) is self.type_list)
def test_get_cluster_nextid(self):
result = self.client.get_cluster_nextid()
self.assertTrue(type(result) is int)
def test_get_cluster_logs(self):
result = self.client.get_cluster_logs()
self.assertTrue(type(result) is self.type_list)
def test_get_cluster_replications(self):
result = self.client.get_cluster_resources()
self.assertTrue(type(result) is self.type_list)
def test_update_cluster_options(self):
result = self.client.update_cluster_options(data={ 'language': 'en' })
self.assertEqual(result, self.success_result)
# Containers
def test_get_all_ct(self):
result = self.client.get_all_ct(data={ "node": self.node })
self.assertTrue(type(result) is self.type_list)
def test_get_nextid(self):
result = self.client.get_nextid()
self.assertTrue(type(result) is int)
def test_get_config_ct(self):
result = self.client.get_config_ct(data={ "node": self.node, "vmid": self.vm_for_other })
self.assertTrue(type(result) is self.type_dict)
def test_create_snapshot(self):
result = self.client.create_snapshot(data={ "node": self.node, 'vmid': self.vm_for_other, "snapname": 'any' })
self.assertEqual(result, self.success_result)
def test_start_ct(self):
result = self.client.start_ct(data={ "node": self.node, 'vmid': self.vm_for_other })
self.assertEqual(result, self.success_result)
def test_stop_ct(self):
result = self.client.stop_ct(data={ "node": self.node, 'vmid': self.vm_for_other })
self.assertEqual(result, self.success_result)
def test_get_snapshots(self):
result = self.client.get_snapshots(data={ "node": self.node, "vmid": self.vm_for_other })
self.assertTrue(type(result) is self.type_list)
def test_get_snapshot(self):
result = self.client.get_snapshot(data={ "node": self.node, "vmid": self.vm_for_other, "snapname": "any" })
self.assertTrue(type(result) is self.type_dict)
def test_clone_ct(self):
result = self.client.clone_ct(data={ "node": self.node, 'vmid':self.vm_for_clonning})
self.assertEqual(result, self.success_result)
def test_create_template(self):
result = self.client.create_template(data={ "node": self.node, 'vmid': self.vm_for_template })
self.assertEqual(result, self.success_result)
def test_update_config_ct(self):
result = self.client.update_config_ct(data={ "node": self.node, 'vmid': self.vm_for_other, "cores": 2 })
self.assertEqual(result, self.success_result)
def test_update_snapshot(self):
result = self.client.update_snapshot(data={
"node": self.node,
'vmid': self.vm_for_other,
"snapname": "any",
"description": "other"
})
self.assertEqual(result, self.success_result)
def test_rollback_snapshot(self):
result = self.client.rollback_snapshot(data={
"node": self.node,
'vmid': self.vm_for_other,
"snapname": "any"
})
self.assertEqual(result, self.success_result)
def test_delete_snapshot(self):
result = self.client.delete_snapshot(data={
"node": self.node,
"vmid": self.vm_for_other,
"snapname": "any"
})
self.assertEqual(result, self.success_result)
def test_delete_ct(self):
result = self.client.delete_ct(data={
"node": self.node,
"vmid": self.vm_for_remove
})
self.assertEqual(result, self.success_result)
if __name__ == '__main__':
unittest.main()