14
14
# limitations under the License.
16
16
from httplib import HTTPConnection
17
18
from os import kill, path
18
19
from signal import SIGTERM
19
20
from subprocess import Popen, PIPE
20
22
from time import sleep, time
22
24
from swiftclient import get_auth, head_account
24
26
from swift.common.ring import Ring
27
from swift.common.utils import readconf
26
from test.probe import CHECK_SERVER_TIMEOUT
29
from test.probe import CHECK_SERVER_TIMEOUT, VALIDATE_RSYNC
29
32
def start_server(port, port2server, pids, check=True):
136
def get_ring(server, force_validate=None):
137
ring = Ring('/etc/swift/%s.ring.gz' % server)
138
if not VALIDATE_RSYNC and not force_validate:
141
assert 3 == ring.replica_count, '%s has %s replicas instead of 3' % (
142
ring.serialized_path, ring.replica_count)
143
assert 4 == len(ring.devs), '%s has %s devices instead of 4' % (
144
ring.serialized_path, len(ring.devs))
145
# map server to config by port
147
for node_id in range(1,5):
148
conf = readconf('/etc/swift/%s-server/%d.conf' % (server, node_id),
149
section_name='%s-replicator' % server)
150
port_to_config[int(conf['bind_port'])] = conf
151
for dev in ring.devs:
152
# verify server is exposing mounted device
153
conf = port_to_config[dev['port']]
154
for device in os.listdir(conf['devices']):
155
if device == dev['device']:
156
full_path = path.realpath(path.join(conf['devices'], device))
157
assert path.ismount(full_path), 'device %s in %s was not ' \
158
'mounted (%s)' % (device, conf['devices'], full_path)
161
assert False, "unable to find ring device %s " \
162
"under %s's devices (%s)" % (
163
dev['device'], server, conf['devices'])
164
# verify server is exposing rsync device
165
rsync_export = '%s%s' % (server, dev['replication_port'])
166
cmd = "rsync rsync://localhost/%s" % rsync_export
167
p = Popen(cmd, shell=True, stdout=PIPE)
168
stdout, _stderr = p.communicate()
170
raise AssertionError('unable to connect to rsync '
171
'export %s (%s)' % (rsync_export, cmd))
172
for line in stdout.splitlines():
173
if line.rsplit(None, 1)[-1] == dev['device']:
176
assert False, "unable to find ring device %s under rsync's " \
177
"exported devices for %s (%s)" % (
178
dev['device'], rsync_export, cmd)
133
182
def reset_environment():
134
183
p = Popen("resetswift 2>&1", shell=True, stdout=PIPE)
135
184
stdout, _stderr = p.communicate()
188
account_ring = get_ring('account')
189
container_ring = get_ring('container')
190
object_ring = get_ring('object')
141
193
for server, port in [('account', 6002), ('container', 6001),
148
200
check_server(port, port2server, pids)
149
201
port2server[8080] = 'proxy'
150
202
url, token, account = start_server(8080, port2server, pids)
151
account_ring = Ring('/etc/swift/account.ring.gz')
152
container_ring = Ring('/etc/swift/container.ring.gz')
153
object_ring = Ring('/etc/swift/object.ring.gz')
154
203
for name in ('account', 'container', 'object'):
155
204
for server in (name, '%s-replicator' % name):
156
205
config_dict[server] = '/etc/swift/%s-server/%%d.conf' % name
157
206
except BaseException:
209
except AssertionError, e:
210
print >>sys.stderr, 'ERROR: %s' % e
162
214
kill_servers(port2server, pids)