From a927ab8a22c5bf9c7365868cccba6737540bc522 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 | 188 +++++++++++++++++++++++++++++++++++++++++++++ yarns/implementations.yarn | 13 ++++ 3 files changed, 202 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..695dcf7e 100644 --- a/yarns/deployment.yarn +++ b/yarns/deployment.yarn @@ -185,3 +185,191 @@ 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 +------------------------ + +We may not always want to deploy every system in a cluster, for example +if we only want to deploy a distbuild controller but we have a cluster +for a full network. + + SCENARIO partially deploying a cluster morphology + GIVEN a workspace + AND a git server + WHEN the user checks out the system branch called 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 + +We now want to add a second system to the cluster, so we can choose +which one to deploy. + + 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 the user builds the system test-system in branch master + AND the user attempts to deploy the following systems from cluster test-cluster in branch master: test-system + THEN morph succeeded + +Morph succeeding alone does not satisfy the requirements of this test. +It may have deployed both systems, or the wrong system, so we need to +make sure only the correct tarball exists. + + THEN file workspace/master/test/morphs/test-system.tar exists + AND file workspace/master/test/morphs/second-system.tar does not exist + +Deploy all of a multi-system cluster +------------------------------------ + +We should also test that not specifying a system deploys both systems. + + SCENARIO deploying a cluster morphology that contains multiple systems + GIVEN a workspace + AND a git server + WHEN the user checks out the system branch called 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 + +We now want to add a second system deployment to the cluster, so we can +check that deployment of clusters with multiple systems actually deploys +multiple systems. + + 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 the user builds the system test-system in branch master + AND the user attempts to deploy the cluster test-cluster in branch master + THEN morph succeeded + +We should also check that both systems were deployed as expected. + + THEN file workspace/master/test/morphs/test-system.tar exists + AND file workspace/master/test/morphs/second-system.tar exists + +Deploy part of a cluster that contains a nested deployment +---------------------------------------------------------- + +Cluster morphs can contain "nested systems", i.e. systems which have +subsystems to deploy as part of them. We should test that partial +deployment works as expected here. + + SCENARIO partially deploying a cluster morphology containing a nested deployment + GIVEN a workspace + AND a git server + WHEN the user checks out the system branch called 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 + +After the usual setup, we also add a subsystem to the cluster. + + 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 + +We now want to add a second system to the cluster, so we can choose +which one to deploy. + + 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 the user builds the system test-system in branch master + AND the user attempts to deploy the following systems from cluster test-cluster in branch master: test-system + THEN morph succeeded + +Morph succeeding alone does not satisfy the requirements of this test. +It may have deployed both systems, or the wrong system, so we need to +make sure only the correct tarball exists. + + THEN file workspace/master/test/morphs/test-system.tar exists + AND file workspace/master/test/morphs/second-system.tar does not exist + +Fail if attempting to deploy a system which does not exist in the cluster +------------------------------------------------------------------------- + +If the user asks to deploy a non-existent deployment, then morph should +fail. We should test that morph fails in this case, rather than treating +the bad name as if it were a deployment option. + + SCENARIO fail to deploy a non-existent system + GIVEN a workspace + AND a git server + WHEN the user checks out the system branch called 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 + +We now want to add a second system to the cluster, so we can choose +which one to deploy. + + 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 the user builds the system test-system in branch master + AND the user attempts to deploy the following systems from cluster test-cluster in branch master: not-a-system + THEN morph failed + +Fail to deploy a subsystem +-------------------------- + +Cluster morphs can contain "nested systems", i.e. systems which have +subsystems to deploy as part of them. We should test that attempting +to deploy a subsystem results in failure. + + SCENARIO fail to deploy a subsystem + GIVEN a workspace + AND a git server + WHEN the user checks out the system branch called 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 + +After the usual setup, we also add a subsystem to the cluster. + + 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 + +We now want to add a second system to the cluster, so we can choose +which one to deploy. + + 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 the user builds the system test-system in branch master + AND the user attempts to deploy the following systems from cluster test-cluster in branch master: test-system.sysroot + THEN morph failed diff --git a/yarns/implementations.yarn b/yarns/implementations.yarn index 66d47bfd..651c0748 100644 --- a/yarns/implementations.yarn +++ b/yarns/implementations.yarn @@ -657,6 +657,16 @@ 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) the following systems from cluster (\S+) in branch (\S+): (.*) + cd "$DATADIR/workspace/$MATCH_3" + set -- deploy "$MATCH_2" + if [ "$MATCH_4" != '' ]; then + # eval used so word splitting in the text is preserved + eval set -- '"$@"' $MATCH_4 + fi + 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" @@ -712,6 +722,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