Merge "Replace exit_with_error with exceptions."

This commit is contained in:
Jenkins
2015-10-20 14:32:32 +00:00
committed by Gerrit Code Review
5 changed files with 13 additions and 10 deletions

View File

@@ -15,7 +15,7 @@
from fuelclient.cli.actions.base import Action
import fuelclient.cli.arguments as Args
from fuelclient.cli.error import exit_with_error
from fuelclient.cli.error import EnvironmentException
from fuelclient.cli.formatting import format_table
from fuelclient.cli.formatting import print_health_check
from fuelclient.objects.environment import Environment
@@ -53,7 +53,7 @@ class HealthCheckAction(Action):
env = Environment(params.env)
if env.status not in self._allowed_statuses and not params.force:
exit_with_error(
raise EnvironmentException(
"Environment is not ready to run health check "
"because it is in {0} state. "
"Health check is likely to fail because of "
@@ -61,7 +61,7 @@ class HealthCheckAction(Action):
)
if env.is_customized and not params.force:
exit_with_error(
raise EnvironmentException(
"Environment deployment facts were updated. "
"Health check is likely to fail because of "
"that. Use --force flag to proceed anyway."

View File

@@ -100,6 +100,10 @@ class InvalidFileException(FuelClientException):
pass
class EnvironmentException(Exception):
pass
def exceptions_decorator(func):
"""Handles HTTP errors and expected exceptions that may occur
in methods of APIClient class

View File

@@ -24,7 +24,7 @@ from time import sleep
import six
from fuelclient.cli.error import DeployProgressError
from fuelclient.cli.error import exit_with_error
from fuelclient.cli.error import InvalidDirectoryException
from six.moves import urllib
@@ -108,7 +108,8 @@ def download_snapshot_with_progress_bar(
to some 'directory'.
"""
if not os.path.exists(directory):
exit_with_error("Folder {0} doesn't exist.".format(directory))
raise InvalidDirectoryException(
"Folder {0} doesn't exist.".format(directory))
file_name = os.path.join(
os.path.abspath(directory),
url.split('/')[-1]

View File

@@ -15,7 +15,7 @@
from operator import attrgetter
import os
from fuelclient.cli.error import exit_with_error
from fuelclient.cli.error import InvalidDirectoryException
from fuelclient.objects.base import BaseObject
from fuelclient.objects.environment import Environment
@@ -105,7 +105,7 @@ class Node(BaseObject):
def read_attribute(self, attributes_type, directory, serializer=None):
attributes_directory = self.get_attributes_path(directory)
if not os.path.exists(attributes_directory):
exit_with_error(
raise InvalidDirectoryException(
"Folder {0} doesn't contain node folder '{1}'"
.format(directory, "node_{0}".format(self.id))
)

View File

@@ -27,7 +27,6 @@ import testtools
from fuelclient import client
from fuelclient import fuelclient_settings
from fuelclient.objects import node
from fuelclient import profiler
from fuelclient.tests.unit.v1 import base
from fuelclient.tests import utils
@@ -137,9 +136,8 @@ class ClientPerfTest(base.UnitTestCase):
self._invoke_client('env', '--list')
@mock.patch.object(node, 'exit_with_error', new_callable=mock.MagicMock)
@mock.patch('__builtin__.open', create=True)
def test_upload_node_settings(self, m_open, m_exit):
def test_upload_node_settings(self, m_open):
node_configs = [json.dumps(utils.get_fake_network_config(3))
for i in six_moves.range(self.NUMBER_OF_NODES)]