2
# Copyright (c) 2010-2012 OpenStack, LLC.
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14
# See the License for the specific language governing permissions and
15
# limitations under the License.
19
from signal import SIGTERM
20
from subprocess import Popen
21
from time import sleep
23
from swiftclient import client
25
from test.probe.common import get_to_final_state, kill_pids, reset_environment
28
class TestRunningWithEachTypeDown(unittest.TestCase):
31
self.pids, self.port2server, self.account_ring, self.container_ring, \
32
self.object_ring, self.url, self.token, self.account = \
39
# TODO: This test "randomly" pass or doesn't pass; need to find out why
41
apart, anodes = self.account_ring.get_nodes(self.account)
42
kill(self.pids[self.port2server[anodes[0]['port']]], SIGTERM)
44
self.container_ring.get_nodes(self.account, 'container1')
45
kill(self.pids[self.port2server[cnodes[0]['port']]], SIGTERM)
47
self.object_ring.get_nodes(self.account, 'container1', 'object1')
48
kill(self.pids[self.port2server[onodes[0]['port']]], SIGTERM)
51
client.put_container(self.url, self.token, 'container1')
52
except client.ClientException, err:
53
# This might 503 if one of the up container nodes tries to update
54
# the down account node. It'll still be saved on one node, but we
55
# can't assure the user.
57
client.put_object(self.url, self.token, 'container1', 'object1', '1234')
59
headers, containers = client.head_account(self.url, self.token)
60
self.assertEquals(headers['x-account-container-count'], '1')
61
self.assertEquals(headers['x-account-object-count'], '1')
62
self.assertEquals(headers['x-account-bytes-used'], '4')
64
for container in containers:
65
if container['name'] == 'container1':
67
self.assertEquals(container['count'], 1)
68
self.assertEquals(container['bytes'], 4)
71
for obj in client.get_container(self.url, self.token, 'container1')[1]:
72
if obj['name'] == 'object1':
74
self.assertEquals(obj['bytes'], 4)
77
self.pids[self.port2server[anodes[0]['port']]] = \
78
Popen(['swift-account-server',
79
'/etc/swift/account-server/%d.conf' %
80
((anodes[0]['port'] - 6002) / 10)]).pid
81
self.pids[self.port2server[cnodes[0]['port']]] = \
82
Popen(['swift-container-server',
83
'/etc/swift/container-server/%d.conf' %
84
((cnodes[0]['port'] - 6001) / 10)]).pid
85
self.pids[self.port2server[onodes[0]['port']]] = \
86
Popen(['swift-object-server',
87
'/etc/swift/object-server/%d.conf' %
88
((onodes[0]['port'] - 6000) / 10)]).pid
90
headers, containers = client.head_account(self.url, self.token)
91
self.assertEquals(headers['x-account-container-count'], '1')
92
self.assertEquals(headers['x-account-object-count'], '1')
93
self.assertEquals(headers['x-account-bytes-used'], '4')
95
for container in containers:
96
if container['name'] == 'container1':
98
# The account node was previously down.
99
self.assert_(not found1)
101
for obj in client.get_container(self.url, self.token, 'container1')[1]:
102
if obj['name'] == 'object1':
104
self.assertEquals(obj['bytes'], 4)
105
# The first container node 404s, but the proxy will try the next node
110
headers, containers = client.head_account(self.url, self.token)
111
self.assertEquals(headers['x-account-container-count'], '1')
112
self.assertEquals(headers['x-account-object-count'], '1')
113
self.assertEquals(headers['x-account-bytes-used'], '4')
115
for container in containers:
116
if container['name'] == 'container1':
118
self.assertEquals(container['count'], 1)
119
self.assertEquals(container['bytes'], 4)
122
for obj in client.get_container(self.url, self.token, 'container1')[1]:
123
if obj['name'] == 'object1':
125
self.assertEquals(obj['bytes'], 4)
129
if __name__ == '__main__':