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
|
import json
import yaml
from mock import patch
#from mock import call, patch, MagicMock
from test_utils import CharmTestCase
import nova_vmware_hooks as hooks
TO_PATCH = [
'config',
'log',
'Hooks',
'apt_install',
'relation_ids',
'relation_set',
'relation_get',
]
TEST_CONFIG = {
'flat_network_bridge': 'br100',
'vmwareapi_ip': 'vmware.mydatacenter',
'vmwareapi_username': 'adam',
'vmwareapi_password': 'foo',
'vmwareapi_cluster_name': 'testcluster',
'vmwareapi_vlan_interface': 'vmnic0',
'vmwareapi_integration_bridge': 'br-int',
}
EXPECTED_RELATION_YAML = """
nova:
/etc/nova/nova.conf:
sections:
DEFAULT:
- [vmwareapi_cluster_name, testcluster]
- [vmwareapi_host_password, foo]
- [flat_network_bridge, br100]
- [vmwareapi_integration_bridge, br-int]
- [vmwareapi_wsdl_loc, 'http://vmware.mydatacenter/sdk/vimService.wsdl']
- [vmwareapi_vlan_interface, vmnic0]
- [compute_driver, vmwareapi.VMwareVCDriver]
- [vmwareapi_host_ip, vmware.mydatacenter]
- [vmwareapi_host_username, adam]
"""
class NovaVMWTests(CharmTestCase):
def setUp(self):
super(NovaVMWTests, self).setUp(hooks, TO_PATCH)
self.config.return_value = TEST_CONFIG
def test_install(self):
hooks.install()
self.apt_install.assert_called_with(
['nova-compute-qemu'],
fatal=True)
def test_principle_changed_no_data(self):
self.relation_get.return_value = ''
with patch.object(hooks, 'install_net_manager_packages') as _inst:
hooks.nova_vmware_relation_changed()
self.assertFalse(_inst.called)
@patch.object(hooks, 'config_changed')
def test_principle_changed_with_data(self, cc):
self.relation_get.return_value = 'somenetmanager'
with patch.object(hooks, 'install_net_manager_packages') as _inst:
hooks.nova_vmware_relation_changed()
_inst.assert_called_with('somenetmanager')
assert cc.called
def test_config_changed(self):
# ensure config settings are appropriately reformated to a json
# relation setting that reflects the spec.
self.relation_ids.return_value = [
'nova-vmware:0',
]
hooks.config_changed()
_json = json.dumps(yaml.load(EXPECTED_RELATION_YAML))
self.relation_set.assert_called_with(
nova_configuration=_json,
relation_id='nova-vmware:0')
|