Update environment statuses

* Do not create session in case of observing environment applications
* Forbid redeployment after failed deploy since it's not working
* Do not show 'Deploy Environment' when environment status is 'ready'

Change-Id: I90a673d82c528ea9f05dfe1967d6c5d3d1df228c
Closes-Bug: #1342404
This commit is contained in:
Ekaterina Fedorova 2014-08-22 18:41:13 +04:00 committed by Ekaterina Chernova
parent f1bb16e065
commit d3a6d9bc81
3 changed files with 33 additions and 26 deletions

View File

@ -122,8 +122,7 @@ class Session(object):
"""
#We store opened sessions for each environment in dictionary per user
sessions = request.session.get('sessions', {})
session_id = sessions[environment_id] \
if environment_id in sessions else None
session_id = sessions.get(environment_id, '')
if session_id:
LOG.debug("Using session_id {0} for the environment {1}".format(
session_id, environment_id))
@ -133,6 +132,19 @@ class Session(object):
return session_id
def _update_env(env):
env.has_new_services = False
if env.services:
for service in env.services:
if service['?']['status'] == 'pending':
env.has_new_services = True
if not env.has_new_services and env.version == 0:
if env.status == consts.STATUS_ID_READY:
env.status = consts.STATUS_ID_NEW
return env
def environments_list(request):
environments = []
client = api.muranoclient(request)
@ -140,15 +152,8 @@ def environments_list(request):
environments = client.environments.list()
LOG.debug('Environment::List {0}'.format(environments))
for index, env in enumerate(environments):
environments[index].has_services = False
environment = environment_get(request, env.id)
for service in environment.services or []:
if service:
environments[index].has_services = True
break
if not environments[index].has_services:
if environments[index].status == consts.STATUS_ID_READY:
environments[index].status = consts.STATUS_ID_NEW
environments[index] = environment_get(request, env.id)
return environments
@ -171,6 +176,8 @@ def environment_get(request, environment_id):
format(environment_id, session_id))
client = api.muranoclient(request)
env = client.environments.get(environment_id, session_id)
env = _update_env(env)
LOG.debug('Environment::Get {0}'.format(env))
return env
@ -194,7 +201,7 @@ def services_list(request, environment_id):
services = []
# need to create new session to see services deployed be other user
session_id = Session.get_or_create(request, environment_id)
session_id = Session.get(request, environment_id)
get_environment = api.muranoclient(request).environments.get
environment = get_environment(environment_id, session_id)
@ -202,6 +209,8 @@ def services_list(request, environment_id):
client = api.muranoclient(request)
reports = client.environments.last_status(environment_id, session_id)
except exc.HTTPNotFound:
LOG.exception(_('Could not get last status for '
'the {0} environment').format(environment_id))
reports = {}
for service_item in environment.services or []:

View File

@ -38,7 +38,9 @@ STATUS_ID_DELETE_FAILURE = 'delete failure'
STATUS_ID_DEPLOY_FAILURE = 'deploy failure'
STATUS_ID_NEW = 'new'
NO_ACTION_ALLOWED_STATUSES = (STATUS_ID_DEPLOYING, STATUS_ID_DELETING)
NO_ACTION_ALLOWED_STATUSES = (STATUS_ID_DEPLOYING,
STATUS_ID_DELETING,
STATUS_ID_DEPLOY_FAILURE)
DEP_STATUS_ID_RUNNING = 'running'
DEP_STATUS_ID_RUNNING_W_ERRORS = 'running_w_errors'

View File

@ -22,7 +22,6 @@ from horizon import tables
from muranodashboard.environments import api
from muranodashboard.environments import consts
from muranodashboard.openstack.common import timeutils
def _get_environment_status_and_version(request, table):
@ -67,17 +66,12 @@ class CreateEnvironment(tables.LinkAction):
class DeleteEnvironment(tables.DeleteAction):
data_type_singular = _('Environment')
data_type_plural = _('Environments')
action_past = _('Start Deleting')
def allowed(self, request, environment):
if environment:
environment = api.environment_get(request, environment.id)
if environment.status == consts.STATUS_ID_DEPLOYING:
deployment = api.deployments_list(request, environment.id)[0]
last_action = timeutils.parse_strtime(
deployment.started.replace(' ', 'T'),
timeutils._ISO8601_TIME_FORMAT)
return timeutils.is_older_than(last_action, 15 * 60)
return environment.status not in consts.NO_ACTION_ALLOWED_STATUSES
return environment.status not in (consts.STATUS_ID_DEPLOYING,
consts.STATUS_ID_DELETING)
return True
def action(self, request, environment_id):
@ -102,6 +96,7 @@ class EditEnvironment(tables.LinkAction):
class DeleteService(tables.DeleteAction):
data_type_singular = _('Component')
data_type_plural = _('Components')
action_past = _('Start Deleting')
def allowed(self, request, service=None):
status, version = _get_environment_status_and_version(request,
@ -132,9 +127,9 @@ class DeployEnvironment(tables.BatchAction):
def allowed(self, request, environment):
status = getattr(environment, 'status', None)
if status not in consts.NO_ACTION_ALLOWED_STATUSES:
return True
if environment.version == 0 and not environment.has_services:
if not environment.has_new_services:
return False
if status in consts.NO_ACTION_ALLOWED_STATUSES:
return False
return True
@ -156,7 +151,8 @@ class DeployThisEnvironment(tables.Action):
def allowed(self, request, service):
status, version = _get_environment_status_and_version(request,
self.table)
if status == consts.STATUS_ID_DEPLOYING:
if (status in consts.NO_ACTION_ALLOWED_STATUSES
or status == consts.STATUS_ID_READY):
return False
apps = self.table.data