Add license validation to the config validation check
Should prevent a customer from accidentally saving a config that violates their license Fixes https://jira.coreos.com/browse/QS-97
This commit is contained in:
parent
024c183f67
commit
72bfebdb60
5 changed files with 75 additions and 0 deletions
48
util/config/validators/test/test_validate_license.py
Normal file
48
util/config/validators/test/test_validate_license.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
import pytest
|
||||
|
||||
from mock import patch
|
||||
|
||||
from util.config.validators import ConfigValidationException
|
||||
from util.config.validators.validate_license import LicenseValidator
|
||||
from util.morecollections import AttrDict
|
||||
from util.license import License, QUAY_DEPLOYMENTS_ENTITLEMENT, QUAY_ENTITLEMENT
|
||||
|
||||
from test.fixtures import *
|
||||
|
||||
@pytest.mark.parametrize('deployments, allowed_deployments', [
|
||||
(1, 1),
|
||||
(3, 3),
|
||||
(3, 2),
|
||||
(3, 1),
|
||||
])
|
||||
def test_too_many_storage_engines(deployments, allowed_deployments, app):
|
||||
def get_license():
|
||||
decoded = {
|
||||
'expirationDate': '2157-12-1',
|
||||
'subscriptions': {
|
||||
'someSubscription': {
|
||||
'serviceEnd': '2157-12-1',
|
||||
'durationPeriod': 'yearly',
|
||||
'entitlements': {
|
||||
QUAY_ENTITLEMENT: 1,
|
||||
QUAY_DEPLOYMENTS_ENTITLEMENT: allowed_deployments,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
return License(decoded)
|
||||
|
||||
storage_configs = [(str(i), {}) for i in range(0, deployments)]
|
||||
|
||||
with patch('app.config_provider.get_license', get_license):
|
||||
validator = LicenseValidator()
|
||||
|
||||
if allowed_deployments < deployments:
|
||||
with pytest.raises(ConfigValidationException):
|
||||
validator.validate({
|
||||
'DISTRIBUTED_STORAGE_CONFIG': storage_configs,
|
||||
}, None, None)
|
||||
else:
|
||||
validator.validate({
|
||||
'DISTRIBUTED_STORAGE_CONFIG': storage_configs,
|
||||
}, None, None)
|
Reference in a new issue