def test_multi_vo_flag(self): """ MULTI VO (CORE): Test operations fail in single_vo mode """ try: config_set('common', 'multi_vo', 'False') with assert_raises(UnsupportedOperation): vo_api.list_vos(issuer='super_root', vo='def') config_remove_option('common', 'multi_vo') with assert_raises(UnsupportedOperation): vo_api.list_vos(issuer='super_root', vo='def') finally: # Make sure we don't leave the config changed due to a test failure if self.vo: config_set('common', 'multi_vo', 'True') else: config_remove_option('common', 'multi_vo')
def GET(self): """ List all VOs. HTTP Success: 200 OK HTTP Error: 401 Unauthorized 409 Conflict 500 InternalError :returns: A list containing all VOs. """ header('Content-Type', 'application/x-json-stream') try: for vo in list_vos(issuer=ctx.env.get('issuer'), vo=ctx.env.get('vo')): yield render_json(**vo) + '\n' except AccessDenied as error: raise generate_http_error(401, 'AccessDenied', error.args[0]) except UnsupportedOperation as error: raise generate_http_error(409, 'UnsupportedOperation', error.args[0]) except RucioException as error: raise generate_http_error(500, error.__class__.__name__, error.args[0]) except Exception as error: print(error) print(format_exc()) raise InternalError(error)
def get(self): """ List all VOs. .. :quickref: VOs; List all VOs. :resheader Content-Type: application/x-json-stream :status 200: VOs found. :status 401: Invalid Auth Token. :status 409: Unsupported operation. :status 500: Internal Error. :returns: A list containing all VOs. """ try: data = "" for vo in list_vos(issuer=request.environ.get('issuer'), vo=request.environ.get('vo')): data += render_json(**vo) + '\n' return Response(data, content_type="application/x-json-stream") except AccessDenied as error: return generate_http_error(401, 'AccessDenied', error.args[0]) except UnsupportedOperation as error: return generate_http_error(409, 'UnsupportedOperation', error.args[0]) except RucioException as error: return generate_http_error(500, error.__class__.__name__, error.args[0]) except Exception as error: print(error) print(format_exc()) return error, 500
def GET(self): ''' List all VOs. ''' header('Content-Type', 'application/json') try: vos = list_vos(issuer=ctx.env.get('issuer'), vo=ctx.env.get('vo')) except RucioException as error: raise generate_http_error(500, error.__class__.__name__, error.args[0]) except Exception as error: print(error) print(format_exc()) raise InternalError(error) return dumps(vos)
def test_update_vo(self): """ MULTI VO (CORE): Test updating VOs """ description = generate_uuid() email = generate_uuid() parameters = {'vo': self.new_vo['vo'], 'description': description, 'email': email} with assert_raises(AccessDenied): vo_api.update_vo(self.new_vo['vo'], parameters, 'root', **self.vo) vo_api.update_vo(self.new_vo['vo'], parameters, 'super_root', 'def') vo_update_success = False for v in vo_api.list_vos('super_root', 'def'): if v['vo'] == parameters['vo']: assert_equal(email, v['email']) assert_equal(description, v['description']) vo_update_success = True assert_true(vo_update_success)
def test_update_vo_success(self): """ MULTI VO (REST): Test updating VO through REST layer succeeds """ mw = [] headers1 = {'X-Rucio-Account': 'super_root', 'X-Rucio-Username': '******', 'X-Rucio-Password': '******'} headers1.update(self.def_header) res1 = TestApp(auth_app.wsgifunc(*mw)).get('/userpass', headers=headers1, expect_errors=True) assert_equal(res1.status, 200) token = str(res1.header('X-Rucio-Auth-Token')) params = {'email': generate_uuid(), 'description': generate_uuid()} headers2 = {'X-Rucio-Auth-Token': str(token)} res2 = TestApp(vo_app.wsgifunc(*mw)).put('/' + self.vo['vo'], headers=headers2, expect_errors=True, params=dumps(params)) assert_equal(res2.status, 200) vo_update_success = False for v in vo_api.list_vos('super_root', 'def'): if v['vo'] == self.vo['vo']: assert_equal(params['email'], v['email']) assert_equal(params['description'], v['description']) vo_update_success = True assert_true(vo_update_success)
def generate(issuer, vo): for vo in list_vos(issuer=issuer, vo=vo): yield render_json(**vo) + '\n'
from rucio.api.vo import add_vo, list_vos from rucio.client import Client from rucio.common.config import config_get_bool from rucio.common.exception import Duplicate from rucio.core.account import add_account_attribute from rucio.common.types import InternalAccount if __name__ == '__main__': if config_get_bool('common', 'multi_vo', raise_exception=False, default=False): voname = 'tst' vo = {'vo': voname} issuer = 'super_root' add_vo(new_vo=vo['vo'], issuer=issuer, password='******', description='A VO to test multi-vo features', email='N/A', vo='def') print('Added VO tst OK') for eachvo in list_vos(issuer=issuer, vo='def'): if eachvo['vo'] != 'def': print("vo = {vo}, description={description}".format( vo=eachvo['vo'], description=eachvo['description'])) else: vo = {}