Merge "Add ringbuilder tests for --yes option"

This commit is contained in:
Jenkins 2016-07-08 23:30:34 +00:00 committed by Gerrit Code Review
commit fa1f67b116
2 changed files with 43 additions and 0 deletions

View File

@ -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

View File

@ -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):