Esempio n. 1
0
 def test_run_config_command_with_image_build(self):
     cmd = ConfigCommand(
         commandline=["echo", "1"],
         container_opts={
             "image": {
                 "dockerfile": "Dockerfile",
                 "context": os.getcwd()
             }
         },
     )
     cmd.container_opts = utils.inherit_container_opts(
         cmd.container_opts, ContainerOpts())
     flexmock(command).should_receive("run_command").with_args([
         "docker",
         "build",
         os.getcwd(),
         "-t",
         "apigentools-test-java-v1",
         "-f",
         "Dockerfile",
     ])
     flexmock(command).should_receive(
         "run_command").with_args(self.EXPECTED_DOCKER_INVOCATION +
                                  ["echo", "apigentools-test-java-v1", "1"])
     MyCommand(None, None).run_config_command(cmd, "java-v1", ".", {}, {},
                                              {})
Esempio n. 2
0
 def postprocess(self):
     self.container_opts = inherit_container_opts(
         self.container_opts,
         ContainerOpts(image=constants.DEFAULT_CONTAINER_IMAGE))
     for lname, lconfig in self.languages.items():
         lconfig.postprocess(self, lname)
     return self
Esempio n. 3
0
 def test_run_config_command(self, cmd, cwd, vars, functions, env_override,
                             docker_run_options, call):
     # make sure container_opts are fully populated
     cmd.container_opts = utils.inherit_container_opts(
         cmd.container_opts, ContainerOpts())
     flexmock(command).should_receive("run_command").with_args(
         call[0], **call[1])
     MyCommand(None, None).run_config_command(
         cmd,
         "testing",
         cwd,
         vars,
         functions,
         env_override,
         docker_run_options=docker_run_options,
     )
Esempio n. 4
0
    def postprocess(self, parent, lname):
        # https://github.com/samuelcolvin/pydantic/issues/655#issuecomment-570312649
        object.__setattr__(self, "language", lname)
        object.__setattr__(self, "user_agent_client_name",
                           parent.user_agent_client_name)

        # This goes through all spec versions defined for the language; if spec sections
        # for a spec version aren't defined in language's spec_sections, they're taken
        # from the top-level spec_sections
        if self.spec_versions is None:
            self.spec_versions = copy.deepcopy(parent.spec_versions)
        if self.spec_sections is None:
            self.spec_sections = copy.deepcopy(parent.spec_sections)
        if self.validation_commands is None:
            self.validation_commands = copy.deepcopy(
                parent.validation_commands)

        for sv in self.spec_versions:
            if sv not in parent.spec_versions:
                raise AttributeError(
                    "{} version not found in top-level versions".format(sv))
            if sv not in self.spec_sections:
                self.spec_sections[sv] = copy.deepcopy(
                    parent.spec_sections.get(sv, []))

        self.container_opts = inherit_container_opts(self.container_opts,
                                                     parent.container_opts)

        for version in self.spec_versions:
            version_generation = self.generation.get(version)
            if version_generation is None:
                version_generation = copy.deepcopy(
                    self.generation.get("default"))
                self.generation[version] = version_generation
            if version_generation:
                version_generation.postprocess(self, version,
                                               self.generation.get("default"))

        # postprocess default section last, because the other sections use it
        # and we don't want the container_opts to be expanded in commands
        # for example, for command defined in "default" generation, we want it to inherit:
        # * container_opts from "v1" when running for "v1" and "v1" has container_opts defined
        # * container_opts from "default" when running for "v2" and "v2" doesn't have container_opts defined
        if "default" in self.generation:
            self.generation["default"].postprocess(self, "default", None)
Esempio n. 5
0
    def postprocess(self, parent, vname, default_generation=None):
        if self.commands is None:
            self.commands = (copy.deepcopy(default_generation.commands)
                             if default_generation
                             and default_generation.commands else [])
        if self.tests is None:
            self.tests = (copy.deepcopy(default_generation.tests)
                          if default_generation and default_generation.tests
                          else [])
        if self.templates is None:
            self.templates = (copy.deepcopy(default_generation.templates)
                              if default_generation
                              and default_generation.templates else [])
        if self.validation_commands is None:
            self.validation_commands = (
                copy.deepcopy(default_generation.validation_commands) if
                default_generation and default_generation.validation_commands
                else None  # ensure that the condition below works correctly
            )
            # it's also allowed to specify validation_commands on language level
            if self.validation_commands is None:
                self.validation_commands = copy.deepcopy(
                    parent.validation_commands)

        if default_generation is not None:
            if self.container_opts is None:
                self.container_opts = copy.deepcopy(
                    default_generation.container_opts)
        self.container_opts = inherit_container_opts(self.container_opts,
                                                     parent.container_opts)

        for c in self.commands:
            c.postprocess(self)
        for t in self.tests:
            t.postprocess(self)
        for v in self.validation_commands:
            v.postprocess(self)
Esempio n. 6
0
 def postprocess(self, parent):
     self.container_opts = inherit_container_opts(self.container_opts,
                                                  parent.container_opts)