Details
For a larger unittest I need a method in Python this allows servers / switches / routers to call IP's and respond accordingly to the test.
My thoughts in this regard:
Reading out the IP's from a CSV file
Create a configuration file in which I enter all relevant data.
Setup
import testcore from testcore.control.ssh import SSH import unittest from test import support import logging import os
Test Setup
def setUp(self):
self.s = testcore.control.ssh.SSH(host='172.23.56.xxx',
username='admin', password='admin', type_of_dut='ecos')
logger.info('self.s = testcore.control.ssh.SSH')
self.s.query_interactive=True
if self.s.login():
logger.info('login')
q = self.s.query('account')
logger.info('account')
self.assertIsNotNone(q, 'missing answer')
self.assertEqual('\r\n', q, 'unexpected result')
logger.info('missing answer')
logger.info('unexpected result')
# switch to prompt account
q=self.s.query('enforce-Password-Rules yes')
logger.info('enforce-Password-Rules yes')
q=self.s.query('exit')
logger.info('exit')
def tearDown(self):
self.s.close()
So what I need:
How can I write a method in Python that allows me to run multiple IP's for my test?
Is this worth a configuration script?
In this example, you'll see a test I'm running.
def test_create_ntp_external1(self):
logger_true.info('test_create_ntp_external1')
if self.s.loggedin:
logger.info('self.s.loggedin')
q = self.s.query('time')
logger.info('time')
self.assertIsNotNone(q, 'missing answer')
self.assertEqual('\r\n', q, 'unexpected result')
logger.info('missing answer')
logger.info('unexpected result')
# switch to prompt account
q = self.s.query('ntp 1 2610:20:6F15:15::27')
logger.info('ntp 1 2610:20:6F15:15::27')
print(q)
q = self.s.query('exit')
self.assertIsNotNone(q, 'missing answer')
self.assertEqual('\r\n', q, 'unexpected result')
logger.info('missing answer')
logger.info('unexpected result')
q = self.s.query('logout')
logger.info('logout')
import time
print('Wait')
time.sleep(2)
print('True')
logger_true.info('True')
The individual tests are called via the setup above but just according to one device at a time. So how is it possible to extend this so that I can call various IP's at the same time?