Files
zaza-openstack-tests/zaza/openstack/charm_tests/tempest/utils.py
T
coreycb a67b4906ee Use juju model as workspace and store in home (#383)
* Use juju model as workspace and store in home

The current juju model will now be used as the tempest workspace name.
Additionally, all workspaces will be stored in ~/.tempest/<workspace>.

This patch also introduces a new option 'keep-workspace' that can be
specified along with other tempest options to keep the workspace after
tempest test execution. It defaults to False.

Also minor adjustment to smoke option to test boolean value.
2020-08-18 15:54:09 +02:00

68 lines
2.0 KiB
Python

# Copyright 2020 Canonical Ltd.
#
# 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.
"""Utility code for working with tempest workspaces."""
import os
from pathlib import Path
import shutil
import subprocess
import zaza.model as model
def get_workspace():
"""Get tempest workspace name and path.
:returns: A tuple containing tempest workspace name and workspace path
:rtype: Tuple[str, str]
"""
home = str(Path.home())
workspace_name = model.get_juju_model()
workspace_path = os.path.join(home, '.tempest', workspace_name)
return (workspace_name, workspace_path)
def destroy_workspace(workspace_name, workspace_path):
"""Delete tempest workspace.
:param workspace_name: name of workspace
:type workspace_name: str
:param workspace_path: directory path where workspace is stored
:type workspace_path: str
:returns: None
:rtype: None
"""
try:
subprocess.check_call(['tempest', 'workspace', 'remove', '--rmdir',
'--name', workspace_name])
except subprocess.CalledProcessError:
pass
if os.path.isdir(workspace_path):
shutil.rmtree(workspace_path)
def init_workspace(workspace_path):
"""Initialize tempest workspace.
:param workspace_path: directory path where workspace is stored
:type workspace_path: str
:returns: None
:rtype: None
"""
try:
subprocess.check_call(['tempest', 'init', workspace_path])
except subprocess.CalledProcessError:
pass