adding site_type to deployment-data schema

This change adds the site_type parameter in deployment_data
The value will be taken from respective site-definition.yaml

Change-Id: I8e65b39c73c94caf3ed4cc517520b9577160b20d
This commit is contained in:
Apurva Gokani 2020-05-22 10:28:06 -05:00 committed by ag759t
parent aa3fca532a
commit 22e6df0870
6 changed files with 37 additions and 9 deletions

View File

@ -28,6 +28,12 @@ called ``pegleg.sh``.
The default workspace for the ``pegleg.sh`` script is ``/workspace``. The
examples below require that this workspace be used.
.. note::
Pegleg collect and render commands generate a deployment-version
document containing information gathered from the site-definition, which
includes the specific commit for each repository used and whether that
repository was clean or dirty.
Environment Variables
=====================

View File

@ -55,7 +55,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(site_name),
explicit_start=True,
explicit_end=True,
default_flow_style=False)
@ -88,7 +88,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(site_name),
default_flow_style=False,
explicit_start=True,
explicit_end=True))
@ -108,7 +108,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())
rendered_documents.append(get_deployment_data_doc(site_name))
if output_stream:
files.dump_all(
rendered_documents,
@ -213,12 +213,12 @@ def show(site_name, output_stream):
click.echo(msg)
def get_deployment_data_doc():
def get_deployment_data_doc(site_name):
stanzas = {
files.path_leaf(repo): _get_repo_deployment_data_stanza(repo)
for repo in config.all_repos()
}
return OrderedDict(
basedeployment_data = OrderedDict(
[
("schema", "pegleg/DeploymentData/v1"),
(
@ -234,6 +234,15 @@ def get_deployment_data_doc():
("storagePolicy", "cleartext"),
])), ("data", OrderedDict([("documents", stanzas)]))
])
try:
data = util.definition.load_as_params(site_name)
basedeployment_data['data'].update({'site_type': data['site_type']})
return basedeployment_data
except Exception as ex:
LOG.debug(
"Unable to get the site definition data for"
" site: %s, Exception :%s", site_name, ex)
return basedeployment_data
def _get_repo_deployment_data_stanza(repo_path):

View File

@ -146,6 +146,7 @@ def _get_current_ref(repo_url):
'checked out ref=%s', repo_url, current_ref)
return current_ref
except Exception as e:
LOG.debug('Exception : %s', str(e))
return None
@ -154,6 +155,7 @@ def get_remote_url(repo_url):
repo = Repo(repo_url, search_parent_directories=True)
return repo.remotes.origin.url
except Exception as e:
LOG.debug('Exception : %s', str(e))
return None

View File

@ -77,7 +77,7 @@ class ShipyardHelper(object):
collected_documents = files.collect_files_by_repo(self.site_name)
collection_data = [site.get_deployment_data_doc()]
collection_data = [site.get_deployment_data_doc(self.site_name)]
LOG.info("Processing %d collection(s)", len(collected_documents))
for idx, document in enumerate(collected_documents):
# Decrypt the documents if encrypted

View File

@ -223,3 +223,14 @@ def test_site_render(create_tmp_site_structure):
doc2['data']['managedDocument']['data'] = doc2['data'][
'managedDocument']['data'].decode()
assert doc2['data']['managedDocument'] == doc
def test_deployment_version_doc(create_tmp_site_structure):
"""
This test case checks the deployment-version document,
test case passes if the site_type parameter exists
"""
sitename = "test"
rootpath = create_tmp_site_structure(sitename)
rendered_doc = site.get_deployment_data_doc(sitename)
assert rendered_doc['data']['site_type'] == sitename

View File

@ -152,8 +152,8 @@ 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 _get_deployment_data_as_yaml(site_name):
return yaml.safe_dump(get_deployment_data_doc(site_name))
def test_shipyard_helper_init_():
@ -204,7 +204,7 @@ def test_upload_documents(*args):
# collection name and buffer mode.
expected_data = '---\n'.join(
[
_get_deployment_data_as_yaml(),
_get_deployment_data_as_yaml(context.obj['site_name']),
_get_data_as_collection(MULTI_REPO_DATA)
])
mock_api_client.post_configdocs.assert_called_with(