From 64c96a31d0d7c59d37703edaa08e85b452eb7f22 Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Fri, 23 May 2014 16:28:21 +0000 Subject: Add yarn tests for new deployment functionality --- scripts/edit-morph | 2 +- yarns/deployment.yarn | 91 ++++++++++++++++++++++++++++++++++++++++++++++ yarns/implementations.yarn | 19 ++++++++++ 3 files changed, 111 insertions(+), 1 deletion(-) diff --git a/scripts/edit-morph b/scripts/edit-morph index 465a3ea3..2b81747c 100755 --- a/scripts/edit-morph +++ b/scripts/edit-morph @@ -209,7 +209,7 @@ class EditMorph(cliapp.Application): d = yaml.load(f) yield d with open(path, 'w') as f: - yaml.dump(d, f) + yaml.dump(d, f, default_flow_style=False) def cmd_set_system_artifact_depends(self, args): '''Change the artifacts used by a System. diff --git a/yarns/deployment.yarn b/yarns/deployment.yarn index 67aecce2..b30aa4cf 100644 --- a/yarns/deployment.yarn +++ b/yarns/deployment.yarn @@ -185,3 +185,94 @@ will mention the initramfs, and the UUID of the disk. AND file mnt/extlinux.conf matches initramfs AND file mnt/extlinux.conf matches root=UUID= FINALLY mnt is unmounted + +Partial deployments +=================== + +Deploy part of a cluster +------------------------ + +Starting from the well-defined position of having a cluster morphology +with only one definition. + + SCENARIO partially deploying a cluster morphology + GIVEN a workspace + AND a git server + WHEN the user checks out the system branch called master + AND the user builds the system test-system in branch master + GIVEN a cluster called test-cluster in system branch master + AND a system in cluster test-cluster in branch master called test-system + AND system test-system in cluster test-cluster in branch master builds test-system + AND system test-system in cluster test-cluster in branch master has deployment type: tar + AND system test-system in cluster test-cluster in branch master has deployment location: test-system.tar + +It is useful to group related deployments together, so we support adding +another deployment to the same cluster morphology. + + GIVEN a system in cluster test-cluster in branch master called second-system + AND system second-system in cluster test-cluster in branch master builds test-system + AND system second-system in cluster test-cluster in branch master has deployment type: tar + AND system second-system in cluster test-cluster in branch master has deployment location: second-system.tar + +When we don't tell `morph deploy` which system we want to deploy, all +of the systems in the cluster are deployed. Here a successful deployment +will have morph exit sucessfully and in the case of tarball deployments, +the tarballs for both the systems will be created. + + WHEN the user attempts to deploy the cluster test-cluster in branch master + THEN morph succeeded + AND file workspace/master/test/morphs/test-system.tar exists + AND file workspace/master/test/morphs/second-system.tar exists + +However, we don't need to deploy every system defined in a cluster at +once. This is useful for cases such as having a cluster morphology for +deploying a whole distbuild network, and re-deploying only nodes that +have failed. + + GIVEN the files workspace/master/test/morphs/test-system.tar and workspace/master/test/morphs/second-system.tar are removed + WHEN the user attempts to deploy test-system from cluster test-cluster in branch master + +A successful deployment will have morph exit successfully, and in the +case of tarball deployments, only the tarball for the system we asked +for will be created. + + THEN morph succeeded + AND file workspace/master/test/morphs/test-system.tar exists + AND file workspace/master/test/morphs/second-system.tar does not exist + +Cluster morphs can contain "nested systems", i.e. systems which have +subsystems to deploy as part of them. + +We need to add a subsystem to the cluster to test this. + + GIVEN a subsystem in cluster test-cluster in branch master called test-system.sysroot + AND subsystem test-system.sysroot in cluster test-cluster in branch master builds test-system + AND subsystem test-system.sysroot in cluster test-cluster in branch master has deployment type: sysroot + +We specify the location as a file path, this is relative to the parent +system's extracted rootfs, before it is configured. + + AND subsystem test-system.sysroot in cluster test-cluster in branch master has deployment location: var/lib/sysroots/test-system + +The system which contains a nested system is deployed the same as +before, we don't need to mention the nested deployment. + + AND the file workspace/master/test/morphs/test-system.tar is removed + WHEN the user attempts to deploy test-system from cluster test-cluster in branch master + THEN morph succeeded + AND file workspace/master/test/morphs/test-system.tar exists + AND tarball workspace/master/test/morphs/test-system.tar contains var/lib/sysroots/test-system/baserock + +Morph will abort deployment if the system to deploy that is specified +on the command line is not defined in the morphology. + + WHEN the user attempts to deploy not-a-system from cluster test-cluster in branch master + THEN morph failed + +It is not valid to deploy a nested system on its own. If it becomes +desirable to deploy a system that is identical to a system that already +exists but is nested in another, it should be redefined as a top-level +deployment. + + WHEN the user attempts to deploy test-system.sysroot from cluster test-cluster in branch master + THEN morph failed diff --git a/yarns/implementations.yarn b/yarns/implementations.yarn index 66d47bfd..b5b6a253 100644 --- a/yarns/implementations.yarn +++ b/yarns/implementations.yarn @@ -657,6 +657,14 @@ them, so they can be added to the end of the implements section. if [ $MATCH_1 == "deploys" ]; then run_morph "$@" else attempt_morph "$@"; fi + IMPLEMENTS WHEN the user (attempts to deploy|deploys) (.*) from cluster (\S+) in branch (\S+) + cd "$DATADIR/workspace/$MATCH_4" + 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 "$@" + 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" set -- deploy --upgrade "$MATCH_3" @@ -694,6 +702,14 @@ The file contents is used as a `printf`(1) format string. IMPLEMENTS GIVEN a file called (\S+) containing "(.*)" printf "$MATCH_2" > "$DATADIR/$MATCH_1" +Remove a file +------------- + + IMPLEMENTS GIVEN the file(s)? (.*) (is|are) removed + cd "$DATADIR" + files=$(echo "$MATCH_2" | sed -e 's/, /\n/g' -e 's/ and /\n/g') + rm $files + Set attributes on a file or directory ------------------------------------- @@ -712,6 +728,9 @@ Check attributes of a file on the filesystem IMPLEMENTS THEN file (\S+) exists test -e "$DATADIR/$MATCH_1" + IMPLEMENTS THEN file (\S+) does not exist + test ! -e "$DATADIR/$MATCH_1" + IMPLEMENTS THEN file (\S+) has permissions (\S+) stat -c %A "$DATADIR/$MATCH_1" | grep -Fx -e "$MATCH_2" -- cgit v1.2.1