From bc6554241bd385389d62c687cb2562f46ac396a2 Mon Sep 17 00:00:00 2001 From: Alexander Hughes Date: Wed, 11 Sep 2019 15:55:44 -0500 Subject: [PATCH] Add deployment_data to rendered docs A bug was found where the deployment_data document was not being included in the upload to shipyard. Upon investigation it was also noticed that deployment_data wasn't being rendered. This patch updates the render and upload commands to include the deployment data document. Change-Id: I916132e80ac13546468f171a75517a9159e48ea6 --- .gitignore | 3 +++ pegleg/engine/site.py | 8 ++++---- pegleg/engine/util/shipyard_helper.py | 3 ++- tests/unit/engine/util/test_shipyard_helper.py | 11 ++++++++++- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index a741440d..2adb41cc 100644 --- a/.gitignore +++ b/.gitignore @@ -114,3 +114,6 @@ AUTHORS # Ansible *.retry + +# Linux +~ diff --git a/pegleg/engine/site.py b/pegleg/engine/site.py index 66fe2c7f..adccd793 100644 --- a/pegleg/engine/site.py +++ b/pegleg/engine/site.py @@ -54,7 +54,7 @@ def _collect_to_stdout(site_name): click.echo("\n".join(line.splitlines())) add_representer_ordered_dict() res = yaml.safe_dump( - _get_deployment_data_doc(), + get_deployment_data_doc(), explicit_start=True, explicit_end=True, default_flow_style=False) @@ -87,7 +87,7 @@ def _collect_to_file(site_name, save_location): add_representer_ordered_dict() save_files[curr_site_repo].writelines( yaml.safe_dump( - _get_deployment_data_doc(), + get_deployment_data_doc(), default_flow_style=False, explicit_start=True, explicit_end=True)) @@ -107,7 +107,7 @@ def collect(site_name, save_location): def render(site_name, output_stream, validate): rendered_documents = get_rendered_docs(site_name, validate=validate) - + rendered_documents.append(get_deployment_data_doc()) if output_stream: files.dump_all( rendered_documents, @@ -192,7 +192,7 @@ def show(site_name, output_stream): click.echo(msg) -def _get_deployment_data_doc(): +def get_deployment_data_doc(): stanzas = { files.path_leaf(repo): _get_repo_deployment_data_stanza(repo) for repo in config.all_repos() diff --git a/pegleg/engine/util/shipyard_helper.py b/pegleg/engine/util/shipyard_helper.py index 33106a14..13c5fe43 100644 --- a/pegleg/engine/util/shipyard_helper.py +++ b/pegleg/engine/util/shipyard_helper.py @@ -22,6 +22,7 @@ from shipyard_client.api_client.shipyardclient_context import \ import yaml from pegleg.engine import exceptions +from pegleg.engine import site from pegleg.engine.util import files from pegleg.engine.util.files import add_representer_ordered_dict from pegleg.engine.util.pegleg_secret_management import PeglegSecretManagement @@ -76,7 +77,7 @@ class ShipyardHelper(object): collected_documents = files.collect_files_by_repo(self.site_name) - collection_data = [] + collection_data = [site.get_deployment_data_doc()] LOG.info("Processing %d collection(s)", len(collected_documents)) for idx, document in enumerate(collected_documents): # Decrypt the documents if encrypted diff --git a/tests/unit/engine/util/test_shipyard_helper.py b/tests/unit/engine/util/test_shipyard_helper.py index 5a23fae4..9704d633 100644 --- a/tests/unit/engine/util/test_shipyard_helper.py +++ b/tests/unit/engine/util/test_shipyard_helper.py @@ -20,6 +20,7 @@ import pytest import yaml from pegleg.engine import util +from pegleg.engine.site import get_deployment_data_doc from pegleg.engine.util.shipyard_helper import ShipyardHelper from pegleg.engine.util.shipyard_helper import ShipyardClient @@ -151,6 +152,10 @@ def _get_data_as_collection(data): return yaml.dump_all(collection, Dumper=yaml.SafeDumper) +def _get_deployment_data_as_yaml(): + return yaml.safe_dump(get_deployment_data_doc()) + + def test_shipyard_helper_init_(): """ Tests ShipyardHelper init method """ # Scenario: @@ -197,7 +202,11 @@ def test_upload_documents(*args): # Validate Shipyard call to post configdocs was invoked with correct # collection name and buffer mode. - expected_data = _get_data_as_collection(MULTI_REPO_DATA) + expected_data = '---\n'.join( + [ + _get_deployment_data_as_yaml(), + _get_data_as_collection(MULTI_REPO_DATA) + ]) mock_api_client.post_configdocs.assert_called_with( collection_id='test-site', buffer_mode='replace',