[Container] Fix deletion of veths

In '_teardown_server' method driver was searching for all matches of
'veth' prefix and looping them for deletion. But using Xenial host
it finds each such veth name twice and tries to delete the same veth
twice too getting following error:

ovs-vsctl: no row "veth7ac5738" in table Interface

So, fix it by translating 'list' of veths to 'set' that
will have only unique names.

Change-Id: I819a885547f9fc595b15f98e4c94de21e33914ac
Closes-Bug: #1630512
(cherry picked from commit 8401c150f3)
This commit is contained in:
Valeriy Ponomaryov 2016-10-07 14:27:43 +03:00
parent 8f2fa31d8a
commit 5a77f19328
2 changed files with 9 additions and 5 deletions

View File

@ -248,7 +248,7 @@ class ContainerShareDriver(driver.ShareDriver, driver.ExecuteMixin):
self.container.stop_container(server_id)
interfaces = self._execute("ovs-vsctl", "list", "interface",
run_as_root=True)[0]
veths = re.findall("veth[0-9a-zA-Z]{7}", interfaces)
veths = set(re.findall("veth[0-9a-zA-Z]{7}", interfaces))
manila_re = ("manila_[0-9a-f]{8}_[0-9a-f]{4}_[0-9a-f]{4}_[0-9a-f]{4}_"
"[0-9a-f]{12}")
for veth in veths:

View File

@ -14,6 +14,7 @@
# under the License.
"""Unit tests for the Container driver module."""
import ddt
import functools
import mock
from oslo_config import cfg
@ -33,6 +34,7 @@ CONF = cfg.CONF
CONF.import_opt('lvm_share_export_ip', 'manila.share.drivers.lvm')
@ddt.ddt
class ContainerShareDriverTestCase(test.TestCase):
"""Tests ContainerShareDriver"""
@ -212,11 +214,12 @@ class ContainerShareDriverTestCase(test.TestCase):
self._driver._connect_to_network("fake-server", network_info,
"fake-veth")
def test__teardown_server(self):
@ddt.data(['veth0000000'], ['veth0000000' * 2])
def test__teardown_server(self, list_of_veths):
def fake_ovs_execute(*args, **kwargs):
kwargs['arguments'].append(args)
if len(args) == 3:
return ['veth0000000']
return list_of_veths
elif len(args) == 4:
return ('fake:manila_b5afb5c1_6011_43c4_8a37_29820e6951a7', '')
else:
@ -236,11 +239,12 @@ class ContainerShareDriverTestCase(test.TestCase):
self.assertEqual(expected_arguments.sort(), actual_arguments.sort())
def test__teardown_server_check_continuation(self):
@ddt.data(['veth0000000'], ['veth0000000' * 2])
def test__teardown_server_check_continuation(self, list_of_veths):
def fake_ovs_execute(*args, **kwargs):
kwargs['arguments'].append(args)
if len(args) == 3:
return ['veth0000000']
return list_of_veths
elif len(args) == 4:
return ('fake:', '')
else: