1 # Copyright 2015 Red Hat, Inc.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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
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
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)
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))
35 def test_wait_until_true_predicate_succeeds(self):
36 utils.wait_until_true(lambda: True)
38 def test_wait_until_true_predicate_fails(self):
39 with testtools.ExpectedException(eventlet.timeout.Timeout):
40 utils.wait_until_true(lambda: False, 2)