Deduplicate method _run_ssh_cmd_with_exit_code
This method is implemented in different places more times than it used. Do refactoring to depuplicate it. Change-Id: If81bf233065f8f9ad0ff8b40f6fce7cdf97e56f4 Closes-Bug: #1520518
This commit is contained in:
parent
3e8ba63735
commit
c2cd664731
|
@ -50,15 +50,3 @@ class CloudValidationTest(nmanager.OfficialClientTest):
|
|||
except Exception:
|
||||
LOG.debug(traceback.format_exc())
|
||||
self.fail("%s command failed." % cmd)
|
||||
|
||||
def _run_ssh_cmd_with_exit_code(self, host, cmd):
|
||||
"""Open SSH session with host and execute command.
|
||||
Fail if exit code != 0
|
||||
"""
|
||||
try:
|
||||
sshclient = SSHClient(host, self.usr, self.pwd,
|
||||
key_filename=self.key, timeout=self.timeout)
|
||||
return sshclient.exec_command(cmd)
|
||||
except Exception:
|
||||
LOG.debug(traceback.format_exc())
|
||||
self.fail("%s command failed." % cmd)
|
||||
|
|
|
@ -374,20 +374,6 @@ class TestPacemakerBase(BaseTestCase):
|
|||
LOG.debug(traceback.format_exc())
|
||||
self.fail("%s command failed." % cmd)
|
||||
|
||||
def _run_ssh_cmd_with_exit_code(self, host, cmd):
|
||||
"""Open SSH session with host and execute command.
|
||||
Fail if exit code != 0
|
||||
"""
|
||||
try:
|
||||
sshclient = ssh.Client(host, self.controller_user,
|
||||
self.controllers_pwd,
|
||||
key_filename=self.controller_key,
|
||||
timeout=self.timeout)
|
||||
return sshclient.exec_command(cmd)
|
||||
except Exception:
|
||||
LOG.debug(traceback.format_exc())
|
||||
self.fail("%s command failed." % cmd)
|
||||
|
||||
def _register_resource(self, res, res_name, resources):
|
||||
if res_name not in resources:
|
||||
resources[res_name] = {
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
import logging
|
||||
import traceback
|
||||
|
||||
from fuel_health.common.ssh import Client as SSHClient
|
||||
from fuel_health import exceptions
|
||||
import fuel_health.nmanager
|
||||
import fuel_health.test
|
||||
|
@ -69,19 +68,6 @@ class IronicTest(fuel_health.nmanager.NovaNetworkScenarioTest):
|
|||
n = self.ironic_client.node.get(node.uuid)
|
||||
return n
|
||||
|
||||
def _run_ssh_cmd_with_exit_code(self, host, cmd):
|
||||
"""Open SSH session with host and execute command.
|
||||
|
||||
Fail if exit code != 0
|
||||
"""
|
||||
try:
|
||||
sshclient = SSHClient(host, self.usr, self.pwd,
|
||||
key_filename=self.key, timeout=self.timeout)
|
||||
return sshclient.exec_command(cmd)
|
||||
except Exception:
|
||||
LOG.debug(traceback.format_exc())
|
||||
self.fail("{0} command failed.".format(cmd))
|
||||
|
||||
def check_service_availability(self, nodes, cmd, expected, timeout=30):
|
||||
"""Check running processes on nodes.
|
||||
|
||||
|
@ -90,7 +76,7 @@ class IronicTest(fuel_health.nmanager.NovaNetworkScenarioTest):
|
|||
"""
|
||||
def check_services():
|
||||
for node in nodes:
|
||||
output = self._run_ssh_cmd_with_exit_code(node, cmd)
|
||||
output = self.run_ssh_cmd_with_exit_code(node, cmd)
|
||||
LOG.debug(output)
|
||||
if expected in output:
|
||||
return True
|
||||
|
|
|
@ -17,11 +17,13 @@
|
|||
# under the License.
|
||||
|
||||
import time
|
||||
import traceback
|
||||
|
||||
import testresources
|
||||
import unittest2
|
||||
|
||||
from fuel_health.common import log as logging
|
||||
from fuel_health.common.ssh import Client as SSHClient
|
||||
from fuel_health.common.test_mixins import FuelTestAssertMixin
|
||||
from fuel_health import config
|
||||
|
||||
|
@ -129,3 +131,16 @@ class TestCase(BaseTestCase):
|
|||
conf.compute.build_interval):
|
||||
self.fail("Timed out waiting to become %s"
|
||||
% expected_status)
|
||||
|
||||
def run_ssh_cmd_with_exit_code(self, host, cmd):
|
||||
"""Open SSH session with host and execute command.
|
||||
|
||||
Fail if exit code != 0
|
||||
"""
|
||||
try:
|
||||
sshclient = SSHClient(host, self.usr, self.pwd,
|
||||
key_filename=self.key, timeout=self.timeout)
|
||||
return sshclient.exec_command(cmd)
|
||||
except Exception:
|
||||
LOG.debug(traceback.format_exc())
|
||||
self.fail("{0} command failed.".format(cmd))
|
||||
|
|
|
@ -43,7 +43,7 @@ class LogRotationTest(cloudvalidation.CloudValidationTest):
|
|||
for host in self.controllers + self.computes:
|
||||
try:
|
||||
self.verify(
|
||||
5, self._run_ssh_cmd_with_exit_code,
|
||||
5, self.run_ssh_cmd_with_exit_code,
|
||||
1, fail_msg % host,
|
||||
'checking logrotate', host, cmd)
|
||||
except AssertionError:
|
||||
|
|
Loading…
Reference in New Issue