Add filtering of projects to skip non-buildable

This will allow the filtering out of projects to build from the
superrepo as installation via deb is not desirable for all.

Change-Id: Ifc441c1ca1ccf8237cf64629adf3e166ce054e44
Signed-off-by: Philip Marc Schwartz <philip@progmad.com>
This commit is contained in:
Philip Marc Schwartz 2016-08-30 08:49:37 -04:00
parent 0344182184
commit 10af8d2d54
4 changed files with 60 additions and 6 deletions

View File

@ -25,7 +25,7 @@ from giftwrap.settings import Settings
class BuildSpec(object):
def __init__(self, manifest, version, build_type=None, parallel=True,
limit_projects=None):
limit_projects=None, project_filter=None):
self._manifest = yaml.load(manifest)
self.version = version
self.build_type = build_type
@ -38,6 +38,7 @@ class BuildSpec(object):
parallel = False
manifest_settings['parallel_build'] = parallel
self.settings = Settings.factory(manifest_settings)
self.project_filter = project_filter
self.projects = self._render_projects(limit_projects)
def _render_projects(self, limit_projects):
@ -97,4 +98,9 @@ class BuildSpec(object):
projects.append(OpenstackProject.factory(self.settings,
project,
project_version))
if self.project_filter:
for project in projects:
if project.name in self.project_filter:
projects.remove(project)
return projects

View File

@ -31,7 +31,7 @@ class Settings(object):
package_name_format=None, version=None,
base_path=None, install_path=None, gerrit_dependencies=True,
force_overwrite=False, output_dir=None, include_config=True,
parallel_build=True, constraints=None):
parallel_build=True, constraints=None, project_filter=None):
if not version:
raise Exception("'version' is a required settings")
if constraints is None:
@ -49,6 +49,7 @@ class Settings(object):
self.include_config = include_config
self.parallel_build = parallel_build
self.constraints = constraints
self.project_filter = project_filter
@property
def package_name_format(self):

View File

@ -48,7 +48,7 @@ def build(args):
manifest = fh.read()
buildspec = BuildSpec(manifest, args.version, args.type, args.parallel,
args.projects)
args.projects, args.project_filter)
builder = BuilderFactory.create_builder(args.type, buildspec)
def _signal_handler(*args):
@ -91,6 +91,8 @@ def main():
return arg.split(',')
build_subcmd.add_argument('-p', '--projects', type=csvarg, dest='projects')
build_subcmd.add_argument('-f', '--filter', type=csvarg,
dest='project_filter')
build_subcmd.set_defaults(func=build)
args = parser.parse_args()

View File

@ -117,6 +117,45 @@ class TestBuildSpec(unittest.TestCase):
childrepo2,
childrepo)
@utils.make_test_repo("parentrepo")
@utils.make_test_repo("childrepo2")
@utils.make_test_repo("childrepo")
@utils.make_test_repo("reqrepo")
def test_build_spec_superrepo_filters(self,
parentrepo,
childrepo2,
childrepo,
reqrepo):
parentrepo = git.Repo(parentrepo)
childname = os.path.basename(childrepo)
childrepo = git.Repo(childrepo)
self._add_setup_py(childrepo)
child2name = os.path.basename(childrepo2)
childrepo2 = git.Repo(childrepo2)
self._add_setup_py(childrepo2)
# tag child repo to test describe behavior
cw = childrepo2.config_writer()
cw.set_value("user", "email", "nobody@noexist.test")
cw.set_value("user", "name", "Nobody McNoperson")
cw.release()
childrepo2.create_tag('test-tag-1', message='Annotated ftw')
parentrepo.create_submodule(childname, childname,
url=childrepo.working_tree_dir)
parentrepo.create_submodule(child2name, child2name,
url=childrepo2.working_tree_dir)
parentrepo.index.commit('adding child repos')
self._populate_reqrepo(reqrepo, childname)
parentrepo.create_submodule('requirements', 'requirements',
url=reqrepo)
version = parentrepo.head.commit.hexsha
self._test_build_spec(version,
parentrepo.working_tree_dir,
childrepo2,
childrepo,
[child2name])
@utils.make_test_repo("childrepo2")
@utils.make_test_repo("childrepo")
@utils.make_test_repo("reqrepo")
@ -150,7 +189,8 @@ class TestBuildSpec(unittest.TestCase):
version,
working_tree,
childrepo2,
childrepo):
childrepo,
filter=None):
childname = os.path.basename(childrepo.working_tree_dir)
child2name = os.path.basename(childrepo2.working_tree_dir)
childhash = childrepo.head.commit.hexsha
@ -164,8 +204,13 @@ class TestBuildSpec(unittest.TestCase):
yaml.safe_dump(manifest, tf)
tf.flush()
tf.seek(0)
bs = build_spec.BuildSpec(tf, version)
bs = build_spec.BuildSpec(tf, version, project_filter=filter)
if not filter:
self.assertEqual(2, len(bs.projects))
else:
self.assertEqual(1, len(bs.projects))
results = {
childname: {
'gitref': childhash,