Commit 85b6d185 authored by Robert Iannucci's avatar Robert Iannucci Committed by Commit Bot

[recipe_modules/cipd] Refactor creation methods.

This clarifies what the 'create' method actually expects,
and adds a nicer approach for recipes that want to synthesize
their own package definition files.

BUG=

Change-Id: Iee5d5c02260bf71d4775ddfc1d4d1ae43937b693
Reviewed-on: https://chromium-review.googlesource.com/440385
Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: 's avatarVadim Shtayura <vadimsh@chromium.org>
parent 96dc085d
This diff is collapsed.
...@@ -302,8 +302,14 @@ ...@@ -302,8 +302,14 @@
], ],
"name": "create fake-package.yaml", "name": "create fake-package.yaml",
"~followup_annotations": [ "~followup_annotations": [
"@@@STEP_LOG_LINE@json.output (invalid)@null@@@", "@@@STEP_TEXT@</br>pkg: fake-package.yaml</br>id: 40-chars-fake-of-the-package-instance_id@@@",
"@@@STEP_LOG_END@json.output (invalid)@@@" "@@@STEP_LOG_LINE@json.output@{@@@",
"@@@STEP_LOG_LINE@json.output@ \"result\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"instance_id\": \"40-chars-fake-of-the-package-instance_id\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"package\": \"fake-package.yaml\"@@@",
"@@@STEP_LOG_LINE@json.output@ }@@@",
"@@@STEP_LOG_LINE@json.output@}@@@",
"@@@STEP_LOG_END@json.output@@@"
] ]
}, },
{ {
......
This diff is collapsed.
...@@ -302,8 +302,14 @@ ...@@ -302,8 +302,14 @@
], ],
"name": "create fake-package.yaml", "name": "create fake-package.yaml",
"~followup_annotations": [ "~followup_annotations": [
"@@@STEP_LOG_LINE@json.output (invalid)@null@@@", "@@@STEP_TEXT@</br>pkg: fake-package.yaml</br>id: 40-chars-fake-of-the-package-instance_id@@@",
"@@@STEP_LOG_END@json.output (invalid)@@@" "@@@STEP_LOG_LINE@json.output@{@@@",
"@@@STEP_LOG_LINE@json.output@ \"result\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"instance_id\": \"40-chars-fake-of-the-package-instance_id\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"package\": \"fake-package.yaml\"@@@",
"@@@STEP_LOG_LINE@json.output@ }@@@",
"@@@STEP_LOG_LINE@json.output@}@@@",
"@@@STEP_LOG_END@json.output@@@"
] ]
}, },
{ {
......
...@@ -302,8 +302,14 @@ ...@@ -302,8 +302,14 @@
], ],
"name": "create fake-package.yaml", "name": "create fake-package.yaml",
"~followup_annotations": [ "~followup_annotations": [
"@@@STEP_LOG_LINE@json.output (invalid)@null@@@", "@@@STEP_TEXT@</br>pkg: fake-package.yaml</br>id: 40-chars-fake-of-the-package-instance_id@@@",
"@@@STEP_LOG_END@json.output (invalid)@@@" "@@@STEP_LOG_LINE@json.output@{@@@",
"@@@STEP_LOG_LINE@json.output@ \"result\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"instance_id\": \"40-chars-fake-of-the-package-instance_id\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"package\": \"fake-package.yaml\"@@@",
"@@@STEP_LOG_LINE@json.output@ }@@@",
"@@@STEP_LOG_LINE@json.output@}@@@",
"@@@STEP_LOG_END@json.output@@@"
] ]
}, },
{ {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
[ [
{ {
"cmd": [ "cmd": [
"cipd", "cipd.bat",
"ensure", "ensure",
"-root", "-root",
"[START_DIR]\\packages", "[START_DIR]\\packages",
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
}, },
{ {
"cmd": [ "cmd": [
"cipd", "cipd.bat",
"search", "search",
"public/package/windows-amd64", "public/package/windows-amd64",
"-tag", "-tag",
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
}, },
{ {
"cmd": [ "cmd": [
"cipd", "cipd.bat",
"describe", "describe",
"public/package/windows-amd64", "public/package/windows-amd64",
"-version", "-version",
...@@ -103,7 +103,7 @@ ...@@ -103,7 +103,7 @@
}, },
{ {
"cmd": [ "cmd": [
"cipd", "cipd.bat",
"ensure", "ensure",
"-root", "-root",
"[START_DIR]\\packages", "[START_DIR]\\packages",
...@@ -133,7 +133,7 @@ ...@@ -133,7 +133,7 @@
}, },
{ {
"cmd": [ "cmd": [
"cipd", "cipd.bat",
"search", "search",
"private/package/windows-amd64", "private/package/windows-amd64",
"-tag", "-tag",
...@@ -158,7 +158,7 @@ ...@@ -158,7 +158,7 @@
}, },
{ {
"cmd": [ "cmd": [
"cipd", "cipd.bat",
"describe", "describe",
"private/package/windows-amd64", "private/package/windows-amd64",
"-version", "-version",
...@@ -204,7 +204,7 @@ ...@@ -204,7 +204,7 @@
}, },
{ {
"cmd": [ "cmd": [
"cipd", "cipd.bat",
"pkg-build", "pkg-build",
"-in", "-in",
"fake-input-dir", "fake-input-dir",
...@@ -228,7 +228,7 @@ ...@@ -228,7 +228,7 @@
}, },
{ {
"cmd": [ "cmd": [
"cipd", "cipd.bat",
"pkg-build", "pkg-build",
"-in", "-in",
"fake-input-dir", "fake-input-dir",
...@@ -254,7 +254,7 @@ ...@@ -254,7 +254,7 @@
}, },
{ {
"cmd": [ "cmd": [
"cipd", "cipd.bat",
"pkg-register", "pkg-register",
"fake-package-path", "fake-package-path",
"-json-output", "-json-output",
...@@ -283,7 +283,7 @@ ...@@ -283,7 +283,7 @@
}, },
{ {
"cmd": [ "cmd": [
"cipd", "cipd.bat",
"create", "create",
"-pkg-def", "-pkg-def",
"[START_DIR]\\fake-package.yaml", "[START_DIR]\\fake-package.yaml",
...@@ -302,13 +302,19 @@ ...@@ -302,13 +302,19 @@
], ],
"name": "create fake-package.yaml", "name": "create fake-package.yaml",
"~followup_annotations": [ "~followup_annotations": [
"@@@STEP_LOG_LINE@json.output (invalid)@null@@@", "@@@STEP_TEXT@</br>pkg: fake-package.yaml</br>id: 40-chars-fake-of-the-package-instance_id@@@",
"@@@STEP_LOG_END@json.output (invalid)@@@" "@@@STEP_LOG_LINE@json.output@{@@@",
"@@@STEP_LOG_LINE@json.output@ \"result\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"instance_id\": \"40-chars-fake-of-the-package-instance_id\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"package\": \"fake-package.yaml\"@@@",
"@@@STEP_LOG_LINE@json.output@ }@@@",
"@@@STEP_LOG_LINE@json.output@}@@@",
"@@@STEP_LOG_END@json.output@@@"
] ]
}, },
{ {
"cmd": [ "cmd": [
"cipd", "cipd.bat",
"set-tag", "set-tag",
"fake-package", "fake-package",
"-version", "-version",
...@@ -338,7 +344,7 @@ ...@@ -338,7 +344,7 @@
}, },
{ {
"cmd": [ "cmd": [
"cipd", "cipd.bat",
"set-ref", "set-ref",
"fake-package", "fake-package",
"-version", "-version",
...@@ -368,7 +374,7 @@ ...@@ -368,7 +374,7 @@
}, },
{ {
"cmd": [ "cmd": [
"cipd", "cipd.bat",
"search", "search",
"fake-package/windows-amd64", "fake-package/windows-amd64",
"-tag", "-tag",
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
from recipe_engine.config import List, Single, ConfigList, ConfigGroup
from recipe_engine.recipe_api import Property
DEPS = [ DEPS = [
'recipe_engine/path', 'recipe_engine/path',
'recipe_engine/platform', 'recipe_engine/platform',
...@@ -10,7 +13,18 @@ DEPS = [ ...@@ -10,7 +13,18 @@ DEPS = [
'cipd', 'cipd',
] ]
def RunSteps(api): PROPERTIES = {
'use_pkg': Property(default=False, kind=bool),
'pkg_files': Property(default=(), kind=List(str)),
'pkg_dirs': Property(default=(), kind=ConfigList(lambda: ConfigGroup(
path=Single(str),
exclusions=List(str),
))),
'ver_files': Property(default=(), kind=List(str)),
'install_mode': Property(default=None),
}
def RunSteps(api, use_pkg, pkg_files, pkg_dirs, ver_files, install_mode):
# Need to set service account credentials. # Need to set service account credentials.
api.cipd.set_service_account_credentials( api.cipd.set_service_account_credentials(
api.cipd.default_bot_service_account_credentials) api.cipd.default_bot_service_account_credentials)
...@@ -49,10 +63,27 @@ def RunSteps(api): ...@@ -49,10 +63,27 @@ def RunSteps(api):
'fake_tag_2': 'fake_value_2'}) 'fake_tag_2': 'fake_value_2'})
# Create (build & register). # Create (build & register).
api.cipd.create(api.path['start_dir'].join('fake-package.yaml'), if use_pkg:
refs=['fake-ref-1', 'fake-ref-2'], root = api.path['start_dir'].join('some_subdir')
tags={'fake_tag_1': 'fake_value_1', pkg = api.cipd.PackageDefinition('infra/fake-package', root, install_mode)
'fake_tag_2': 'fake_value_2'}) for fullpath in pkg_files:
pkg.add_file(api.path.abs_to_path(fullpath))
for obj in pkg_dirs:
pkg.add_dir(api.path.abs_to_path(obj.get('path', '')),
obj.get('exclusions'))
for pth in ver_files:
pkg.add_version_file(pth)
api.cipd.create_from_pkg(pkg,
refs=['fake-ref-1', 'fake-ref-2'],
tags={'fake_tag_1': 'fake_value_1',
'fake_tag_2': 'fake_value_2'})
else:
api.cipd.create_from_yaml(api.path['start_dir'].join('fake-package.yaml'),
refs=['fake-ref-1', 'fake-ref-2'],
tags={'fake_tag_1': 'fake_value_1',
'fake_tag_2': 'fake_value_2'})
# Set tag or ref of an already existing package. # Set tag or ref of an already existing package.
api.cipd.set_tag('fake-package', api.cipd.set_tag('fake-package',
...@@ -67,39 +98,89 @@ def RunSteps(api): ...@@ -67,39 +98,89 @@ def RunSteps(api):
def GenTests(api): def GenTests(api):
yield ( yield (
# This is very common dev workstation, but not all devs are on it. # This is very common dev workstation, but not all devs are on it.
api.test('basic') + api.test('basic')
api.platform('linux', 64) + api.platform('linux', 64)
) )
yield ( yield (
api.test('mac64') + api.test('mac64')
api.platform('mac', 64) + api.platform('mac', 64)
) )
yield ( yield (
api.test('win64') + api.test('win64')
api.platform('win', 64) + api.platform('win', 64)
) )
yield ( yield (
api.test('describe-failed') + api.test('describe-failed')
api.platform('linux', 64) + + api.platform('linux', 64)
api.override_step_data( + api.override_step_data(
'cipd describe public/package/linux-amd64', 'cipd describe public/package/linux-amd64',
api.cipd.example_error( api.cipd.example_error(
'package "public/package/linux-amd64-ubuntu14_04" not registered', 'package "public/package/linux-amd64-ubuntu14_04" not registered',
) ))
)
) )
yield ( yield (
api.test('describe-many-instances') + api.test('describe-many-instances')
api.platform('linux', 64) + + api.platform('linux', 64)
api.override_step_data( + api.override_step_data(
'cipd search fake-package/linux-amd64 dead:beaf', 'cipd search fake-package/linux-amd64 dead:beaf',
api.cipd.example_search( api.cipd.example_search(
'public/package/linux-amd64-ubuntu14_04', 'public/package/linux-amd64-ubuntu14_04',
instances=3 instances=3
) ))
)
yield (
api.test('basic_pkg')
+ api.properties(
use_pkg=True,
pkg_files=[
'[START_DIR]/some_subdir/a/path/to/file.py',
'[START_DIR]/some_subdir/some_config.cfg',
],
pkg_dirs=[
{
'path': '[START_DIR]/some_subdir/directory',
},
{
'path': '[START_DIR]/some_subdir/other_dir',
'exclusions': [
r'.*\.pyc',
]
},
],
ver_file=['.versions/file.cipd_version'],
)
)
yield (
api.test('pkg_bad_verfile')
+ api.properties(
use_pkg=True,
ver_files=['a', 'b'],
)
+ api.expect_exception('ValueError')
)
yield (
api.test('pkg_bad_mode')
+ api.properties(
use_pkg=True,
install_mode='',
)
+ api.expect_exception('ValueError')
)
yield (
api.test('pkg_bad_file')
+ api.properties(
use_pkg=True,
pkg_files=[
'[START_DIR]/a/path/to/file.py',
],
) )
+ api.expect_exception('ValueError')
) )
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment