Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding deprecation message for db storage type as file in config #559

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pebblo/app/config/config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ def validate(self):
if not os.path.exists(expand_path(str(default_location))):
os.makedirs(expand_path(str(default_location)), exist_ok=True)

@staticmethod
def validate_input(input_dict):
deprecate_error = f"DeprecationWarning: '{StorageTypes.FILE.value}' in storage type is deprecated, use '{StorageTypes.DATABASE.value}' instead"

valid_storage_type = [storage_type.value for storage_type in StorageTypes]
input_storage_type = input_dict.get("storage", {}).get("type")
if input_storage_type not in valid_storage_type:
raise Exception(
f"Either '{StorageTypes.FILE.value}' or '{StorageTypes.DATABASE.value}' should be there in storage type"
)

if StorageTypes.FILE.value in input_storage_type:
print(deprecate_error)
return input_dict


def expand_path(file_path: str) -> str:
# Expand user (~) and environment variables
Expand Down Expand Up @@ -177,6 +192,7 @@ def validate_input(input_dict):
"""This function is used to validate input of config file"""
validators = {
"reports": ReportsConfig,
"storage": StorageConfig,
}

validation_errors = []
Expand Down
1 change: 0 additions & 1 deletion pebblo/app/enums/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class StorageTypes(Enum):

class DBStorageTypes(Enum):
SQLITE = "sqlite"
MONGODB = "mongodb"


class ClassificationMode(Enum):
Expand Down
40 changes: 40 additions & 0 deletions tests/app/config/test_config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
DaemonConfig,
LoggingConfig,
ReportsConfig,
StorageConfig,
validate_config,
)

Expand Down Expand Up @@ -169,6 +170,45 @@ def test_classifier_config_validate():
]


def test_storage_config_validate():
# Test with storage type `file` correct value
storage = {"type": "file"}
validator = StorageConfig(storage)
validator.validate()
assert validator.errors == []

# Test with storage type `db` correct value
storage = {"type": "db", "db": "sqlite", "name": "pebblo_db"}
validator = StorageConfig(storage)
validator.validate()
assert validator.errors == []

# Test with wrong storage type
storage = {"type": "xyz"}
validator = StorageConfig(storage)
validator.validate()
assert validator.errors == [
"Error: Unsupported storage type 'xyz' specified in the configuration.Valid values are ['file', 'db']"
]

# Test with storage type as `db` wrong `db` value
storage = {"type": "db", "db": "db123", "name": "pebblo_db"}
validator = StorageConfig(storage)
validator.validate()
assert validator.errors == [
"Error: Unsupported db type 'db123' specified in the configuration.Valid values are ['sqlite']"
]

# Test with storage type as `db` without `db` and `name`
storage = {"type": "db"}
validator = StorageConfig(storage)
validator.validate()
assert validator.errors == [
"Error: Unsupported db type 'None' specified in the configuration.Valid values are ['sqlite']",
"Error: Unsupported db name 'None specified in the configurationString values are allowed only",
]


def test_validate_config(setup_and_teardown):
# Test with valid configuration
config = {
Expand Down