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

« back to all changes in this revision

Viewing changes to unit_tests/test_neutron_api_utils.py

  • Committer: Ryan Beisner
  • Date: 2015-08-22 04:25:22 UTC
  • mfrom: (134 trunk)
  • mto: This revision was merged to the branch mainline in revision 139.
  • Revision ID: ryan.beisner@canonical.com-20150822042522-2rit5gskbly37hd6
rebase

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    'os_release',
34
34
    'pip_install',
35
35
    'subprocess',
 
36
    'is_elected_leader',
36
37
]
37
38
 
38
39
openstack_origin_git = \
103
104
        expect.extend(nutils.KILO_PACKAGES)
104
105
        self.assertItemsEqual(pkg_list, expect)
105
106
 
 
107
    @patch.object(nutils, 'git_install_requested')
 
108
    def test_determine_packages_noplugin(self, git_requested):
 
109
        git_requested.return_value = False
 
110
        self.test_config.set('manage-neutron-plugin-legacy-mode', False)
 
111
        pkg_list = nutils.determine_packages()
 
112
        expect = deepcopy(nutils.BASE_PACKAGES)
 
113
        expect.extend(['neutron-server'])
 
114
        self.assertItemsEqual(pkg_list, expect)
 
115
 
106
116
    def test_determine_ports(self):
107
117
        port_list = nutils.determine_ports()
108
118
        self.assertItemsEqual(port_list, [9696])
109
119
 
 
120
    @patch.object(nutils, 'manage_plugin')
110
121
    @patch('os.path.exists')
111
 
    def test_resource_map(self, _path_exists):
 
122
    def test_resource_map(self, _path_exists, _manage_plugin):
112
123
        _path_exists.return_value = False
 
124
        _manage_plugin.return_value = True
113
125
        _map = nutils.resource_map()
114
126
        confs = [nutils.NEUTRON_CONF, nutils.NEUTRON_DEFAULT,
115
127
                 nutils.APACHE_CONF]
116
128
        [self.assertIn(q_conf, _map.keys()) for q_conf in confs]
117
129
        self.assertTrue(nutils.APACHE_24_CONF not in _map.keys())
118
130
 
 
131
    @patch.object(nutils, 'manage_plugin')
119
132
    @patch('os.path.exists')
120
 
    def test_resource_map_apache24(self, _path_exists):
 
133
    def test_resource_map_apache24(self, _path_exists, _manage_plugin):
121
134
        _path_exists.return_value = True
 
135
        _manage_plugin.return_value = True
122
136
        _map = nutils.resource_map()
123
137
        confs = [nutils.NEUTRON_CONF, nutils.NEUTRON_DEFAULT,
124
138
                 nutils.APACHE_24_CONF]
125
139
        [self.assertIn(q_conf, _map.keys()) for q_conf in confs]
126
140
        self.assertTrue(nutils.APACHE_CONF not in _map.keys())
127
141
 
 
142
    @patch.object(nutils, 'manage_plugin')
 
143
    @patch('os.path.exists')
 
144
    def test_resource_map_noplugin(self, _path_exists, _manage_plugin):
 
145
        _path_exists.return_value = True
 
146
        _manage_plugin.return_value = False
 
147
        _map = nutils.resource_map()
 
148
        found_sdn_ctxt = False
 
149
        found_sdnconfig_ctxt = False
 
150
        for ctxt in _map[nutils.NEUTRON_CONF]['contexts']:
 
151
            if isinstance(ctxt, ncontext.NeutronApiSDNContext):
 
152
                found_sdn_ctxt = True
 
153
        for ctxt in _map[nutils.NEUTRON_DEFAULT]['contexts']:
 
154
            if isinstance(ctxt, ncontext.NeutronApiSDNConfigFileContext):
 
155
                found_sdnconfig_ctxt = True
 
156
        self.assertTrue(found_sdn_ctxt and found_sdnconfig_ctxt)
 
157
 
128
158
    @patch('os.path.exists')
129
159
    def test_restart_map(self, mock_path_exists):
