Make probe tests tolerate deprecated policies

A deprecated policy in swift.conf causes errors in
probe tests that may attempt to use that policy.

This patch introduces a list ENABLED_POLICIES in
test/probe/common.py and changes probe tests to only
use policies contained in that list.

Change-Id: Ie65477c15d631fcfc3a4a5772fbe6d7d171b22b0
This commit is contained in:
Alistair Coles 2014-09-08 16:54:41 +01:00
parent f436da3b9b
commit 22b65846aa
6 changed files with 31 additions and 23 deletions

View File

@ -26,6 +26,8 @@ from swift.common.http import HTTP_NOT_FOUND
from swiftclient import client, get_auth, ClientException
from test.probe.common import ENABLED_POLICIES
TIMEOUT = 60
@ -73,7 +75,7 @@ class BrainSplitter(object):
self.object_name = object_name
server_list = ['%s-server' % server_type] if server_type else ['all']
self.servers = Manager(server_list)
policies = list(POLICIES)
policies = list(ENABLED_POLICIES)
random.shuffle(policies)
self.policies = itertools.cycle(policies)

View File

@ -31,6 +31,9 @@ from swift.common.storage_policy import POLICIES
from test.probe import CHECK_SERVER_TIMEOUT, VALIDATE_RSYNC
ENABLED_POLICIES = [p for p in POLICIES if not p.is_deprecated]
def get_server_number(port, port2server):
server_number = port2server[port]
server, number = server_number[:-1], server_number[-1:]

View File

@ -22,7 +22,7 @@ from swift.common.manager import Manager
from swift.common.direct_client import direct_delete_account, \
direct_get_object, direct_head_container, ClientException
from test.probe.common import kill_servers, reset_environment, \
get_to_final_state
get_to_final_state, ENABLED_POLICIES
class TestAccountReaper(unittest.TestCase):
@ -38,7 +38,7 @@ class TestAccountReaper(unittest.TestCase):
def test_sync(self):
all_objects = []
# upload some containers
for policy in POLICIES:
for policy in ENABLED_POLICIES:
container = 'container-%s-%s' % (policy.name, uuid.uuid4())
client.put_container(self.url, self.token, container,
headers={'X-Storage-Policy': policy.name})
@ -52,11 +52,11 @@ class TestAccountReaper(unittest.TestCase):
headers = client.head_account(self.url, self.token)
self.assertEqual(int(headers['x-account-container-count']),
len(POLICIES))
len(ENABLED_POLICIES))
self.assertEqual(int(headers['x-account-object-count']),
len(POLICIES))
len(ENABLED_POLICIES))
self.assertEqual(int(headers['x-account-bytes-used']),
len(POLICIES) * len(body))
len(ENABLED_POLICIES) * len(body))
part, nodes = self.account_ring.get_nodes(self.account)
for node in nodes:

View File

