-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathSystemLogin.py
More file actions
173 lines (147 loc) · 5.27 KB
/
SystemLogin.py
File metadata and controls
173 lines (147 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env python3
# OpenPOWER Automated Test Project
#
# Contributors Listed Below - COPYRIGHT 2017, 2018
# [+] International Business Machines Corp.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing
# permissions and limitations under the License.
#
'''
System Login
------------
Really simple tests to ensure we can simply log into a booted host.
'''
import time
import subprocess
import subprocess
import re
import sys
import os
import unittest
import OpTestConfiguration
from common.OpTestSystem import OpSystemState
from common.Exceptions import CommandFailed
import common.OpTestQemu as OpTestQemu
import common.OpTestMambo as OpTestMambo
import logging
import OpTestLogger
log = OpTestLogger.optest_logger_glob.get_logger(__name__)
class OOBHostLogin(unittest.TestCase):
'''
Log into the host via out of band console and run different commands
'''
def setUp(self):
conf = OpTestConfiguration.conf
self.cv_SYSTEM = conf.system()
def runTest(self):
self.cv_SYSTEM.goto_state(OpSystemState.OS)
l_con = self.cv_SYSTEM.console
r = l_con.run_command("echo 'Hello World'")
self.assertIn("Hello World", r)
try:
r = l_con.run_command("false")
except CommandFailed as r:
self.assertEqual(r.exitcode, 1)
for i in range(2):
l_con.run_command("dmesg|tail", timeout=60)
l_con.run_command("lscpu")
try:
r = l_con.run_command("sleep 2", timeout=10)
except CommandFailed as r:
log.debug(str(r))
l_con.run_command("lscpu")
class BMCLogin(unittest.TestCase):
'''
Log into the BMC via SSH and run different commands
'''
def setUp(self):
conf = OpTestConfiguration.conf
self.cv_SYSTEM = conf.system()
self.cv_BMC = conf.bmc()
def runTest(self):
if (isinstance(self.cv_BMC, OpTestMambo.OpTestMambo)) \
or (isinstance(self.cv_BMC, OpTestQemu.OpTestQemu)):
raise unittest.SkipTest("QEMU/Mambo so skipping BMCLogin test")
filter_list = [
'Out of memory: Kill process',
'Killed process',
]
found_issues = []
r = self.cv_BMC.run_command("echo 'Hello World'")
self.assertIn("Hello World", r)
try:
r = self.cv_BMC.run_command("false")
except CommandFailed as r:
self.assertEqual(r.exitcode, 1)
for i in range(2):
self.cv_BMC.run_command("dmesg")
try:
r = self.cv_BMC.run_command("dmesg")
for f in filter_list:
fre = re.compile(f)
found_issues = [l for l in r if fre.search(l)]
log.debug("BMC found_issues={}".format(found_issues))
msg = '\n'.join(filter(None, found_issues))
if len(found_issues) != 0:
r = self.cv_BMC.run_command("dmesg -c")
log.debug("REPORT_BUG so we cleared dmesg to allow other tests to succeed")
self.assertTrue( len(found_issues) == 0, "REPORT_BUG BMC dmesg, debug log has full details:\n{}".format(msg))
except CommandFailed as r:
log.debug("BMC dmesg grep for issues failed")
class SSHHostLogin(unittest.TestCase):
'''
Log into the host via SSH and run different commands
'''
def setUp(self):
conf = OpTestConfiguration.conf
self.cv_SYSTEM = conf.system()
self.cv_HOST = conf.host()
def runTest(self):
self.cv_SYSTEM.goto_state(OpSystemState.OS)
r = self.cv_HOST.host_run_command("echo 'Hello World'")
self.assertIn("Hello World", r)
try:
r = self.cv_HOST.host_run_command("false")
except CommandFailed as r:
self.assertEqual(r.exitcode, 1)
for i in range(2):
self.cv_HOST.host_run_command("dmesg")
self.cv_HOST.host_run_command("whoami")
self.cv_HOST.host_run_command("sudo -s")
self.cv_HOST.host_run_command("lscpu")
try:
r = self.cv_HOST.host_run_command(
"echo \'hai\';sleep 20", timeout=10)
except CommandFailed as r:
log.debug(str(r))
self.cv_HOST.host_run_command("whoami")
self.cv_HOST.host_run_command("lscpu")
class ExampleRestAPI(unittest.TestCase):
def setUp(self):
conf = OpTestConfiguration.conf
self.cv_SYSTEM = conf.system()
self.bmc_type = conf.args.bmc_type
def runTest(self):
if "OpenBMC" not in self.bmc_type:
self.skipTest("OpenBMC specific Rest API Tests")
self.cv_SYSTEM.sys_inventory()
self.cv_SYSTEM.sys_sensors()
self.cv_SYSTEM.sys_bmc_state()
def system_access_suite():
s = unittest.TestSuite()
s.addTest(OOBHostLogin())
s.addTest(BMCLogin())
s.addTest(SSHHostLogin())
s.addTest(ExampleRestAPI())
return s