Merge "Correct env status in the new session"

This commit is contained in:
Jenkins 2016-08-22 13:56:48 +00:00 committed by Gerrit Code Review
commit 20e61be28d
4 changed files with 162 additions and 9 deletions

View File

@ -154,12 +154,25 @@ class Session(object):
request.session['sessions'] = sessions
def _update_env(env):
env.has_new_services = False
def _update_env(env, request):
# TODO(vakovalchuk): optimize latest deployment when limit is available
deployments = deployments_list(request, env.id)
if deployments:
latest_deployment = deployments[0]
deployed_services = {service['?']['id'] for service in
latest_deployment.description['services']}
else:
deployed_services = set()
if env.services:
for service in env.services:
if service['?']['status'] == 'pending':
env.has_new_services = True
current_services = {service['?']['id'] for service in env.services}
else:
current_services = set()
env.has_new_services = current_services != deployed_services
if not env.has_new_services and env.status == consts.STATUS_ID_PENDING:
env.status = consts.STATUS_ID_READY
if not env.has_new_services and env.version == 0:
if env.status == consts.STATUS_ID_READY:
@ -207,7 +220,7 @@ def environment_get(request, environment_id):
env = client.environments.get(environment_id, acquired)
Session.set(request, environment_id, acquired)
env = _update_env(env)
env = _update_env(env, request)
LOG.debug('Environment::Get {0}'.format(env))
return env

View File

@ -504,9 +504,15 @@ class ApplicationTestCase(ImageTestCase):
self.driver.find_element_by_xpath(consts.InputSubmit).click()
self.wait_for_alert_message()
def add_app_to_env(self, app_id, app_name='TestApp'):
def add_app_to_env(self, app_id, app_name='TestApp', env_id=None):
self.go_to_submenu('Browse')
self.select_and_click_action_for_app('quick-add', app_id)
if env_id:
action = 'add'
app = '{0}/{1}'.format(app_id, env_id)
else:
action = 'quick-add'
app = app_id
self.select_and_click_action_for_app(action, app)
field_id = "{0}_0-name".format(app_id)
self.fill_field(by.By.ID, field_id, value=app_name)
self.driver.find_element_by_xpath(consts.ButtonSubmit).click()
@ -514,7 +520,12 @@ class ApplicationTestCase(ImageTestCase):
self.select_from_list('osImage', self.image.id)
self.driver.find_element_by_xpath(consts.InputSubmit).click()
self.wait_for_alert_message()
if env_id:
self.driver.find_element_by_xpath(consts.InputSubmit).click()
self.wait_element_is_clickable(by.By.ID, consts.AddComponent)
self.check_element_on_page(by.By.LINK_TEXT, app_name)
else:
self.wait_for_alert_message()
class PackageTestCase(ApplicationTestCase):

View File

@ -203,6 +203,128 @@ class TestSuiteEnvironment(base.ApplicationTestCase):
c.EnvStatus.format('quick-env-2', 'Ready'),
sec=90)
def test_env_status_new_session_add_to_empty(self):
"""Test that environments status is correct in the new session
Scenario:
1. Create environment.
2. Add app to environment.
3. Check that env status is 'Ready to deploy'.
4. Log out.
5. Log in.
6. Check that env status is 'Ready to configure'.
"""
self.add_app_to_env(self.mockapp_id)
self.go_to_submenu('Environments')
self.check_element_on_page(by.By.XPATH,
c.EnvStatus.format('quick-env-1',
'Ready to deploy'))
self.log_out()
self.log_in(cfg.common.user, cfg.common.password)
self.go_to_submenu('Environments')
self.check_element_on_page(by.By.XPATH,
c.EnvStatus.format('quick-env-1',
'Ready to configure'))
def test_env_status_new_session_add_to_not_empty(self):
"""Test that environments status is correct in the new session
Scenario:
1. Create environment.
2. Add app to environment.
3. Deploy environment.
4. Add one more app to environment.
5. Check that env status is 'Ready to deploy'.
6. Log out.
7. Log in.
8. Check that env status is 'Ready'.
"""
self.add_app_to_env(self.mockapp_id)
self.driver.find_element_by_id('services__action_deploy_env').click()
self.check_element_on_page(by.By.XPATH,
c.Status.format('Ready'),
sec=90)
self.go_to_submenu('Environments')
self.check_element_on_page(by.By.LINK_TEXT, 'quick-env-1')
env_id = self.get_element_id('quick-env-1')
self.add_app_to_env(self.mockapp_id, 'TestApp1', env_id)
self.go_to_submenu('Environments')
self.check_element_on_page(by.By.XPATH,
c.EnvStatus.format('quick-env-1',
'Ready to deploy'))
self.log_out()
self.log_in(cfg.common.user, cfg.common.password)
self.go_to_submenu('Environments')
self.check_element_on_page(by.By.XPATH,
c.EnvStatus.format('quick-env-1',
'Ready'))
def test_env_status_new_session_remove_from_one(self):
"""Test that environments status is correct in the new session
Scenario:
1. Create environment.
2. Add app to environment.
3. Deploy environment.
4. Remove app from environment.
5. Check that env status is 'Ready to deploy'.
6. Log out.
7. Log in.
8. Check that env status is 'Ready'.
"""
self.add_app_to_env(self.mockapp_id)
self.driver.find_element_by_id('services__action_deploy_env').click()
self.check_element_on_page(by.By.XPATH,
c.Status.format('Ready'),
sec=90)
self.delete_component('TestApp')
self.check_element_not_on_page(by.By.LINK_TEXT, 'TestApp')
self.go_to_submenu('Environments')
self.check_element_on_page(by.By.XPATH,
c.EnvStatus.format('quick-env-1',
'Ready to deploy'))
self.log_out()
self.log_in(cfg.common.user, cfg.common.password)
self.go_to_submenu('Environments')
self.check_element_on_page(by.By.XPATH,
c.EnvStatus.format('quick-env-1',
'Ready'))
def test_env_status_new_session_remove_from_two(self):
"""Test that environments status is correct in the new session
Scenario:
1. Create environment.
2. Add two apps to environment.
3. Deploy environment.
4. Remove one app from environment.
5. Check that env status is 'Ready to deploy'.
6. Log out.
7. Log in.
8. Check that env status is 'Ready'.
"""
self.add_app_to_env(self.mockapp_id)
self.go_to_submenu('Environments')
self.check_element_on_page(by.By.LINK_TEXT, 'quick-env-1')
env_id = self.get_element_id('quick-env-1')
self.add_app_to_env(self.mockapp_id, 'TestApp1', env_id)
self.driver.find_element_by_id('services__action_deploy_env').click()
self.check_element_on_page(by.By.XPATH,
c.Status.format('Ready'),
sec=90)
self.delete_component('TestApp1')
self.check_element_not_on_page(by.By.LINK_TEXT, 'TestApp1')
self.go_to_submenu('Environments')
self.check_element_on_page(by.By.XPATH,
c.EnvStatus.format('quick-env-1',
'Ready to deploy'))
self.log_out()
self.log_in(cfg.common.user, cfg.common.password)
self.go_to_submenu('Environments')
self.check_element_on_page(by.By.XPATH,
c.EnvStatus.format('quick-env-1',
'Ready'))
class TestSuiteImage(base.ImageTestCase):
def test_mark_image(self):

View File

@ -0,0 +1,7 @@
---
fixes:
- Previously on user relogin changes to the environment made in the
previous session (adding or removing components without deploying) were
not saved but environment status was updated. Now status of environment is
'Ready to deploy' only in case when current services list is not equal to
the list of last deployed services.