Skip to content

Commit cd57891

Browse files
authored
Merge pull request #68 from fortinet-solutions-cse/jenkins
Jenkins
2 parents c646136 + fc1da5c commit cd57891

File tree

2 files changed

+30
-40
lines changed

2 files changed

+30
-40
lines changed

tests/test_fortiosapi_virsh.py

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
###################################################################
4040
from fortiosapi import FortiOSAPI
4141

42-
4342
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
4443
formatter = logging.Formatter(
4544
'%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
@@ -96,26 +95,26 @@ def sendtoconsole(cmds, in_output=" "):
9695

9796
logged = False
9897
while not logged:
99-
r = child.expect(['.* login:', '.* #', '.* $', 'Escape character'])
98+
r = child.expect(['.* login:', '.* # ', '.* $ ', 'Escape character', 'Password:'], timeout=3)
10099
if r == 0:
101-
child.send(conf["sut"]["user"] + "\n")
102-
rr = child.expect(["Password:", '.* #', '.* $'], timeout=10)
100+
child.sendline(conf["sut"]["user"])
101+
rr = child.expect(["Password:", '.* # ', '.* $ '], timeout=3)
103102
if rr == 0:
104-
child.send(conf["sut"]["passwd"] + "\n")
105-
child.expect(['.* #', '.* $'], timeout=9)
103+
child.sendline(conf["sut"]["passwd"])
104+
child.expect(['.* # ', '.* $ '], timeout=2)
106105
logged = True
107-
if rr in (1,2):
106+
if rr in (1, 2):
108107
child.sendline('\n')
109108
logged = True
110109
if rr > 2:
111110
child.sendline('end\n')
112111
child.sendline('exit\n')
113112
logged = False
114-
if r in (1,2):
113+
if r in (1, 2):
115114
child.sendline('\n')
116-
child.expect(['.* #', '.* $'])
115+
child.expect(['.* # ', '.* $ '], timeout=2)
117116
logged = True
118-
if r == 3:
117+
if r > 3:
119118
child.sendline('\n')
120119
logged = False
121120
result = True
@@ -124,13 +123,13 @@ def sendtoconsole(cmds, in_output=" "):
124123

125124
if in_output:
126125
try:
127-
r = child.expect([in_output], timeout=6)
126+
r = child.expect([in_output], timeout=2)
128127
except:
129128
r = 99
130129
result = False
131130
if r != 0:
132131
result = False
133-
return result
132+
return result, child.readline()
134133

135134

136135
def test_00login(self):
@@ -159,7 +158,6 @@ def test_00login(self):
159158
fgt.cert = None
160159
fgt._session.cert = None
161160
# ensure no previous session was left open
162-
self.sendtoconsole("get system status\r")
163161

164162
try:
165163
apikey = conf["sut"]["api-key"]
@@ -171,7 +169,6 @@ def test_00login(self):
171169
except Exception as e:
172170
self.fail("issue in the virsh yaml definition : %s" + str(e))
173171

174-
175172
def test_01logout_login(self):
176173
# This test if we properly regenerate the CSRF from the cookie when not restarting the program
177174
# can include changing login/vdom passwd on the same session
@@ -200,6 +197,8 @@ def test_setaccessperm(self):
200197

201198
# self.assertEqual(fgt.set('system', 'interface', vdom="global", data=data)['http_status'], 200)
202199

200+
def test_check_version(self):
201+
self.assertEqual("v"+conf["sut"]["version"],fgt.get_version())
203202

204203
def test_setfirewalladdress(self):
205204
data = {
@@ -271,11 +270,9 @@ def test_02getsystemglobal(self):
271270

272271
@unittest.skipIf(conf["sut"]["vdom"] != "root",
273272
"not allowed for non admin vdom")
273+
@unittest.skipIf(Version(conf["sut"]["version"]) < Version('6.0'), "not supported before 6.0")
274274
def test_is_license_valid(self):
275-
if Version(fgt.get_version()) > Version('5.6'):
276-
self.assertTrue(fgt.license()['results']['vm']['status'] == "vm_valid" or "vm_eval")
277-
else:
278-
self.assertTrue(True, "not supported before 5.6")
275+
self.assertTrue(fgt.license()['results']['vm']['status'] == "vm_valid" or "vm_eval")
279276

280277
@unittest.skipIf(conf["sut"]["vdom"] != "root",
281278
"not allowed for non admin vdom")
@@ -295,6 +292,7 @@ def test_execute_update(self):
295292
self.assertEqual(fgt.execute('system', 'fortiguard', None, mkey="update", vdom=conf["sut"]["vdom"])['status'],
296293
'success')
297294

295+
@unittest.skipIf(Version(conf["sut"]["version"])< Version('6.0'),"not supported before 6.0")
298296
def test_webfilteripsv_set(self):
299297
# This call does not have mkey
300298
data = {
@@ -303,22 +301,19 @@ def test_webfilteripsv_set(self):
303301
"gateway6": "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
304302
"geo-filter": ""
305303
}
306-
if Version(fgt.get_version()) > Version('6.0'):
307-
# TODO delete the setting from console first
308-
self.assertEqual(
309-
fgt.set('webfilter', 'ips-urlfilter-setting6', vdom=conf["sut"]["vdom"], data=data)['status'],
310-
'success')
311-
# doing a second time to verify set is behaving correctly (imdepotent)
312-
self.assertEqual(
313-
fgt.set('webfilter', 'ips-urlfilter-setting6', vdom=conf["sut"]["vdom"], data=data)['status'],
314-
'success')
315-
else:
316-
self.assertTrue(True, "not supported before 6.0")
304+
self.assertEqual(
305+
fgt.set('webfilter', 'ips-urlfilter-setting6', vdom=conf["sut"]["vdom"], data=data)['status'],
306+
'success')
307+
# doing a second time to verify set is behaving correctly (imdepotent)
308+
self.assertEqual(
309+
fgt.set('webfilter', 'ips-urlfilter-setting6', vdom=conf["sut"]["vdom"], data=data)['status'],
310+
'success')
317311

318312
def test_monitorresources(self):
319313
self.assertEqual(fgt.monitor('system', 'vdom-resource', mkey='select', vdom=conf["sut"]["vdom"])['status'],
320314
'success')
321315

316+
@unittest.skipIf(Version(conf["sut"]["version"])< Version('6.0'),"not supported before 6.0")
322317
def test_downloadconfig(self):
323318
if conf["sut"]["vdom"] == "global":
324319
parameters = {'destination': 'file',
@@ -327,14 +322,9 @@ def test_downloadconfig(self):
327322
parameters = {'destination': 'file',
328323
'scope': 'vdom',
329324
'vdom': conf["sut"]["vdom"]}
330-
331-
if Version(fgt.get_version()) >= Version('6.0'):
332-
self.assertEqual(
333-
fgt.download('system/config', 'backup', vdom=conf["sut"]["vdom"], parameters=parameters).status_code,
334-
200)
335-
else:
336-
self.assertTrue(True, "not supported before 6.0")
337-
325+
self.assertEqual(
326+
fgt.download('system/config', 'backup', vdom=conf["sut"]["vdom"], parameters=parameters).status_code,
327+
200)
338328

339329
def test_setoverlayconfig(self):
340330
yamldata = '''
@@ -417,9 +407,8 @@ def test_movecommand(self):
417407
# tests are run on alphabetic sorting so this must be last call
418408
def test_zzlogout(self):
419409
# close the console session too
420-
self.sendtoconsole("exit\r")
421-
self.sendtoconsole("\r")
422-
child.terminate()
410+
self.sendtoconsole("exit")
411+
child.close()
423412
logpexecpt.close() # avoid py35 warning
424413
self.assertEqual(fgt.logout(), None)
425414

tests/virshGlobal.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sut:
33
# could be qemu+ssh://ip/system
44
ip: 40domain.com
55
vmname: "fostest"
6+
version: "6.0.2"
67
vdom: "root"
78
user: "admin"
89
# Password is mandatory for vish console access

0 commit comments

Comments
 (0)