コード例 #1
0
def test_remove_dockerfile_content():
    plugins_json = {
        'prebuild_plugins': [
            {
                'name': 'before',
            },
            {
                'name': PLUGIN_DOCKERFILE_CONTENT_KEY,
            },
            {
                'name': 'after',
            },
        ]
    }

    mock_env = {
        'BUILD': '{}',
        'SOURCE_URI': 'https://github.com/foo/bar.git',
        'SOURCE_REF': 'master',
        'OUTPUT_IMAGE': 'asdf:fdsa',
        'OUTPUT_REGISTRY': 'localhost:5000',
        'ATOMIC_REACTOR_PLUGINS': json.dumps(plugins_json),
    }
    flexmock(os, environ=mock_env)

    plugin = OSv3InputPlugin()
    assert plugin.run()['prebuild_plugins'] == [
        {
            'name': 'before',
        },
        {
            'name': 'after',
        },
    ]
コード例 #2
0
def test_validate_reactor_config_override(override, valid, buildtype):
    plugins_json = {
        'postbuild_plugins': [],
    }

    user_params = {
        'build_json_dir': 'inputs',
        'build_type': buildtype,
        'git_ref': 'test',
        'git_uri': 'test',
        'user': '******',
        'reactor_config_map': REACTOR_CONFIG_MAP,
    }
    if override:
        user_params['reactor_config_override'] = override
    mock_env = {
        'BUILD': '{}',
        'SOURCE_URI': 'https://github.com/foo/bar.git',
        'SOURCE_REF': 'master',
        'OUTPUT_IMAGE': 'asdf:fdsa',
        'OUTPUT_REGISTRY': 'localhost:5000',
        'REACTOR_CONFIG': REACTOR_CONFIG_MAP,
        'USER_PARAMS': json.dumps(user_params)
    }

    enable_plugins_configuration(plugins_json)

    flexmock(os, environ=mock_env)

    plugin = OSv3InputPlugin()
    if valid:
        plugin.run()
    else:
        with pytest.raises(ValidationError):
            plugin.run()
コード例 #3
0
def test_plugins_variable(plugins_variable, valid):
    plugins_json = {
        'postbuild_plugins': [],
    }

    mock_env = {
        'BUILD': '{}',
        'SOURCE_URI': 'https://github.com/foo/bar.git',
        'SOURCE_REF': 'master',
        'OUTPUT_IMAGE': 'asdf:fdsa',
        'OUTPUT_REGISTRY': 'localhost:5000',
        plugins_variable: json.dumps(plugins_json),
    }

    if plugins_variable == 'USER_PARAMS':
        mock_env['REACTOR_CONFIG'] = REACTOR_CONFIG_MAP
        enable_plugins_configuration(plugins_json)
        mock_env.update({
            plugins_variable: json.dumps({
                'build_json_dir': 'inputs',
                'build_type': 'orchestrator',
                'git_ref': 'test',
                'git_uri': 'test',
                'user': '******'
            }),
        })

    flexmock(os, environ=mock_env)

    plugin = OSv3InputPlugin()
    if valid:
        assert plugin.run()['postbuild_plugins'] is not None
    else:
        with pytest.raises(RuntimeError):
            plugin.run()
