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

« back to all changes in this revision

Viewing changes to unit_tests/test_neutron_ovs_utils.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:
18
18
TO_PATCH = [
19
19
    'add_bridge',
20
20
    'add_bridge_port',
 
21
    'apt_install',
 
22
    'apt_update',
21
23
    'config',
22
24
    'os_release',
 
25
    'filter_installed_packages',
23
26
    'neutron_plugin_attribute',
24
27
    'full_restart',
25
28
    'service_restart',
75
78
        # Reset cached cache
76
79
        hookenv.cache = {}
77
80
 
 
81
    @patch.object(nutils, 'determine_packages')
 
82
    def test_install_packages(self, _determine_packages):
 
83
        _determine_packages.return_value = 'randompkg'
 
84
        nutils.install_packages()
 
85
        self.apt_update.assert_called_with()
 
86
        self.apt_install.assert_called_with(self.filter_installed_packages())
 
87
 
78
88
    @patch.object(nutils, 'use_dvr')
79
89
    @patch.object(nutils, 'git_install_requested')
80
90
    @patch.object(charmhelpers.contrib.openstack.neutron, 'os_release')
81
91
    @patch.object(charmhelpers.contrib.openstack.neutron, 'headers_package')
82
92
    def test_determine_packages(self, _head_pkgs, _os_rel, _git_requested,
83
93
                                _use_dvr):
84
 
        _git_requested.return_value = False
85
 
        _use_dvr.return_value = False
86
 
        _os_rel.return_value = 'trusty'
87
 
        _head_pkgs.return_value = head_pkg
88
 
        pkg_list = nutils.determine_packages()
89
 
        expect = [['neutron-plugin-openvswitch-agent'], [head_pkg]]
90
 
        self.assertItemsEqual(pkg_list, expect)
 
94
        self.test_config.set('enable-local-dhcp-and-metadata', False)
 
95
        _git_requested.return_value = False
 
96
        _use_dvr.return_value = False
 
97
        _os_rel.return_value = 'trusty'
 
98
        _head_pkgs.return_value = head_pkg
 
99
        pkg_list = nutils.determine_packages()
 
100
        expect = ['neutron-plugin-openvswitch-agent', head_pkg]
 
101
        self.assertItemsEqual(pkg_list, expect)
 
102
 
 
103
    @patch.object(nutils, 'use_dvr')
 
104
    @patch.object(nutils, 'git_install_requested')
 
105
    @patch.object(charmhelpers.contrib.openstack.neutron, 'os_release')
 
106
    @patch.object(charmhelpers.contrib.openstack.neutron, 'headers_package')
 
107
    def test_determine_packages_metadata(self, _head_pkgs, _os_rel,
 
108
                                         _git_requested, _use_dvr):
 
109
        self.test_config.set('enable-local-dhcp-and-metadata', True)
 
110
        _git_requested.return_value = False
 
111
        _use_dvr.return_value = False
 
112
        _os_rel.return_value = 'trusty'
 
113
        _head_pkgs.return_value = head_pkg
 
114
        pkg_list = nutils.determine_packages()
 
115
        expect = ['neutron-plugin-openvswitch-agent', head_pkg,
 
116
                  'neutron-metadata-agent', 'neutron-dhcp-agent']
 
117
        self.assertItemsEqual(pkg_list, expect)
 
118
 
 
119
    @patch.object(nutils, 'use_dvr')
 
120
    @patch.object(nutils, 'git_install_requested')
 
121
    @patch.object(charmhelpers.contrib.openstack.neutron, 'os_release')
 
122
    @patch.object(charmhelpers.contrib.openstack.neutron, 'headers_package')
 
123
    def test_determine_packages_git(self, _head_pkgs, _os_rel,
 
124
                                    _git_requested, _use_dvr):
 
125
        self.test_config.set('enable-local-dhcp-and-metadata', False)
 
126
        _git_requested.return_value = True
 
127
        _use_dvr.return_value = True
 
128
        _os_rel.return_value = 'trusty'
 
129
        _head_pkgs.return_value = head_pkg
 
130
        pkg_list = nutils.determine_packages()
 
131
        self.assertFalse('neutron-l3-agent' in pkg_list)
91
132
 
92
133
    @patch.object(nutils, 'use_dvr')
93
134
    def test_register_configs(self, _use_dvr):
128
169
        [self.assertIn(q_conf, _map.keys()) for q_conf in confs]
129
170
        self.assertEqual(_map[nutils.NEUTRON_CONF]['services'], svcs)
130
171
 
 
172
    @patch.object(nutils, 'enable_local_dhcp')
 
173
    @patch.object(nutils, 'use_dvr')
 
174
    def test_resource_map_dhcp(self, _use_dvr, _enable_local_dhcp):
 
175
        _enable_local_dhcp.return_value = True
 
176
        _use_dvr.return_value = False
 
177
        _map = nutils.resource_map()
 
178
        svcs = ['neutron-plugin-openvswitch-agent', 'neutron-metadata-agent',
 
179
                'neutron-dhcp-agent']
 
180
        confs = [nutils.NEUTRON_CONF, nutils.NEUTRON_METADATA_AGENT_CONF,
 
181
                 nutils.NEUTRON_DHCP_AGENT_CONF]
 
182
        [self.assertIn(q_conf, _map.keys()) for q_conf in confs]
 
183
        self.assertEqual(_map[nutils.NEUTRON_CONF]['services'], svcs)
 
184
 
131
185
    @patch.object(nutils, 'use_dvr')
132
186
    def test_restart_map(self, _use_dvr):
133
187
        _use_dvr.return_value = False
213
267
        ])
214
268
        self.add_bridge_port.assert_called_with('br-ex', 'eth0')
215
269
 
216
 
    @patch.object(neutron_ovs_context, 'DVRSharedSecretContext')
 
270
    @patch.object(neutron_ovs_context, 'SharedSecretContext')
217
271
    def test_get_shared_secret(self, _dvr_secret_ctxt):
218
272
        _dvr_secret_ctxt.return_value = \
219
273
            DummyContext(return_value={'shared_secret': 'supersecret'})