-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added config module for tuning various client options
Signed-off-by: Mikhail Ushanov <[email protected]>
- Loading branch information
1 parent
d5a2307
commit eb5e442
Showing
11 changed files
with
134 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,60 @@ | ||
from __future__ import unicode_literals | ||
|
||
from six import add_metaclass | ||
|
||
from object_validator import validate, ValidationError | ||
from object_validator import Integer, String, DictScheme | ||
|
||
import pyscaleio.config | ||
from pyscaleio import exceptions | ||
from pyscaleio import utils | ||
|
||
|
||
NETWORK_TIMEOUT = 30 | ||
"""Timeout for all network operations.""" | ||
|
||
REQUEST_RETRIES = 3 | ||
"""Default retries count for HTTP request.""" | ||
|
||
VOLUME_PREFIX = "/dev/disk/by-id" | ||
"""Default prefix for volume path.""" | ||
|
||
VOLUME_NAME = "emc-vol-{system_id}-{volume_id}" | ||
""" | ||
Default name for volume path on SDC. | ||
Must be parametrized with system_id and volume_id. | ||
""" | ||
|
||
|
||
@add_metaclass(utils.singleton) | ||
class ScaleIOConfig(object): | ||
"""ScaleIO config manager.""" | ||
|
||
__scheme__ = { | ||
"network_timeout": Integer(min=0, optional=True), | ||
"request_retries": Integer(min=0, optional=True), | ||
"volume_prefix": String(optional=True), | ||
"volume_name": String(optional=True), | ||
} | ||
|
||
@classmethod | ||
def _get_scheme(cls): | ||
"""Returns config scheme.""" | ||
|
||
return DictScheme(cls.__scheme__) | ||
|
||
def _validate(self, options): | ||
"""Validates config.""" | ||
|
||
try: | ||
return validate("config", options, self._get_scheme()) | ||
except ValidationError as e: | ||
raise exceptions.ScaleIOConfigError(e) | ||
|
||
def apply(self, **options): | ||
"""Applies config options to a config module.""" | ||
|
||
self._validate(options) | ||
|
||
for option, value in options.items(): | ||
setattr(pyscaleio.config, option.upper(), value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,27 @@ | ||
from __future__ import unicode_literals | ||
|
||
import pytest | ||
import mock | ||
|
||
import pyscaleio | ||
from pyscaleio import exceptions | ||
|
||
|
||
def test_config_apply(): | ||
|
||
assert pyscaleio.config.NETWORK_TIMEOUT == 30 | ||
assert pyscaleio.config.REQUEST_RETRIES == 3 | ||
assert pyscaleio.config.VOLUME_PREFIX == "/dev/disk/by-id" | ||
|
||
with mock.patch("pyscaleio.config", autospec=True): | ||
pyscaleio.configure(network_timeout=10) | ||
assert pyscaleio.config.NETWORK_TIMEOUT == 10 | ||
|
||
pyscaleio.configure(volume_prefix="/dev") | ||
assert pyscaleio.config.VOLUME_PREFIX == "/dev" | ||
|
||
with pytest.raises(exceptions.ScaleIOConfigError): | ||
pyscaleio.configure(network_timeout="timeout") | ||
|
||
with pytest.raises(exceptions.ScaleIOConfigError): | ||
pyscaleio.configure(unexist_field="value") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters