Skip to content

Commit

Permalink
solving storage failure on caas test
Browse files Browse the repository at this point in the history
  • Loading branch information
ycliuhw committed Dec 13, 2018
1 parent 46e5716 commit 376c603
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
36 changes: 35 additions & 1 deletion acceptancetests/assess_caas_deploy_charms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import logging
import sys
import os
import subprocess

import requests

Expand All @@ -36,6 +37,23 @@

log = logging.getLogger("assess_caas_charm_deployment")

JUJU_STORAGECLASS_NAME = "juju-storageclass"
JUJU_STORAGECLASS_TEMPLATE = """
kind: PersistentVolume
apiVersion: v1
metadata:
name: {model}-data
spec:
capacity:
storage: 100Mi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: {class_name}
hostPath:
path: "/mnt/data/{model}"
"""


def check_app_healthy(url, timeout=300):
status_code = None
Expand Down Expand Up @@ -66,7 +84,23 @@ def assess_caas_charm_deployment(client):
raise JujuAssertionError('k8s cluster is not healthy because kubectl is not accessible')

# add caas model for deploying caas charms on top of it
k8s_model = caas_client.add_model('testcaas')
model_name = 'testcaas'
k8s_model = caas_client.add_model(model_name)

# ensure storage class
caas_client.kubectl_apply(JUJU_STORAGECLASS_TEMPLATE.format(model=model_name, class_name=JUJU_STORAGECLASS_NAME))

# ensure tmp dir for storage class.model_name
o = subprocess.check_output(
('sudo', 'mkdir', '-p', '/mnt/data/%s' % model_name) # unfortunately, needs sudo
)
log.debug(o.decode('UTF-8').strip())

# ensure storage pool
k8s_model.juju(
'create-storage-pool',
('operator-storage', 'kubernetes', 'storage-class=%s' % JUJU_STORAGECLASS_NAME)
)

gitlab_charm_path = local_charm_path(charm='caas-gitlab', juju_ver=client.version)
k8s_model.deploy(
Expand Down
5 changes: 4 additions & 1 deletion acceptancetests/deploy_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@

__metaclass__ = type

log = logging.getLogger(__name__)


LXD_PROFILE = """
name: juju-{model_name}
Expand Down Expand Up @@ -140,10 +142,11 @@ def deploy_caas_stack(bundle_path, client, timeout=3600):
model_name = client.model_name
profile = LXD_PROFILE.format(model_name=model_name)
with subprocess.Popen(('echo', profile), stdout=subprocess.PIPE) as echo:
subprocess.check_output(
o = subprocess.check_output(
('lxc', 'profile', 'edit', 'juju-%s' % model_name),
stdin=echo.stdout
).decode('UTF-8').strip()
log.debug(o)

client.deploy_bundle(bundle_path, static_bundle=True)
# Wait for the deployment to finish.
Expand Down
8 changes: 8 additions & 0 deletions acceptancetests/jujupy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2171,6 +2171,14 @@ def kubectl(self, *args):
args = (self.kubectl_path, '--kubeconfig', self.kube_config_path) + args
return subprocess.check_output(args, stderr=subprocess.STDOUT).decode('UTF-8').strip()

def kubectl_apply(self, stdin):
with subprocess.Popen(('echo', stdin), stdout=subprocess.PIPE) as echo:
o = subprocess.check_output(
(self.kubectl_path, '--kubeconfig', self.kube_config_path, 'apply', '-f', '-'),
stdin=echo.stdout
).decode('UTF-8').strip()
log.debug(o)

def get_external_hostname(self):
status = self.client.get_status()
# assume here always use single node cdk core or microk8s
Expand Down

0 comments on commit 376c603

Please sign in to comment.