def test_create_list_subscription_by_id(self): """ SUBSCRIPTION (API): Test the creation of a new subscription and list it by id """ subscription_name = uuid() subscription_id = add_subscription(name=subscription_name, account='root', filter={'project': self.projects, 'datatype': ['AOD', ], 'excluded_pattern': self.pattern1, 'account': ['tier0', ]}, replication_rules=[{'lifetime': 86400, 'rse_expression': 'MOCK|MOCK2', 'copies': 2, 'activity': 'Data Brokering'}], lifetime=100000, retroactive=0, dry_run=0, comments='This is a comment', issuer='root') subscription_info = get_subscription_by_id(subscription_id) assert_equal(loads(subscription_info['filter'])['project'], self.projects)
def get(self, subscription_id): """ Retrieve a subscription matching the given subscription id .. :quickref: SubscriptionId; Get a subscription by ID. :param subscription_id: The subscription id. :resheader Content-Type: application/json :status 200: OK. :status 401: Invalid Auth Token. :status 404: Subscription Not Found. :status 406: Not Acceptable. :status 500: Internal Error. :returns: dictionary with subscription information. """ try: subscription = get_subscription_by_id(subscription_id, vo=request.environ.get('vo')) except SubscriptionNotFound as error: return generate_http_error_flask(404, 'SubscriptionNotFound', error.args[0]) except RucioException as error: return generate_http_error_flask(500, error.__class__.__name__, error.args[0]) except Exception as error: print(format_exc()) return str(error), 500 return Response(render_json(**subscription), content_type="application/json")
def test_create_list_subscription_by_id(self): """ SUBSCRIPTION (API): Test the creation of a new subscription and list it by id """ subscription_name = uuid() subscription_id = add_subscription(name=subscription_name, account='root', filter={'project': ['data12_900GeV', 'data12_8TeV', 'data13_900GeV', 'data13_8TeV'], 'datatype': ['AOD', ], 'excluded_pattern': '(_tid|physics_(Muons|JetTauEtmiss|Egamma)\..*\.ESD|express_express(?!.*NTUP|.*\.ESD|.*RAW)|(physics|express)(?!.*NTUP).* \ \.x|physics_WarmStart|calibration(?!_PixelBeam.merge.(NTUP_IDVTXLUMI|AOD))|merge.HIST|NTUP_MUONCALIB|NTUP_TRIG)', 'account': 'tier0'}, replication_rules=[(2, 'T1_DATATAPE', True, True), (1, 'T1_DATADISK', False, True)], lifetime=100000, retroactive=0, dry_run=0, comments='This is a comment') subscription_info = get_subscription_by_id(subscription_id) assert_equal(loads(subscription_info['filter'])['project'], ['data12_900GeV', 'data12_8TeV', 'data13_900GeV', 'data13_8TeV'])
def test_api_subscription(self): """ SUBSCRIPTION (API): Test external representation of subscriptions """ sub = 'ext_' + generate_uuid() did = 'ext_' + generate_uuid() new_acc_name = ''.join(random.choice(string.ascii_lowercase) for x in range(10)) new_scope_name = ''.join(random.choice(string.ascii_lowercase) for x in range(10)) add_account(new_acc_name, 'USER', '*****@*****.**', 'root', **self.new_vo) add_scope(new_scope_name, new_acc_name, 'root', **self.new_vo) api_acc_lim.set_local_account_limit(new_acc_name, self.rse3_name, 10, 'root', **self.new_vo) api_acc_lim.set_local_account_limit(new_acc_name, self.rse4_name, 10, 'root', **self.new_vo) add_did(new_scope_name, did, 'DATASET', 'root', account=new_acc_name, rse=self.rse3_name, **self.new_vo) sub_id = add_subscription(sub, new_acc_name, {'account': [new_acc_name], 'scope': [new_scope_name]}, [{'copies': 1, 'rse_expression': self.rse3_name, 'weight': 0, 'activity': 'User Subscriptions', 'source_replica_expression': self.rse4_name}], '', False, 0, 0, 3, 'root', **self.new_vo) add_replication_rule(dids=[{'scope': new_scope_name, 'name': did}], copies=1, rse_expression=self.rse3_name, weight=None, lifetime=180, grouping='DATASET', account=new_acc_name, locked=False, subscription_id=sub_id, source_replica_expression=self.rse4_name, activity='User Subscriptions', notify=None, purge_replicas=False, ignore_availability=False, comment='', ask_approval=False, asynchronous=False, priority=0, split_container=False, meta='', issuer='root', **self.new_vo) out = list_subscriptions(sub, **self.new_vo) out = list(out) assert_not_equal(0, len(out)) assert_in(sub_id, [o['id'] for o in out]) for o in out: if o['id'] == sub_id: assert_equal(o['account'], new_acc_name) rules = loads(o['replication_rules'])[0] assert_equal(rules['rse_expression'], self.rse3_name) assert_equal(rules['source_replica_expression'], self.rse4_name) fil = loads(o['filter']) assert_equal(fil['account'], [new_acc_name]) assert_equal(fil['scope'], [new_scope_name]) out = list_subscription_rule_states(sub, **self.new_vo) out = list(out) assert_not_equal(0, len(out)) for o in out: assert_equal(o.account, new_acc_name) out = get_subscription_by_id(sub_id, **self.new_vo) assert_equal(out['account'], new_acc_name) rules = loads(out['replication_rules'])[0] assert_equal(rules['rse_expression'], self.rse3_name) assert_equal(rules['source_replica_expression'], self.rse4_name) fil = loads(out['filter']) assert_equal(fil['account'], [new_acc_name]) assert_equal(fil['scope'], [new_scope_name])
def GET(self, subscription_id): """ Retrieve a subscription matching the given subscription id HTTP Success: 200 OK HTTP Error: 401 Unauthorized 404 Not Found """ header('Content-Type', 'application/json') try: subscription = get_subscription_by_id(subscription_id) except SubscriptionNotFound, e: raise generate_http_error(404, 'SubscriptionNotFound', e.args[0][0])
def GET(self, subscription_id): """ Retrieve a subscription matching the given subscription id HTTP Success: 200 OK HTTP Error: 404 Not Found 401 Unauthorized """ header('Content-Type', 'application/json') try: subscription = get_subscription_by_id(subscription_id) except SubscriptionNotFound, error: raise generate_http_error(404, 'SubscriptionNotFound', error.args[0][0])
def test_create_list_subscription_by_id(self): """ SUBSCRIPTION (API): Test the creation of a new subscription and list it by id """ rse1, _ = self.rse_factory.make_mock_rse() rse2, _ = self.rse_factory.make_mock_rse() rse_expression = '%s|%s' % (rse1, rse2) subscription_name = uuid() subscription_id = add_subscription(name=subscription_name, account='root', filter_={ 'project': self.projects, 'datatype': [ 'AOD', ], 'excluded_pattern': self.pattern1, 'account': [ 'tier0', ] }, replication_rules=[{ 'lifetime': 86400, 'rse_expression': rse_expression, 'copies': 2, 'activity': 'Data Brokering' }], lifetime=100000, retroactive=0, dry_run=0, comments='This is a comment', issuer='root', **self.vo) subscription_info = get_subscription_by_id(subscription_id, **self.vo) assert loads(subscription_info['filter'])['project'] == self.projects
def GET(self, subscription_id): """ Retrieve a subscription matching the given subscription id HTTP Success: 200 OK HTTP Error: 401 Unauthorized 404 Not Found 406 Not Acceptable """ header('Content-Type', 'application/json') try: subscription = get_subscription_by_id(subscription_id, vo=ctx.env.get('vo')) except SubscriptionNotFound as error: raise generate_http_error(404, 'SubscriptionNotFound', error.args[0]) except RucioException as error: raise generate_http_error(500, error.__class__.__name__, error.args[0]) except Exception as error: raise InternalError(error) return render_json(**subscription)