File 0001-Use-strongswan-piddir-when-bind-mount-the-run-dir.patch of Package openstack-neutron-vpnaas

From 1abd2b955822c6d15ba91e9dd9ea3d9fb51794b1 Mon Sep 17 00:00:00 2001
From: Thomas Bechtold <thomasbechtold@jpberlin.de>
Date: Thu, 26 May 2016 16:57:13 +0200
Subject: [PATCH] Use strongswan piddir when bind mount the run dir

Instead of hardcoding /var/run as bind mount dir, use the directory
strongswan is using for creating pid files and sockets. The directory
can be deteced via the "ipsec --piddir" command.

Co-Authored-By: Ralf Haferkamp <rhafer@suse.de>
Closes-Bug: #1586082
Change-Id: I1d78f654945329738b06034e81423e8959e39085
---
 .../services/vpn/device_drivers/strongswan_ipsec.py         | 13 +++++++++++--
 .../tests/unit/services/vpn/device_drivers/test_ipsec.py    |  2 ++
 2 files changed, 13 insertions(+), 2 deletions(-)

Index: neutron-vpnaas-7.0.5.dev3/neutron_vpnaas/services/vpn/device_drivers/strongswan_ipsec.py
===================================================================
--- neutron-vpnaas-7.0.5.dev3.orig/neutron_vpnaas/services/vpn/device_drivers/strongswan_ipsec.py
+++ neutron-vpnaas-7.0.5.dev3/neutron_vpnaas/services/vpn/device_drivers/strongswan_ipsec.py
@@ -20,6 +20,7 @@ from oslo_config import cfg
 from oslo_log import log as logging
 
 from neutron.agent.linux import ip_lib
+from neutron.agent.linux import utils
 from neutron.plugins.common import constants
 from neutron_vpnaas.services.vpn.device_drivers import ipsec
 
@@ -78,9 +79,15 @@ class StrongSwanProcess(ipsec.BaseSwanPr
     def __init__(self, conf, process_id, vpnservice, namespace):
         self.DIALECT_MAP['v1'] = 'ikev1'
         self.DIALECT_MAP['v2'] = 'ikev2'
+        self._strongswan_piddir = self._get_strongswan_piddir()
+        LOG.debug("strongswan piddir is '%s'" % (self._strongswan_piddir))
         super(StrongSwanProcess, self).__init__(conf, process_id,
                                                 vpnservice, namespace)
 
+    def _get_strongswan_piddir(self):
+        return utils.execute(
+            cmd=[self.binary, "--piddir"], run_as_root=True).strip()
+
     def _execute(self, cmd, check_exit_code=True, extra_ok_codes=None):
         """Execute command on namespace.
 
@@ -90,8 +97,8 @@ class StrongSwanProcess(ipsec.BaseSwanPr
         ip_wrapper = ip_lib.IPWrapper(namespace=self.namespace)
         return ip_wrapper.netns.execute(
             [NS_WRAPPER,
-             '--mount_paths=/etc:%s/etc,/var/run:%s/var/run' % (
-                 self.config_dir, self.config_dir),
+             '--mount_paths=/etc:%s/etc,%s:%s/var/run' % (
+                 self.config_dir, self._strongswan_piddir, self.config_dir),
              '--cmd=%s' % ','.join(cmd)],
             check_exit_code=check_exit_code,
             extra_ok_codes=extra_ok_codes)
Index: neutron-vpnaas-7.0.5.dev3/neutron_vpnaas/tests/unit/services/vpn/device_drivers/test_ipsec.py
===================================================================
--- neutron-vpnaas-7.0.5.dev3.orig/neutron_vpnaas/tests/unit/services/vpn/device_drivers/test_ipsec.py
+++ neutron-vpnaas-7.0.5.dev3/neutron_vpnaas/tests/unit/services/vpn/device_drivers/test_ipsec.py
@@ -286,6 +286,8 @@ class BaseIPsecDeviceDriver(base.BaseTes
         self.iptables = mock.Mock()
         self.apply_mock = mock.Mock()
         self.vpnservice = copy.deepcopy(FAKE_VPN_SERVICE)
+        ipsec_process._get_strongswan_piddir = mock.Mock(
+            return_value="/var/run")
 
     @staticmethod
     def generate_diff(a, b):
openSUSE Build Service is sponsored by