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:
parent
cac2937bef
commit
9db1a03c7f
@ -73,7 +73,7 @@ class Application(ABC):
|
|||||||
self.metadata = app_data["metadataFile-config"]
|
self.metadata = app_data["metadataFile-config"]
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def generate(self, package_only, no_package):
|
def generate(self, package_only):
|
||||||
"""Abstract method for generating application."""
|
"""Abstract method for generating application."""
|
||||||
|
|
||||||
def check_charts(self):
|
def check_charts(self):
|
||||||
|
@ -22,15 +22,14 @@ class FluxCD(Application):
|
|||||||
# 7 - Package plugins in wheel format
|
# 7 - Package plugins in wheel format
|
||||||
# 8 - Generate checksum
|
# 8 - Generate checksum
|
||||||
# 9 - Package entire application
|
# 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.
|
"""Responsible for all the process for the creation of the FluxCD app tarball.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
package_only (bool): Instructs the generator to only execute packaging related code.
|
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:
|
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('-', '_')
|
app_name_fixed = self._app['appName'].replace(' ', '_').replace('-', '_')
|
||||||
updated_app_name = f'k8sapp_{app_name_fixed}'
|
updated_app_name = f'k8sapp_{app_name_fixed}'
|
||||||
@ -97,7 +96,7 @@ class FluxCD(Application):
|
|||||||
print('FluxCD Metadata generation failed!')
|
print('FluxCD Metadata generation failed!')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not no_package:
|
else:
|
||||||
# 6 - Package helm-charts
|
# 6 - Package helm-charts
|
||||||
for chart in self._chart:
|
for chart in self._chart:
|
||||||
ret = self._gen_helm_chart_tarball(
|
ret = self._gen_helm_chart_tarball(
|
||||||
@ -267,7 +266,7 @@ class FluxCD(Application):
|
|||||||
print(f'File {kustomize_template} not found')
|
print(f'File {kustomize_template} not found')
|
||||||
return False
|
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(
|
kustomize_file = os.path.join(
|
||||||
plugin_dir, appname, 'kustomize', kustomize_file_name
|
plugin_dir, appname, 'kustomize', kustomize_file_name
|
||||||
)
|
)
|
||||||
|
@ -154,17 +154,16 @@ def create_app_directories(app_out, overwrite):
|
|||||||
os.makedirs(app_out)
|
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.
|
"""Generate the application.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
app_data (dict): Contents from the input file.
|
app_data (dict): Contents from the input file.
|
||||||
output_folder (str): Path to where the application files will be placed.
|
output_folder (str): Path to where the application files will be placed.
|
||||||
package_only (bool): Instructs the generator to only execute packaging related code.
|
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 = FluxCD(app_data, output_folder)
|
||||||
app.generate(package_only, no_package)
|
app.generate(package_only)
|
||||||
|
|
||||||
|
|
||||||
def handle_args():
|
def handle_args():
|
||||||
@ -201,15 +200,6 @@ def handle_args():
|
|||||||
action='store_true'
|
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(
|
parser.add_argument(
|
||||||
"--package-only",
|
"--package-only",
|
||||||
help="""
|
help="""
|
||||||
@ -260,4 +250,4 @@ def main():
|
|||||||
create_app_directories(output_folder, ARGS.overwrite)
|
create_app_directories(output_folder, ARGS.overwrite)
|
||||||
|
|
||||||
generate_app(
|
generate_app(
|
||||||
app_data, output_folder, ARGS.package_only, ARGS.no_package)
|
app_data, output_folder, ARGS.package_only)
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
import git
|
import git
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import glob
|
||||||
|
|
||||||
|
|
||||||
from app_gen_tool.common import get_chart_from_git
|
from app_gen_tool.common import get_chart_from_git
|
||||||
from app_gen_tool.fluxcd import FluxCD
|
from app_gen_tool.fluxcd import FluxCD
|
||||||
from app_gen_tool.generator import parse_yaml, create_app_directories, check_input_file
|
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):
|
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
|
overwrite = True
|
||||||
package_only = False
|
package_only = False
|
||||||
no_package = False
|
|
||||||
|
|
||||||
if not check_input_file(self.app_data):
|
if not check_input_file(self.app_data):
|
||||||
assert False
|
assert False
|
||||||
@ -56,7 +68,68 @@ class TestFluxCDAppGen:
|
|||||||
|
|
||||||
create_app_directories(app.output_folder, overwrite)
|
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 = \
|
output_file = \
|
||||||
os.path.join(self.OUTPUT_FOLDER,
|
os.path.join(self.OUTPUT_FOLDER,
|
||||||
@ -65,7 +138,6 @@ class TestFluxCDAppGen:
|
|||||||
file_exists = os.path.exists(output_file)
|
file_exists = os.path.exists(output_file)
|
||||||
|
|
||||||
assert file_exists
|
assert file_exists
|
||||||
# assert True
|
|
||||||
|
|
||||||
def test_clone_helm_chart_from_git(self):
|
def test_clone_helm_chart_from_git(self):
|
||||||
"""Test cloning helm chart from a git url"""
|
"""Test cloning helm chart from a git url"""
|
||||||
@ -89,3 +161,24 @@ class TestFluxCDAppGen:
|
|||||||
if os.path.exists(tmp_folder):
|
if os.path.exists(tmp_folder):
|
||||||
shutil.rmtree(tmp_folder)
|
shutil.rmtree(tmp_folder)
|
||||||
assert not os.path.exists(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
|
2
tox.ini
2
tox.ini
@ -192,7 +192,7 @@ commands =
|
|||||||
basepython = python3
|
basepython = python3
|
||||||
description = Run pytest with code coverage report
|
description = Run pytest with code coverage report
|
||||||
commands =
|
commands =
|
||||||
coverage report --fail-under=55
|
coverage report --fail-under=70
|
||||||
|
|
||||||
[testenv:coverage]
|
[testenv:coverage]
|
||||||
basepython = python3
|
basepython = python3
|
||||||
|
Loading…
Reference in New Issue
Block a user