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

« back to all changes in this revision

Viewing changes to neutron/tests/unit/agent/linux/test_process_monitor.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:
19
19
from neutron.tests import base
20
20
 
21
21
TEST_UUID = 'test-uuid'
22
 
TEST_SERVICE1 = 'testsvc'
 
22
TEST_SERVICE = 'testsvc'
23
23
TEST_PID = 1234
24
24
 
25
25
 
27
27
 
28
28
    def setUp(self):
29
29
        super(BaseTestProcessMonitor, self).setUp()
30
 
        self.pm_patch = mock.patch("neutron.agent.linux.external_process."
31
 
                                   "ProcessManager", side_effect=mock.Mock)
32
 
        self.pmanager = self.pm_patch.start()
33
 
 
34
30
        self.log_patch = mock.patch("neutron.agent.linux.external_process."
35
31
                                    "LOG.error")
36
32
        self.error_log = self.log_patch.start()
47
43
        conf.AGENT.check_child_processes = True
48
44
        self.pmonitor = external_process.ProcessMonitor(
49
45
            config=conf,
50
 
            root_helper=None,
51
46
            resource_type='test')
52
47
 
53
 
    def get_monitored_process_manager(self, uuid, service=None):
54
 
        self.pmonitor.enable(uuid=uuid, service=service, cmd_callback=None)
55
 
        return self.pmonitor.get_process_manager(uuid, service)
 
48
    def get_monitored_process(self, uuid, service=None):
 
49
        monitored_process = mock.Mock()
 
50
        self.pmonitor.register(uuid=uuid,
 
51
                               service_name=service,
 
52
                               monitored_process=monitored_process)
 
53
        return monitored_process
56
54
 
57
55
 
58
56
class TestProcessMonitor(BaseTestProcessMonitor):
59
57
 
60
58
    def test_error_logged(self):
61
 
        pm = self.get_monitored_process_manager(TEST_UUID)
 
59
        pm = self.get_monitored_process(TEST_UUID)
62
60
        pm.active = False
63
61
        self.pmonitor._check_child_processes()
64
62
        self.assertTrue(self.error_log.called)
65
63
 
66
64
    def test_exit_handler(self):
67
65
        self.create_child_process_monitor('exit')
68
 
        pm = self.get_monitored_process_manager(TEST_UUID)
 
66
        pm = self.get_monitored_process(TEST_UUID)
69
67
        pm.active = False
70
68
        with mock.patch.object(external_process.ProcessMonitor,
71
69
                               '_exit_handler') as exit_handler:
72
70
            self.pmonitor._check_child_processes()
73
71
            exit_handler.assert_called_once_with(TEST_UUID, None)
74
72
 
75
 
    def test_different_service_types(self):
76
 
        pm_none = self.get_monitored_process_manager(TEST_UUID)
77
 
        pm_svc1 = self.get_monitored_process_manager(TEST_UUID, TEST_SERVICE1)
78
 
        self.assertNotEqual(pm_none, pm_svc1)
79
 
 
80
 
    def test_active_method(self, service=None):
81
 
        pm = self.get_monitored_process_manager(TEST_UUID, service)
82
 
        pm.active = False
83
 
        self.assertFalse(self.pmonitor.is_active(TEST_UUID, service))
84
 
        pm.active = True
85
 
        self.assertTrue(self.pmonitor.is_active(TEST_UUID, service))
86
 
 
87
 
    def test_active_method_with_service(self):
88
 
        self.test_active_method(TEST_SERVICE1)
89
 
 
90
 
    def test_pid_method(self, service=None):
91
 
        pm = self.get_monitored_process_manager(TEST_UUID, service)
92
 
        pm.pid = TEST_PID
93
 
        self.assertEqual(TEST_PID, self.pmonitor.get_pid(TEST_UUID, service))
94
 
 
95
 
    def test_pid_method_with_service(self):
96
 
        self.test_pid_method(TEST_PID)
 
73
    def test_register(self):
 
74
        pm = self.get_monitored_process(TEST_UUID)
 
75
        self.assertEqual(len(self.pmonitor._monitored_processes), 1)
 
76
        self.assertIn(pm, self.pmonitor._monitored_processes.values())
 
77
 
 
78
    def test_register_same_service_twice(self):
 
79
        self.get_monitored_process(TEST_UUID)
 
80
        self.get_monitored_process(TEST_UUID)
 
81
        self.assertEqual(len(self.pmonitor._monitored_processes), 1)
 
82
 
 
83
    def test_register_different_service_types(self):
 
84
        self.get_monitored_process(TEST_UUID)
 
85
        self.get_monitored_process(TEST_UUID, TEST_SERVICE)
 
86
        self.assertEqual(len(self.pmonitor._monitored_processes), 2)
 
87
 
 
88
    def test_unregister(self):
 
89
        self.get_monitored_process(TEST_UUID)
 
90
        self.pmonitor.unregister(TEST_UUID, None)
 
91
        self.assertEqual(len(self.pmonitor._monitored_processes), 0)
 
92
 
 
93
    def test_unregister_unknown_process(self):
 
94
        self.pmonitor.unregister(TEST_UUID, None)
 
95
        self.assertEqual(len(self.pmonitor._monitored_processes), 0)