コード例 #1
0
ファイル: common.py プロジェクト: isabella232/swift-2
def reset_environment():
    call(['resetswift'])
    pids = {}
    try:
        port2server = {}
        for s, p in (('account', 6002), ('container', 6001), ('object', 6000)):
            for n in xrange(1, 5):
                pids['%s%d' % (s, n)] = \
                    Popen(['swift-%s-server' % s,
                           '/etc/swift/%s-server/%d.conf' % (s, n)]).pid
                port2server[p + (n * 10)] = '%s%d' % (s, n)
        pids['proxy'] = Popen(
            ['swift-proxy-server', '/etc/swift/proxy-server.conf']).pid
        account_ring = Ring('/etc/swift/account.ring.gz')
        container_ring = Ring('/etc/swift/container.ring.gz')
        object_ring = Ring('/etc/swift/object.ring.gz')
        attempt = 0
        while True:
            attempt += 1
            try:
                url, token = get_auth('http://127.0.0.1:8080/auth/v1.0',
                                      'test:tester', 'testing')
                account = url.split('/')[-1]
                break
            except Exception, err:
                if attempt > 9:
                    print err
                    print 'Giving up after %s retries.' % attempt
                    raise err
                print err
                print 'Retrying in 2 seconds...'
                sleep(2)
    except BaseException, err:
        kill_pids(pids)
        raise err
コード例 #2
0
def reset_environment():
    call(['resetswift'])
    pids = {}
    try:
        port2server = {}
        for s, p in (('account', 6002), ('container', 6001), ('object', 6000)):
            for n in xrange(1, 5):
                pids['%s%d' % (s, n)] = \
                    Popen(['swift-%s-server' % s,
                           '/etc/swift/%s-server/%d.conf' % (s, n)]).pid
                port2server[p + (n * 10)] = '%s%d' % (s, n)
        pids['proxy'] = Popen(['swift-proxy-server',
                               '/etc/swift/proxy-server.conf']).pid
        account_ring = Ring('/etc/swift/account.ring.gz')
        container_ring = Ring('/etc/swift/container.ring.gz')
        object_ring = Ring('/etc/swift/object.ring.gz')
        attempt = 0
        while True:
            attempt += 1
            try:
                url, token = get_auth('http://127.0.0.1:8080/auth/v1.0',
                                      'test:tester', 'testing')
                account = url.split('/')[-1]
                break
            except Exception, err:
                if attempt > 9:
                    print err
                    print 'Giving up after %s retries.' % attempt
                    raise err
                print err
                print 'Retrying in 2 seconds...'
                sleep(2)
    except BaseException, err:
        kill_pids(pids)
        raise err
コード例 #3
0
ファイル: common.py プロジェクト: zuiwufenghua/zft
def reset_environment():
    call(['resetswift'])
    pids = {}
    try:
        if AUTH_TYPE == 'devauth':
            pids['auth'] = Popen(
                ['swift-auth-server', '/etc/swift/auth-server.conf']).pid
        pids['proxy'] = Popen(
            ['swift-proxy-server', '/etc/swift/proxy-server.conf']).pid
        port2server = {}
        for s, p in (('account', 6002), ('container', 6001), ('object', 6000)):
            for n in xrange(1, 5):
                pids['%s%d' % (s, n)] = \
                    Popen(['swift-%s-server' % s,
                           '/etc/swift/%s-server/%d.conf' % (s, n)]).pid
                port2server[p + (n * 10)] = '%s%d' % (s, n)
        account_ring = Ring('/etc/swift/account.ring.gz')
        container_ring = Ring('/etc/swift/container.ring.gz')
        object_ring = Ring('/etc/swift/object.ring.gz')
        sleep(5)
        if AUTH_TYPE == 'devauth':
            conn = http_connect('127.0.0.1',
                                '11000',
                                'POST',
                                '/recreate_accounts',
                                headers={
                                    'X-Auth-Admin-User': '******',
                                    'X-Auth-Admin-Key': SUPER_ADMIN_KEY
                                })
            resp = conn.getresponse()
            if resp.status != 200:
                raise Exception('Recreating accounts failed. (%d)' %
                                resp.status)
            url, token = get_auth('http://127.0.0.1:11000/auth', 'test:tester',
                                  'testing')
        elif AUTH_TYPE == 'swauth':
            call(['recreateaccounts'])
            url, token = get_auth('http://127.0.0.1:8080/auth/v1.0',
                                  'test:tester', 'testing')
        account = url.split('/')[-1]
    except BaseException, err:
        kill_pids(pids)
        raise err
