← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~racb/maas/systemtesting into lp:maas

 

Robie Basak has proposed merging lp:~racb/maas/systemtesting into lp:maas.

Requested reviews:
  MAAS Maintainers (maas-maintainers)

For more details, see:
https://code.launchpad.net/~racb/maas/systemtesting/+merge/123321

This does an end to end test of MAAS and system management on an ARM server. It has hardcoded pieces right now and isn't ready to land. I'd like to see this kind of test land in CI, though it needs more work first.
-- 
https://code.launchpad.net/~racb/maas/systemtesting/+merge/123321
Your team MAAS Maintainers is requested to review the proposed merge of lp:~racb/maas/systemtesting into lp:maas.
=== added directory 'contrib/systemtesting'
=== added file 'contrib/systemtesting/arm-test.py'
--- contrib/systemtesting/arm-test.py	1970-01-01 00:00:00 +0000
+++ contrib/systemtesting/arm-test.py	2012-09-07 16:45:27 +0000
@@ -0,0 +1,116 @@
+import os
+import subprocess
+
+import pexpect
+
+from maasserver.enum import NODE_STATUS
+from maasserver.models.node import Node
+from maasserver.models.sshkey import SSHKey
+from maasserver.models.userprofile import UserProfileManager
+from maasserver.testing import reload_object
+from provisioningserver.enum import POWER_TYPE
+
+
+def assert_one_node():
+    assert(len(Node.objects.all()) == 1)
+
+
+def assert_node_ready(node):
+    assert(node.status == NODE_STATUS.READY)
+
+
+def get_node():
+    return Node.objects.all()[0]
+
+
+def set_ipmi(node, ip_address, username, password):
+    node.power_type = POWER_TYPE.IPMI
+    node.power_parameters = { 'power_address': ip_address, 'power_user': username, 'power_pass': password }
+
+
+def get_user():
+    return UserProfileManager().all_users()[0]
+
+
+def add_ssh_key(user):
+    with open(os.path.join(os.getenv('HOME'), '.ssh/id_rsa.pub'), 'rb') as f:
+        key = f.read()
+    SSHKey(user=user, key=key).save()
+
+
+def expect_boot(child):
+    [child.expect(s) for s in [
+        'TFTP from server',
+        'Bytes transferred',
+        'Starting kernel',
+        'Booting Linux' ]]
+
+
+def expect_enlist(child):
+    expect_boot(child)
+    child.expect('IP-Config: Complete')
+    child.expect('successfully enlisted', timeout=180)
+    child.expect('Power down')
+
+
+def expect_commission(child):
+    expect_boot(child)
+    child.expect('IP-Config: Complete')
+    child.expect('Finished, powering off.', timeout=180)
+    child.expect('Power down')
+
+
+def expect_install(child):
+    expect_boot(child)
+    child.expect('cloud-init boot finished', timeout=20*60)
+
+
+def main(host_ip='10.193.36.17', bmc_ip='10.193.36.18',
+         console_command='ssh -T u@10.193.37.19'):
+
+    def ipmi(cmd):
+        subprocess.check_call('ipmitool -H %s -U admin -P admin %s' % (
+                (bmc_ip, cmd)), shell=True)
+
+    # Create ubuntu/ubuntu superuser
+    subprocess.check_call('PATH=$PATH:$PWD/bin:$PWD/scripts maas createadmin --username=ubuntu --password=ubuntu --email=ubuntu@xxxxxxxxxxx', shell=True)
+    user = get_user()
+    add_ssh_key(user) # add ~/.ssh/id_rsa.pub to MAAS' ubuntu user
+
+    # PXE boot the machine and it should enlist itself
+    ipmi('chassis bootdev pxe options=persistent')
+    ipmi('chassis power off')
+    ipmi('chassis power on')
+    expect_enlist(pexpect.spawn(console_command))
+
+    # Check MAAS has enlisted the node
+    assert_one_node()
+    node = get_node()
+
+    # Set IPMI parameters for the node in MAAS and it should commission it
+    set_ipmi(node, bmc_ip, 'admin', 'admin')
+    node.accept_enlistment(user)
+    expect_commission(pexpect.spawn(console_command))
+
+    node = reload_object(node) # state changes outside this scope so reload
+
+    # Check MAAS has commissioned the node
+    assert_node_ready(node)
+
+    # Acquire the node and MAAS should install it
+    node.acquire(user, token=None)
+    Node.objects.start_nodes([node.system_id], user)
+    expect_install(pexpect.spawn(console_command))
+    
+    # Reset ssh known_hosts and check that we can ssh and run true
+    subprocess.check_call('ssh-keygen -f %s -R %s' % (
+            os.path.join(os.getenv('HOME'), '.ssh/known_hosts'),
+            host_ip), shell=True)
+    subprocess.check_call('ssh-keyscan %s >> %s' % (
+            host_ip,
+            os.path.join(os.getenv('HOME'), '.ssh/known_hosts')),
+            shell=True)
+    subprocess.check_call('ssh ubuntu@%s true' % host_ip, shell=True)
+
+
+main()

=== added file 'contrib/systemtesting/arm-test.sh'
--- contrib/systemtesting/arm-test.sh	1970-01-01 00:00:00 +0000
+++ contrib/systemtesting/arm-test.sh	2012-09-07 16:45:27 +0000
@@ -0,0 +1,27 @@
+#!/bin/sh
+set -x
+
+console_host=10.193.37.19
+
+if [ ! -d src ]; then
+	echo "$0: run this from the top of the MAAS source tree" >&2
+	exit 2
+fi
+
+if [ ! -r ../arm-test.py ]; then
+	echo "$0: needs ../arm-test.py present" >&2
+	exit 2
+fi
+
+if ! dpkg-query -W python-pexpect >/dev/null; then
+	echo "$0: needs python-pexpect" >&2
+	sudo apt-get update
+	sudo apt-get install -y --no-install-recommends python-pexpect
+fi
+
+if [ ! -f ~/.ssh/known_hosts ] || [ "$(ssh-keygen -F $console_host)" = "" ]; then
+	mkdir -pm700 ~/.ssh
+	ssh-keyscan $console_host 2>/dev/null >> ~/.ssh/known_hosts
+fi
+
+echo 'execfile("../arm-test.py")' | bin/maas shell


Follow ups