Browse Source

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
tags/10.0.0rc1
Cao Xuan Hoang 2 years ago
parent
commit
8520aeafd9

+ 3
- 3
fuel_health/cloudvalidation.py View File

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

+ 4
- 4
fuel_health/ironicmanager.py View File

@@ -18,7 +18,7 @@ import logging
18 18
 from fuel_health import nmanager
19 19
 import fuel_health.test
20 20
 
21
-from fuel_health.common.ssh import Client as SSHClient
21
+from fuel_health.common import ssh
22 22
 from ironicclient.common import utils
23 23
 from ironicclient import exc as ironic_exc
24 24
 
@@ -83,9 +83,9 @@ class IronicTest(nmanager.SanityChecksTest):
83 83
         def check_services():
84 84
             succeed_count = 0
85 85
             for node in nodes:
86
-                remote = SSHClient(node, self.usr, self.pwd,
87
-                                   key_filename=self.key,
88
-                                   timeout=self.timeout)
86
+                remote = ssh.Client(node, self.usr, self.pwd,
87
+                                    key_filename=self.key,
88
+                                    timeout=self.timeout)
89 89
                 try:
90 90
                     output = remote.exec_command(cmd)
91 91
                     LOG.debug(output)

+ 16
- 15
fuel_health/nmanager.py View File

@@ -71,7 +71,7 @@ import keystoneclient
71 71
 import novaclient.client
72 72
 import novaclient.exceptions as nova_exc
73 73
 
74
-from fuel_health.common.ssh import Client as SSHClient
74
+from fuel_health.common import ssh as f_ssh
75 75
 from fuel_health.common.utils.data_utils import rand_int_id
76 76
 from fuel_health.common.utils.data_utils import rand_name
77 77
 from fuel_health import exceptions
@@ -614,8 +614,9 @@ class NovaNetworkScenarioTest(OfficialClientTest):
614 614
                       '"online_controllers" parameter is empty.')
615 615
 
616 616
         try:
617
-            sshclient = SSHClient(self.host[0], self.usr, self.pwd,
618
-                                  key_filename=self.key, timeout=self.timeout)
617
+            sshclient = f_ssh.Client(self.host[0], self.usr, self.pwd,
618
+                                     key_filename=self.key,
619
+                                     timeout=self.timeout)
619 620
             return sshclient.exec_longrun_command(cmd)
620 621
         except Exception:
621 622
             LOG.exception()
@@ -828,10 +829,10 @@ class NovaNetworkScenarioTest(OfficialClientTest):
828 829
 
829 830
             if self.host:
830 831
                 try:
831
-                    ssh = SSHClient(self.host[0],
832
-                                    self.usr, self.pwd,
833
-                                    key_filename=self.key,
834
-                                    timeout=timeout)
832
+                    ssh = f_ssh.Client(self.host[0],
833
+                                       self.usr, self.pwd,
834
+                                       key_filename=self.key,
835
+                                       timeout=timeout)
835 836
                 except Exception:
836 837
                     LOG.exception()
837 838
 
@@ -858,10 +859,10 @@ class NovaNetworkScenarioTest(OfficialClientTest):
858 859
             try:
859 860
                 host = viaHost or self.host[0]
860 861
                 LOG.debug('Get ssh to instance')
861
-                ssh = SSHClient(host,
862
-                                self.usr, self.pwd,
863
-                                key_filename=self.key,
864
-                                timeout=timeout)
862
+                ssh = f_ssh.Client(host,
863
+                                   self.usr, self.pwd,
864
+                                   key_filename=self.key,
865
+                                   timeout=timeout)
865 866
 
866 867
             except Exception:
867 868
                 LOG.exception()
@@ -888,10 +889,10 @@ class NovaNetworkScenarioTest(OfficialClientTest):
888 889
             try:
889 890
                 host = viaHost or self.host[0]
890 891
                 LOG.debug('Get ssh to instance')
891
-                ssh = SSHClient(host,
892
-                                self.usr, self.pwd,
893
-                                key_filename=self.key,
894
-                                timeout=timeout)
892
+                ssh = f_ssh.Client(host,
893
+                                   self.usr, self.pwd,
894
+                                   key_filename=self.key,
895
+                                   timeout=timeout)
895 896
                 LOG.debug('Host is {0}'.format(host))
896 897
 
897 898
             except Exception:

+ 5
- 5
fuel_health/test.py View File

@@ -22,8 +22,8 @@ import testresources
22 22
 import unittest2
23 23
 
24 24
 from fuel_health.common import log as logging
25
-from fuel_health.common.ssh import Client as SSHClient
26
-from fuel_health.common.test_mixins import FuelTestAssertMixin
25
+from fuel_health.common import ssh
26
+from fuel_health.common import test_mixins
27 27
 from fuel_health import config
