From 4ae29f2672ecf648591c3ab9317fcc694f063618 Mon Sep 17 00:00:00 2001 From: Andrew Pashkin Date: Tue, 24 Feb 2015 14:24:55 +0300 Subject: [PATCH] Fixed logic of determining environment status DEPLOYED status of sessions was not handled properly - the bug was caused that if environment was deployed with failure it may remain with this status even if it was deployed successfully after that. Change-Id: I00309a7605067727eca4108e3fedac7bf0998847 Closes-Bug: #1413260 --- murano/db/services/environments.py | 2 + murano/tests/unit/db/services/__init__.py | 0 .../unit/db/services/test_environments.py | 65 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 murano/tests/unit/db/services/__init__.py create mode 100644 murano/tests/unit/db/services/test_environments.py diff --git a/murano/db/services/environments.py b/murano/db/services/environments.py index 09b2019c..90f40ee5 100644 --- a/murano/db/services/environments.py +++ b/murano/db/services/environments.py @@ -70,6 +70,8 @@ class EnvironmentServices(object): return states.EnvironmentStatus.DELETE_FAILURE elif session.state == states.SessionState.OPENED: has_opened = True + elif session.state == states.SessionState.DEPLOYED: + break if has_opened: return states.EnvironmentStatus.PENDING diff --git a/murano/tests/unit/db/services/__init__.py b/murano/tests/unit/db/services/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/murano/tests/unit/db/services/test_environments.py b/murano/tests/unit/db/services/test_environments.py new file mode 100644 index 00000000..5d031b93 --- /dev/null +++ b/murano/tests/unit/db/services/test_environments.py @@ -0,0 +1,65 @@ +# Copyright (c) 2015 Mirantis, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +import datetime as dt + +from oslo.utils import timeutils + +from murano.db import models +from murano.db.services import environments +from murano.db import session as db_session +from murano.services import states +from murano.tests.unit import base + + +class TestEnvironmentServices(base.MuranoWithDBTestCase): + def test_environment_ready_if_last_session_deployed_after_failed(self): + """If last session was deployed successfully and other session + was failed - environment must have status "ready". + + Bug: #1413260 + """ + OLD_VERSION = 0 + LATEST_VERSION = 1 + + session = db_session.get_session() + + environment = models.Environment( + name='test_environment', tenant_id='test_tenant_id', + version=LATEST_VERSION + ) + session.add(environment) + + now = timeutils.utcnow() + + session_1 = models.Session( + environment=environment, user_id='test_user_id_1', + version=OLD_VERSION, + state=states.SessionState.DEPLOY_FAILURE, + updated=now, description={} + ) + session_2 = models.Session( + environment=environment, user_id='test_user_id_2', + version=LATEST_VERSION, + state=states.SessionState.DEPLOYED, + updated=now + dt.timedelta(minutes=1), description={} + ) + session.add_all([session_1, session_2]) + session.flush() + + expected_status = states.EnvironmentStatus.READY + actual_status = environments.EnvironmentServices.get_status( + environment.id + ) + + self.assertEqual(actual_status, expected_status)