From cffec56ed0eb9eb84c6c2bf85fb5927cfd3500ed Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Wed, 12 Feb 2014 10:52:50 +0000 Subject: Remove test for tagging with multiple morphs repos We don't support this any more, it makes morphologies complicated to implement and reason about. --- .../tag-works-with-multiple-morphs-repos.script | 113 ------------- .../tag-works-with-multiple-morphs-repos.stdout | 176 --------------------- 2 files changed, 289 deletions(-) delete mode 100755 tests.branching/tag-works-with-multiple-morphs-repos.script delete mode 100644 tests.branching/tag-works-with-multiple-morphs-repos.stdout diff --git a/tests.branching/tag-works-with-multiple-morphs-repos.script b/tests.branching/tag-works-with-multiple-morphs-repos.script deleted file mode 100755 index f6ecbf32..00000000 --- a/tests.branching/tag-works-with-multiple-morphs-repos.script +++ /dev/null @@ -1,113 +0,0 @@ -#!/bin/sh -# -# Copyright (C) 2012-2013 Codethink Limited -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - -## Check that "morph tag" works if morphologies are spread across multiple -## repositories. In this case, it should copy all petrified morphologies -## into the branch root repository and only create the tag there. - -set -eu - -# Make sure the commits always have the same SHA1s. -. "$SRCDIR/scripts/fix-committer-info" - -# Create the first morphs repository. -mkdir "$DATADIR/morphs1" - -# Create system morphology in first morphs repository. -cat < "$DATADIR/morphs1/test-system.morph" -name: test-system -kind: system -arch: $(uname -m) -strata: -- morph: stratum1 - ref: master - repo: test:morphs1 -- morph: stratum2 - ref: master - repo: test:morphs2 -EOF - -# Create stratum that depends on another stratum. -cat < "$DATADIR/morphs1/stratum1.morph" -name: stratum1 -kind: stratum -build-depends: -- morph: stratum3 - ref: master - repo: test:morphs2 -chunks: -- build-depends: [] - name: hello - ref: master - repo: test:hello -EOF - -# Commit all files to the first repository. -scripts/run-git-in "$DATADIR/morphs1" init -q -scripts/run-git-in "$DATADIR/morphs1" add . -scripts/run-git-in "$DATADIR/morphs1" commit -q -m initial - -# Create second morphs repository. -mkdir "$DATADIR/morphs2" - -# Create two strata in the second repository. -cat < "$DATADIR/morphs2/stratum2.morph" -name: stratum2 -kind: stratum -build-depends: -- morph: stratum3 - repo: test:morphs2 - ref: master -chunks: -- build-depends: [] - name: hello - ref: master - repo: test:hello -EOF -cat < "$DATADIR/morphs2/stratum3.morph" -kind: stratum -name: stratum3 -chunks: -- build-depends: [] - build-mode: test - name: hello - ref: master - repo: test:hello -EOF - -# Commit all files to the second repository. -"$SRCDIR/scripts/run-git-in" "$DATADIR/morphs2" init -q -"$SRCDIR/scripts/run-git-in" "$DATADIR/morphs2" add . -"$SRCDIR/scripts/run-git-in" "$DATADIR/morphs2" commit -q -m initial - -cd "$DATADIR/workspace" -"$SRCDIR/scripts/test-morph" init - -# Check out the master system branch. -"$SRCDIR/scripts/test-morph" \ - checkout test:morphs1 master - -# Tag the master system branch. -"$SRCDIR/scripts/test-morph" \ - tag tag-across-multiple-repos -- -m "create tag" - -# Show the tag. -GIT_DIR="$DATADIR/workspace/master/test:morphs1/.git" \ - git show tag-across-multiple-repos -GIT_DIR="$DATADIR/workspace/master/test:morphs1/.git" \ - git log --format=fuller -n1 -p --stat tag-across-multiple-repos diff --git a/tests.branching/tag-works-with-multiple-morphs-repos.stdout b/tests.branching/tag-works-with-multiple-morphs-repos.stdout deleted file mode 100644 index 81fbf20d..00000000 --- a/tests.branching/tag-works-with-multiple-morphs-repos.stdout +++ /dev/null @@ -1,176 +0,0 @@ -tag tag-across-multiple-repos -Tagger: developer -Date: Tue Jul 31 16:51:54 2012 +0000 - -create tag - -commit 7323ed5dcc47715e7303fd36d537aef98a04df9a -Author: developer -Date: Tue Jul 31 16:51:54 2012 +0000 - - create tag - -diff --git a/stratum1.morph b/stratum1.morph -index 6d439df..074a838 100644 ---- a/stratum1.morph -+++ b/stratum1.morph -@@ -2,10 +2,13 @@ name: stratum1 - kind: stratum - build-depends: - - morph: stratum3 -- ref: master -- repo: test:morphs2 -+ ref: tag-across-multiple-repos -+ repo: test:morphs1 -+ unpetrify-ref: master -+ unpetrify-repo: test:morphs2 - chunks: - - build-depends: [] - name: hello -- ref: master -+ ref: 6c7ddb7a9c0c5bf4ee02a8de030f0892a399c6bb - repo: test:hello -+ unpetrify-ref: master -diff --git a/stratum2.morph b/stratum2.morph -new file mode 100644 -index 0000000..0b421ab ---- /dev/null -+++ b/stratum2.morph -@@ -0,0 +1,14 @@ -+name: stratum2 -+kind: stratum -+build-depends: -+- morph: stratum3 -+ repo: test:morphs1 -+ ref: tag-across-multiple-repos -+ unpetrify-ref: master -+ unpetrify-repo: test:morphs2 -+chunks: -+- build-depends: [] -+ name: hello -+ ref: 6c7ddb7a9c0c5bf4ee02a8de030f0892a399c6bb -+ repo: test:hello -+ unpetrify-ref: master -diff --git a/stratum3.morph b/stratum3.morph -new file mode 100644 -index 0000000..610fae6 ---- /dev/null -+++ b/stratum3.morph -@@ -0,0 +1,9 @@ -+kind: stratum -+name: stratum3 -+chunks: -+- build-depends: [] -+ build-mode: test -+ name: hello -+ ref: 6c7ddb7a9c0c5bf4ee02a8de030f0892a399c6bb -+ repo: test:hello -+ unpetrify-ref: master -diff --git a/test-system.morph b/test-system.morph -index 62d3b08..edb5745 100644 ---- a/test-system.morph -+++ b/test-system.morph -@@ -3,8 +3,11 @@ kind: system - arch: x86_64 - strata: - - morph: stratum1 -- ref: master -+ ref: tag-across-multiple-repos - repo: test:morphs1 -+ unpetrify-ref: master - - morph: stratum2 -- ref: master -- repo: test:morphs2 -+ ref: tag-across-multiple-repos -+ repo: test:morphs1 -+ unpetrify-ref: master -+ unpetrify-repo: test:morphs2 -commit 7323ed5dcc47715e7303fd36d537aef98a04df9a -Author: developer -AuthorDate: Tue Jul 31 16:51:54 2012 +0000 -Commit: developer -CommitDate: Tue Jul 31 16:51:54 2012 +0000 - - create tag ---- - stratum1.morph | 9 ++++++--- - stratum2.morph | 14 ++++++++++++++ - stratum3.morph | 9 +++++++++ - test-system.morph | 9 ++++++--- - 4 files changed, 35 insertions(+), 6 deletions(-) - -diff --git a/stratum1.morph b/stratum1.morph -index 6d439df..074a838 100644 ---- a/stratum1.morph -+++ b/stratum1.morph -@@ -2,10 +2,13 @@ name: stratum1 - kind: stratum - build-depends: - - morph: stratum3 -- ref: master -- repo: test:morphs2 -+ ref: tag-across-multiple-repos -+ repo: test:morphs1 -+ unpetrify-ref: master -+ unpetrify-repo: test:morphs2 - chunks: - - build-depends: [] - name: hello -- ref: master -+ ref: 6c7ddb7a9c0c5bf4ee02a8de030f0892a399c6bb - repo: test:hello -+ unpetrify-ref: master -diff --git a/stratum2.morph b/stratum2.morph -new file mode 100644 -index 0000000..0b421ab ---- /dev/null -+++ b/stratum2.morph -@@ -0,0 +1,14 @@ -+name: stratum2 -+kind: stratum -+build-depends: -+- morph: stratum3 -+ repo: test:morphs1 -+ ref: tag-across-multiple-repos -+ unpetrify-ref: master -+ unpetrify-repo: test:morphs2 -+chunks: -+- build-depends: [] -+ name: hello -+ ref: 6c7ddb7a9c0c5bf4ee02a8de030f0892a399c6bb -+ repo: test:hello -+ unpetrify-ref: master -diff --git a/stratum3.morph b/stratum3.morph -new file mode 100644 -index 0000000..610fae6 ---- /dev/null -+++ b/stratum3.morph -@@ -0,0 +1,9 @@ -+kind: stratum -+name: stratum3 -+chunks: -+- build-depends: [] -+ build-mode: test -+ name: hello -+ ref: 6c7ddb7a9c0c5bf4ee02a8de030f0892a399c6bb -+ repo: test:hello -+ unpetrify-ref: master -diff --git a/test-system.morph b/test-system.morph -index 62d3b08..edb5745 100644 ---- a/test-system.morph -+++ b/test-system.morph -@@ -3,8 +3,11 @@ kind: system - arch: x86_64 - strata: - - morph: stratum1 -- ref: master -+ ref: tag-across-multiple-repos - repo: test:morphs1 -+ unpetrify-ref: master - - morph: stratum2 -- ref: master -- repo: test:morphs2 -+ ref: tag-across-multiple-repos -+ repo: test:morphs1 -+ unpetrify-ref: master -+ unpetrify-repo: test:morphs2 -- cgit v1.2.1 From df8a5901bd886519b9fb06861d3c7a440d5ee7f1 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Wed, 12 Feb 2014 11:04:47 +0000 Subject: Remove edit-updates-stratum-build-depends test This test stopped being fit for purpose after an accidental edit made it no longer check the stratum build depends. However, rather than fixing it, it should be removed, since we're changing morph's behaviour to not support morphologies in different repositories, which means that updating these refs is no longer necessary. --- .../edit-updates-stratum-build-depends.script | 69 ---------------------- .../edit-updates-stratum-build-depends.stdout | 26 -------- 2 files changed, 95 deletions(-) delete mode 100755 tests.branching/edit-updates-stratum-build-depends.script delete mode 100644 tests.branching/edit-updates-stratum-build-depends.stdout diff --git a/tests.branching/edit-updates-stratum-build-depends.script b/tests.branching/edit-updates-stratum-build-depends.script deleted file mode 100755 index a108ce8a..00000000 --- a/tests.branching/edit-updates-stratum-build-depends.script +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/sh -# -# Copyright (C) 2012-2013 Codethink Limited -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - -## Verify that "morph edit" clones a chunk repository into a system branch. - -set -eu - -# Add a second stratum that build-depends on the first. We can ignore the fact -# that both strata contain the same chunk for this test. -cd "$DATADIR/morphs" - -cat < xyzzy-stratum.morph -build-depends: -- morph: hello-stratum - ref: master - repo: test:morphs -chunks: -- build-depends: [] - name: hello - ref: master - repo: test:hello -kind: stratum -name: xyzzy-stratum -EOF - - -# Add the xyzzy-stratum to hello-system. -awk ' -flag == 0 { print } -/^strata:/ { flag=1; next } -flag == 1 && /^[ -]/ { print; next } -flag == 1 { - print "- morph: xyzzy-stratum" - print " ref: master" - print " repo: test:morphs" - print $0 - flag = 0 -} -' hello-system.morph > temp -mv temp hello-system.morph - -git add xyzzy-stratum.morph hello-system.morph -git commit -q -m "Add 2nd stratum with a build dependency" - -# Create system branch. -cd "$DATADIR/workspace" -"$SRCDIR/scripts/test-morph" init -"$SRCDIR/scripts/test-morph" branch test:morphs newbranch - -# Edit chunk. -"$SRCDIR/scripts/test-morph" edit hello-system hello-stratum hello - -# See what effect the editing had. -"$SRCDIR/scripts/run-git-in" "newbranch/test:morphs" diff diff --git a/tests.branching/edit-updates-stratum-build-depends.stdout b/tests.branching/edit-updates-stratum-build-depends.stdout deleted file mode 100644 index 7120ef50..00000000 --- a/tests.branching/edit-updates-stratum-build-depends.stdout +++ /dev/null @@ -1,26 +0,0 @@ -diff --git a/hello-stratum.morph b/hello-stratum.morph -index 73ed482..475fe0f 100644 ---- a/hello-stratum.morph -+++ b/hello-stratum.morph -@@ -2,7 +2,8 @@ chunks: - - build-depends: [] - build-mode: test - name: hello -- ref: master -+ ref: newbranch - repo: test:hello -+ unpetrify-ref: master - kind: stratum - name: hello-stratum -diff --git a/hello-system.morph b/hello-system.morph -index 3f7b4d3..199c924 100644 ---- a/hello-system.morph -+++ b/hello-system.morph -@@ -3,5 +3,6 @@ kind: system - name: hello-system - strata: - - morph: hello-stratum -- ref: master -+ ref: newbranch - repo: test:morphs -+ unpetrify-ref: master -- cgit v1.2.1 From f6c767a64edd2634f1d513e15ce7bb5cfe62dfd9 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Wed, 12 Feb 2014 16:04:53 +0000 Subject: Allow tagging branches with null refs This includes various changes allowing the repo and ref fields to be missing; but also a change to the the component_key function, so that instead of generating a string, it returns a tuple, since it's only required to be a consistently hashable index. --- morphlib/plugins/branch_and_merge_plugin.py | 40 ++++++++++------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py index 4666ea96..d268decf 100644 --- a/morphlib/plugins/branch_and_merge_plugin.py +++ b/morphlib/plugins/branch_and_merge_plugin.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012,2013 Codethink Limited +# Copyright (C) 2012,2013,2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -610,10 +610,10 @@ class BranchAndMergePlugin(cliapp.Plugin): root_repo_dir): '''Check out the morphology that 'spec' refers to, for editing''' - if spec['repo'] == root_repo: + if spec.get('repo') in (None, root_repo): # This is only possible for stratum morphologies repo_dir = root_repo_dir - if spec['ref'] != branch: + if spec.get('ref') not in (None, root_repo): # Bring the morphology forward from its ref to the current HEAD repo = self.lrc.get_repo(root_repo) m = repo.load_morphology(spec['ref'], spec['morph']) @@ -1138,11 +1138,8 @@ class BranchAndMergePlugin(cliapp.Plugin): if 'strata' in morphology and morphology['strata']: strata += morphology['strata'] for info in strata: - # Obtain the commit SHA1 this stratum would be built from. - commit = self.resolve_info(info, resolved_refs) stratum_repo_dir = self.make_available( info, branch, branch_dir, repo, repo_dir) - info['ref'] = branch # Load the stratum morphology and petrify it recursively if # that hasn't happened yet. @@ -1150,24 +1147,13 @@ class BranchAndMergePlugin(cliapp.Plugin): if not stratum in petrified_morphologies: self.petrify_morphology(branch, branch_dir, branch_root, branch_root_dir, - info['repo'], stratum_repo_dir, - tagref, info['morph'], stratum, + info.get('repo') or branch_root, + stratum_repo_dir, tagref, + info['morph'], stratum, petrified_morphologies, resolved_refs, env, update_working_tree) - # Change the ref for this morphology to the tag we're creating. - if info['ref'] != tagref: - info['unpetrify-ref'] = info['ref'] - info['ref'] = tagref - - # We'll be copying all systems/strata into the tag commit - # in the branch root repo, so make sure to note what repos - # they all came from - if info['repo'] != branch_root: - info['unpetrify-repo'] = info['repo'] - info['repo'] = branch_root - # If this morphology is a stratum, resolve the refs of all its # chunks into SHA1s. if morphology['kind'] == 'stratum': @@ -1202,7 +1188,7 @@ class BranchAndMergePlugin(cliapp.Plugin): def resolve_info(self, info, resolved_refs): '''Takes a morphology info and resolves its ref with cache support.''' - key = (info['repo'], info['ref']) + key = (info.get('repo'), info.get('ref')) if not key in resolved_refs: commit_sha1, tree_sha1 = self.app.resolve_ref( self.lrc, self.rrc, info['repo'], info['ref'], @@ -1292,10 +1278,10 @@ class BranchAndMergePlugin(cliapp.Plugin): def component_key(info): # This function needs only to be stable and reproducible - key = info['repo'] + '|' + info['morph'] if 'name' in info: - key += '|' + info['name'] - return key + return (info.get('repo'), info['morph'], info['name']) + else: + return (info.get('repo'), info['morph']) if from_morph['name'] != to_morph['name']: # We should enforce name == filename in load_morphology() @@ -1471,12 +1457,12 @@ class BranchAndMergePlugin(cliapp.Plugin): changed = False edited_strata = [si for si in from_morph['strata'] - if si['ref'] == from_branch] + if si.get('ref') == from_branch] for si in edited_strata: for old_si in to_morph['strata']: # We make no attempt at rename / move detection if (old_si['morph'] == si['morph'] - and old_si['repo'] == si['repo']): + and old_si.get('repo') == si.get('repo')): break else: raise cliapp.AppException( @@ -1484,7 +1470,7 @@ class BranchAndMergePlugin(cliapp.Plugin): 'subsequently edited. This is not yet supported: ' 'refusing to merge.' % si['morph']) changed = True - si['ref'] = old_si['ref'] + si['ref'] = old_si.get('ref') merge_stratum(name, old_si, si) if changed: self.update_morphology(to_root_dir, name, to_morph) -- cgit v1.2.1 From 4e50b8850f13bef14ec31710c31801330e41cc32 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Wed, 12 Feb 2014 16:14:30 +0000 Subject: Allow omitting repo and ref when referring to strata --- morphlib/app.py | 10 +++---- morphlib/artifactresolver.py | 8 +++--- morphlib/buildbranch.py | 4 +-- morphlib/buildcommand.py | 4 +-- morphlib/morphset.py | 37 +++++++++++++------------ morphlib/plugins/branch_and_merge_new_plugin.py | 6 ++-- 6 files changed, 35 insertions(+), 34 deletions(-) diff --git a/morphlib/app.py b/morphlib/app.py index aecee42b..7fb71c7b 100644 --- a/morphlib/app.py +++ b/morphlib/app.py @@ -1,4 +1,4 @@ -# Copyright (C) 2011-2013 Codethink Limited +# Copyright (C) 2011-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -346,14 +346,14 @@ class Morph(cliapp.Application): visit(reponame, ref, filename, absref, tree, morphology) if morphology['kind'] == 'system': - queue.extend((s['repo'] or reponame, - s['ref'] or ref, + queue.extend((s.get('repo') or reponame, + s.get('ref') or ref, '%s.morph' % s['morph']) for s in morphology['strata']) elif morphology['kind'] == 'stratum': if morphology['build-depends']: - queue.extend((s['repo'] or reponame, - s['ref'] or ref, + queue.extend((s.get('repo') or reponame, + s.get('ref') or ref, '%s.morph' % s['morph']) for s in morphology['build-depends']) queue.extend((c['repo'], c['ref'], '%s.morph' % c['morph']) diff --git a/morphlib/artifactresolver.py b/morphlib/artifactresolver.py index ae0cfcf5..00976eb7 100644 --- a/morphlib/artifactresolver.py +++ b/morphlib/artifactresolver.py @@ -140,8 +140,8 @@ class ArtifactResolver(object): for info in source.morphology['strata']: stratum_source = self._source_pool.lookup( - info['repo'] or source.repo_name, - info['ref'] or source.original_ref, + info.get('repo') or source.repo_name, + info.get('ref') or source.original_ref, '%s.morph' % info['morph']) stratum_name = stratum_source.morphology['name'] @@ -165,8 +165,8 @@ class ArtifactResolver(object): for stratum_info in source.morphology.get('build-depends') or []: other_source = self._source_pool.lookup( - stratum_info['repo'] or source.repo_name, - stratum_info['ref'] or source.original_ref, + stratum_info.get('repo') or source.repo_name, + stratum_info.get('ref') or source.original_ref, '%s.morph' % stratum_info['morph']) # Make every stratum artifact this stratum source produces diff --git a/morphlib/buildbranch.py b/morphlib/buildbranch.py index d4426afb..546a29d5 100644 --- a/morphlib/buildbranch.py +++ b/morphlib/buildbranch.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013 Codethink Limited +# Copyright (C) 2013-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -125,7 +125,7 @@ class BuildBranch(object): sb_info[repo, ref] = (gd, build_ref) def filter(m, kind, spec): - return (spec['repo'], spec['ref']) in sb_info + return (spec.get('repo'), spec.get('ref')) in sb_info def process(m, kind, spec): repo, ref = spec['repo'], spec['ref'] gd, build_ref = sb_info[repo, ref] diff --git a/morphlib/buildcommand.py b/morphlib/buildcommand.py index 6485f510..137c63b4 100644 --- a/morphlib/buildcommand.py +++ b/morphlib/buildcommand.py @@ -228,8 +228,8 @@ class BuildCommand(object): def _validate_cross_refs_for_xxx(self, src, srcpool, specs, wanted): for spec in specs: - repo_name = spec['repo'] or src.repo_name - ref = spec['ref'] or src.original_ref + repo_name = spec.get('repo') or src.repo_name + ref = spec.get('ref') or src.original_ref filename = '%s.morph' % spec['morph'] logging.debug( 'Validating cross ref to %s:%s:%s' % diff --git a/morphlib/morphset.py b/morphlib/morphset.py index 6aabbde5..dedbabd5 100644 --- a/morphlib/morphset.py +++ b/morphlib/morphset.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013 Codethink Limited +# Copyright (C) 2013-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -81,7 +81,7 @@ class MorphologySet(object): for spec in specs: name = spec.get('morph', spec.get('name')) if name == wanted_name: - return spec['repo'], spec['ref'], name + return spec.get('repo'), spec.get('ref'), name return None, None, None def get_stratum_in_system(self, system_morph, stratum_name): @@ -160,7 +160,8 @@ class MorphologySet(object): specs = m[kind] for spec in specs: if cb_filter(m, kind, spec): - orig_spec = (spec['repo'], spec['ref'], spec['morph']) + orig_spec = (spec.get('repo'), spec.get('ref'), + spec['morph']) dirtied = cb_process(m, kind, spec) if dirtied: m.dirty = True @@ -177,11 +178,11 @@ class MorphologySet(object): tup = (m.repo_url, m.ref, m.filename[:-len('.morph')]) if tup in altered_references: spec = altered_references[tup] - if m.ref != spec['ref']: - m.ref = spec['ref'] + if m.ref != spec.get('ref'): + m.ref = spec.get('ref') m.dirty = True assert (m.filename == spec['morph'] + '.morph' - or m.repo_url == spec['repo']), \ + or m.repo_url == spec.get('repo')), \ 'Moving morphologies is not supported.' def change_ref(self, repo_url, orig_ref, morph_filename, new_ref): @@ -193,12 +194,12 @@ class MorphologySet(object): ''' def wanted_spec(m, kind, spec): - return (spec['repo'] == repo_url and - spec['ref'] == orig_ref and + return (spec.get('repo') == repo_url and + spec.get('ref') == orig_ref and spec['morph'] + '.morph' == morph_filename) def process_spec(m, kind, spec): - spec['unpetrify-ref'] = spec['ref'] + spec['unpetrify-ref'] = spec.get('ref') spec['ref'] = new_ref return True @@ -214,10 +215,10 @@ class MorphologySet(object): known = set() def wanted_spec(m, kind, spec): - return (spec['repo'], spec['ref']) not in known + return (spec.get('repo'), spec.get('ref')) not in known def process_spec(m, kind, spec): - known.add((spec['repo'], spec['ref'])) + known.add((spec.get('repo'), spec.get('ref'))) return False self.traverse_specs(process_spec, wanted_spec) @@ -234,11 +235,11 @@ class MorphologySet(object): ''' def wanted_spec(m, kind, spec): - return spec['repo'] == repo_url + return spec.get('repo') == repo_url def process_spec(m, kind, spec): if 'unpetrify-ref' not in spec: - spec['unpetrify-ref'] = spec['ref'] + spec['unpetrify-ref'] = spec.get('ref') spec['ref'] = new_ref return True @@ -262,13 +263,13 @@ class MorphologySet(object): # the details are tricky. if not (m['kind'] == 'stratum' and kind == 'chunks'): return - ref = spec['ref'] + ref = spec.get('ref') return (not morphlib.git.is_valid_sha1(ref) - and (spec['repo'], ref) in resolutions) + and (spec.get('repo'), ref) in resolutions) def process_chunk_spec(m, kind, spec): - tup = (spec['repo'], spec['ref']) - spec['unpetrify-ref'] = spec['ref'] + tup = (spec.get('repo'), spec.get('ref')) + spec['unpetrify-ref'] = spec.get('ref') spec['ref'] = resolutions[tup] return True @@ -281,7 +282,7 @@ class MorphologySet(object): def wanted_spec(m, kind, spec): return ('unpetrify-ref' in spec and - morphlib.git.is_valid_sha1(spec['ref'])) + morphlib.git.is_valid_sha1(spec.get('ref'))) def process_spec(m, kind, spec): spec['ref'] = spec.pop('unpetrify-ref') return True diff --git a/morphlib/plugins/branch_and_merge_new_plugin.py b/morphlib/plugins/branch_and_merge_new_plugin.py index f3b47468..94b2381c 100644 --- a/morphlib/plugins/branch_and_merge_new_plugin.py +++ b/morphlib/plugins/branch_and_merge_new_plugin.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012,2013 Codethink Limited +# Copyright (C) 2012,2013,2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -284,8 +284,8 @@ class SimpleBranchAndMergePlugin(cliapp.Plugin): # of triplets (repo url, ref, filename). return [ - (spec['repo'] or morph.repo_url, - spec['ref'] or morph.ref, + (spec.get('repo') or morph.repo_url, + spec.get('ref') or morph.ref, '%s.morph' % spec['morph']) for spec in specs ] -- cgit v1.2.1 From 2c9ad8890860f47d03433405c57f33f514fcd456 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Wed, 12 Feb 2014 16:18:45 +0000 Subject: Don't use repo or ref in test suite --- morphlib/morphloader_tests.py | 10 +++++----- morphlib/morphologyfactory_tests.py | 2 -- tests.as-root/metadata-includes-morph-version.setup | 6 +----- tests.as-root/metadata-includes-repo-alias.setup | 6 +----- tests.as-root/setup | 14 +------------- tests.as-root/system-overlap.script | 6 +----- tests.as-root/tarball-image-is-sensible.setup | 8 +------- tests.branching/setup | 4 +--- tests.build/setup | 4 +--- tests.build/setup-build-essential | 4 +--- tests.deploy/setup | 10 +--------- tests/show-dependencies.setup | 6 +----- yarns/implementations.yarn | 10 ---------- yarns/regression.yarn | 2 -- yarns/splitting.yarn | 2 -- 15 files changed, 15 insertions(+), 79 deletions(-) diff --git a/morphlib/morphloader_tests.py b/morphlib/morphloader_tests.py index 39923348..bd3e77e3 100644 --- a/morphlib/morphloader_tests.py +++ b/morphlib/morphloader_tests.py @@ -382,8 +382,6 @@ build-system: dummy m['build-depends'] = [ { - "repo": "foo", - "ref": "foo", "morph": "foo", }, ] @@ -655,17 +653,19 @@ name: foo self.loader.set_defaults(m) self.loader.validate(m) self.assertEqual( - dict(m), { 'kind': 'system', 'name': 'foo', 'description': '', 'arch': 'testarch', 'strata': [ - {'morph': 'bar'}, + { + 'morph': 'bar', + }, ], 'configuration-extensions': [], - }) + }, + dict(m)) def test_unsets_defaults_for_system(self): m = morphlib.morph3.Morphology( diff --git a/morphlib/morphologyfactory_tests.py b/morphlib/morphologyfactory_tests.py index 30504e00..39092857 100644 --- a/morphlib/morphologyfactory_tests.py +++ b/morphlib/morphologyfactory_tests.py @@ -103,8 +103,6 @@ class FakeLocalRepo(object): "kind": "stratum", "build-depends": [ { - "repo": "test:repo", - "ref": "sha1", "morph": "stratum" } ], diff --git a/tests.as-root/metadata-includes-morph-version.setup b/tests.as-root/metadata-includes-morph-version.setup index f0aefb3c..31829b01 100755 --- a/tests.as-root/metadata-includes-morph-version.setup +++ b/tests.as-root/metadata-includes-morph-version.setup @@ -1,6 +1,6 @@ #!/bin/bash # -# Copyright (C) 2013 Codethink Limited +# Copyright (C) 2013-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -31,13 +31,9 @@ cat < hello-tarball.morph "strata": [ { "morph": "hello-stratum", - "repo": "test:morphs", - "ref": "master" }, { "morph": "linux-stratum", - "repo": "test:morphs", - "ref": "master" } ] } diff --git a/tests.as-root/metadata-includes-repo-alias.setup b/tests.as-root/metadata-includes-repo-alias.setup index f0aefb3c..31829b01 100755 --- a/tests.as-root/metadata-includes-repo-alias.setup +++ b/tests.as-root/metadata-includes-repo-alias.setup @@ -1,6 +1,6 @@ #!/bin/bash # -# Copyright (C) 2013 Codethink Limited +# Copyright (C) 2013-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -31,13 +31,9 @@ cat < hello-tarball.morph "strata": [ { "morph": "hello-stratum", - "repo": "test:morphs", - "ref": "master" }, { "morph": "linux-stratum", - "repo": "test:morphs", - "ref": "master" } ] } diff --git a/tests.as-root/setup b/tests.as-root/setup index 2ab1cd94..b865f42d 100755 --- a/tests.as-root/setup +++ b/tests.as-root/setup @@ -10,7 +10,7 @@ # The stratum repository contains a single branch, "master", with a # stratum and a system morphology that include the chunk above. # -# Copyright (C) 2011, 2012, 2013 Codethink Limited +# Copyright (C) 2011, 2012, 2013, 2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -120,8 +120,6 @@ name: tools-stratum kind: stratum build-depends: - morph: linux-stratum - repo: test:morphs - ref: master chunks: - name: tools repo: test:tools-repo @@ -137,8 +135,6 @@ kind: system arch: `uname -m` strata: - morph: hello-stratum - repo: test:morphs - ref: master EOF git add hello-system.morph @@ -147,8 +143,6 @@ name: linux-stratum kind: stratum build-depends: - morph: hello-stratum - repo: test:morphs - ref: master chunks: - name: linux repo: test:kernel-repo @@ -164,14 +158,8 @@ kind: system arch: `uname -m` strata: - morph: hello-stratum - repo: test:morphs - ref: master - morph: linux-stratum - repo: test:morphs - ref: master - morph: tools-stratum - repo: test:morphs - ref: master EOF git add linux-system.morph diff --git a/tests.as-root/system-overlap.script b/tests.as-root/system-overlap.script index 41ff7536..c6154e0e 100755 --- a/tests.as-root/system-overlap.script +++ b/tests.as-root/system-overlap.script @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (C) 2011-2013 Codethink Limited +# Copyright (C) 2011-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -35,13 +35,9 @@ cat <overlap-system.morph "strata": [ { "morph": "foo-baz-stratum", - "repo": "test:morphs", - "ref": "overlap" }, { "morph": "foo-barqux-stratum", - "repo": "test:morphs", - "ref": "overlap" } ] } diff --git a/tests.as-root/tarball-image-is-sensible.setup b/tests.as-root/tarball-image-is-sensible.setup index 5fd7b283..505707b3 100755 --- a/tests.as-root/tarball-image-is-sensible.setup +++ b/tests.as-root/tarball-image-is-sensible.setup @@ -1,6 +1,6 @@ #!/bin/bash # -# Copyright (C) 2011-2013 Codethink Limited +# Copyright (C) 2011-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -50,18 +50,12 @@ cat < hello-tarball.morph "strata": [ { "morph": "link-stratum", - "repo": "test:morphs", - "ref": "tarball-links" }, { "morph": "hello-stratum", - "repo": "test:morphs", - "ref": "tarball-links" }, { "morph": "linux-stratum", - "repo": "test:morphs", - "ref": "tarball-links" } ] } diff --git a/tests.branching/setup b/tests.branching/setup index 1263e3b6..9dfe27df 100755 --- a/tests.branching/setup +++ b/tests.branching/setup @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (C) 2012-2013 Codethink Limited +# Copyright (C) 2012-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -53,8 +53,6 @@ kind: system name: hello-system strata: - morph: hello-stratum - ref: master - repo: test:morphs EOF cat < "$DATADIR/morphs/hello-stratum.morph" diff --git a/tests.build/setup b/tests.build/setup index 563482e6..8b1dfd0e 100755 --- a/tests.build/setup +++ b/tests.build/setup @@ -10,7 +10,7 @@ # The stratum repository contains a single branch, "master", with a # stratum and a system morphology that include the chunk above. # -# Copyright (C) 2011-2013 Codethink Limited +# Copyright (C) 2011-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -111,8 +111,6 @@ cat < hello-system.morph "strata": [ { "morph": "hello-stratum", - "repo": "test:morphs-repo", - "ref": "master" } ] } diff --git a/tests.build/setup-build-essential b/tests.build/setup-build-essential index 778716f1..5674020d 100755 --- a/tests.build/setup-build-essential +++ b/tests.build/setup-build-essential @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (C) 2013 Codethink Limited +# Copyright (C) 2013-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -117,8 +117,6 @@ cat < "hello-stratum.morph" "build-depends": [ { "morph": "build-essential", - "repo": "test:morphs-repo", - "ref": "master" } ], "chunks": [ diff --git a/tests.deploy/setup b/tests.deploy/setup index 5f83747e..5fbe0262 100755 --- a/tests.deploy/setup +++ b/tests.deploy/setup @@ -10,7 +10,7 @@ # The stratum repository contains a single branch, "master", with a # stratum and a system morphology that include the chunk above. # -# Copyright (C) 2011, 2012, 2013 Codethink Limited +# Copyright (C) 2011, 2012, 2013, 2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -116,8 +116,6 @@ cat < hello-system.morph "strata": [ { "morph": "hello-stratum", - "repo": "test:morphs", - "ref": "master" } ] } @@ -131,8 +129,6 @@ cat < linux-stratum.morph "build-depends": [ { "morph": "hello-stratum", - "repo": "test:morphs", - "ref": "master" } ], "chunks": [ @@ -156,13 +152,9 @@ cat < linux-system.morph "strata": [ { "morph": "hello-stratum", - "repo": "test:morphs", - "ref": "master" }, { "morph": "linux-stratum", - "repo": "test:morphs", - "ref": "master" } ], "configuration-extensions": [ diff --git a/tests/show-dependencies.setup b/tests/show-dependencies.setup index edb9b6ab..e1cc71ae 100755 --- a/tests/show-dependencies.setup +++ b/tests/show-dependencies.setup @@ -1,6 +1,6 @@ #!/bin/bash # -# Copyright (C) 2012-2013 Codethink Limited +# Copyright (C) 2012-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -197,8 +197,6 @@ cat < xfce-core.morph "build-depends": [ { "morph": "gtk-stack", - "repo": "test:test-repo", - "ref": "master" } ], "chunks": [ @@ -352,8 +350,6 @@ cat < xfce-system.morph "arch": "$(uname -m)", "strata": [ { - "repo": "test:test-repo", - "ref": "master", "build-mode": "test", "morph": "xfce-core" } diff --git a/yarns/implementations.yarn b/yarns/implementations.yarn index b4d8e7ce..e3db6b10 100644 --- a/yarns/implementations.yarn +++ b/yarns/implementations.yarn @@ -78,8 +78,6 @@ another to hold a chunk. arch: $arch strata: - name: test-stratum - repo: test:morphs - ref: master morph: test-stratum EOF @@ -293,8 +291,6 @@ have a morphology using the test architecture. kind: stratum build-depends: - morph: build-essential - ref: master - repo: test:morphs chunks: - name: test-chunk repo: test:test-chunk @@ -312,12 +308,8 @@ have a morphology using the test architecture. name: $MATCH_1 strata: - name: build-essential - repo: test:morphs - ref: master morph: build-essential - name: core - repo: test:morphs - ref: master morph: core EOF @@ -469,8 +461,6 @@ print-architecture` to get a value appropriate for morph. name: $MATCH_1 strata: - name: test-stratum - repo: test:morphs - ref: master morph: test-stratum EOF diff --git a/yarns/regression.yarn b/yarns/regression.yarn index 71431ff7..d8eedea2 100644 --- a/yarns/regression.yarn +++ b/yarns/regression.yarn @@ -77,8 +77,6 @@ Implementations arch: $arch strata: - morph: bootstrap-stratum - repo: test:morphs - ref: master EOF cat << EOF > "$DATADIR/gits/morphs/bootstrap-stratum.morph" diff --git a/yarns/splitting.yarn b/yarns/splitting.yarn index 40da5fb4..3da397f5 100644 --- a/yarns/splitting.yarn +++ b/yarns/splitting.yarn @@ -158,8 +158,6 @@ Implementations arch: $(run_morph print-architecture) strata: - name: test-stratum - repo: test:morphs - ref: master morph: test-stratum artifacts: - test-stratum-runtime -- cgit v1.2.1 From 070bcbd497583955e9069ced7aa2473bce2bc3b5 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Wed, 12 Feb 2014 16:25:23 +0000 Subject: Remove tests for working with null refs Refs should be completely omitted, and this is now the standard behaviour, so there's little value in testing the behaviour separately. --- scripts/nullify-local-refs | 18 -------- tests.build/build-system-with-null-refs.script | 24 ---------- tests.build/build-system-with-null-refs.setup | 23 ---------- tests.deploy/deploy-with-null-refs.script | 35 -------------- yarns/branches-workspaces.yarn | 63 -------------------------- yarns/implementations.yarn | 11 ----- yarns/morph.shell-lib | 7 +-- 7 files changed, 1 insertion(+), 180 deletions(-) delete mode 100755 scripts/nullify-local-refs delete mode 100755 tests.build/build-system-with-null-refs.script delete mode 100755 tests.build/build-system-with-null-refs.setup delete mode 100755 tests.deploy/deploy-with-null-refs.script diff --git a/scripts/nullify-local-refs b/scripts/nullify-local-refs deleted file mode 100755 index 5db5c587..00000000 --- a/scripts/nullify-local-refs +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/python - -import yaml, sys -repo = sys.argv[1] -ref = sys.argv[2] -for filename in sys.argv[3:]: - with open(filename, "r") as f: - d = yaml.load(f) - if "strata" in d: - for spec in d["strata"]: - if spec["repo"] == repo and spec["ref"] == ref: - spec["repo"] = spec["ref"] = None - if "build-depends" in d: - for spec in d["build-depends"]: - if spec["repo"] == repo and spec["ref"] == ref: - spec["repo"] = spec["ref"] = None - with open(filename, "w") as f: - yaml.dump(d, f) diff --git a/tests.build/build-system-with-null-refs.script b/tests.build/build-system-with-null-refs.script deleted file mode 100755 index e23dcafa..00000000 --- a/tests.build/build-system-with-null-refs.script +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -# -# Copyright (C) 2013 Codethink Limited -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - -## Test building a system with null refs - -set -eu - -"$SRCDIR/scripts/test-morph" build-morphology \ - test:morphs-repo master hello-system diff --git a/tests.build/build-system-with-null-refs.setup b/tests.build/build-system-with-null-refs.setup deleted file mode 100755 index cbf53076..00000000 --- a/tests.build/build-system-with-null-refs.setup +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh -# -# Copyright (C) 2013 Codethink Limited -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -set -eu - -cd "$DATADIR/morphs-repo" -"$SRCDIR/scripts/nullify-local-refs" test:morphs master *.morph -git add *.morph -git commit --quiet -m "Nullify all refs" diff --git a/tests.deploy/deploy-with-null-refs.script b/tests.deploy/deploy-with-null-refs.script deleted file mode 100755 index c283debf..00000000 --- a/tests.deploy/deploy-with-null-refs.script +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -# -# Copyright (C) 2013 Codethink Limited -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - - -set -eu - - -. "$SRCDIR/tests.deploy/setup-build" - -cd "$DATADIR/workspace/branch1" -"$SRCDIR/scripts/nullify-local-refs" test:morphs master test:morphs/*.morph - -"$SRCDIR/scripts/test-morph" build hello-system - -"$SRCDIR/scripts/test-morph" build linux-system - -"$SRCDIR/scripts/test-morph" --log "$DATADIR/deploy.log" \ - deploy test_cluster \ - linux-system-2.HOSTNAME="baserock-rocks-even-more" \ - > /dev/null diff --git a/yarns/branches-workspaces.yarn b/yarns/branches-workspaces.yarn index b928f628..08627fe9 100644 --- a/yarns/branches-workspaces.yarn +++ b/yarns/branches-workspaces.yarn @@ -300,69 +300,6 @@ Creating a tag twice should fail. WHEN the user attempts to tag the system branch called foo as test123 THEN morph failed -Working with null repositories and refs ---------------------------------------- - -It is convenient to not explicitly name the repository and branch of -a stratum morphology, instead assuming it is the same as the current -morphology. - -These can be checked out like normal system branches. - - SCENARIO check out an existing system branch with null refs - GIVEN a workspace - AND a git server - AND null refs for local strata - WHEN the user checks out the system branch called master - THEN the system branch master is checked out - -Likewise we can also create new system branches from these, and we -wouldn't need to worry about changing the system branch ref. - - - SCENARIO branch off a system branch with null refs - GIVEN a workspace - AND a git server - AND null refs for local strata - WHEN the user creates a system branch called foo - THEN the system branch foo is checked out - -When we edit a morphology with null refs, they stay null. - - SCENARIO editing with null refs - GIVEN a workspace - AND a git server - AND null refs for local strata - -When creating the branch, the refs remain null. - - WHEN the user creates a system branch called foo - THEN in branch foo, system test-system refs test-stratum in None - -After editing the stratum they remain null. - - WHEN the user edits the stratum test-stratum in the system test-system in branch foo - THEN in branch foo, system test-system refs test-stratum in None - -Refs to chunks are still altered as usual - - WHEN the user edits the chunk test-chunk in the stratum test-stratum in the system test-system in branch foo - THEN in branch foo, system test-system refs test-stratum in None - AND in branch foo, stratum test-stratum refs test-chunk in foo - AND the edited chunk test:test-chunk has git branch foo - -Petrifying also leaves null refs unmolested - - SCENARIO morph petrifies null refs - GIVEN a workspace - AND a git server - AND null refs for local strata - WHEN the user creates a system branch called foo - AND the user pushes the system branch called foo to the git server - AND remembering all refs in foo - AND petrifying foo - THEN in branch foo, system test-system refs test-stratum in None - Generating a manifest works SCENARIO morph generates a manifest diff --git a/yarns/implementations.yarn b/yarns/implementations.yarn index e3db6b10..2a46dfa2 100644 --- a/yarns/implementations.yarn +++ b/yarns/implementations.yarn @@ -318,17 +318,6 @@ have a morphology using the test architecture. run_in "$DATADIR/gits/morphs" git add "$MATCH_1.morph" run_in "$DATADIR/gits/morphs" git commit -m "Added $MATCH_1 and strata morphologies." -Morphologies need to support having a null ref, which means look for the -stratum in the same repository and ref. Testing this requires different -morphologies. - - IMPLEMENTS GIVEN null refs for local strata - nullify_local_refs test:morphs master \ - "$DATADIR/gits/morphs/test-system.morph" \ - "$DATADIR/gits/morphs/test-stratum.morph" - run_in "$DATADIR/gits/morphs" git add . - run_in "$DATADIR/gits/morphs" git commit -m "Use null refs." - Implementation sections for system branch operations ---------------------------------------------------- diff --git a/yarns/morph.shell-lib b/yarns/morph.shell-lib index 66abd076..31dcc7af 100644 --- a/yarns/morph.shell-lib +++ b/yarns/morph.shell-lib @@ -3,7 +3,7 @@ # The shell functions in this library are meant to make writing IMPLEMENTS # sections for yarn scenario tests easier. -# Copyright (C) 2013 Codethink Limited +# Copyright (C) 2013-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -152,11 +152,6 @@ assert_morphologies_are_petrified() } -nullify_local_refs() -{ - "$SRCDIR/scripts/nullify-local-refs" "$@" -} - # Currently, yarn isn't setting $SRCDIR to point at the project source # directory. We simulate this here. -- cgit v1.2.1 From fbf70e2e5595d0cc7edaf7240a732cc5d2632c34 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Wed, 12 Feb 2014 16:27:32 +0000 Subject: Warn and default to null if repo or ref are given This now means that the system morphology is not altered when chunks are altered, so some tests had to change. Since this uses the python warnings API, these warnings can be ignored by running python -W ignore:"stratum morphology" \ -W ignore:"system morphology" \ "$(which morph)" ...` or turned into errors with python -W error:"stratum morphology" \ -W error:"system morphology" \ "$(which morph)" ...` --- morphlib/morphloader.py | 57 +++++++++++++++- morphlib/morphloader_tests.py | 80 ++++++++++++++++++++++- morphlib/morphologyfactory.py | 10 +++ scripts/test-morph | 10 ++- tests.branching/edit-updates-stratum.stdout | 12 ---- tests.branching/tag-creates-commit-and-tag.stdout | 18 +---- tests.branching/tag-tag-works-as-expected.stdout | 18 +---- tests.branching/workflow.stdout | 1 - yarns/branches-workspaces.yarn | 15 +---- 9 files changed, 158 insertions(+), 63 deletions(-) diff --git a/morphlib/morphloader.py b/morphlib/morphloader.py index 32b5b40b..e4367fa1 100644 --- a/morphlib/morphloader.py +++ b/morphlib/morphloader.py @@ -18,11 +18,27 @@ import collections import logging +import warnings import yaml import morphlib +class MorphologyObsoleteFieldWarning(UserWarning): + + def __init__(self, morphology, spec, field): + self.kind = morphology['kind'] + self.morphology_name = morphology.get('name', '') + self.stratum_name = spec.get('alias', spec['morph']) + self.field = field + + def __str__(self): + format_string = ('%(kind)s morphology %(morphology_name)s refers to ' + 'stratum %(stratum_name)s with the %(field)s field. ' + 'Defaulting to null.') + return format_string % self.__dict__ + + class MorphologySyntaxError(morphlib.Error): def __init__(self, morphology): @@ -366,6 +382,9 @@ class MorphologyLoader(object): raise DuplicateStratumError(morph['name'], name) names.add(name) + # Validate stratum spec fields + self._validate_stratum_specs_fields(morph, 'strata') + # We allow the ARMv7 little-endian architecture to be specified # as armv7 and armv7l. Normalise. if morph['arch'] == 'armv7': @@ -409,6 +428,9 @@ class MorphologyLoader(object): raise NoStratumBuildDependenciesError( morph['name'], morph.filename) + # Validate build-dependencies if specified + self._validate_stratum_specs_fields(morph, 'build-depends') + # Require build-dependencies for each chunk. for spec in morph['chunks']: if 'build-depends' not in spec: @@ -496,6 +518,18 @@ class MorphologyLoader(object): type(pattern), morphology_name) errors.append(e) + @classmethod + def _warn_obsolete_field(cls, morphology, spec, field): + warnings.warn(MorphologyObsoleteFieldWarning(morphology, spec, field), + stacklevel=2) + + @classmethod + def _validate_stratum_specs_fields(cls, morphology, specs_field): + for spec in morphology.get(specs_field, None) or []: + for obsolete_field in ('repo', 'ref'): + if obsolete_field in spec: + cls._warn_obsolete_field(morphology, spec, obsolete_field) + def _require_field(self, field, morphology): if field not in morphology: raise MissingFieldError(field, morphology.filename) @@ -542,9 +576,23 @@ class MorphologyLoader(object): if key in morphology and morphology[key] == defaults[key]: del morphology[key] - if kind in ('stratum', 'cluster'): + if kind in ('system', 'stratum', 'cluster'): getattr(self, '_unset_%s_defaults' % kind)(morphology) + @classmethod + def _set_stratum_specs_defaults(cls, morphology, specs_field): + for spec in morphology.get(specs_field, None) or []: + for obsolete_field in ('repo', 'ref'): + if obsolete_field in spec: + del spec[obsolete_field] + + @classmethod + def _unset_stratum_specs_defaults(cls, morphology, specs_field): + for spec in morphology.get(specs_field, []): + for obsolete_field in ('repo', 'ref'): + if obsolete_field in spec: + del spec[obsolete_field] + def _set_cluster_defaults(self, morph): for system in morph.get('systems', []): if 'deploy-defaults' not in system: @@ -560,7 +608,10 @@ class MorphologyLoader(object): del system['deploy'] def _set_system_defaults(self, morph): - pass + self._set_stratum_specs_defaults(morph, 'strata') + + def _unset_system_defaults(self, morph): + self._unset_stratum_specs_defaults(morph, 'strata') def _set_stratum_defaults(self, morph): for spec in morph['chunks']: @@ -568,6 +619,7 @@ class MorphologyLoader(object): spec['repo'] = spec['name'] if 'morph' not in spec: spec['morph'] = spec['name'] + self._set_stratum_specs_defaults(morph, 'build-depends') def _unset_stratum_defaults(self, morph): for spec in morph['chunks']: @@ -575,6 +627,7 @@ class MorphologyLoader(object): del spec['repo'] if 'morph' in spec and spec['morph'] == spec['name']: del spec['morph'] + self._unset_stratum_specs_defaults(morph, 'strata') def _set_chunk_defaults(self, morph): if morph['max-jobs'] is not None: diff --git a/morphlib/morphloader_tests.py b/morphlib/morphloader_tests.py index bd3e77e3..b8738804 100644 --- a/morphlib/morphloader_tests.py +++ b/morphlib/morphloader_tests.py @@ -16,12 +16,15 @@ # =*= License: GPL-2 =*= +import contextlib import os import shutil import tempfile import unittest +import warnings import morphlib +from morphlib.morphloader import MorphologyObsoleteFieldWarning class MorphologyLoaderTests(unittest.TestCase): @@ -648,10 +651,13 @@ name: foo name='foo', arch='testarch', strata=[ - {'morph': 'bar'}, + { + 'morph': 'bar', + 'repo': 'obsolete', + 'ref': 'obsolete', + }, ]) self.loader.set_defaults(m) - self.loader.validate(m) self.assertEqual( { 'kind': 'system', @@ -675,7 +681,11 @@ name: foo 'name': 'foo', 'arch': 'testarch', 'strata': [ - {'morph': 'bar'}, + { + 'morph': 'bar', + 'repo': None, + 'ref': None, + }, ], 'configuration-extensions': [], }) @@ -788,3 +798,67 @@ name: foo self.assertEqual(m['name'], 'foo') self.assertEqual(m['kind'], 'cluster') self.assertEqual(m['systems'][0]['morph'], 'bar') + + @contextlib.contextmanager + def catch_warnings(*warning_classes): + with warnings.catch_warnings(record=True) as caught_warnings: + warnings.resetwarnings() + for warning_class in warning_classes: + warnings.simplefilter("always", warning_class) + yield caught_warnings + + def test_warns_when_systems_refer_to_strata_with_repo_or_ref(self): + for obsolete_field in ('repo', 'ref'): + m = morphlib.morph3.Morphology( + name="foo", + kind="system", + arch="testarch", + strata=[ + { + 'morph': 'bar', + obsolete_field: 'obsolete', + }]) + + with self.catch_warnings(MorphologyObsoleteFieldWarning) \ + as caught_warnings: + + self.loader.validate(m) + self.assertEqual(len(caught_warnings), 1) + warning = caught_warnings[0].message + self.assertEqual(warning.kind, 'system') + self.assertEqual(warning.morphology_name, 'foo') + self.assertEqual(warning.stratum_name, 'bar') + self.assertEqual(warning.field, obsolete_field) + + def test_warns_when_strata_refer_to_build_depends_with_repo_or_ref(self): + for obsolete_field in ('repo', 'ref'): + m = morphlib.morph3.Morphology( + { + 'name': 'foo', + 'kind': 'stratum', + 'build-depends': [ + { + 'morph': 'bar', + obsolete_field: 'obsolete' + }, + ], + 'chunks': [ + { + 'morph': 'chunk', + 'name': 'chunk', + 'build-mode': 'test', + 'build-depends': [], + }, + ], + }) + + with self.catch_warnings(MorphologyObsoleteFieldWarning) \ + as caught_warnings: + + self.loader.validate(m) + self.assertEqual(len(caught_warnings), 1) + warning = caught_warnings[0].message + self.assertEqual(warning.kind, 'stratum') + self.assertEqual(warning.morphology_name, 'foo') + self.assertEqual(warning.stratum_name, 'bar') + self.assertEqual(warning.field, obsolete_field) diff --git a/morphlib/morphologyfactory.py b/morphlib/morphologyfactory.py index 3462dd36..8a0b047a 100644 --- a/morphlib/morphologyfactory.py +++ b/morphlib/morphologyfactory.py @@ -145,6 +145,11 @@ class MorphologyFactory(object): morphology.needs_artifact_metadata_cached = False + morphlib.morphloader.MorphologyLoader._validate_stratum_specs_fields( + morphology, 'strata') + morphlib.morphloader.MorphologyLoader._set_stratum_specs_defaults( + morphology, 'strata') + def _check_and_tweak_stratum(self, morphology, reponame, sha1, filename): '''Check and tweak a stratum morphology.''' @@ -164,6 +169,11 @@ class MorphologyFactory(object): morphology.builds_artifacts = [morphology['name']] morphology.needs_artifact_metadata_cached = True + morphlib.morphloader.MorphologyLoader._validate_stratum_specs_fields( + morphology, 'build-depends') + morphlib.morphloader.MorphologyLoader._set_stratum_specs_defaults( + morphology, 'build-depends') + def _check_and_tweak_chunk(self, morphology, reponame, sha1, filename): '''Check and tweak a chunk morphology.''' diff --git a/scripts/test-morph b/scripts/test-morph index 46d87d9f..d8480d92 100755 --- a/scripts/test-morph +++ b/scripts/test-morph @@ -1,5 +1,5 @@ #!/bin/sh -# Copyright (C) 2012,2013 Codethink Limited +# Copyright (C) 2012,2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -27,10 +27,12 @@ set -eu # distributed builds, which invoke morph as a sub-process. export PATH="$SRCDIR:$PATH" +WARNING_IGNORES='-W ignore:(stratum|system)\s+morphology' if [ "$1" = "--find-system-artifact" ]; then shift - "$SRCDIR/morph" --no-default-config \ + python $WARNING_IGNORES \ + "$SRCDIR/morph" --no-default-config \ --tarball-server= --cache-server= \ --cachedir-min-space=0 --tempdir-min-space=0 \ --config="$DATADIR/morph.conf" --verbose "$@" > $DATADIR/stdout @@ -46,7 +48,9 @@ if [ "$1" = "--find-system-artifact" ]; then echo $ARTIFACT else - "$SRCDIR/scripts/cmd-filter" "$SRCDIR/morph" --no-default-config \ + "$SRCDIR/scripts/cmd-filter" \ + python $WARNING_IGNORES \ + "$SRCDIR/morph" --no-default-config \ --cachedir-min-space=0 --tempdir-min-space=0 \ --tarball-server= --cache-server= \ --config="$DATADIR/morph.conf" "$@" diff --git a/tests.branching/edit-updates-stratum.stdout b/tests.branching/edit-updates-stratum.stdout index 7120ef50..ae1af132 100644 --- a/tests.branching/edit-updates-stratum.stdout +++ b/tests.branching/edit-updates-stratum.stdout @@ -12,15 +12,3 @@ index 73ed482..475fe0f 100644 + unpetrify-ref: master kind: stratum name: hello-stratum -diff --git a/hello-system.morph b/hello-system.morph -index 3f7b4d3..199c924 100644 ---- a/hello-system.morph -+++ b/hello-system.morph -@@ -3,5 +3,6 @@ kind: system - name: hello-system - strata: - - morph: hello-stratum -- ref: master -+ ref: newbranch - repo: test:morphs -+ unpetrify-ref: master diff --git a/tests.branching/tag-creates-commit-and-tag.stdout b/tests.branching/tag-creates-commit-and-tag.stdout index b6098eb5..e1e2126a 100644 --- a/tests.branching/tag-creates-commit-and-tag.stdout +++ b/tests.branching/tag-creates-commit-and-tag.stdout @@ -5,7 +5,7 @@ Date: Tue Jul 31 16:51:54 2012 +0000 Message -commit 6895ed63425bedb3dccaea3f258c705b1600f6be +commit 53a2d5f00aead3f01c001da4b2b5677e25970b06 Author: developer Date: Tue Jul 31 16:51:54 2012 +0000 @@ -25,21 +25,9 @@ index 73ed482..2218f63 100644 + unpetrify-ref: master kind: stratum name: hello-stratum -diff --git a/hello-system.morph b/hello-system.morph -index 3f7b4d3..d909347 100644 ---- a/hello-system.morph -+++ b/hello-system.morph -@@ -3,5 +3,6 @@ kind: system - name: hello-system - strata: - - morph: hello-stratum -- ref: master -+ ref: example-tag - repo: test:morphs -+ unpetrify-ref: master test:morphs -commit 6895ed63425bedb3dccaea3f258c705b1600f6be +commit 53a2d5f00aead3f01c001da4b2b5677e25970b06 Author: developer AuthorDate: Tue Jul 31 16:51:54 2012 +0000 Commit: developer @@ -47,7 +35,7 @@ CommitDate: Tue Jul 31 16:51:54 2012 +0000 Message -commit e11a36aa9e4c998c41a3ec3209324b9318e484ae +commit acb64a107d0ebdbbf0b6850b8272301a66c0a4b7 Author: developer AuthorDate: Tue Jul 31 16:51:54 2012 +0000 Commit: developer diff --git a/tests.branching/tag-tag-works-as-expected.stdout b/tests.branching/tag-tag-works-as-expected.stdout index 98a3be81..9525db0b 100644 --- a/tests.branching/tag-tag-works-as-expected.stdout +++ b/tests.branching/tag-tag-works-as-expected.stdout @@ -9,7 +9,7 @@ Date: Tue Jul 31 16:51:54 2012 +0000 Second -commit 476e4ff4b19c38eb64ad3a151b7c58a7ab95c9ee +commit 332fc39a03b63a9586950e0826374dc6fa4ceaf8 Author: developer Date: Tue Jul 31 16:51:54 2012 +0000 @@ -29,21 +29,9 @@ index 73ed482..2218f63 100644 + unpetrify-ref: master kind: stratum name: hello-stratum -diff --git a/hello-system.morph b/hello-system.morph -index 3f7b4d3..431e15d 100644 ---- a/hello-system.morph -+++ b/hello-system.morph -@@ -3,5 +3,6 @@ kind: system - name: hello-system - strata: - - morph: hello-stratum -- ref: master -+ ref: tagged-tag - repo: test:morphs -+ unpetrify-ref: master test:morphs -commit 476e4ff4b19c38eb64ad3a151b7c58a7ab95c9ee +commit 332fc39a03b63a9586950e0826374dc6fa4ceaf8 Author: developer AuthorDate: Tue Jul 31 16:51:54 2012 +0000 Commit: developer @@ -51,7 +39,7 @@ CommitDate: Tue Jul 31 16:51:54 2012 +0000 Second -commit e11a36aa9e4c998c41a3ec3209324b9318e484ae +commit acb64a107d0ebdbbf0b6850b8272301a66c0a4b7 Author: developer AuthorDate: Tue Jul 31 16:51:54 2012 +0000 Commit: developer diff --git a/tests.branching/workflow.stdout b/tests.branching/workflow.stdout index 65985486..e69de29b 100644 --- a/tests.branching/workflow.stdout +++ b/tests.branching/workflow.stdout @@ -1 +0,0 @@ -WARNING: chunk "hello-system.hello-stratum.hello" is now petrified diff --git a/yarns/branches-workspaces.yarn b/yarns/branches-workspaces.yarn index 08627fe9..15d31cb1 100644 --- a/yarns/branches-workspaces.yarn +++ b/yarns/branches-workspaces.yarn @@ -187,21 +187,14 @@ all the refs are unchanged. GIVEN a workspace AND a git server WHEN the user creates a system branch called foo - THEN in branch foo, system test-system refs test-stratum in master - AND in branch foo, stratum test-stratum refs test-chunk in master - -Then edit the stratum. - - WHEN the user edits the stratum test-stratum in the system test-system in branch foo - THEN in branch foo, system test-system refs test-stratum in foo + THEN in branch foo, stratum test-stratum refs test-chunk in master Edit the chunk. We make use of special knowledge here: `test:test-chunk` is a chunk repository created in the mocked git server, for testing purposes. WHEN the user edits the chunk test-chunk in the stratum test-stratum in the system test-system in branch foo - THEN in branch foo, system test-system refs test-stratum in foo - AND in branch foo, stratum test-stratum refs test-chunk in foo + THEN in branch foo, stratum test-stratum refs test-chunk in foo AND the edited chunk test:test-chunk has git branch foo Morph edit should only work with a system argument. @@ -228,9 +221,7 @@ repositories referenced in the system branch. THEN morph reports no outstanding changes in foo WHEN the user edits the stratum test-stratum in the system test-system in branch foo - THEN morph reports changes in foo in test:morphs only - - WHEN the user edits the chunk test-chunk in the stratum test-stratum in the system test-system in branch foo + AND the user edits the chunk test-chunk in the stratum test-stratum in the system test-system in branch foo THEN morph reports changes in foo in test:morphs only WHEN creating file foo in test:test-chunk in branch foo -- cgit v1.2.1