Add tests for providers and update install script

This commit is contained in:
Evan Cordell 2017-05-23 15:43:21 -04:00
parent 0c05958739
commit 20da91d879
7 changed files with 64 additions and 10 deletions

View file

@ -24,11 +24,11 @@ if [ -f /conf/stack/extra_ca_certs ]; then
fi fi
## Add extra trusted certificates (prefixed) ## 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 do
echo "Installing extra cert $f" echo "Installing extra cert $f"
cp "/conf/stack/$f" /usr/local/share/ca-certificates/ cp "$f" /usr/local/share/ca-certificates/
cat "/conf/stack/$f" >> /venv/lib/python2.7/site-packages/requests/cacert.pem cat "$f" >> /venv/lib/python2.7/site-packages/requests/cacert.pem
done done
# Update all CA certificates. # Update all CA certificates.

View file

@ -110,7 +110,7 @@ class BaseProvider(object):
""" """
raise NotImplementedError 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, """ Helper for constructing file paths, which may differ between providers. For example,
kubernetes can't have subfolders in configmaps """ kubernetes can't have subfolders in configmaps """
raise NotImplementedError raise NotImplementedError

View file

@ -111,5 +111,5 @@ class FileConfigProvider(BaseProvider):
return False return False
def get_volume_path(self, directory, file): def get_volume_path(self, directory, filename):
return os.path.join(directory, file) return os.path.join(directory, filename)

View file

@ -144,5 +144,5 @@ class KubernetesConfigProvider(FileConfigProvider):
request = Request(method, url, data=data, headers=headers) request = Request(method, url, data=data, headers=headers)
return session.send(request.prepare(), verify=False, timeout=2) return session.send(request.prepare(), verify=False, timeout=2)
def get_volume_path(self, directory, file): def get_volume_path(self, directory, filename):
return "_".join([directory, file]) return "_".join([directory.rstrip('/'), filename])

View 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)

View 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)

View file

@ -90,6 +90,6 @@ class TestConfigProvider(BaseProvider):
self._config['SUPER_USERS'] = ['devtable'] self._config['SUPER_USERS'] = ['devtable']
self.files = {} self.files = {}
def get_volume_path(self, directory, file): def get_volume_path(self, directory, filename):
return os.path.join(directory, file) return os.path.join(directory, filename)