forked from ungleich/python-oca
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_virtual_network.py
More file actions
63 lines (51 loc) · 1.99 KB
/
Copy pathtest_virtual_network.py
File metadata and controls
63 lines (51 loc) · 1.99 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
# -*- coding: UTF-8 -*-
import os
from mock import Mock
import oca
VN_TEMPLATE = '''NAME = "Red LAN"
TYPE = RANGED
PUBLIC = NO
BRIDGE = vbr0
NETWORK_SIZE = C
NETWORK_ADDRESS = 192.168.0.0'''
class TestVirtualNetwork:
def setUp(self):
self.client = oca.Client('test:test')
self.xml = open(os.path.join(os.path.dirname(oca.__file__),
'tests/fixtures/vnet.xml')).read()
def test_allocate(self):
self.client.call = Mock(return_value=2)
assert oca.VirtualNetwork.allocate(self.client, VN_TEMPLATE) == 2
def test_publish(self):
self.client.call = Mock(return_value='')
h = oca.VirtualNetwork(self.xml, self.client)
h._convert_types()
h.publish()
self.client.call.assert_called_once_with('vn.publish', 3, True)
def test_unpublish(self):
self.client.call = Mock(return_value='')
h = oca.VirtualNetwork(self.xml, self.client)
h._convert_types()
h.unpublish()
self.client.call.assert_called_once_with('vn.publish', 3, False)
def test_repr(self):
h = oca.VirtualNetwork(self.xml, self.client)
h._convert_types()
assert h.__repr__() == '<oca.VirtualNetwork("Red LAN")>'
def test_chown(self):
self.client.call = Mock(return_value='')
h = oca.VirtualNetwork(self.xml, self.client)
h._convert_types()
h.chown(2, 2)
self.client.call.assert_called_once_with('vn.chown', 3, 2, 2)
def test_address_ranges(self):
h = oca.VirtualNetwork(self.xml, self.client)
h._convert_types()
assert(2==len(h.address_ranges))
assert(1==h.address_ranges[1].id)
assert(0==h.address_ranges[0].id)
assert(" 0 68719479930 1 68719545020"==h.address_ranges[0].allocated)
assert("10.1.0.10"==h.address_ranges[0].ip)
assert("00:22:44:66:88:aa"==h.address_ranges[0].mac)
assert(507==h.address_ranges[0].size)
assert("IP4"==h.address_ranges[0].type)