When juju 3.x is used (installed from a snap in strict confinement) the temporary directory of the system (e.g. /tmp) can't be read by 'juju', this is used by zaza-openstack-tests to write testing policy files among other transitory files that are passed to juju's CLI. This change moves Python's default temporary file to ~/tmp unless overriden by the environment variable TEST_TMPDIR.
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
# Copyright 2018 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.
|
|
|
|
"""OpenStack specific zaza functionality."""
|
|
|
|
import os
|
|
import tempfile
|
|
|
|
|
|
# The temporary directory can't be used when juju's snap is installed in strict
|
|
# mode, so zaza-openstack-tests changes the default tmp directory to the
|
|
# directory referenced by TEST_TMPDIR otherwise a directory is created under
|
|
# the user's home.
|
|
def _set_tmpdir():
|
|
tmpdir = os.environ.get('TEST_TMPDIR')
|
|
|
|
if tmpdir and os.path.exists(tmpdir) and os.path.isdir(tmpdir):
|
|
tempfile.tempdir = tmpdir
|
|
else:
|
|
tmpdir = os.path.expanduser('~/tmp')
|
|
if not os.path.isdir(tmpdir):
|
|
os.mkdir(tmpdir, 0o770)
|
|
tempfile.tempdir = tmpdir
|
|
|
|
|
|
_set_tmpdir()
|