Implement not packaging as default behavior

Remove --no-package flag and implement not packaging
as the default behavior;

Test Plan:
PASS - When running without the --package-only flag
the generator only creates the manifest files.
PASS - --package-only flag continues to work as intended

Story: 2010937
Task: 48925

Change-Id: Ib155a39cb01df802c381aa4242563fb42267f815
Signed-off-by: Daniel Caires <daniel.caires@encora.com>
This commit is contained in:
Daniel Caires 2023-12-20 12:57:02 -03:00
parent cac2937bef
commit 9db1a03c7f
5 changed files with 105 additions and 23 deletions

View File

@ -73,7 +73,7 @@ class Application(ABC):
self.metadata = app_data["metadataFile-config"]
@abstractmethod
def generate(self, package_only, no_package):
def generate(self, package_only):
"""Abstract method for generating application."""
def check_charts(self):

View File

@ -22,15 +22,14 @@ class FluxCD(Application):
# 7 - Package plugins in wheel format
# 8 - Generate checksum
# 9 - Package entire application
def generate(self, package_only, no_package):
def generate(self, package_only):
"""Responsible for all the process for the creation of the FluxCD app tarball.
Args:
package_only (bool): Instructs the generator to only execute packaging related code.
no_package (bool): Instrutcs the generator to only create the files without packaging.
Returns:
bool: False if a step in the generator fails
bool: False if a step in the generator fails.
"""
app_name_fixed = self._app['appName'].replace(' ', '_').replace('-', '_')
updated_app_name = f'k8sapp_{app_name_fixed}'
@ -97,7 +96,7 @@ class FluxCD(Application):
print('FluxCD Metadata generation failed!')
return False
if not no_package:
else:
# 6 - Package helm-charts
for chart in self._chart:
ret = self._gen_helm_chart_tarball(
@ -267,7 +266,7 @@ class FluxCD(Application):
print(f'File {kustomize_template} not found')
return False
kustomize_file_name = f'kustomie_{self.APP_NAME_WITH_UNDERSCORE}.py'
kustomize_file_name = f'kustomize_{self.APP_NAME_WITH_UNDERSCORE}.py'
kustomize_file = os.path.join(
plugin_dir, appname, 'kustomize', kustomize_file_name
)

View File

@ -154,17 +154,16 @@ def create_app_directories(app_out, overwrite):
os.makedirs(app_out)
def generate_app(app_data, output_folder, package_only, no_package):
def generate_app(app_data, output_folder, package_only):
"""Generate the application.
Args:
app_data (dict): Contents from the input file.
output_folder (str): Path to where the application files will be placed.
package_only (bool): Instructs the generator to only execute packaging related code.
no_package (bool): Instrutcs the generator to only create the files without packaging.
"""
app = FluxCD(app_data, output_folder)
app.generate(package_only, no_package)
app.generate(package_only)
def handle_args():
@ -201,15 +200,6 @@ def handle_args():
action='store_true'
)
parser.add_argument(
"--no-package",
help="""
Instructs the generator to only create the application manifest and
plugins files, but not package them.
""",
action='store_true'
)
parser.add_argument(
"--package-only",
help="""
@ -260,4 +250,4 @@ def main():
create_app_directories(output_folder, ARGS.overwrite)
generate_app(
app_data, output_folder, ARGS.package_only, ARGS.no_package)
app_data, output_folder, ARGS.package_only)

View File

@ -2,6 +2,9 @@
import git
import os
import shutil
import glob
from app_gen_tool.common import get_chart_from_git
from app_gen_tool.fluxcd import FluxCD
from app_gen_tool.generator import parse_yaml, create_app_directories, check_input_file
@ -45,9 +48,18 @@ class TestFluxCDAppGen:
def test_generate_fluxcd_app(self):
file_list = ["metadata.yaml",
"fluxcd-manifests/kustomization.yaml",
"fluxcd-manifests/base/helmrepository.yaml",
"fluxcd-manifests/base/kustomization.yaml",
"fluxcd-manifests/base/namespace.yaml",
"fluxcd-manifests/adminer/helmrelease.yaml",
"fluxcd-manifests/adminer/kustomization.yaml",
"fluxcd-manifests/adminer/adminer-static-overrides.yaml",
"fluxcd-manifests/adminer/adminer-system-overrides.yaml",
]
overwrite = True
package_only = False
no_package = False
if not check_input_file(self.app_data):
assert False
@ -56,7 +68,68 @@ class TestFluxCDAppGen:
create_app_directories(app.output_folder, overwrite)
app.generate(package_only, no_package)
app.generate(package_only)
for file in file_list:
output_file = os.path.join(self.OUTPUT_FOLDER, file)
file_exists = os.path.exists(output_file)
if not file_exists:
print(f"File not found! Error while trying to find {output_file}")
assert False
def test_generate_plugins_app(self):
file_list = ["setup.cfg",
"setup.py",
"__init__.py",
"k8sapp_app_adminer/common/constants.py",
"k8sapp_app_adminer/common/__init__.py",
"k8sapp_app_adminer/helm/adminer.py",
"k8sapp_app_adminer/helm/__init__.py",
"k8sapp_app_adminer/kustomize/kustomize_app_adminer.py",
"k8sapp_app_adminer/kustomize/__init__.py",
"k8sapp_app_adminer/lifecycle/lifecycle_app_adminer.py",
"k8sapp_app_adminer/lifecycle/__init__.py",
"k8sapp_app_adminer/__init__.py"
]
overwrite = True
package_only = False
if not check_input_file(self.app_data):
assert False
app = FluxCD(self.app_data, self.OUTPUT_FOLDER)
create_app_directories(app.output_folder, overwrite)
app.generate(package_only)
for file in file_list:
output_file = os.path.join(self.OUTPUT_FOLDER, "plugins", file)
file_exists = os.path.exists(output_file)
if not file_exists:
print(f"File not found! Error while trying to find {output_file}")
assert False
def test_package_app(self):
overwrite = [True, False]
package_only = [False, True]
if not check_input_file(self.app_data):
assert False
app = FluxCD(self.app_data, self.OUTPUT_FOLDER)
# Run the generator twice, first to generate the files and
# a second time to test the packaging. Each time the generator
# runs, it has different conditions for overwrite and package-only
# 1º run - overwrite: True; package-only: False
# 2º run - overwrite: False; package-only: True
for i in range(2):
create_app_directories(app.output_folder, overwrite[i])
app.generate(package_only[i])
output_file = \
os.path.join(self.OUTPUT_FOLDER,
@ -65,7 +138,6 @@ class TestFluxCDAppGen:
file_exists = os.path.exists(output_file)
assert file_exists
# assert True
def test_clone_helm_chart_from_git(self):
"""Test cloning helm chart from a git url"""
@ -89,3 +161,24 @@ class TestFluxCDAppGen:
if os.path.exists(tmp_folder):
shutil.rmtree(tmp_folder)
assert not os.path.exists(tmp_folder)
def test_wheels_package(self):
overwrite = True
package_only = False
if not check_input_file(self.app_data):
assert False
app = FluxCD(self.app_data, self.OUTPUT_FOLDER)
create_app_directories(app.output_folder, overwrite)
app.generate(package_only)
FluxCD._gen_plugin_wheels(app)
output_file = os.path.join(self.OUTPUT_FOLDER, "plugins", "*.whl")
file_exists = glob.glob(output_file, recursive = True)
assert file_exists

View File

@ -192,7 +192,7 @@ commands =
basepython = python3
description = Run pytest with code coverage report
commands =
coverage report --fail-under=55
coverage report --fail-under=70
[testenv:coverage]
basepython = python3