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
This commit is contained in:
Alexander Hughes 2019-09-11 15:55:44 -05:00 committed by Alexander Hughes
parent e2dad75a99
commit bc6554241b
4 changed files with 19 additions and 6 deletions

3
.gitignore vendored
View File

@ -114,3 +114,6 @@ AUTHORS
# Ansible # Ansible
*.retry *.retry
# Linux
~

View File

@ -54,7 +54,7 @@ def _collect_to_stdout(site_name):
click.echo("\n".join(line.splitlines())) click.echo("\n".join(line.splitlines()))
add_representer_ordered_dict() add_representer_ordered_dict()
res = yaml.safe_dump( res = yaml.safe_dump(
_get_deployment_data_doc(), get_deployment_data_doc(),
explicit_start=True, explicit_start=True,
explicit_end=True, explicit_end=True,
default_flow_style=False) default_flow_style=False)
@ -87,7 +87,7 @@ def _collect_to_file(site_name, save_location):
add_representer_ordered_dict() add_representer_ordered_dict()
save_files[curr_site_repo].writelines( save_files[curr_site_repo].writelines(
yaml.safe_dump( yaml.safe_dump(
_get_deployment_data_doc(), get_deployment_data_doc(),
default_flow_style=False, default_flow_style=False,
explicit_start=True, explicit_start=True,
explicit_end=True)) explicit_end=True))
@ -107,7 +107,7 @@ def collect(site_name, save_location):
def render(site_name, output_stream, validate): def render(site_name, output_stream, validate):
rendered_documents = get_rendered_docs(site_name, validate=validate) rendered_documents = get_rendered_docs(site_name, validate=validate)
rendered_documents.append(get_deployment_data_doc())
if output_stream: if output_stream:
files.dump_all( files.dump_all(
rendered_documents, rendered_documents,
@ -192,7 +192,7 @@ def show(site_name, output_stream):
click.echo(msg) click.echo(msg)
def _get_deployment_data_doc(): def get_deployment_data_doc():
stanzas = { stanzas = {
files.path_leaf(repo): _get_repo_deployment_data_stanza(repo) files.path_leaf(repo): _get_repo_deployment_data_stanza(repo)
for repo in config.all_repos() for repo in config.all_repos()

View File

@ -22,6 +22,7 @@ from shipyard_client.api_client.shipyardclient_context import \
import yaml import yaml
from pegleg.engine import exceptions from pegleg.engine import exceptions
from pegleg.engine import site
from pegleg.engine.util import files from pegleg.engine.util import files
from pegleg.engine.util.files import add_representer_ordered_dict from pegleg.engine.util.files import add_representer_ordered_dict
from pegleg.engine.util.pegleg_secret_management import PeglegSecretManagement 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) 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)) LOG.info("Processing %d collection(s)", len(collected_documents))
for idx, document in enumerate(collected_documents): for idx, document in enumerate(collected_documents):
# Decrypt the documents if encrypted # Decrypt the documents if encrypted

View File

@ -20,6 +20,7 @@ import pytest
import yaml import yaml
from pegleg.engine import util 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 ShipyardHelper
from pegleg.engine.util.shipyard_helper import ShipyardClient 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) 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_(): def test_shipyard_helper_init_():
""" Tests ShipyardHelper init method """ """ Tests ShipyardHelper init method """
# Scenario: # Scenario:
@ -197,7 +202,11 @@ def test_upload_documents(*args):
# Validate Shipyard call to post configdocs was invoked with correct # Validate Shipyard call to post configdocs was invoked with correct
# collection name and buffer mode. # 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( mock_api_client.post_configdocs.assert_called_with(
collection_id='test-site', collection_id='test-site',
buffer_mode='replace', buffer_mode='replace',