~ionutbalutoiu/charms/trusty/neutron-api/next

« back to all changes in this revision

Viewing changes to unit_tests/test_neutron_api_utils.py

  • Committer: Liam Young
  • Date: 2014-06-20 10:02:09 UTC
  • Revision ID: liam.young@canonical.com-20140620100209-ibeiy1g9kt5ayimn
Added openstack upgrade, unit tests and lint fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
 
from mock import MagicMock, call, patch
 
2
from mock import MagicMock, patch
3
3
from collections import OrderedDict
4
4
import charmhelpers.contrib.openstack.templating as templating
5
5
 
16
16
 
17
17
 
18
18
TO_PATCH = [
 
19
    'apt_install',
 
20
    'apt_update',
 
21
    'apt_upgrade',
19
22
    'b64encode',
20
23
    'config',
 
24
    'configure_installation_source',
 
25
    'get_os_codename_install_source',
 
26
    'log',
21
27
    'neutron_plugin_attribute',
22
28
]
23
29
 
 
30
 
24
31
def _mock_npa(plugin, attr, net_manager=None):
25
32
    plugins = {
26
33
        'ovs': {
36
43
    }
37
44
    return plugins[plugin][attr]
38
45
 
 
46
 
39
47
class TestNeutronAPIUtils(CharmTestCase):
40
 
 
41
 
 
42
48
    def setUp(self):
43
49
        super(TestNeutronAPIUtils, self).setUp(nutils, TO_PATCH)
44
50
        self.config.side_effect = self.test_config.get
57
63
        test_url = 'http://127.0.0.1'
58
64
        endpoints = nutils.determine_endpoints(test_url)
59
65
        neutron_url = '%s:%s' % (test_url,
60
 
                                 nutils.api_port('neutron-server')) 
 
66
                                 nutils.api_port('neutron-server'))
61
67
        expect = {
62
68
            'quantum_service': 'quantum',
63
69
            'quantum_region': 'region101',
125
131
    def test_keystone_ca_cert_b64(self, _isfile):
126
132
        _isfile.return_value = True
127
133
        with patch_open() as (_open, _file):
128
 
            cert = nutils.keystone_ca_cert_b64()
 
134
            nutils.keystone_ca_cert_b64()
129
135
            self.assertTrue(self.b64encode.called)
 
136
 
 
137
    def test_do_openstack_upgrade(self):
 
138
        self.config.side_effect = self.test_config.get
 
139
        self.test_config.set('openstack-origin', 'cloud:precise-havana')
 
140
        self.get_os_codename_install_source.return_value = 'havana'
 
141
        configs = MagicMock()
 
142
        nutils.do_openstack_upgrade(configs)
 
143
        configs.set_release.assert_called_with(openstack_release='havana')
 
144
        self.log.assert_called()
 
145
        self.apt_update.assert_called_with(fatal=True)
 
146
        dpkg_opts = [
 
147
            '--option', 'Dpkg::Options::=--force-confnew',
 
148
            '--option', 'Dpkg::Options::=--force-confdef',
 
149
        ]
 
150
        pkgs = nutils.BASE_PACKAGES
 
151
        pkgs.sort()
 
152
        self.apt_install.assert_called_with(
 
153
            options=dpkg_opts,
 
154
            packages=pkgs,
 
155
            fatal=True
 
156
        )
 
157
        self.configure_installation_source.assert_called_with(
 
158
            'cloud:precise-havana'
 
159
        )