mlfmonde / cluster_cli

A client utility to easly administrate cluster
MIT License
0 stars 2 forks source link

Migrate from branches with same prefix traceback: kv.find multi results #14

Open pyseed opened 5 years ago

pyseed commented 5 years ago

use case:

cluster migrate foobar dev dev2 --no-update
Traceback (most recent call last):
  File "/home/vgreiner/venvs/cluster_cli/bin/cluster", line 9, in <module>
    load_entry_point('cluster-cli', 'console_scripts', 'cluster')()
  File "/home/vgreiner/prj/cluster_cli/cluster/client.py", line 239, in main
    arguments.func(arguments)
  File "/home/vgreiner/prj/cluster_cli/cluster/client.py", line 207, in cluster_migrate
    no_update=cmd_args.no_update
  File "/home/vgreiner/prj/cluster_cli/cluster/cluster.py", line 349, in migrate
    source_repo, source_branch
  File "/home/vgreiner/prj/cluster_cli/cluster/cluster.py", line 95, in get_kv_application
    apps.keys(), repo_name, branch
RuntimeError: Repo / branch are ambiguous, multiple keys (dict_keys(['app/foobar_dev.dc926', 'app/foobar_dev2.dc926'])) found forgiven repo: foobar, branch: dev

Notes: consulates kv.find search by prefix, so better to search by exact matching

./cluster/cluster.py:86:        apps = self.consul.kv.find('app/{repo}_{branch}'.format(
./cluster/cluster.py:205:        for key, value in self.consul.kv.find('app/').items():
./cluster/tests/test_deploy.py:431:            'kv.find.return_value': {
./cluster/tests/test_deploy.py:456:            'kv.find.return_value': {
./cluster/tests/test_deploy.py:478:            'kv.find.return_value': {
./cluster/tests/test_deploy.py:502:            'kv.find.return_value': {}
./cluster/tests/test_deploy.py:539:            'kv.find.return_value': {}
./cluster/tests/test_deploy.py:572:            'kv.find.return_value': {
./cluster/tests/cluster_test_case.py:68:            'kv.find.side_effect': kv_find

Note2: cluster handler seems not to use find, good news !

petrus-v commented 5 years ago

oh yes I forgot about this limitation. If I remember I choose to do that to avoid to recalculate the md5 part of the project name (cf https://github.com/mlfmonde/cluster/blob/master/consul/consul_watcher_deployer/handler.py#L120-L124 which was added to avoid conflict between projects/volumes) while searching an entry in the k/v store without the need to searching in values. We may require to do that exact match looking in values instead keys only.

Regards,

pyseed commented 5 years ago

as branch/md5 is separated by dot '.' with have just to find by branch + '.'