Misc bug fixes: VPP, deb package detection, lxd 06/6906/1
authorMarcel Enguehard <[email protected]>
Mon, 29 May 2017 13:54:39 +0000 (15:54 +0200)
committerMarcel Enguehard <[email protected]>
Mon, 29 May 2017 13:54:39 +0000 (15:54 +0200)
Change-Id: Ib3d339e636c0ec62dc0fe3227af85bcc167445cf
Signed-off-by: Marcel Enguehard <[email protected]>
12 files changed:
netmodel/network/flow_table.py
vicn/core/resource.py
vicn/core/resource_mgr.py
vicn/resource/ip/prefix_tree.py
vicn/resource/linux/certificate.py
vicn/resource/linux/net_device.py
vicn/resource/linux/numa_mgr.py
vicn/resource/linux/package_manager.py
vicn/resource/lxd/lxc_container.py
vicn/resource/lxd/lxd_hypervisor.py
vicn/resource/lxd/lxd_profile.py
vicn/resource/vpp/vpp.py

index 86c6e52..99e42e9 100644 (file)
@@ -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])
index 9044ec2..f92e125 100644 (file)
@@ -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):
index e6029cd..4450355 100644 (file)
@@ -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:
index f5f7d1e..34af1d1 100644 (file)
@@ -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):
index 7f9b8a7..dd45177 100644 (file)
@@ -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__()
 
index 40d3edb..c393ac1 100644 (file)
@@ -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} ' \
index 632264c..90c526a 100644 (file)
@@ -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:
index 1b9d518..9324150 100644 (file)
@@ -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}
index 654b3bc..8c8b481 100644 (file)
@@ -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):
index f9952e4..bbdba7c 100644 (file)
@@ -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',
index e7afee4..db87167 100644 (file)
@@ -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}'
index 0edbe9b..9edcfea 100644 (file)
@@ -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)