Combines all exceptions into a single file
This change moves spyglass-plugin-xls's necessary exception definitions locally into the spyglass-plugin-xls project and changes their base to the SpyglassBaseException class. This change must be merged before Spyglass's exceptions may be consolidated. Related Change: https://review.opendev.org/#/c/667240/ Change-Id: I81c5ca2d9083aece3641bc8b5405dfd44baec810
This commit is contained in:
parent
e84b80c32d
commit
b0f7b952b4
@ -1,52 +0,0 @@
|
|||||||
# Copyright 2019 AT&T Intellectual Property. All other rights reserved.
|
|
||||||
#
|
|
||||||
# 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 BaseError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class NotEnoughIp(BaseError):
|
|
||||||
|
|
||||||
def __init__(self, cidr, total_nodes):
|
|
||||||
self.cidr = cidr
|
|
||||||
self.total_nodes = total_nodes
|
|
||||||
|
|
||||||
def display_error(self):
|
|
||||||
print("{} can not handle {} nodes".format(self.cidr, self.total_nodes))
|
|
||||||
|
|
||||||
|
|
||||||
class NoSpecMatched(BaseError):
|
|
||||||
|
|
||||||
def __init__(self, excel_specs):
|
|
||||||
self.specs = excel_specs
|
|
||||||
|
|
||||||
def display_error(self):
|
|
||||||
print(
|
|
||||||
"No spec matched. Following are the available specs:\n".format(
|
|
||||||
self.specs))
|
|
||||||
|
|
||||||
|
|
||||||
class ExcelFileNotSpecified(BaseError):
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def display_error():
|
|
||||||
print("Engineering excel file not specified")
|
|
||||||
|
|
||||||
|
|
||||||
class ExcelSpecNotSpecified(BaseError):
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def display_error():
|
|
||||||
print("Engineering excel spec not specified")
|
|
@ -16,12 +16,13 @@ import itertools
|
|||||||
import logging
|
import logging
|
||||||
import pprint
|
import pprint
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from spyglass.data_extractor.base import BaseDataSourcePlugin
|
from spyglass.data_extractor.base import BaseDataSourcePlugin
|
||||||
from spyglass.data_extractor import models
|
from spyglass.data_extractor import models
|
||||||
|
|
||||||
from spyglass_plugin_xls.check_exceptions import ExcelFileNotSpecified
|
|
||||||
from spyglass_plugin_xls.check_exceptions import ExcelSpecNotSpecified
|
|
||||||
from spyglass_plugin_xls.excel_parser import ExcelParser
|
from spyglass_plugin_xls.excel_parser import ExcelParser
|
||||||
|
from spyglass_plugin_xls.exceptions import ExcelFileNotSpecified
|
||||||
|
from spyglass_plugin_xls.exceptions import ExcelSpecNotSpecified
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -20,9 +20,7 @@ import re
|
|||||||
import sys
|
import sys
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from spyglass.data_extractor.custom_exceptions import NoSpecMatched
|
from spyglass_plugin_xls.exceptions import NoSpecMatched
|
||||||
|
|
||||||
# from spyglass.data_extractor.custom_exceptions
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -77,7 +75,7 @@ class ExcelParser(object):
|
|||||||
self.excel_specs["specs"][spec]["ipmi_sheet_name"] = sheet
|
self.excel_specs["specs"][spec]["ipmi_sheet_name"] = sheet
|
||||||
if self.validate_sheet(spec, sheet):
|
if self.validate_sheet(spec, sheet):
|
||||||
return spec
|
return spec
|
||||||
raise NoSpecMatched(self.excel_specs)
|
raise NoSpecMatched(excel_specs=self.excel_specs)
|
||||||
|
|
||||||
def _get_workbook(self):
|
def _get_workbook(self):
|
||||||
provided_sheetname = self.excel_specs["specs"][
|
provided_sheetname = self.excel_specs["specs"][
|
||||||
|
27
spyglass_plugin_xls/exceptions.py
Normal file
27
spyglass_plugin_xls/exceptions.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# Copyright 2019 AT&T Intellectual Property. All other rights reserved.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
from spyglass.exceptions import SpyglassBaseException
|
||||||
|
|
||||||
|
|
||||||
|
class NoSpecMatched(SpyglassBaseException):
|
||||||
|
message = 'No spec matched. The available specs are: %(excel_specs)'
|
||||||
|
|
||||||
|
|
||||||
|
class ExcelFileNotSpecified(SpyglassBaseException):
|
||||||
|
message = 'Engineering excel file not specified'
|
||||||
|
|
||||||
|
|
||||||
|
class ExcelSpecNotSpecified(SpyglassBaseException):
|
||||||
|
message = 'Engineering excel spec not specified'
|
@ -20,10 +20,10 @@ from unittest import mock
|
|||||||
import pytest
|
import pytest
|
||||||
from spyglass.data_extractor import models
|
from spyglass.data_extractor import models
|
||||||
|
|
||||||
from spyglass_plugin_xls.check_exceptions import ExcelFileNotSpecified
|
|
||||||
from spyglass_plugin_xls.check_exceptions import ExcelSpecNotSpecified
|
|
||||||
from spyglass_plugin_xls.excel import ExcelPlugin
|
from spyglass_plugin_xls.excel import ExcelPlugin
|
||||||
from spyglass_plugin_xls.excel_parser import ExcelParser
|
from spyglass_plugin_xls.excel_parser import ExcelParser
|
||||||
|
from spyglass_plugin_xls.exceptions import ExcelFileNotSpecified
|
||||||
|
from spyglass_plugin_xls.exceptions import ExcelSpecNotSpecified
|
||||||
|
|
||||||
FIXTURE_DIR = os.path.join(
|
FIXTURE_DIR = os.path.join(
|
||||||
os.path.dirname(os.path.dirname(__file__)), 'shared')
|
os.path.dirname(os.path.dirname(__file__)), 'shared')
|
||||||
|
@ -18,7 +18,7 @@ import unittest
|
|||||||
from openpyxl import Workbook
|
from openpyxl import Workbook
|
||||||
from openpyxl.worksheet.worksheet import Worksheet
|
from openpyxl.worksheet.worksheet import Worksheet
|
||||||
import pytest
|
import pytest
|
||||||
from spyglass.data_extractor.custom_exceptions import NoSpecMatched
|
from spyglass_plugin_xls.exceptions import NoSpecMatched
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from spyglass_plugin_xls.excel_parser import ExcelParser
|
from spyglass_plugin_xls.excel_parser import ExcelParser
|
||||||
|
Loading…
x
Reference in New Issue
Block a user