Merge "Use more specific asserts in test/unit/cli tests"

This commit is contained in:
Jenkins 2016-08-30 00:44:02 +00:00 committed by Gerrit Code Review
commit 95322d9830
5 changed files with 111 additions and 112 deletions

View File

@ -49,14 +49,14 @@ class TestFormSignature(unittest.TestCase):
max_file_count, str(expires), key])
self.assertEqual(exitcode, 0)
self.assertTrue("Signature: %s" % expected_signature
in out.getvalue())
self.assertTrue("Expires: %d" % (the_time + expires,)
in out.getvalue())
self.assertIn("Signature: %s" % expected_signature,
out.getvalue())
self.assertIn("Expires: %d" % (the_time + expires,),
out.getvalue())
sig_input = ('<input type="hidden" name="signature" value="%s" />'
% expected_signature)
self.assertTrue(sig_input in out.getvalue())
self.assertIn(sig_input, out.getvalue())
def test_too_few_args(self):
out = StringIO()
@ -67,7 +67,7 @@ class TestFormSignature(unittest.TestCase):
self.assertNotEqual(exitcode, 0)
usage = 'Syntax: swift-form-signature <path>'
self.assertTrue(usage in out.getvalue())
self.assertIn(usage, out.getvalue())
def test_invalid_filesize_arg(self):
out = StringIO()

View File

