aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Enguehard <mengueha+fdio@cisco.com>2017-05-29 15:54:39 +0200
committerMarcel Enguehard <mengueha+fdio@cisco.com>2017-05-29 15:54:39 +0200
commit97c6a8bb1847febe8bda5f95e19f527cabc060b9 (patch)
treeeef5bd3a9c10179d59205f11240535d8be20f5ee
parenta836e5c16ea7df38646c46f2e9ffc6163ab05f06 (diff)
Misc bug fixes: VPP, deb package detection, lxd
Change-Id: Ib3d339e636c0ec62dc0fe3227af85bcc167445cf Signed-off-by: Marcel Enguehard <mengueha+fdio@cisco.com>
-rw-r--r--netmodel/network/flow_table.py1
-rw-r--r--vicn/core/resource.py7
-rw-r--r--vicn/core/resource_mgr.py11
-rw-r--r--vicn/resource/ip/prefix_tree.py3
-rw-r--r--vicn/resource/linux/certificate.py8
-rw-r--r--vicn/resource/linux/net_device.py4
-rw-r--r--vicn/resource/linux/numa_mgr.py24
-rw-r--r--vicn/resource/linux/package_manager.py2
-rw-r--r--vicn/resource/lxd/lxc_container.py1
-rw-r--r--vicn/resource/lxd/lxd_hypervisor.py3
-rw-r--r--vicn/resource/lxd/lxd_profile.py2
-rw-r--r--vicn/resource/vpp/vpp.py6
12 files changed, 42 insertions, 30 deletions
diff --git a/netmodel/network/flow_table.py b/netmodel/network/flow_table.py
index 86c6e52e..99e42e99 100644
--- a/netmodel/network/flow_table.py
+++ b/netmodel/network/flow_table.py
@@ -106,7 +106,6 @@ class FlowTable:
# If the flow is a subscription, we need to associate it to the list
query = packet.to_query()
if query.action == ACTION_SUBSCRIBE:
- print('adding subscription', query.to_dict())
# XXX we currently don't merge subscriptions, and assume a single
# next hop interface
s = Subscription(packet, [ingress_interface], [interface])
diff --git a/vicn/core/resource.py b/vicn/core/resource.py
index 9044ec21..f92e1255 100644
--- a/vicn/core/resource.py
+++ b/vicn/core/resource.py
@@ -288,6 +288,8 @@ class BaseResource(BaseType, ABC, metaclass=ResourceMetaclass):
# Automatic instanciation
#
# Used for instance in route.node.routing_table.routes
+ # XXX We can only auto_instanciate local attributes, otherwise we
+ # get issues with asyncio loop not present in thread
if attribute.requirements:
log.warning('Ignored requirements {}'.format(
attribute.requirements))
@@ -301,7 +303,8 @@ class BaseResource(BaseType, ABC, metaclass=ResourceMetaclass):
value = self.get_default(attribute)
self.set(attribute.name, value)
else:
- log.info("Fetching remote value for {}.{}".format(self,attribute.name))
+ # printing self might do an infinite loop here !
+ log.info("Fetching remote value for {}.{}".format(self.get_uuid(), attribute.name))
task = getattr(self, "_get_{}".format(attribute.name))()
#XXX This is ugly but it prevents the LxdNotFound exception
while True:
@@ -315,7 +318,7 @@ class BaseResource(BaseType, ABC, metaclass=ResourceMetaclass):
import traceback; traceback.print_tb(e.__traceback__)
log.error("Failed to retrieve remote value for {} on {}".format(attribute.name, self))
import os; os._exit(1)
- value = rv[attribute.name]
+ value = rv[attribute.name] if isinstance(rv, dict) else rv
vars(self)[attribute.name] = value
if unref and isinstance(value, UUID):
diff --git a/vicn/core/resource_mgr.py b/vicn/core/resource_mgr.py
index e6029cd7..44503555 100644
--- a/vicn/core/resource_mgr.py
+++ b/vicn/core/resource_mgr.py
@@ -1126,6 +1126,7 @@ class ResourceManager(metaclass=Singleton):
def _trigger_state_change(self, resource, fut):
try:
+
ret = fut.result()
resource._state.change_success = True
resource._state.change_value = ret
@@ -1375,8 +1376,14 @@ class ResourceManager(metaclass=Singleton):
# Update state based on task results
if pending_state == ResourceState.PENDING_DEPS:
- # XXX NO CHANGE SUCCESS TEST ??
- new_state = ResourceState.DEPS_OK
+ if resource._state.change_success == True:
+ self.log(resource, 'DEPS done.')
+ new_state = ResourceState.DEPS_OK
+ else:
+ e = resource._state.change_value
+ log.error('Cannot wait resource dependencies {} : {}'.format(
+ resource.get_uuid(), e))
+ new_state = ResourceState.ERROR
elif pending_state == ResourceState.PENDING_INIT:
if resource._state.change_success == True:
diff --git a/vicn/resource/ip/prefix_tree.py b/vicn/resource/ip/prefix_tree.py
index f5f7d1e9..34af1d14 100644
--- a/vicn/resource/ip/prefix_tree.py
+++ b/vicn/resource/ip/prefix_tree.py
@@ -85,8 +85,7 @@ class Prefix(metaclass=ABCMeta):
return hash(str(self))
def __iter__(self):
- for i in range(self.first_prefix_address(), self.last_prefix_address()+1):
- yield self.ntoa(i)
+ return self.get_iterator()
#Iterates by steps of prefix_size, e.g., on all available /31 in a /24
def get_iterator(self, prefix_size=None):
diff --git a/vicn/resource/linux/certificate.py b/vicn/resource/linux/certificate.py
index 7f9b8a74..dd451770 100644
--- a/vicn/resource/linux/certificate.py
+++ b/vicn/resource/linux/certificate.py
@@ -43,12 +43,12 @@ class Certificate(Resource):
Implements a SSL certificate.
"""
- node = Attribute(Node,
+ node = Attribute(Node,
description = 'Node on which the certificate is created',
mandatory = True,
multiplicity = Multiplicity.ManyToOne)
cert = Attribute(String, description = 'Certificate path',
- mandatory = True)
+ mandatory = True)
key = Attribute(String, description = 'Key path',
mandatory = True)
@@ -69,8 +69,8 @@ class Certificate(Resource):
return self._cert_file.__get__() | self._key_file.__get__()
def __create__(self):
- return BashTask(None, CMD_CREATE, {'self': self})
-
+ return BashTask(self.node, CMD_CREATE, {'self': self})
+
def __delete__(self):
return self._cert_file.__delete__() | self._key_file.__delete__()
diff --git a/vicn/resource/linux/net_device.py b/vicn/resource/linux/net_device.py
index 40d3edb7..c393ac1a 100644
--- a/vicn/resource/linux/net_device.py
+++ b/vicn/resource/linux/net_device.py
@@ -34,8 +34,6 @@ from vicn.resource.interface import Interface
# parse_ip_addr inspired from:
# From: https://github.com/ohmu/poni/blob/master/poni/cloud_libvirt.py
-LXD_FIX = lambda cmd: 'sleep 1 && {}'.format(cmd)
-
MAX_DEVICE_NAME_SIZE = 15
IPV4=4
@@ -50,7 +48,7 @@ RX_INTERFACE_GET = '.*?(?P<ifname>{})@{}:'
log = logging.getLogger(__name__)
-CMD_GET = LXD_FIX('ip link show {netdevice.device_name}')
+CMD_GET = 'ip link show {netdevice.device_name}'
CMD_CREATE = 'ip link add name {netdevice.device_name} ' \
'type {netdevice.netdevice_type}'
CMD_CREATE_PARENT = 'ip link add name {netdevice.device_name} ' \
diff --git a/vicn/resource/linux/numa_mgr.py b/vicn/resource/linux/numa_mgr.py
index 632264ce..90c526a8 100644
--- a/vicn/resource/linux/numa_mgr.py
+++ b/vicn/resource/linux/numa_mgr.py
@@ -56,7 +56,7 @@ def parse_lscpu_rv(rv):
ret.append(parse_lscpu_line(line))
return ret
-#------------------------------------------------------------------------------
+#------------------------------------------------------------------------------
class NumaManager(Resource):
"""
@@ -68,36 +68,36 @@ class NumaManager(Resource):
multiplicity = Multiplicity.OneToOne,
reverse_auto = True,
reverse_name = 'numa_mgr')
- numa_repartitor = Attribute(CycleType,
+ numa_repartitor = Attribute(CycleType,
description = 'Tool to separate cores/CPUs/sockets',
- multiplicity = Multiplicity.OneToMany,
+ multiplicity = Multiplicity.OneToMany,
ro = True)
- #--------------------------------------------------------------------------
+ #--------------------------------------------------------------------------
# Resource lifecycle
- #--------------------------------------------------------------------------
+ #--------------------------------------------------------------------------
__create__ = None
__delete__ = None
- #--------------------------------------------------------------------------
+ #--------------------------------------------------------------------------
# Constructor and Accessors
- #--------------------------------------------------------------------------
+ #--------------------------------------------------------------------------
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.current_numa_node = 0
- #--------------------------------------------------------------------------
+ #--------------------------------------------------------------------------
# Attributes
- #--------------------------------------------------------------------------
+ #--------------------------------------------------------------------------
def _get_numa_repartitor(self):
return BashTask(self.node, CMD_LSCPU, parse=parse_lscpu_rv)
- #--------------------------------------------------------------------------
- # Public API
- #--------------------------------------------------------------------------
+ #--------------------------------------------------------------------------
+ # Public API
+ #--------------------------------------------------------------------------
def get_numa_core(self, numa_node=None):
if numa_node is None:
diff --git a/vicn/resource/linux/package_manager.py b/vicn/resource/linux/package_manager.py
index 1b9d518c..93241502 100644
--- a/vicn/resource/linux/package_manager.py
+++ b/vicn/resource/linux/package_manager.py
@@ -41,7 +41,7 @@ apt-get update
'''
# We need to double { } we want to preserve
-CMD_PKG_TEST='dpkg -s {self.package_name}'
+CMD_PKG_TEST='dpkg -s {self.package_name} | grep "Status:.* install "'
CMD_PKG_INSTALL='''
# Installing package {package_name}
diff --git a/vicn/resource/lxd/lxc_container.py b/vicn/resource/lxd/lxc_container.py
index 654b3bc5..8c8b4816 100644
--- a/vicn/resource/lxd/lxc_container.py
+++ b/vicn/resource/lxd/lxc_container.py
@@ -154,6 +154,7 @@ class LxcContainer(Node):
container = self._get_container_description()
log.debug('Container description: {}'.format(container))
client = self.node.lxd_hypervisor.client
+
self._container = client.containers.create(container, wait=True)
def _get_container_description(self):
diff --git a/vicn/resource/lxd/lxd_hypervisor.py b/vicn/resource/lxd/lxd_hypervisor.py
index f9952e4f..bbdba7c6 100644
--- a/vicn/resource/lxd/lxd_hypervisor.py
+++ b/vicn/resource/lxd/lxd_hypervisor.py
@@ -52,7 +52,6 @@ DEFAULT_CERT_PATH = os.path.expanduser(os.path.join(
DEFAULT_KEY_PATH = os.path.expanduser(os.path.join(
'~', '.vicn', 'lxd_client_cert', 'client_key.pem'))
-# FIXME hardcoded password for LXD server
LXD_TRUST_PWD_DEFAULT = 'vicn'
LXD_STORAGE_SIZE_DEFAULT = 100 # GB
@@ -199,6 +198,8 @@ class LxdHypervisor(Service):
owner = self)
lxd_cert_install = LxdInstallCert(certificate = lxd_local_cert,
owner = self)
+ # XXX BUG network has to exist before profile, although as an attribute it
+ # will be setup after
lxd_vicn_profile = LxdProfile(name=LXD_PROFILE_NAME_DEFAULT,
node=self.node,
description='vICN profile',
diff --git a/vicn/resource/lxd/lxd_profile.py b/vicn/resource/lxd/lxd_profile.py
index e7afee4a..db871671 100644
--- a/vicn/resource/lxd/lxd_profile.py
+++ b/vicn/resource/lxd/lxd_profile.py
@@ -28,6 +28,8 @@ lxc profile device add {profile.name} root disk pool={profile.pool} path=/
lxc profile device add {profile.name} {profile.iface_name} nic name={profile.iface_name} nictype=bridged parent={profile.network}
lxc profile unset {profile.name} environment.http_proxy
lxc profile unset {profile.name} user.network_mode
+# Temp fix for VPP
+lxc profile create vpp
'''
CMD_LXD_PROFILE_GET = 'lxc profile list | grep {profile.name}'
diff --git a/vicn/resource/vpp/vpp.py b/vicn/resource/vpp/vpp.py
index 0edbe9b8..9edcfea3 100644
--- a/vicn/resource/vpp/vpp.py
+++ b/vicn/resource/vpp/vpp.py
@@ -25,6 +25,7 @@ from vicn.core.resource import Resource
from vicn.core.task import BashTask, task, inline_task
from vicn.resource.lxd.lxc_container import LxcContainer
from vicn.resource.node import Node
+from vicn.resource.linux.application import LinuxApplication
from vicn.resource.linux.file import TextFile
from vicn.resource.vpp.dpdk_device import DpdkDevice
from vicn.resource.vpp.scripts import FN_VPP_DPDK_SCRIPT
@@ -32,6 +33,7 @@ from vicn.resource.vpp.scripts import TPL_VPP_DPDK_DAEMON_SCRIPT
from vicn.resource.vpp.vpp_commands import CMD_VPP_DISABLE, CMD_VPP_STOP
from vicn.resource.vpp.vpp_commands import CMD_VPP_START
from vicn.resource.vpp.vpp_commands import CMD_VPP_ENABLE_PLUGIN
+from vicn.resource.vpp.vpp_host import VPPHost
#------------------------------------------------------------------------------
# VPP forwarder
@@ -40,7 +42,7 @@ from vicn.resource.vpp.vpp_commands import CMD_VPP_ENABLE_PLUGIN
CMD_GET = 'killall -0 vpp_main'
CMD_DISABLE_IP_FORWARD = 'sysctl -w net.ipv4.ip_forward=0'
-class VPP(Resource):
+class VPP(LinuxApplication):
"""
Todo:
- make VPP an application with package install
@@ -48,7 +50,7 @@ class VPP(Resource):
start and stop commands
"""
- #__package_names__ = ['vpp', 'vpp-dbg', 'vpp-dpdk-dev']
+ __package_names__ = ['vpp', 'vpp-dbg', 'vpp-dpdk-dev']
plugins = Attribute(String,
multiplicity = Multiplicity.OneToMany)