本文整理汇总了Python中fts3rest.lib.base.Session类的典型用法代码示例。如果您正苦于以下问题:Python Session类的具体用法?Python Session怎么用?Python Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_retries
def test_get_retries(self):
"""
Get the retries for a file, forcing one
"""
self.setup_gridsite_environment()
self.push_delegation()
job_id = self._submit()
answer = self.app.get(url="/jobs/%s/files" % job_id, status=200)
files = json.loads(answer.body)
file_id = files[0]['file_id']
retry = FileRetryLog()
retry.file_id = file_id
retry.attempt = 1
retry.datetime = datetime.utcnow()
retry.reason = 'Blahblahblah'
Session.merge(retry)
Session.commit()
answer = self.app.get(url="/jobs/%s/files/%d/retries" % (job_id, file_id), status=200)
retries = json.loads(answer.body)
self.assertEqual(1, len(retries))
self.assertEqual(1, retries[0]['attempt'])
self.assertEqual('Blahblahblah', retries[0]['reason'])
示例2: test_set_voms
def test_set_voms(self):
"""
The server must regenerate a proxy with VOMS extensions
Need a real proxy for this one
"""
self.setup_gridsite_environment()
creds = self.get_user_credentials()
# Need to push a real proxy :/
proxy_pem = self.get_real_x509_proxy()
if proxy_pem is None:
raise SkipTest('Could not get a valid real proxy for test_set_voms')
proxy = Credential()
proxy.dn = creds.user_dn
proxy.dlg_id = creds.delegation_id
proxy.termination_time = datetime.utcnow() + timedelta(hours=1)
proxy.proxy = proxy_pem
Session.merge(proxy)
Session.commit()
# Now, request the voms extensions
self.app.post(url="/delegation/%s/voms" % creds.delegation_id,
content_type='application/json',
params=json.dumps(['dteam:/dteam/Role=lcgadmin']),
status=203)
# And validate
proxy2 = Session.query(Credential).get((creds.delegation_id, creds.user_dn))
self.assertNotEqual(proxy.proxy, proxy2.proxy)
self.assertEqual('dteam:/dteam/Role=lcgadmin', proxy2.voms_attrs)
示例3: get_my_apps
def get_my_apps(self):
"""
Returns the list of registered apps
"""
user = pylons.request.environ['fts3.User.Credentials']
my_apps = Session.query(OAuth2Application).filter(OAuth2Application.owner == user.user_dn).all()
authorized_apps = Session.query(
OAuth2Application.client_id, OAuth2Application.name, OAuth2Application.website,
OAuth2Application.description, OAuth2Token.refresh_token, OAuth2Token.scope, OAuth2Token.expires
).filter((OAuth2Token.dlg_id == user.delegation_id) & (OAuth2Token.client_id == OAuth2Application.client_id))
response = {'apps': my_apps, 'authorized': authorized_apps}
if _accept_html(pylons.request.accept):
pylons.response.headers['Content-Type'] = 'text/html; charset=UTF-8'
response['user'] = user
response['site'] = pylons.config['fts3.SiteName']
return render('/apps.html', extra_vars=response)
else:
pylons.response.headers['Content-Type'] = 'application/json'
# Better serialization for authorized apps
authorized = list()
for auth in authorized_apps:
authorized.append({
'name': auth.name,
'website': auth.website,
'description': auth.description,
'scope': auth.scope,
'expires': auth.expires
})
response['authorized'] = authorized
return to_json(response)
示例4: test_expired
def test_expired(self):
"""
Get a token, the token expires, so it should be denied
"""
client_id, access_token, refresh_token, expires = self.test_get_token()
del self.app.extra_environ['GRST_CRED_AURI_0']
response = self.app.get(
url="/whoami",
headers={'Authorization': str('Bearer %s' % access_token)},
status=200
)
whoami = json.loads(response.body)
self.assertEqual('oauth2', whoami['method'])
token = Session.query(OAuth2Token).get((client_id, refresh_token))
token.expires = datetime.utcnow() - timedelta(hours=1)
Session.merge(token)
Session.commit()
response = self.app.get(
url="/whoami",
headers={'Authorization': str('Bearer %s' % access_token)},
status=403
)
示例5: popDelegation
def popDelegation(self):
cred = self.getUserCredentials()
if cred and cred.delegation_id:
delegated = Session.query(Credential).get((cred.delegation_id, cred.user_dn))
if delegated:
Session.delete(delegated)
Session.commit()
示例6: test_ban_se_cancel
def test_ban_se_cancel(self):
"""
Ban a SE that has files queued, make sure they are canceled
"""
jobs = list()
jobs.append(insert_job('dteam', 'gsiftp://source', 'gsiftp://destination', 'SUBMITTED'))
jobs.append(insert_job('dteam', 'gsiftp://source', 'gsiftp://destination2', 'ACTIVE'))
jobs.append(insert_job('dteam', 'gsiftp://source', 'gsiftp://destination2', 'FAILED', duration=10, queued=20))
answer = self.app.post(url="/ban/se", params={'storage': 'gsiftp://source'}, status=200)
canceled_ids = json.loads(answer.body)
self.assertEqual(2, len(canceled_ids))
self.assertIn(jobs[0], canceled_ids)
self.assertIn(jobs[1], canceled_ids)
self.assertNotIn(jobs[2], canceled_ids)
for job_id in jobs[0:2]:
job = Session.query(Job).get(job_id)
files = Session.query(File).filter(File.job_id == job_id)
self.assertEqual('CANCELED', job.job_state)
self.assertNotEqual(None, job.job_finished)
self.assertNotEqual(None, job.finish_time)
for f in files:
self.assertEqual('CANCELED', f.file_state)
self.assertNotEqual(None, f.job_finished)
self.assertNotEqual(None, f.finish_time)
self.assertEqual('Storage banned', f.reason)
job = Session.query(Job).get(jobs[2])
self.assertEqual(job.job_state, 'FAILED')
files = Session.query(File).filter(File.job_id == job.job_id)
for f in files:
self.assertEqual('FAILED', f.file_state)
示例7: apiVersion
def apiVersion(self):
credV = Session.query(CredentialVersion)[0]
schemaV = Session.query(SchemaVersion)[0]
return {'api': _Version(0, 2, 1),
'schema': credV,
'delegation': schemaV,
'_links': {
'curies': [{'name': 'fts', 'href': 'https://svnweb.cern.ch/trac/fts3'}],
'fts:whoami': {'href': '/whoami', 'title': 'Check user certificate'},
'fts:joblist': {'href': '/jobs{?vo_name,user_dn}', 'title': 'List of active jobs', 'templated': True},
'fts:job': {
'href': '/jobs/{id}',
'title': 'Job information',
'templated': True,
'hints': {
'allow': ['GET', 'DELETE']
}
},
'fts:configaudit': {'href': '/config/audit', 'title': 'Configuration'},
'fts:submitschema': {'href': '/schema/submit', 'title': 'JSON schema of messages'},
'fts:jobsubmit': {
'href': '/jobs',
'hints': {
'allow': ['POST'],
'representations': ['fts:submitschema']
}
},
}
}
示例8: test_ban_se_partial_job
def test_ban_se_partial_job(self):
"""
Ban a SE that has files queued. If a job has other pairs, the job must remain!
"""
job_id = insert_job(
'dteam',
multiple=[('gsiftp://source', 'gsiftp://destination'), ('gsiftp://other', 'gsiftp://destination')]
)
answer = self.app.post(url="/ban/se", params={'storage': 'gsiftp://source'}, status=200)
canceled_ids = json.loads(answer.body)
self.assertEqual(1, len(canceled_ids))
self.assertEqual(job_id, canceled_ids[0])
job = Session.query(Job).get(job_id)
self.assertEqual('SUBMITTED', job.job_state)
self.assertEqual(None, job.job_finished)
self.assertEqual(None, job.finish_time)
files = Session.query(File).filter(File.job_id == job_id)
for f in files:
if f.source_se == 'gsiftp://source':
self.assertEqual('CANCELED', f.file_state)
self.assertNotEqual(None, f.finish_time)
else:
self.assertEqual('SUBMITTED', f.file_state)
self.assertEqual(None, f.job_finished)
示例9: test_ban_se_cancel_vo
def test_ban_se_cancel_vo(self):
"""
Cancel a SE that has files queued, make sure they are canceled (with VO)
"""
jobs = list()
jobs.append(insert_job('dteam', 'gsiftp://source', 'gsiftp://destination', 'SUBMITTED'))
jobs.append(insert_job('atlas', 'gsiftp://source', 'gsiftp://destination', 'SUBMITTED'))
jobs.append(insert_job('atlas', 'gsiftp://source', 'gsiftp://destination2', 'SUBMITTED'))
answer = self.app.post(
url="/ban/se",
params={'storage': 'gsiftp://source', 'status': 'cancel', 'vo_name': 'dteam'},
status=200
)
canceled_ids = json.loads(answer.body)
self.assertEqual(1, len(canceled_ids))
self.assertIn(jobs[0], canceled_ids)
for job_id in jobs:
job = Session.query(Job).get(job_id)
files = Session.query(File).filter(File.job_id == job_id)
if job_id in canceled_ids:
self.assertEqual('CANCELED', job.job_state)
else:
self.assertEqual('SUBMITTED', job.job_state)
for f in files:
if job_id in canceled_ids:
self.assertEqual('CANCELED', f.file_state)
else:
self.assertEqual('SUBMITTED', f.file_state)
示例10: test_ban_se_wait_vo
def test_ban_se_wait_vo(self):
"""
Ban a SE, but instead of canceling, give jobs some time to finish (with VO)
"""
jobs = list()
jobs.append(insert_job('dteam', 'gsiftp://source', 'gsiftp://destination', 'SUBMITTED'))
jobs.append(insert_job('atlas', 'gsiftp://source', 'gsiftp://destination', 'SUBMITTED'))
jobs.append(insert_job('atlas', 'gsiftp://source', 'gsiftp://destination2', 'SUBMITTED'))
answer = self.app.post(
url="/ban/se",
params={'storage': 'gsiftp://source', 'status': 'wait', 'vo_name': 'dteam', 'timeout': 33},
status=200
)
waiting_ids = json.loads(answer.body)
self.assertEqual(1, len(waiting_ids))
self.assertIn(jobs[0], waiting_ids)
for job_id in jobs:
job = Session.query(Job).get(job_id)
files = Session.query(File).filter(File.job_id == job_id)
self.assertEqual('SUBMITTED', job.job_state)
for f in files:
self.assertEqual('SUBMITTED', f.file_state)
if job_id in waiting_ids:
self.assertEqual(33, f.wait_timeout)
else:
self.assertEqual(None, f.wait_timeout)
示例11: cancel
def cancel(self, id, **kwargs):
"""DELETE /jobs/id: Delete an existing item"""
job = self._getJob(id)
if job.job_state in JobActiveStates:
now = datetime.now()
job.job_state = 'CANCELED'
job.finish_time = now
job.job_finished = now
job.reason = 'Job canceled by the user'
for f in job.files:
if f.file_state in JobActiveStates:
f.file_state = 'CANCELED'
f.job_finished = now
f.finish_time = now
f.reason = 'Job canceled by the user'
Session.merge(job)
Session.commit()
job = self._getJob(id)
files = job.files
return job
示例12: pop_delegation
def pop_delegation(self):
"""
Remove the mock proxy from the database
"""
cred = self.get_user_credentials()
if cred and cred.delegation_id:
delegated = Session.query(Credential).get((cred.delegation_id, cred.user_dn))
if delegated:
Session.delete(delegated)
Session.commit()
示例13: test_ban_dn_submission
def test_ban_dn_submission(self):
"""
If a DN is banned, submissions from this user must not be accepted
"""
banned = BannedDN()
banned.dn = self.get_user_credentials().user_dn
Session.merge(banned)
Session.commit()
self.push_delegation()
self.app.post(url="/jobs", content_type='application/json', params='[]', status=403)
示例14: pushDelegation
def pushDelegation(self, lifetime = timedelta(hours = 7)):
creds = self.getUserCredentials()
delegated = Credential()
delegated.dlg_id = creds.delegation_id
delegated.dn = creds.user_dn
delegated.proxy = '-NOT USED-'
delegated.voms_attrs = None
delegated.termination_time = datetime.now() + lifetime
Session.merge(delegated)
Session.commit()
示例15: get_files
def get_files(self, job_id):
"""
Get the files within a job
"""
owner = Session.query(Job.user_dn, Job.vo_name).filter(Job.job_id == job_id).first()
if owner is None:
raise HTTPNotFound('No job with the id "%s" has been found' % job_id)
if not authorized(TRANSFER, resource_owner=owner[0], resource_vo=owner[1]):
raise HTTPForbidden('Not enough permissions to check the job "%s"' % job_id)
files = Session.query(File).filter(File.job_id == job_id).options(noload(File.retries))
return files.all()