
With the implementation of revisioned repository to the CLI in https://review.openstack.org/#/c/577886 there was a change to the lint command [0], which changed it from being a global lint to a site-level (targetted lint)... kind of: Only the CLI logic was modified to support targetted single-site linting. Thus, the first issue this patch set addresses is implementing the back-end logic to realize targetted, single-site linting. The second issue this patch set addresses is re-supporting global linting (linting all sites within a repository) which means that this partially reverts [0] which had (kind of) replaced global linting with per-site linting. So, this patch set: 1) Implements targetted, single-site linting back-end logic 2) Re-implements global linting for all sites in a repo 3) Adds unit tests for both 4) Adds some helper functions to util.engine.definition to help with 1) and 2) [0] https://review.openstack.org/#/c/577886/4/src/bin/pegleg/pegleg/cli.py@191 Change-Id: I5147282556763d93dfaf06912d2c4c876e1bd69f
67 lines
2.7 KiB
Python
67 lines
2.7 KiB
Python
# Copyright 2018 AT&T Intellectual Property. All other rights reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
from pegleg.engine.util import definition
|
|
from tests.unit.fixtures import create_tmp_deployment_files
|
|
|
|
|
|
class TestSiteDefinitionHelpers(object):
|
|
def _test_documents_for_site(self, sitename):
|
|
documents = definition.documents_for_site(sitename)
|
|
global_documents = []
|
|
site_documents = []
|
|
|
|
for document in documents:
|
|
name = document["metadata"]["name"]
|
|
# Assert that the document is either global level or a relevant
|
|
# site document.
|
|
assert name.startswith("global") or name.startswith(sitename)
|
|
|
|
if name.startswith("global"):
|
|
global_documents.append(document)
|
|
elif name.startswith(sitename):
|
|
site_documents.append(document)
|
|
else:
|
|
raise AssertionError("Unexpected document retrieved by "
|
|
"`documents_for_site`: %s" % document)
|
|
|
|
# Assert that documents from both levels appear.
|
|
assert global_documents
|
|
assert site_documents
|
|
|
|
return global_documents + site_documents
|
|
|
|
def test_documents_for_site(self, create_tmp_deployment_files):
|
|
self._test_documents_for_site("cicd")
|
|
self._test_documents_for_site("lab")
|
|
|
|
def test_documents_for_each_site(self, create_tmp_deployment_files):
|
|
documents_by_site = definition.documents_for_each_site()
|
|
sort_func = lambda x: x['metadata']['name']
|
|
|
|
# Validate that both expected site documents are found.
|
|
assert 2 == len(documents_by_site)
|
|
assert "cicd" in documents_by_site
|
|
assert "lab" in documents_by_site
|
|
|
|
cicd_documents = self._test_documents_for_site("cicd")
|
|
lab_documents = self._test_documents_for_site("lab")
|
|
|
|
# Validate that each set of site documents matches the same set of
|
|
# documents returned by ``documents_for_site`` for that site.
|
|
assert (sorted(cicd_documents, key=sort_func) == sorted(
|
|
documents_by_site["cicd"], key=sort_func))
|
|
assert (sorted(lab_documents, key=sort_func) == sorted(
|
|
documents_by_site["lab"], key=sort_func))
|