130
160
        mock_path_exists.return_value = False
190
220
    def test_do_openstack_upgrade_juno(self, git_requested,
191
221
                                       stamp_neutron_db, migrate_neutron_db):
192
222
        git_requested.return_value = False
 
223
        self.is_elected_leader.return_value = True
193
224
        self.config.side_effect = self.test_config.get
194
225
        self.test_config.set('openstack-origin', 'cloud:trusty-juno')
195
226
        self.os_release.return_value = 'icehouse'
227
258
                                       stamp_neutron_db, migrate_neutron_db,
228
259
                                       gsrc):
229
260
        git_requested.return_value = False
 
261
        self.is_elected_leader.return_value = True
230
262
        self.os_release.return_value = 'juno'
231
263
        self.config.side_effect = self.test_config.get
232
264
        self.test_config.set('openstack-origin', 'cloud:trusty-kilo')
256
288
        stamp_neutron_db.assert_called_with('juno')
257
289
        migrate_neutron_db.assert_called_with()
258
290
 
 
291
    @patch.object(charmhelpers.contrib.openstack.utils,
 
292
                  'get_os_codename_install_source')
 
293
    @patch.object(nutils, 'migrate_neutron_database')
 
294
    @patch.object(nutils, 'stamp_neutron_database')
 
295
    @patch.object(nutils, 'git_install_requested')
 
296
    def test_do_openstack_upgrade_kilo_notleader(self, git_requested,
 
297
                                                 stamp_neutron_db,
 
298
                                                 migrate_neutron_db,
 
299
                                                 gsrc):
 
300
        git_requested.return_value = False
 
301
        self.is_elected_leader.return_value = False
 
302
        self.os_release.return_value = 'juno'
 
303
        self.config.side_effect = self.test_config.get
 
304
        self.test_config.set('openstack-origin', 'cloud:trusty-kilo')
 
305
        gsrc.return_value = 'kilo'
 
306
        self.get_os_codename_install_source.return_value = 'kilo'
 
307
        configs = MagicMock()
 
308
        nutils.do_openstack_upgrade(configs)
 
309
        self.os_release.assert_called_with('neutron-server')
 
310
        self.log.assert_called()
 
311
        self.configure_installation_source.assert_called_with(
 
312
            'cloud:trusty-kilo'
 
313
        )
 
314
        self.apt_update.assert_called_with(fatal=True)
 
315
        dpkg_opts = [
 
316
            '--option', 'Dpkg::Options::=--force-confnew',
 
317
            '--option', 'Dpkg::Options::=--force-confdef',
 
318
        ]
 
319
        self.apt_upgrade.assert_called_with(options=dpkg_opts,
 
320
                                            fatal=True,
 
321
                                            dist=True)
 
322
        pkgs = nutils.determine_packages()
 
323
        pkgs.sort()
 
324
        self.apt_install.assert_called_with(packages=pkgs,
 
325
                                            options=dpkg_opts,
 
326
                                            fatal=True)
 
327
        configs.set_release.assert_called_with(openstack_release='kilo')
 
328
        self.assertFalse(stamp_neutron_db.called)
 
329
        self.assertFalse(migrate_neutron_db.called)
 
330
 
259
331
    @patch.object(ncontext, 'IdentityServiceContext')
260
332
    @patch('neutronclient.v2_0.client.Client')
261
333
    def test_get_neutron_client(self, nclient, IdentityServiceContext):
477
549
               'upgrade',
478
550
               'head']
479
551
        self.subprocess.check_output.assert_called_with(cmd)
 
552
 
 
553
    def test_manage_plugin_true(self):
 
554
        self.test_config.set('manage-neutron-plugin-legacy-mode', True)
 
555
        manage = nutils.manage_plugin()
 
556
        self.assertTrue(manage)
 
557
 
 
558
    def test_manage_plugin_false(self):
 
559
        self.test_config.set('manage-neutron-plugin-legacy-mode', False)
 
560
        manage = nutils.manage_plugin()
 
561
        self.assertFalse(manage)