示例#1
0
    def publish_artifacts(self, stack, artifacts=None):
        """Make and publish all the artifacts for a single stack"""
        stack.find_missing_build_env()

        if artifacts is None:
            artifacts = stack.artifacts.items()

        # Iterate over each artifact we need to build
        for key, artifact in artifacts:
            # Skip artifacts that are created elsewhere
            if artifact.not_created_here:
                continue

            # Gather our environment variables
            environment = dict(env.pair for env in stack.build_env)

            # Create a temporary file to tar to
            with hp.a_temp_file() as temp_tar_file:
                # Make the artifact
                hp.generate_tar_file(temp_tar_file,
                                     artifact.commands + artifact.paths +
                                     artifact.files,
                                     environment=environment,
                                     compression=artifact.compression_type)
                log.info("Finished generating artifact: {0}".format(key))

                # Upload the artifact
                s3_location = artifact.upload_to.format(**environment)
                if stack.bespin.dry_run:
                    log.info("DRYRUN: Would upload tar file to %s",
                             s3_location)
                else:
                    stack.s3.upload_file_to_s3(temp_tar_file.name, s3_location)
示例#2
0
    def publish_artifacts(self, stack, artifacts=None):
        """Make and publish all the artifacts for a single stack"""
        stack.find_missing_build_env()

        if artifacts is None:
            artifacts = stack.artifacts.items()

        # Iterate over each artifact we need to build
        for key, artifact in artifacts:
            # Skip artifacts that are created elsewhere
            if artifact.not_created_here:
                continue

            # Gather our environment variables
            environment = dict(env.pair for env in stack.build_env)

            # Create a temporary file to tar to
            with hp.a_temp_file() as temp_tar_file:
                # Make the artifact
                hp.generate_tar_file(temp_tar_file, artifact.commands + artifact.paths + artifact.files
                    , environment=environment
                    , compression=artifact.compression_type
                    )
                log.info("Finished generating artifact: {0}".format(key))

                # Upload the artifact
                s3_location = artifact.upload_to.format(**environment)
                if stack.bespin.dry_run:
                    log.info("DRYRUN: Would upload tar file to %s", s3_location)
                else:
                    stack.s3.upload_file_to_s3(temp_tar_file.name, s3_location)
示例#3
0
            for _ in until(step=step):
                if done.count(1) == 5:
                    done.append("break")
                    break
                else:
                    done.append(1)

        self.assertEqual(done, [1, "sleep", 1, "sleep", 1, "sleep", 1, "sleep", 1, "sleep", "break"])
        self.assertEqual(fake_time.sleep.mock_calls, [mock.call(step), mock.call(step), mock.call(step), mock.call(step), mock.call(step)])

describe BespinCase, "generate_tar_file":
    it "Creates an empty file when paths and files is empty":
        if six.PY2 and sys.version_info[1] == 6:
            raise nose.SkipTest()
        with a_temp_file() as temp_tar_file:
            generate_tar_file(temp_tar_file, [])
            tar = tarfile.open(temp_tar_file.name)

            self.assertEqual(len(tar.getnames()), 0)

    it "Creates a file with the files and directories given a path to process":
        with a_temp_file() as temp_tar_file:
            root, folders = self.setup_directory({"one": {"two": "blah", "three": {"four": ""}}})
            path1 = ArtifactPath(root, "/app")
            generate_tar_file(temp_tar_file, [path1])
            tar = tarfile.open(temp_tar_file.name, "r")

            self.assertEqual(len(tar.getnames()), 2)
            self.assertTarFileContent(temp_tar_file.name, {"app/one/two": "blah", "app/one/three/four": ""})

    it "Creates a file with the files given a file list to add":