Device Refactor.
Refactor devide with Vnf and clean references and unused code. Change-Id: If5b06b7cbf2c46a5f2f82027ba97c7920855d0cd
This commit is contained in:
parent
eab8c1b71f
commit
0e7b4d31bc
|
@ -55,12 +55,12 @@ tacker.nfvo.vim.drivers =
|
||||||
tacker.openstack.common.cache.backends =
|
tacker.openstack.common.cache.backends =
|
||||||
memory = tacker.openstack.common.cache._backends.memory:MemoryBackend
|
memory = tacker.openstack.common.cache._backends.memory:MemoryBackend
|
||||||
tacker.tacker.vnfm.drivers =
|
tacker.tacker.vnfm.drivers =
|
||||||
noop = tacker.vnfm.infra_drivers.noop:DeviceNoop
|
noop = tacker.vnfm.infra_drivers.noop:VnfNoop
|
||||||
openstack = tacker.vnfm.infra_drivers.openstack.openstack:OpenStack
|
openstack = tacker.vnfm.infra_drivers.openstack.openstack:OpenStack
|
||||||
kubernetes = tacker.vnfm.infra_drivers.kubernetes.kubernetes_driver:Kubernetes
|
kubernetes = tacker.vnfm.infra_drivers.kubernetes.kubernetes_driver:Kubernetes
|
||||||
tacker.tacker.mgmt.drivers =
|
tacker.tacker.mgmt.drivers =
|
||||||
noop = tacker.vnfm.mgmt_drivers.noop:DeviceMgmtNoop
|
noop = tacker.vnfm.mgmt_drivers.noop:VnfMgmtNoop
|
||||||
openwrt = tacker.vnfm.mgmt_drivers.openwrt.openwrt:DeviceMgmtOpenWRT
|
openwrt = tacker.vnfm.mgmt_drivers.openwrt.openwrt:VnfMgmtOpenWRT
|
||||||
tacker.tacker.monitor.drivers =
|
tacker.tacker.monitor.drivers =
|
||||||
ping = tacker.vnfm.monitor_drivers.ping.ping:VNFMonitorPing
|
ping = tacker.vnfm.monitor_drivers.ping.ping:VNFMonitorPing
|
||||||
http_ping = tacker.vnfm.monitor_drivers.http_ping.http_ping:VNFMonitorHTTPPing
|
http_ping = tacker.vnfm.monitor_drivers.http_ping.http_ping:VNFMonitorHTTPPing
|
||||||
|
|
|
@ -13,12 +13,8 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import fcntl
|
|
||||||
import os
|
import os
|
||||||
import shlex
|
import shlex
|
||||||
import socket
|
|
||||||
import struct
|
|
||||||
import tempfile
|
|
||||||
|
|
||||||
from eventlet.green import subprocess
|
from eventlet.green import subprocess
|
||||||
from eventlet import greenthread
|
from eventlet import greenthread
|
||||||
|
@ -86,34 +82,6 @@ def execute(cmd, root_helper=None, process_input=None, addl_env=None,
|
||||||
return return_stderr and (_stdout, _stderr) or _stdout
|
return return_stderr and (_stdout, _stderr) or _stdout
|
||||||
|
|
||||||
|
|
||||||
def get_interface_mac(interface):
|
|
||||||
DEVICE_NAME_LEN = 15
|
|
||||||
MAC_START = 18
|
|
||||||
MAC_END = 24
|
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
||||||
info = fcntl.ioctl(s.fileno(), 0x8927,
|
|
||||||
struct.pack('256s', interface[:DEVICE_NAME_LEN]))
|
|
||||||
return ''.join(['%02x:' % ord(char)
|
|
||||||
for char in info[MAC_START:MAC_END]])[:-1]
|
|
||||||
|
|
||||||
|
|
||||||
def replace_file(file_name, data):
|
|
||||||
"""Replaces the contents of file_name with data in a safe manner.
|
|
||||||
|
|
||||||
First write to a temp file and then rename. Since POSIX renames are
|
|
||||||
atomic, the file is unlikely to be corrupted by competing writes.
|
|
||||||
|
|
||||||
We create the tempfile on the same device to ensure that it can be renamed.
|
|
||||||
"""
|
|
||||||
|
|
||||||
base_dir = os.path.dirname(os.path.abspath(file_name))
|
|
||||||
tmp_file = tempfile.NamedTemporaryFile('w+', dir=base_dir, delete=False)
|
|
||||||
tmp_file.write(data)
|
|
||||||
tmp_file.close()
|
|
||||||
os.chmod(tmp_file.name, 0o644)
|
|
||||||
os.rename(tmp_file.name, file_name)
|
|
||||||
|
|
||||||
|
|
||||||
def find_child_pids(pid):
|
def find_child_pids(pid):
|
||||||
"""Retrieve a list of the pids of child processes of the given pid."""
|
"""Retrieve a list of the pids of child processes of the given pid."""
|
||||||
|
|
||||||
|
|
|
@ -22,9 +22,9 @@ from tacker.db.common_services import common_services_db_plugin
|
||||||
from tacker.plugins.common import constants
|
from tacker.plugins.common import constants
|
||||||
from tacker.vnfm import monitor
|
from tacker.vnfm import monitor
|
||||||
|
|
||||||
MOCK_DEVICE_ID = 'a737497c-761c-11e5-89c3-9cb6541d805d'
|
MOCK_VNF_ID = 'a737497c-761c-11e5-89c3-9cb6541d805d'
|
||||||
MOCK_VNF_DEVICE = {
|
MOCK_VNF = {
|
||||||
'id': MOCK_DEVICE_ID,
|
'id': MOCK_VNF_ID,
|
||||||
'management_ip_addresses': {
|
'management_ip_addresses': {
|
||||||
'vdu1': 'a.b.c.d'
|
'vdu1': 'a.b.c.d'
|
||||||
},
|
},
|
||||||
|
@ -65,22 +65,22 @@ class TestVNFMonitor(testtools.TestCase):
|
||||||
|
|
||||||
def test_to_hosting_vnf(self):
|
def test_to_hosting_vnf(self):
|
||||||
test_vnf_dict = {
|
test_vnf_dict = {
|
||||||
'id': MOCK_DEVICE_ID,
|
'id': MOCK_VNF_ID,
|
||||||
'mgmt_url': '{"vdu1": "a.b.c.d"}',
|
'mgmt_url': '{"vdu1": "a.b.c.d"}',
|
||||||
'attributes': {
|
'attributes': {
|
||||||
'monitoring_policy': json.dumps(
|
'monitoring_policy': json.dumps(
|
||||||
MOCK_VNF_DEVICE['monitoring_policy'])
|
MOCK_VNF['monitoring_policy'])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
action_cb = mock.MagicMock()
|
action_cb = mock.MagicMock()
|
||||||
expected_output = {
|
expected_output = {
|
||||||
'id': MOCK_DEVICE_ID,
|
'id': MOCK_VNF_ID,
|
||||||
'action_cb': action_cb,
|
'action_cb': action_cb,
|
||||||
'management_ip_addresses': {
|
'management_ip_addresses': {
|
||||||
'vdu1': 'a.b.c.d'
|
'vdu1': 'a.b.c.d'
|
||||||
},
|
},
|
||||||
'vnf': test_vnf_dict,
|
'vnf': test_vnf_dict,
|
||||||
'monitoring_policy': MOCK_VNF_DEVICE['monitoring_policy']
|
'monitoring_policy': MOCK_VNF['monitoring_policy']
|
||||||
}
|
}
|
||||||
output_dict = monitor.VNFMonitor.to_hosting_vnf(test_vnf_dict,
|
output_dict = monitor.VNFMonitor.to_hosting_vnf(test_vnf_dict,
|
||||||
action_cb)
|
action_cb)
|
||||||
|
@ -89,11 +89,11 @@ class TestVNFMonitor(testtools.TestCase):
|
||||||
@mock.patch('tacker.vnfm.monitor.VNFMonitor.__run__')
|
@mock.patch('tacker.vnfm.monitor.VNFMonitor.__run__')
|
||||||
def test_add_hosting_vnf(self, mock_monitor_run):
|
def test_add_hosting_vnf(self, mock_monitor_run):
|
||||||
test_vnf_dict = {
|
test_vnf_dict = {
|
||||||
'id': MOCK_DEVICE_ID,
|
'id': MOCK_VNF_ID,
|
||||||
'mgmt_url': '{"vdu1": "a.b.c.d"}',
|
'mgmt_url': '{"vdu1": "a.b.c.d"}',
|
||||||
'attributes': {
|
'attributes': {
|
||||||
'monitoring_policy': json.dumps(
|
'monitoring_policy': json.dumps(
|
||||||
MOCK_VNF_DEVICE['monitoring_policy'])
|
MOCK_VNF['monitoring_policy'])
|
||||||
},
|
},
|
||||||
'status': 'ACTIVE'
|
'status': 'ACTIVE'
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ class TestVNFMonitor(testtools.TestCase):
|
||||||
new_dict = test_vnfmonitor.to_hosting_vnf(test_vnf_dict, action_cb)
|
new_dict = test_vnfmonitor.to_hosting_vnf(test_vnf_dict, action_cb)
|
||||||
test_vnfmonitor.add_hosting_vnf(new_dict)
|
test_vnfmonitor.add_hosting_vnf(new_dict)
|
||||||
test_vnf_id = list(test_vnfmonitor._hosting_vnfs.keys())[0]
|
test_vnf_id = list(test_vnfmonitor._hosting_vnfs.keys())[0]
|
||||||
self.assertEqual(MOCK_DEVICE_ID, test_vnf_id)
|
self.assertEqual(MOCK_VNF_ID, test_vnf_id)
|
||||||
self._cos_db_plugin.create_event.assert_called_with(
|
self._cos_db_plugin.create_event.assert_called_with(
|
||||||
mock.ANY, res_id=mock.ANY, res_type=constants.RES_TYPE_VNF,
|
mock.ANY, res_id=mock.ANY, res_type=constants.RES_TYPE_VNF,
|
||||||
res_state=mock.ANY, evt_type=constants.RES_EVT_MONITOR,
|
res_state=mock.ANY, evt_type=constants.RES_EVT_MONITOR,
|
||||||
|
@ -111,7 +111,7 @@ class TestVNFMonitor(testtools.TestCase):
|
||||||
|
|
||||||
@mock.patch('tacker.vnfm.monitor.VNFMonitor.__run__')
|
@mock.patch('tacker.vnfm.monitor.VNFMonitor.__run__')
|
||||||
def test_run_monitor(self, mock_monitor_run):
|
def test_run_monitor(self, mock_monitor_run):
|
||||||
test_hosting_vnf = MOCK_VNF_DEVICE
|
test_hosting_vnf = MOCK_VNF
|
||||||
test_hosting_vnf['vnf'] = {}
|
test_hosting_vnf['vnf'] = {}
|
||||||
test_boot_wait = 30
|
test_boot_wait = 30
|
||||||
mock_kwargs = {
|
mock_kwargs = {
|
||||||
|
|
|
@ -22,7 +22,7 @@ from tacker.api import extensions
|
||||||
|
|
||||||
|
|
||||||
@six.add_metaclass(abc.ABCMeta)
|
@six.add_metaclass(abc.ABCMeta)
|
||||||
class DeviceAbstractDriver(extensions.PluginInterface):
|
class VnfAbstractDriver(extensions.PluginInterface):
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_type(self):
|
def get_type(self):
|
||||||
|
|
|
@ -58,7 +58,7 @@ def get_scaling_policy_name(action, policy_name):
|
||||||
return '%s_scale_%s' % (policy_name, action)
|
return '%s_scale_%s' % (policy_name, action)
|
||||||
|
|
||||||
|
|
||||||
class Kubernetes(abstract_driver.DeviceAbstractDriver,
|
class Kubernetes(abstract_driver.VnfAbstractDriver,
|
||||||
scale_driver.VnfScaleAbstractDriver):
|
scale_driver.VnfScaleAbstractDriver):
|
||||||
"""Kubernetes infra driver for hosting containerized vnfs"""
|
"""Kubernetes infra driver for hosting containerized vnfs"""
|
||||||
|
|
||||||
|
|
|
@ -25,12 +25,12 @@ from tacker.vnfm.infra_drivers import abstract_driver
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class DeviceNoop(abstract_driver.DeviceAbstractDriver):
|
class VnfNoop(abstract_driver.VnfAbstractDriver):
|
||||||
|
|
||||||
"""Noop driver of hosting vnf for tests."""
|
"""Noop driver of hosting vnf for tests."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(DeviceNoop, self).__init__()
|
super(VnfNoop, self).__init__()
|
||||||
self._instances = set()
|
self._instances = set()
|
||||||
|
|
||||||
def get_type(self):
|
def get_type(self):
|
||||||
|
|
|
@ -75,7 +75,7 @@ def get_scaling_policy_name(action, policy_name):
|
||||||
return '%s_scale_%s' % (policy_name, action)
|
return '%s_scale_%s' % (policy_name, action)
|
||||||
|
|
||||||
|
|
||||||
class OpenStack(abstract_driver.DeviceAbstractDriver,
|
class OpenStack(abstract_driver.VnfAbstractDriver,
|
||||||
scale_driver.VnfScaleAbstractDriver):
|
scale_driver.VnfScaleAbstractDriver):
|
||||||
"""Openstack infra driver for hosting vnfs"""
|
"""Openstack infra driver for hosting vnfs"""
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ from tacker.api import extensions
|
||||||
|
|
||||||
|
|
||||||
@six.add_metaclass(abc.ABCMeta)
|
@six.add_metaclass(abc.ABCMeta)
|
||||||
class DeviceMGMTAbstractDriver(extensions.PluginInterface):
|
class VnfMGMTAbstractDriver(extensions.PluginInterface):
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_type(self):
|
def get_type(self):
|
||||||
|
|
|
@ -22,7 +22,7 @@ from tacker.vnfm.mgmt_drivers import abstract_driver
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class DeviceMgmtNoop(abstract_driver.DeviceMGMTAbstractDriver):
|
class VnfMgmtNoop(abstract_driver.VnfMGMTAbstractDriver):
|
||||||
def get_type(self):
|
def get_type(self):
|
||||||
return 'noop'
|
return 'noop'
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ def config_opts():
|
||||||
return [('openwrt', OPTS)]
|
return [('openwrt', OPTS)]
|
||||||
|
|
||||||
|
|
||||||
class DeviceMgmtOpenWRT(abstract_driver.DeviceMGMTAbstractDriver):
|
class VnfMgmtOpenWRT(abstract_driver.VnfMGMTAbstractDriver):
|
||||||
def get_type(self):
|
def get_type(self):
|
||||||
return 'openwrt'
|
return 'openwrt'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue