def on_project_added(self, name):
if name not in self._tasklet.projects:
- # Restart case, directly calling apply
try:
self._tasklet.projects[name] = \
self._class(name, self._tasklet, **(self._kw))
def on_add_prepare(self, name):
self._log.debug("Project {} to be added to {}".
format(name, self._get_tasklet_name()))
-
- try:
- self._tasklet.projects[name] = \
- self._class(name, self._tasklet, **(self._kw))
- except Exception as e:
- self._log.exception("Project {} create for {} failed: {}".
- format(name, self._get_tasklet_name(), e))
- raise e
-
- try:
- yield from self._get_project(name).register()
- except Exception as e:
- self._log.exception("Project {} register for tasklet {} failed: {}".
- format(name, self._get_tasklet_name(), e))
- raise e
+ if name in self._tasklet.projects:
+ self._log.error("Project {} already exists for {}".
+ format(name, self._get_tasklet_name()))
@asyncio.coroutine
def on_delete_prepare(self, name):
else:
self._log.debug("Project {}: Invoking on_prepare add request".
format(name))
- yield from self._callbacks.on_add_prepare(name, msg)
-
+ rc, err_msg = yield from self._callbacks.on_add_prepare(name, msg)
+ if rc is False:
+ xact_info.send_error_xpath(RwTypes.RwStatus.FAILURE,
+ ProjectDtsHandler.XPATH,
+ err_msg)
+ xact_info.respond_xpath(rwdts.XactRspCode.NACK)
+ return
elif action == rwdts.QueryAction.DELETE:
# Check if the entire project got deleted
self._loop = tasklet.loop
self._class = project_class
+ self.mano_roles = [role['mano-role'] for role in MANO_PROJECT_ROLES]
+
self._log.debug("Creating project config handler")
self.project_cfg_handler = ProjectDtsHandler(
self._dts, self._log,
def on_project_added(self, name, cfg):
if name not in self._tasklet.projects:
- # Restart case, directly calling apply
try:
self._tasklet.projects[name] = \
self._class(name, self._tasklet)
self._log.debug("Project {} to be added to {}".
format(name, self._get_tasklet_name()))
- try:
- self._tasklet.projects[name] = \
- self._class(name, self._tasklet)
- except Exception as e:
- self._log.exception("Project {} create for {} failed: {}".
- format(name, self._get_tasklet_name(), e))
+ if name in self._tasklet.projects:
+ err_msg = ("Project already exists: {}".
+ format(name))
+ self._log.error(err_msg)
+ return False, err_msg
+ # Validate mano-roles, if present
try:
- yield from self._get_project(name).register()
- except Exception as e:
- self._log.exception("Project {} register for tasklet {} failed: {}".
- format(name, self._get_tasklet_name(), e))
-
- self._log.debug("Project {} added to {}".
- format(name, self._get_tasklet_name()))
+ cfg = msg.project_config
+ users = cfg.user
+ for user in users:
+ for role in user.mano_role:
+ if role.role not in self.mano_roles:
+ err_msg = ("Invalid role {} for user {} in project {}".
+ format(role.role, user.user_name, name))
+ self._log.error(err_msg)
+ return False, err_msg
+
+ except AttributeError as e:
+ # If the user or mano role is not present, ignore
+ self._log.debug("Project {}: {}".format(name, e))
+
+ return True, ""
@asyncio.coroutine
def on_delete_prepare(self, name):