Skip to content

Commit

Permalink
Remove apply_resource_limits
Browse files Browse the repository at this point in the history
  • Loading branch information
lcarva committed Feb 15, 2017
1 parent 745e61b commit 9150f8b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 44 deletions.
33 changes: 13 additions & 20 deletions osbs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,12 @@ def get_pod_for_build(self, build_id):
return pod_list[0]

@osbsapi
def get_build_request(self, build_type=None, apply_resource_limits=True,
inner_template=None, outer_template=None):
def get_build_request(self, build_type=None, inner_template=None,
outer_template=None):
"""
return instance of BuildRequest
:param build_type: str, unused
:param apply_resource_limits: bool, whether or not to set resource limits
:param inner_template: str, name of inner template for BuildRequest
:param outer_template: str, name of outer template for BuildRequest
:return: instance of BuildRequest
Expand All @@ -160,17 +159,16 @@ def get_build_request(self, build_type=None, apply_resource_limits=True,
inner_template=inner_template,
outer_template=outer_template)

cpu_limit = memory_limit = storage_limit = None
if apply_resource_limits:
# Fetch configured resource limits.
cpu_limit = self.build_conf.get_cpu_limit()
memory_limit = self.build_conf.get_memory_limit()
storage_limit = self.build_conf.get_storage_limit()
# Always set resources_limits, even if values are None.
# This ensures that BuildConfig is overwritten properly.
build_request.set_resource_limits(cpu=cpu_limit,
memory=memory_limit,
storage=storage_limit)
# Apply configured resource limits.
cpu_limit = self.build_conf.get_cpu_limit()
memory_limit = self.build_conf.get_memory_limit()
storage_limit = self.build_conf.get_storage_limit()
if (cpu_limit is not None or
memory_limit is not None or
storage_limit is not None):
build_request.set_resource_limits(cpu=cpu_limit,
memory=memory_limit,
storage=storage_limit)

return build_request

Expand Down Expand Up @@ -402,7 +400,6 @@ def create_prod_build(self, git_uri, git_ref,
filesystem_koji_task_id=None,
scratch=None,
platform=None,
apply_resource_limits=True,
inner_template=None,
outer_template=None,
**kwargs):
Expand All @@ -421,16 +418,14 @@ def create_prod_build(self, git_uri, git_ref,
:param filesystem_koji_task_id: int, koji task for base image filesystem
:param scratch: bool, this is a scratch build
:param platform: str, the platform name
:param apply_resource_limits: bool, whether or not to set resource limits
:param inner_template: str, name of inner template for BuildRequest
:param outer_template: str, name of outer template for BuildRequest
:return: BuildResponse instance
"""

df_parser = utils.get_df_parser(git_uri, git_ref, git_branch=git_branch)
build_request = self.get_build_request(inner_template=inner_template,
outer_template=outer_template,
apply_resource_limits=apply_resource_limits)
outer_template=outer_template)
labels = utils.Labels(df_parser.labels)

try:
Expand Down Expand Up @@ -533,7 +528,6 @@ def create_worker_build(self, *args, **kwargs):
- platform param is required
- inner template set to worker_inner.json if not set
- outer template set to worker.json if not set
- apply_resource_limits set to False if not set
:return: BuildResponse instance
"""
Expand All @@ -542,7 +536,6 @@ def create_worker_build(self, *args, **kwargs):

kwargs.setdefault('inner_template', WORKER_INNER_TEMPLATE)
kwargs.setdefault('outer_template', WORKER_OUTER_TEMPLATE)
kwargs.setdefault('apply_resource_limits', False)

return self.create_prod_build(*args, **kwargs)

Expand Down
39 changes: 15 additions & 24 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,15 @@ class MockParser(object):
.with_args(TEST_GIT_URI, TEST_GIT_REF, git_branch=TEST_GIT_BRANCH)
.and_return(MockParser()))

apply_resource_limits = False
(flexmock(osbs)
.should_call('get_build_request')
.with_args(inner_template=inner_template,
outer_template=outer_template,
apply_resource_limits=apply_resource_limits)
)
outer_template=outer_template)
.once())
response = osbs.create_prod_build(TEST_GIT_URI, TEST_GIT_REF,
TEST_GIT_BRANCH, TEST_USER,
inner_template=inner_template,
outer_template=outer_template,
apply_resource_limits=apply_resource_limits,
)
outer_template=outer_template,)
assert isinstance(response, BuildResponse)

@pytest.mark.parametrize(('inner_template', 'outer_template'), (
Expand Down Expand Up @@ -181,10 +177,8 @@ class MockParser(object):
'platform': platform,
'inner_template': WORKER_INNER_TEMPLATE,
'outer_template': WORKER_OUTER_TEMPLATE,
'apply_resource_limits': False,
}

apply_resource_limits = False
(flexmock(osbs)
.should_call('create_prod_build')
.with_args(*args, **expected_kwargs)
Expand Down Expand Up @@ -385,15 +379,14 @@ def test_get_build_request_api_build_type(self, osbs, build_type):
build = osbs.get_build_request()
assert isinstance(build, BuildRequest)

@pytest.mark.parametrize(('cpu', 'memory', 'storage'), (
(None, None, None),
('spam', None, None),
(None, 'spam', None),
(None, None, 'spam'),
('spam', 'spam', 'spam'),
@pytest.mark.parametrize(('cpu', 'memory', 'storage', 'set_resource'), (
(None, None, None, False),
('spam', None, None, True),
(None, 'spam', None, True),
(None, None, 'spam', True),
('spam', 'spam', 'spam', True),
))
@pytest.mark.parametrize('apply_resource_limits', (None, True, False))
def test_get_build_request_api(self, osbs, cpu, memory, storage, apply_resource_limits):
def test_get_build_request_api(self, osbs, cpu, memory, storage, set_resource):
inner_template = 'inner.json'
outer_template = 'outer.json'
build_json_store = 'build/json/store'
Expand All @@ -405,22 +398,20 @@ def test_get_build_request_api(self, osbs, cpu, memory, storage, apply_resource_
flexmock(osbs.os_conf).should_receive('get_build_json_store').and_return(build_json_store)

set_resource_limits_kwargs = {
'cpu': cpu if apply_resource_limits is not False else None,
'memory': memory if apply_resource_limits is not False else None,
'storage': storage if apply_resource_limits is not False else None,
'cpu': cpu,
'memory': memory,
'storage': storage,
}

(flexmock(BuildRequest)
.should_receive('set_resource_limits')
.with_args(**set_resource_limits_kwargs)
.once()
)
.times(1 if set_resource else 0))

get_build_request_kwargs = {
'inner_template': inner_template,
'outer_template': outer_template,
}
if apply_resource_limits is not None:
get_build_request_kwargs['apply_resource_limits'] = apply_resource_limits
osbs.get_build_request(**get_build_request_kwargs)

def test_create_build_from_buildrequest(self, osbs):
Expand Down

0 comments on commit 9150f8b

Please sign in to comment.