aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2020-03-26 13:56:17 +0100
committerCédric Ollivier <cedric.ollivier@orange.com>2020-03-27 10:41:08 +0100
commitc4206f485163d0fd75acf98683aea1268aa1205d (patch)
tree5689f9d36d1860b29bfd18f5144f3572f73418b0
parentfa573a5c0aae16aecb4bc521b34b71af4a263a6f (diff)
Check the login prompt in console in SingleVm1
It also checks the second vm2 console log in case of vping_ssh. Change-Id: I13a5edfb3e19449a38d2f0478d549bd8fcc5cfa7 Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
-rw-r--r--functest/core/singlevm.py11
-rw-r--r--functest/opnfv_tests/openstack/vping/vping_ssh.py2
-rw-r--r--functest/tests/unit/openstack/vping/test_vping_ssh.py24
3 files changed, 28 insertions, 9 deletions
diff --git a/functest/core/singlevm.py b/functest/core/singlevm.py
index 5ecd482ac..c307c8a09 100644
--- a/functest/core/singlevm.py
+++ b/functest/core/singlevm.py
@@ -217,7 +217,7 @@ class VmReady1(tenantnetwork.TenantNetwork1):
self.__logger.debug("vm: %s", vm1)
return vm1
- def check_regex_in_console(self, name, regex=' login: ', loop=1):
+ def check_regex_in_console(self, name, regex=' login: ', loop=6):
"""Wait for specific message in console
Returns: True or False on errors
@@ -480,10 +480,11 @@ class SingleVm1(VmReady1):
self.prepare()
self.sshvm = self.boot_vm(
key_name=self.keypair.id, security_groups=[self.sec.id])
- (self.fip, self.ssh) = self.connect(self.sshvm)
- if not self.execute():
- self.result = 100
- status = testcase.TestCase.EX_OK
+ if self.check_regex_in_console(self.sshvm.name):
+ (self.fip, self.ssh) = self.connect(self.sshvm)
+ if not self.execute():
+ self.result = 100
+ status = testcase.TestCase.EX_OK
except Exception: # pylint: disable=broad-except
self.__logger.exception('Cannot run %s', self.case_name)
finally:
diff --git a/functest/opnfv_tests/openstack/vping/vping_ssh.py b/functest/opnfv_tests/openstack/vping/vping_ssh.py
index 6420013a0..e6c07ee91 100644
--- a/functest/opnfv_tests/openstack/vping/vping_ssh.py
+++ b/functest/opnfv_tests/openstack/vping/vping_ssh.py
@@ -44,6 +44,8 @@ class VPingSSH(singlevm.SingleVm2):
Returns: ping exit codes
"""
assert self.ssh
+ if not self.check_regex_in_console(self.vm2.name):
+ return 1
(_, stdout, stderr) = self.ssh.exec_command(
'ping -c 1 {}'.format(
self.vm2.private_v4 or self.vm2.addresses[
diff --git a/functest/tests/unit/openstack/vping/test_vping_ssh.py b/functest/tests/unit/openstack/vping/test_vping_ssh.py
index 05482ed6b..bc1148da4 100644
--- a/functest/tests/unit/openstack/vping/test_vping_ssh.py
+++ b/functest/tests/unit/openstack/vping/test_vping_ssh.py
@@ -61,22 +61,38 @@ class VpingSSHTesting(unittest.TestCase):
'{}-vm2_{}'.format(self.vping.case_name, self.vping.guid),
security_groups=[self.vping.sec.id])
- def test_execute_exc(self):
- self.vping.vm2 = munch.Munch(private_v4='127.0.0.1')
+ @mock.patch('functest.opnfv_tests.openstack.vping.vping_ssh.VPingSSH.'
+ 'check_regex_in_console', return_value=True)
+ def test_execute_exc(self, *args):
+ self.vping.vm2 = munch.Munch(private_v4='127.0.0.1', name='foo')
self.vping.ssh = mock.Mock()
self.vping.ssh.exec_command.side_effect = ssh_exception.SSHException
with self.assertRaises(ssh_exception.SSHException):
self.vping.execute()
self.vping.ssh.exec_command.assert_called_once_with(
'ping -c 1 {}'.format(self.vping.vm2.private_v4))
+ args[0].assert_called_once_with('foo')
+
+ @mock.patch('functest.opnfv_tests.openstack.vping.vping_ssh.VPingSSH.'
+ 'check_regex_in_console', return_value=False)
+ def test_execute_exc2(self, *args):
+ self.vping.vm2 = munch.Munch(private_v4='127.0.0.1', name='foo')
+ self.vping.ssh = mock.Mock()
+ self.vping.execute()
+ self.vping.ssh.exec_command.assert_not_called()
+ args[0].assert_called_once_with('foo')
def _test_execute(self, ret=0):
- self.vping.vm2 = munch.Munch(private_v4='127.0.0.1')
+ self.vping.vm2 = munch.Munch(private_v4='127.0.0.1', name='foo')
self.vping.ssh = mock.Mock()
stdout = mock.Mock()
stdout.channel.recv_exit_status.return_value = ret
self.vping.ssh.exec_command.return_value = (None, stdout, mock.Mock())
- self.assertEqual(self.vping.execute(), ret)
+ with mock.patch(
+ 'functest.opnfv_tests.openstack.vping.vping_ssh.VPingSSH.'
+ 'check_regex_in_console', return_value=True) as mock_check:
+ self.assertEqual(self.vping.execute(), ret)
+ mock_check.assert_called_once_with('foo')
self.vping.ssh.exec_command.assert_called_once_with(
'ping -c 1 {}'.format(self.vping.vm2.private_v4))