This commit adds Keystone audit middleware API logging to the Cinder charm in versions Yoga and newer to allow users to configure their environment for CADF compliance. This feature can be enabled/disabled and is set to 'disabled' by default to avoid bloat in log files. The logging output is configured to /var/log/apache2/cinder_error.log. This commit builds on previous discussions: https://github.com/juju/charm-helpers/pull/808. Related-Pr: https://github.com/juju/charm-helpers/pull/893 func-test-pr: https://github.com/openstack-charmers/zaza-openstack-tests/pull/1200 Closes-Bug: 1856555 Change-Id: Ia7dbd6af2305e92eaa9a65890644c4a324ab2c65
62 lines
2.1 KiB
Python
62 lines
2.1 KiB
Python
import platform
|
|
import os
|
|
|
|
|
|
def get_platform():
|
|
"""Return the current OS platform.
|
|
|
|
For example: if current os platform is Ubuntu then a string "ubuntu"
|
|
will be returned (which is the name of the module).
|
|
This string is used to decide which platform module should be imported.
|
|
"""
|
|
current_platform = _get_current_platform()
|
|
|
|
if "Ubuntu" in current_platform:
|
|
return "ubuntu"
|
|
elif "CentOS" in current_platform:
|
|
return "centos"
|
|
elif "debian" in current_platform or "Debian" in current_platform:
|
|
# Stock Python does not detect Ubuntu and instead returns debian.
|
|
# Or at least it does in some build environments like Travis CI
|
|
return "ubuntu"
|
|
elif "elementary" in current_platform:
|
|
# ElementaryOS fails to run tests locally without this.
|
|
return "ubuntu"
|
|
elif "Pop!_OS" in current_platform:
|
|
# Pop!_OS also fails to run tests locally without this.
|
|
return "ubuntu"
|
|
else:
|
|
raise RuntimeError("This module is not supported on {}."
|
|
.format(current_platform))
|
|
|
|
|
|
def _get_current_platform():
|
|
"""Return the current platform information for the OS.
|
|
|
|
Attempts to lookup linux distribution information from the platform
|
|
module for releases of python < 3.7. For newer versions of python,
|
|
the platform is determined from the /etc/os-release file.
|
|
"""
|
|
# linux_distribution is deprecated and will be removed in Python 3.7
|
|
# Warnings *not* disabled, as we certainly need to fix this.
|
|
if hasattr(platform, 'linux_distribution'):
|
|
tuple_platform = platform.linux_distribution()
|
|
current_platform = tuple_platform[0]
|
|
else:
|
|
current_platform = _get_platform_from_fs()
|
|
|
|
return current_platform
|
|
|
|
|
|
def _get_platform_from_fs():
|
|
"""Get Platform from /etc/os-release."""
|
|
with open(os.path.join(os.sep, 'etc', 'os-release')) as fin:
|
|
content = dict(
|
|
line.split('=', 1)
|
|
for line in fin.read().splitlines()
|
|
if '=' in line
|
|
)
|
|
for k, v in content.items():
|
|
content[k] = v.strip('"')
|
|
return content["NAME"]
|