-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge upgrade and preupgrade script, add sync script for rhc devel wo…
…rker
- Loading branch information
Peter Zdravecký
committed
Jan 16, 2024
1 parent
7bd3516
commit ffc3d44
Showing
41 changed files
with
404 additions
and
1,237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import os | ||
import ruamel.yaml | ||
|
||
# Scripts located in this project | ||
SCRIPT_PATH = "scripts/leapp_script.py" | ||
|
||
# Yaml playbooks in rhc-worker-script | ||
PRE_UPGRADE_YAML_PATH = os.path.join( | ||
"..", "rhc-worker-script/development/nginx/data/leapp_preupgrade.yml" | ||
) | ||
UPGRADE_YAML_PATH = os.path.join( | ||
"..", "rhc-worker-script/development/nginx/data/leapp_upgrade.yml" | ||
) | ||
|
||
DEFAULT_YAML_ENVELOPE = """ | ||
- name: LEAPP | ||
vars: | ||
insights_signature: | | ||
ascii_armored gpg signature | ||
insights_signature_exclude: /vars/insights_signature,/vars/content_vars | ||
interpreter: /usr/bin/python | ||
content: | | ||
placeholder | ||
content_vars: | ||
# variables that will be handed to the script as environment vars | ||
# will be prefixed with RHC_WORKER_* | ||
LEAPP_SCRIPT_TYPE: type | ||
""" | ||
|
||
|
||
def _get_updated_yaml_content(yaml_path, script_path): | ||
if not os.path.exists(yaml_path): | ||
yaml = ruamel.yaml.YAML() | ||
config = yaml.load(DEFAULT_YAML_ENVELOPE) | ||
mapping = 2 | ||
offset = 0 | ||
else: | ||
config, mapping, offset = ruamel.yaml.util.load_yaml_guess_indent( | ||
open(yaml_path) | ||
) | ||
print(mapping, offset) | ||
|
||
with open(script_path) as script: | ||
content = script.read() | ||
|
||
script_type = "PREUPGRADE" if "preupgrade" in yaml_path else "UPGRADE" | ||
config[0]["name"] = "LEAPP %s" % script_type.title() | ||
config[0]["vars"]["content"] = content | ||
config[0]["vars"]["content_vars"]["LEAPP_SCRIPT_TYPE"] = script_type | ||
return config, mapping, offset | ||
|
||
|
||
def _write_content(config, path, mapping=None, offset=None): | ||
yaml = ruamel.yaml.YAML() | ||
if mapping and offset: | ||
yaml.indent(mapping=mapping, sequence=mapping, offset=offset) | ||
with open(path, "w") as handler: | ||
yaml.dump(config, handler) | ||
|
||
|
||
def main(): | ||
config, mapping, offset = _get_updated_yaml_content( | ||
PRE_UPGRADE_YAML_PATH, SCRIPT_PATH | ||
) | ||
print("Writing new content to %s" % PRE_UPGRADE_YAML_PATH) | ||
_write_content(config, PRE_UPGRADE_YAML_PATH, mapping, offset) | ||
config, mapping, offset = _get_updated_yaml_content(UPGRADE_YAML_PATH, SCRIPT_PATH) | ||
print("Writing new content to %s" % UPGRADE_YAML_PATH) | ||
_write_content(config, UPGRADE_YAML_PATH, mapping, offset) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ jsonschema==3.2.0 | |
mock==3.0.5 | ||
pytest==4.6.11 | ||
pytest-cov==2.12.1 | ||
ruamel.yaml==0.16.13 |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.