Skip to content

Commit

Permalink
expand user when deserializing configuration (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop committed Jan 12, 2019
1 parent f34cec6 commit 76247d3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions nornir/core/deserializer/configuration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import importlib
import logging
from pathlib import Path
from typing import Any, Callable, Dict, List, Optional, Type, cast

from nornir.core import configuration
Expand All @@ -25,6 +26,7 @@ class Config:
@classmethod
def deserialize(cls, **kwargs) -> configuration.SSHConfig:
s = SSHConfig(**kwargs)
s.config_file = str(Path(s.config_file).expanduser())
return configuration.SSHConfig(**s.dict())


Expand Down
5 changes: 3 additions & 2 deletions tests/core/deserializer/test_configuration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
from pathlib import Path

from nornir.core.configuration import Config
from nornir.plugins.inventory.simple import SimpleInventory
Expand Down Expand Up @@ -83,7 +84,7 @@ def test_deserialize_defaults(self):
assert not c.logging.to_console
assert c.logging.loggers == ["nornir"]

assert c.ssh.config_file == "~/.ssh/config"
assert c.ssh.config_file == str(Path("~/.ssh/config").expanduser())

assert c.inventory.plugin == SimpleInventory
assert c.inventory.options == {}
Expand All @@ -110,7 +111,7 @@ def test_deserialize_basic(self):
assert not c.logging.to_console
assert c.logging.loggers == ["nornir"]

assert c.ssh.config_file == "~/.ssh/alt_config"
assert c.ssh.config_file == str(Path("~/.ssh/alt_config").expanduser())

assert c.inventory.plugin == AnsibleInventory
assert c.inventory.options == {}
Expand Down

0 comments on commit 76247d3

Please sign in to comment.