コード例 #4
0
    def test_remove_everything(self):
        plugins_json = {
            'build_json_dir': 'inputs',
            'build_type': 'orchestrator',
            'git_ref': 'test',
            'git_uri': 'test',
            'user': '******',
            'prebuild_plugins': [
                {'name': 'before', },
                {'name': PLUGIN_BUMP_RELEASE_KEY, },
                {'name': PLUGIN_KOJI_DELEGATE_KEY, },
                {'name': PLUGIN_FETCH_MAVEN_KEY, },
                {'name': PLUGIN_DISTGIT_FETCH_KEY, },
                {'name': PLUGIN_INJECT_PARENT_IMAGE_KEY, },
                {'name': PLUGIN_KOJI_PARENT_KEY, },
                {'name': PLUGIN_RESOLVE_COMPOSES_KEY, },
                {'name': 'after', },
            ],
            'postbuild_plugins': [
                {'name': 'before', },
                {'name': PLUGIN_KOJI_UPLOAD_PLUGIN_KEY, },
                {'name': 'after', },
            ],
            'exit_plugins': [
                {'name': 'before', },
                {'name': PLUGIN_KOJI_IMPORT_PLUGIN_KEY, },
                {'name': PLUGIN_KOJI_PROMOTE_PLUGIN_KEY, },
                {'name': PLUGIN_KOJI_TAG_BUILD_KEY, },
                {'name': PLUGIN_SENDMAIL_KEY, },
                {'name': 'after', },
            ]
        }
        minimal_config = dedent("""\
            version: 1
            koji:
                hub_url: ''
                root_url: ''
                auth: {}
        """)

        mock_env = {
            'BUILD': '{}',
            'SOURCE_URI': 'https://github.com/foo/bar.git',
            'SOURCE_REF': 'master',
            'OUTPUT_IMAGE': 'asdf:fdsa',
            'OUTPUT_REGISTRY': 'localhost:5000',
            'USER_PARAMS': json.dumps(plugins_json),
            'REACTOR_CONFIG': minimal_config
        }
        flexmock(os, environ=mock_env)
        enable_plugins_configuration(plugins_json)

        plugin = OSv3InputPlugin()
        plugins = plugin.run()
        for phase in ('prebuild_plugins', 'postbuild_plugins', 'exit_plugins'):
            assert plugins[phase] == [
                {'name': 'before', },
                {'name': 'after', },
            ]
コード例 #5
0
def test_remove_v1_pulp_and_exit_delete():
    plugins_json = {
        'build_json_dir': 'inputs',
        'build_type': 'orchestrator',
        'git_ref': 'test',
        'git_uri': 'test',
        'user': '******',
        'postbuild_plugins': [
            {'name': 'before', },
            {'name': PLUGIN_PULP_PUSH_KEY, },
            {'name': 'after', },
        ],
        'exit_plugins': [
            {'name': 'before', },
            {'name': PLUGIN_DELETE_FROM_REG_KEY, },
            {'name': 'after', },
        ],
    }
    minimal_config = dedent("""\
        version: 1
        pulp:
            name: my-pulp
            auth:
                password: testpasswd
                username: testuser
        content_versions:
        - v2
        registries:
        - url: https://container-registry.example.com/v2
        auth:
            cfg_path: /var/run/secrets/atomic-reactor/v2-registry-dockercfg
        source_registry:
            url: https://container-registry.example.com/v2
            insecure: True
    """)

    mock_env = {
        'BUILD': '{}',
        'SOURCE_URI': 'https://github.com/foo/bar.git',
        'SOURCE_REF': 'master',
        'OUTPUT_IMAGE': 'asdf:fdsa',
        'OUTPUT_REGISTRY': 'localhost:5000',
        'USER_PARAMS': json.dumps(plugins_json),
        'REACTOR_CONFIG': minimal_config
    }
    flexmock(os, environ=mock_env)
    enable_plugins_configuration(plugins_json)

    plugin = OSv3InputPlugin()
    plugins = plugin.run()
    for phase in ('postbuild_plugins', 'exit_plugins'):
        assert plugins[phase] == [
            {'name': 'before', },
            {'name': 'after', },
        ]
コード例 #6
0
def test_sets_selflink(build, expected):
    mock_env = {
        'BUILD': build,
        'SOURCE_URI': 'https://github.com/foo/bar.git',
        'SOURCE_REF': 'master',
        'OUTPUT_IMAGE': 'asdf:fdsa',
        'OUTPUT_REGISTRY': 'localhost:5000',
        'ATOMIC_REACTOR_PLUGINS': '{}',
    }
    flexmock(os, environ=mock_env)

    plugin = OSv3InputPlugin()
    assert plugin.run()['openshift_build_selflink'] == expected
コード例 #7
0
def test_doesnt_fail_if_no_plugins():
    mock_env = {
        'BUILD': '{}',
        'SOURCE_URI': 'https://github.com/foo/bar.git',
        'SOURCE_REF': 'master',
        'OUTPUT_IMAGE': 'asdf:fdsa',
        'OUTPUT_REGISTRY': 'localhost:5000',
        'ATOMIC_REACTOR_PLUGINS': '{}',
    }
    flexmock(os, environ=mock_env)

    plugin = OSv3InputPlugin()
    assert plugin.run()['prebuild_plugins'] == [{'name': 'pull_base_image'}]
