From c6606b8b078957dd7d6d5d74b5e83f40561baf39 Mon Sep 17 00:00:00 2001 From: Richard Ipsum Date: Sun, 16 Nov 2014 18:37:01 +0000 Subject: Add relative_to_root_repo to sysbranchdir --- morphlib/sysbranchdir.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/morphlib/sysbranchdir.py b/morphlib/sysbranchdir.py index 4dbc5f6c..8da2a386 100644 --- a/morphlib/sysbranchdir.py +++ b/morphlib/sysbranchdir.py @@ -107,6 +107,11 @@ class SystemBranchDirectory(object): return os.path.join(self.root_directory, relative) + def relative_to_root_repo(self, path): # pragma: no cover + gitdirpath = self.get_git_directory_name(self.root_repository_url) + + return os.path.relpath(os.path.abspath(path), gitdirpath) + def get_git_directory_name(self, repo_url): '''Return directory pathname for a given git repository. @@ -123,6 +128,7 @@ class SystemBranchDirectory(object): ''' found_repo = self._find_git_directory(repo_url) + if not found_repo: return self._fabricate_git_directory_name(repo_url) return found_repo -- cgit v1.2.1 From 09e5755c88305da7ef5fcd163320ddb9be7ca2f0 Mon Sep 17 00:00:00 2001 From: Richard Ipsum Date: Fri, 23 Jan 2015 10:53:10 +0000 Subject: Treat path given to build cmd as relative to cwd Currently the build commands treat the system argument as a path relative to the root repo. This means that regardless of your working directory you must run morph build systems/foo-system.morph This behaviour can be confusing, for example when your working directory is $systembranch/definitions/systems you might expect to be able to run morph build foo-system.morph especially since most shells would tab-complete the filename for you. At the moment running the above command from $systembranch/definitions/systems would result in an error, because morph would look for $systembranch/definitions/foo-system.morph rather than $systembranch/definitions/systems/foo-system.morph This behaviour also means you can't give the morph build commands an absolute path to a system morph. This patch changes the treatment of the system arg so that it is interpreted relative to the current working directory. --- morphlib/plugins/build_plugin.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/morphlib/plugins/build_plugin.py b/morphlib/plugins/build_plugin.py index c5adffb7..e9290b8d 100644 --- a/morphlib/plugins/build_plugin.py +++ b/morphlib/plugins/build_plugin.py @@ -17,6 +17,7 @@ import cliapp import contextlib import uuid +import logging import morphlib @@ -160,11 +161,14 @@ class BuildPlugin(cliapp.Plugin): self.app.settings['cachedir'], self.app.settings['cachedir-min-space']) - system_filename = morphlib.util.sanitise_morphology_path(args[0]) - ws = morphlib.workspace.open('.') sb = morphlib.sysbranchdir.open_from_within('.') + system_filename = morphlib.util.sanitise_morphology_path(args[0]) + system_filename = sb.relative_to_root_repo(system_filename) + + logging.debug('System branch is %s' % sb.root_directory) + if self.use_distbuild: addr = self.app.settings['controller-initiator-address'] port = self.app.settings['controller-initiator-port'] -- cgit v1.2.1 From cbc779d28c8f1978d235fb43ac91bf6f779bb796 Mon Sep 17 00:00:00 2001 From: Richard Ipsum Date: Sun, 16 Nov 2014 18:56:39 +0000 Subject: Update tests to work with modified build commands Existing tests generally request something like morph build systems/foo-system.morph, now that the system arg is treated relative to the working directory we must change into the directory that contains the morphs to run morph build systems/foo-system.morph --- yarns/implementations.yarn | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/yarns/implementations.yarn b/yarns/implementations.yarn index e1ae271f..2c2c6d18 100644 --- a/yarns/implementations.yarn +++ b/yarns/implementations.yarn @@ -703,7 +703,7 @@ Implementation sections for building ==================================== IMPLEMENTS WHEN the user (attempts to )?((dist)?build)s? the system (\S+) in branch (\S+) - cd "$DATADIR/workspace/$MATCH_5" + cd "$DATADIR/workspace/$MATCH_5/test/morphs" set "$MATCH_2" "$MATCH_4" if [ "$MATCH_1" != "attempts to " ]; then run_morph "$@" else attempt_morph "$@"; fi @@ -712,7 +712,7 @@ Implementation sections for cross-bootstraping ============================================== IMPLEMENTS THEN the user cross-bootstraps the system (\S+) in branch (\S+) of repo (\S+) to the arch (\S+) - cd "$DATADIR/workspace/$MATCH_2" + cd "$DATADIR/workspace/$MATCH_2/test/morphs" set -- cross-bootstrap "$MATCH_4" "$MATCH_3" "$MATCH_2" "$MATCH_1" run_morph "$@" @@ -734,7 +734,7 @@ them, so they can be added to the end of the implements section. else attempt_morph "$@"; fi IMPLEMENTS WHEN the user (attempts to deploy|deploys) (.*) from cluster (\S+) in branch (\S+) - cd "$DATADIR/workspace/$MATCH_4" + cd "$DATADIR/workspace/$MATCH_4/test/morphs" set -- deploy "$MATCH_3" systems=$(echo "$MATCH_2" | sed -e 's/, /\n/g' -e 's/ and /\n/g') set -- "$@" $systems @@ -742,7 +742,7 @@ them, so they can be added to the end of the implements section. else attempt_morph "$@"; fi IMPLEMENTS WHEN the user (attempts to upgrade|upgrades) the (system|cluster) (\S+) in branch (\S+)( with options (.*))? - cd "$DATADIR/workspace/$MATCH_4" + cd "$DATADIR/workspace/$MATCH_4/test/morphs" set -- upgrade "$MATCH_3" if [ "$MATCH_5" != '' ]; then # eval used so word splitting in the text is preserved @@ -892,11 +892,11 @@ Implementations for building systems ------------------------------------ IMPLEMENTS THEN morph ((dist)?build) the system (\S+) of the (branch|tag) (\S+) - cd "$DATADIR/workspace/$MATCH_5" + cd "$DATADIR/workspace/$MATCH_5/test/morphs" run_morph "$MATCH_1" "$MATCH_3" IMPLEMENTS WHEN the user builds (\S+) of the (\S+) (branch|tag) - cd "$DATADIR/workspace/$MATCH_2" + cd "$DATADIR/workspace/$MATCH_2/test/morphs" run_morph build "$MATCH_1" Implementations for tarball inspection -- cgit v1.2.1 From f23433b50eca403eb47161fa7ce95085d618c75d Mon Sep 17 00:00:00 2001 From: Richard Ipsum Date: Sun, 16 Nov 2014 19:04:01 +0000 Subject: Add yarns to test building with relative paths --- yarns/building.yarn | 27 +++++++++++++++++++++++++++ yarns/implementations.yarn | 8 ++++++++ 2 files changed, 35 insertions(+) diff --git a/yarns/building.yarn b/yarns/building.yarn index 253b3b3c..7e9406ac 100644 --- a/yarns/building.yarn +++ b/yarns/building.yarn @@ -9,6 +9,33 @@ Morph Building Tests THEN morph build the system systems/base-system.morph of the branch master FINALLY the git server is shut down + SCENARIO build system with relative path + GIVEN a workspace + AND a git server + WHEN the user checks out the system branch called master + AND the user creates an uncommitted system morphology called systems/base-system.morph for our architecture in system branch master + AND from the directory workspace/master/test/morphs/systems the user attempts to morph build the system base-system.morph + THEN morph succeeded + FINALLY the git server is shut down + + SCENARIO build system with relative path (second variant) + GIVEN a workspace + AND a git server + WHEN the user checks out the system branch called master + AND the user creates an uncommitted system morphology called systems/base-system.morph for our architecture in system branch master + AND from the directory workspace/master/test/morphs/systems the user attempts to morph build the system ../systems/base-system.morph + THEN morph succeeded + FINALLY the git server is shut down + + SCENARIO build system with absolute path + GIVEN a workspace + AND a git server + WHEN the user checks out the system branch called master + AND the user creates an uncommitted system morphology called systems/base-system.morph for our architecture in system branch master + AND from the directory workspace/master/test/morphs/systems the user attempts to morph build the system using the absolute path to base-system.morph + THEN morph succeeded + FINALLY the git server is shut down + System integrations ------------------- diff --git a/yarns/implementations.yarn b/yarns/implementations.yarn index 2c2c6d18..f73e3c64 100644 --- a/yarns/implementations.yarn +++ b/yarns/implementations.yarn @@ -899,6 +899,14 @@ Implementations for building systems cd "$DATADIR/workspace/$MATCH_2/test/morphs" run_morph build "$MATCH_1" + IMPLEMENTS WHEN from the directory (\S+) the user attempts to morph build the system (\S+) + cd "$DATADIR/$MATCH_1" + attempt_morph build "$MATCH_2" + + IMPLEMENTS WHEN from the directory (\S+) the user attempts to morph build the system using the absolute path to (\S+) + cd "$DATADIR/$MATCH_1" + attempt_morph build "$(pwd)/$MATCH_2" + Implementations for tarball inspection -------------------------------------- -- cgit v1.2.1 From abdffd583d9696c8740bbcec689aedb77750016b Mon Sep 17 00:00:00 2001 From: Richard Ipsum Date: Sat, 22 Nov 2014 15:03:00 +0000 Subject: Treat path given to deploy cmd as relative to cwd --- morphlib/plugins/deploy_plugin.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/morphlib/plugins/deploy_plugin.py b/morphlib/plugins/deploy_plugin.py index 87fd259f..6d506a21 100644 --- a/morphlib/plugins/deploy_plugin.py +++ b/morphlib/plugins/deploy_plugin.py @@ -335,11 +335,12 @@ class DeployPlugin(cliapp.Plugin): self.app.settings['tempdir-min-space'], '/', 0) - cluster_filename = morphlib.util.sanitise_morphology_path(args[0]) - ws = morphlib.workspace.open('.') sb = morphlib.sysbranchdir.open_from_within('.') + cluster_filename = morphlib.util.sanitise_morphology_path(args[0]) + cluster_filename = sb.relative_to_root_repo(cluster_filename) + build_uuid = uuid.uuid4().hex build_command = morphlib.buildcommand.BuildCommand(self.app) @@ -351,6 +352,7 @@ class DeployPlugin(cliapp.Plugin): build_ref_prefix = self.app.settings['build-ref-prefix'] root_repo_dir = morphlib.gitdir.GitDirectory( sb.get_git_directory_name(sb.root_repository_url)) + cluster_text = root_repo_dir.read_file(cluster_filename) cluster_morphology = loader.load_from_string(cluster_text, filename=cluster_filename) -- cgit v1.2.1 From a44c4b0e3cae671663c4d99b6d89d6a2f12add35 Mon Sep 17 00:00:00 2001 From: Richard Ipsum Date: Sat, 22 Nov 2014 16:14:30 +0000 Subject: Add yarns to test deploying with relative paths --- yarns/deployment.yarn | 27 +++++++++++++++++++++++++++ yarns/implementations.yarn | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/yarns/deployment.yarn b/yarns/deployment.yarn index 0782c7c1..31406cc0 100644 --- a/yarns/deployment.yarn +++ b/yarns/deployment.yarn @@ -24,6 +24,33 @@ Morph Deployment Tests THEN morph succeeded FINALLY the git server is shut down + SCENARIO deploying a cluster using a relative path + GIVEN a workspace + AND a git server + WHEN the user checks out the system branch called master + AND the user builds the system systems/test-system.morph in branch master + AND from directory workspace/master/test/morphs/clusters the user attempts to deploy the cluster test-cluster.morph in branch master + THEN morph succeeded + FINALLY the git server is shut down + + SCENARIO deploying a cluster using a relative path (second variant) + GIVEN a workspace + AND a git server + WHEN the user checks out the system branch called master + AND the user builds the system systems/test-system.morph in branch master + AND from directory workspace/master/test/morphs/clusters the user attempts to deploy the cluster ../clusters/test-cluster.morph in branch master + THEN morph succeeded + FINALLY the git server is shut down + + SCENARIO deploying a cluster using an absolute path + GIVEN a workspace + AND a git server + WHEN the user checks out the system branch called master + AND the user builds the system systems/test-system.morph in branch master + AND from directory workspace/master/test/morphs/clusters the user attempts to deploy the cluster using the absolute path to test-cluster.morph in branch master + THEN morph succeeded + FINALLY the git server is shut down + Some deployment types support upgrades, but some do not and Morph needs to make this clear. diff --git a/yarns/implementations.yarn b/yarns/implementations.yarn index f73e3c64..83ff03c6 100644 --- a/yarns/implementations.yarn +++ b/yarns/implementations.yarn @@ -247,6 +247,19 @@ another to hold a chunk. morph: strata/core.morph EOF + mkdir "$DATADIR/gits/morphs/clusters" + cd "$DATADIR/gits/morphs" + install -m644 -D /dev/stdin << EOF "clusters/test-cluster.morph" + name: test-cluster + kind: cluster + systems: + - morph: systems/test-system.morph + deploy: + test-system: + type: tar + location: test.tar + EOF + install -m644 -D /dev/stdin << EOF "strata/build-essential.morph" name: build-essential kind: stratum @@ -723,14 +736,26 @@ Defaults are set in the cluster morphology, so we can deploy without setting any extra parameters, but we also need to be able to override them, so they can be added to the end of the implements section. - IMPLEMENTS WHEN the user (attempts to deploy|deploys) the (system|cluster) (\S+) in branch (\S+)( with options (.*))? - cd "$DATADIR/workspace/$MATCH_4" - set -- deploy "$MATCH_3" - if [ "$MATCH_5" != '' ]; then + IMPLEMENTS WHEN (from directory (\S+) )?the user (attempts to deploy|deploys) the (system|cluster) (using the absolute path to )?(\S+) in branch (\S+)( with options (.*))? + if [ "$MATCH_1" != "" ] + then + cd "$DATADIR/$MATCH_2" + else + cd "$DATADIR/workspace/$MATCH_7/test/morphs" + fi + + if [ "$MATCH_5" != "" ] + then + set -- deploy "$(pwd)/$MATCH_6" + else + set -- deploy "$MATCH_6" + fi + + if [ "$MATCH_8" != '' ]; then # eval used so word splitting in the text is preserved - eval set -- '"$@"' $MATCH_6 + eval set -- '"$@"' $MATCH_9 fi - if [ $MATCH_1 == "deploys" ]; then run_morph "$@" + if [ $MATCH_3 == "deploys" ]; then run_morph "$@" else attempt_morph "$@"; fi IMPLEMENTS WHEN the user (attempts to deploy|deploys) (.*) from cluster (\S+) in branch (\S+) -- cgit v1.2.1 From bc62b5835f1a18b3a72dfdcb58e37188c72501fb Mon Sep 17 00:00:00 2001 From: Richard Ipsum Date: Sun, 23 Nov 2014 14:38:32 +0000 Subject: Quote variables and use = instead of == --- yarns/implementations.yarn | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarns/implementations.yarn b/yarns/implementations.yarn index 83ff03c6..8b43286f 100644 --- a/yarns/implementations.yarn +++ b/yarns/implementations.yarn @@ -755,7 +755,7 @@ them, so they can be added to the end of the implements section. # eval used so word splitting in the text is preserved eval set -- '"$@"' $MATCH_9 fi - if [ $MATCH_3 == "deploys" ]; then run_morph "$@" + if [ "$MATCH_3" = "deploys" ]; then run_morph "$@" else attempt_morph "$@"; fi IMPLEMENTS WHEN the user (attempts to deploy|deploys) (.*) from cluster (\S+) in branch (\S+) @@ -763,7 +763,7 @@ them, so they can be added to the end of the implements section. set -- deploy "$MATCH_3" systems=$(echo "$MATCH_2" | sed -e 's/, /\n/g' -e 's/ and /\n/g') set -- "$@" $systems - if [ $MATCH_1 == "deploys" ]; then run_morph "$@" + if [ "$MATCH_1" = "deploys" ]; then run_morph "$@" else attempt_morph "$@"; fi IMPLEMENTS WHEN the user (attempts to upgrade|upgrades) the (system|cluster) (\S+) in branch (\S+)( with options (.*))? @@ -773,7 +773,7 @@ them, so they can be added to the end of the implements section. # eval used so word splitting in the text is preserved eval set -- '"$@"' $MATCH_6 fi - if [ $MATCH_1 == "upgrades" ]; then run_morph "$@" + if [ "$MATCH_1" = "upgrades" ]; then run_morph "$@" else attempt_morph "$@"; fi Implementations sections for reading error messages -- cgit v1.2.1 From 6b1c80a8a4e839a644aaaacba109b9cb81b51813 Mon Sep 17 00:00:00 2001 From: Richard Ipsum Date: Sun, 23 Nov 2014 14:41:41 +0000 Subject: Make some existing deployment scenarios simpler Simplify 'deploying a cluster morphology as a tarfile' and 'attempting to upgrade a tarfile deployment' --- yarns/deployment.yarn | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/yarns/deployment.yarn b/yarns/deployment.yarn index 31406cc0..47aeff5d 100644 --- a/yarns/deployment.yarn +++ b/yarns/deployment.yarn @@ -14,13 +14,8 @@ Morph Deployment Tests GIVEN a workspace AND a git server WHEN the user checks out the system branch called master - GIVEN a cluster called test-cluster.morph in system branch master - AND a system in cluster test-cluster.morph in branch master called test-system - AND system test-system in cluster test-cluster.morph in branch master builds systems/test-system.morph - AND system test-system in cluster test-cluster.morph in branch master has deployment type: tar - AND system test-system in cluster test-cluster.morph in branch master has deployment location: test.tar - WHEN the user builds the system systems/test-system.morph in branch master - AND the user attempts to deploy the cluster test-cluster.morph in branch master + AND the user builds the system systems/test-system.morph in branch master + AND the user attempts to deploy the cluster clusters/test-cluster.morph in branch master THEN morph succeeded FINALLY the git server is shut down @@ -58,13 +53,8 @@ this clear. GIVEN a workspace AND a git server WHEN the user checks out the system branch called master - GIVEN a cluster called test-cluster.morph in system branch master - AND a system in cluster test-cluster.morph in branch master called test-system - AND system test-system in cluster test-cluster.morph in branch master builds systems/test-system.morph - AND system test-system in cluster test-cluster.morph in branch master has deployment type: tar - AND system test-system in cluster test-cluster.morph in branch master has deployment location: test.tar - WHEN the user builds the system systems/test-system.morph in branch master - AND the user attempts to upgrade the cluster test-cluster.morph in branch master + AND the user builds the system systems/test-system.morph in branch master + AND the user attempts to upgrade the cluster clusters/test-cluster.morph in branch master THEN morph failed FINALLY the git server is shut down -- cgit v1.2.1 From d5731dcb9c304d1946bec99771d2cedcd8ec864d Mon Sep 17 00:00:00 2001 From: Richard Ipsum Date: Sun, 7 Dec 2014 23:29:59 +0000 Subject: Fix an existing build yarn Fix "attempting to build a system morphology which has never been committed" use WHEN ... THEN morph succeeded The old yarn worked just as well, this change is just for consistency. --- yarns/building.yarn | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/yarns/building.yarn b/yarns/building.yarn index 7e9406ac..52f2b561 100644 --- a/yarns/building.yarn +++ b/yarns/building.yarn @@ -6,7 +6,8 @@ Morph Building Tests AND a git server WHEN the user checks out the system branch called master AND the user creates an uncommitted system morphology called systems/base-system.morph for our architecture in system branch master - THEN morph build the system systems/base-system.morph of the branch master + AND the user attempts to build the system systems/base-system.morph in branch master + THEN morph succeeded FINALLY the git server is shut down SCENARIO build system with relative path -- cgit v1.2.1 From 837a7a34df88ae2e10339e42553010b08d92fc62 Mon Sep 17 00:00:00 2001 From: Richard Ipsum Date: Fri, 23 Jan 2015 10:57:56 +0000 Subject: Fix copyright --- morphlib/sysbranchdir.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/morphlib/sysbranchdir.py b/morphlib/sysbranchdir.py index 8da2a386..80e56b33 100644 --- a/morphlib/sysbranchdir.py +++ b/morphlib/sysbranchdir.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2014 Codethink Limited +# Copyright (C) 2013-2015 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 -- cgit v1.2.1