From 3b2ce82fa1c2131a542d3af7768c6b4c56094a18 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Tue, 24 Apr 2018 16:10:59 -0700 Subject: [PATCH] Use true_name for remove operation Signed-off-by: Joffrey F --- compose/network.py | 7 ++----- compose/volume.py | 9 +++------ tests/unit/network_test.py | 3 +++ tests/unit/project_test.py | 2 ++ 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/compose/network.py b/compose/network.py index b00e2ae99..4ac3a0ea4 100644 --- a/compose/network.py +++ b/compose/network.py @@ -95,14 +95,11 @@ class Network(object): def remove(self): if self.external: - log.info("Network %s is external, skipping", self.full_name) + log.info("Network %s is external, skipping", self.true_name) return log.info("Removing network {}".format(self.true_name)) - try: - self.client.remove_network(self.full_name) - except NotFound: - self.client.remove_network(self.legacy_full_name) + self.client.remove_network(self.true_name) def inspect(self, legacy=False): if legacy: diff --git a/compose/volume.py b/compose/volume.py index 56ff601cd..7618417ff 100644 --- a/compose/volume.py +++ b/compose/volume.py @@ -38,13 +38,10 @@ class Volume(object): def remove(self): if self.external: - log.info("Volume %s is external, skipping", self.full_name) + log.info("Volume %s is external, skipping", self.true_name) return - log.info("Removing volume %s", self.full_name) - try: - return self.client.remove_volume(self.full_name) - except NotFound: - self.client.remove_volume(self.legacy_full_name) + log.info("Removing volume %s", self.true_name) + return self.client.remove_volume(self.true_name) def inspect(self, legacy=None): if legacy: diff --git a/tests/unit/network_test.py b/tests/unit/network_test.py index b27339af8..426156662 100644 --- a/tests/unit/network_test.py +++ b/tests/unit/network_test.py @@ -78,6 +78,7 @@ class NetworkTest(unittest.TestCase): {'Driver': 'overlay', 'Options': remote_options}, net ) + @mock.patch('compose.network.Network.true_name', lambda n: n.full_name) def test_check_remote_network_config_driver_mismatch(self): net = Network(None, 'compose_test', 'net1', 'overlay') with pytest.raises(NetworkConfigChangedError) as e: @@ -87,6 +88,7 @@ class NetworkTest(unittest.TestCase): assert 'driver has changed' in str(e.value) + @mock.patch('compose.network.Network.true_name', lambda n: n.full_name) def test_check_remote_network_config_options_mismatch(self): net = Network(None, 'compose_test', 'net1', 'overlay') with pytest.raises(NetworkConfigChangedError) as e: @@ -140,6 +142,7 @@ class NetworkTest(unittest.TestCase): net ) + @mock.patch('compose.network.Network.true_name', lambda n: n.full_name) def test_check_remote_network_labels_mismatch(self): net = Network(None, 'compose_test', 'net1', 'overlay', labels={ 'com.project.touhou.character': 'sakuya.izayoi' diff --git a/tests/unit/project_test.py b/tests/unit/project_test.py index 83a014758..1b6b6651f 100644 --- a/tests/unit/project_test.py +++ b/tests/unit/project_test.py @@ -60,6 +60,7 @@ class ProjectTest(unittest.TestCase): assert project.get_service('db').options['image'] == 'busybox:latest' assert not project.networks.use_networking + @mock.patch('compose.network.Network.true_name', lambda n: n.full_name) def test_from_config_v2(self): config = Config( version=V2_0, @@ -217,6 +218,7 @@ class ProjectTest(unittest.TestCase): ) assert project.get_service('test')._get_volumes_from() == [container_name + ":rw"] + @mock.patch('compose.network.Network.true_name', lambda n: n.full_name) def test_use_volumes_from_service_container(self): container_ids = ['aabbccddee', '12345']