Skip to content

Commit

Permalink
Hotfix/fix prefs remove (#3890)
Browse files Browse the repository at this point in the history
* fixing prefs removal

* test passing

* defining binary remote too

* sleep to force timestamp increase for --update
  • Loading branch information
memsharded authored and lasote committed Oct 31, 2018
1 parent 6f397ba commit 3edf061
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 21 deletions.
5 changes: 4 additions & 1 deletion conans/client/graph/graph_binaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ def _evaluate_node(self, node, build_mode, update, evaluated_references, remote_
if remote_name:
remote = self._registry.remotes.get(remote_name)
else:
remote = self._registry.prefs.get(package_ref)
# If the remote_name is not given, follow the binary remote, or
# the recipe remote
# If it is defined it won't iterate (might change in conan2.0)
remote = self._registry.prefs.get(package_ref) or self._registry.refs.get(conan_ref)
remotes = self._registry.remotes.list

if os.path.exists(package_folder):
Expand Down
1 change: 1 addition & 0 deletions conans/client/remover.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def _local_remove(self, reference, src, build_ids, package_ids):
if not src and build_ids is None and package_ids is None:
remover.remove(reference)
self._registry.refs.remove(reference, quiet=True)
self._registry.prefs.remove_all(reference)

def remove(self, pattern, remote_name, src=None, build_ids=None, package_ids_filter=None, force=False,
packages_query=None, outdated=False):
Expand Down
21 changes: 21 additions & 0 deletions conans/test/command/remove_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@
from conans.test.utils.tools import TestClient, TestBufferConanOutput, TestServer
from conans.test.utils.cpp_test_files import cpp_hello_conan_files
from conans.test.utils.test_files import temp_folder
from conans.util.files import load


class RemoveRegistryTest(unittest.TestCase):

def remove_registry_test(self):
test_server = TestServer(users={"lasote": "password"}) # exported users and passwords
servers = {"default": test_server}
client = TestClient(servers=servers, users={"default": [("lasote", "password")]})
conanfile = """from conans import ConanFile
class Test(ConanFile):
pass
"""
client.save({"conanfile.py": conanfile})
client.run("create . Test/0.1@lasote/testing")
client.run("upload * --all --confirm")
client.run('remove "*" -f')
client.run("remote list_pref Test/0.1@lasote/testing")
self.assertNotIn("Test/0.1@lasote/testing", client.out)
registry_content = load(client.client_cache.registry)
self.assertNotIn("Test/0.1@lasote/testing", registry_content)


class RemoveOutdatedTest(unittest.TestCase):
Expand Down
52 changes: 32 additions & 20 deletions conans/test/integration/multi_remote_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import unittest
from conans.test.utils.tools import TestServer, TestClient
from conans.model.ref import ConanFileReference, PackageReference
from conans.test.utils.cpp_test_files import cpp_hello_conan_files
from collections import OrderedDict

from conans.model.ref import ConanFileReference
from conans.test.utils.cpp_test_files import cpp_hello_conan_files
from conans.test.utils.tools import TestServer, TestClient
from conans.util.files import load
import json
import time


class MultiRemoteTest(unittest.TestCase):

Expand Down Expand Up @@ -115,39 +119,47 @@ def install_from_remotes_test(self):
self.assertIn("Remote: remote1=http://", client2.user_io.out)
self.assertIn("Remote: remote2=http://", client2.user_io.out)

def package_remote_follows_recipe_remote_test(self):
def package_binary_remote_test(self):
# https://github.com/conan-io/conan/issues/3882
conanfile = """from conans import ConanFile
class ConanFileToolsTest(ConanFile):
pass
"""

# Upload recipe + package to remote1 and remote2
ref = "Hello/0.1@lasote/stable"
self.client.save({"conanfile.py": conanfile})
self.client.run("create . %s" % ref)
self.client.run("upload %s -r=remote1 --all" % ref)
self.client.run("upload %s -r=remote0 --all" % ref)
self.client.run("upload %s -r=remote2 --all" % ref)

# Remove only binary from remote1 and everything in local
self.client.run("remove -f %s -p5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 -r remote1" % ref)
self.client.run('remove %s -f' % ref)
self.client.run("remove -f %s -p -r remote0" % ref)
self.client.run('remove "*" -f')

self.servers.pop("remote1")
# Now install it from a client, it won't find the binary in remote2
error = self.client.run("install %s" % ref, ignore_error=True)
self.assertTrue(error)
self.assertIn("Can't find a 'Hello/0.1@lasote/stable' package", self.client.out)
self.assertNotIn("remote2", self.client.out)

self.client.run("install %s -r remote2" % ref, ignore_error=False)
self.client.run("install %s -r remote2" % ref)
self.assertIn("Package installed 5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9", self.client.out)

ref = ConanFileReference.loads(ref)
pref = PackageReference(ref, "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")

# Package from remote2
remote = self.client.remote_registry.prefs.get(pref)
self.assertEquals(remote.name, "remote2")

# But recipe from remote1
remote = self.client.remote_registry.refs.get(ref)
self.assertEquals(remote.name, "remote1")
registry = load(self.client.client_cache.registry)
registry = json.loads(registry)
self.assertEquals(registry["references"], {"Hello/0.1@lasote/stable": "remote0"})
self.assertEquals(registry["package_references"],
{"Hello/0.1@lasote/stable:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9":
"remote2"})

client = TestClient(servers=self.servers, users=self.users)
time.sleep(1) # Make sure timestamps increase
client.save({"conanfile.py": conanfile + " # Comment"})
client.run("create . %s" % ref)
client.run("upload %s -r=remote2 --all" % ref)
self.client.run("install %s --update" % ref)
self.assertNotIn("Hello/0.1@lasote/stable: WARN: Can't update, no package in remote",
self.client.out)
self.assertIn("Hello/0.1@lasote/stable:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 - Update",
self.client.out)
self.assertIn("Downloading conan_package.tgz", self.client.out)

0 comments on commit 3edf061

Please sign in to comment.