~ubuntu-branches/ubuntu/trusty/swift/trusty-updates

« back to all changes in this revision

Viewing changes to test/probe/common.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, James Page, Chuck Short
  • Date: 2013-08-13 10:37:13 UTC
  • mfrom: (1.2.21)
  • Revision ID: package-import@ubuntu.com-20130813103713-1ctbx4zifyljs2aq
Tags: 1.9.1-0ubuntu1
[ James Page ]
* d/control: Update VCS fields for new branch locations.

[ Chuck Short ]
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# limitations under the License.
15
15
 
16
16
from httplib import HTTPConnection
 
17
import os
17
18
from os import kill, path
18
19
from signal import SIGTERM
19
20
from subprocess import Popen, PIPE
 
21
import sys
20
22
from time import sleep, time
21
23
 
22
24
from swiftclient import get_auth, head_account
23
25
 
24
26
from swift.common.ring import Ring
 
27
from swift.common.utils import readconf
25
28
 
26
 
from test.probe import CHECK_SERVER_TIMEOUT
 
29
from test.probe import CHECK_SERVER_TIMEOUT, VALIDATE_RSYNC
27
30
 
28
31
 
29
32
def start_server(port, port2server, pids, check=True):
130
133
            return port
131
134
 
132
135
 
 
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:
 
139
        return ring
 
140
    # easy sanity checks
 
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
 
146
    port_to_config = {}
 
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)
 
159
                break
 
160
        else:
 
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()
 
169
        if p.returncode:
 
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']:
 
174
                break
 
175
        else:
 
176
            assert False, "unable to find ring device %s under rsync's " \
 
177
                    "exported devices for %s (%s)" % (
 
178
                        dev['device'], rsync_export, cmd)
 
179
    return ring
 
180
 
 
181
 
133
182
def reset_environment():
134
183
    p = Popen("resetswift 2>&1", shell=True, stdout=PIPE)
135
184
    stdout, _stderr = p.communicate()
136
185
    print stdout
137
186
    pids = {}
138
187
    try:
 
188
        account_ring = get_ring('account')
 
189
        container_ring = get_ring('container')
 
190
        object_ring = get_ring('object')
139
191
        port2server = {}
140
192
        config_dict = {}
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:
158
207
        try:
159
208
            raise
 
209
        except AssertionError, e:
 
210
            print >>sys.stderr, 'ERROR: %s' % e
 
211
            os._exit(1)
160
212
        finally:
161
213
            try:
162
214
                kill_servers(port2server, pids)
202
254
                'once']))
203
255
    for process in processes:
204
256
        process.wait()
 
257
 
 
258
 
 
259
if __name__ == "__main__":
 
260
    for server in ('account', 'container', 'object'):
 
261
        get_ring(server, force_validate=True)
 
262
        print '%s OK' % server