Skip to content

Commit

Permalink
Test more plugins in arrangements
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Waugh <twaugh@redhat.com>
  • Loading branch information
twaugh committed Jul 13, 2017
1 parent fbe9afc commit 0cdf081
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 49 deletions.
101 changes: 69 additions & 32 deletions tests/build_/test_arrangements.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
TEST_COMPONENT,
TEST_VERSION,
TEST_FILESYSTEM_KOJI_TASK_ID)
from tests.fake_api import openshift, osbs # noqa:F401
from tests.fake_api import openshift, osbs, osbs_with_pulp # noqa:F401
from tests.test_api import request_as_response
from tests.build_.test_build_request import (get_plugins_from_build_json,
get_plugin,
Expand Down Expand Up @@ -80,23 +80,28 @@ def test_orchestrator_running_order(self, osbs, template):

assert actual == self.DEFAULT_PLUGINS[template]

def get_orchestrator_build_request(self, osbs, # noqa:F811
additional_params=None):
def get_build_request(self, build_type, osbs, additional_params=None):
self.mock_env(base_image=additional_params.get('base_image'))
params = self.COMMON_PARAMS.copy()
params.update(self.ORCHESTRATOR_ADD_PARAMS)
assert build_type in ('orchestrator', 'worker')
if build_type == 'orchestrator':
params.update(self.ORCHESTRATOR_ADD_PARAMS)
fn = osbs.create_orchestrator_build
elif build_type == 'worker':
params.update(self.WORKER_ADD_PARAMS)
fn = osbs.create_worker_build

params.update(additional_params or {})
params['arrangement_version'] = self.ARRANGEMENT_VERSION
return params, osbs.create_orchestrator_build(**params).json
return params, fn(**params).json

def get_orchestrator_build_request(self, osbs, # noqa:F811
additional_params=None):
return self.get_build_request('orchestrator', osbs, additional_params)

def get_worker_build_request(self, osbs, # noqa:F811
additional_params=None):
self.mock_env(base_image=additional_params.get('base_image'))
params = self.COMMON_PARAMS.copy()
params.update(self.WORKER_ADD_PARAMS)
params.update(additional_params or {})
params['arrangement_version'] = self.ARRANGEMENT_VERSION
return params, osbs.create_worker_build(**params).json
return self.get_build_request('worker', osbs, additional_params)

def assert_plugin_not_present(self, build_json, phase, name):
plugins = get_plugins_from_build_json(build_json)
Expand Down Expand Up @@ -195,38 +200,72 @@ class TestArrangementV1(ArrangementBase):
],

'exit_plugins': [
'delete_from_registry',
'koji_promote',
'store_metadata_in_osv3',
'koji_tag_build',
'sendmail',
'remove_built_image',
'delete_from_registry', # not tested
'koji_promote', # not tested
'store_metadata_in_osv3', # not tested
'koji_tag_build', # not tested
'sendmail', # not tested
'remove_built_image', # not tested
],
},
}

