X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=rwlaunchpad%2Fplugins%2Frwstagingmgr%2Frift%2Ftasklets%2Frwstagingmgr%2Fstore%2Ffile_store.py;fp=rwlaunchpad%2Fplugins%2Frwstagingmgr%2Frift%2Ftasklets%2Frwstagingmgr%2Fstore%2Ffile_store.py;h=9adce9af40694bab57b674f40c9dda9dfbccbd6c;hb=4870d0ee29789b859931e4e2c73e13dcb29537d5;hp=aec4180bf634cad2257582200bceae1c2dea6df6;hpb=6f1a3fe149e4a6b9803382cb299c902f4cf58ec9;p=osm%2FSO.git diff --git a/rwlaunchpad/plugins/rwstagingmgr/rift/tasklets/rwstagingmgr/store/file_store.py b/rwlaunchpad/plugins/rwstagingmgr/rift/tasklets/rwstagingmgr/store/file_store.py index aec4180b..9adce9af 100644 --- a/rwlaunchpad/plugins/rwstagingmgr/rift/tasklets/rwstagingmgr/store/file_store.py +++ b/rwlaunchpad/plugins/rwstagingmgr/rift/tasklets/rwstagingmgr/store/file_store.py @@ -33,6 +33,7 @@ import gi gi.require_version("RwStagingMgmtYang", "1.0") from gi.repository import RwStagingMgmtYang import rift.mano.dts as mano_dts +from rift.mano.utils.project import DEFAULT_PROJECT from .. import model from ..protocol import StagingStorePublisherProtocol @@ -53,9 +54,9 @@ class StagingFileStore(StagingStorePublisherProtocol): META_YAML = "meta.yaml" DEFAULT_EXPIRY = 60 * 60 - def __init__(self, log=None, root_dir=None): + def __init__(self, tasklet, root_dir=None): default_path = os.path.join( - os.getenv('RIFT_ARTIFACTS'), + os.getenv('RIFT_VAR_ROOT'), "launchpad/staging") self.root_dir = root_dir or default_path @@ -63,11 +64,11 @@ class StagingFileStore(StagingStorePublisherProtocol): if not os.path.isdir(self.root_dir): os.makedirs(self.root_dir) - self.log = log or logging.getLogger() + self.log = tasklet.log self.tmp_dir = tempfile.mkdtemp(dir=self.root_dir) self._cache = {} - self.delegate = None + self.tasklet = tasklet def on_recovery(self, staging_areas): for area in staging_areas: @@ -82,6 +83,20 @@ class StagingFileStore(StagingStorePublisherProtocol): return self._cache[area_id] + def get_delegate(self, project_name): + if not project_name: + project_name = DEFAULT_PROJECT + + try: + proj = self.tasklet.projects[project_name] + except Exception as e: + err = "Project or project name not found {}: {}". \ + format(msg.as_dict(), e) + self.log.error (err) + raise Exception (err) + + return proj.publisher + def create_staging_area(self, staging_area_config): """Create the staging area Args: @@ -93,6 +108,8 @@ class StagingFileStore(StagingStorePublisherProtocol): Raises: StagingAreaExists: if the staging area already exists """ + delegate = self.get_delegate(staging_area_config.project_name) + area_id = str(uuid.uuid4()) container_path = os.path.join(self.root_dir, str(area_id)) @@ -112,16 +129,16 @@ class StagingFileStore(StagingStorePublisherProtocol): "path": container_path }) - staging_area = RwStagingMgmtYang.StagingArea.from_dict(config_dict) + staging_area = RwStagingMgmtYang.YangData_RwProject_Project_StagingAreas_StagingArea.from_dict(config_dict) staging_area = model.StagingArea(staging_area) self._cache[area_id] = staging_area try: - if self.delegate: - self.delegate.on_staging_area_create(staging_area.model) + if delegate: + delegate.on_staging_area_create(staging_area.model) except Exception as e: - self.log.exception(str(e)) + self.log.exception(e) return staging_area @@ -134,13 +151,15 @@ class StagingFileStore(StagingStorePublisherProtocol): if type(staging_area) is str: staging_area = self.get_staging_area(staging_area) + delegate = self.get_delegate(staging_area.project_name) + if os.path.isdir(staging_area.model.path): shutil.rmtree(staging_area.model.path) staging_area.model.status = "EXPIRED" try: - if self.delegate: - self.delegate.on_staging_area_delete(staging_area.model) + if delegate: + delegate.on_staging_area_delete(staging_area.model) except Exception as e: - self.log.exception(str(e)) + self.log.exception(e)