28 28
 
29 29
 
@@ -32,7 +32,7 @@ LOG = logging.getLogger(__name__)
32 32
 
33 33
 class BaseTestCase(unittest2.TestCase,
34 34
                    testresources.ResourcedTestCase,
35
-                   FuelTestAssertMixin):
35
+                   test_mixins.FuelTestAssertMixin):
36 36
 
37 37
     def __init__(self, *args, **kwargs):
38 38
         super(BaseTestCase, self).__init__(*args, **kwargs)
@@ -137,8 +137,8 @@ class TestCase(BaseTestCase):
137 137
         Fail if exit code != 0
138 138
         """
139 139
         try:
140
-            sshclient = SSHClient(host, self.usr, self.pwd,
141
-                                  key_filename=self.key, timeout=self.timeout)
140
+            sshclient = ssh.Client(host, self.usr, self.pwd,
141
+                                   key_filename=self.key, timeout=self.timeout)
142 142
             return sshclient.exec_command(cmd)
143 143
         except Exception:
144 144
             LOG.exception("Failed while opening ssh session with host")

+ 7
- 7
fuel_health/tests/configuration/test_configuration.py View File

@@ -15,10 +15,10 @@
15 15
 import logging
16 16
 import paramiko.ssh_exception as exc
17 17
 
18
-from fuel_health.common.ssh import Client as SSHClient
18
+from fuel_health.common import ssh
19 19
 from fuel_health import exceptions
20 20
 from fuel_health import nmanager
21
-from keystoneclient.exceptions import Unauthorized
21
+from keystoneclient import exceptions as k_exceptions
22 22
 from keystoneclient.v2_0 import Client as keystoneclient
23 23
 
24 24
 LOG = logging.getLogger(__name__)
@@ -52,10 +52,10 @@ class SanityConfigurationTest(nmanager.SanityChecksTest):
52 52
         """
53 53
         ip = self.config.nailgun_host
54 54
 
55
-        ssh_client = SSHClient(ip,
56
-                               self.config.master.master_node_ssh_user,
57
-                               self.config.master.master_node_ssh_password,
58
-                               timeout=self.config.master.ssh_timeout)
55
+        ssh_client = ssh.Client(ip,
56
+                                self.config.master.master_node_ssh_user,
57
+                                self.config.master.master_node_ssh_password,
58
+                                timeout=self.config.master.ssh_timeout)
59 59
         cmd = "date"
60 60
         output = []
61 61
         try:
@@ -122,7 +122,7 @@ class SanityConfigurationTest(nmanager.SanityChecksTest):
122 122
                                           password=pwd,
123 123
                                           auth_url=url)
124 124
                 keystone.authenticate()
125
-            except Unauthorized:
125
+            except k_exceptions.Unauthorized:
126 126
                 pass
127 127
             else:
128 128
                 self.fail('Step 1 failed: Default credentials '

+ 4
- 4
fuel_health/tests/ha/test_haproxy.py View File

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

+ 14
- 14
fuel_health/tests/ha/test_mysql_replication.py View File

@@ -14,14 +14,14 @@
14 14
 
15 15
 import logging
16 16
 
17
-from fuel_health.common.ssh import Client as SSHClient
17
+from fuel_health.common import ssh
18 18
 from fuel_health.common.utils import data_utils
19
-from fuel_health.tests.ha.test_mysql_status import BaseMysqlTest
19
+from fuel_health.tests.ha import test_mysql_status
20 20
 
21 21
 LOG = logging.getLogger(__name__)
22 22
 
23 23
 
24
-class TestMysqlReplication(BaseMysqlTest):
24
+class TestMysqlReplication(test_mysql_status.BaseMysqlTest):
25 25
     @classmethod
26 26
     def setUpClass(cls):
27 27
         super(TestMysqlReplication, cls).setUpClass()
@@ -38,8 +38,8 @@ class TestMysqlReplication(BaseMysqlTest):
38 38
         if cls.master_ip:
39 39
             try:
40 40
                 cmd = "mysql -h localhost -e 'DROP DATABASE %s'" % cls.database
41
-                SSHClient(cls.master_ip, cls.node_user,
42
-                          key_filename=cls.node_key).exec_command(cmd)
41
+                ssh.Client(cls.master_ip, cls.node_user,
42
+                           key_filename=cls.node_key).exec_command(cmd)
43 43
             except Exception:
44 44
                 LOG.exception("Failed to connect to mysql cmd:{0}".format(cmd))
45 45
 
@@ -76,7 +76,7 @@ class TestMysqlReplication(BaseMysqlTest):
76 76
         # check that mysql is running on all hosts
77 77
         cmd = 'mysql -h localhost -e "" '
78 78
         for db_node in databases:
79
-            ssh_client = SSHClient(
79
+            ssh_client = ssh.Client(
80 80
                 db_node, self.node_user,
81 81
                 key_filename=self.node_key, timeout=100)
82 82
             self.verify(
@@ -122,9 +122,9 @@ class TestMysqlReplication(BaseMysqlTest):
122 122
 
123 123
         # create db, table, insert data on one node
124 124
         LOG.info('target node ip/hostname: "{0}" '.format(self.master_ip))
125
-        master_ssh_client = SSHClient(self.master_ip, self.node_user,
126
-                                      key_filename=self.node_key,
127
-                                      timeout=100)
125
+        master_ssh_client = ssh.Client(self.master_ip, self.node_user,
126
+                                       key_filename=self.node_key,
127
+                                       timeout=100)
128 128
 
129 129
         self.verify(20, master_ssh_client.exec_command, 2,
130 130
                     'Database creation failed', 'create database',
@@ -141,9 +141,9 @@ class TestMysqlReplication(BaseMysqlTest):
141 141
         # Verify that data is replicated on other databases
142 142
         for db_node in databases:
143 143
             if db_node != self.master_ip:
144
-                client = SSHClient(db_node,
145
-                                   self.node_user,
146
-                                   key_filename=self.node_key)
144
+                client = ssh.Client(db_node,
145
+                                    self.node_user,
146
+                                    key_filename=self.node_key)
147 147
 
148 148
                 output = self.verify(
149 149
                     20, client.exec_command, 5,
@@ -155,8 +155,8 @@ class TestMysqlReplication(BaseMysqlTest):
155 155
                                           failed_step='6')
156 156
 
157 157
         # Drop created db
158
-        ssh_client = SSHClient(self.master_ip, self.node_user,
159
-                               key_filename=self.node_key)
158
+        ssh_client = ssh.Client(self.master_ip, self.node_user,
159
+                                key_filename=self.node_key)
160 160
         self.verify(20, ssh_client.exec_command, 7,
161 161
                     'Can not delete created database',
162 162
                     'database deletion', drop_db)

+ 11
- 11
fuel_health/tests/ha/test_mysql_status.py View File

@@ -15,13 +15,13 @@
15 15
 from distutils import version
16 16
 import logging
17 17
 
18
-from fuel_health.common.ssh import Client as SSHClient
19
-from fuel_health.test import BaseTestCase
18
+from fuel_health.common import ssh
19
+from fuel_health import test
20 20
 
21 21
 LOG = logging.getLogger(__name__)
22 22
 
23 23
 
24
-class BaseMysqlTest(BaseTestCase):
24
+class BaseMysqlTest(test.BaseTestCase):
25 25
     """Base methods for MySQL DB tests
26 26
     """
27 27
     @classmethod
@@ -54,10 +54,10 @@ class BaseMysqlTest(BaseTestCase):
54 54
                 < version.StrictVersion('7.0'):
55 55
             return cls.config.compute.online_controllers
56 56
         # retrieve data from controller
57
-        ssh_client = SSHClient(controller_ip,
58
-                               username,
59
-                               key_filename=key,
60
-                               timeout=100)
57
+        ssh_client = ssh.Client(controller_ip,
58
+                                username,
59
+                                key_filename=key,
60
+                                timeout=100)
61 61
 
62 62
         hiera_cmd = ('ruby -e \'require "hiera"; '
63 63
                      'db_h = Hiera.new().lookup("database_nodes", {}, {}); '
@@ -118,7 +118,7 @@ class TestMysqlStatus(BaseMysqlTest):
118 118
                 LOG.info('Current database node is %s' % node)
119 119
                 cmd1 = cmd % {'database': database}
120 120
                 LOG.info('Try to execute command %s' % cmd1)
121
-                tables = SSHClient(
121
+                tables = ssh.Client(
122 122
                     node, self.node_user,
123 123
                     key_filename=self.node_key,
124 124
                     timeout=self.config.compute.ssh_timeout)
@@ -181,9 +181,9 @@ class TestMysqlStatus(BaseMysqlTest):
181 181
 
182 182
         for db_node in databases:
183 183
             command = "mysql -h localhost -e \"SHOW STATUS LIKE 'wsrep_%'\""
184
-            ssh_client = SSHClient(db_node, self.node_user,
185
-                                   key_filename=self.node_key,
186
-                                   timeout=100)
184
+            ssh_client = ssh.Client(db_node, self.node_user,
185
+                                    key_filename=self.node_key,
186
+                                    timeout=100)
187 187
             output = self.verify(
188 188
                 20, ssh_client.exec_command, 2,
189 189
                 "Verification of galera cluster node status failed",

+ 11
- 11
fuel_health/tests/sanity/test_sanity_infrastructure.py View File

@@ -17,7 +17,7 @@
17 17
 import logging
18 18
 import time
19 19
 
20
-from fuel_health.common.ssh import Client as SSHClient
20
+from fuel_health.common import ssh
21 21
 from fuel_health import nmanager
22 22
 
23 23
 LOG = logging.getLogger(__name__)
@@ -108,11 +108,11 @@ class SanityInfrastructureTest(nmanager.SanityChecksTest):
108 108
 
109 109
         cmd = "ping -q -c1 -w10 8.8.8.8"
110 110
 
111
-        ssh_client = SSHClient(self.computes[0],
112
-                               self.usr,
113
-                               self.pwd,
114
-                               key_filename=self.key,
115
-                               timeout=self.timeout)
111
+        ssh_client = ssh.Client(self.computes[0],
112
+                                self.usr,
113
+                                self.pwd,
114
+                                key_filename=self.key,
115
+                                timeout=self.timeout)
116 116
         self.verify(100, self.retry_command, 1,
117 117
                     "'ping' command failed. Looks like there is no "
118 118
                     "Internet connection on the compute node.",
@@ -137,11 +137,11 @@ class SanityInfrastructureTest(nmanager.SanityChecksTest):
137 137
 
138 138
         dns = self.fuel_dns.spit(',') if self.fuel_dns else ['8.8.8.8']
139 139
 
140
-        ssh_client = SSHClient(self.computes[0],
141
-                               self.usr,
142
-                               self.pwd,
143
-                               key_filename=self.key,
144
-                               timeout=self.timeout)
140
+        ssh_client = ssh.Client(self.computes[0],
141
+                                self.usr,
142
+                                self.pwd,
143
+                                key_filename=self.key,
144
+                                timeout=self.timeout)
145 145
         expected_output = "{0}.in-addr.arpa domain name pointer".format(dns[0])
146 146
 
147 147
         cmd = "host {0}".format(dns[0])

+ 2
- 2
fuel_plugin/ostf_adapter/nose_plugin/nose_adapter.py View File

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

+ 2
- 2
fuel_plugin/ostf_adapter/nose_plugin/nose_utils.py View File

@@ -21,7 +21,7 @@ import re
21 21
 import traceback
22 22
 
23 23
 from nose import case
24
-from nose.suite import ContextSuite
24
+from nose import suite
25 25
 
26 26
 try:
27 27
     from oslo.serialization import jsonutils
@@ -172,7 +172,7 @@ def get_tests_to_update(test):
172 172
 
173 173
     if isinstance(test, case.Test):
174 174
         tests.append(test)
175
-    elif isinstance(test, ContextSuite):
175
+    elif isinstance(test, suite.ContextSuite):
176 176
         for sub_test in test._tests:
177 177
             tests.extend(get_tests_to_update(sub_test))
178 178
 

+ 3
- 3
fuel_plugin/testing/tests/functional/base.py View File

@@ -15,7 +15,7 @@
15 15
 import functools
16 16
 import unittest
17 17
 
18
-from fuel_plugin.ostf_client.client import TestingAdapterClient
18
+from fuel_plugin.ostf_client import client
19 19
 
20 20
 
21 21
 class EmptyResponseError(Exception):
@@ -66,10 +66,10 @@ class Response(object):
66 66
 class AdapterClientProxy(object):
67 67
 
68 68
     def __init__(self, url):
69
-        self.client = TestingAdapterClient(url)
69
+        self.client = client.TestingAdapterClient(url)
70 70
 
71 71
     def __getattr__(self, item):
72
-        if item in TestingAdapterClient.__dict__:
72
+        if item in client.TestingAdapterClient.__dict__:
73 73
             call = getattr(self.client, item)
74 74
             return self._decorate_call(call)
75 75
 

+ 3
- 3
fuel_plugin/testing/tests/unit/test_results_logger.py View File

@@ -16,11 +16,11 @@
16 16
 
17 17
 import mock
18 18
 
19
-from fuel_plugin.ostf_adapter.logger import ResultsLogger
19
+from fuel_plugin.ostf_adapter import logger
20 20
 from fuel_plugin.testing.tests import base
21 21
 
22 22
 
23
-@mock.patch.object(ResultsLogger, '_init_file_logger')
23
+@mock.patch.object(logger.ResultsLogger, '_init_file_logger')
24 24
 class TestResultsLogger(base.BaseUnitTest):
25 25
 
26 26
     def get_logger(self, **kwargs):
@@ -29,7 +29,7 @@ class TestResultsLogger(base.BaseUnitTest):
29 29
             'cluster_id': 1,
30 30
         }
31 31
         options.update(kwargs)
32
-        return ResultsLogger(**options)
32
+        return logger.ResultsLogger(**options)
33 33
 
34 34
     def test_filename(self, m_init_logger):
35 35
         logger = self.get_logger(testset='testset_name',

Loading…
Cancel
Save