| Index: appengine/swarming/server/task_request_test.py
|
| diff --git a/appengine/swarming/server/task_request_test.py b/appengine/swarming/server/task_request_test.py
|
| index a8581b01c148df2980e2886cfb233a0b57267db0..e9e462eea9d8ff03d1af776079efd0c3642f8b03 100755
|
| --- a/appengine/swarming/server/task_request_test.py
|
| +++ b/appengine/swarming/server/task_request_test.py
|
| @@ -5,7 +5,6 @@
|
|
|
| import datetime
|
| import logging
|
| -import os
|
| import random
|
| import sys
|
| import unittest
|
| @@ -18,6 +17,7 @@ from google.appengine.ext import ndb
|
|
|
| from components import auth_testing
|
| from components import utils
|
| +from proto import config_pb2
|
| from test_support import test_case
|
|
|
| from server import task_pack
|
| @@ -27,7 +27,11 @@ from server import task_request
|
| # pylint: disable=W0212
|
|
|
|
|
| -PINNED_PACKAGE_VERSION = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef'
|
| +CIPD_SETTINGS = config_pb2.CipdSettings(
|
| + server_host='chrome-infra-packages.appspot.com',
|
| + client_package_name='infra/tools/cipd/${platform}',
|
| + client_package_version='git_revision:deadbeef')
|
| +PINNED_PACKAGE_VERSION = 'git_revision:deadbeef'
|
|
|
|
|
| def mkreq(req):
|
| @@ -37,17 +41,30 @@ def mkreq(req):
|
| def _gen_request(properties=None, **kwargs):
|
| """Creates a TaskRequest."""
|
| properties = properties or {}
|
| - packages = properties.pop('packages', [{
|
| - 'package_name': 'rm',
|
| - 'version': PINNED_PACKAGE_VERSION,
|
| - }])
|
| +
|
| + def merge(override, defaults):
|
| + if override is None:
|
| + return None
|
| + result = defaults.copy()
|
| + result.update(override)
|
| + return result
|
| +
|
| + cipd_input = merge(properties.pop('cipd_input', {}), {
|
| + 'settings': CIPD_SETTINGS.SerializeToString(),
|
| + 'packages': [{
|
| + 'package_name': 'rm',
|
| + 'version': PINNED_PACKAGE_VERSION,
|
| + }]
|
| + })
|
| +
|
| inputs_ref = properties.pop('inputs_ref', {
|
| 'isolatedserver': 'https://isolateserver.appspot.com',
|
| 'namespace': 'default-gzip',
|
| })
|
| - props = {
|
| +
|
| + properties = merge(properties, {
|
| + 'cipd_input': cipd_input,
|
| 'command': [u'command1', u'arg1'],
|
| - 'packages': [task_request.CipdPackage(**p) for p in packages],
|
| 'dimensions': {
|
| u'OS': u'Windows-3.1.1',
|
| u'hostname': u'localhost',
|
| @@ -59,19 +76,19 @@ def _gen_request(properties=None, **kwargs):
|
| 'idempotent': False,
|
| 'inputs_ref': inputs_ref,
|
| 'io_timeout_secs': None,
|
| - }
|
| - props.update(properties)
|
| + })
|
| now = utils.utcnow()
|
| args = {
|
| 'created_ts': now,
|
| 'name': 'Request name',
|
| 'priority': 50,
|
| - 'properties': task_request.TaskProperties(**props),
|
| + 'properties': properties,
|
| 'expiration_ts': now + datetime.timedelta(seconds=30),
|
| 'tags': [u'tag:1'],
|
| 'user': 'Jesus',
|
| }
|
| args.update(kwargs)
|
| + # Note that ndb model constructor accepts dicts for structured properties.
|
| return task_request.TaskRequest(**args)
|
|
|
|
|
| @@ -200,6 +217,10 @@ class TaskRequestApiTest(TestCase):
|
| r = _gen_request(properties=dict(idempotent=True), parent_task_id=parent_id)
|
| request = mkreq(r)
|
| expected_properties = {
|
| + 'cipd_input': {
|
| + 'settings': CIPD_SETTINGS.SerializeToString(),
|
| + 'packages': [{'package_name': 'rm', 'version': PINNED_PACKAGE_VERSION}],
|
| + },
|
| 'command': [u'command1', u'arg1'],
|
| 'dimensions': {
|
| u'OS': u'Windows-3.1.1',
|
| @@ -217,7 +238,6 @@ class TaskRequestApiTest(TestCase):
|
| 'namespace': 'default-gzip',
|
| },
|
| 'io_timeout_secs': None,
|
| - 'packages': [{'package_name': 'rm', 'version': PINNED_PACKAGE_VERSION}],
|
| }
|
| expected_request = {
|
| 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY,
|
| @@ -227,7 +247,7 @@ class TaskRequestApiTest(TestCase):
|
| 'properties': expected_properties,
|
| # Intentionally hard code the hash value since it has to be deterministic.
|
| # Other unit tests should use the calculated value.
|
| - 'properties_hash': 'c3e067b4e232be5478e7147bb1f0506477444014',
|
| + 'properties_hash': '2559848c0be0921d34b2f2085a6fb599efc9a8c9',
|
| 'pubsub_topic': None,
|
| 'pubsub_userdata': None,
|
| 'tags': [
|
| @@ -260,6 +280,10 @@ class TaskRequestApiTest(TestCase):
|
| request = mkreq(_gen_request(
|
| properties={'idempotent':True}, parent_task_id=parent_id))
|
| expected_properties = {
|
| + 'cipd_input': {
|
| + 'packages': [{'package_name': 'rm', 'version': PINNED_PACKAGE_VERSION}],
|
| + 'settings': CIPD_SETTINGS.SerializeToString(),
|
| + },
|
| 'command': [u'command1', u'arg1'],
|
| 'dimensions': {
|
| u'OS': u'Windows-3.1.1',
|
| @@ -277,7 +301,6 @@ class TaskRequestApiTest(TestCase):
|
| 'namespace': 'default-gzip',
|
| },
|
| 'io_timeout_secs': None,
|
| - 'packages': [{'package_name': 'rm', 'version': PINNED_PACKAGE_VERSION}],
|
| }
|
| expected_request = {
|
| 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY,
|
| @@ -287,7 +310,7 @@ class TaskRequestApiTest(TestCase):
|
| 'properties': expected_properties,
|
| # Intentionally hard code the hash value since it has to be deterministic.
|
| # Other unit tests should use the calculated value.
|
| - 'properties_hash': 'c3e067b4e232be5478e7147bb1f0506477444014',
|
| + 'properties_hash': '2559848c0be0921d34b2f2085a6fb599efc9a8c9',
|
| 'pubsub_topic': None,
|
| 'pubsub_userdata': None,
|
| 'tags': [
|
| @@ -327,7 +350,7 @@ class TaskRequestApiTest(TestCase):
|
| # Other unit tests should use the calculated value.
|
| # Ensure the algorithm is deterministic.
|
| self.assertEqual(
|
| - 'c3e067b4e232be5478e7147bb1f0506477444014', as_dict['properties_hash'])
|
| + '2559848c0be0921d34b2f2085a6fb599efc9a8c9', as_dict['properties_hash'])
|
|
|
| def test_duped(self):
|
| # Two TestRequest with the same properties.
|
| @@ -374,25 +397,29 @@ class TaskRequestApiTest(TestCase):
|
| mkreq(_gen_request(properties=dict(command=['python'])))
|
| mkreq(_gen_request(properties=dict(command=[u'python'])))
|
|
|
| + def mkcipdreq(idempotent=False, **cipd_input):
|
| + mkreq(_gen_request(
|
| + properties=dict(idempotent=idempotent, cipd_input=cipd_input)))
|
| +
|
| with self.assertRaises(datastore_errors.BadValueError):
|
| - mkreq(_gen_request(properties=dict(packages=[{}])))
|
| + mkcipdreq(packages=[{}])
|
| with self.assertRaises(datastore_errors.BadValueError):
|
| - mkreq(_gen_request(properties=dict(packages=[dict(package_name='rm')])))
|
| + mkcipdreq(packages=[dict(package_name='rm')])
|
| with self.assertRaises(datastore_errors.BadValueError):
|
| - mkreq(_gen_request(properties=dict(
|
| - packages=[{'package_name': 'infra|rm', 'version': 'latest'}])))
|
| + mkcipdreq(packages=[{'package_name': 'infra|rm', 'version': 'latest'}])
|
| with self.assertRaises(datastore_errors.BadValueError):
|
| - mkreq(_gen_request(properties=dict(
|
| - packages=[
|
| - {'package_name': 'rm', 'version': 'latest'},
|
| - {'package_name': 'rm', 'version': 'canary'},
|
| - ])))
|
| + mkcipdreq(packages=[
|
| + {'package_name': 'rm', 'version': 'latest'},
|
| + {'package_name': 'rm', 'version': 'canary'},
|
| + ])
|
| with self.assertRaises(datastore_errors.BadValueError):
|
| - mkreq(_gen_request(properties=dict(
|
| - idempotent=True,
|
| - packages=[{'package_name': 'rm', 'version': 'latest'}])))
|
| - mkreq(_gen_request(properties=dict(
|
| - packages=[{'package_name': 'rm', 'version': 'latest'}])))
|
| + mkcipdreq(
|
| + idempotent=True,
|
| + packages=[{'package_name': 'rm', 'version': 'latest'}])
|
| + with self.assertRaises(datastore_errors.BadValueError):
|
| + mkcipdreq(settings='blablah_invalid_protobuf')
|
| + mkcipdreq()
|
| + mkcipdreq(packages=[{'package_name': 'rm', 'version': 'latest'}])
|
|
|
| with self.assertRaises(TypeError):
|
| mkreq(_gen_request(properties=dict(dimensions=[])))
|
| @@ -478,6 +505,10 @@ class TaskRequestApiTest(TestCase):
|
| # - idempotent was reset to False.
|
| # - parent_task_id was reset to None.
|
| expected_properties = {
|
| + 'cipd_input': {
|
| + 'settings': CIPD_SETTINGS.SerializeToString(),
|
| + 'packages': [{'package_name': 'rm', 'version': PINNED_PACKAGE_VERSION}],
|
| + },
|
| 'command': [u'command1', u'arg1'],
|
| 'dimensions': {
|
| u'OS': u'Windows-3.1.1',
|
| @@ -495,7 +526,6 @@ class TaskRequestApiTest(TestCase):
|
| 'namespace': 'default-gzip',
|
| },
|
| 'io_timeout_secs': None,
|
| - 'packages': [{'package_name': 'rm', 'version': PINNED_PACKAGE_VERSION}],
|
| }
|
| # Differences from make_request() are:
|
| # - parent_task_id was reset to None.
|
|
|