From: Thierry Parmentelat Date: Tue, 19 Oct 2010 10:53:00 +0000 (+0300) Subject: namespace module is gone, plxrn provides PL-specific translations X-Git-Tag: sfa-1.0-5~12 X-Git-Url: http://git.onelab.eu/?p=sfa.git;a=commitdiff_plain;h=06b330f0ee047bdb107e43e82b1d7356c876bc15 namespace module is gone, plxrn provides PL-specific translations helper functions re-implemented on top of (pl)xrn - temporarily --- diff --git a/config/default_config.xml b/config/default_config.xml index 37cd6cce..ce5ec403 100644 --- a/config/default_config.xml +++ b/config/default_config.xml @@ -5,8 +5,6 @@ Default SFA configuration file Thierry Parmentelat -$Id$ -$URL$ --> diff --git a/sfa/managers/aggregate_manager_eucalyptus.py b/sfa/managers/aggregate_manager_eucalyptus.py index 3d2018bf..b9f6df8c 100644 --- a/sfa/managers/aggregate_manager_eucalyptus.py +++ b/sfa/managers/aggregate_manager_eucalyptus.py @@ -337,7 +337,7 @@ class ZoneResultParser(object): def get_rspec(api, creds, options): global cloud # get slice's hrn from options - xrn = options.get('geni_slice_urn', None) + xrn = options.get('geni_slice_urn', '') hrn, type = urn_to_hrn(xrn) # get hrn of the original caller diff --git a/sfa/managers/aggregate_manager_max.py b/sfa/managers/aggregate_manager_max.py index 14b924d4..2a46cb5a 100644 --- a/sfa/managers/aggregate_manager_max.py +++ b/sfa/managers/aggregate_manager_max.py @@ -3,8 +3,8 @@ from sfa.util.rspec import RSpec import sys import pdb -from sfa.util.namespace import hrn_to_pl_slicename from sfa.util.xrn import urn_to_hrn, get_authority +from sfa.util.plxrn import hrn_to_pl_slicename from sfa.util.rspec import * from sfa.util.specdict import * from sfa.util.faults import * @@ -250,7 +250,7 @@ def create_slice_max_aggregate(api, hrn, nodes): def get_rspec(api, creds, options): # get slice's hrn from options - xrn = options.get('geni_slice_urn', None) + xrn = options.get('geni_slice_urn', '') hrn, type = urn_to_hrn(xrn) # Eg. config line: # plc.princeton.sapan vlan23,vlan45 diff --git a/sfa/managers/aggregate_manager_openflow.py b/sfa/managers/aggregate_manager_openflow.py index 6d12446d..92858977 100755 --- a/sfa/managers/aggregate_manager_openflow.py +++ b/sfa/managers/aggregate_manager_openflow.py @@ -9,7 +9,7 @@ import struct #from soaplib.serializers.clazz import * from sfa.util.faults import * -from sfa.util.namespace import urn_to_hrn +from sfa.util.xrn import urn_to_hrn from sfa.util.rspec import RSpec from sfa.server.registry import Registries from sfa.util.config import Config diff --git a/sfa/managers/aggregate_manager_pl.py b/sfa/managers/aggregate_manager_pl.py index d3422c98..0c70ddae 100644 --- a/sfa/managers/aggregate_manager_pl.py +++ b/sfa/managers/aggregate_manager_pl.py @@ -4,11 +4,13 @@ import traceback import sys import re from types import StringTypes +from dateutil.parser import parse -from sfa.util.namespace import get_authority, urn_to_hrn, slicename_to_hrn, hrn_to_pl_slicename, hrn_to_urn +from sfa.util.faults import * +from sfa.util.xrn import get_authority, hrn_to_urn, urn_to_hrn +from sfa.util.plxrn import slicename_to_hrn, hrn_to_pl_slicename from sfa.util.rspec import * from sfa.util.specdict import * -from sfa.util.faults import * from sfa.util.record import SfaRecord from sfa.util.policy import Policy from sfa.util.record import * @@ -19,7 +21,6 @@ import sfa.plc.peers as peers from sfa.plc.network import * from sfa.plc.api import SfaAPI from sfa.plc.slices import * -from dateutil.parser import parse def __get_registry_objects(slice_xrn, creds, users): @@ -265,7 +266,7 @@ def get_slices(api, creds): def get_rspec(api, creds, options): # get slice's hrn from options - xrn = options.get('geni_slice_urn', None) + xrn = options.get('geni_slice_urn', '') hrn, type = urn_to_hrn(xrn) # look in cache first diff --git a/sfa/managers/aggregate_manager_vini.py b/sfa/managers/aggregate_manager_vini.py index d974259d..2b56eebe 100644 --- a/sfa/managers/aggregate_manager_vini.py +++ b/sfa/managers/aggregate_manager_vini.py @@ -4,7 +4,8 @@ import traceback import sys from types import StringTypes -from sfa.util.namespace import hrn_to_pl_slicename, urn_to_hrn +from sfa.util.xrn import urn_to_hrn +from sfa.util.plxrn import hrn_to_pl_slicename from sfa.util.rspec import * from sfa.util.specdict import * from sfa.util.faults import * @@ -96,7 +97,7 @@ def create_slice(api, xrn, creds, xml, users): def get_rspec(api, creds, options): # get slice's hrn from options - xrn = options.get('geni_slice_urn', None) + xrn = options.get('geni_slice_urn', '') hrn, type = urn_to_hrn(xrn) # look in cache first diff --git a/sfa/managers/component_manager_pl.py b/sfa/managers/component_manager_pl.py index 5c9506df..6c368097 100644 --- a/sfa/managers/component_manager_pl.py +++ b/sfa/managers/component_manager_pl.py @@ -2,7 +2,8 @@ import os import xmlrpclib from sfa.util.faults import * -from sfa.util.namespace import urn_to_hrn, hrn_to_pl_slicename +from sfa.util.xrn import urn_to_hrn +from sfa.util.plxrn import hrn_to_pl_slicename from sfa.util.sfaticket import SfaTicket def init_server(): diff --git a/sfa/managers/registry_manager_pl.py b/sfa/managers/registry_manager_pl.py index ac5901c8..3835873a 100644 --- a/sfa/managers/registry_manager_pl.py +++ b/sfa/managers/registry_manager_pl.py @@ -7,8 +7,8 @@ from sfa.util.record import SfaRecord from sfa.util.table import SfaTable from sfa.util.record import SfaRecord from sfa.trust.gid import GID -from sfa.util.namespace import hrn_to_pl_login_base from sfa.util.xrn import Xrn, get_leaf, get_authority, hrn_to_urn, urn_to_hrn +from sfa.util.plxrn import hrn_to_pl_login_base from sfa.trust.credential import Credential from sfa.trust.certificate import Certificate, Keypair from sfa.trust.gid import create_uuid @@ -368,21 +368,18 @@ def update(api, record_dict): return 1 -# being PL specific it sounds right to expect a hrn+type (not a xrn) -def remove(api, hrn, type, origin_hrn=None): -# # convert xrn to hrn -# if type: -# hrn = urn_to_hrn(xrn)[0] -# else: -# hrn, type = urn_to_hrn(xrn) +# expecting an Xrn instance +def remove(api, xrn, origin_hrn=None): table = SfaTable() - filter = {'hrn': hrn} + filter = {'hrn': xrn.get_hrn()} + hrn=xrn.get_hrn() + type=xrn.get_type() if type and type not in ['all', '*']: filter['type'] = type + records = table.find(filter) - if not records: - raise RecordNotFound(hrn) + if not records: raise RecordNotFound(hrn) record = records[0] type = record['type'] diff --git a/sfa/managers/slice_manager_pl.py b/sfa/managers/slice_manager_pl.py index 2c98e242..4aca6fae 100644 --- a/sfa/managers/slice_manager_pl.py +++ b/sfa/managers/slice_manager_pl.py @@ -11,7 +11,7 @@ from lxml import etree from sfa.util.sfalogging import sfa_logger from sfa.util.rspecHelper import merge_rspecs -from sfa.util.namespace import urn_to_hrn, hrn_to_urn +from sfa.util.xrn import urn_to_hrn, hrn_to_urn from sfa.util.rspec import * from sfa.util.specdict import * from sfa.util.faults import * @@ -339,7 +339,7 @@ def get_slices(api, creds): def get_rspec(api, creds, options): # get slice's hrn from options - xrn = options.get('geni_slice_urn', None) + xrn = options.get('geni_slice_urn', '') hrn, type = urn_to_hrn(xrn) # get hrn of the original caller diff --git a/sfa/methods/CreateSliver.py b/sfa/methods/CreateSliver.py index e32f9fdc..0c729b94 100644 --- a/sfa/methods/CreateSliver.py +++ b/sfa/methods/CreateSliver.py @@ -1,5 +1,5 @@ from sfa.util.faults import * -from sfa.util.namespace import urn_to_hrn +from sfa.util.xrn import urn_to_hrn from sfa.util.method import Method from sfa.util.parameter import Parameter, Mixed from sfa.util.sfatablesRuntime import run_sfatables diff --git a/sfa/methods/DeleteSliver.py b/sfa/methods/DeleteSliver.py index 8715407d..2df5f750 100644 --- a/sfa/methods/DeleteSliver.py +++ b/sfa/methods/DeleteSliver.py @@ -2,7 +2,7 @@ ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/stop_slice.py $ from sfa.util.faults import * -from sfa.util.namespace import urn_to_hrn +from sfa.util.xrn import urn_to_hrn from sfa.util.method import Method from sfa.util.parameter import Parameter, Mixed from sfa.trust.auth import Auth diff --git a/sfa/methods/GetCredential.py b/sfa/methods/GetCredential.py index 849da807..34a4cb93 100644 --- a/sfa/methods/GetCredential.py +++ b/sfa/methods/GetCredential.py @@ -1,7 +1,7 @@ # from sfa.trust.rights import * from sfa.util.faults import * -from sfa.util.namespace import urn_to_hrn +from sfa.util.xrn import urn_to_hrn from sfa.util.method import Method from sfa.util.parameter import Parameter, Mixed from sfa.trust.credential import Credential diff --git a/sfa/methods/GetSelfCredential.py b/sfa/methods/GetSelfCredential.py index 647e6369..6a8261c9 100644 --- a/sfa/methods/GetSelfCredential.py +++ b/sfa/methods/GetSelfCredential.py @@ -1,6 +1,6 @@ from sfa.util.faults import * -from sfa.util.namespace import urn_to_hrn +from sfa.util.xrn import urn_to_hrn from sfa.util.method import Method from sfa.util.parameter import Parameter, Mixed from sfa.util.record import SfaRecord diff --git a/sfa/methods/GetTicket.py b/sfa/methods/GetTicket.py index f9b8c22c..812fb08c 100644 --- a/sfa/methods/GetTicket.py +++ b/sfa/methods/GetTicket.py @@ -2,7 +2,7 @@ ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/get_ticket.py $ import time from sfa.util.faults import * -from sfa.util.namespace import urn_to_hrn +from sfa.util.xrn import urn_to_hrn from sfa.util.method import Method from sfa.util.parameter import Parameter, Mixed from sfa.trust.auth import Auth diff --git a/sfa/methods/List.py b/sfa/methods/List.py index a812c867..8b4fcbea 100644 --- a/sfa/methods/List.py +++ b/sfa/methods/List.py @@ -1,8 +1,6 @@ -### $Id: list.py 16588 2010-01-13 17:53:44Z anil $ -### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/list.py $ from sfa.util.faults import * -from sfa.util.namespace import urn_to_hrn +from sfa.util.xrn import urn_to_hrn from sfa.util.method import Method from sfa.util.parameter import Parameter, Mixed from sfa.util.record import SfaRecord diff --git a/sfa/methods/ListResources.py b/sfa/methods/ListResources.py index 04258530..6afeb490 100644 --- a/sfa/methods/ListResources.py +++ b/sfa/methods/ListResources.py @@ -1,11 +1,12 @@ +import sys +import zlib + from sfa.util.faults import * -from sfa.util.namespace import urn_to_hrn +from sfa.util.xrn import urn_to_hrn from sfa.util.method import Method from sfa.util.parameter import Parameter, Mixed from sfa.trust.credential import Credential from sfa.util.sfatablesRuntime import run_sfatables -import sys -import zlib class ListResources(Method): """ @@ -26,7 +27,7 @@ class ListResources(Method): self.api.logger.info("interface: %s\tmethod-name: %s" % (self.api.interface, self.name)) # get slice's hrn from options - xrn = options.get('geni_slice_urn', None) + xrn = options.get('geni_slice_urn', '') hrn, _ = urn_to_hrn(xrn) # Find the valid credentials diff --git a/sfa/methods/RegisterPeerObject.py b/sfa/methods/RegisterPeerObject.py index e4cea962..864b1d53 100644 --- a/sfa/methods/RegisterPeerObject.py +++ b/sfa/methods/RegisterPeerObject.py @@ -5,7 +5,7 @@ from sfa.trust.certificate import Keypair, convert_public_key from sfa.trust.gid import * from sfa.util.faults import * -from sfa.util.namespace import get_authority +from sfa.util.xrn import get_authority from sfa.util.method import Method from sfa.util.parameter import Parameter, Mixed from sfa.util.record import SfaRecord diff --git a/sfa/methods/Remove.py b/sfa/methods/Remove.py index db0fe08e..73fcdf85 100644 --- a/sfa/methods/Remove.py +++ b/sfa/methods/Remove.py @@ -1,8 +1,5 @@ -### $Id: remove.py 16497 2010-01-07 03:33:24Z tmack $ -### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/remove.py $ - from sfa.util.faults import * -from sfa.util.namespace import urn_to_hrn +from sfa.util.xrn import Xrn from sfa.util.method import Method from sfa.util.parameter import Parameter, Mixed from sfa.trust.credential import Credential @@ -31,21 +28,18 @@ class Remove(Method): returns = Parameter(int, "1 if successful") -# this does not sound quite right, but the best I could come up with is: -# if type is not specified then we expect a URN def call(self, xrn, creds, type): - if type: hrn=xrn - else: (hrn,type) = urn_to_hrn(xrn) + xrn=Xrn(xrn=xrn,type=type) # validate the cred valid_creds = self.api.auth.checkCredentials(creds, "remove") - self.api.auth.verify_object_permission(hrn) + self.api.auth.verify_object_permission(xrn.get_hrn()) #log the call origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn() - self.api.logger.info("interface: %s\tmethod-name: %s\tcaller-hrn: %s\ttarget-hrn: %s\ttype: %s"%( - self.api.interface, self.name, origin_hrn, hrn, type)) + self.api.logger.info("interface: %s\tmethod-name: %s\tcaller-hrn: %s\ttarget-urn: %s"%( + self.api.interface, self.name, origin_hrn, xrn.get_urn())) manager = self.api.get_interface_manager() - return manager.remove(self.api, hrn, type) + return manager.remove(self.api, xrn) diff --git a/sfa/methods/RenewSliver.py b/sfa/methods/RenewSliver.py index 1d7c540b..fd0971af 100644 --- a/sfa/methods/RenewSliver.py +++ b/sfa/methods/RenewSliver.py @@ -1,5 +1,5 @@ from sfa.util.faults import * -from sfa.util.namespace import urn_to_hrn +from sfa.util.xrn import urn_to_hrn from sfa.util.method import Method from sfa.util.parameter import Parameter from sfa.trust.credential import Credential diff --git a/sfa/methods/Resolve.py b/sfa/methods/Resolve.py index d8a536e9..92aeec29 100644 --- a/sfa/methods/Resolve.py +++ b/sfa/methods/Resolve.py @@ -3,7 +3,7 @@ import traceback import types from sfa.util.faults import * -from sfa.util.namespace import urn_to_hrn +from sfa.util.xrn import urn_to_hrn from sfa.util.method import Method from sfa.util.parameter import Parameter, Mixed from sfa.trust.credential import Credential diff --git a/sfa/methods/SliverStatus.py b/sfa/methods/SliverStatus.py index 0842c14a..842c3e45 100644 --- a/sfa/methods/SliverStatus.py +++ b/sfa/methods/SliverStatus.py @@ -1,5 +1,5 @@ from sfa.util.faults import * -from sfa.util.namespace import urn_to_hrn +from sfa.util.xrn import urn_to_hrn from sfa.util.method import Method from sfa.util.parameter import Parameter, Mixed diff --git a/sfa/methods/Start.py b/sfa/methods/Start.py index 3619106f..e1ca60e9 100644 --- a/sfa/methods/Start.py +++ b/sfa/methods/Start.py @@ -2,7 +2,7 @@ ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/stop_slice.py $ from sfa.util.faults import * -from sfa.util.namespace import urn_to_hrn +from sfa.util.xrn import urn_to_hrn from sfa.util.method import Method from sfa.util.parameter import Parameter, Mixed from sfa.trust.auth import Auth diff --git a/sfa/methods/Stop.py b/sfa/methods/Stop.py index 13106e75..579a77d6 100644 --- a/sfa/methods/Stop.py +++ b/sfa/methods/Stop.py @@ -2,7 +2,7 @@ ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/stop_slice.py $ from sfa.util.faults import * -from sfa.util.namespace import urn_to_hrn +from sfa.util.xrn import urn_to_hrn from sfa.util.method import Method from sfa.util.parameter import Parameter, Mixed from sfa.trust.auth import Auth diff --git a/sfa/methods/get_aggregates.py b/sfa/methods/get_aggregates.py index cfc9daac..59d6001a 100644 --- a/sfa/methods/get_aggregates.py +++ b/sfa/methods/get_aggregates.py @@ -1,6 +1,6 @@ from types import StringTypes from sfa.util.faults import * -from sfa.util.namespace import urn_to_hrn +from sfa.util.xrn import urn_to_hrn from sfa.util.method import Method from sfa.util.parameter import Parameter, Mixed from sfa.trust.auth import Auth diff --git a/sfa/methods/get_key.py b/sfa/methods/get_key.py index 5e3f3fd6..9cec0ec5 100644 --- a/sfa/methods/get_key.py +++ b/sfa/methods/get_key.py @@ -1,10 +1,8 @@ -### $Id: $ -### $URL: $ import os import tempfile import commands from sfa.util.faults import * -from sfa.util.namespace import hrn_to_urn +from sfa.util.xrn import hrn_to_urn from sfa.util.method import Method from sfa.util.parameter import Parameter, Mixed from sfa.trust.auth import Auth diff --git a/sfa/methods/get_registries.py b/sfa/methods/get_registries.py index e2331433..a2a65a57 100644 --- a/sfa/methods/get_registries.py +++ b/sfa/methods/get_registries.py @@ -2,7 +2,7 @@ ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/get_registries.py $ from types import StringTypes from sfa.util.faults import * -from sfa.util.namespace import urn_to_hrn +from sfa.util.xrn import urn_to_hrn from sfa.util.method import Method from sfa.util.parameter import Parameter, Mixed from sfa.trust.auth import Auth diff --git a/sfa/methods/register_peer_object.py b/sfa/methods/register_peer_object.py index 51fbe25c..e89f18bd 100644 --- a/sfa/methods/register_peer_object.py +++ b/sfa/methods/register_peer_object.py @@ -5,7 +5,7 @@ from sfa.trust.certificate import Keypair, convert_public_key from sfa.trust.gid import * from sfa.util.faults import * -from sfa.util.namespace import get_authority +from sfa.util.xrn import get_authority from sfa.util.method import Method from sfa.util.parameter import Parameter, Mixed from sfa.util.record import SfaRecord diff --git a/sfa/methods/reset_slice.py b/sfa/methods/reset_slice.py index 21fec61f..9d02364c 100644 --- a/sfa/methods/reset_slice.py +++ b/sfa/methods/reset_slice.py @@ -2,7 +2,7 @@ ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/reset_slices.py $ from sfa.util.faults import * -from sfa.util.namespace import urn_to_hrn +from sfa.util.xrn import urn_to_hrn from sfa.util.method import Method from sfa.util.parameter import Parameter, Mixed from sfa.trust.auth import Auth diff --git a/sfa/plc/api.py b/sfa/plc/api.py index 7e68a6b8..9e77ddaa 100644 --- a/sfa/plc/api.py +++ b/sfa/plc/api.py @@ -17,7 +17,8 @@ from sfa.trust.auth import Auth from sfa.trust.rights import Right, Rights, determine_rights from sfa.trust.credential import Credential,Keypair from sfa.trust.certificate import Certificate -from sfa.util.namespace import get_authority, hrn_to_pl_slicename, hrn_to_pl_slicename, hrn_to_urn, slicename_to_hrn, hostname_to_hrn +from sfa.util.xrn import get_authority, hrn_to_urn +from sfa.util.plxrn import hostname_to_hrn, hrn_to_pl_slicename, hrn_to_pl_slicename, slicename_to_hrn from sfa.util.nodemanager import NodeManager try: from collections import defaultdict diff --git a/sfa/plc/network.py b/sfa/plc/network.py index 42933019..7d2f235d 100644 --- a/sfa/plc/network.py +++ b/sfa/plc/network.py @@ -1,7 +1,8 @@ from __future__ import with_statement import re import socket -from sfa.util.namespace import get_authority, hrn_to_pl_slicename +from sfa.util.xrn import get_authority +from sfa.util.plxrn import hrn_to_pl_slicename from sfa.util.faults import * from xmlbuilder import XMLBuilder from lxml import etree diff --git a/sfa/plc/peers.py b/sfa/plc/peers.py index 455c682a..e85800c8 100644 --- a/sfa/plc/peers.py +++ b/sfa/plc/peers.py @@ -1,4 +1,4 @@ -from sfa.util.namespace import * +from sfa.util.xrn import get_authority from types import StringTypes def get_peer(api, hrn): diff --git a/sfa/plc/sfa-import-plc.py b/sfa/plc/sfa-import-plc.py index 0fed0655..637109ae 100755 --- a/sfa/plc/sfa-import-plc.py +++ b/sfa/plc/sfa-import-plc.py @@ -20,7 +20,8 @@ import tempfile from sfa.util.record import * from sfa.util.table import SfaTable -from sfa.util.namespace import get_leaf, get_authority, hostname_to_hrn, slicename_to_hrn, email_to_hrn, hrn_to_pl_slicename +from sfa.util.xrn import get_leaf, get_authority +from sfa.util.plxrn import hostname_to_hrn, slicename_to_hrn, email_to_hrn, hrn_to_pl_slicename from sfa.util.config import Config from sfa.trust.certificate import convert_public_key, Keypair from sfa.trust.trustedroot import * diff --git a/sfa/plc/sfaImport.py b/sfa/plc/sfaImport.py index 2e8f9d9a..ecad66fb 100644 --- a/sfa/plc/sfaImport.py +++ b/sfa/plc/sfaImport.py @@ -16,7 +16,8 @@ from sfa.util.sfalogging import sfa_logger_goes_to_import,sfa_logger from sfa.util.record import * from sfa.util.table import SfaTable -from sfa.util.namespace import get_authority, hrn_to_urn, email_to_hrn +from sfa.util.xrn import get_authority, hrn_to_urn +from sfa.util.plxrn import email_to_hrn from sfa.util.config import Config from sfa.trust.certificate import convert_public_key, Keypair from sfa.trust.trustedroot import * diff --git a/sfa/plc/slices.py b/sfa/plc/slices.py index 9df40c8b..c5a9c149 100644 --- a/sfa/plc/slices.py +++ b/sfa/plc/slices.py @@ -4,7 +4,8 @@ import traceback import sys from types import StringTypes -from sfa.util.namespace import get_leaf, get_authority, hrn_to_urn, hrn_to_pl_slicename, urn_to_hrn +from sfa.util.xrn import get_leaf, get_authority, hrn_to_urn, urn_to_hrn +from sfa.util.plxrn import hrn_to_pl_slicename from sfa.util.rspec import * from sfa.util.specdict import * from sfa.util.faults import * diff --git a/sfa/rspecs/aggregates/rspec_manager_max.py b/sfa/rspecs/aggregates/rspec_manager_max.py index 99b390ae..c055d2d3 100644 --- a/sfa/rspecs/aggregates/rspec_manager_max.py +++ b/sfa/rspecs/aggregates/rspec_manager_max.py @@ -3,7 +3,8 @@ from sfa.util.rspec import RSpec import sys import pdb -from sfa.util.namespace import get_authority, hrn_to_pl_slicename, +from sfa.util.xrn import get_authority +from sfa.util.plxrn import hrn_to_pl_slicename from sfa.util.rspec import * from sfa.util.specdict import * from sfa.util.faults import * diff --git a/sfa/server/aggregate.py b/sfa/server/aggregate.py index 3dee1849..f4f380ce 100644 --- a/sfa/server/aggregate.py +++ b/sfa/server/aggregate.py @@ -4,7 +4,7 @@ from sfa.util.faults import * from sfa.util.server import SfaServer -from sfa.util.namespace import hrn_to_urn +from sfa.util.xrn import hrn_to_urn from sfa.server.interface import Interfaces import sfa.util.xmlrpcprotocol as xmlrpcprotocol import sfa.util.soapprotocol as soapprotocol diff --git a/sfa/server/interface.py b/sfa/server/interface.py index 7ae027d1..0804fc1d 100644 --- a/sfa/server/interface.py +++ b/sfa/server/interface.py @@ -5,7 +5,7 @@ from sfa.util.faults import * from sfa.util.storage import * -from sfa.util.namespace import get_authority, hrn_to_urn +from sfa.util.xrn import get_authority, hrn_to_urn from sfa.trust.gid import GID from sfa.util.record import SfaRecord import traceback diff --git a/sfa/server/registry.py b/sfa/server/registry.py index 1dea183b..b7bfdd87 100644 --- a/sfa/server/registry.py +++ b/sfa/server/registry.py @@ -7,7 +7,7 @@ from sfa.util.server import SfaServer from sfa.util.faults import * -from sfa.util.namespace import hrn_to_urn +from sfa.util.xrn import hrn_to_urn from sfa.server.interface import Interfaces import sfa.util.xmlrpcprotocol as xmlrpcprotocol import sfa.util.soapprotocol as soapprotocol diff --git a/sfa/server/sfa_component_setup.py b/sfa/server/sfa_component_setup.py index 80a03a84..b0a5a478 100755 --- a/sfa/server/sfa_component_setup.py +++ b/sfa/server/sfa_component_setup.py @@ -3,10 +3,11 @@ import sys import os import tempfile from optparse import OptionParser + +from sfa.util.faults import * from sfa.util.config import Config import sfa.util.xmlrpcprotocol as xmlrpcprotocol -from sfa.util.namespace import hrn_to_pl_slicename, slicename_to_hrn -from sfa.util.faults import * +from sfa.util.plxrn import hrn_to_pl_slicename, slicename_to_hrn from sfa.trust.certificate import Keypair, Certificate from sfa.trust.credential import Credential from sfa.trust.gid import GID diff --git a/sfa/trust/auth.py b/sfa/trust/auth.py index 39522727..0b76d9ee 100644 --- a/sfa/trust/auth.py +++ b/sfa/trust/auth.py @@ -9,7 +9,7 @@ from sfa.trust.trustedroot import TrustedRootList from sfa.util.faults import * from sfa.trust.hierarchy import Hierarchy from sfa.util.config import * -from sfa.util.namespace import get_authority +from sfa.util.xrn import get_authority from sfa.util.sfaticket import * from sfa.util.sfalogging import sfa_logger diff --git a/sfa/trust/certificate.py b/sfa/trust/certificate.py index 25bb99a7..839d1df2 100644 --- a/sfa/trust/certificate.py +++ b/sfa/trust/certificate.py @@ -46,7 +46,7 @@ import M2Crypto from M2Crypto import X509 from sfa.util.sfalogging import sfa_logger -from sfa.util.namespace import urn_to_hrn +from sfa.util.xrn import urn_to_hrn from sfa.util.faults import * def convert_public_key(key): diff --git a/sfa/trust/credential.py b/sfa/trust/credential.py index 43dc7685..5aa76319 100644 --- a/sfa/trust/credential.py +++ b/sfa/trust/credential.py @@ -41,7 +41,7 @@ from sfa.trust.certificate import Keypair from sfa.trust.credential_legacy import CredentialLegacy from sfa.trust.rights import Right, Rights from sfa.trust.gid import GID -from sfa.util.namespace import urn_to_hrn +from sfa.util.xrn import urn_to_hrn # 2 weeks, in seconds DEFAULT_CREDENTIAL_LIFETIME = 86400 * 14 diff --git a/sfa/trust/gid.py b/sfa/trust/gid.py index 5976b662..94240cdd 100644 --- a/sfa/trust/gid.py +++ b/sfa/trust/gid.py @@ -25,14 +25,12 @@ # descendant of the certificate class. ## -### $Id$ -### $URL$ import xmlrpclib import uuid from sfa.util.sfalogging import sfa_logger from sfa.trust.certificate import Certificate -from sfa.util.namespace import hrn_to_urn, urn_to_hrn +from sfa.util.xrn import hrn_to_urn, urn_to_hrn ## # Create a new uuid. Returns the UUID as a string. diff --git a/sfa/trust/hierarchy.py b/sfa/trust/hierarchy.py index 0aafa5fb..0f3af465 100644 --- a/sfa/trust/hierarchy.py +++ b/sfa/trust/hierarchy.py @@ -15,7 +15,7 @@ import os from sfa.util.sfalogging import sfa_logger -from sfa.util.namespace import get_leaf, get_authority, hrn_to_urn, urn_to_hrn +from sfa.util.xrn import get_leaf, get_authority, hrn_to_urn, urn_to_hrn from sfa.trust.certificate import Keypair from sfa.trust.credential import Credential from sfa.trust.gid import GID, create_uuid diff --git a/sfa/util/namespace.py b/sfa/util/namespace.py deleted file mode 100644 index c66e5266..00000000 --- a/sfa/util/namespace.py +++ /dev/null @@ -1,153 +0,0 @@ -# -# WARNING - This file should be soon deprecated in favor of sfa.util.xrn -# -# -# WARNING - This file should be soon deprecated in favor of sfa.util.xrn -# -# -# WARNING - This file should be soon deprecated in favor of sfa.util.xrn -# -# -# WARNING - This file should be soon deprecated in favor of sfa.util.xrn -# -# -# WARNING - This file should be soon deprecated in favor of sfa.util.xrn -# -# -# WARNING - This file should be soon deprecated in favor of sfa.util.xrn -# -import re -from sfa.util.faults import * -URN_PREFIX = "urn:publicid:IDN" - -def __get_hierarchy_delim_indexes(hrn): - # find all non escaped '.' - hierarchy_delim = '([a-zA-Z0-9][\.])' - parts = re.findall(hierarchy_delim, hrn) - # list of indexes for every hierarchy delimieter - indexes = [] - for part in parts: - indexes.append(hrn.index(part) + 1) - return indexes - -def get_leaf(hrn): - delim_indexes = __get_hierarchy_delim_indexes(hrn) - if not delim_indexes: - return hrn - - last_delim_index = delim_indexes[-1:][0] + 1 - return hrn[last_delim_index:] - -def get_authority(xrn): - hrn, type = urn_to_hrn(xrn) - if type and type == 'authority': - return hrn - - delim_indexes = __get_hierarchy_delim_indexes(hrn) - if not delim_indexes: - return '' - last_delim_index = delim_indexes[-1:][0] - return hrn[:last_delim_index] - -def hrn_to_pl_slicename(hrn): - # remove any escaped no alpah numeric characters - #hrn = re.sub('\\\[^a-zA-Z0-9]', '', hrn) - hrn = re.sub(r'\\(.)', '', hrn) - parts = hrn.split(".") - return parts[-2] + "_" + parts[-1] - -# assuming hrn is the hrn of an authority, return the plc authority name -def hrn_to_pl_authname(hrn): - # remove any escaped no alpah numeric characters - hrn = re.sub(r'\\(.)', '', hrn) - parts = hrn.split(".") - return parts[-1] - -# assuming hrn is the hrn of an authority, return the plc login_base -def hrn_to_pl_login_base(hrn): - # remove any escaped no alpah numeric characters - hrn = re.sub(r'\\(.)', '', hrn) - return hrn_to_pl_authname(hrn) - -def hostname_to_hrn(auth_hrn, login_base, hostname): - """ - Convert hrn to plantelab name. - """ - sfa_hostname = ".".join([auth_hrn, login_base, hostname.split(".")[0]]) - return sfa_hostname - -def slicename_to_hrn(auth_hrn, slicename): - """ - Convert hrn to planetlab name. - """ - parts = slicename.split("_") - slice_hrn = ".".join([auth_hrn, parts[0]]) + "." + "_".join(parts[1:]) - - return slice_hrn - -def email_to_hrn(auth_hrn, email): - parts = email.split("@") - username = parts[0] - username = username.replace(".", "_").replace("+", "_") - person_hrn = ".".join([auth_hrn, username]) - - return person_hrn - -def urn_to_hrn(urn): - """ - convert a urn to hrn - return a tuple (hrn, type) - """ - - # if this is already a hrn dont do anything - if not urn or not urn.startswith(URN_PREFIX): - return urn, None - - name = urn[len(URN_PREFIX):] - urn_parts = name.split("+") - type = urn_parts.pop(2) - - - # Remove the authority name (e.g. '.sa') - if type == 'authority': - urn_parts = urn_parts[:-1] - - # convert hrn_parts (list) into hrn (str) by doing the following - # 1. remove blank elements - # 2. escape all non alpha numeric chars (excluding ':') - # 3. replace ':' with '.' (':' is the urn hierarchy delimiter) - # 4. join list elements using '.' - #hrn = '.'.join([part.replace('.', '\\.').replace(':', '.') for part in hrn_parts if part]) -# hrn = '.'.join([re.sub(r'([^a-zA-Z0-9\:])', r'\\\1', part).replace(':', '.') for part in urn_parts if part]) - hrn = '.'.join([re.sub(r'\\.', r'\\.', part).replace(':', '.') for part in urn_parts if part]) - - return str(hrn), str(type) - - -def hrn_to_urn(hrn, type=None): - """ - convert an hrn and type to a urn string - """ - # if this is already a urn dont do anything - if not hrn or hrn.startswith(URN_PREFIX): - return hrn - - if type == 'authority': - authority = hrn - name = 'sa' - else: - authority = get_authority(hrn) - name = get_leaf(hrn) - - # convert from hierarchy delimiter from '.' to ':' - authority = re.sub(r'([a-zA-Z0-9])[\.]', r'\1:', authority) - # unescape escaped characters - authority = re.sub(r'\\(.)', r'\1', authority) - - if type == None: - urn = "+".join(['',authority,name]) - else: - urn = "+".join(['',authority,type,name]) - - - return URN_PREFIX + urn diff --git a/sfa/util/record.py b/sfa/util/record.py index 6cb9d37d..a539f620 100644 --- a/sfa/util/record.py +++ b/sfa/util/record.py @@ -13,7 +13,7 @@ from sfa.trust.gid import * from sfa.util.rspec import * from sfa.util.parameter import * -from sfa.util.namespace import get_authority +from sfa.util.xrn import get_authority from sfa.util.row import Row class SfaRecord(Row): diff --git a/sfa/util/xrn.py b/sfa/util/xrn.py index 86a1f863..eb0d39e4 100644 --- a/sfa/util/xrn.py +++ b/sfa/util/xrn.py @@ -3,10 +3,9 @@ import re from sfa.util.faults import * from sfa.util.sfalogging import sfa_logger -# for convenience and smoother translation -def get_leaf(hrn): return Xrn(hrn=hrn).get_leaf() -def get_authority(hrn): return Xrn(hrn=hrn).get_authority_hrn() -# these methods we should get rid of eventually +# for convenience and smoother translation - we should get rid of these functions eventually +def get_leaf(hrn): return Xrn(xrn=hrn).get_leaf() +def get_authority(hrn): return Xrn(xrn=hrn).get_authority_hrn() def urn_to_hrn(urn): xrn=Xrn(xrn=urn); return (xrn.hrn, xrn.type) def hrn_to_urn(hrn,type): return Xrn(hrn=hrn, type=type).urn @@ -24,13 +23,13 @@ class Xrn: @staticmethod def hrn_leaf(hrn): return Xrn.hrn_split(hrn)[-1] - # e.g. hrn_path_list ('a\.b.c.d') -> ['a\.b', 'c'] + # e.g. hrn_auth_list ('a\.b.c.d') -> ['a\.b', 'c'] @staticmethod - def hrn_path_list(hrn): return Xrn.hrn_split(hrn)[0:-1] + def hrn_auth_list(hrn): return Xrn.hrn_split(hrn)[0:-1] - # e.g. hrn_path ('a\.b.c.d') -> 'a\.b.c' + # e.g. hrn_auth ('a\.b.c.d') -> 'a\.b.c' @staticmethod - def hrn_path(hrn): return '.'.join(Xrn.hrn_path_list(hrn)) + def hrn_auth(hrn): return '.'.join(Xrn.hrn_auth_list(hrn)) # e.g. escape ('a.b') -> 'a\.b' @staticmethod @@ -54,9 +53,15 @@ class Xrn: def urn_split (urn): return Xrn.urn_meaningful(urn).split('+') + #################### + # the local fields that are kept consistent + # self.urn + # self.hrn + # self.type + # self.path # provide either urn, or (hrn + type) def __init__ (self, xrn=None, urn=None, hrn=None, type=None): - if xrn: + if xrn is not None: if xrn.startswith(Xrn.URN_PREFIX): self.urn=xrn self.urn_to_hrn() @@ -64,39 +69,42 @@ class Xrn: self.hrn=xrn self.type=type self.hrn_to_urn() - elif urn: + elif urn is not None: self.urn=urn self.urn_to_hrn() - elif hrn and type: + elif hrn is not None and type is not None: self.hrn=hrn self.type=type self.hrn_to_urn() else: raise SfaAPIError,"Xrn.__init__" - if not type: - sfa_logger().debug("type-less Xrn's are not safe") +# happens all the time .. +# if not type: +# sfa_logger().debug("type-less Xrn's are not safe") def get_urn(self): return self.urn - def get_hrn(self): return (self.hrn, self.type) + def get_hrn(self): return self.hrn + def get_type(self): return self.type + def get_hrn_type(self): return (self.hrn, self.type) - def get_leaf(self): - if not self.hrn: raise SfaAPIError, "Xrn.get_leaf" + def _normalize(self): + if self.hrn is None: raise SfaAPIError, "Xrn._normalize" if not hasattr(self,'leaf'): self.leaf=Xrn.hrn_split(self.hrn)[-1] + # self.authority keeps a list + if not hasattr(self,'authority'): + self.authority=Xrn.hrn_auth_list(self.hrn) + + def get_leaf(self): + self._normalize() return self.leaf def get_authority_hrn(self): - if not self.hrn: raise SfaAPIError, "Xrn.get_authority_hrn" - # self.authority keeps a list - if not hasattr(self,'authority'): - self.authority=Xrn.hrn_path_list(self.hrn) + self._normalize() return '.'.join( self.authority ) def get_authority_urn(self): - if not self.hrn: raise SfaAPIError, "Xrn.get_authority_urn" - # self.authority keeps a list - if not hasattr(self,'authority'): - self.authority=Xrn.hrn_path_list(self.hrn) + self._normalize() return ':'.join( [Xrn.unescape(x) for x in self.authority] ) def urn_to_hrn(self): @@ -104,7 +112,8 @@ class Xrn: compute tuple (hrn, type) from urn """ - if not self.urn or not self.urn.startswith(Xrn.URN_PREFIX): +# if not self.urn or not self.urn.startswith(Xrn.URN_PREFIX): + if not self.urn.startswith(Xrn.URN_PREFIX): raise SfaAPIError, "Xrn.urn_to_hrn" parts = Xrn.urn_split(self.urn) @@ -127,14 +136,15 @@ class Xrn: compute urn from (hrn, type) """ - if not self.hrn or self.hrn.startswith(Xrn.URN_PREFIX): - raise SfaAPIError, "Xrn.hrn_to_urn" +# if not self.hrn or self.hrn.startswith(Xrn.URN_PREFIX): + if self.hrn.startswith(Xrn.URN_PREFIX): + raise SfaAPIError, "Xrn.hrn_to_urn, hrn=%s"%self.hrn if self.type == 'authority': self.authority = Xrn.hrn_split(self.hrn) name = 'sa' else: - self.authority = Xrn.hrn_path_list(self.hrn) + self.authority = Xrn.hrn_auth_list(self.hrn) name = Xrn.hrn_leaf(self.hrn) authority_string = self.get_authority_urn() diff --git a/tests/testInterfaces.py b/tests/testInterfaces.py index c43da2c7..2b358012 100755 --- a/tests/testInterfaces.py +++ b/tests/testInterfaces.py @@ -8,7 +8,7 @@ import sfa.util.xmlrpcprotocol as xmlrpc from unittest import TestCase from optparse import OptionParser from sfa.util.xmlrpcprotocol import ServerException -from sfa.util.namespace import * +from sfa.util.xrn import get_authority from sfa.util.config import * from sfa.trust.certificate import * from sfa.trust.credential import * diff --git a/tests/testNamespace.py b/tests/testNamespace.py deleted file mode 100755 index 7994bc9a..00000000 --- a/tests/testNamespace.py +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/python -import sys -import unittest - -from sfa.util.namespace import * - -class TestNamespace(unittest.TestCase): - - hrns=[ - ('plc.princeton.tmack','user'), - ('fake-pi1@onelab.eu','user'), - ('ple.inria.baris','user'), - ('emulab\.net.slice.jktest','slice'), - ] - - urns=[ - 'urn:publicid:IDN+emulab:net+slice+jktest', - 'urn:publicid:IDN+emulab.net+slice+jktest', - - ] - - def test_hrns(self): - for (h,t) in TestNamespace.hrns: - print 'testing hrn',h,t - urn=hrn_to_urn(h,t) - (h1,t1) = urn_to_hrn(urn) - self.assertEqual(h1,h) - self.assertEqual(t1,t) - if h1!=h or t1!=t: - print "hrn->urn->hrn : MISMATCH with in=(%s,%s) -- out=(%s,%s) -- urn=%s"%(h,t,h1,t1,urn) - - def test_urns(self): - for urn in TestNamespace.urns: - print 'testing urn',urn - (h,t)=urn_to_hrn(urn) - urn1 = hrn_to_urn(h,t) - self.assertEqual(urn1,urn) - if urn1!=urn: - print "urn->hrn->urn : MISMATCH with in=(%s) -- out=(%s) -- hrn=(%s,%s)"%(urn,urn1,h,t) diff --git a/tests/testXrn.py b/tests/testXrn.py index 82707ac2..9725652d 100755 --- a/tests/testXrn.py +++ b/tests/testXrn.py @@ -4,62 +4,104 @@ import unittest from sfa.util.faults import * from sfa.util.xrn import Xrn +from sfa.util.plxrn import PlXrn verbose=False class TestXrn(unittest.TestCase): - hrns=[ # hrn, type, expected_urn - ('ple.inria.baris','user', "urn:publicid:IDN+ple:inria+user+baris"), - ('emulab\.net.slice.jktest','slice', "urn:publicid:IDN+emulab.net:slice+slice+jktest"), - ('plc.princeton.tmack','user', "urn:publicid:IDN+plc:princeton+user+tmack"), - ('fake-pi1@onelab.eu','user', "urn:publicid:IDN+fake-pi1@onelab+user+eu"), - # not providing a type is currently not supported - ('fake-pi1@onelab.eu',None, None), - ] + def __hrn(self,h,t,exp_urn): + if verbose: print 'testing (',h,t,') expecting',exp_urn + if exp_urn: + xrn=Xrn(hrn=h,type=t) + if verbose: print xrn.dump_string() + urn=xrn.get_urn() + (h1,t1) = Xrn(urn=urn).get_hrn_type() + if h1!=h or t1!=t or urn!=exp_urn: + print "hrn->urn->hrn : MISMATCH with in=(%s,%s) -- out=(%s,%s) -- urn=%s"%(h,t,h1,t1,urn) + self.assertEqual(h1,h) + self.assertEqual(t1,t) + self.assertEqual(urn,exp_urn) + else: + # could not figure how to use assertFails on object construction.. + # with self.assertRaises(SfaAPIError): + # Xrn(hrn=h,type=t).get_urn() + try: + Xrn(hrn=h,type=t).get_urn() + failure="Unexpectedly created Xrn object" + except SfaAPIError: + failure=False + except Exception,e: + failure="Xrn creation raised unexpected exception %r"%e + if failure: + print "hrn->urn->hrn - %s with HRN=%s TYPE=%s"%(failure,h,t) + self.assertFalse(True) + + + def test_hrn001 (self): + self.__hrn("ple.inria.baris",'user', + "urn:publicid:IDN+ple:inria+user+baris") + def test_hnr002 (self): + self.__hrn("emulab\.net.myslice.jktest",'slice', + "urn:publicid:IDN+emulab.net:myslice+slice+jktest") + def test_hrn003(self): + self.__hrn("emulab\\.net.jktest", "slice", + "urn:publicid:IDN+emulab.net+slice+jktest") + def test_hrn004(self): + self.__hrn("plc.princeton.tmack",'user', + "urn:publicid:IDN+plc:princeton+user+tmack") + def test_hrn005(self): + self.__hrn("fake-pi1@onelab.eu",'user', + "urn:publicid:IDN+fake-pi1@onelab+user+eu") + def test_hrn006(self): + self.__hrn("plc.princeton.tmack", 'user', + "urn:publicid:IDN+plc:princeton+user+tmack" ) + def test_hrn007(self): + # not providing a type is currently not supporte + self.__hrn("fake-pi1@onelab.eu",None, + None) + def test_hrn008(self): + self.__hrn("plc.princeton.planetlab1", 'node', + "urn:publicid:IDN+plc:princeton+node+planetlab1" ) + def test_hrn009(self): + self.__hrn("plc.princeton", 'authority', + "urn:publicid:IDN+plc:princeton+authority+sa" ) + def test_hrn010(self): + self.__hrn("plc.vini.site", 'authority', + "urn:publicid:IDN+plc:vini:site+authority+sa" ) + + - urns=[ # urn, expected_hrn, expected_type - ('urn:publicid:IDN+emulab:net+slice+jktest', "emulab.net.jktest", "slice"), - ('urn:publicid:IDN+emulab.net+slice+jktest', "emulab\\.net.jktest", "slice"), - ("urn:publicid:IDN+plc:princeton+user+tmack", "plc.princeton.tmack", "user"), - ] + def test_host001 (self): + xrn=PlXrn (auth="ple.inria",hostname="onelab09.pl.sophia.inria.fr") + self.assertEqual (xrn.get_hrn_type(), ("ple.inria.onelab09",'node')) + def test_host002 (self): + xrn=PlXrn (auth="ple\\.inria",hostname="onelab09.pl.sophia.inria.fr") + self.assertEqual (xrn.get_hrn_type(), ("ple\\.inria.onelab09",'node')) + + def test_slice001 (self): + xrn=PlXrn (auth="ple",slicename="inria_omftest") + self.assertEqual (xrn.get_hrn_type(), ("ple.inria.omftest",'slice')) + + def test_person001 (self): + xrn=PlXrn (auth="ple.inria",email="first.last@some.domain.com") + self.assertEqual (xrn.get_hrn_type(), ("ple.inria.first_last",'person')) + def test_person002 (self): + xrn=PlXrn (auth="ple.inria",email="first+last@some.domain.com") + self.assertEqual (xrn.get_hrn_type(), ("ple.inria.first_last",'person')) + + + + def test_login_base_001 (self): + xrn=PlXrn(hrn='ple.inria.omftest',type='slice') + self.assertEqual(xrn.login_base(),'inria') + + def test_slicename_001 (self): + xrn=PlXrn(hrn='ple.inria.omftest',type='slice') + self.assertEqual(xrn.slicename(),'inria_omftest') + + def test_authname_001 (self): + xrn=PlXrn(hrn='ple.inria.omftest',type='slice') + self.assertEqual(xrn.authname(),'inria') - def test_hrns(self): - for (h,t,exp_urn) in TestXrn.hrns: - print 'testing (',h,t,') expecting',exp_urn - if exp_urn: - xrn=Xrn(hrn=h,type=t) - if verbose: print xrn.dump_string() - urn=xrn.get_urn() - (h1,t1) = Xrn(urn=urn).get_hrn() - if h1!=h or t1!=t or urn!=exp_urn: - print "hrn->urn->hrn : MISMATCH with in=(%s,%s) -- out=(%s,%s) -- urn=%s"%(h,t,h1,t1,urn) - self.assertEqual(h1,h) - self.assertEqual(t1,t) - self.assertEqual(urn,exp_urn) - else: - # could not figure how to use assertFails on object construction.. - # with self.assertRaises(SfaAPIError): - # Xrn(hrn=h,type=t).get_urn() - try: - Xrn(hrn=h,type=t).get_urn() - failure="Unexpectedly created Xrn object" - except SfaAPIError: - failure=False - except Exception,e: - failure="Xrn creation raised unexpected exception %r"%e - if failure: - print "hrn->urn->hrn - %s with HRN=%s TYPE=%s"%(failure,h,t) - self.assertFalse(True) - - def test_urns(self): - for (urn, exp_hrn, exp_type) in TestXrn.urns: - xrn=Xrn(urn=urn) - print 'testing urn',urn,'expecting (',exp_hrn,exp_type,')' - if verbose: print xrn.dump_string() - (h,t)=xrn.get_hrn() - urn1 = Xrn(hrn=h,type=t).get_urn() - if urn1!=urn: - print "urn->hrn->urn : MISMATCH with in=(%s) -- out=(%s) -- hrn=(%s,%s)"%(urn,urn1,h,t) - self.assertEqual(urn1,urn)