Ejemplo n.º 1
0
 def run(self):
     Bench.run(self)
     for container in self.containers:
         try:
             client.delete_container(self.url, self.token, container)
         except client.ClientException, e:
             if e.http_status != HTTP_CONFLICT:
                 self._log_status("Unable to delete container '%s'. " \
                     "Got http status '%d'." % (container, e.http_status))
Ejemplo n.º 2
0
 def run(self):
     Bench.run(self)
     for container in self.containers:
         try:
             client.delete_container(self.url, self.token, container)
         except client.ClientException, e:
             if e.http_status != 409:
                 self._log_status("Unable to delete container '%s'. " \
                     "Got http status '%d'." % (container, e.http_status))
Ejemplo n.º 3
0
    def test_first_two_nodes_fail(self):
        container = 'container-%s' % uuid4()
        client.put_container(self.url, self.token, container)
        self.assert_(
            container in
            [c['name'] for c in client.get_account(self.url, self.token)[1]])

        object1 = 'object1'
        client.put_object(self.url, self.token, container, object1, 'test')
        self.assert_(
            container in
            [c['name'] for c in client.get_account(self.url, self.token)[1]])
        self.assert_(object1 in [
            o['name']
            for o in client.get_container(self.url, self.token, container)[1]
        ])

        cpart, cnodes = self.container_ring.get_nodes(self.account, container)
        for x in xrange(2):
            kill(self.pids[self.port2server[cnodes[x]['port']]], SIGTERM)

        client.delete_object(self.url, self.token, container, object1)
        self.assert_(
            container in
            [c['name'] for c in client.get_account(self.url, self.token)[1]])
        self.assert_(object1 not in [
            o['name']
            for o in client.get_container(self.url, self.token, container)[1]
        ])

        for x in xrange(2):
            self.pids[self.port2server[cnodes[x]['port']]] = \
                Popen(['swift-container-server',
                       '/etc/swift/container-server/%d.conf' %
                        ((cnodes[x]['port'] - 6001) / 10)]).pid
        sleep(2)
        self.assert_(
            container in
            [c['name'] for c in client.get_account(self.url, self.token)[1]])
        # This okay because the first node hasn't got the update that the
        # object was deleted yet.
        self.assert_(object1 in [
            o['name'] for o in direct_client.direct_get_container(
                cnodes[0], cpart, self.account, container)[1]
        ])

        # This fails because all three nodes have to indicate deletion before
        # we tell the user it worked. Since the first node 409s (it hasn't got
        # the update that the object was deleted yet), the whole must 503
        # (until every is synced up, then the delete would work).
        exc = None
        try:
            client.delete_container(self.url, self.token, container)
        except client.ClientException, err:
            exc = err
