Exemplo n.º 1
0
    def test_task_template_update_env_prefix(self):
        tti = pools_config.TaskTemplate._Intermediate(self.ctx,
                                                      pools_pb2.TaskTemplate())
        tti.update(self.ctx,
                   self.tt(env=[self.PE(var='PATH', prefix=['1'], soft=True)]),
                   None)

        self.assertEqual(
            self.tt(env=[self.PE(var='PATH', prefix=['1'], soft=True)]),
            tti.finalize(self.ctx))

        # append existing
        tti.update(self.ctx, self.tt(env=[self.PE(var='PATH', prefix=['2'])]),
                   None)

        self.assertEqual(self.tt(env=[self.PE(var='PATH', prefix=['1', '2'])]),
                         tti.finalize(self.ctx))

        # existing, add new
        tti.update(self.ctx,
                   self.tt(env=[self.PE(var='OTHER', prefix=['thing'])]), None)

        self.assertEqual(
            self.tt(env=[
                self.PE(var='OTHER', prefix=['thing']),
                self.PE(var='PATH', prefix=['1', '2']),
            ]), tti.finalize(self.ctx))
Exemplo n.º 2
0
    def test_task_template_update_env(self):
        tti = pools_config.TaskTemplate._Intermediate(self.ctx,
                                                      pools_pb2.TaskTemplate())
        tti.update(self.ctx,
                   self.tt(env=[self.PE(var='VAR', value='1', soft=True)]),
                   None)

        self.assertEqual(
            self.tt(env=[self.PE(var='VAR', value='1', soft=True)]),
            tti.finalize(self.ctx))

        # override existing
        tti.update(self.ctx, self.tt(env=[self.PE(var='VAR', value='2')]),
                   None)

        self.assertEqual(self.tt(env=[self.PE(var='VAR', value='2')]),
                         tti.finalize(self.ctx))

        # add new
        tti.update(self.ctx,
                   self.tt(env=[self.PE(var='OTHER', value='thing')]), None)

        self.assertEqual(
            self.tt(env=[
                self.PE(var='OTHER', value='thing'),
                self.PE(var='VAR', value='2'),
            ]),
            tti.finalize(self.ctx),
        )
Exemplo n.º 3
0
    def test_task_template_update_cache(self):
        tti = pools_config.TaskTemplate._Intermediate(self.ctx,
                                                      pools_pb2.TaskTemplate())
        tti.update(self.ctx,
                   self.tt(cache=[self.PCE(name='hi', path='there')]), None)

        self.assertEqual(self.tt(cache=[self.PCE(name='hi', path='there')]),
                         tti.finalize(self.ctx))

        # override existing
        tti.update(self.ctx, self.tt(cache=[self.PCE(name='hi', path='nerd')]),
                   None)

        self.assertEqual(self.tt(cache=[self.PCE(name='hi', path='nerd')]),
                         tti.finalize(self.ctx))

        # add new
        tti.update(self.ctx,
                   self.tt(cache=[self.PCE(name='other', path='yep')]), None)

        self.assertEqual(
            self.tt(cache=[
                self.PCE(name='hi', path='nerd'),
                self.PCE(name='other', path='yep'),
            ]), tti.finalize(self.ctx))
Exemplo n.º 4
0
    def from_pb(cls, ctx, t, resolve_func=lambda _: None):
        """This returns a TaskTemplate from `t` and `resolve_func`.

    Args:
      ctx (validation.Context) - The validation context.
      t (pools_pb2.TaskTemplate) - The proto TaskTemplate message to convert.
      resolve_func (func(include_name) -> TaskTemplate) - A function which,
        given `include_name` returns the resolved TaskTemplate object.
          If the resolved TaskTemplate has errors, it should return None.
          If an include cycle was detected, it should return TaskTemplate.CYCLE.
          If the include_name is not resolvable, it should raise KeyError.
        As a convenience, resolve_func may also be a dict, and an appropriate
        resolution function will be generated for it (dict.__getitem__).

    Returns a TaskTemplate object (this class), None if there were errors. If
    any of the included object results in a CYCLE, this returns CYCLE.
    """
        assert isinstance(t, pools_pb2.TaskTemplate)
        if isinstance(resolve_func, dict):
            resolve_func = resolve_func.__getitem__

        tmp = cls._Intermediate(ctx, pools_pb2.TaskTemplate())

        found_cycle = False
        for include in t.include:
            try:
                resolved = resolve_func(include)
                if isinstance(resolved, TaskTemplate):
                    tmp.update(ctx, resolved, include)
                elif resolved is None:
                    ctx.error('depends on %r, which has errors', include)
                elif resolved is cls.CYCLE:
                    found_cycle = True
                    ctx.error('depends on %r, which causes an import cycle',
                              include)
                else:
                    assert False, ('resolve_func returned a bad type: %s: %r' %
                                   (type(resolved), resolved))
            except KeyError:
                ctx.error('unknown include: %r', include)

        tmp.update(ctx, cls._Intermediate(ctx, t).finalize(ctx), None)

        # Evaluate this here so that ctx can contain all errors before returning.
        ret = tmp.finalize(ctx)

        if found_cycle:
            return cls.CYCLE
        return None if ctx.result().has_errors else ret
Exemplo n.º 5
0
    def test_task_template_update_cipd_package(self):
        tti = pools_config.TaskTemplate._Intermediate(self.ctx,
                                                      pools_pb2.TaskTemplate())
        tti.update(
            self.ctx,
            self.tt(cipd_package=[
                self.PCP(path='path', pkg='some/pkg', version='latest')
            ]), None)

        self.assertEqual(
            self.tt(cipd_package=[
                self.PCP(path='path', pkg='some/pkg', version='latest')
            ]),
            tti.finalize(self.ctx),
        )

        # override existing
        tti.update(
            self.ctx,
            self.tt(cipd_package=[
                self.PCP(path='path', pkg='some/pkg', version='oldest')
            ]), None)

        self.assertEqual(
            self.tt(cipd_package=[
                self.PCP(path='path', pkg='some/pkg', version='oldest')
            ]),
            tti.finalize(self.ctx),
        )

        # add new
        tti.update(
            self.ctx,
            self.tt(cipd_package=[
                self.PCP(path='other_path', pkg='some/pkg', version='1'),
            ]), None)

        self.assertEqual(
            self.tt(cipd_package=[
                self.PCP(path='other_path', pkg='some/pkg', version='1'),
                self.PCP(path='path', pkg='some/pkg', version='oldest'),
            ]),
            tti.finalize(self.ctx),
        )
Exemplo n.º 6
0
 def parse(textpb):
     return text_format.Merge(textpb, pools_pb2.TaskTemplate())