~ubuntu-branches/ubuntu/vivid/neutron/vivid-updates

« back to all changes in this revision

Viewing changes to neutron/tests/unit/test_linux_external_process.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-03-30 11:17:19 UTC
  • mfrom: (1.1.21)
  • Revision ID: package-import@ubuntu.com-20150330111719-h0gx7233p4jkkgfh
Tags: 1:2015.1~b3-0ubuntu1
* New upstream milestone release:
  - d/control: Align version requirements with upstream.
  - d/control: Add new dependency on oslo-log.
  - d/p/*: Rebase.
  - d/control,d/neutron-plugin-hyperv*: Dropped, decomposed into
    separate project upstream.
  - d/control,d/neutron-plugin-openflow*: Dropped, decomposed into
    separate project upstream.
  - d/neutron-common.install: Add neutron-rootwrap-daemon and 
    neutron-keepalived-state-change binaries.
  - d/rules: Ignore neutron-hyperv-agent when installing; only for Windows.
  - d/neutron-plugin-cisco.install: Drop neutron-cisco-cfg-agent as
    decomposed into separate project upstream.
  - d/neutron-plugin-vmware.install: Drop neutron-check-nsx-config and
    neutron-nsx-manage as decomposed into separate project upstream.
  - d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent.
* d/pydist-overrides: Add overrides for oslo packages.
* d/control: Fixup type in package description (LP: #1263539).
* d/p/fixup-driver-test-execution.patch: Cherry pick fix from upstream VCS
  to support unit test exection in out-of-tree vendor drivers.
* d/neutron-common.postinst: Allow general access to /etc/neutron but limit
  access to root/neutron to /etc/neutron/neutron.conf to support execution
  of unit tests in decomposed vendor drivers.
* d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent
  package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
import os.path
17
17
 
18
18
from neutron.agent.linux import external_process as ep
 
19
from neutron.agent.linux import utils
19
20
from neutron.tests import base
20
21
 
21
22
 
26
27
        self.execute = self.execute_p.start()
27
28
        self.delete_if_exists = mock.patch(
28
29
            'neutron.openstack.common.fileutils.delete_if_exists').start()
29
 
        self.makedirs = mock.patch('os.makedirs').start()
 
30
        self.ensure_dir = mock.patch.object(
 
31
            utils, 'ensure_dir').start()
30
32
 
31
33
        self.conf = mock.Mock()
32
34
        self.conf.external_pids = '/var/path'
34
36
    def test_processmanager_ensures_pid_dir(self):
35
37
        pid_file = os.path.join(self.conf.external_pids, 'pid')
36
38
        ep.ProcessManager(self.conf, 'uuid', pid_file=pid_file)
37
 
        self.makedirs.assert_called_once_with(self.conf.external_pids, 0o755)
 
39
        self.ensure_dir.assert_called_once_with(self.conf.external_pids)
38
40
 
39
41
    def test_enable_no_namespace(self):
40
42
        callback = mock.Mock()
49
51
                manager.enable(callback)
50
52
                callback.assert_called_once_with('pidfile')
51
53
                self.execute.assert_called_once_with(['the', 'cmd'],
52
 
                                                     root_helper='sudo',
53
54
                                                     check_exit_code=True,
54
55
                                                     extra_ok_codes=None)
55
56
 
67
68
                    manager.enable(callback)
68
69
                    callback.assert_called_once_with('pidfile')
69
70
                    ip_lib.assert_has_calls([
70
 
                        mock.call.IPWrapper('sudo', 'ns'),
 
71
                        mock.call.IPWrapper(namespace='ns'),
71
72
                        mock.call.IPWrapper().netns.execute(['the', 'cmd'],
72
73
                                                            addl_env=None)])
73
74
 
88
89
            pid.__get__ = mock.Mock(return_value=4)
89
90
            with mock.patch.object(ep.ProcessManager, 'active') as active:
90
91
                active.__get__ = mock.Mock(return_value=True)
91
 
 
92
92
                manager = ep.ProcessManager(self.conf, 'uuid')
93
 
                manager.disable()
94
 
                self.execute(['kill', '-9', 4], 'sudo')
 
93
 
 
94
                with mock.patch.object(ep, 'utils') as utils:
 
95
                    manager.disable()
 
96
                    utils.assert_has_calls(
 
97
                        mock.call.execute(['kill', '-9', 4], run_as_root=True))
95
98
 
96
99
    def test_disable_namespace(self):
97
100
        with mock.patch.object(ep.ProcessManager, 'pid') as pid:
104
107
                with mock.patch.object(ep, 'utils') as utils:
105
108
                    manager.disable()
106
109
                    utils.assert_has_calls(
107
 
                        mock.call.execute(['kill', '-9', 4], 'sudo'))
 
110
                        mock.call.execute(['kill', '-9', 4], run_as_root=True))
108
111
 
109
112
    def test_disable_not_active(self):
110
113
        with mock.patch.object(ep.ProcessManager, 'pid') as pid: