Add ringbuilder tests for --yes option
Also added a Timeout class to test.unit to wrap possible long-running functions. For example, if there is some regression and the "--yes" argument is no longer evaluated correctly and the test excepts some keyboard input, it will be terminated after a few seconds to ensure there is no long-running blocker on the gate. Change-Id: I07b17d21d5af7fcc594ce5319ae2b6f7f58df4bb
This commit is contained in:
parent
561284e3d4
commit
e5a6d45882
@ -32,6 +32,7 @@ import eventlet
|
|||||||
from eventlet.green import socket
|
from eventlet.green import socket
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
|
import signal
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
@ -1061,3 +1062,20 @@ def mocked_http_conn(*args, **kwargs):
|
|||||||
|
|
||||||
def make_timestamp_iter():
|
def make_timestamp_iter():
|
||||||
return iter(Timestamp(t) for t in itertools.count(int(time.time())))
|
return iter(Timestamp(t) for t in itertools.count(int(time.time())))
|
||||||
|
|
||||||
|
|
||||||
|
class Timeout(object):
|
||||||
|
def __init__(self, seconds):
|
||||||
|
self.seconds = seconds
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
signal.signal(signal.SIGALRM, self._exit)
|
||||||
|
signal.alarm(self.seconds)
|
||||||
|
|
||||||
|
def __exit__(self, type, value, traceback):
|
||||||
|
signal.alarm(0)
|
||||||
|
|
||||||
|
def _exit(self, signum, frame):
|
||||||
|
class TimeoutException(Exception):
|
||||||
|
pass
|
||||||
|
raise TimeoutException
|
||||||
|
@ -29,6 +29,8 @@ from swift.cli.ringbuilder import EXIT_SUCCESS, EXIT_WARNING, EXIT_ERROR
|
|||||||
from swift.common import exceptions
|
from swift.common import exceptions
|
||||||
from swift.common.ring import RingBuilder
|
from swift.common.ring import RingBuilder
|
||||||
|
|
||||||
|
from test.unit import Timeout
|
||||||
|
|
||||||
|
|
||||||
class RunSwiftRingBuilderMixin(object):
|
class RunSwiftRingBuilderMixin(object):
|
||||||
|
|
||||||
@ -1955,6 +1957,29 @@ class TestCommands(unittest.TestCase, RunSwiftRingBuilderMixin):
|
|||||||
argv = ["-safe", self.tmpfile]
|
argv = ["-safe", self.tmpfile]
|
||||||
self.assertSystemExit(EXIT_SUCCESS, ringbuilder.main, argv)
|
self.assertSystemExit(EXIT_SUCCESS, ringbuilder.main, argv)
|
||||||
|
|
||||||
|
def test_remove_all_devices(self):
|
||||||
|
# Would block without the 'yes' argument
|
||||||
|
self.create_sample_ring()
|
||||||
|
argv = ["", self.tmpfile, "remove", "--weight", "100", "--yes"]
|
||||||
|
with Timeout(5):
|
||||||
|
self.assertSystemExit(EXIT_SUCCESS, ringbuilder.main, argv)
|
||||||
|
|
||||||
|
def test_set_info_all_devices(self):
|
||||||
|
# Would block without the 'yes' argument
|
||||||
|
self.create_sample_ring()
|
||||||
|
argv = ["", self.tmpfile, "set_info", "--weight", "100",
|
||||||
|
"--change-meta", "something", "--yes"]
|
||||||
|
with Timeout(5):
|
||||||
|
self.assertSystemExit(EXIT_SUCCESS, ringbuilder.main, argv)
|
||||||
|
|
||||||
|
def test_set_weight_all_devices(self):
|
||||||
|
# Would block without the 'yes' argument
|
||||||
|
self.create_sample_ring()
|
||||||
|
argv = ["", self.tmpfile, "set_weight",
|
||||||
|
"--weight", "100", "200", "--yes"]
|
||||||
|
with Timeout(5):
|
||||||
|
self.assertSystemExit(EXIT_SUCCESS, ringbuilder.main, argv)
|
||||||
|
|
||||||
|
|
||||||
class TestRebalanceCommand(unittest.TestCase, RunSwiftRingBuilderMixin):
|
class TestRebalanceCommand(unittest.TestCase, RunSwiftRingBuilderMixin):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user