diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..bb9c811 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog +All notable changes to this project will be documented in this file. +This project adheres to [Semantic Versioning](http://semver.org/). + +## [1.0.0] - 2017-12-14 +### Added +- Changelog +- Support for processing release manifest from beetmover + +### Fixed +- fixed some logging diff --git a/balrogscript/script.py b/balrogscript/script.py index 75ad647..39a6f35 100644 --- a/balrogscript/script.py +++ b/balrogscript/script.py @@ -16,14 +16,35 @@ def create_submitter(e, balrog_auth, config): - from balrog.submitter.cli import NightlySubmitterV4 # noqa: E402 + from balrog.submitter.cli import NightlySubmitterV4, ReleaseSubmitterV4 # noqa: E402 auth = balrog_auth if "tc_release" in e: - raise NotImplementedError("This logic piece has yet to be implemented") + log.info("Taskcluster Release style Balrog submission") + + complete_info = e['completeInfo'] + partial_info = e.get('partialInfo') + submitter = ReleaseSubmitterV4(api_root=config['api_root'], auth=auth, + dummy=config['dummy']) + + data = { + 'platform': e['platform'], + 'productName': e['appName'], + 'appVersion': e['appVersion'], + 'version': e['version'], + 'build_number': e['build_number'], + 'locale': e['locale'], + 'hashFunction': e['hashType'], + 'extVersion': e['extVersion'], + 'buildID': e['buildid'], + 'completeInfo': complete_info + } + if partial_info: + data['partialInfo'] = partial_info + return submitter, data elif "tc_nightly" in e: - log.info("Taskcluster Nightly Fennec style Balrog submission") + log.info("Taskcluster Nightly style Balrog submission") complete_info = e['completeInfo'] partial_info = e.get('partialInfo') diff --git a/balrogscript/test/__init__.py b/balrogscript/test/__init__.py index e69de29..5b7789f 100644 --- a/balrogscript/test/__init__.py +++ b/balrogscript/test/__init__.py @@ -0,0 +1,65 @@ +import json +import os +import pytest +import shutil +import tempfile + + +# constants, helpers, and fixtures {{{1 +NIGHTLY_MANIFEST_PATH = os.path.join(os.path.dirname(__file__), "data", "nightly_manifest.json") +NIGHTLY_TASK_PATH = os.path.join(os.path.dirname(__file__), "data", "nightly_task.json") + + +@pytest.fixture(scope='function') +def nightly_manifest(): + with open(NIGHTLY_MANIFEST_PATH, "r") as fh: + return json.load(fh) + + +@pytest.yield_fixture(scope='function') +def config(): + tmpdir = tempfile.mkdtemp() + try: + yield { + "work_dir": os.path.join(tmpdir, "work_dir"), + "artifact_dir": os.path.join(tmpdir, "artifact_dir"), + "schema_file": "balrogscript/data/balrog_task_schema.json", + "dummy": False, + "api_root": "BALROG_API_ROOT", + "server_config": { + "nightly": { + "balrog_username": "BALROG_USERNAME", + "balrog_password": "BALROG_PASSWORD", + "allowed_channels": ["nightly"] + }, + "release": { + "balrog_username": "BALROG_USERNAME", + "balrog_password": "BALROG_PASSWORD", + "allowed_channels": ["release", "release-localtest", "release-cdntest"] + }, + "dep": { + "balrog_username": "BALROG_USERNAME", + "balrog_password": "BALROG_PASSWORD", + "allowed_channels": ["nightly", "release", "beta", "etc"] + }, + + }, + "disable_certs": False, + "verbose": True + } + finally: + shutil.rmtree(tmpdir) + + +@pytest.yield_fixture(scope='function') +def nightly_config(config): + os.makedirs(os.path.join(config['work_dir'], "upstream-task-id", "public")) + shutil.copyfile( + NIGHTLY_MANIFEST_PATH, + os.path.join(config['work_dir'], "upstream-task-id", "public", "manifest.json") + ) + shutil.copyfile( + NIGHTLY_TASK_PATH, + os.path.join(config['work_dir'], "task.json") + ) + yield config diff --git a/balrogscript/test/test_script.py b/balrogscript/test/test_script.py index bebb1c0..c49cf14 100644 --- a/balrogscript/test/test_script.py +++ b/balrogscript/test/test_script.py @@ -1,13 +1,12 @@ # -*- coding: utf-8 -*- -import json import logging import pytest import os -import shutil import sys -import tempfile import balrogscript.script as balrogscript + +from balrogscript.test import (nightly_manifest, config, nightly_config) from balrogscript.task import (get_task, validate_task_schema, get_task_server) sys.path.insert(0, os.path.join( @@ -17,53 +16,9 @@ logging.basicConfig() -# constants, helpers, and fixtures {{{1 -NIGHTLY_MANIFEST_PATH = os.path.join(os.path.dirname(__file__), "data", "nightly_manifest.json") -NIGHTLY_TASK_PATH = os.path.join(os.path.dirname(__file__), "data", "nightly_task.json") - - -@pytest.fixture(scope='function') -def nightly_manifest(): - with open(NIGHTLY_MANIFEST_PATH, "r") as fh: - return json.load(fh) - - -@pytest.yield_fixture(scope='function') -def config(): - tmpdir = tempfile.mkdtemp() - try: - yield { - "work_dir": os.path.join(tmpdir, "work_dir"), - "artifact_dir": os.path.join(tmpdir, "artifact_dir"), - "schema_file": "balrogscript/data/balrog_task_schema.json", - "dummy": False, - "api_root": "BALROG_API_ROOT", - "server_config": { - "nightly": { - "balrog_username": "BALROG_USERNAME", - "balrog_password": "BALROG_PASSWORD", - "allowed_channels": ["nightly"] - }, - }, - "disable_certs": False, - "verbose": True - } - finally: - shutil.rmtree(tmpdir) - - -@pytest.yield_fixture(scope='function') -def nightly_config(config): - os.makedirs(os.path.join(config['work_dir'], "upstream-task-id", "public")) - shutil.copyfile( - NIGHTLY_MANIFEST_PATH, - os.path.join(config['work_dir'], "upstream-task-id", "public", "manifest.json") - ) - shutil.copyfile( - NIGHTLY_TASK_PATH, - os.path.join(config['work_dir'], "task.json") - ) - yield config +assert nightly_config # silence pyflakes +assert config # silence pyflakes +assert nightly_manifest # silence pyflakes # get_task {{{1 diff --git a/balrogscript/test/test_task.py b/balrogscript/test/test_task.py new file mode 100644 index 0000000..13e871b --- /dev/null +++ b/balrogscript/test/test_task.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +import pytest + +from balrogscript.test import config, nightly_config +from balrogscript.task import (get_task, get_task_channel, get_task_server, + get_upstream_artifacts) + +assert nightly_config # silence pyflakes +assert config # silence pyflakes + + +def test_get_task_channel(nightly_config): + task = get_task(nightly_config) + with pytest.raises(NotImplementedError): + get_task_channel(task, nightly_config) + + +@pytest.mark.parametrize("scopes,expected,raises", (( + ["project:releng:balrog:server:dep", "project:releng:balrog:server:release"], + None, True, +), ( + ["project:releng:balrog:server:!!"], + None, True +), ( + ["project:releng:balrog:server:foo", "project:releng:balrog:action:foo"], + None, True +), ( + ["project:releng:balrog:server:dep", "project:releng:balrog:action:foo"], + "dep", False +))) +def test_get_task_server(nightly_config, scopes, expected, raises): + task = get_task(nightly_config) + task['scopes'] = scopes + + if raises: + with pytest.raises(ValueError): + get_task_server(task, nightly_config) + else: + assert expected == get_task_server(task, nightly_config) + + +@pytest.mark.parametrize("expected", ([ + [{ + u'paths': [u'public/manifest.json'], + u'taskId': u'upstream-task-id', + u'taskType': u'baz' + }] +])) +def test_get_upstream_artifacts(nightly_config, expected): + task = get_task(nightly_config) + assert get_upstream_artifacts(task) == expected diff --git a/version.json b/version.json index f25fe32..b40f563 100644 --- a/version.json +++ b/version.json @@ -1,8 +1,8 @@ { "version": [ - 0, 1, - 1 + 0, + 0 ], - "version_string": "0.1.1" + "version_string": "1.0.0" }