コード例 #4
0
ファイル: common.py プロジェクト: edwardt/swift
def reset_environment():
    call(['resetswift'])
    pids = {}
    try:
        if AUTH_TYPE == 'devauth':
            pids['auth'] = Popen(['swift-auth-server',
                                  '/etc/swift/auth-server.conf']).pid
        pids['proxy'] = Popen(['swift-proxy-server',
                               '/etc/swift/proxy-server.conf']).pid
        port2server = {}
        for s, p in (('account', 6002), ('container', 6001), ('object', 6000)):
            for n in xrange(1, 5):
                pids['%s%d' % (s, n)] = \
                    Popen(['swift-%s-server' % s,
                           '/etc/swift/%s-server/%d.conf' % (s, n)]).pid
                port2server[p + (n * 10)] = '%s%d' % (s, n)
        account_ring = Ring('/etc/swift/account.ring.gz')
        container_ring = Ring('/etc/swift/container.ring.gz')
        object_ring = Ring('/etc/swift/object.ring.gz')
        sleep(5)
        if AUTH_TYPE == 'devauth':
            conn = http_connect('127.0.0.1', '11000', 'POST',
                    '/recreate_accounts',
                    headers={'X-Auth-Admin-User': '******',
                             'X-Auth-Admin-Key': SUPER_ADMIN_KEY})
            resp = conn.getresponse()
            if resp.status != 200:
                raise Exception('Recreating accounts failed. (%d)' %
                                resp.status)
            url, token = get_auth('http://127.0.0.1:11000/auth', 'test:tester',
                                  'testing')
        elif AUTH_TYPE == 'swauth':
            call(['recreateaccounts'])
            url, token = get_auth('http://127.0.0.1:8080/auth/v1.0',
                                  'test:tester', 'testing')
        account = url.split('/')[-1]
    except BaseException, err:
        kill_pids(pids)
        raise err
コード例 #5
0
ファイル: test_client.py プロジェクト: bhuvan/swift
 def test_auth_v2(self):
     def read(*args, **kwargs):
         acct_url = 'http://127.0.01/AUTH_FOO'
         body = {'access': {'serviceCatalog':
                                [{u'endpoints': [{'publicURL': acct_url}],
                                  'type': 'object-store'}],
                            'token': {'id': 'XXXXXXX'}}}
         return c.json_dumps(body)
     c.http_connection = self.fake_http_connection(200, return_read=read)
     url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf',
                             tenant_name='asdf', auth_version="2.0")
     self.assertTrue(url.startswith("http"))
     self.assertTrue(token)
コード例 #6
0
ファイル: test_client.py プロジェクト: pvo/swift
    def test_auth_v2(self):
        def read(*args, **kwargs):
            acct_url = "http://127.0.01/AUTH_FOO"
            body = {
                "access": {
                    "serviceCatalog": [{u"endpoints": [{"publicURL": acct_url}], "type": "object-store"}],
                    "token": {"id": "XXXXXXX"},
                }
            }
            return c.json_dumps(body)

        c.http_connection = self.fake_http_connection(200, return_read=read)
        url, token = c.get_auth("http://www.test.com", "asdf", "asdf", auth_version="2.0")
        self.assertTrue(url.startswith("http"))
        self.assertTrue(token)
コード例 #7
0
ファイル: test_cdmi_object.py プロジェクト: litong01/cdmi
    def setUp(self):
        self.conf = get_config()
        if self.conf.get('auth_ssl', 'no') == 'yes':
            auth_method = 'https://'
        else:
            auth_method = 'http://'
        auth_host = (self.conf.get('auth_host') + ':' +
                     self.conf.get('auth_port'))
        auth_url = (auth_method + auth_host +
                    self.conf.get('auth_prefix') + 'v1.0')
        try:
            rets = get_auth(auth_url, (self.conf.get('account') + ':' +
                                       self.conf.get('username')),
                            self.conf.get('password'))
            self.auth_token = rets[1]
            #Parse the storage root and get the access root for CDMI
            pieces = rets[0].partition('/v1/')
            self.os_access_root = '/v1/' + pieces[2]
            self.access_root = ('/' + self.conf.get('cdmi_root', 'cdmi') +
                                '/' + pieces[2])
            self.cdmi_capability_root = ('/' +
                                         self.conf.get('cdmi_root', 'cdmi') +
                                         '/' +
                                         self.conf.get('cdmi_capability_id',
                                                       'cdmi_capabilities') +
                                         '/' + pieces[2])
            #Setup two container names
            suffix = format(time.time(), '.6f')
            self.top_container = 'cdmi_test_top_container_' + suffix
            self.child_container = 'cdmi_test_child_container_' + suffix
            self.object_create = 'cdmi_test_object_create_' + suffix
            self.object_test = 'cdmi_test_object_' + suffix

            #Create test containers
            self.__create_test_container(self.top_container)
            self.__create_test_container(self.top_container + '/' +
                                         self.child_container)
            self.__create_test_container(self.top_container + '/a/b/c/d/e/f')
            self.__create_test_container(self.top_container + '/a/b/c/d')
            self.__create_test_object(self.top_container + '/' +
                                      self.child_container + '/' +
                                      self.object_test)
            self.__create_test_object(self.top_container + '/a/b/cc')

        except Exception as login_error:
            raise login_error
コード例 #8
0
    def __init__(self, logger, conf, names):
        self.logger = logger
        self.user = conf.user
        self.key = conf.key
        self.auth_url = conf.auth
        self.use_proxy = conf.use_proxy in TRUE_VALUES
        if self.use_proxy:
            url, token = client.get_auth(self.auth_url, self.user, self.key)
            self.token = token
            self.account = url.split('/')[-1]
            if conf.url == '':
                self.url = url
            else:
                self.url = conf.url
        else:
            self.token = 'SlapChop!'
            self.account = conf.account
            self.url = conf.url
            self.ip, self.port = self.url.split('/')[2].split(':')
        self.containers = [
            '%s_%d' % (conf.container_name, i)
            for i in xrange(int(conf.num_containers))
        ]

        self.object_size = int(conf.object_size)
        self.object_sources = conf.object_sources
        self.files = []
        if self.object_sources:
            self.object_sources = self.object_sources.split()
            self.files = [file(f, 'rb').read() for f in self.object_sources]

        self.put_concurrency = int(conf.put_concurrency)
        self.get_concurrency = int(conf.get_concurrency)
        self.del_concurrency = int(conf.del_concurrency)
        self.total_objects = int(conf.num_objects)
        self.total_gets = int(conf.num_gets)
        self.timeout = int(conf.timeout)
        self.devices = conf.devices.split()
        self.names = names
        self.conn_pool = ConnectionPool(
            self.url,
            max(self.put_concurrency, self.get_concurrency,
                self.del_concurrency))
コード例 #9
0
ファイル: bench.py プロジェクト: AsylumCorp/swift
    def __init__(self, logger, conf, names):
        self.logger = logger
        self.user = conf.user
        self.key = conf.key
        self.auth_url = conf.auth
        self.use_proxy = conf.use_proxy.lower() in TRUE_VALUES
        if self.use_proxy:
            url, token = client.get_auth(self.auth_url, self.user, self.key)
            self.token = token
            self.account = url.split('/')[-1]
            if conf.url == '':
                self.url = url
            else:
                self.url = conf.url
        else:
            self.token = 'SlapChop!'
            self.account = conf.account
            self.url = conf.url
            self.ip, self.port = self.url.split('/')[2].split(':')
        self.containers = ['%s_%d' % (conf.container_name, i)
            for i in xrange(int(conf.num_containers))]

        self.object_size = int(conf.object_size)
        self.object_sources = conf.object_sources
        self.files = []
        if self.object_sources:
            self.object_sources = self.object_sources.split()
            self.files = [file(f, 'rb').read() for f in self.object_sources]

        self.put_concurrency = int(conf.put_concurrency)
        self.get_concurrency = int(conf.get_concurrency)
        self.del_concurrency = int(conf.del_concurrency)
        self.total_objects = int(conf.num_objects)
        self.total_gets = int(conf.num_gets)
        self.timeout = int(conf.timeout)
        self.devices = conf.devices.split()
        self.names = names
        self.conn_pool = ConnectionPool(self.url,
            max(self.put_concurrency, self.get_concurrency,
                self.del_concurrency))
コード例 #10
0
ファイル: test_cdmi_container.py プロジェクト: litong01/cdmi
 def setUp(self):
     self.conf = get_config()
     if self.conf.get("auth_ssl", "no") == "yes":
         auth_method = "https://"
     else:
         auth_method = "http://"
     auth_host = self.conf.get("auth_host") + ":" + self.conf.get("auth_port")
     auth_url = auth_method + auth_host + self.conf.get("auth_prefix") + "v1.0"
     try:
         rets = get_auth(
             auth_url, (self.conf.get("account") + ":" + self.conf.get("username")), self.conf.get("password")
         )
         self.auth_token = rets[1]
         # Parse the storage root and get the access root for CDMI
         pieces = rets[0].partition("/v1/")
         self.os_access_root = "/v1/" + pieces[2]
         self.access_root = "/" + self.conf.get("cdmi_root", "cdmi") + "/" + pieces[2]
         self.cdmi_capability_root = (
             "/"
             + self.conf.get("cdmi_root", "cdmi")
             + "/"
             + self.conf.get("cdmi_capability_id", "cdmi_capabilities")
             + "/"
             + pieces[2]
         )
         # Setup two container names
         suffix = format(time.time(), ".6f")
         self.child_container = "cdmi_test_child_container_" + suffix
         self.top_container = "cdmi_test_top_container_" + suffix
         self.child_container_to_create = "cdmi_test_child_container_create_" + suffix
         self.top_container_to_create = "cdmi_test_top_container_create_" + suffix
         self.top_container_to_delete = "cdmi_test_top_container_delete_" + suffix
         # Create test containers
         self.__create_test_container(self.top_container)
         self.__create_test_container(self.top_container + "/" + self.child_container)
         self.__create_test_container(self.top_container_to_delete)
         self.__create_test_container(self.top_container + "/a/b/c/d/e/f")
     except Exception as login_error:
         raise login_error
コード例 #11
0
ファイル: swift_testing.py プロジェクト: zuiwufenghua/zft
def retry(func, *args, **kwargs):
    """
    You can use the kwargs to override the 'retries' (default: 5) and
    'use_account' (default: 1).
    """
    global url, token, parsed, conn
    retries = kwargs.get('retries', 5)
    use_account = 1
    if 'use_account' in kwargs:
        use_account = kwargs['use_account']
        del kwargs['use_account']
    use_account -= 1
    attempts = 0
    backoff = 1
    while attempts <= retries:
        attempts += 1
        try:
            if not url[use_account] or not token[use_account]:
                url[use_account], token[use_account] = \
                    get_auth(swift_test_auth, swift_test_user[use_account],
                             swift_test_key[use_account])
                parsed[use_account] = conn[use_account] = None
            if not parsed[use_account] or not conn[use_account]:
                parsed[use_account], conn[use_account] = \
                    http_connection(url[use_account])
            return func(url[use_account], token[use_account],
                        parsed[use_account], conn[use_account], *args,
                        **kwargs)
        except (socket.error, HTTPException):
            if attempts > retries:
                raise
            parsed[use_account] = conn[use_account] = None
        except AuthError, err:
            url[use_account] = token[use_account] = None
            continue
        except InternalServerError, err:
            pass
コード例 #12
0
ファイル: swift_testing.py プロジェクト: AsylumCorp/swift
def retry(func, *args, **kwargs):
    """
    You can use the kwargs to override the 'retries' (default: 5) and
    'use_account' (default: 1).
    """
    global url, token, parsed, conn
    retries = kwargs.get('retries', 5)
    use_account = 1
    if 'use_account' in kwargs:
        use_account = kwargs['use_account']
        del kwargs['use_account']
    use_account -= 1
    attempts = 0
    backoff = 1
    while attempts <= retries:
        attempts += 1
        try:
            if not url[use_account] or not token[use_account]:
                url[use_account], token[use_account] = \
                    get_auth(swift_test_auth, swift_test_user[use_account],
                             swift_test_key[use_account])
                parsed[use_account] = conn[use_account] = None
            if not parsed[use_account] or not conn[use_account]:
                parsed[use_account], conn[use_account] = \
                    http_connection(url[use_account])
            return func(url[use_account], token[use_account],
                       parsed[use_account], conn[use_account], *args, **kwargs)
        except (socket.error, HTTPException):
            if attempts > retries:
                raise
            parsed[use_account] = conn[use_account] = None
        except AuthError, err:
            url[use_account] = token[use_account] = None
            continue
        except InternalServerError, err:
            pass
コード例 #13
0
def reset_environment():
    call(['resetswift'])
    pids = {}
    try:
        pids['proxy'] = Popen(
            ['swift-proxy-server', '/etc/swift/proxy-server.conf']).pid
        port2server = {}
        for s, p in (('account', 6002), ('container', 6001), ('object', 6000)):
            for n in xrange(1, 5):
                pids['%s%d' % (s, n)] = \
                    Popen(['swift-%s-server' % s,
                           '/etc/swift/%s-server/%d.conf' % (s, n)]).pid
                port2server[p + (n * 10)] = '%s%d' % (s, n)
        account_ring = Ring('/etc/swift/account.ring.gz')
        container_ring = Ring('/etc/swift/container.ring.gz')
        object_ring = Ring('/etc/swift/object.ring.gz')
        sleep(5)
        call(['recreateaccounts'])
        url, token = get_auth('http://127.0.0.1:8080/auth/v1.0', 'test:tester',
                              'testing')
        account = url.split('/')[-1]
    except BaseException, err:
        kill_pids(pids)
        raise err
コード例 #14
0
ファイル: common.py プロジェクト: colecrawford/swift
def reset_environment():
    call(['resetswift'])
    pids = {}
    try:
        pids['proxy'] = Popen(['swift-proxy-server',
                               '/etc/swift/proxy-server.conf']).pid
        port2server = {}
        for s, p in (('account', 6002), ('container', 6001), ('object', 6000)):
            for n in xrange(1, 5):
                pids['%s%d' % (s, n)] = \
                    Popen(['swift-%s-server' % s,
                           '/etc/swift/%s-server/%d.conf' % (s, n)]).pid
                port2server[p + (n * 10)] = '%s%d' % (s, n)
        account_ring = Ring('/etc/swift/account.ring.gz')
        container_ring = Ring('/etc/swift/container.ring.gz')
        object_ring = Ring('/etc/swift/object.ring.gz')
        sleep(5)
        call(['recreateaccounts'])
        url, token = get_auth('http://127.0.0.1:8080/auth/v1.0',
                              'test:tester', 'testing')
        account = url.split('/')[-1]
    except BaseException, err:
        kill_pids(pids)
        raise err
コード例 #15
0
ファイル: test_client.py プロジェクト: OpenStack-Kha/swift
 def test_ok(self):
     c.http_connection = self.fake_http_connection(200)
     url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf')
     self.assertEquals(url, None)
     self.assertEquals(token, None)
コード例 #16
0
ファイル: rgwauthAPI.py プロジェクト: pacasrc/rgwauthAPI
 def _authSwift(self):
     # radosgw only support auth version 1.0
     return swiftClient.get_auth(self.authUrl, "%s:%s" % (self.uid, self.subuser)
             , self.secretKey.replace('\\',''), auth_version="1.0")
コード例 #17
0
ファイル: test_client.py プロジェクト: pvo/swift
 def test_ok(self):
     c.http_connection = self.fake_http_connection(200)
     url, token = c.get_auth("http://www.test.com", "asdf", "asdf")
     self.assertEquals(url, None)
     self.assertEquals(token, None)
コード例 #18
0
ファイル: test_client.py プロジェクト: bhuvan/swift
 def test_auth_v1(self):
     c.http_connection = self.fake_http_connection(200)
     url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf',
                             auth_version="1.0")
     self.assertEquals(url, None)
     self.assertEquals(token, None)