def testRetryOn502SucceedsEventually(self): """ CLIENTS (BASECLIENT): Ensure client retries on 502 error codes""" invocations = [] class FailTwiceWith502(MockServer.Handler): def do_GET(self, invocations=invocations): invocations.append(self.path) if len(invocations) <= 2: self.send_code_and_message(502, {}, '') else: self.send_code_and_message( 200, {'x-rucio-auth-token': 'sometoken'}, '') start_time = datetime.utcnow() with MockServer(FailTwiceWith502) as server: creds = {'username': '******', 'password': '******'} del invocations[:] client = BaseClient(rucio_host=server.base_url, auth_host=server.base_url, account='root', auth_type='userpass', creds=creds, **self.vo) del invocations[:] client._send_request(server.base_url) # noqa # The client did back-off multiple times before succeeding: 2 * 0.25s (authentication) + 2 * 0.25s (request) = 1s assert datetime.now() - start_time > timedelta(seconds=0.9)
def testRetryOn502AlwaysFail(self): """ CLIENTS (BASECLIENT): Ensure client retries on 502 error codes, but fails on repeated errors""" class AlwaysFailWith502(MockServer.Handler): def do_GET(self): self.send_code_and_message(502, {}, '') with MockServer(AlwaysFailWith502) as server: with pytest.raises(CannotAuthenticate): creds = {'username': '******', 'password': '******'} BaseClient(rucio_host=server.base_url, auth_host=server.base_url, account='root', auth_type='userpass', creds=creds, **self.vo) with pytest.raises(RucioException): creds = { 'client_cert': self.usercert, 'client_key': self.userkey } BaseClient(rucio_host=server.base_url, auth_host=server.base_url, account='root', ca_cert=self.cacert, auth_type='x509', creds=creds, **self.vo)
def setup(self): self.did_client = DIDClient() self.replica_client = ReplicaClient() self.base_client = BaseClient(account='root', ca_cert=config_get('client', 'ca_cert'), auth_type='x509') self.token = self.base_client.headers['X-Rucio-Auth-Token'] self.fname = generate_uuid() rses = ['MOCK', 'MOCK3', 'MOCK4'] dsn = generate_uuid() self.files = [{ 'scope': 'mock', 'name': self.fname, 'bytes': 1, 'adler32': '0cc737eb' }] self.did_client.add_dataset(scope='mock', name=dsn) self.did_client.add_files_to_dataset('mock', name=dsn, files=self.files, rse='MOCK') for r in rses: self.replica_client.add_replicas(r, self.files)
def testx509NonExistingCert(self): """ CLIENTS (BASECLIENT): authenticate with x509 with missing certificate.""" creds = {'client_cert': '/opt/rucio/etc/web/notthere.crt'} BaseClient(account='root', ca_cert=self.cacert, auth_type='x509', creds=creds)
def testx509(self): """ CLIENTS (BASECLIENT): authenticate with x509.""" creds = {'client_cert': self.usercert} BaseClient(account='root', ca_cert=self.cacert, auth_type='x509', creds=creds)
def testUserpassWrongCreds(self): """ CLIENTS (BASECLIENT): try to authenticate with wrong username.""" creds = {'username': '******', 'password': '******'} BaseClient(account='root', ca_cert=self.cacert, auth_type='userpass', creds=creds)
def testUserpass(self): """ CLIENTS (BASECLIENT): authenticate with userpass.""" creds = {'username': '******', 'password': '******'} BaseClient(account='root', ca_cert=self.cacert, auth_type='userpass', creds=creds)
def testUserpassNoCACert(self): """ CLIENTS (BASECLIENT): authenticate with userpass without ca cert.""" creds = {'username': '******', 'password': '******'} BaseClient(account='root', auth_type='userpass', creds=creds, **self.vo)
def testClientProtocolNotSupported(self): """ CLIENTS (BASECLIENT): try to pass an host with a not supported protocol.""" creds = {'username': '******', 'password': '******'} BaseClient(rucio_host='localhost', auth_host='junk://localhost', account='root', auth_type='userpass', creds=creds)
def __init__(self): self.cacert = config_get('test', 'cacert') self.host = config_get('client', 'rucio_host') self.auth_host = config_get('client', 'auth_host') self.base_client = BaseClient() self.token = self.base_client.headers['X-Rucio-Auth-Token'] self.replica_client = ReplicaClient()
def setUp(self): if config_get_bool('common', 'multi_vo', raise_exception=False, default=False): self.vo_header = '-H "X-Rucio-VO: %s"' % config_get('client', 'vo', raise_exception=False, default='tst') else: self.vo_header = '' self.cacert = config_get('test', 'cacert') self.host = config_get('client', 'rucio_host') self.auth_host = config_get('client', 'auth_host') self.base_client = BaseClient() self.token = self.base_client.headers['X-Rucio-Auth-Token'] self.replica_client = ReplicaClient()