~opnfv-team/charms/trusty/odl-controller/Be

« back to all changes in this revision

Viewing changes to unit_tests/test_odl_controller_utils.py

  • Committer: James Page
  • Date: 2015-11-12 11:25:54 UTC
  • mfrom: (10.1.2 odl-controller)
  • Revision ID: james.page@ubuntu.com-20151112112554-xbh2zetd8zzldl0z
Add unit tests, functional tests, Makefiles and tox configuration

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from mock import patch, call
 
2
from test_utils import CharmTestCase
 
3
 
 
4
import odl_controller_utils as utils
 
5
import odl_outputs
 
6
 
 
7
TO_PATCH = [
 
8
    'subprocess',
 
9
    'render',
 
10
    'config',
 
11
    'retry_on_exception',
 
12
]
 
13
 
 
14
 
 
15
class ODLControllerUtilsTests(CharmTestCase):
 
16
 
 
17
    def setUp(self):
 
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')
 
21
 
 
22
    def test_mvn_proxy_ctx(self):
 
23
        expect = {
 
24
            'http_noproxy': [],
 
25
            'http_proxy': True,
 
26
            'http_proxy_host': 'proxy.int',
 
27
            'http_proxy_port': 3128
 
28
        }
 
29
        self.assertEqual(utils.mvn_proxy_ctx('http'), expect)
 
30
 
 
31
    def test_mvn_ctx(self):
 
32
        self.test_config.set('http-proxy', 'http://proxy.int:3128')
 
33
        expect = {
 
34
            'http_noproxy': [],
 
35
            'http_proxy': True,
 
36
            'http_proxy_host': 'proxy.int',
 
37
            'http_proxy_port': 3128
 
38
        }
 
39
        self.assertEqual(utils.mvn_ctx(), expect)
 
40
 
 
41
    def test_mvn_ctx_unset(self):
 
42
        self.test_config.set('http-proxy', '')
 
43
        self.assertEqual(utils.mvn_ctx(), {})
 
44
 
 
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
 
52
        )
 
53
 
 
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']
 
59
        )
 
60
 
 
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)
 
68
 
 
69
    def test_filter_installed(self):
 
70
        self.subprocess.check_output.return_value = \
 
71
            odl_outputs.ODL_023_FEATURE_LIST
 
72
        self.assertEqual(
 
73
            utils.filter_installed(['odl-l2switch-hosttracker']),
 
74
            ['odl-l2switch-hosttracker']
 
75
        )
 
76
        self.assertEqual(utils.filter_installed(['odl-config-api']), [])
 
77
 
 
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):
 
81
        test_profile = {
 
82
            "feature:install": ["odl-l2switch-all"],
 
83
            "log:set": {
 
84
                "TRACE": ["cosc-cvpn-ovs-rest"],
 
85
            },
 
86
            "port": 1181
 
87
        }
 
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'])
 
93
        ])