Clean imports in code

This patch set modifies lines which are importing objects
instead of modules. As per openstack import guide lines, user should
import modules in a file not objects.

http://docs.openstack.org/developer/hacking/#imports

Change-Id: I5b4bdcb674b58ab419d00ca9c6bff105ce19aca8
This commit is contained in:
Cao Xuan Hoang 2016-09-07 13:24:50 +07:00
parent a993603408
commit 8520aeafd9
13 changed files with 85 additions and 84 deletions

View File

@ -17,7 +17,7 @@ import logging
LOG = logging.getLogger(__name__)
from fuel_health.common.ssh import Client as SSHClient
from fuel_health.common import ssh
from fuel_health import nmanager
@ -43,8 +43,8 @@ class CloudValidationTest(nmanager.OfficialClientTest):
def _run_ssh_cmd(self, host, cmd):
"""Open SSH session with host and execute command."""
try:
sshclient = SSHClient(host, self.usr, self.pwd,
key_filename=self.key, timeout=self.timeout)
sshclient = ssh.Client(host, self.usr, self.pwd,
key_filename=self.key, timeout=self.timeout)
return sshclient.exec_longrun_command(cmd)
except Exception:
LOG.exception('Failure on ssh run cmd')

View File

@ -18,7 +18,7 @@ import logging
from fuel_health import nmanager
import fuel_health.test
from fuel_health.common.ssh import Client as SSHClient
from fuel_health.common import ssh
from ironicclient.common import utils
from ironicclient import exc as ironic_exc
@ -83,9 +83,9 @@ class IronicTest(nmanager.SanityChecksTest):
def check_services():
succeed_count = 0
for node in nodes:
remote = SSHClient(node, self.usr, self.pwd,
key_filename=self.key,
timeout=self.timeout)
remote = ssh.Client(node, self.usr, self.pwd,
key_filename=self.key,
timeout=self.timeout)
try:
output = remote.exec_command(cmd)
LOG.debug(output)

View File

@ -71,7 +71,7 @@ import keystoneclient
import novaclient.client
import novaclient.exceptions as nova_exc
from fuel_health.common.ssh import Client as SSHClient
from fuel_health.common import ssh as f_ssh
from fuel_health.common.utils.data_utils import rand_int_id
from fuel_health.common.utils.data_utils import rand_name
from fuel_health import exceptions
@ -614,8 +614,9 @@ class NovaNetworkScenarioTest(OfficialClientTest):
'"online_controllers" parameter is empty.')
try:
sshclient = SSHClient(self.host[0], self.usr, self.pwd,
key_filename=self.key, timeout=self.timeout)
sshclient = f_ssh.Client(self.host[0], self.usr, self.pwd,
key_filename=self.key,
timeout=self.timeout)
return sshclient.exec_longrun_command(cmd)
except Exception:
LOG.exception()
@ -828,10 +829,10 @@ class NovaNetworkScenarioTest(OfficialClientTest):
if self.host:
try:
ssh = SSHClient(self.host[0],
self.usr, self.pwd,
key_filename=self.key,
timeout=timeout)
ssh = f_ssh.Client(self.host[0],
self.usr, self.pwd,
key_filename=self.key,
timeout=timeout)
except Exception:
LOG.exception()
@ -858,10 +859,10 @@ class NovaNetworkScenarioTest(OfficialClientTest):
try:
host = viaHost or self.host[0]
LOG.debug('Get ssh to instance')
ssh = SSHClient(host,
self.usr, self.pwd,
key_filename=self.key,
timeout=timeout)
ssh = f_ssh.Client(host,
self.usr, self.pwd,
key_filename=self.key,
timeout=timeout)
except Exception:
LOG.exception()
@ -888,10 +889,10 @@ class NovaNetworkScenarioTest(OfficialClientTest):
try:
host = viaHost or self.host[0]
LOG.debug('Get ssh to instance')
ssh = SSHClient(host,
self.usr, self.pwd,
key_filename=self.key,
timeout=timeout)
ssh = f_ssh.Client(host,
self.usr, self.pwd,
key_filename=self.key,
timeout=timeout)
LOG.debug('Host is {0}'.format(host))
except Exception:

