Clean imports in code

In some part in the code we import objects.
In the Openstack style guidelines they recommend to import only
modules.

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

Change-Id: Ib35cc8a00d7f89e1e38949a7e77bdb2630ec2547
This commit is contained in:
Nguyen Hung Phuong 2016-08-23 15:11:56 +07:00
parent 80b638fcac
commit 22a32a1cca
10 changed files with 42 additions and 37 deletions

View File

@ -13,7 +13,7 @@
from oslo_log import log as logging
import paramiko
from tacker.common.exceptions import NotAuthorized
from tacker.common import exceptions
LOG = logging.getLogger(__name__)
@ -68,7 +68,7 @@ class RemoteCommandExecutor(object):
except paramiko.AuthenticationException:
LOG.error(_("Authentication failed when connecting to %s")
% self.__host)
raise NotAuthorized
raise exceptions.NotAuthorized
except paramiko.SSHException:
LOG.error(_("Could not connect to %s. Giving up") % self.__host)
raise

View File

@ -19,7 +19,7 @@ from oslo_config import cfg
from tempest.lib import base
import yaml
from tacker.common.exceptions import TackerException
from tacker.common import exceptions
from tacker.tests import constants
from tacker.tests.utils import read_file
from tacker import version
@ -98,7 +98,8 @@ class BaseTackerTest(base.BaseTestCase):
status = vnf_result['vnf']['status']
if (status != 'PENDING_DELETE') or ((
int(time.time()) - start_time) > timeout):
raise TackerException(_("Failed with status: %s"), status)
raise exceptions.TackerException(_("Failed with status: %s"),
status)
@classmethod
def wait_until_vnf_dead(cls, vnf_id, timeout, sleep_interval):

View File

@ -12,7 +12,7 @@
# under the License.
from oslo_config import cfg
from toscaparser.tosca_template import ToscaTemplate
from toscaparser import tosca_template
import yaml
from tacker.common import utils
@ -58,7 +58,7 @@ class VnfTestToscaMultipleVDU(base.BaseTackerTest):
input_dict = yaml.load(input_yaml)
toscautils.updateimports(input_dict)
tosca = ToscaTemplate(parsed_params={}, a_file=False,
tosca = tosca_template.ToscaTemplate(parsed_params={}, a_file=False,
yaml_dict_tpl=input_dict)
vdus = toscautils.findvdus(tosca)

View File

@ -20,7 +20,7 @@ import testtools
from tacker.db.common_services import common_services_db
from tacker.plugins.common import constants
from tacker.vnfm.monitor import VNFMonitor
from tacker.vnfm import monitor
MOCK_DEVICE_ID = 'a737497c-761c-11e5-89c3-9cb6541d805d'
MOCK_VNF_DEVICE = {
@ -81,7 +81,7 @@ class TestVNFMonitor(testtools.TestCase):
'vnf': test_device_dict,
'monitoring_policy': MOCK_VNF_DEVICE['monitoring_policy']
}
output_dict = VNFMonitor.to_hosting_vnf(test_device_dict,
output_dict = monitor.VNFMonitor.to_hosting_vnf(test_device_dict,
action_cb)
self.assertEqual(expected_output, output_dict)
@ -98,7 +98,7 @@ class TestVNFMonitor(testtools.TestCase):
}
action_cb = mock.MagicMock()
test_boot_wait = 30
test_vnfmonitor = VNFMonitor(test_boot_wait)
test_vnfmonitor = monitor.VNFMonitor(test_boot_wait)
new_dict = test_vnfmonitor.to_hosting_vnf(test_device_dict, action_cb)
test_vnfmonitor.add_hosting_vnf(new_dict)
test_device_id = list(test_vnfmonitor._hosting_vnfs.keys())[0]
@ -120,7 +120,7 @@ class TestVNFMonitor(testtools.TestCase):
'mgmt_ip': 'a.b.c.d',
'timeout': 2
}
test_vnfmonitor = VNFMonitor(test_boot_wait)
test_vnfmonitor = monitor.VNFMonitor(test_boot_wait)
self.mock_monitor_manager.invoke = mock.MagicMock()
test_vnfmonitor._monitor_manager = self.mock_monitor_manager
test_vnfmonitor.run_monitor(test_hosting_vnf)