@ -26,7 +26,8 @@ from swift.common import utils, direct_client
from swift.common.storage_policy import POLICIES
from swift.common.http import HTTP_NOT_FOUND
from test.probe.brain import BrainSplitter
from test.probe.common import reset_environment, get_to_final_state
from test.probe.common import reset_environment, get_to_final_state, \
ENABLED_POLICIES
from swiftclient import client, ClientException
@ -36,7 +37,7 @@ TIMEOUT = 60
class TestContainerMergePolicyIndex(unittest.TestCase):
def setUp(self):
if len(POLICIES) < 2:
if len(ENABLED_POLICIES) < 2:
raise SkipTest()
(self.pids, self.port2server, self.account_ring, self.container_ring,
self.object_ring, self.policy, self.url, self.token,
@ -252,7 +253,7 @@ class TestContainerMergePolicyIndex(unittest.TestCase):
# get an old container stashed
self.brain.stop_primary_half()
policy = random.choice(list(POLICIES))
policy = random.choice(ENABLED_POLICIES)
self.brain.put_container(policy.idx)
self.brain.start_primary_half()
# write some parts
@ -260,7 +261,8 @@ class TestContainerMergePolicyIndex(unittest.TestCase):
write_part(i)
self.brain.stop_handoff_half()
wrong_policy = random.choice([p for p in POLICIES if p is not policy])
wrong_policy = random.choice([p for p in ENABLED_POLICIES
if p is not policy])
self.brain.put_container(wrong_policy.idx)
# write some more parts
for i in range(10, 20):
@ -347,8 +349,9 @@ class TestContainerMergePolicyIndex(unittest.TestCase):
def test_reconciler_move_object_twice(self):
# select some policies
old_policy = random.choice(list(POLICIES))
new_policy = random.choice([p for p in POLICIES if p != old_policy])
old_policy = random.choice(ENABLED_POLICIES)
new_policy = random.choice([p for p in ENABLED_POLICIES
if p != old_policy])
# setup a split brain
self.brain.stop_handoff_half()

View File

@ -20,9 +20,8 @@ from nose import SkipTest
from swiftclient import client
from swift.common.storage_policy import POLICIES
from swift.common.manager import Manager
from test.probe.common import kill_servers, reset_environment
from test.probe.common import kill_servers, reset_environment, ENABLED_POLICIES
def get_current_realm_cluster(url):
@ -62,8 +61,8 @@ class TestContainerSync(unittest.TestCase):
dest_container = 'dest-container-%s' % uuid.uuid4()
dest_headers = base_headers.copy()
dest_policy = None
if len(POLICIES) > 1:
dest_policy = random.choice(list(POLICIES))
if len(ENABLED_POLICIES) > 1:
dest_policy = random.choice(ENABLED_POLICIES)
dest_headers['X-Storage-Policy'] = dest_policy.name
client.put_container(self.url, self.token, dest_container,
headers=dest_headers)
@ -75,7 +74,7 @@ class TestContainerSync(unittest.TestCase):
dest_container)
source_headers['X-Container-Sync-To'] = sync_to
if dest_policy:
source_policy = random.choice([p for p in POLICIES
source_policy = random.choice([p for p in ENABLED_POLICIES
if p is not dest_policy])
source_headers['X-Storage-Policy'] = source_policy.name
client.put_container(self.url, self.token, source_container,

View File

@ -20,10 +20,10 @@ from nose import SkipTest
from swift.common.internal_client import InternalClient
from swift.common.manager import Manager
from swift.common.storage_policy import POLICIES
from swift.common.utils import Timestamp
from test.probe.common import reset_environment, get_to_final_state
from test.probe.common import reset_environment, get_to_final_state, \
ENABLED_POLICIES
from test.probe.test_container_merge_policy_index import BrainSplitter
from swiftclient import client
@ -32,7 +32,7 @@ from swiftclient import client
class TestObjectExpirer(unittest.TestCase):
def setUp(self):
if len(POLICIES) < 2:
if len(ENABLED_POLICIES) < 2:
raise SkipTest('Need more than one policy')
self.expirer = Manager(['object-expirer'])
@ -56,8 +56,9 @@ class TestObjectExpirer(unittest.TestCase):
self.object_name)
def test_expirer_object_split_brain(self):
old_policy = random.choice(list(POLICIES))
wrong_policy = random.choice([p for p in POLICIES if p != old_policy])
old_policy = random.choice(ENABLED_POLICIES)
wrong_policy = random.choice([p for p in ENABLED_POLICIES
if p != old_policy])
# create an expiring object and a container with the wrong policy
self.brain.stop_primary_half()
self.brain.put_container(int(old_policy))
@ -114,7 +115,7 @@ class TestObjectExpirer(unittest.TestCase):
# and validate object is tombstoned
found_in_policy = None
for policy in POLICIES:
for policy in ENABLED_POLICIES:
metadata = self.client.get_object_metadata(
self.account, self.container_name, self.object_name,
acceptable_statuses=(4,),