@pytest.mark.parametrize('base_image', [ # noqa:F811
'koji/image-build',
'foo',
@pytest.mark.parametrize('build_type', [ # noqa:F811
'orchestrator',
'worker',
])
@pytest.mark.parametrize('scratch', [False, True])
def test_add_filesystem_in_orchestrator(self, osbs, scratch, base_image):
"""
Orchestrator builds should not run add_filesystem
"""
@pytest.mark.parametrize('base_image, expect_plugin', [
('koji/image-build', False),
('foo', True),
])
def test_pull_base_image(self, osbs, build_type, scratch,
base_image, expect_plugin):
phase = 'prebuild_plugins'
plugin = 'pull_base_image'
additional_params = {
'base_image': base_image,
'yum_repourls': ['https://example.com/my.repo'],
}
if scratch:
additional_params['scratch'] = True

(_, build_json) = self.get_orchestrator_build_request(osbs,
additional_params)
(params, build_json) = self.get_build_request(build_type,
osbs,
additional_params)
plugins = get_plugins_from_build_json(build_json)

if not expect_plugin:
with pytest.raises(NoSuchPluginException):
get_plugin(plugins, phase, plugin)
else:
args = plugin_value_get(plugins, phase, plugin, 'args')

self.assert_plugin_not_present(build_json,
'prebuild_plugins',
'add_filesystem')
allowed_args = set([
'parent_registry',
'parent_registry_insecure',
])
assert set(args.keys()) <= allowed_args

@pytest.mark.parametrize('scratch', [False, True])
@pytest.mark.parametrize('base_image', ['koji/image-build', 'foo'])
def test_delete_from_registry(self, osbs_with_pulp, base_image, scratch):
phase = 'exit_plugins'
plugin = 'delete_from_registry'
additional_params = {
'base_image': base_image,
}
if scratch:
additional_params['scratch'] = True

(params, build_json) = self.get_build_request('worker',
osbs_with_pulp,
additional_params)
plugins = get_plugins_from_build_json(build_json)
args = plugin_value_get(plugins, phase, plugin, 'args')
allowed_args = set([
'registries',
])
assert set(args.keys()) <= allowed_args

@pytest.mark.parametrize('scratch', [False, True]) # noqa:F811
@pytest.mark.parametrize('base_image, expect_plugin', [
Expand Down Expand Up @@ -260,8 +299,6 @@ def test_add_filesystem_in_worker(self, osbs, base_image, scratch,
assert 'koji_hub' in args
assert args['repos'] == params['yum_repourls']

# ...


class TestArrangementV2(TestArrangementV1):
"""
Expand Down
49 changes: 32 additions & 17 deletions tests/fake_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
TEST_GIT_URI_HUMAN_NAME, TEST_KOJI_TASK_ID,
TEST_FILESYSTEM_KOJI_TASK_ID, TEST_IMAGESTREAM)
from tempfile import NamedTemporaryFile
from textwrap import dedent

try:
# py2
Expand Down Expand Up @@ -340,24 +341,29 @@ def openshift(request):


@pytest.fixture
def osbs(openshift):
def osbs(openshift, additional_config=None):
with NamedTemporaryFile(mode="wt") as fp:
fp.write("""
[general]
build_json_dir = {build_json_dir}
[default]
openshift_url = /
registry_uri = registry.example.com
sources_command = fedpkg sources
vendor = Example, Inc.
build_host = localhost
authoritative_registry = registry.example.com
distribution_scope = authoritative-source-only
koji_root = http://koji.example.com/kojiroot
koji_hub = http://koji.example.com/kojihub
use_auth = false
can_orchestrate = true
""".format(build_json_dir="inputs"))
config = dedent("""\
[general]
build_json_dir = {build_json_dir}
[default]
openshift_url = /
registry_uri = registry.example.com
sources_command = fedpkg sources
vendor = Example, Inc.
build_host = localhost
authoritative_registry = registry.example.com
distribution_scope = authoritative-source-only
koji_root = http://koji.example.com/kojiroot
koji_hub = http://koji.example.com/kojihub
use_auth = false
can_orchestrate = true""")

if additional_config is not None:
config += '\n'
config += additional_config

fp.write(config.format(build_json_dir="inputs"))
fp.flush()
dummy_config = Configuration(fp.name)
osbs = OSBS(dummy_config, dummy_config)
Expand All @@ -366,6 +372,15 @@ def osbs(openshift):
return osbs


@pytest.fixture
def osbs_with_pulp(openshift):
additional_config = dedent("""\
pulp_registry_name = pulp
pulp_secret = secret
registry_uri = registry.example.com/v2""")
return osbs(openshift, additional_config=additional_config)


@pytest.fixture
def osbs_cant_orchestrate(openshift):
with NamedTemporaryFile(mode="wt") as fp:
Expand Down

0 comments on commit 0cdf081

Please sign in to comment.