X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FContainerUtils.py;h=b552e4d9e63387b095c7ce0f2fb70f4688c9324b;hb=080b0394d24c52ffcf752630605a714bfe0fb8dd;hp=363411c070565f3d3d8f85024309acd90405bfc1;hpb=c79c748013ec53ff59e9260034822a5b26afa441;p=csit.git diff --git a/resources/libraries/python/ContainerUtils.py b/resources/libraries/python/ContainerUtils.py index 363411c070..b552e4d9e6 100644 --- a/resources/libraries/python/ContainerUtils.py +++ b/resources/libraries/python/ContainerUtils.py @@ -21,13 +21,13 @@ from collections import OrderedDict, Counter from resources.libraries.python.ssh import SSH from resources.libraries.python.Constants import Constants -from resources.libraries.python.topology import Topology +from resources.libraries.python.topology import Topology, SocketType from resources.libraries.python.VppConfigGenerator import VppConfigGenerator __all__ = ["ContainerManager", "ContainerEngine", "LXC", "Docker", "Container"] -SUPERVISOR_CONF = '/etc/supervisord.conf' +SUPERVISOR_CONF = '/etc/supervisor/supervisord.conf' class ContainerManager(object): @@ -397,39 +397,55 @@ class ContainerEngine(object): if isinstance(self, LXC): self.execute('sleep 3; apt-get update') self.execute('apt-get install -y supervisor') - self.execute('echo "{config}" > {config_file} && ' - 'supervisord -c {config_file}'. - format( - config='[unix_http_server]\n' - 'file = /tmp/supervisor.sock\n\n' - '[rpcinterface:supervisor]\n' - 'supervisor.rpcinterface_factory = ' - 'supervisor.rpcinterface:make_main_rpcinterface\n\n' - '[supervisorctl]\n' - 'serverurl = unix:///tmp/supervisor.sock\n\n' - '[supervisord]\n' - 'pidfile = /tmp/supervisord.pid\n' - 'identifier = supervisor\n' - 'directory = /tmp\n' - 'logfile=/tmp/supervisord.log\n' - 'loglevel=debug\n' - 'nodaemon=false\n\n', - config_file=SUPERVISOR_CONF)) + self.execute('echo "{config}" > {config_file} && ' + 'supervisord -c {config_file}'. + format( + config='[unix_http_server]\n' + 'file = /tmp/supervisor.sock\n\n' + '[rpcinterface:supervisor]\n' + 'supervisor.rpcinterface_factory = supervisor.' + 'rpcinterface:make_main_rpcinterface\n\n' + '[supervisorctl]\n' + 'serverurl = unix:///tmp/supervisor.sock\n\n' + '[supervisord]\n' + 'pidfile = /tmp/supervisord.pid\n' + 'identifier = supervisor\n' + 'directory = /tmp\n' + 'logfile = /tmp/supervisord.log\n' + 'loglevel = debug\n' + 'nodaemon = false\n\n', + config_file=SUPERVISOR_CONF)) def start_vpp(self): """Start VPP inside a container.""" - self.execute('echo "{config}" >> {config_file}'. + self.execute('echo "{config}" >> {config_file} && ' + 'supervisorctl reload'. format( config='[program:vpp]\n' - 'command=/usr/bin/vpp -c /etc/vpp/startup.conf\n' - 'autostart=false\n' - 'autorestart=false\n' - 'redirect_stderr=true\n' - 'priority=1', + 'command = /usr/bin/vpp -c /etc/vpp/startup.conf\n' + 'autostart = false\n' + 'autorestart = false\n' + 'redirect_stderr = true\n' + 'priority = 1', config_file=SUPERVISOR_CONF)) - self.execute('supervisorctl reload') self.execute('supervisorctl start vpp') + from robot.libraries.BuiltIn import BuiltIn + topo_instance = BuiltIn().get_library_instance( + 'resources.libraries.python.topology.Topology') + topo_instance.add_new_socket( + self.container.node, + SocketType.PAPI, + self.container.name, + '{root}/tmp/vpp_sockets/{name}/api.sock'. + format(root=self.container.root, name=self.container.name)) + topo_instance.add_new_socket( + self.container.node, + SocketType.STATS, + self.container.name, + '{root}/tmp/vpp_sockets/{name}/stats.sock'. + format(root=self.container.root, name=self.container.name)) + def restart_vpp(self): """Restart VPP service inside a container.""" self.execute('supervisorctl restart vpp') @@ -449,7 +465,8 @@ class ContainerEngine(object): vpp_config.add_unix_cli_listen() vpp_config.add_unix_nodaemon() vpp_config.add_unix_exec('/tmp/running.exec') - vpp_config.add_socksvr() + vpp_config.add_socksvr(socket=Constants.SOCKSVR_PATH) + vpp_config.add_statseg_per_node_counters(value='on') # We will pop the first core from the list to be a main core vpp_config.add_cpu_main_core(str(cpuset_cpus.pop(0))) # If more cores in the list, the rest will be used as workers. @@ -499,7 +516,8 @@ class ContainerEngine(object): vpp_config.add_unix_cli_listen() vpp_config.add_unix_nodaemon() vpp_config.add_unix_exec('/tmp/running.exec') - vpp_config.add_socksvr() + vpp_config.add_socksvr(socket=Constants.SOCKSVR_PATH) + vpp_config.add_statseg_per_node_counters(value='on') vpp_config.add_plugin('disable', 'dpdk_plugin.so') # Apply configuration @@ -615,16 +633,26 @@ class LXC(ContainerEngine): :raises RuntimeError: If creating the container fails. """ if self.container.mnt: + # LXC fix for tmpfs + # https://github.com/lxc/lxc/issues/434 + ret, _, _ = self.container.ssh.exec_command_sudo( + "sh -c 'echo \"{e}\" >> /var/lib/lxc/{c.name}/config'". + format(e="lxc.mount.entry = tmpfs run tmpfs defaults", + c=self.container)) + if int(ret) != 0: + raise RuntimeError('Failed to write {c.name} config.'. + format(c=self.container)) + for mount in self.container.mnt: host_dir, guest_dir = mount.split(':') options = 'bind,create=dir' \ if guest_dir.endswith('/') else 'bind,create=file' - entry = 'lxc.mount.entry = {host_dir} '\ - '/var/lib/lxc/{c.name}/rootfs{guest_dir} none ' \ - '{options} 0 0'.format(c=self.container, - host_dir=host_dir, - guest_dir=guest_dir, - options=options) + entry = 'lxc.mount.entry = {host_dir} {guest_dir} none ' \ + '{options} 0 0'.format( + host_dir=host_dir, guest_dir=guest_dir[1:], + options=options) + self.container.ssh.exec_command_sudo( + "sh -c 'mkdir -p {host_dir}'".format(host_dir=host_dir)) ret, _, _ = self.container.ssh.exec_command_sudo( "sh -c 'echo \"{e}\" >> /var/lib/lxc/{c.name}/config'". format(e=entry, c=self.container)) @@ -637,8 +665,7 @@ class LXC(ContainerEngine): if self.container.cpuset_cpus else '' ret, _, _ = self.container.ssh.exec_command_sudo( - 'lxc-start --name {c.name} --daemon'. - format(c=self.container)) + 'lxc-start --name {c.name} --daemon'.format(c=self.container)) if int(ret) != 0: raise RuntimeError('Failed to start container {c.name}.'. format(c=self.container))