summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/selftest
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2015-07-27 14:04:02 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-07-27 23:29:14 +0100
commit76d8c4e97c9dbf9e50d8e73805f77b8404a53caf (patch)
treee6eda6a3d87c413b8ce41cfe49ec39a39e58113a /meta/lib/oeqa/selftest
parent01ccad15dab5743ab1cb0f566e48167672389fdd (diff)
downloadpoky-76d8c4e97c9dbf9e50d8e73805f77b8404a53caf.tar.gz
oeqa/selftest/imagefeatures: Use QemuTarget code
Create a runqemu function which uses the QemuTarget() code from oeqa.targetcontrol to setup the QEMU instance, with all of the added robustness that that gives us. To do this, a datastore is needed for the recipe in question (core-image-minimal) so we do the work needed to set this up. We then use this runqemu function within the imagefeatures tests instead of a hand-rolled implementation. We can then use SSHControl to run the SSH tests rather than rolling our own code to do that as an added bonus. Fixed and extended by Paul Eggleton <paul.eggleton@linux.intel.com>. Part of the fix for [YOCTO #7994]. (From OE-Core rev: 7d18d1169204ee80f1c00b35998f10fffaefa107) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/selftest')
-rw-r--r--meta/lib/oeqa/selftest/imagefeatures.py96
1 files changed, 18 insertions, 78 deletions
diff --git a/meta/lib/oeqa/selftest/imagefeatures.py b/meta/lib/oeqa/selftest/imagefeatures.py
index 1795b7bcf3..d48435fedf 100644
--- a/meta/lib/oeqa/selftest/imagefeatures.py
+++ b/meta/lib/oeqa/selftest/imagefeatures.py
@@ -1,20 +1,18 @@
1from oeqa.selftest.base import oeSelfTest 1from oeqa.selftest.base import oeSelfTest
2from oeqa.utils.commands import runCmd, bitbake, get_bb_var 2from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu
3from oeqa.utils.decorators import testcase 3from oeqa.utils.decorators import testcase
4import pexpect 4from oeqa.utils.sshcontrol import SSHControl
5from os.path import isfile 5from os.path import isfile
6from os import system, killpg 6from os import system
7import glob 7import glob
8import signal 8import os
9 9import sys
10import logging
10 11
11class ImageFeatures(oeSelfTest): 12class ImageFeatures(oeSelfTest):
12 13
13 test_user = 'tester' 14 test_user = 'tester'
14 root_user = 'root' 15 root_user = 'root'
15 prompt = r'qemux86:\S+[$#]\s+'
16 ssh_cmd = "ssh {} -l {} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
17 get_ip_patt = r'\s+ip=(?P<qemu_ip>(\d+.){3}\d+)::'
18 16
19 @testcase(1107) 17 @testcase(1107)
20 def test_non_root_user_can_connect_via_ssh_without_password(self): 18 def test_non_root_user_can_connect_via_ssh_without_password(self):
@@ -37,41 +35,12 @@ class ImageFeatures(oeSelfTest):
37 # Build a core-image-minimal 35 # Build a core-image-minimal
38 bitbake('core-image-minimal') 36 bitbake('core-image-minimal')
39 37
40 # Boot qemu image 38 with runqemu("core-image-minimal", self) as qemu:
41 proc_qemu = pexpect.spawn('runqemu qemux86 nographic') 39 # Attempt to ssh with each user into qemu with empty password
42 try: 40 for user in [self.root_user, self.test_user]:
43 proc_qemu.expect(self.get_ip_patt, timeout=100) 41 ssh = SSHControl(ip=qemu.ip, logfile=qemu.sshlog, user=user)
44 qemu_ip = proc_qemu.match.group('qemu_ip') 42 status, output = ssh.run("true")
45 proc_qemu.expect('qemux86 login:', timeout=100) 43 self.assertEqual(status, 0, 'ssh to user %s failed with %s' % (user, output))
46 except Exception as e:
47 try:
48 killpg(proc_qemu.pid, signal.SIGTERM)
49 except:
50 pass
51 self.fail('Failed to start qemu: %s' % e)
52
53 # Attempt to ssh with each user into qemu with empty password
54 for user in [self.root_user, self.test_user]:
55 proc_ssh = pexpect.spawn(self.ssh_cmd.format(qemu_ip, user))
56 index = proc_ssh.expect([self.prompt, pexpect.TIMEOUT, pexpect.EOF])
57 if index == 0:
58 # user successfully logged in with empty password
59 pass
60 elif index == 1:
61 killpg(proc_qemu.pid, signal.SIGTERM)
62 proc_ssh.terminate()
63 self.fail('Failed to ssh with {} user into qemu (timeout).'.format(user))
64 else:
65 killpg(proc_qemu.pid, signal.SIGTERM)
66 proc_ssh.terminate()
67 self.fail('Failed to ssh with {} user into qemu (eof).'.format(user))
68 proc_ssh.terminate()
69
70 # Cleanup
71 try:
72 killpg(proc_qemu.pid, signal.SIGTERM)
73 except:
74 pass
75 44
76 @testcase(1115) 45 @testcase(1115)
77 def test_all_users_can_connect_via_ssh_without_password(self): 46 def test_all_users_can_connect_via_ssh_without_password(self):
@@ -82,7 +51,6 @@ class ImageFeatures(oeSelfTest):
82 Author: Ionut Chisanovici <ionutx.chisanovici@intel.com> 51 Author: Ionut Chisanovici <ionutx.chisanovici@intel.com>
83 AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com> 52 AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
84 """ 53 """
85
86 features = 'EXTRA_IMAGE_FEATURES += "ssh-server-openssh allow-empty-password"\n' 54 features = 'EXTRA_IMAGE_FEATURES += "ssh-server-openssh allow-empty-password"\n'
87 features += 'INHERIT += "extrausers"\n' 55 features += 'INHERIT += "extrausers"\n'
88 features += 'EXTRA_USERS_PARAMS = "useradd -p \'\' {}; usermod -s /bin/sh {};"'.format(self.test_user, self.test_user) 56 features += 'EXTRA_USERS_PARAMS = "useradd -p \'\' {}; usermod -s /bin/sh {};"'.format(self.test_user, self.test_user)
@@ -93,41 +61,13 @@ class ImageFeatures(oeSelfTest):
93 # Build a core-image-minimal 61 # Build a core-image-minimal
94 bitbake('core-image-minimal') 62 bitbake('core-image-minimal')
95 63
96 # Boot qemu image 64 with runqemu("core-image-minimal", self) as qemu:
97 proc_qemu = pexpect.spawn('runqemu qemux86 nographic') 65 # Attempt to ssh with each user into qemu with empty password
98 try: 66 for user in [self.root_user, self.test_user]:
99 proc_qemu.expect(self.get_ip_patt, timeout=100) 67 ssh = SSHControl(ip=qemu.ip, logfile=qemu.sshlog, user=user)
100 qemu_ip = proc_qemu.match.group('qemu_ip') 68 status, output = ssh.run("true")
101 proc_qemu.expect('qemux86 login:', timeout=100) 69 self.assertEqual(status, 0, 'ssh to user tester failed with %s' % output)
102 except Exception as e:
103 try:
104 killpg(proc_qemu.pid, signal.SIGTERM)
105 except:
106 pass
107 self.fail('Failed to start qemu: %s' % e)
108
109 # Attempt to ssh with each user into qemu with empty password
110 for user in [self.root_user, self.test_user]:
111 proc_ssh = pexpect.spawn(self.ssh_cmd.format(qemu_ip, user))
112 index = proc_ssh.expect([self.prompt, pexpect.TIMEOUT, pexpect.EOF])
113 if index == 0:
114 # user successfully logged in with empty password
115 pass
116 elif index == 1:
117 killpg(proc_qemu.pid, signal.SIGTERM)
118 proc_ssh.terminate()
119 self.fail('Failed to ssh with {} user into qemu (timeout).'.format(user))
120 else:
121 killpg(proc_qemu.pid, signal.SIGTERM)
122 proc_ssh.terminate()
123 self.fail('Failed to ssh with {} user into qemu (eof).'.format(user))
124 proc_ssh.terminate()
125 70
126 # Cleanup
127 try:
128 killpg(proc_qemu.pid, signal.SIGTERM)
129 except:
130 pass
131 71
132 @testcase(1114) 72 @testcase(1114)
133 def test_rpm_version_4_support_on_image(self): 73 def test_rpm_version_4_support_on_image(self):