summaryrefslogtreecommitdiff
path: root/morphlib/exts/nfsboot.check
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2014-03-18 17:32:59 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2014-03-18 18:13:14 +0000
commit4581d2ed753dc6e7e63cdefd5fcc68b7a4c4e3c9 (patch)
tree750f04d1883ddc293e0982e8521087b1384923f4 /morphlib/exts/nfsboot.check
parent5227b7c6c99a5a1ed7d10fe4f3737594ca2557a5 (diff)
downloadmorph-4581d2ed753dc6e7e63cdefd5fcc68b7a4c4e3c9.tar.gz
Make sanity checks for nfsboot deployments run earlier
Move some code to the '.check' extension to verify that the deployment can happen *before* spending 5 minutes unpacking and configuring the rootfs. This is not a perfect solution yet because when multiple systems are being deployed in a cluster, we do not check all systems and then deploy them all. Instead, we check one, then deploy it, then check the second, etc.
Diffstat (limited to 'morphlib/exts/nfsboot.check')
-rwxr-xr-xmorphlib/exts/nfsboot.check66
1 files changed, 66 insertions, 0 deletions
diff --git a/morphlib/exts/nfsboot.check b/morphlib/exts/nfsboot.check
index 092a1df7..e240dd72 100755
--- a/morphlib/exts/nfsboot.check
+++ b/morphlib/exts/nfsboot.check
@@ -17,18 +17,84 @@
'''Preparatory checks for Morph 'nfsboot' write extension'''
import cliapp
+import os
import morphlib.writeexts
class NFSBootCheckExtension(morphlib.writeexts.WriteExtension):
+
+ _nfsboot_root = '/srv/nfsboot'
+
def process_args(self, args):
if len(args) != 1:
raise cliapp.AppException('Wrong number of command line args')
+ location = args[0]
+
upgrade = self.get_environment_boolean('UPGRADE')
if upgrade:
raise cliapp.AppException(
'Upgrading is not currently supported for NFS deployments.')
+ hostname = os.environ.get('HOSTNAME', None)
+ if hostname is None:
+ raise cliapp.AppException('You must specify a HOSTNAME.')
+ if hostname == 'baserock':
+ raise cliapp.AppException('It is forbidden to nfsboot a system '
+ 'with hostname "%s"' % hostname)
+
+ self.test_good_server(location)
+
+ version_label = os.getenv('VERSION_LABEL', 'factory')
+ versioned_root = os.path.join(self._nfsboot_root, hostname, 'systems',
+ version_label)
+ if self.version_exists(versioned_root, location):
+ raise cliapp.AppException(
+ 'Root file system for host %s (version %s) already exists on '
+ 'the NFS server %s. Deployment aborted.' % (hostname,
+ version_label, location))
+
+ def test_good_server(self, server):
+ # Can be ssh'ed into
+ try:
+ cliapp.ssh_runcmd('root@%s' % server, ['true'])
+ except cliapp.AppException:
+ raise cliapp.AppException('You are unable to ssh into server %s'
+ % server)
+
+ # Is an NFS server
+ try:
+ cliapp.ssh_runcmd(
+ 'root@%s' % server, ['test', '-e', '/etc/exports'])
+ except cliapp.AppException:
+ raise cliapp.AppException('server %s is not an nfs server'
+ % server)
+ try:
+ cliapp.ssh_runcmd(
+ 'root@%s' % server, ['systemctl', 'is-enabled',
+ 'nfs-server.service'])
+
+ except cliapp.AppException:
+ raise cliapp.AppException('server %s does not control its '
+ 'nfs server by systemd' % server)
+
+ # TFTP server exports /srv/nfsboot/tftp
+ try:
+ cliapp.ssh_runcmd(
+ 'root@%s' % server, ['test' , '-d', '/srv/nfsboot/tftp'])
+ except cliapp.AppException:
+ raise cliapp.AppException('server %s does not export '
+ '/srv/nfsboot/tftp' % server)
+
+ def version_exists(self, versioned_root, location):
+ try:
+ cliapp.ssh_runcmd('root@%s' % location,
+ ['test', '-d', versioned_root])
+ except cliapp.AppException:
+ return False
+
+ return True
+
+
NFSBootCheckExtension().run()