Merge "Refactor and fix dummy process fixture" into stable/mitaka
This commit is contained in:
commit
7a7ac882ae
|
@ -12,7 +12,9 @@
|
|||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import multiprocessing
|
||||
import os
|
||||
import time
|
||||
|
||||
import fixtures
|
||||
|
||||
|
@ -56,3 +58,30 @@ class AdminDirFixture(fixtures.Fixture):
|
|||
delete_cmd = ['rm', '-r', self.directory]
|
||||
utils.execute(create_cmd, run_as_root=True)
|
||||
self.addCleanup(utils.execute, delete_cmd, run_as_root=True)
|
||||
|
||||
|
||||
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):
|
||||
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
|
||||
|
|
|
@ -13,10 +13,6 @@
|
|||
# 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._i18n import _
|
||||
|
@ -24,6 +20,7 @@ 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
|
||||
|
||||
|
||||
|
@ -86,7 +83,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:
|
||||
|
@ -110,23 +107,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):
|
||||
self.process = Process(target=self.yawn)
|
||||
|
||||
def destroy(self):
|
||||
self.process.terminate()
|
||||
|
||||
@property
|
||||
def pid(self):
|
||||
return self.process.pid
|
||||
|
|
Loading…
Reference in New Issue