Refactor and fix dummy process fixture
Extracting the test fixture that creates a new process and leaves it
running for a given amount of time into helpers where other fixtures for
functional tests live. This both keeps the fixtures at one place and
increases visibility of the fixture so that it can be reused in other
tests. At the same time, the fixture is fixed as the original code
omitted starting the process.
Conflicts:
neutron/tests/functional/agent/linux/helpers.py
Change-Id: I97aeb8d1d5773ef3d59e8f908aea34ccceb38378
Related-Bug: 1561046
(cherry picked from commit 2690eed19a
)
This commit is contained in:
parent
6dea586906
commit
7175fdef97
|
@ -12,7 +12,9 @@
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
import multiprocessing
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
|
|
||||||
|
@ -34,3 +36,30 @@ class RecursivePermDirFixture(fixtures.Fixture):
|
||||||
os.chmod(current_directory, perms | self.least_perms)
|
os.chmod(current_directory, perms | self.least_perms)
|
||||||
previous_directory = current_directory
|
previous_directory = current_directory
|
||||||
current_directory = os.path.dirname(current_directory)
|
current_directory = os.path.dirname(current_directory)
|
||||||
|
|
||||||
|
|
||||||
|
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
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import fixtures
|
|
||||||
from multiprocessing import Process
|
|
||||||
import time
|
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
|
||||||
|
@ -24,6 +20,7 @@ from neutron.agent.linux import external_process
|
||||||
from neutron.agent.linux import keepalived
|
from neutron.agent.linux import keepalived
|
||||||
from neutron.agent.linux import utils
|
from neutron.agent.linux import utils
|
||||||
from neutron.tests import base
|
from neutron.tests import base
|
||||||
|
from neutron.tests.functional.agent.linux import helpers
|
||||||
from neutron.tests.unit.agent.linux import test_keepalived
|
from neutron.tests.unit.agent.linux import test_keepalived
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,7 +86,7 @@ class KeepalivedManagerTestCase(base.BaseTestCase,
|
||||||
# existing non-keepalived process. This situation can happen e.g.
|
# existing non-keepalived process. This situation can happen e.g.
|
||||||
# after hard node reset.
|
# after hard node reset.
|
||||||
|
|
||||||
spawn_process = SleepyProcessFixture()
|
spawn_process = helpers.SleepyProcessFixture()
|
||||||
self.useFixture(spawn_process)
|
self.useFixture(spawn_process)
|
||||||
|
|
||||||
with open(pid_file, "w") as f_pid_file:
|
with open(pid_file, "w") as f_pid_file:
|
||||||
|
@ -113,23 +110,3 @@ class KeepalivedManagerTestCase(base.BaseTestCase,
|
||||||
self._test_keepalived_spawns_conflicting_pid(
|
self._test_keepalived_spawns_conflicting_pid(
|
||||||
process,
|
process,
|
||||||
self.manager.get_vrrp_pid_file_name(pid_file))
|
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