Helm template testing

This PS lays the groundwork for testing helm packages
rendered yaml in the gate. This should allow us to test
many more configurations much more quickly.

It also fixes a problem it discovered. A broken
cinder-backup template.

Change-Id: I24a70fb4dbdbf06f8340abe3b7e72f794e09a5d9
This commit is contained in:
Kevin Fox 2017-01-30 10:30:45 -08:00
parent db4b59d296
commit e8b988469e
4 changed files with 92 additions and 1 deletions

View File

@ -52,7 +52,7 @@ spec:
},
{
"name": "initialize-cinder-logs",
"image": "{{ cinder_backup_image_full }}",
"image": "{{ $imageFull }}",
"command": [
"sh",
"-ce",

View File

@ -0,0 +1,61 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
import os
import yaml
from kolla_kubernetes.tests import base
from kolla_kubernetes.utils import ExecUtils
def _isdir(path, entry):
return os.path.isdir(os.path.join(path, entry))
class TestK8sTemplatesTest(base.BaseTestCase):
def test_validate_templates(self):
srcdir = os.environ['HELMDIR']
helmbin = os.environ['HELMBIN']
repodir = os.environ['REPODIR']
microdir = os.path.join(srcdir, "microservice")
microservices = os.listdir(microdir)
packages = [p for p in microservices if _isdir(microdir, p)]
print("Working on:")
for package in packages:
print(" %s" % package)
with open(os.path.join(microdir, package, 'Chart.yaml')) as stream:
version = yaml.load(stream)['version']
cmd = "%s template %s/%s-%s.tgz" % (helmbin, repodir,
package, version)
out, err = ExecUtils.exec_command(cmd)
if err:
raise err
l = yaml.load_all(out)
for y in l:
js = '[]'
try:
# If there is a beta init container, validate it is proper
# json
key = 'pod.beta.kubernetes.io/init-containers'
js = y['spec']['template']['metadata']['annotations'][key]
except KeyError:
pass
except TypeError as e:
m = ("'NoneType' object has no attribute '__getitem__'",
"'NoneType' object is not subscriptable")
if e.args[0] not in m:
raise
json.loads(js)

View File

@ -0,0 +1,12 @@
#!/bin/bash
mkdir -p /tmp/.helmbuild.$$
cd /tmp/.helmbuild.$$
export GOPATH=`pwd`
export PATH="$PATH:$(pwd)/bin"
mkdir -p $GOPATH/src/github.com/technosophos/
cd $GOPATH/src/github.com/technosophos/
git clone --depth=1 https://github.com/technosophos/helm-template.git
cd helm-template
make install
cd
rm -rf /tmp/.helmbuild.$$

View File

@ -3,4 +3,22 @@
grep api_interface_address ../kolla/etc/kolla/globals.yml || echo api_interface_address: "0.0.0.0" >> ../kolla/etc/kolla/globals.yml
grep tunnel_interface_address ../kolla/etc/kolla/globals.yml || echo tunnel_interface_address: "0.0.0.0" >> ../kolla/etc/kolla/globals.yml
grep orchestration_engine ../kolla/etc/kolla/globals.yml || echo orchestration_engine: KUBERNETES >> ../kolla/etc/kolla/globals.yml
#sudo yum install -y golang-bin || sudo apt-get install -y golang
#tools/build_helm_templates.sh
set -x
mkdir -p ~/.helm/plugins/template
curl -L -o /tmp/helm-template.tar.gz https://github.com/technosophos/helm-template/releases/download/2.1.3%2B1/helm-template-linux.tgz
curl -L -o /tmp/helm.tar.gz https://storage.googleapis.com/kubernetes-helm/helm-v2.1.3-linux-amd64.tar.gz
mkdir -p ~/bin
tar --strip-components 1 -C ~/bin linux-amd64/helm -zxf /tmp/helm.tar.gz
tar -C ~/.helm/plugins/template/ -zxf /tmp/helm-template.tar.gz
export PATH=$PATH:~/bin
export HOME=$(cd ~; pwd)
export HELMDIR=$(pwd)/helm
export HELMBIN=$HOME/bin/helm
export HELM_HOME=$HOME/.helm/
export REPODIR=/tmp/repo.$$
helm init -c
helm template || true
tools/helm_build_all.sh /tmp/repo.$$
python setup.py test --slowest --testr-args="$1"