Ejemplo n.º 4
0
 def run_test(num_locks, catch_503):
     container = 'container-%s' % uuid4()
     client.put_container(self.url, self.token, container)
     db_files = self._get_container_db_files(container)
     db_conns = []
     for i in range(num_locks):
         db_conn = sqlite3.connect(db_files[i])
         db_conn.execute('begin exclusive transaction')
         db_conns.append(db_conn)
     if catch_503:
         try:
             client.delete_container(self.url, self.token, container)
         except client.ClientException, e:
             self.assertEquals(e.http_status, 503)
 def run_test(num_locks, catch_503):
     container = 'container-%s' % uuid4()
     client.put_container(self.url, self.token, container)
     db_files = self._get_container_db_files(container)
     db_conns = []
     for i in range(num_locks):
         db_conn = sqlite3.connect(db_files[i])
         db_conn.execute('begin exclusive transaction')
         db_conns.append(db_conn)
     if catch_503:
         try:
             client.delete_container(self.url, self.token, container)
         except client.ClientException, e:
             self.assertEquals(e.http_status, 503)
    def test_first_two_nodes_fail(self):
        container = 'container-%s' % uuid4()
        client.put_container(self.url, self.token, container)
        self.assert_(container in [c['name'] for c in
                     client.get_account(self.url, self.token)[1]])

        object1 = 'object1'
        client.put_object(self.url, self.token, container, object1, 'test')
        self.assert_(container in [c['name'] for c in
                     client.get_account(self.url, self.token)[1]])
        self.assert_(object1 in [o['name'] for o in
                     client.get_container(self.url, self.token, container)[1]])

        cpart, cnodes = self.container_ring.get_nodes(self.account, container)
        for x in xrange(2):
            kill(self.pids[self.port2server[cnodes[x]['port']]], SIGTERM)

        client.delete_object(self.url, self.token, container, object1)
        self.assert_(container in [c['name'] for c in
                     client.get_account(self.url, self.token)[1]])
        self.assert_(object1 not in [o['name'] for o in
                     client.get_container(self.url, self.token, container)[1]])

        for x in xrange(2):
            self.pids[self.port2server[cnodes[x]['port']]] = \
                Popen(['swift-container-server',
                       '/etc/swift/container-server/%d.conf' %
                        ((cnodes[x]['port'] - 6001) / 10)]).pid
        sleep(2)
        self.assert_(container in [c['name'] for c in
                     client.get_account(self.url, self.token)[1]])
        # This okay because the first node hasn't got the update that the
        # object was deleted yet.
        self.assert_(object1 in [o['name'] for o in
                     direct_client.direct_get_container(cnodes[0], cpart,
                     self.account, container)[1]])

        # This fails because all three nodes have to indicate deletion before
        # we tell the user it worked. Since the first node 409s (it hasn't got
        # the update that the object was deleted yet), the whole must 503
        # (until every is synced up, then the delete would work).
        exc = None
        try:
            client.delete_container(self.url, self.token, container)
        except client.ClientException, err:
            exc = err
Ejemplo n.º 7
0
        def run_test(num_locks, catch_503):
            container = 'container-%s' % uuid4()
            client.put_container(self.url, self.token, container)
            db_files = self._get_container_db_files(container)
            db_conns = []
            for i in range(num_locks):
                db_conn = sqlite3.connect(db_files[i])
                db_conn.execute('begin exclusive transaction')
                db_conns.append(db_conn)
            if catch_503:
                try:
                    client.delete_container(self.url, self.token, container)
                except client.ClientException, e:
                    self.assertEquals(e.http_status, 503)
            else:
                client.delete_container(self.url, self.token, container)

        pool = eventlet.GreenPool()
        try:
            with eventlet.Timeout(15):
                p = pool.spawn(run_test, 1, False)
                r = pool.spawn(run_test, 2, True)
                q = pool.spawn(run_test, 3, True)
                pool.waitall()
        except eventlet.Timeout, e:
            raise Exception(
                "The server did not return a 503 on container db locks, "
                "it just hangs: %s" % e)


if __name__ == '__main__':
Ejemplo n.º 8
0
 def test_ok(self):
     c.http_connection = self.fake_http_connection(200)
     value = c.delete_container('http://www.test.com', 'asdf', 'asdf')
     self.assertEquals(value, None)
        def run_test(num_locks, catch_503):
            container = 'container-%s' % uuid4()
            client.put_container(self.url, self.token, container)
            db_files = self._get_container_db_files(container)
            db_conns = []
            for i in range(num_locks):
                db_conn = sqlite3.connect(db_files[i])
                db_conn.execute('begin exclusive transaction')
                db_conns.append(db_conn)
            if catch_503:
                try:
                    client.delete_container(self.url, self.token, container)
                except client.ClientException, e:
                    self.assertEquals(e.http_status, 503)
            else:
                client.delete_container(self.url, self.token, container)

        pool = eventlet.GreenPool()
        try:
            with eventlet.Timeout(15):
                p = pool.spawn(run_test, 1, False)
                r = pool.spawn(run_test, 2, True)
                q = pool.spawn(run_test, 3, True)
                pool.waitall()
        except eventlet.Timeout, e:
            raise Exception(
                "The server did not return a 503 on container db locks, "
                "it just hangs: %s" % e)


