5508457218eda66c0ae23b4aa6c09fa156fd6c93
[openstack-build/neutron-build.git] / neutron / tests / functional / agent / linux / test_utils.py
1 # Copyright 2015 Red Hat, Inc.
2 #
3 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
4 #    not use this file except in compliance with the License. You may obtain
5 #    a copy of the License at
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
9 #    Unless required by applicable law or agreed to in writing, software
10 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 #    License for the specific language governing permissions and limitations
13 #    under the License.
14
15 import eventlet
16 import testtools
17
18 from neutron.agent.linux import async_process
19 from neutron.agent.linux import utils
20 from neutron.tests.functional.agent.linux import test_async_process
21
22
23 class TestPIDHelpers(test_async_process.AsyncProcessTestFramework):
24     def test_get_cmdline_from_pid_and_pid_invoked_with_cmdline(self):
25         cmd = ['tail', '-f', self.test_file_path]
26         proc = async_process.AsyncProcess(cmd)
27         proc.start(block=True)
28         self.addCleanup(proc.stop)
29
30         pid = proc.pid
31         self.assertEqual(cmd, utils.get_cmdline_from_pid(pid))
32         self.assertTrue(utils.pid_invoked_with_cmdline(pid, cmd))
33         self.assertEqual([], utils.get_cmdline_from_pid(-1))
34
35     def test_wait_until_true_predicate_succeeds(self):
36         utils.wait_until_true(lambda: True)
37
38     def test_wait_until_true_predicate_fails(self):
39         with testtools.ExpectedException(eventlet.timeout.Timeout):
40             utils.wait_until_true(lambda: False, 2)