diff --git a/murano/api/v1/actions.py b/murano/api/v1/actions.py index a8ffee770..73efd9c2b 100644 --- a/murano/api/v1/actions.py +++ b/murano/api/v1/actions.py @@ -20,10 +20,10 @@ from murano.db import models from murano.db.services import environments as envs from murano.db.services import sessions from murano.db import session as db_session - from murano.openstack.common.gettextutils import _ # noqa from murano.openstack.common import log as logging from murano.services import actions +from murano.services import states LOG = logging.getLogger(__name__) @@ -50,8 +50,8 @@ class Controller(object): # no new session can be opened if environment has deploying status env_status = envs.EnvironmentServices.get_status(environment_id) - if env_status in (envs.EnvironmentStatus.DEPLOYING, - envs.EnvironmentStatus.DELETING): + if env_status in (states.EnvironmentStatus.DEPLOYING, + states.EnvironmentStatus.DELETING): LOG.info(_('Could not open session for environment ,' 'environment has deploying ' 'status.').format(environment_id)) diff --git a/murano/api/v1/sessions.py b/murano/api/v1/sessions.py index d7e586fd3..a6b1a115e 100644 --- a/murano/api/v1/sessions.py +++ b/murano/api/v1/sessions.py @@ -20,9 +20,9 @@ from murano.db import models from murano.db.services import environments as envs from murano.db.services import sessions from murano.db import session as db_session - from murano.openstack.common.gettextutils import _ # noqa from murano.openstack.common import log as logging +from murano.services import states LOG = logging.getLogger(__name__) API_NAME = 'Sessions' @@ -62,8 +62,8 @@ class Controller(object): # no new session can be opened if environment has deploying status env_status = envs.EnvironmentServices.get_status(environment_id) - if env_status in (envs.EnvironmentStatus.DEPLOYING, - envs.EnvironmentStatus.DELETING): + if env_status in (states.EnvironmentStatus.DEPLOYING, + states.EnvironmentStatus.DELETING): msg = _('Could not open session for environment ,' 'environment has deploying status.').format(environment_id) LOG.error(msg) @@ -113,7 +113,7 @@ class Controller(object): LOG.error(msg) raise exc.HTTPUnauthorized(explanation=msg) - if session.state == sessions.SessionState.DEPLOYING: + if session.state == states.SessionState.DEPLOYING: msg = _('Session is in deploying state and ' 'could not be deleted').format(session_id) LOG.error(msg) @@ -138,7 +138,7 @@ class Controller(object): LOG.error(msg) raise exc.HTTPForbidden(explanation=msg) - if session.state != sessions.SessionState.OPENED: + if session.state != states.SessionState.OPENED: msg = _('Session is already deployed or ' 'deployment is in progress').format(session_id) LOG.error(msg) diff --git a/murano/common/server.py b/murano/common/server.py index 2a5695d42..66e3ac199 100644 --- a/murano/common/server.py +++ b/murano/common/server.py @@ -25,11 +25,11 @@ from murano.common.helpers import token_sanitizer from murano.db import models from murano.db.services import environments from murano.db.services import instances -from murano.db.services import sessions from murano.db import session from murano.openstack.common.gettextutils import _ # noqa from murano.openstack.common import log as logging from murano.openstack.common import timeutils +from murano.services import states RPC_SERVICE = None @@ -96,13 +96,14 @@ class ResultEndpoint(object): #close session conf_session = unit.query(models.Session).filter_by( **{'environment_id': environment.id, - 'state': 'deploying' if not deleted else 'deleting'}).first() + 'state': states.SessionState.DEPLOYING if not deleted + else states.SessionState.DELETING}).first() if num_errors > 0: conf_session.state = \ - sessions.SessionState.DELETE_FAILURE if deleted else \ - sessions.SessionState.DEPLOY_FAILURE + states.SessionState.DELETE_FAILURE if deleted else \ + states.SessionState.DEPLOY_FAILURE else: - conf_session.state = sessions.SessionState.DEPLOYED + conf_session.state = states.SessionState.DEPLOYED conf_session.save(unit) diff --git a/murano/db/services/actions.py b/murano/db/services/actions.py index b4a1f7e72..c43b46197 100644 --- a/murano/db/services/actions.py +++ b/murano/db/services/actions.py @@ -12,7 +12,7 @@ from murano.common.helpers import token_sanitizer from murano.db import models -from murano.services import state +from murano.services import states def get_environment(session, unit): @@ -22,10 +22,11 @@ def get_environment(session, unit): def update_task(action, session, task, unit): - session.state = state.SessionState.deploying + objects = session.description.get('Objects', None) + session.state = states.SessionState.DELETING if objects is None \ + else states.SessionState.DEPLOYING task_info = models.Task() task_info.environment_id = session.environment_id - objects = session.description.get('Objects', None) if objects: task_info.description = token_sanitizer.TokenSanitizer().sanitize( dict(session.description.get('Objects'))) diff --git a/murano/db/services/environments.py b/murano/db/services/environments.py index 5701bb720..4eff4ee4a 100644 --- a/murano/db/services/environments.py +++ b/murano/db/services/environments.py @@ -12,28 +12,13 @@ # License for the specific language governing permissions and limitations # under the License. -import collections - from murano.common import uuidutils - from murano.db import models from murano.db.services import sessions from murano.db import session as db_session +from murano.services import states -EnvironmentStatus = collections.namedtuple('EnvironmentStatus', [ - 'READY', 'PENDING', 'DEPLOYING', 'DEPLOY_FAILURE', 'DELETING', - 'DELETE_FAILURE' -])( - READY='ready', - PENDING='pending', - DEPLOYING='deploying', - DEPLOY_FAILURE='deploy failure', - DELETING='deleting', - DELETE_FAILURE='delete failure' - -) - DEFAULT_NETWORKS = { 'environment': 'io.murano.resources.NeutronNetwork', # 'flat': 'io.murano.resources.ExistingNetworkConnector' @@ -75,20 +60,20 @@ class EnvironmentServices(object): session_list = sessions.SessionServices.get_sessions(environment_id) has_opened = False for session in session_list: - if session.state == sessions.SessionState.DEPLOYING: - return EnvironmentStatus.DEPLOYING - elif session.state == sessions.SessionState.DELETING: - return EnvironmentStatus.DELETING - elif session.state == sessions.SessionState.DEPLOY_FAILURE: - return EnvironmentStatus.DEPLOY_FAILURE - elif session.state == sessions.SessionState.DELETE_FAILURE: - return EnvironmentStatus.DELETE_FAILURE - elif session.state == sessions.SessionState.OPENED: + if session.state == states.SessionState.DEPLOYING: + return states.EnvironmentStatus.DEPLOYING + elif session.state == states.SessionState.DELETING: + return states.EnvironmentStatus.DELETING + elif session.state == states.SessionState.DEPLOY_FAILURE: + return states.EnvironmentStatus.DEPLOY_FAILURE + elif session.state == states.SessionState.DELETE_FAILURE: + return states.EnvironmentStatus.DELETE_FAILURE + elif session.state == states.SessionState.OPENED: has_opened = True if has_opened: - return EnvironmentStatus.PENDING + return states.EnvironmentStatus.PENDING - return EnvironmentStatus.READY + return states.EnvironmentStatus.READY @staticmethod def create(environment_params, tenant_id): @@ -169,7 +154,7 @@ class EnvironmentServices(object): if session_id: session = unit.query(models.Session).get(session_id) if sessions.SessionServices.validate(session): - if session.state != sessions.SessionState.DEPLOYED: + if session.state != states.SessionState.DEPLOYED: env_description = session.description else: env = unit.query(models.Environment) \ diff --git a/murano/db/services/sessions.py b/murano/db/services/sessions.py index f4c407ff1..1db5f4116 100644 --- a/murano/db/services/sessions.py +++ b/murano/db/services/sessions.py @@ -12,24 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. -import collections - from murano.db import models from murano.db import session as db_session from murano.services import actions - - -SessionState = collections.namedtuple('SessionState', [ - 'OPENED', 'DEPLOYING', 'DEPLOYED', 'DEPLOY_FAILURE', 'DELETING', - 'DELETE_FAILURE' -])( - OPENED='opened', - DEPLOYING='deploying', - DEPLOYED='deployed', - DEPLOY_FAILURE='deploy failure', - DELETING='deleting', - DELETE_FAILURE='delete failure' -) +from murano.services import states class SessionServices(object): @@ -38,7 +24,7 @@ class SessionServices(object): """Get list of sessions for specified environment. :param environment_id: Environment Id - :param state: glazierapi.db.services.environments.EnvironmentStatus + :param state: murano.services.states.EnvironmentStatus :return: Sessions for specified Environment, if SessionState is not defined all sessions for specified environment is returned. """ @@ -73,7 +59,7 @@ class SessionServices(object): session = models.Session() session.environment_id = environment.id session.user_id = user_id - session.state = SessionState.OPENED + session.state = states.SessionState.OPENED # used for checking if other sessions was deployed before this one session.version = environment.version # all changes to environment is stored here, and translated to @@ -105,9 +91,10 @@ class SessionServices(object): #if other session is deploying now current session is invalid other_is_deploying = unit.query(models.Session).filter_by( - environment_id=session.environment_id, state=SessionState.DEPLOYING + environment_id=session.environment_id, + state=states.SessionState.DEPLOYING ).count() > 0 - if session.state == SessionState.OPENED and other_is_deploying: + if session.state == states.SessionState.OPENED and other_is_deploying: return False return True diff --git a/murano/services/actions.py b/murano/services/actions.py index 3b4726c58..9f0c81b84 100644 --- a/murano/services/actions.py +++ b/murano/services/actions.py @@ -13,7 +13,7 @@ from murano.common import rpc from murano.db import models from murano.db.services import actions as actions_db -from murano.services import state as states +from murano.services import states class ActionServices(object): diff --git a/murano/services/state.py b/murano/services/states.py similarity index 54% rename from murano/services/state.py rename to murano/services/states.py index 13aaafc7f..96af385bb 100644 --- a/murano/services/state.py +++ b/murano/services/states.py @@ -14,7 +14,26 @@ import collections SessionState = collections.namedtuple('SessionState', [ - 'open', 'deploying', 'deployed' + 'OPENED', 'DEPLOYING', 'DEPLOYED', 'DEPLOY_FAILURE', 'DELETING', + 'DELETE_FAILURE' ])( - open='open', deploying='deploying', deployed='deployed' + OPENED='opened', + DEPLOYING='deploying', + DEPLOYED='deployed', + DEPLOY_FAILURE='deploy failure', + DELETING='deleting', + DELETE_FAILURE='delete failure' +) + +EnvironmentStatus = collections.namedtuple('EnvironmentStatus', [ + 'READY', 'PENDING', 'DEPLOYING', 'DEPLOY_FAILURE', 'DELETING', + 'DELETE_FAILURE' +])( + READY='ready', + PENDING='pending', + DEPLOYING='deploying', + DEPLOY_FAILURE='deploy failure', + DELETING='deleting', + DELETE_FAILURE='delete failure' + ) diff --git a/murano/utils.py b/murano/utils.py index 5b1461819..9d7f1da81 100644 --- a/murano/utils.py +++ b/murano/utils.py @@ -21,6 +21,7 @@ from murano.db.services import sessions from murano.db import session as db_session from murano.openstack.common.gettextutils import _ # noqa from murano.openstack.common import log as logging +from murano.services import states LOG = logging.getLogger(__name__) @@ -67,7 +68,7 @@ def verify_session(func): 'is invalid').format(session_id)) raise exc.HTTPForbidden() - if session.state == sessions.SessionState.DEPLOYING: + if session.state == states.SessionState.DEPLOYING: LOG.info(_('Session is already in ' 'deployment state').format(session_id)) raise exc.HTTPForbidden()