コード例 #8
0
    def test_does_fail_if_no_plugins(self):
        mock_env = {
            'BUILD': '{}',
            'SOURCE_URI': 'https://github.com/foo/bar.git',
            'SOURCE_REF': 'master',
            'OUTPUT_IMAGE': 'asdf:fdsa',
            'OUTPUT_REGISTRY': 'localhost:5000',
        }
        flexmock(os, environ=mock_env)

        plugin = OSv3InputPlugin()
        with pytest.raises(RuntimeError) as exc:
            plugin.run()
        assert 'No plugin configuration found!' in str(exc.value)
コード例 #9
0
def test_invalid_v1_registry():
    plugins_json = {
        'build_json_dir': 'inputs',
        'build_type': 'orchestrator',
        'git_ref': 'test',
        'git_uri': 'test',
        'user': '******',
        'postbuild_plugins': [
            {'name': 'before', },
            {'name': PLUGIN_PULP_SYNC_KEY, },
            {'name': 'after', },
        ],
        'exit_plugins': [
            {'name': 'before', },
            {'name': PLUGIN_DELETE_FROM_REG_KEY, },
            {'name': 'after', },
        ],
    }
    # v1 registry URL is no longer supported
    minimal_config = dedent("""\
        version: 1
        pulp:
            name: my-pulp
            auth:
                password: testpasswd
                username: testuser
        registries:
        - url: https://container-registry.example.com/v1
        auth:
            cfg_path: /var/run/secrets/atomic-reactor/v1-registry-dockercfg
    """)

    mock_env = {
        'BUILD': '{}',
        'SOURCE_URI': 'https://github.com/foo/bar.git',
        'SOURCE_REF': 'master',
        'OUTPUT_IMAGE': 'asdf:fdsa',
        'OUTPUT_REGISTRY': 'localhost:5000',
        'USER_PARAMS': json.dumps(plugins_json),
        'REACTOR_CONFIG': minimal_config
    }
    flexmock(os, environ=mock_env)
    enable_plugins_configuration(plugins_json)

    plugin = OSv3InputPlugin()
    with pytest.raises(OsbsValidationException):
        plugin.run()
コード例 #10
0
def test_postbuild_plugins_rewrite(output_registry, postbuild_json, expected_json):
    plugins_json = {
        'postbuild_plugins': postbuild_json,
    }

    mock_env = {
        'BUILD': '{}',
        'SOURCE_URI': 'https://github.com/foo/bar.git',
        'SOURCE_REF': 'master',
        'OUTPUT_IMAGE': 'asdf:fdsa',
        'OUTPUT_REGISTRY': output_registry,
        'ATOMIC_REACTOR_PLUGINS': json.dumps(plugins_json),
    }
    flexmock(os, environ=mock_env)

    plugin = OSv3InputPlugin()
    assert plugin.run()['postbuild_plugins'] == expected_json
コード例 #11
0
def test_plugins_variable(plugins_variable):
    plugins_json = {
        'postbuild_plugins': [],
    }

    mock_env = {
        'BUILD': '{}',
        'SOURCE_URI': 'https://github.com/foo/bar.git',
        'SOURCE_REF': 'master',
        'OUTPUT_IMAGE': 'asdf:fdsa',
        'OUTPUT_REGISTRY': 'localhost:5000',
        plugins_variable: json.dumps(plugins_json),
    }
    flexmock(os, environ=mock_env)

    plugin = OSv3InputPlugin()
    assert plugin.run()['postbuild_plugins'] is not None
コード例 #12
0
def test_fails_on_invalid_plugin_request(plugins_type):
    # no name plugin request
    plugins_json = {plugins_type: [{'args': {}}, {'name': 'foobar'}]},

    mock_env = {
        'BUILD': '{}',
        'SOURCE_URI': 'https://github.com/foo/bar.git',
        'SOURCE_REF': 'master',
        'OUTPUT_IMAGE': 'asdf:fdsa',
        'OUTPUT_REGISTRY': 'localhost:5000',
        'ATOMIC_REACTOR_PLUGINS': json.dumps(plugins_json),
    }
    flexmock(os, environ=mock_env)

    plugin = OSv3InputPlugin()
    with pytest.raises(ValidationError):
        plugin.run()
コード例 #13
0
def test_prebuild_plugins_rewrite(prebuild_json, expected_json):
    plugins_json = {
        'prebuild_plugins': prebuild_json,
    }

    mock_env = {
        'BUILD': '"UNUSED"',
        'SOURCE_URI': 'https://github.com/foo/bar.git',
        'SOURCE_REF': 'master',
        'OUTPUT_IMAGE': 'asdf:fdsa',
        'OUTPUT_REGISTRY': 'localhost:5000',
        'DOCK_PLUGINS': json.dumps(plugins_json),
    }
    flexmock(os, environ=mock_env)

    plugin = OSv3InputPlugin()
    assert plugin.run()['prebuild_plugins'] == expected_json