if __name__ == '__main__':
Ejemplo n.º 10
0
    def test_main(self):
        container1 = 'container1'
        client.put_container(self.url, self.token, container1)
        container2 = 'container2'
        client.put_container(self.url, self.token, container2)
        headers, containers = client.get_account(self.url, self.token)
        self.assertEquals(headers['x-account-container-count'], '2')
        self.assertEquals(headers['x-account-object-count'], '0')
        self.assertEquals(headers['x-account-bytes-used'], '0')
        found1 = False
        found2 = False
        for c in containers:
            if c['name'] == container1:
                found1 = True
                self.assertEquals(c['count'], 0)
                self.assertEquals(c['bytes'], 0)
            elif c['name'] == container2:
                found2 = True
                self.assertEquals(c['count'], 0)
                self.assertEquals(c['bytes'], 0)
        self.assert_(found1)
        self.assert_(found2)

        client.put_object(self.url, self.token, container2, 'object1', '1234')
        headers, containers = client.get_account(self.url, self.token)
        self.assertEquals(headers['x-account-container-count'], '2')
        self.assertEquals(headers['x-account-object-count'], '0')
        self.assertEquals(headers['x-account-bytes-used'], '0')
        found1 = False
        found2 = False
        for c in containers:
            if c['name'] == container1:
                found1 = True
                self.assertEquals(c['count'], 0)
                self.assertEquals(c['bytes'], 0)
            elif c['name'] == container2:
                found2 = True
                self.assertEquals(c['count'], 0)
                self.assertEquals(c['bytes'], 0)
        self.assert_(found1)
        self.assert_(found2)

        get_to_final_state()
        headers, containers = client.get_account(self.url, self.token)
        self.assertEquals(headers['x-account-container-count'], '2')
        self.assertEquals(headers['x-account-object-count'], '1')
        self.assertEquals(headers['x-account-bytes-used'], '4')
        found1 = False
        found2 = False
        for c in containers:
            if c['name'] == container1:
                found1 = True
                self.assertEquals(c['count'], 0)
                self.assertEquals(c['bytes'], 0)
            elif c['name'] == container2:
                found2 = True
                self.assertEquals(c['count'], 1)
                self.assertEquals(c['bytes'], 4)
        self.assert_(found1)
        self.assert_(found2)

        apart, anodes = self.account_ring.get_nodes(self.account)
        kill(self.pids[self.port2server[anodes[0]['port']]], SIGTERM)

        client.delete_container(self.url, self.token, container1)
        client.put_object(self.url, self.token, container2, 'object2', '12345')
        headers, containers = client.get_account(self.url, self.token)
        self.assertEquals(headers['x-account-container-count'], '1')
        self.assertEquals(headers['x-account-object-count'], '1')
        self.assertEquals(headers['x-account-bytes-used'], '4')
        found1 = False
        found2 = False
        for c in containers:
            if c['name'] == container1:
                found1 = True
            elif c['name'] == container2:
                found2 = True
                self.assertEquals(c['count'], 1)
                self.assertEquals(c['bytes'], 4)
        self.assert_(not found1)
        self.assert_(found2)

        ps = []
        for n in xrange(1, 5):
            ps.append(
                Popen([
                    'swift-container-updater',
                    '/etc/swift/container-server/%d.conf' % n, 'once'
                ]))
        for p in ps:
            p.wait()
        headers, containers = client.get_account(self.url, self.token)
        self.assertEquals(headers['x-account-container-count'], '1')
        self.assertEquals(headers['x-account-object-count'], '2')
        self.assertEquals(headers['x-account-bytes-used'], '9')
        found1 = False
        found2 = False
        for c in containers:
            if c['name'] == container1:
                found1 = True
            elif c['name'] == container2:
                found2 = True
                self.assertEquals(c['count'], 2)
                self.assertEquals(c['bytes'], 9)
        self.assert_(not found1)
        self.assert_(found2)

        self.pids[self.port2server[anodes[0]['port']]] = \
            Popen(['swift-account-server',
                   '/etc/swift/account-server/%d.conf' %
                    ((anodes[0]['port'] - 6002) / 10)]).pid
        sleep(2)
        # This is the earlier counts and bytes because the first node doesn't
        # have the newest udpates yet.
        headers, containers = \
            direct_client.direct_get_account(anodes[0], apart, self.account)
        self.assertEquals(headers['x-account-container-count'], '2')
        self.assertEquals(headers['x-account-object-count'], '1')
        self.assertEquals(headers['x-account-bytes-used'], '4')
        found1 = False
        found2 = False
        for c in containers:
            if c['name'] == container1:
                found1 = True
            elif c['name'] == container2:
                found2 = True
                # This is the earlier count and bytes because the first node
                # doesn't have the newest udpates yet.
                self.assertEquals(c['count'], 1)
                self.assertEquals(c['bytes'], 4)
        # This okay because the first node hasn't got the update that
        # container1 was deleted yet.
        self.assert_(found1)
        self.assert_(found2)

        get_to_final_state()
        headers, containers = \
            direct_client.direct_get_account(anodes[0], apart, self.account)
        self.assertEquals(headers['x-account-container-count'], '1')
        self.assertEquals(headers['x-account-object-count'], '2')
        self.assertEquals(headers['x-account-bytes-used'], '9')
        found1 = False
        found2 = False
        for c in containers:
            if c['name'] == container1:
                found1 = True
            elif c['name'] == container2:
                found2 = True
                self.assertEquals(c['count'], 2)
                self.assertEquals(c['bytes'], 9)
        self.assert_(not found1)
        self.assert_(found2)
Ejemplo n.º 11
0
 def test_ok(self):
     c.http_connection = self.fake_http_connection(200)
     value = c.delete_container('http://www.test.com', 'asdf', 'asdf')
     self.assertEquals(value, None)
    def test_main(self):
        container1 = 'container1'
        client.put_container(self.url, self.token, container1)
        container2 = 'container2'
        client.put_container(self.url, self.token, container2)
        headers, containers = client.get_account(self.url, self.token)
        self.assertEquals(headers['x-account-container-count'], '2')
        self.assertEquals(headers['x-account-object-count'], '0')
        self.assertEquals(headers['x-account-bytes-used'], '0')
        found1 = False
        found2 = False
        for c in containers:
            if c['name'] == container1:
                found1 = True
                self.assertEquals(c['count'], 0)
                self.assertEquals(c['bytes'], 0)
            elif c['name'] == container2:
                found2 = True
                self.assertEquals(c['count'], 0)
                self.assertEquals(c['bytes'], 0)
        self.assert_(found1)
        self.assert_(found2)

        client.put_object(self.url, self.token, container2, 'object1', '1234')
        headers, containers = client.get_account(self.url, self.token)
        self.assertEquals(headers['x-account-container-count'], '2')
        self.assertEquals(headers['x-account-object-count'], '0')
        self.assertEquals(headers['x-account-bytes-used'], '0')
        found1 = False
        found2 = False
        for c in containers:
            if c['name'] == container1:
                found1 = True
                self.assertEquals(c['count'], 0)
                self.assertEquals(c['bytes'], 0)
            elif c['name'] == container2:
                found2 = True
                self.assertEquals(c['count'], 0)
                self.assertEquals(c['bytes'], 0)
        self.assert_(found1)
        self.assert_(found2)

        get_to_final_state()
        headers, containers = client.get_account(self.url, self.token)
        self.assertEquals(headers['x-account-container-count'], '2')
        self.assertEquals(headers['x-account-object-count'], '1')
        self.assertEquals(headers['x-account-bytes-used'], '4')
        found1 = False
        found2 = False
        for c in containers:
            if c['name'] == container1:
                found1 = True
                self.assertEquals(c['count'], 0)
                self.assertEquals(c['bytes'], 0)
            elif c['name'] == container2:
                found2 = True
                self.assertEquals(c['count'], 1)
                self.assertEquals(c['bytes'], 4)
        self.assert_(found1)
        self.assert_(found2)

        apart, anodes = self.account_ring.get_nodes(self.account)
        kill(self.pids[self.port2server[anodes[0]['port']]], SIGTERM)

        client.delete_container(self.url, self.token, container1)
        client.put_object(self.url, self.token, container2, 'object2', '12345')
        headers, containers = client.get_account(self.url, self.token)
        self.assertEquals(headers['x-account-container-count'], '1')
        self.assertEquals(headers['x-account-object-count'], '1')
        self.assertEquals(headers['x-account-bytes-used'], '4')
        found1 = False
        found2 = False
        for c in containers:
            if c['name'] == container1:
                found1 = True
            elif c['name'] == container2:
                found2 = True
                self.assertEquals(c['count'], 1)
                self.assertEquals(c['bytes'], 4)
        self.assert_(not found1)
        self.assert_(found2)

        ps = []
        for n in xrange(1, 5):
            ps.append(Popen(['swift-container-updater',
                             '/etc/swift/container-server/%d.conf' % n,
                             'once']))
        for p in ps:
            p.wait()
        headers, containers = client.get_account(self.url, self.token)
        self.assertEquals(headers['x-account-container-count'], '1')
        self.assertEquals(headers['x-account-object-count'], '2')
        self.assertEquals(headers['x-account-bytes-used'], '9')
        found1 = False
        found2 = False
        for c in containers:
            if c['name'] == container1:
                found1 = True
            elif c['name'] == container2:
                found2 = True
                self.assertEquals(c['count'], 2)
                self.assertEquals(c['bytes'], 9)
        self.assert_(not found1)
        self.assert_(found2)

        self.pids[self.port2server[anodes[0]['port']]] = \
            Popen(['swift-account-server',
                   '/etc/swift/account-server/%d.conf' %
                    ((anodes[0]['port'] - 6002) / 10)]).pid
        sleep(2)
        # This is the earlier counts and bytes because the first node doesn't
        # have the newest udpates yet.
        headers, containers = \
            direct_client.direct_get_account(anodes[0], apart, self.account)
        self.assertEquals(headers['x-account-container-count'], '2')
        self.assertEquals(headers['x-account-object-count'], '1')
        self.assertEquals(headers['x-account-bytes-used'], '4')
        found1 = False
        found2 = False
        for c in containers:
            if c['name'] == container1:
                found1 = True
            elif c['name'] == container2:
                found2 = True
                # This is the earlier count and bytes because the first node
                # doesn't have the newest udpates yet.
                self.assertEquals(c['count'], 1)
                self.assertEquals(c['bytes'], 4)
        # This okay because the first node hasn't got the update that
        # container1 was deleted yet.
        self.assert_(found1)
        self.assert_(found2)

        get_to_final_state()
        headers, containers = \
            direct_client.direct_get_account(anodes[0], apart, self.account)
        self.assertEquals(headers['x-account-container-count'], '1')
        self.assertEquals(headers['x-account-object-count'], '2')
        self.assertEquals(headers['x-account-bytes-used'], '9')
        found1 = False
        found2 = False
        for c in containers:
            if c['name'] == container1:
                found1 = True
            elif c['name'] == container2:
                found2 = True
                self.assertEquals(c['count'], 2)
                self.assertEquals(c['bytes'], 9)
        self.assert_(not found1)
        self.assert_(found2)
Ejemplo n.º 13
0
def operation(request):
    """对swift的后台操作,ajax调用"""
    q = request.GET.get('q','')
    name = request.GET.get('name','')
    if q=='cc':#创建container
        try:
            client.put_container(utils.auth_url, utils.auth_token, name)
        except client.ClientException:
            return HttpResponse('failure')
    elif q=='dc': #删除container
        try:
            client.delete_container(utils.auth_url, utils.auth_token, name)
        except client.ClientException:
            return HttpResponse('failure')
    elif q=='lo': #列出container中的object
        try:
            object_list = utils.get_object_list(name)
            name_list = '^'.join([obj.get_name() for obj in object_list])
            time_list = '^'.join([obj.get_last_modified() for obj in object_list])
            size_list = '^'.join([str(obj.get_size()) for obj in object_list])
            obj_list = '\n'.join([name_list,time_list,size_list])
            return HttpResponse(obj_list)
        except client.ClientException:
            return HttpResponse('failure')
    elif q=='do': #删除object
        objs = name.split('^')
        container_name = objs[-1:][0]
        objs = objs[:-1]
        for obj in objs:
            try:
                client.delete_object(utils.auth_url,utils.auth_token,
                        container_name, obj)
            except client.ClientException:
                return HttpResponse('failure')
        client.put_container(utils.auth_url,utils.auth_token,
                container_name)
    elif q=='dl': #下载object
        objs = name.split('^')
        container_name = objs[-1:][0]
        objs = objs[:-1]
        if len(objs)==1:
            response = utils.download_single_file(container_name, objs[0])
            return response
    elif q=='ic':#查询container信息
        try:
            result = client.get_container(utils.auth_url,utils.auth_token,
                    name)[0].get('x-container-read','')
            if result:
                result = utils.auth_url+'/'
            return HttpResponse(result)
        except client.ClientException:
            return HttpResponse('failure')
    elif q=='sc':#共享container
        try:
            client.post_container(utils.auth_url,utils.auth_token,
                    name,headers={'X-Container-Read':'.r:*'})
            return HttpResponse(utils.auth_url+'/')
        except client.ClientException:
            return HttpResponse('failure')
    elif q=='pc':#使container变为私有
        try:
            client.post_container(utils.auth_url,utils.auth_token,
                    name,headers={'X-Container-Read':''})
            return HttpResponse('success')
        except client.ClientException:
            return HttpResponse('failure')
    return HttpResponse('success')
Ejemplo n.º 14
0
def operation(request):
    """对swift的后台操作,ajax调用"""
    q = request.GET.get('q', '')
    name = request.GET.get('name', '')
    if q == 'cc':  #创建container
        try:
            client.put_container(utils.auth_url, utils.auth_token, name)
        except client.ClientException:
            return HttpResponse('failure')
    elif q == 'dc':  #删除container
        try:
            client.delete_container(utils.auth_url, utils.auth_token, name)
        except client.ClientException:
            return HttpResponse('failure')
    elif q == 'lo':  #列出container中的object
        try:
            object_list = utils.get_object_list(name)
            name_list = '^'.join([obj.get_name() for obj in object_list])
            time_list = '^'.join(
                [obj.get_last_modified() for obj in object_list])
            size_list = '^'.join([str(obj.get_size()) for obj in object_list])
            obj_list = '\n'.join([name_list, time_list, size_list])
            return HttpResponse(obj_list)
        except client.ClientException:
            return HttpResponse('failure')
    elif q == 'do':  #删除object
        objs = name.split('^')
        container_name = objs[-1:][0]
        objs = objs[:-1]
        for obj in objs:
            try:
                client.delete_object(utils.auth_url, utils.auth_token,
                                     container_name, obj)
            except client.ClientException:
                return HttpResponse('failure')
        client.put_container(utils.auth_url, utils.auth_token, container_name)
    elif q == 'dl':  #下载object
        objs = name.split('^')
        container_name = objs[-1:][0]
        objs = objs[:-1]
        if len(objs) == 1:
            response = utils.download_single_file(container_name, objs[0])
            return response
    elif q == 'ic':  #查询container信息
        try:
            result = client.get_container(utils.auth_url, utils.auth_token,
                                          name)[0].get('x-container-read', '')
            if result:
                result = utils.auth_url + '/'
            return HttpResponse(result)
        except client.ClientException:
            return HttpResponse('failure')
    elif q == 'sc':  #共享container
        try:
            client.post_container(utils.auth_url,
                                  utils.auth_token,
                                  name,
                                  headers={'X-Container-Read': '.r:*'})
            return HttpResponse(utils.auth_url + '/')
        except client.ClientException:
            return HttpResponse('failure')
    elif q == 'pc':  #使container变为私有
        try:
            client.post_container(utils.auth_url,
                                  utils.auth_token,
                                  name,
                                  headers={'X-Container-Read': ''})
            return HttpResponse('success')
        except client.ClientException:
            return HttpResponse('failure')
    return HttpResponse('success')