Merge "Clean imports in code"

This commit is contained in:
Jenkins
2016-09-07 09:44:46 +00:00
committed by Gerrit Code Review
10 changed files with 42 additions and 37 deletions

View File

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

View File

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

View File

@@ -12,7 +12,7 @@
# under the License. # under the License.
from oslo_config import cfg from oslo_config import cfg
from toscaparser.tosca_template import ToscaTemplate from toscaparser import tosca_template
import yaml import yaml
from tacker.common import utils from tacker.common import utils
@@ -58,7 +58,7 @@ class VnfTestToscaMultipleVDU(base.BaseTackerTest):
input_dict = yaml.load(input_yaml) input_dict = yaml.load(input_yaml)
toscautils.updateimports(input_dict) 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) yaml_dict_tpl=input_dict)
vdus = toscautils.findvdus(tosca) vdus = toscautils.findvdus(tosca)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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