diff --git a/fuel_upgrade_system/fuel_upgrade/fuel_upgrade/before_upgrade_checker.py b/fuel_upgrade_system/fuel_upgrade/fuel_upgrade/before_upgrade_checker.py index 416838b80c..1e04fd7bc9 100644 --- a/fuel_upgrade_system/fuel_upgrade/fuel_upgrade/before_upgrade_checker.py +++ b/fuel_upgrade_system/fuel_upgrade/fuel_upgrade/before_upgrade_checker.py @@ -17,6 +17,7 @@ import abc import logging +import requests import six from fuel_upgrade import errors @@ -55,7 +56,13 @@ class CheckNoRunningTasks(BaseBeforeUpgradeChecker): running tasks """ logger.info('Check nailgun tasks') - tasks = self.nailgun_client.get_tasks() + + try: + tasks = self.nailgun_client.get_tasks() + except requests.ConnectionError: + raise errors.NailgunIsNotRunningError( + 'Cannot connect to rest api service') + logger.debug('Nailgun tasks {0}'.format(tasks)) running_tasks = filter( diff --git a/fuel_upgrade_system/fuel_upgrade/fuel_upgrade/cli.py b/fuel_upgrade_system/fuel_upgrade/fuel_upgrade/cli.py index 61a9a16430..698f347de2 100644 --- a/fuel_upgrade_system/fuel_upgrade/fuel_upgrade/cli.py +++ b/fuel_upgrade_system/fuel_upgrade/fuel_upgrade/cli.py @@ -64,6 +64,8 @@ def handle_exception(exc): print(messages.docker_is_dead) elif isinstance(exc, errors.UpgradeVerificationError): print(messages.health_checker_failed) + elif isinstance(exc, errors.NailgunIsNotRunningError): + print(messages.nailgun_is_not_running) sys.exit(-1) diff --git a/fuel_upgrade_system/fuel_upgrade/fuel_upgrade/errors.py b/fuel_upgrade_system/fuel_upgrade/fuel_upgrade/errors.py index bae9525c84..1f906d7c6e 100644 --- a/fuel_upgrade_system/fuel_upgrade/fuel_upgrade/errors.py +++ b/fuel_upgrade_system/fuel_upgrade/fuel_upgrade/errors.py @@ -75,3 +75,7 @@ class WrongVersionError(FuelUpgradeException): class UnsupportedActionTypeError(FuelUpgradeException): pass + + +class NailgunIsNotRunningError(FuelUpgradeException): + pass diff --git a/fuel_upgrade_system/fuel_upgrade/fuel_upgrade/messages.py b/fuel_upgrade_system/fuel_upgrade/fuel_upgrade/messages.py index f47ed0c8e2..aa4948d496 100644 --- a/fuel_upgrade_system/fuel_upgrade/fuel_upgrade/messages.py +++ b/fuel_upgrade_system/fuel_upgrade/fuel_upgrade/messages.py @@ -37,6 +37,15 @@ https://bugs.launchpad.net/fuel/+bug/1359725 """ +nailgun_is_not_running = """ +REST API service (nailgun) is not running. Unable to verify that +there are no running tasks. + +Use `--no-check` as a parameter for upgrade script to skip all +pre-upgrade checks. +""" + + health_checker_failed = """ Couldn't start some of the services, try to run upgrade again. """ diff --git a/fuel_upgrade_system/fuel_upgrade/fuel_upgrade/tests/test_before_upgrade_checker.py b/fuel_upgrade_system/fuel_upgrade/fuel_upgrade/tests/test_before_upgrade_checker.py index 5cafe3bc88..3b809ba91a 100644 --- a/fuel_upgrade_system/fuel_upgrade/fuel_upgrade/tests/test_before_upgrade_checker.py +++ b/fuel_upgrade_system/fuel_upgrade/fuel_upgrade/tests/test_before_upgrade_checker.py @@ -16,6 +16,8 @@ import mock +import requests + from fuel_upgrade.before_upgrade_checker import CheckFreeSpace from fuel_upgrade.before_upgrade_checker import CheckNoRunningTasks from fuel_upgrade.before_upgrade_checker import CheckUpgradeVersions @@ -56,6 +58,17 @@ class TestCheckNoRunningTasks(BaseTestCase): checker.check() self.called_once(get_tasks_mock) + @mock.patch('fuel_upgrade.before_upgrade_checker.NailgunClient.get_tasks', + side_effect=requests.ConnectionError('')) + def test_check_raises_error_if_nailgun_is_not_running( + self, get_tasks_mock): + checker = CheckNoRunningTasks(self.config) + self.assertRaisesRegexp( + errors.NailgunIsNotRunningError, + 'Cannot connect to rest api service', + checker.check) + self.called_once(get_tasks_mock) + @mock.patch('fuel_upgrade.before_upgrade_checker.utils.find_mount_point', side_effect=['/var', '/var', '/etc'])