Skip to content

Commit

Permalink
Fix updating BuildConfigs. Fixes #244
Browse files Browse the repository at this point in the history
  • Loading branch information
bkabrda committed Oct 14, 2015
1 parent d7bcc0c commit da5829a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion osbs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def _create_build_config_and_build(self, build_request, namespace):

build = None
if existing_bc is not None:
utils.deep_update(existing_bc, build_json)
utils.buildconfig_update(existing_bc, build_json)
logger.debug('build config for %s already exists, updating...', build_config_name)
self.os.update_build_config(build_config_name, json.dumps(existing_bc), namespace)
else:
Expand Down
15 changes: 13 additions & 2 deletions osbs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,22 @@ def graceful_chain_get(d, *args):
return t


def deep_update(orig, new):
def buildconfig_update(orig, new):
"""Performs update of given `orig` BuildConfig with values from `new` BuildConfig.
Both BuildConfigs have to be represented as `dict`s.
This function:
- adds all key/value pairs to `orig` from `new` that are missing
- replaces values in `orig` for keys that are in both
- removes key/value pairs from `orig` for keys that are not in `new`
"""
if isinstance(orig, dict) and isinstance(new, dict):
missing = set(orig.keys()) - set(new.keys())
for k in missing:
orig.pop(k)
for k, v in new.items():
if isinstance(orig.get(k, None), dict) and isinstance(v, dict):
deep_update(orig[k], v)
buildconfig_update(orig[k], v)
else:
orig[k] = v

Expand Down
12 changes: 6 additions & 6 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
import sys
from time import tzset

from osbs.utils import (deep_update,
from osbs.utils import (buildconfig_update,
get_imagestreamtag_from_image,
git_repo_humanish_part_from_uri,
get_time_from_rfc3339)
from osbs.exceptions import OsbsException
import osbs.kerberos_ccache


def test_deep_update():
x = {'a': 'A', 'b': {'b1': 'B1', 'b2': 'B2'}}
y = {'b': {'b1': 'newB1', 'b3': 'B3'}, 'c': 'C'}
deep_update(x, y)
assert x == {'a': 'A', 'b': {'b1': 'newB1', 'b2': 'B2', 'b3': 'B3'}, 'c': 'C'}
def test_buildconfig_update():
x = {'a': 'a', 'b': {'b1': 'B1', 'b2': 'B2'}, 'd': 'D'}
y = {'a': 'A', 'b': {'b1': 'newB1', 'b3': 'B3'}, 'c': 'C'}
buildconfig_update(x, y)
assert x == {'a': 'A', 'b': {'b1': 'newB1', 'b3': 'B3'}, 'c': 'C'}


@pytest.mark.parametrize(('uri', 'humanish'), [
Expand Down

0 comments on commit da5829a

Please sign in to comment.