View File

@ -22,8 +22,8 @@ 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.common import ssh
from fuel_health.common import test_mixins
from fuel_health import config
@ -32,7 +32,7 @@ LOG = logging.getLogger(__name__)
class BaseTestCase(unittest2.TestCase,
testresources.ResourcedTestCase,
FuelTestAssertMixin):
test_mixins.FuelTestAssertMixin):
def __init__(self, *args, **kwargs):
super(BaseTestCase, self).__init__(*args, **kwargs)
@ -137,8 +137,8 @@ class TestCase(BaseTestCase):
Fail if exit code != 0
"""
try:
sshclient = SSHClient(host, self.usr, self.pwd,
key_filename=self.key, timeout=self.timeout)
sshclient = ssh.Client(host, self.usr, self.pwd,
key_filename=self.key, timeout=self.timeout)
return sshclient.exec_command(cmd)
except Exception:
LOG.exception("Failed while opening ssh session with host")

View File

@ -15,10 +15,10 @@
import logging
import paramiko.ssh_exception as exc
from fuel_health.common.ssh import Client as SSHClient
from fuel_health.common import ssh
from fuel_health import exceptions
from fuel_health import nmanager
from keystoneclient.exceptions import Unauthorized
from keystoneclient import exceptions as k_exceptions
from keystoneclient.v2_0 import Client as keystoneclient
LOG = logging.getLogger(__name__)
@ -52,10 +52,10 @@ class SanityConfigurationTest(nmanager.SanityChecksTest):
"""
ip = self.config.nailgun_host
ssh_client = SSHClient(ip,
self.config.master.master_node_ssh_user,
self.config.master.master_node_ssh_password,
timeout=self.config.master.ssh_timeout)
ssh_client = ssh.Client(ip,
self.config.master.master_node_ssh_user,
self.config.master.master_node_ssh_password,
timeout=self.config.master.ssh_timeout)
cmd = "date"
output = []
try:
@ -122,7 +122,7 @@ class SanityConfigurationTest(nmanager.SanityChecksTest):
password=pwd,
auth_url=url)
keystone.authenticate()
except Unauthorized:
except k_exceptions.Unauthorized:
pass
else:
self.fail('Step 1 failed: Default credentials '

View File

@ -14,7 +14,7 @@
import logging
from fuel_health.common.ssh import Client as SSHClient
from fuel_health.common import ssh
from fuel_health import test
@ -71,9 +71,9 @@ class HAProxyCheck(test.BaseTestCase):
"""
LOG.info("Controllers nodes are %s" % self.controllers)
for controller in self.controllers:
remote = SSHClient(controller, self.controller_user,
key_filename=self.controller_key,
timeout=100)
remote = ssh.Client(controller, self.controller_user,
key_filename=self.controller_key,
timeout=100)
ignore_services = []
if 'neutron' not in self.config.network.network_provider:
ignore_services.append('nova-metadata-api')

View File

@ -14,14 +14,14 @@
import logging
from fuel_health.common.ssh import Client as SSHClient
from fuel_health.common import ssh
from fuel_health.common.utils import data_utils
from fuel_health.tests.ha.test_mysql_status import BaseMysqlTest
from fuel_health.tests.ha import test_mysql_status
LOG = logging.getLogger(__name__)
class TestMysqlReplication(BaseMysqlTest):
class TestMysqlReplication(test_mysql_status.BaseMysqlTest):
@classmethod
def setUpClass(cls):
super(TestMysqlReplication, cls).setUpClass()
@ -38,8 +38,8 @@ class TestMysqlReplication(BaseMysqlTest):
if cls.master_ip:
try:
cmd = "mysql -h localhost -e 'DROP DATABASE %s'" % cls.database
SSHClient(cls.master_ip, cls.node_user,
key_filename=cls.node_key).exec_command(cmd)
ssh.Client(cls.master_ip, cls.node_user,
key_filename=cls.node_key).exec_command(cmd)
except Exception:
LOG.exception("Failed to connect to mysql cmd:{0}".format(cmd))
@ -76,7 +76,7 @@ class TestMysqlReplication(BaseMysqlTest):
# check that mysql is running on all hosts
cmd = 'mysql -h localhost -e "" '
for db_node in databases:
ssh_client = SSHClient(
ssh_client = ssh.Client(
db_node, self.node_user,
key_filename=self.node_key, timeout=100)
self.verify(
@ -122,9 +122,9 @@ class TestMysqlReplication(BaseMysqlTest):
# create db, table, insert data on one node
LOG.info('target node ip/hostname: "{0}" '.format(self.master_ip))
master_ssh_client = SSHClient(self.master_ip, self.node_user,
key_filename=self.node_key,
timeout=100)
master_ssh_client = ssh.Client(self.master_ip, self.node_user,
key_filename=self.node_key,
timeout=100)
self.verify(20, master_ssh_client.exec_command, 2,
'Database creation failed', 'create database',
@ -141,9 +141,9 @@ class TestMysqlReplication(BaseMysqlTest):
# Verify that data is replicated on other databases
for db_node in databases:
if db_node != self.master_ip:
client = SSHClient(db_node,
self.node_user,
key_filename=self.node_key)
client = ssh.Client(db_node,
self.node_user,
key_filename=self.node_key)
output = self.verify(
20, client.exec_command, 5,
@ -155,8 +155,8 @@ class TestMysqlReplication(BaseMysqlTest):
failed_step='6')
# Drop created db
ssh_client = SSHClient(self.master_ip, self.node_user,
key_filename=self.node_key)
ssh_client = ssh.Client(self.master_ip, self.node_user,
key_filename=self.node_key)
self.verify(20, ssh_client.exec_command, 7,
'Can not delete created database',
'database deletion', drop_db)

View File

@ -15,13 +15,13 @@
from distutils import version
import logging
from fuel_health.common.ssh import Client as SSHClient
from fuel_health.test import BaseTestCase
from fuel_health.common import ssh
from fuel_health import test
LOG = logging.getLogger(__name__)
class BaseMysqlTest(BaseTestCase):
class BaseMysqlTest(test.BaseTestCase):
"""Base methods for MySQL DB tests
"""
@classmethod
@ -54,10 +54,10 @@ class BaseMysqlTest(BaseTestCase):
< version.StrictVersion('7.0'):
return cls.config.compute.online_controllers
# retrieve data from controller
ssh_client = SSHClient(controller_ip,
username,
key_filename=key,
timeout=100)
ssh_client = ssh.Client(controller_ip,
username,
key_filename=key,
timeout=100)
hiera_cmd = ('ruby -e \'require "hiera"; '
'db_h = Hiera.new().lookup("database_nodes", {}, {}); '
@ -118,7 +118,7 @@ class TestMysqlStatus(BaseMysqlTest):
LOG.info('Current database node is %s' % node)
cmd1 = cmd % {'database': database}
LOG.info('Try to execute command %s' % cmd1)
tables = SSHClient(
tables = ssh.Client(
node, self.node_user,
key_filename=self.node_key,
timeout=self.config.compute.ssh_timeout)
@ -181,9 +181,9 @@ class TestMysqlStatus(BaseMysqlTest):
for db_node in databases:
command = "mysql -h localhost -e \"SHOW STATUS LIKE 'wsrep_%'\""
ssh_client = SSHClient(db_node, self.node_user,
key_filename=self.node_key,
timeout=100)
ssh_client = ssh.Client(db_node, self.node_user,
key_filename=self.node_key,
timeout=100)
output = self.verify(
20, ssh_client.exec_command, 2,
"Verification of galera cluster node status failed",

View File

@ -17,7 +17,7 @@
import logging
import time
from fuel_health.common.ssh import Client as SSHClient
from fuel_health.common import ssh
from fuel_health import nmanager
LOG = logging.getLogger(__name__)
@ -108,11 +108,11 @@ class SanityInfrastructureTest(nmanager.SanityChecksTest):
cmd = "ping -q -c1 -w10 8.8.8.8"
ssh_client = SSHClient(self.computes[0],
self.usr,
self.pwd,
key_filename=self.key,
timeout=self.timeout)
ssh_client = ssh.Client(self.computes[0],
self.usr,
self.pwd,
key_filename=self.key,
timeout=self.timeout)
self.verify(100, self.retry_command, 1,
"'ping' command failed. Looks like there is no "
"Internet connection on the compute node.",
@ -137,11 +137,11 @@ class SanityInfrastructureTest(nmanager.SanityChecksTest):
dns = self.fuel_dns.spit(',') if self.fuel_dns else ['8.8.8.8']
ssh_client = SSHClient(self.computes[0],
self.usr,
self.pwd,
key_filename=self.key,
timeout=self.timeout)
ssh_client = ssh.Client(self.computes[0],
self.usr,
self.pwd,
key_filename=self.key,
timeout=self.timeout)
expected_output = "{0}.in-addr.arpa domain name pointer".format(dns[0])
cmd = "host {0}".format(dns[0])

View File

@ -23,7 +23,7 @@ except ImportError:
from oslo_config import cfg
from fuel_plugin import consts
from fuel_plugin.ostf_adapter.logger import ResultsLogger
from fuel_plugin.ostf_adapter import logger
from fuel_plugin.ostf_adapter.nose_plugin import nose_storage_plugin
from fuel_plugin.ostf_adapter.nose_plugin import nose_test_runner
from fuel_plugin.ostf_adapter.nose_plugin import nose_utils
@ -58,7 +58,7 @@ class NoseDriver(object):
else:
argv_add = [test_set.test_path] + test_set.additional_arguments
results_log = ResultsLogger(test_set.id, test_run.cluster_id)
results_log = logger.ResultsLogger(test_set.id, test_run.cluster_id)
lock_path = cfg.CONF.adapter.lock_dir
test_run.pid = nose_utils.run_proc(self._run_tests,

View File

@ -21,7 +21,7 @@ import re
import traceback
from nose import case
from nose.suite import ContextSuite
from nose import suite
try:
from oslo.serialization import jsonutils
@ -172,7 +172,7 @@ def get_tests_to_update(test):
if isinstance(test, case.Test):
tests.append(test)
elif isinstance(test, ContextSuite):
elif isinstance(test, suite.ContextSuite):
for sub_test in test._tests:
tests.extend(get_tests_to_update(sub_test))

View File

@ -15,7 +15,7 @@
import functools
import unittest
from fuel_plugin.ostf_client.client import TestingAdapterClient
from fuel_plugin.ostf_client import client
class EmptyResponseError(Exception):
@ -66,10 +66,10 @@ class Response(object):
class AdapterClientProxy(object):
def __init__(self, url):
self.client = TestingAdapterClient(url)
self.client = client.TestingAdapterClient(url)
def __getattr__(self, item):
if item in TestingAdapterClient.__dict__:
if item in client.TestingAdapterClient.__dict__:
call = getattr(self.client, item)
return self._decorate_call(call)

View File

@ -16,11 +16,11 @@
import mock
from fuel_plugin.ostf_adapter.logger import ResultsLogger
from fuel_plugin.ostf_adapter import logger
from fuel_plugin.testing.tests import base
@mock.patch.object(ResultsLogger, '_init_file_logger')
@mock.patch.object(logger.ResultsLogger, '_init_file_logger')
class TestResultsLogger(base.BaseUnitTest):
def get_logger(self, **kwargs):
@ -29,7 +29,7 @@ class TestResultsLogger(base.BaseUnitTest):
'cluster_id': 1,
}
options.update(kwargs)
return ResultsLogger(**options)
return logger.ResultsLogger(**options)
def test_filename(self, m_init_logger):
logger = self.get_logger(testset='testset_name',