diff options
author | Jenkins <jenkins@review.openstack.org> | 2016-04-01 14:51:40 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2016-04-01 14:51:40 +0000 |
commit | 990c0a0c36b5a667b6d5aa17f77369c38605dd5b (patch) | |
tree | c9ef939cff9024c8fd8a83d9457c270e2979166d | |
parent | 943ef4934eb2fee07635fcd80c813dbaf7cb24b7 (diff) | |
parent | 9d483ee8166b4bed9b1c0d3e78f951a2e22a6f6a (diff) | |
download | neutron-990c0a0c36b5a667b6d5aa17f77369c38605dd5b.tar.gz |
Merge "Refactor and fix dummy process fixture" into stable/kilo
-rw-r--r-- | neutron/tests/functional/agent/linux/helpers.py | 30 | ||||
-rw-r--r-- | neutron/tests/functional/agent/linux/test_keepalived.py | 28 |
2 files changed, 32 insertions, 26 deletions
diff --git a/neutron/tests/functional/agent/linux/helpers.py b/neutron/tests/functional/agent/linux/helpers.py index dd42761062..a21c55aec9 100644 --- a/neutron/tests/functional/agent/linux/helpers.py +++ b/neutron/tests/functional/agent/linux/helpers.py @@ -13,12 +13,14 @@ # License for the specific language governing permissions and limitations # under the License. import functools +import multiprocessing import os import random import re import select import shlex import subprocess +import time import fixtures import netaddr @@ -256,3 +258,31 @@ class NetcatTester(object): proc.kill() proc.wait() setattr(self, proc_attr, None) + + +class SleepyProcessFixture(fixtures.Fixture): + """ + Process fixture that performs time.sleep for the given number of seconds. + """ + + def __init__(self, timeout=60): + super(SleepyProcessFixture, self).__init__() + self.timeout = timeout + + @staticmethod + def yawn(seconds): + time.sleep(seconds) + + def setUp(self): + super(SleepyProcessFixture, self).setUp() + self.process = multiprocessing.Process(target=self.yawn, + args=[self.timeout]) + self.process.start() + self.addCleanup(self.destroy) + + def destroy(self): + self.process.terminate() + + @property + def pid(self): + return self.process.pid diff --git a/neutron/tests/functional/agent/linux/test_keepalived.py b/neutron/tests/functional/agent/linux/test_keepalived.py index 2079e9fd4e..ccf7975626 100644 --- a/neutron/tests/functional/agent/linux/test_keepalived.py +++ b/neutron/tests/functional/agent/linux/test_keepalived.py @@ -13,16 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. -import fixtures -from multiprocessing import Process -import time - from oslo_config import cfg from neutron.agent.linux import external_process from neutron.agent.linux import keepalived from neutron.agent.linux import utils from neutron.tests import base +from neutron.tests.functional.agent.linux import helpers from neutron.tests.unit.agent.linux import test_keepalived @@ -81,7 +78,7 @@ class KeepalivedManagerTestCase(base.BaseTestCase, # existing non-keepalived process. This situation can happen e.g. # after hard node reset. - spawn_process = SleepyProcessFixture() + spawn_process = helpers.SleepyProcessFixture() self.useFixture(spawn_process) with open(pid_file, "w") as f_pid_file: @@ -105,24 +102,3 @@ class KeepalivedManagerTestCase(base.BaseTestCase, self._test_keepalived_spawns_conflicting_pid( process, self.manager.get_vrrp_pid_file_name(pid_file)) - - -class SleepyProcessFixture(fixtures.Fixture): - - def __init__(self): - super(SleepyProcessFixture, self).__init__() - - @staticmethod - def yawn(): - time.sleep(60) - - def setUp(self): - super(SleepyProcessFixture, self).setUp() - self.process = Process(target=self.yawn) - - def destroy(self): - self.process.terminate() - - @property - def pid(self): - return self.process.pid |