some exceptions refactoring

* rename the file from exc to exceptions
* move CommandException to exceptions and change it to CommandError
* use argparse required=True instead of checking in the code

Change-Id: I67450ff0acb317fa1ab3996a094e871023f5383f
This commit is contained in:
Eyal 2017-07-19 17:45:44 +03:00
parent 989a0419cc
commit 24300ee09e
7 changed files with 19 additions and 35 deletions

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from vitrageclient import exc
from vitrageclient import exceptions as exc
from keystoneauth1 import adapter as keystoneauth
from oslo_utils import importutils

View File

@ -1,22 +0,0 @@
# Copyright 2016 - Nokia Corporation
#
# 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.
class CommandException(Exception):
"""An error occurred."""
def __init__(self, message=None):
self.message = message
def __str__(self):
return self.message or self.__class__.__doc__

View File

@ -12,6 +12,10 @@
import json
class CommandError(Exception):
pass
class ClientException(Exception):
"""The base exception class for all exceptions this library raises."""
message = 'Unknown Error'

View File

@ -15,7 +15,6 @@
from cliff import lister
from cliff import show
from vitrageclient.common import exc
from vitrageclient.common import utils
@ -24,8 +23,10 @@ class TemplateValidate(show.ShowOne):
def get_parser(self, prog_name):
parser = super(TemplateValidate, self).get_parser(prog_name)
parser.add_argument('--path', help='full path for template file or '
'templates dir)')
parser.add_argument('--path',
required=True,
help='full path for template file or templates dir'
)
return parser
@property
@ -34,9 +35,6 @@ class TemplateValidate(show.ShowOne):
def take_action(self, parsed_args):
if not parsed_args.path:
raise exc.CommandException(message='No path requested, add --path')
result = utils.get_client(self).template.validate(
path=parsed_args.path)

View File

@ -11,9 +11,11 @@
# under the License.
import argparse
from cliff import show
from vitrageclient.common import exc
from vitrageclient.common import utils
from vitrageclient import exceptions as exc
# noinspection PyAbstractClass
@ -76,8 +78,8 @@ class TopologyShow(show.ShowOne):
all_tenants = parsed_args.all_tenants
if graph_type == 'graph' and limit is not None and root is None:
raise exc.CommandException(
message="Graph-type 'graph' requires a 'root' with 'limit'.")
raise exc.CommandError("Graph-type 'graph' "
"requires a 'root' with 'limit'.")
topology = utils.get_client(self).topology.get(limit=limit,
graph_type=graph_type,

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from vitrageclient.exc import ClientException
from vitrageclient.exceptions import ClientException
class HealthCheck(object):

View File

@ -11,9 +11,11 @@
# 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 os
from vitrageclient.common import exc
from vitrageclient.common import yaml_utils
from vitrageclient import exceptions as exc
class Template(object):
@ -70,4 +72,4 @@ class Template(object):
except ValueError as e:
message = 'Could not load template file: %s. Reason: %s' \
% (path, e.message)
raise exc.CommandException(message=message)
raise exc.CommandError(message)