View File

@ -17,8 +17,8 @@ import testtools
import yaml
from tacker.vnfm.tosca import utils as toscautils
from toscaparser.tosca_template import ToscaTemplate
from translator.hot.tosca_translator import TOSCATranslator
from toscaparser import tosca_template
from translator.hot import tosca_translator
def _get_template(name):
@ -33,7 +33,7 @@ class TestToscaUtils(testtools.TestCase):
tosca_openwrt = _get_template('test_tosca_openwrt.yaml')
vnfd_dict = yaml.load(tosca_openwrt)
toscautils.updateimports(vnfd_dict)
tosca = ToscaTemplate(parsed_params={}, a_file=False,
tosca = tosca_template.ToscaTemplate(parsed_params={}, a_file=False,
yaml_dict_tpl=vnfd_dict)
tosca_flavor = _get_template('test_tosca_flavor.yaml')
@ -70,7 +70,7 @@ class TestToscaUtils(testtools.TestCase):
self.assertEqual(expected_mgmt_ports, mgmt_ports)
def test_post_process_template(self):
tosca2 = ToscaTemplate(parsed_params={}, a_file=False,
tosca2 = tosca_template.ToscaTemplate(parsed_params={}, a_file=False,
yaml_dict_tpl=self.vnfd_dict)
toscautils.post_process_template(tosca2)
invalidNodes = 0
@ -101,10 +101,10 @@ class TestToscaUtils(testtools.TestCase):
self.assertEqual(0, convertedProperties)
def test_post_process_heat_template(self):
tosca1 = ToscaTemplate(parsed_params={}, a_file=False,
tosca1 = tosca_template.ToscaTemplate(parsed_params={}, a_file=False,
yaml_dict_tpl=self.vnfd_dict)
toscautils.post_process_template(tosca1)
translator = TOSCATranslator(tosca1, {})
translator = tosca_translator.TOSCATranslator(tosca1, {})
heat_template_yaml = translator.translate()
expected_heat_tpl = _get_template('hot_tosca_openwrt.yaml')
mgmt_ports = toscautils.get_mgmt_ports(self.tosca)
@ -127,7 +127,8 @@ class TestToscaUtils(testtools.TestCase):
def test_get_flavor_dict(self):
vnfd_dict = yaml.load(self.tosca_flavor)
toscautils.updateimports(vnfd_dict)
tosca = ToscaTemplate(a_file=False, yaml_dict_tpl=vnfd_dict)
tosca = tosca_template.ToscaTemplate(a_file=False,
yaml_dict_tpl=vnfd_dict)
expected_flavor_dict = {
"VDU1": {
"vcpus": 2,
@ -159,7 +160,8 @@ class TestToscaUtils(testtools.TestCase):
'tosca_flavor_all_numa_count.yaml')
vnfd_dict = yaml.load(tosca_fes_all_numa_count)
toscautils.updateimports(vnfd_dict)
tosca = ToscaTemplate(a_file=False, yaml_dict_tpl=vnfd_dict)
tosca = tosca_template.ToscaTemplate(a_file=False,
yaml_dict_tpl=vnfd_dict)
expected_flavor_dict = {
"VDU1": {
"vcpus": 8,
@ -181,7 +183,8 @@ class TestToscaUtils(testtools.TestCase):
'tosca_flavor_all_numa_count.yaml')
vnfd_dict = yaml.load(tosca_fes_all_numa_count)
toscautils.updateimports(vnfd_dict)
tosca = ToscaTemplate(a_file=False, yaml_dict_tpl=vnfd_dict)
tosca = tosca_template.ToscaTemplate(a_file=False,
yaml_dict_tpl=vnfd_dict)
expected_flavor_dict = {
"VDU1": {
"vcpus": 8,

View File

@ -22,9 +22,9 @@ from oslo_config import cfg
from oslo_log import log as logging
from oslo_serialization import jsonutils
from six import iteritems
from toscaparser.tosca_template import ToscaTemplate
from toscaparser import tosca_template
from toscaparser.utils import yamlparser
from translator.hot.tosca_translator import TOSCATranslator
from translator.hot import tosca_translator
import yaml
from tacker.common import clients
@ -115,8 +115,8 @@ class DeviceHeat(abstract_driver.DeviceAbstractDriver,
toscautils.updateimports(inner_vnfd_dict)
try:
tosca = ToscaTemplate(a_file=False,
yaml_dict_tpl=inner_vnfd_dict)
tosca = tosca_template.ToscaTemplate(
a_file=False, yaml_dict_tpl=inner_vnfd_dict)
except Exception as e:
LOG.exception(_("tosca-parser error: %s"), str(e))
raise vnfm.ToscaParserFailed(error_msg_details=str(e))
@ -321,9 +321,9 @@ class DeviceHeat(abstract_driver.DeviceAbstractDriver,
toscautils.updateimports(vnfd_dict)
try:
tosca = ToscaTemplate(parsed_params=parsed_params,
a_file=False,
yaml_dict_tpl=vnfd_dict)
tosca = tosca_template.ToscaTemplate(
parsed_params=parsed_params, a_file=False,
yaml_dict_tpl=vnfd_dict)
except Exception as e:
LOG.debug("tosca-parser error: %s", str(e))
@ -335,7 +335,8 @@ class DeviceHeat(abstract_driver.DeviceAbstractDriver,
STACK_FLAVOR_EXTRA)
toscautils.post_process_template(tosca)
try:
translator = TOSCATranslator(tosca, parsed_params)
translator = tosca_translator.TOSCATranslator(tosca,
parsed_params)
heat_template_yaml = translator.translate()
except Exception as e:
LOG.debug("heat-translator error: %s", str(e))

View File

@ -16,7 +16,7 @@
import os
from cryptography.fernet import Fernet
from cryptography import fernet
from keystoneclient.auth import identity
from keystoneclient import client
from keystoneclient import exceptions
@ -76,6 +76,6 @@ class Keystone(object):
'permissions to create it'))
def create_fernet_key(self):
fernet_key = Fernet.generate_key()
fernet_obj = Fernet(fernet_key)
fernet_key = fernet.Fernet.generate_key()
fernet_obj = fernet.Fernet(fernet_key)
return fernet_key, fernet_obj

View File

@ -20,7 +20,7 @@ from oslo_serialization import jsonutils
import yaml
from tacker.common import cmd_executer
from tacker.common.exceptions import MgmtDriverException
from tacker.common import exceptions
from tacker.common import log
from tacker.vnfm.mgmt_drivers import abstract_driver
from tacker.vnfm.mgmt_drivers import constants as mgmt_constants
@ -65,7 +65,7 @@ class DeviceMgmtOpenWRT(abstract_driver.DeviceMGMTAbstractDriver):
commander.execute_command(cmd, input_data=config)
except Exception as ex:
LOG.error(_("While executing command on remote: %s"), ex)
raise MgmtDriverException()
raise exceptions.MgmtDriverException()
@log.log
def mgmt_call(self, plugin, context, vnf, kwargs):

View File

@ -18,7 +18,7 @@ import yaml
from oslo_log import log as logging
from six import iteritems
from toscaparser.properties import Property
from toscaparser import properties
from toscaparser.utils import yamlparser
from tacker.common import log
@ -227,8 +227,8 @@ def post_process_template(template):
if prop == p.name:
schema_dict = {'type': p.type}
v = nt.get_property_value(p.name)
newprop = Property(convert_prop[nt.type][prop], v,
schema_dict)
newprop = properties.Property(
convert_prop[nt.type][prop], v, schema_dict)
nt.get_properties_objects().append(newprop)
nt.get_properties_objects().remove(p)

View File

@ -15,7 +15,7 @@
import os
from cryptography.fernet import Fernet
from cryptography import fernet
from oslo_config import cfg
from oslo_log import log as logging
from oslo_log import versionutils
@ -113,7 +113,7 @@ class VimClient(object):
Decrypt VIM cred. using Fernet Key
"""
vim_key = self._find_vim_key(vim_id)
f = Fernet(vim_key)
f = fernet.Fernet(vim_key)
if not f:
LOG.warning(_('Unable to decode VIM auth'))
raise nfvo.VimNotFoundException('Unable to decode VIM auth key')