Add tests for providers and update install script
This commit is contained in:
parent
0c05958739
commit
20da91d879
7 changed files with 64 additions and 10 deletions
|
@ -24,11 +24,11 @@ if [ -f /conf/stack/extra_ca_certs ]; then
|
|||
fi
|
||||
|
||||
## Add extra trusted certificates (prefixed)
|
||||
for f in $(ls /conf/stack/extra_ca* | grep -v ':$')
|
||||
for f in $(ls -p /conf/stack/extra_ca* | grep -v ':$' | grep -v '/$')
|
||||
do
|
||||
echo "Installing extra cert $f"
|
||||
cp "/conf/stack/$f" /usr/local/share/ca-certificates/
|
||||
cat "/conf/stack/$f" >> /venv/lib/python2.7/site-packages/requests/cacert.pem
|
||||
cp "$f" /usr/local/share/ca-certificates/
|
||||
cat "$f" >> /venv/lib/python2.7/site-packages/requests/cacert.pem
|
||||
done
|
||||
|
||||
# Update all CA certificates.
|
||||
|
|
|
@ -110,7 +110,7 @@ class BaseProvider(object):
|
|||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def get_volume_path(self, directory, file):
|
||||
def get_volume_path(self, directory, filename):
|
||||
""" Helper for constructing file paths, which may differ between providers. For example,
|
||||
kubernetes can't have subfolders in configmaps """
|
||||
raise NotImplementedError
|
||||
|
|
|
@ -111,5 +111,5 @@ class FileConfigProvider(BaseProvider):
|
|||
|
||||
return False
|
||||
|
||||
def get_volume_path(self, directory, file):
|
||||
return os.path.join(directory, file)
|
||||
def get_volume_path(self, directory, filename):
|
||||
return os.path.join(directory, filename)
|
||||
|
|
|
@ -144,5 +144,5 @@ class KubernetesConfigProvider(FileConfigProvider):
|
|||
request = Request(method, url, data=data, headers=headers)
|
||||
return session.send(request.prepare(), verify=False, timeout=2)
|
||||
|
||||
def get_volume_path(self, directory, file):
|
||||
return "_".join([directory, file])
|
||||
def get_volume_path(self, directory, filename):
|
||||
return "_".join([directory.rstrip('/'), filename])
|
29
util/config/provider/test/test_fileprovider.py
Normal file
29
util/config/provider/test/test_fileprovider.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
import pytest
|
||||
|
||||
from util.config.provider import FileConfigProvider
|
||||
|
||||
from test.fixtures import *
|
||||
|
||||
|
||||
class TestFileConfigProvider(FileConfigProvider):
|
||||
def __init__(self):
|
||||
self.yaml_filename = 'yaml_filename'
|
||||
self._service_token = 'service_token'
|
||||
self.config_volume = 'config_volume'
|
||||
self.py_filename = 'py_filename'
|
||||
self.yaml_path = os.path.join(self.config_volume, self.yaml_filename)
|
||||
self.py_path = os.path.join(self.config_volume, self.py_filename)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('directory,filename,expected', [
|
||||
("directory", "file", "directory/file"),
|
||||
("directory/dir", "file", "directory/dir/file"),
|
||||
("directory/dir/", "file", "directory/dir/file"),
|
||||
("directory", "file/test", "directory/file/test"),
|
||||
])
|
||||
def test_get_volume_path(directory, filename, expected):
|
||||
provider = TestFileConfigProvider()
|
||||
|
||||
assert expected == provider.get_volume_path(directory, filename)
|
||||
|
||||
|
25
util/config/provider/test/test_k8sprovider.py
Normal file
25
util/config/provider/test/test_k8sprovider.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
import pytest
|
||||
|
||||
from util.config.provider import KubernetesConfigProvider
|
||||
|
||||
from test.fixtures import *
|
||||
|
||||
|
||||
class TestKubernetesConfigProvider(KubernetesConfigProvider):
|
||||
def __init__(self):
|
||||
self.yaml_filename = 'yaml_filename'
|
||||
self._service_token = 'service_token'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('directory,filename,expected', [
|
||||
("directory", "file", "directory_file"),
|
||||
("directory/dir", "file", "directory/dir_file"),
|
||||
("directory/dir/", "file", "directory/dir_file"),
|
||||
("directory", "file/test", "directory_file/test"),
|
||||
])
|
||||
def test_get_volume_path(directory, filename, expected):
|
||||
provider = TestKubernetesConfigProvider()
|
||||
|
||||
assert expected == provider.get_volume_path(directory, filename)
|
||||
|
||||
|
|
@ -90,6 +90,6 @@ class TestConfigProvider(BaseProvider):
|
|||
self._config['SUPER_USERS'] = ['devtable']
|
||||
self.files = {}
|
||||
|
||||
def get_volume_path(self, directory, file):
|
||||
return os.path.join(directory, file)
|
||||
def get_volume_path(self, directory, filename):
|
||||
return os.path.join(directory, filename)
|
||||
|
||||
|
|
Reference in a new issue