~james-page/charms/trusty/neutron-openvswitch/tox

« back to all changes in this revision

Viewing changes to unit_tests/test_neutron_ovs_hooks.py

  • Committer: james.page at ubuntu
  • Date: 2015-09-15 07:47:30 UTC
  • mfrom: (85.2.8 local-metadata)
  • Revision ID: james.page@ubuntu.com-20150915074730-jey2hm36p4tt6did
[gnuoy,r=james-page] Add support for local DHCP and Metadata agents

This change allows nova-compute nodes to also run Neutron DHCP and Metadata
agents, allowing deploying without the neutron-gateway charm in VLAN and
flat networking configurations.

Only useful if l3 routing, vpnaas, fwaas and lbaas services are not required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from mock import MagicMock, patch, call
 
1
from mock import MagicMock, patch
2
2
import yaml
3
3
 
4
4
from test_utils import CharmTestCase
19
19
utils.restart_map = _map
20
20
 
21
21
TO_PATCH = [
22
 
    'apt_update',
23
 
    'apt_install',
24
 
    'apt_purge',
25
22
    'config',
26
23
    'CONFIGS',
27
 
    'determine_packages',
28
 
    'determine_dvr_packages',
29
24
    'get_shared_secret',
30
25
    'git_install',
31
26
    'log',
33
28
    'relation_set',
34
29
    'configure_ovs',
35
30
    'use_dvr',
 
31
    'install_packages',
 
32
    'purge_packages',
 
33
    'enable_nova_metadata',
 
34
    'enable_local_dhcp',
36
35
]
37
36
NEUTRON_CONF_DIR = "/etc/neutron"
38
37
 
54
53
    @patch.object(hooks, 'git_install_requested')
55
54
    def test_install_hook(self, git_requested):
56
55
        git_requested.return_value = False
57
 
        _pkgs = ['foo', 'bar']
58
 
        self.determine_packages.return_value = [_pkgs]
59
56
        self._call_hook('install')
60
 
        self.apt_update.assert_called_with()
61
 
        self.apt_install.assert_has_calls([
62
 
            call(_pkgs, fatal=True),
63
 
        ])
 
57
        self.install_packages.assert_called_with()
64
58
 
65
59
    @patch.object(hooks, 'git_install_requested')
66
60
    def test_install_hook_git(self, git_requested):
67
61
        git_requested.return_value = True
68
 
        _pkgs = ['foo', 'bar']
69
 
        self.determine_packages.return_value = _pkgs
70
62
        openstack_origin_git = {
71
63
            'repositories': [
72
64
                {'name': 'requirements',
81
73
        projects_yaml = yaml.dump(openstack_origin_git)
82
74
        self.test_config.set('openstack-origin-git', projects_yaml)
83
75
        self._call_hook('install')
84
 
        self.apt_update.assert_called_with()
85
 
        self.assertTrue(self.determine_packages)
 
76
        self.install_packages.assert_called_with()
86
77
        self.git_install.assert_called_with(projects_yaml)
87
78
 
88
79
    @patch.object(hooks, 'git_install_requested')
124
115
    @patch.object(hooks, 'git_install_requested')
125
116
    def test_config_changed_dvr(self, git_requested):
126
117
        git_requested.return_value = False
127
 
        self.determine_dvr_packages.return_value = ['dvr']
128
118
        self._call_hook('config-changed')
129
 
        self.apt_update.assert_called_with()
 
119
        self.install_packages.assert_called_with()
130
120
        self.assertTrue(self.CONFIGS.write_all.called)
131
 
        self.apt_install.assert_has_calls([
132
 
            call(['dvr'], fatal=True),
133
 
        ])
134
121
        self.configure_ovs.assert_called_with()
135
122
 
136
123
    @patch.object(hooks, 'neutron_plugin_joined')
140
127
        self.configure_ovs.assert_called_with()
141
128
        self.assertTrue(self.CONFIGS.write_all.called)
142
129
        _plugin_joined.assert_called_with(relation_id='rid')
 
130
        self.install_packages.assert_called_with()
 
131
 
 
132
    @patch.object(hooks, 'neutron_plugin_joined')
 
133
    def test_neutron_plugin_api_nodvr(self, _plugin_joined):
 
134
        self.use_dvr.return_value = False
 
135
        self.relation_ids.return_value = ['rid']
 
136
        self._call_hook('neutron-plugin-api-relation-changed')
 
137
        self.configure_ovs.assert_called_with()
 
138
        self.assertTrue(self.CONFIGS.write_all.called)
 
139
        _plugin_joined.assert_called_with(relation_id='rid')
 
140
        self.purge_packages.assert_called_with(['neutron-l3-agent'])
143
141
 
144
142
    @patch.object(hooks, 'git_install_requested')
145
143
    def test_neutron_plugin_joined(self, git_requested):
 
144
        self.enable_nova_metadata.return_value = True
 
145
        self.enable_local_dhcp.return_value = True
146
146
        git_requested.return_value = False
147
147
        self.get_shared_secret.return_value = 'secret'
148
148
        self._call_hook('neutron-plugin-relation-joined')