コード例 #14
0
def test_remove_v2_pulp():
    plugins_json = {
        'build_json_dir':
        'inputs',
        'build_type':
        'orchestrator',
        'git_ref':
        'test',
        'git_uri':
        'test',
        'user':
        '******',
        'postbuild_plugins': [
            {
                'name': 'before',
            },
            {
                'name': 'pulp_sync',
            },
            {
                'name': 'after',
            },
        ],
        'exit_plugins': [
            {
                'name': 'before',
            },
            {
                'name': 'delete_from_registry',
            },
            {
                'name': 'after',
            },
        ],
    }
    minimal_config = dedent("""\
        version: 1
        pulp:
            name: my-pulp
            auth:
                password: testpasswd
                username: testuser
        registries:
        - url: https://container-registry.example.com/v1
        auth:
            cfg_path: /var/run/secrets/atomic-reactor/v1-registry-dockercfg
    """)

    mock_env = {
        'BUILD': '{}',
        'SOURCE_URI': 'https://github.com/foo/bar.git',
        'SOURCE_REF': 'master',
        'OUTPUT_IMAGE': 'asdf:fdsa',
        'OUTPUT_REGISTRY': 'localhost:5000',
        'USER_PARAMS': json.dumps(plugins_json),
        'REACTOR_CONFIG': minimal_config
    }
    flexmock(os, environ=mock_env)
    enable_plugins_configuration(plugins_json)

    plugin = OSv3InputPlugin()
    plugins = plugin.run()
    assert plugins['postbuild_plugins'] == [
        {
            'name': 'before',
        },
        {
            'name': 'after',
        },
    ]
コード例 #15
0
def test_remove_everything():
    plugins_json = {
        'build_json_dir':
        'inputs',
        'build_type':
        'orchestrator',
        'git_ref':
        'test',
        'git_uri':
        'test',
        'user':
        '******',
        'prebuild_plugins': [
            {
                'name': 'before',
            },
            {
                'name': 'bump_release',
            },
            {
                'name': 'fetch_maven_artifacts',
            },
            {
                'name': 'distgit_fetch_artefacts',
            },
            {
                'name': 'dockerfile_content',
            },
            {
                'name': 'inject_parent_image',
            },
            {
                'name': 'koji_parent',
            },
            {
                'name': 'resolve_composes',
            },
            {
                'name': 'after',
            },
        ],
        'postbuild_plugins': [
            {
                'name': 'before',
            },
            {
                'name': 'koji_upload',
            },
            {
                'name': 'pulp_pull',
            },
            {
                'name': 'pulp_push',
            },
            {
                'name': 'pulp_sync',
            },
            {
                'name': 'pulp_tag',
            },
            {
                'name': 'after',
            },
        ],
        'exit_plugins': [
            {
                'name': 'before',
            },
            {
                'name': 'delete_from_registry',
            },
            {
                'name': 'koji_import',
            },
            {
                'name': 'koji_promote',
            },
            {
                'name': 'koji_tag_build',
            },
            {
                'name': 'pulp_publish',
            },
            {
                'name': 'pulp_pull',
            },
            {
                'name': 'sendmail',
            },
            {
                'name': 'after',
            },
        ]
    }
    minimal_config = dedent("""\
        version: 1
    """)

    mock_env = {
        'BUILD': '{}',
        'SOURCE_URI': 'https://github.com/foo/bar.git',
        'SOURCE_REF': 'master',
        'OUTPUT_IMAGE': 'asdf:fdsa',
        'OUTPUT_REGISTRY': 'localhost:5000',
        'USER_PARAMS': json.dumps(plugins_json),
        'REACTOR_CONFIG': minimal_config
    }
    flexmock(os, environ=mock_env)
    enable_plugins_configuration(plugins_json)

    plugin = OSv3InputPlugin()
    plugins = plugin.run()
    for phase in ('prebuild_plugins', 'postbuild_plugins', 'exit_plugins'):
        assert plugins[phase] == [
            {
                'name': 'before',
            },
            {
                'name': 'after',
            },
        ]