@ -89,9 +89,8 @@ class TestCliInfoBase(unittest.TestCase):
try:
func(*args, **kwargs)
except Exception as e:
self.assertTrue(msg in str(e),
"Expected %r in %r" % (msg, str(e)))
self.assertTrue(isinstance(e, exc),
self.assertIn(msg, str(e), "Expected %r in %r" % (msg, str(e)))
self.assertIsInstance(e, exc,
"Expected %s, got %s" % (exc, type(e)))
@ -206,9 +205,9 @@ No user metadata found in db file''' % POLICIES[0].name
print_ring_locations(acctring, 'dir', 'acct')
exp_db = os.path.join('${DEVICE:-/srv/node*}', 'sdb1', 'dir', '3',
'b47', 'dc5be2aa4347a22a0fee6bc7de505b47')
self.assertTrue(exp_db in out.getvalue())
self.assertTrue('127.0.0.1' in out.getvalue())
self.assertTrue('127.0.0.2' in out.getvalue())
self.assertIn(exp_db, out.getvalue())
self.assertIn('127.0.0.1', out.getvalue())
self.assertIn('127.0.0.2', out.getvalue())
def test_print_ring_locations_container(self):
out = StringIO()
@ -217,7 +216,7 @@ No user metadata found in db file''' % POLICIES[0].name
print_ring_locations(contring, 'dir', 'acct', 'con')
exp_db = os.path.join('${DEVICE:-/srv/node*}', 'sdb1', 'dir', '1',
'fe6', '63e70955d78dfc62821edc07d6ec1fe6')
self.assertTrue(exp_db in out.getvalue())
self.assertIn(exp_db, out.getvalue())
def test_print_ring_locations_obj(self):
out = StringIO()
@ -226,7 +225,7 @@ No user metadata found in db file''' % POLICIES[0].name
print_ring_locations(objring, 'dir', 'acct', 'con', 'obj')
exp_obj = os.path.join('${DEVICE:-/srv/node*}', 'sda1', 'dir', '1',
'117', '4a16154fc15c75e26ba6afadf5b1c117')
self.assertTrue(exp_obj in out.getvalue())
self.assertIn(exp_obj, out.getvalue())
def test_print_ring_locations_partition_number(self):
out = StringIO()
@ -237,8 +236,8 @@ No user metadata found in db file''' % POLICIES[0].name
'objects', '1')
exp_obj2 = os.path.join('${DEVICE:-/srv/node*}', 'sdb1',
'objects', '1')
self.assertTrue(exp_obj1 in out.getvalue())
self.assertTrue(exp_obj2 in out.getvalue())
self.assertIn(exp_obj1, out.getvalue())
self.assertIn(exp_obj2, out.getvalue())
def test_print_item_locations_invalid_args(self):
# No target specified
@ -265,9 +264,9 @@ No user metadata found in db file''' % POLICIES[0].name
# Test mismatch of ring and policy name (valid policy)
self.assertRaises(InfoSystemExit, print_item_locations,
objring, policy_name='zero')
self.assertTrue('Warning: mismatch between ring and policy name!'
in out.getvalue())
self.assertTrue('No target specified' in out.getvalue())
self.assertIn('Warning: mismatch between ring and policy name!',
out.getvalue())
self.assertIn('No target specified', out.getvalue())
def test_print_item_locations_invalid_policy_no_target(self):
out = StringIO()
@ -277,8 +276,8 @@ No user metadata found in db file''' % POLICIES[0].name
self.assertRaises(InfoSystemExit, print_item_locations,
objring, policy_name=policy_name)
exp_msg = 'Warning: Policy %s is not valid' % policy_name
self.assertTrue(exp_msg in out.getvalue())
self.assertTrue('No target specified' in out.getvalue())
self.assertIn(exp_msg, out.getvalue())
self.assertIn('No target specified', out.getvalue())
def test_print_item_locations_policy_object(self):
out = StringIO()
@ -290,10 +289,10 @@ No user metadata found in db file''' % POLICIES[0].name
exp_acct_msg = 'Account \tNone'
exp_cont_msg = 'Container\tNone'
exp_obj_msg = 'Object \tNone'
self.assertTrue(exp_part_msg in out.getvalue())
self.assertTrue(exp_acct_msg in out.getvalue())
self.assertTrue(exp_cont_msg in out.getvalue())
self.assertTrue(exp_obj_msg in out.getvalue())
self.assertIn(exp_part_msg, out.getvalue())
self.assertIn(exp_acct_msg, out.getvalue())
self.assertIn(exp_cont_msg, out.getvalue())
self.assertIn(exp_obj_msg, out.getvalue())
def test_print_item_locations_dashed_ring_name_partition(self):
out = StringIO()
@ -306,10 +305,10 @@ No user metadata found in db file''' % POLICIES[0].name
exp_acct_msg = 'Account \tNone'
exp_cont_msg = 'Container\tNone'
exp_obj_msg = 'Object \tNone'
self.assertTrue(exp_part_msg in out.getvalue())
self.assertTrue(exp_acct_msg in out.getvalue())
self.assertTrue(exp_cont_msg in out.getvalue())
self.assertTrue(exp_obj_msg in out.getvalue())
self.assertIn(exp_part_msg, out.getvalue())
self.assertIn(exp_acct_msg, out.getvalue())
self.assertIn(exp_cont_msg, out.getvalue())
self.assertIn(exp_obj_msg, out.getvalue())
def test_print_item_locations_account_with_ring(self):
out = StringIO()
@ -318,16 +317,16 @@ No user metadata found in db file''' % POLICIES[0].name
account_ring = ring.Ring(self.testdir, ring_name=account)
print_item_locations(account_ring, account=account)
exp_msg = 'Account \t%s' % account
self.assertTrue(exp_msg in out.getvalue())
self.assertIn(exp_msg, out.getvalue())
exp_warning = 'Warning: account specified ' + \
'but ring not named "account"'
self.assertTrue(exp_warning in out.getvalue())
self.assertIn(exp_warning, out.getvalue())
exp_acct_msg = 'Account \t%s' % account
exp_cont_msg = 'Container\tNone'
exp_obj_msg = 'Object \tNone'
self.assertTrue(exp_acct_msg in out.getvalue())
self.assertTrue(exp_cont_msg in out.getvalue())
self.assertTrue(exp_obj_msg in out.getvalue())
self.assertIn(exp_acct_msg, out.getvalue())
self.assertIn(exp_cont_msg, out.getvalue())
self.assertIn(exp_obj_msg, out.getvalue())
def test_print_item_locations_account_no_ring(self):
out = StringIO()
@ -338,9 +337,9 @@ No user metadata found in db file''' % POLICIES[0].name
exp_acct_msg = 'Account \t%s' % account
exp_cont_msg = 'Container\tNone'
exp_obj_msg = 'Object \tNone'
self.assertTrue(exp_acct_msg in out.getvalue())
self.assertTrue(exp_cont_msg in out.getvalue())
self.assertTrue(exp_obj_msg in out.getvalue())
self.assertIn(exp_acct_msg, out.getvalue())
self.assertIn(exp_cont_msg, out.getvalue())
self.assertIn(exp_obj_msg, out.getvalue())
def test_print_item_locations_account_container_ring(self):
out = StringIO()
@ -353,9 +352,9 @@ No user metadata found in db file''' % POLICIES[0].name
exp_acct_msg = 'Account \t%s' % account
exp_cont_msg = 'Container\t%s' % container
exp_obj_msg = 'Object \tNone'
self.assertTrue(exp_acct_msg in out.getvalue())
self.assertTrue(exp_cont_msg in out.getvalue())
self.assertTrue(exp_obj_msg in out.getvalue())
self.assertIn(exp_acct_msg, out.getvalue())
self.assertIn(exp_cont_msg, out.getvalue())
self.assertIn(exp_obj_msg, out.getvalue())
def test_print_item_locations_account_container_no_ring(self):
out = StringIO()
@ -367,9 +366,9 @@ No user metadata found in db file''' % POLICIES[0].name
exp_acct_msg = 'Account \t%s' % account
exp_cont_msg = 'Container\t%s' % container
exp_obj_msg = 'Object \tNone'
self.assertTrue(exp_acct_msg in out.getvalue())
self.assertTrue(exp_cont_msg in out.getvalue())
self.assertTrue(exp_obj_msg in out.getvalue())
self.assertIn(exp_acct_msg, out.getvalue())
self.assertIn(exp_cont_msg, out.getvalue())
self.assertIn(exp_obj_msg, out.getvalue())
def test_print_item_locations_account_container_object_ring(self):
out = StringIO()
@ -384,9 +383,9 @@ No user metadata found in db file''' % POLICIES[0].name
exp_acct_msg = 'Account \t%s' % account
exp_cont_msg = 'Container\t%s' % container
exp_obj_msg = 'Object \t%s' % obj
self.assertTrue(exp_acct_msg in out.getvalue())
self.assertTrue(exp_cont_msg in out.getvalue())
self.assertTrue(exp_obj_msg in out.getvalue())
self.assertIn(exp_acct_msg, out.getvalue())
self.assertIn(exp_cont_msg, out.getvalue())
self.assertIn(exp_obj_msg, out.getvalue())
def test_print_item_locations_account_container_object_dashed_ring(self):
out = StringIO()
@ -401,9 +400,9 @@ No user metadata found in db file''' % POLICIES[0].name
exp_acct_msg = 'Account \t%s' % account
exp_cont_msg = 'Container\t%s' % container
exp_obj_msg = 'Object \t%s' % obj
self.assertTrue(exp_acct_msg in out.getvalue())
self.assertTrue(exp_cont_msg in out.getvalue())
self.assertTrue(exp_obj_msg in out.getvalue())
self.assertIn(exp_acct_msg, out.getvalue())
self.assertIn(exp_cont_msg, out.getvalue())
self.assertIn(exp_obj_msg, out.getvalue())
def test_print_info(self):
db_file = 'foo'
@ -431,7 +430,7 @@ No user metadata found in db file''' % POLICIES[0].name
if exp_raised:
self.fail("Unexpected exception raised")
else:
self.assertTrue(len(out.getvalue().strip()) > 800)
self.assertGreater(len(out.getvalue().strip()), 800)
controller = ContainerController(
{'devices': self.testdir, 'mount_check': 'false'})
@ -459,7 +458,7 @@ No user metadata found in db file''' % POLICIES[0].name
if exp_raised:
self.fail("Unexpected exception raised")
else:
self.assertTrue(len(out.getvalue().strip()) > 600)
self.assertGreater(len(out.getvalue().strip()), 600)
out = StringIO()
exp_raised = False
@ -517,8 +516,8 @@ class TestPrintObj(TestCliInfoBase):
print_obj(self.datafile, swift_dir=self.testdir)
etag_msg = 'ETag: Not found in metadata'
length_msg = 'Content-Length: Not found in metadata'
self.assertTrue(etag_msg in out.getvalue())
self.assertTrue(length_msg in out.getvalue())
self.assertIn(etag_msg, out.getvalue())
self.assertIn(length_msg, out.getvalue())
def test_print_obj_with_policy(self):
out = StringIO()
@ -527,15 +526,15 @@ class TestPrintObj(TestCliInfoBase):
etag_msg = 'ETag: Not found in metadata'
length_msg = 'Content-Length: Not found in metadata'
ring_loc_msg = 'ls -lah'
self.assertTrue(etag_msg in out.getvalue())
self.assertTrue(length_msg in out.getvalue())
self.assertTrue(ring_loc_msg in out.getvalue())
self.assertIn(etag_msg, out.getvalue())
self.assertIn(length_msg, out.getvalue())
self.assertIn(ring_loc_msg, out.getvalue())
def test_missing_etag(self):
out = StringIO()
with mock.patch('sys.stdout', out):
print_obj(self.datafile)
self.assertTrue('ETag: Not found in metadata' in out.getvalue())
self.assertIn('ETag: Not found in metadata', out.getvalue())
class TestPrintObjFullMeta(TestCliInfoBase):
@ -558,7 +557,7 @@ class TestPrintObjFullMeta(TestCliInfoBase):
out = StringIO()
with mock.patch('sys.stdout', out):
print_obj(self.datafile, swift_dir=self.testdir)
self.assertTrue('/objects-1/' in out.getvalue())
self.assertIn('/objects-1/', out.getvalue())
def test_print_obj_policy_index(self):
# Check an output of policy index when current directory is in
@ -575,7 +574,7 @@ class TestPrintObjFullMeta(TestCliInfoBase):
print_obj(file_name, swift_dir=self.testdir)
finally:
os.chdir(cwd)
self.assertTrue('X-Backend-Storage-Policy-Index: 1' in out.getvalue())
self.assertIn('X-Backend-Storage-Policy-Index: 1', out.getvalue())
def test_print_obj_curl_command_ipv4(self):
# Note: policy 2 has IPv4 addresses in its ring
@ -668,7 +667,7 @@ class TestPrintObjFullMeta(TestCliInfoBase):
out = StringIO()
with mock.patch('sys.stdout', out):
print_obj(test_file, swift_dir=self.testdir)
self.assertTrue('/objects-1/' in out.getvalue())
self.assertIn('/objects-1/', out.getvalue())
def test_print_obj_no_ring(self):
no_rings_dir = os.path.join(self.testdir, 'no_rings_here')
@ -677,22 +676,22 @@ class TestPrintObjFullMeta(TestCliInfoBase):
out = StringIO()
with mock.patch('sys.stdout', out):
print_obj(self.datafile, swift_dir=no_rings_dir)
self.assertTrue('d41d8cd98f00b204e9800998ecf8427e' in out.getvalue())
self.assertTrue('Partition' not in out.getvalue())
self.assertIn('d41d8cd98f00b204e9800998ecf8427e', out.getvalue())
self.assertNotIn('Partition', out.getvalue())
def test_print_obj_policy_name_mismatch(self):
out = StringIO()
with mock.patch('sys.stdout', out):
print_obj(self.datafile, policy_name='two', swift_dir=self.testdir)
ring_alert_msg = 'Warning: Ring does not match policy!'
self.assertTrue(ring_alert_msg in out.getvalue())
self.assertIn(ring_alert_msg, out.getvalue())
def test_valid_etag(self):
out = StringIO()
with mock.patch('sys.stdout', out):
print_obj(self.datafile)
self.assertTrue('ETag: d41d8cd98f00b204e9800998ecf8427e (valid)'
in out.getvalue())
self.assertIn('ETag: d41d8cd98f00b204e9800998ecf8427e (valid)',
out.getvalue())
def test_invalid_etag(self):
with open(self.datafile, 'wb') as fp:
@ -705,15 +704,15 @@ class TestPrintObjFullMeta(TestCliInfoBase):
out = StringIO()
with mock.patch('sys.stdout', out):
print_obj(self.datafile)
self.assertTrue('ETag: badetag doesn\'t match file hash'
in out.getvalue())
self.assertIn('ETag: badetag doesn\'t match file hash',
out.getvalue())
def test_unchecked_etag(self):
out = StringIO()
with mock.patch('sys.stdout', out):
print_obj(self.datafile, check_etag=False)
self.assertTrue('ETag: d41d8cd98f00b204e9800998ecf8427e (not checked)'
in out.getvalue())
self.assertIn('ETag: d41d8cd98f00b204e9800998ecf8427e (not checked)',
out.getvalue())
def test_print_obj_metadata(self):
self.assertRaisesMessage(ValueError, 'Metadata is None',

View File

@ -74,7 +74,7 @@ class TestScout(unittest.TestCase):
mock_urlopen.side_effect = urllib2.URLError("")
url, content, status, ts_start, ts_end = self.scout_instance.scout(
("127.0.0.1", "8080"))
self.assertTrue(isinstance(content, urllib2.URLError))
self.assertIsInstance(content, urllib2.URLError)
self.assertEqual(url, self.url)
self.assertEqual(status, -1)
@ -85,7 +85,7 @@ class TestScout(unittest.TestCase):
url, content, status, ts_start, ts_end = self.scout_instance.scout(
("127.0.0.1", "8080"))
self.assertEqual(url, self.url)
self.assertTrue(isinstance(content, urllib2.HTTPError))
self.assertIsInstance(content, urllib2.HTTPError)
self.assertEqual(status, 404)
@mock.patch('eventlet.green.urllib2.urlopen')
@ -93,7 +93,7 @@ class TestScout(unittest.TestCase):
mock_urlopen.side_effect = socket.timeout("timeout")
url, content, status, ts_start, ts_end = self.scout_instance.scout(
("127.0.0.1", "8080"))
self.assertTrue(isinstance(content, socket.timeout))
self.assertIsInstance(content, socket.timeout)
self.assertEqual(url, self.url)
self.assertEqual(status, -1)
@ -114,7 +114,7 @@ class TestScout(unittest.TestCase):
mock_urlopen.side_effect = urllib2.URLError("")
url, content, status = self.scout_instance.scout_server_type(
("127.0.0.1", "8080"))
self.assertTrue(isinstance(content, urllib2.URLError))
self.assertIsInstance(content, urllib2.URLError)
self.assertEqual(url, self.server_type_url)
self.assertEqual(status, -1)
@ -125,7 +125,7 @@ class TestScout(unittest.TestCase):
url, content, status = self.scout_instance.scout_server_type(
("127.0.0.1", "8080"))
self.assertEqual(url, self.server_type_url)
self.assertTrue(isinstance(content, urllib2.HTTPError))
self.assertIsInstance(content, urllib2.HTTPError)
self.assertEqual(status, 404)
@mock.patch('eventlet.green.urllib2.urlopen')
@ -133,7 +133,7 @@ class TestScout(unittest.TestCase):
mock_urlopen.side_effect = socket.timeout("timeout")
url, content, status = self.scout_instance.scout_server_type(
("127.0.0.1", "8080"))
self.assertTrue(isinstance(content, socket.timeout))
self.assertIsInstance(content, socket.timeout)
self.assertEqual(url, self.server_type_url)
self.assertEqual(status, -1)
@ -596,8 +596,8 @@ class TestReconCommands(unittest.TestCase):
self.recon.server_type_check(hosts)
output = stdout.getvalue()
self.assertTrue(res_container in output.splitlines())
self.assertTrue(res_account in output.splitlines())
self.assertIn(res_container, output.splitlines())
self.assertIn(res_account, output.splitlines())
stdout.truncate(0)
# Test ok for object server type - default
@ -607,7 +607,7 @@ class TestReconCommands(unittest.TestCase):
self.recon.server_type_check([hosts[0]])
output = stdout.getvalue()
self.assertTrue(valid in output.splitlines())
self.assertIn(valid, output.splitlines())
stdout.truncate(0)
# Test for account server type
@ -618,8 +618,8 @@ class TestReconCommands(unittest.TestCase):
self.recon.server_type_check(hosts)
output = stdout.getvalue()
self.assertTrue(res_container in output.splitlines())
self.assertTrue(res_object in output.splitlines())
self.assertIn(res_container, output.splitlines())
self.assertIn(res_object, output.splitlines())
stdout.truncate(0)
# Test ok for account server type
@ -630,7 +630,7 @@ class TestReconCommands(unittest.TestCase):
self.recon.server_type_check([hosts[2]])
output = stdout.getvalue()
self.assertTrue(valid in output.splitlines())
self.assertIn(valid, output.splitlines())
stdout.truncate(0)
# Test for container server type
@ -641,8 +641,8 @@ class TestReconCommands(unittest.TestCase):
self.recon.server_type_check(hosts)
output = stdout.getvalue()
self.assertTrue(res_account in output.splitlines())
self.assertTrue(res_object in output.splitlines())
self.assertIn(res_account, output.splitlines())
self.assertIn(res_object, output.splitlines())
stdout.truncate(0)
# Test ok for container server type
@ -653,7 +653,7 @@ class TestReconCommands(unittest.TestCase):
self.recon.server_type_check([hosts[1]])
output = stdout.getvalue()
self.assertTrue(valid in output.splitlines())
self.assertIn(valid, output.splitlines())
def test_get_swiftconfmd5(self):
hosts = set([('10.1.1.1', 10000),
@ -672,7 +672,7 @@ class TestReconCommands(unittest.TestCase):
self.recon.get_swiftconfmd5(hosts, printfn=printed.append)
output = '\n'.join(printed) + '\n'
self.assertTrue("2/2 hosts matched" in output)
self.assertIn("2/2 hosts matched", output)
def test_get_swiftconfmd5_mismatch(self):
hosts = set([('10.1.1.1', 10000),
@ -691,9 +691,9 @@ class TestReconCommands(unittest.TestCase):
self.recon.get_swiftconfmd5(hosts, printfn=printed.append)
output = '\n'.join(printed) + '\n'
self.assertTrue("1/2 hosts matched" in output)
self.assertTrue("http://10.2.2.2:10000/recon/swiftconfmd5 (bogus) "
"doesn't match on disk md5sum" in output)
self.assertIn("1/2 hosts matched", output)
self.assertIn("http://10.2.2.2:10000/recon/swiftconfmd5 (bogus) "
"doesn't match on disk md5sum", output)
def test_object_auditor_check(self):
# Recon middleware response from an object server
@ -738,7 +738,7 @@ class TestReconCommands(unittest.TestCase):
computed = response.get(name)
self.assertTrue(computed)
for key in keys:
self.assertTrue(key in computed)
self.assertIn(key, computed)
def test_disk_usage(self):
def dummy_request(*args, **kwargs):

View File

@ -46,7 +46,7 @@ class TestRunScenario(unittest.TestCase):
# Just test that it produced some output as it ran; the fact that
# this doesn't crash and produces output that resembles something
# useful is good enough.
self.assertTrue('Rebalance' in fake_stdout.getvalue())
self.assertIn('Rebalance', fake_stdout.getvalue())
self.assertTrue(os.path.exists(builder_path))

View File

@ -482,7 +482,7 @@ class TestCommands(unittest.TestCase, RunSwiftRingBuilderMixin):
# Check that ring was created with sane value for region
ring = RingBuilder.load(self.tmpfile)
dev = ring.devs[-1]
self.assertTrue(dev['region'] > 0)
self.assertGreater(dev['region'], 0)
def test_remove_device(self):
for search_value in self.search_values:
@ -1305,8 +1305,8 @@ class TestCommands(unittest.TestCase, RunSwiftRingBuilderMixin):
out, err = self.run_srb(*argv)
ring = RingBuilder.load(self.tmpfile)
self.assertEqual(ring.overload, 0.1)
self.assertTrue('10.00%' in out)
self.assertTrue('0.100000' in out)
self.assertIn('10.00%', out)
self.assertIn('0.100000', out)
def test_set_overload_percent_strange_input(self):
self.create_sample_ring()
@ -1314,8 +1314,8 @@ class TestCommands(unittest.TestCase, RunSwiftRingBuilderMixin):
out, err = self.run_srb(*argv)
ring = RingBuilder.load(self.tmpfile)
self.assertEqual(ring.overload, 0.26)
self.assertTrue('26.00%' in out)
self.assertTrue('0.260000' in out)
self.assertIn('26.00%', out)
self.assertIn('0.260000', out)
def test_server_overload_crazy_high(self):
self.create_sample_ring()
@ -1323,17 +1323,17 @@ class TestCommands(unittest.TestCase, RunSwiftRingBuilderMixin):
out, err = self.run_srb(*argv)
ring = RingBuilder.load(self.tmpfile)
self.assertEqual(ring.overload, 10.0)
self.assertTrue('Warning overload is greater than 100%' in out)
self.assertTrue('1000.00%' in out)
self.assertTrue('10.000000' in out)
self.assertIn('Warning overload is greater than 100%', out)
self.assertIn('1000.00%', out)
self.assertIn('10.000000', out)
# but it's cool if you do it on purpose
argv[-1] = '1000%'
out, err = self.run_srb(*argv)
ring = RingBuilder.load(self.tmpfile)
self.assertEqual(ring.overload, 10.0)
self.assertTrue('Warning overload is greater than 100%' not in out)
self.assertTrue('1000.00%' in out)
self.assertTrue('10.000000' in out)
self.assertNotIn('Warning overload is greater than 100%', out)
self.assertIn('1000.00%', out)
self.assertIn('10.000000', out)
def test_set_overload_number_of_arguments(self):
self.create_sample_ring()
@ -1855,7 +1855,7 @@ class TestCommands(unittest.TestCase, RunSwiftRingBuilderMixin):
self.assertSystemExit(EXIT_SUCCESS, ringbuilder.main, argv)
ring = RingBuilder.load(self.tmpfile)
self.assertTrue(ring.validate())
self.assertEqual(ring.devs[3], None)
self.assertIsNone(ring.devs[3])
def test_rebalance_resets_time_remaining(self):
self.create_sample_ring()
@ -1960,7 +1960,7 @@ class TestCommands(unittest.TestCase, RunSwiftRingBuilderMixin):
os.remove(self.tmpfile) # loses file...
argv = ["", backup_file, "write_builder", "24"]
self.assertEqual(ringbuilder.main(argv), None)
self.assertIsNone(ringbuilder.main(argv))
def test_warn_at_risk(self):
# when the number of total part replicas (3 * 2 ** 4 = 48 in
@ -2147,7 +2147,7 @@ class TestRebalanceCommand(unittest.TestCase, RunSwiftRingBuilderMixin):
"r1z1-10.1.1.1:2345/sdc", 100.0,
"r1z1-10.1.1.1:2345/sdd", 100.0)
out, err = self.run_srb("rebalance")
self.assertTrue("rebalance/repush" not in out)
self.assertNotIn("rebalance/repush", out)
# 2 machines of equal size: balanceable, but not in one pass due to
# min_part_hours > 0
@ -2158,12 +2158,12 @@ class TestRebalanceCommand(unittest.TestCase, RunSwiftRingBuilderMixin):
"r1z1-10.1.1.2:2345/sdd", 100.0)
self.run_srb("pretend_min_part_hours_passed")
out, err = self.run_srb("rebalance")
self.assertTrue("rebalance/repush" in out)
self.assertIn("rebalance/repush", out)
# after two passes, it's all balanced out
self.run_srb("pretend_min_part_hours_passed")
out, err = self.run_srb("rebalance")
self.assertTrue("rebalance/repush" not in out)
self.assertNotIn("rebalance/repush", out)
def test_rebalance_warning_with_overload(self):
self.run_srb("create", 8, 3, 24)
@ -2175,14 +2175,14 @@ class TestRebalanceCommand(unittest.TestCase, RunSwiftRingBuilderMixin):
"r1z1-10.1.1.1:2345/sdb", 100.0,
"r1z1-10.1.1.1:2345/sdc", 120.0)
out, err = self.run_srb("rebalance")
self.assertTrue("rebalance/repush" not in out)
self.assertNotIn("rebalance/repush", out)
# Now we add in a really big device, but not enough partitions move
# to fill it in one pass, so we see the rebalance warning.
self.run_srb("add", "r1z1-10.1.1.1:2345/sdd", 99999.0)
self.run_srb("pretend_min_part_hours_passed")
out, err = self.run_srb("rebalance")
self.assertTrue("rebalance/repush" in out)
self.assertIn("rebalance/repush", out)
def test_cached_dispersion_value(self):
self.run_srb("create", 8, 3, 24)
@ -2193,18 +2193,18 @@ class TestRebalanceCommand(unittest.TestCase, RunSwiftRingBuilderMixin):
"r1z1-10.1.1.1:2345/sdd", 100.0)
self.run_srb('rebalance')
out, err = self.run_srb() # list devices
self.assertTrue('dispersion' in out)
self.assertIn('dispersion', out)
# remove cached dispersion value
builder = RingBuilder.load(self.tempfile)
builder.dispersion = None
builder.save(self.tempfile)
# now dispersion output is suppressed
out, err = self.run_srb() # list devices
self.assertFalse('dispersion' in out)
self.assertNotIn('dispersion', out)
# but will show up after rebalance
self.run_srb('rebalance', '-f')
out, err = self.run_srb() # list devices
self.assertTrue('dispersion' in out)
self.assertIn('dispersion', out)
if __name__ == '__main__':