Skip to content

Commit

Permalink
Added logserver and fixed Glidein log token and URL propagation
Browse files Browse the repository at this point in the history
Added php and python example for a server receiving Glidein logs

Fixed JWT generation and GLIDEIN_LOG_RECIPIENTS_FACTORY param for Factory logserver, improved also code and docstrings, and added documentation for logging and log server

Added example custom script using Glidein logging

Fixed mod_ssl dependency and fixed ReleaseManagerLib bugs and replaced deprecated optparse with argparse

Added the glideinwms-logserver RPM and adjusted ReleaseManagerLib for it
  • Loading branch information
mambelli committed Dec 18, 2024
1 parent d64a273 commit 0531bf3
Show file tree
Hide file tree
Showing 18 changed files with 854 additions and 197 deletions.
4 changes: 4 additions & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Files: .codecov.yml .coveragerc .editorconfig .gitattributes .gitignore .gitmodu
Copyright: 2009 Fermi Research Alliance, LLC
License: Apache-2.0

Files: logserver/logging_config.json
Copyright: 2009 Fermi Research Alliance, LLC
License: Apache-2.0

Files: .github/ISSUE_TEMPLATE/* bigfiles/* etc/* config/* creation/templates/*.service creation/templates/*.cron creation/templates/*.timer doc/tags*txt lib/logging.conf test/bats/fixtures/* unittests/*.fixture unittests/fixtures/*
Copyright: 2009 Fermi Research Alliance, LLC
License: Apache-2.0
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Changes since the last release

- item one of the list
- item N
- Added custom log server example (glideinwms-logging) (Issue #398, PR #467)

### Changed defaults / behaviours

Expand All @@ -21,6 +22,7 @@ Changes since the last release
### Bug Fixes

- Fixed early truncation in log files configuration and inconsistent documentation (Issue #464, PR #462, PR #463)
- Fixed JWT logging credentials not transferred to the Glidein. This includes removal of DictFile.append() and use of add_environment() for JWT tokens (Issue #398, PR #467)

### Testing / Development

Expand Down
52 changes: 43 additions & 9 deletions build/ReleaseManager/ReleaseManagerLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def __init__(self, ver, srcDir, relDir, rc, rpmRel):
self.srpmFile = os.path.join(
self.rpmbuildDir,
"SRPMS",
"glideinwms-%s-%s.%s%s.src.rpm"
% (self.rpmVersion, self.rpmRelease, self.rpmOSVersion[0], self.rpmOSVersion[1]),
f"glideinwms-{self.rpmVersion}-{self.rpmRelease}.{self.rpmOSVersion[0]}{self.rpmOSVersion[1]}.src.rpm",
)
self.buildRPMs = bool(which("rpmbuild"))
if not self.buildRPMs:
Expand Down Expand Up @@ -81,11 +80,18 @@ def getElVersion(self):
# Deprecated - distname, version, id = distro.linux_distribution()
distname = distro.name() # If full_distribution_name is false, the result of distro.id()
version = distro.version()
id = distro.codename()
dist_id = distro.codename()
else:
# TODO: remove the else branch once Py3.6 is no more supported
distname, version, id = platform.linux_distribution() # pylint: disable=no-member
distmap = {"Fedora": "fc", "Scientific Linux": "el", "Red Hat": "el", "CentOS Stream": "el"}
distname, version, dist_id = platform.linux_distribution() # pylint: disable=no-member
distmap = {
"Fedora": "fc",
"Scientific Linux": "el",
"Red Hat": "el",
"CentOS Stream": "el",
"AlmaLinux": "al",
"RockyLinux": "el",
}
dist = None
for d in distmap:
if distname.startswith(d):
Expand All @@ -96,7 +102,7 @@ def getElVersion(self):
else:
el_string = dist
major_version = version.split(".")[0]
return (el_string, major_version)
return el_string, major_version

def addTask(self, task):
self.tasks.append(task)
Expand Down Expand Up @@ -277,9 +283,10 @@ def checksumRelease(self, chksumFile, exclude):


class TaskRPM(TaskTar):
def __init__(self, rel, python_version, use_mock=True):
def __init__(self, rel, python_version, use_mock=True, verbose=False):
TaskTar.__init__(self, rel)
self.name = "GlideinwmsRPM"
self.verbose = verbose
self.use_mock = use_mock
self.python_version = python_version
self.releaseFile = os.path.join(self.release.releaseDir, self.releaseFilename)
Expand All @@ -288,6 +295,7 @@ def __init__(self, rel, python_version, use_mock=True):
self.specFile = os.path.join(self.release.rpmbuildDir, "SPECS", "glideinwms.spec")
# self.rpmmacrosFile = os.path.join(os.path.expanduser('~'),
self.rpmmacrosFile = os.path.join(os.path.dirname(self.release.rpmbuildDir), ".rpmmacros")
# Files in build/pkg/rpm to copy in the SOURCES directory
self.sourceFilenames = [
"chksum.sh",
"factory_startup",
Expand All @@ -300,6 +308,7 @@ def __init__(self, rel, python_version, use_mock=True):
"gwms-factory.sysconfig",
"gwms-frontend.conf.httpd",
"gwms-frontend.sysconfig",
"gwms-logserver.conf.httpd",
]
self.rpmMacros = {
"_topdir": self.release.rpmbuildDir,
Expand All @@ -318,6 +327,8 @@ def createRPMBuildDirs(self):
rpm_dirs = ["BUILD", "RPMS", "SOURCES", "SPECS", "SRPMS"]
for dirname in rpm_dirs:
create_dir(os.path.join(self.release.rpmbuildDir, dirname))
if self.verbose:
print(f"RPM build directories created in {self.release.rpmbuildDir}")

def createSpecFile(self):
# No error checking because we want to fail in case of errors
Expand Down Expand Up @@ -351,33 +362,56 @@ def buildSRPM(self):
cmd = "rpmbuild -bs %s" % self.specFile
for m in self.rpmMacros:
cmd = f'{cmd} --define "{m} {self.rpmMacros[m]}"'
if self.verbose:
print(f"Building source RPM: {cmd}")
execute_cmd(cmd)

def buildRPM(self):
cmd = "mock -r epel-{}-x86_64 --macro-file={} -i {}".format(
# Check if mock profiles changed
# As of Dec 2024 on AlmaLinux9: alma+epel-..., rhel+epel-..., centos-stream+epel-...
# No profile has epel-... (maybe rhel-7 for sl7)
if self.release.rpmOSVersion[0] == "al":
mock_profile = "alma+epel"
elif self.release.rpmOSVersion[0] == "el" and int(self.release.rpmOSVersion[1]) >= 8:
mock_profile = "rhel+epel"
else:
mock_profile = "epel"
cmd = "mock -r {}-{}-x86_64 --macro-file={} -i {}".format(
mock_profile,
self.release.rpmOSVersion[1],
self.rpmmacrosFile,
self.python_version,
)
if self.verbose:
print(f"Build mock environment: {cmd}")
execute_cmd(cmd)
cmd = "mock --no-clean -r epel-{}-x86_64 --macro-file={} --resultdir={}/RPMS rebuild {}".format(
cmd = "mock --no-clean -r {}-{}-x86_64 --macro-file={} --resultdir={}/RPMS rebuild {}".format(
mock_profile,
self.release.rpmOSVersion[1],
self.rpmmacrosFile,
self.release.rpmbuildDir,
self.release.srpmFile,
)
if self.verbose:
print(f"Build RPM with mock: {cmd}")
execute_cmd(cmd)

def buildRPMWithRPMBuild(self):
cmd = "rpmbuild -bb %s" % self.specFile
for m in self.rpmMacros:
cmd = f'{cmd} --define "{m} {self.rpmMacros[m]}"'
if self.verbose:
print(f"Build RPM without mock: {cmd}")
execute_cmd(cmd)

def execute(self):
if not self.release.buildRPMs:
self.status = "SKIPPED"
else:
if self.verbose:
print(
f"Building RPM (version:{self.release.rpmVersion}, release:{self.release.rpmRelease}, use_mock:{self.use_mock})"
)
# First build the source tarball
# TaskTar.execute(self)

Expand Down
84 changes: 32 additions & 52 deletions build/ReleaseManager/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

import sys
import os
import optparse
import argparse
from argparse import RawDescriptionHelpFormatter

# Necessary to allow relative import when started as executable
if __name__ == "__main__" and __package__ is None:
Expand Down Expand Up @@ -42,7 +43,7 @@ def manager_version():


def usage():
help = [
help_str = [
"%s <version> <SourceDir> <ReleaseDir>" % os.path.basename(sys.argv[0]),
"NOTE that this script works on the files in your current directory tree",
"- no git operations like clone/checkout are performed",
Expand All @@ -64,113 +65,92 @@ def usage():
"release.py --release-version=3_2_11 --source-dir=/home/parag/glideinwms --release-dir=/var/tmp/release --rpm-release=3",
"",
]
return "\n".join(help)
return "\n".join(help_str)


def parse_opts(argv):
parser = optparse.OptionParser(usage=usage(), version=manager_version(), conflict_handler="resolve")
parser.add_option(
parser = argparse.ArgumentParser(
prog=os.path.basename(sys.argv[0]),
description=usage(),
conflict_handler="resolve",
formatter_class=RawDescriptionHelpFormatter,
)
parser.add_argument(
"--release-version",
dest="relVersion",
action="store",
required=True,
metavar="<release version>",
help="GlideinWMS version to release (format w/ underscores, for tarball, RPM version derived from it)",
)
parser.add_option(
parser.add_argument(
"--source-dir",
dest="srcDir",
action="store",
required=True,
metavar="<source directory>",
help="directory containing the glideinwms source code",
help="directory containing the GlideinWMS source code",
)
parser.add_option(
parser.add_argument(
"--release-dir",
dest="relDir",
default="/tmp/release",
action="store",
metavar="<release directory>",
help="directory to store release tarballs and webpages",
)
parser.add_option(
"--rc", dest="rc", default=None, action="store", metavar="<Release Candidate Number>", help="Release Candidate"
parser.add_argument(
"--rc", default=None, action="store", metavar="<Release Candidate Number>", help="Release Candidate"
)
parser.add_option(
parser.add_argument(
"--rpm-release",
dest="rpmRel",
default=None,
action="store",
metavar="<RPM Release Number>",
help="RPM Release Number",
)
parser.add_option(
parser.add_argument(
"--no-mock", dest="use_mock", action="store_false", help="Set to use rpmbuild instead of mock to build the RPM"
)
parser.add_option(
parser.add_argument(
"--python-version",
dest="python_version",
default="python36",
action="store",
metavar="<Python version>",
help="Python version (default: python36)",
)
parser.add_argument("--verbose", action="store_true", help="Set to see more details of the release building")
parser.add_argument("-v", "--version", action="version", version=manager_version())

if len(argv) == 2 and argv[1] in ["-v", "--version"]:
parser.print_version()
sys.exit()
if len(argv) < 4:
print("ERROR: Insufficient arguments specified")
parser.print_help()
sys.exit(1)
options, remainder = parser.parse_args(argv)
if len(remainder) > 1:
parser.print_help()
if not required_args_present(options):
print("ERROR: Missing required arguments")
parser.print_help()
sys.exit(1)
options = parser.parse_args()
return options


def required_args_present(options):
try:
if (options.relVersion is None) or (options.srcDir is None) or (options.relDir is None):
return False
except AttributeError:
return False
return True


# check_required_args


# def main(ver, srcDir, relDir):
def main(argv):
options = parse_opts(argv)
# sys.exit(1)
ver = options.relVersion
srcDir = options.srcDir
relDir = options.relDir
ver = options.release_version
src_dir = options.source_dir
rel_dir = options.release_dir
rc = options.rc
rpmRel = options.rpmRel
rpm_rel = options.rpm_release
python_version = options.python_version
use_mock = options.use_mock
is_verbose = options.verbose

print("___________________________________________________________________")
print("Creating following GlideinWMS release")
print(
"Version=%s\nSourceDir=%s\nReleaseDir=%s\nReleaseCandidate=%s\nRPMRelease=%s\nPython=%s"
% (ver, srcDir, relDir, rc, rpmRel, python_version)
% (ver, src_dir, rel_dir, rc, rpm_rel, python_version)
)
print("___________________________________________________________________")
print()
rel = ReleaseManagerLib.Release(ver, srcDir, relDir, rc, rpmRel)
rel = ReleaseManagerLib.Release(ver, src_dir, rel_dir, rc, rpm_rel)

rel.addTask(ReleaseManagerLib.TaskClean(rel))
rel.addTask(ReleaseManagerLib.TaskSetupReleaseDir(rel))
rel.addTask(ReleaseManagerLib.TaskVersionFile(rel))
rel.addTask(ReleaseManagerLib.TaskTar(rel))
rel.addTask(ReleaseManagerLib.TaskDocumentation(rel))
rel.addTask(ReleaseManagerLib.TaskRPM(rel, python_version, use_mock))
rel.addTask(ReleaseManagerLib.TaskRPM(rel, python_version, use_mock, is_verbose))

rel.executeTasks()
rel.printReport()
Expand Down
Loading

0 comments on commit 0531bf3

Please sign in to comment.