1
from mock import patch, call
2
from test_utils import CharmTestCase
4
import odl_controller_utils as utils
15
class ODLControllerUtilsTests(CharmTestCase):
18
super(ODLControllerUtilsTests, self).setUp(utils, TO_PATCH)
19
self.config.side_effect = self.test_config.get
20
self.test_config.set('http-proxy', 'http://proxy.int:3128')
22
def test_mvn_proxy_ctx(self):
26
'http_proxy_host': 'proxy.int',
27
'http_proxy_port': 3128
29
self.assertEqual(utils.mvn_proxy_ctx('http'), expect)
31
def test_mvn_ctx(self):
32
self.test_config.set('http-proxy', 'http://proxy.int:3128')
36
'http_proxy_host': 'proxy.int',
37
'http_proxy_port': 3128
39
self.assertEqual(utils.mvn_ctx(), expect)
41
def test_mvn_ctx_unset(self):
42
self.test_config.set('http-proxy', '')
43
self.assertEqual(utils.mvn_ctx(), {})
45
def test_write_mvn_config(self):
46
self.test_config.set('http-proxy', '')
47
self.test_config.set('https-proxy', '')
48
utils.write_mvn_config()
49
self.render.assert_called_with(
50
"settings.xml", "/home/opendaylight/.m2/settings.xml", {},
51
"opendaylight", "opendaylight", 0400
54
def test_run_odl(self):
55
utils.run_odl(["feature:list"])
56
self.subprocess.check_output.assert_called_with(
57
["/opt/opendaylight-karaf/bin/client", "-r", '20', "-h",
58
'localhost', "-a", '8101', 'feature:list']
61
def test_installed_features(self):
62
self.subprocess.check_output.return_value = \
63
odl_outputs.ODL_023_FEATURE_LIST
64
installed = utils.installed_features()
65
for feature in utils.PROFILES["openvswitch-odl"]["feature:install"]:
66
self.assertTrue(feature in installed)
67
self.assertFalse('odl-l2switch-hosttracker' in installed)
69
def test_filter_installed(self):
70
self.subprocess.check_output.return_value = \
71
odl_outputs.ODL_023_FEATURE_LIST
73
utils.filter_installed(['odl-l2switch-hosttracker']),
74
['odl-l2switch-hosttracker']
76
self.assertEqual(utils.filter_installed(['odl-config-api']), [])
78
@patch.object(utils, 'run_odl')
79
@patch.object(utils, 'filter_installed')
80
def test_process_odl_cmds(self, mock_filter_installed, mock_run_odl):
82
"feature:install": ["odl-l2switch-all"],
84
"TRACE": ["cosc-cvpn-ovs-rest"],
88
mock_filter_installed.return_value = ["odl-l2switch-all"]
89
utils.process_odl_cmds(test_profile)
90
mock_run_odl.assert_has_calls([
91
call(["feature:install", "odl-l2switch-all"]),
92
call(['log:set', 'TRACE', 'cosc-cvpn-ovs-rest'])