2018-06-28 23:42:08 +00:00
|
|
|
from storage import get_storage_driver, TYPE_LOCAL_STORAGE
|
2018-06-25 21:40:59 +00:00
|
|
|
from util.config.validators import BaseValidator, ConfigValidationException
|
2018-05-24 18:58:38 +00:00
|
|
|
|
2017-01-31 20:56:25 +00:00
|
|
|
|
|
|
|
class StorageValidator(BaseValidator):
|
|
|
|
name = "registry-storage"
|
|
|
|
|
|
|
|
@classmethod
|
2018-05-25 19:42:27 +00:00
|
|
|
def validate(cls, validator_context):
|
2017-01-31 20:56:25 +00:00
|
|
|
""" Validates registry storage. """
|
2018-05-25 19:42:27 +00:00
|
|
|
config = validator_context.config
|
|
|
|
client = validator_context.http_client
|
|
|
|
ip_resolver = validator_context.ip_resolver
|
2018-05-29 17:50:51 +00:00
|
|
|
config_provider = validator_context.config_provider
|
2018-05-25 19:42:27 +00:00
|
|
|
|
2017-01-31 20:56:25 +00:00
|
|
|
replication_enabled = config.get('FEATURE_STORAGE_REPLICATION', False)
|
|
|
|
|
2018-05-29 17:50:51 +00:00
|
|
|
providers = _get_storage_providers(config, ip_resolver, config_provider).items()
|
2017-01-31 20:56:25 +00:00
|
|
|
if not providers:
|
|
|
|
raise ConfigValidationException('Storage configuration required')
|
|
|
|
|
|
|
|
for name, (storage_type, driver) in providers:
|
2018-06-28 23:42:08 +00:00
|
|
|
# We can skip localstorage validation, since we can't guarantee that
|
|
|
|
# this will be the same machine Q.E. will run under
|
|
|
|
if storage_type == TYPE_LOCAL_STORAGE:
|
2018-06-28 20:56:33 +00:00
|
|
|
continue
|
|
|
|
|
2017-01-31 20:56:25 +00:00
|
|
|
try:
|
|
|
|
if replication_enabled and storage_type == 'LocalStorage':
|
|
|
|
raise ConfigValidationException('Locally mounted directory not supported ' +
|
|
|
|
'with storage replication')
|
|
|
|
|
|
|
|
# Run validation on the driver.
|
2018-05-25 19:42:27 +00:00
|
|
|
driver.validate(client)
|
2017-01-31 20:56:25 +00:00
|
|
|
|
|
|
|
# Run setup on the driver if the read/write succeeded.
|
|
|
|
driver.setup()
|
|
|
|
except Exception as ex:
|
2017-07-27 16:05:06 +00:00
|
|
|
msg = str(ex).strip().split("\n")[0]
|
2017-02-15 18:11:16 +00:00
|
|
|
raise ConfigValidationException('Invalid storage configuration: %s: %s' % (name, msg))
|
2017-01-31 20:56:25 +00:00
|
|
|
|
|
|
|
|
2018-05-29 17:50:51 +00:00
|
|
|
def _get_storage_providers(config, ip_resolver, config_provider):
|
2017-01-31 20:56:25 +00:00
|
|
|
storage_config = config.get('DISTRIBUTED_STORAGE_CONFIG', {})
|
|
|
|
drivers = {}
|
|
|
|
|
|
|
|
try:
|
|
|
|
for name, parameters in storage_config.items():
|
2017-09-26 20:08:50 +00:00
|
|
|
driver = get_storage_driver(None, None, None, config_provider, ip_resolver, parameters)
|
|
|
|
drivers[name] = (parameters[0], driver)
|
2017-01-31 20:56:25 +00:00
|
|
|
except TypeError:
|
|
|
|
raise ConfigValidationException('Missing required parameter(s) for storage %s' % name)
|
|
|
|
|
|
|
|
return drivers
|