Пример #1
0
  def test_determine_most_common_prefix(self):
    options = self.options
    builder = BomBuilder(options, self.scm)
    self.assertIsNone(builder.determine_most_common_prefix())

    prefix = ['http://github.com/one', '/local/source/path/two']

    # Test two vs one in from different repo prefix
    # run the test twice changing the ordering the desired prefix is visible.
    for which in [0, 1]:
      repository = GitRepositorySpec(
          'RepoOne', origin=prefix[0] + '/RepoOne',
          commit_id='RepoOneCommit')
      summary = RepositorySummary('RepoOneCommit', 'RepoOneTag',
                                  '1.2.3', '1.2.2', [])
      source_info = SourceInfo('BuildOne', summary)
      builder.add_repository(repository, source_info)
      self.assertEquals(prefix[0], builder.determine_most_common_prefix())

      repository = GitRepositorySpec(
          'RepoTwo', origin=prefix[which] + '/RepoTwo',
          commit_id='RepoTwoCommit')
      summary = RepositorySummary('RepoTwoCommit', 'RepoTwoTag',
                                  '2.2.3', '2.2.3', [])
      source_info = SourceInfo('BuildTwo', summary)
      builder.add_repository(repository, source_info)

      repository = GitRepositorySpec(
          'RepoThree', origin=prefix[1] + '/RepoThree',
          commit_id='RepoThreeCommit')
      summary = RepositorySummary('RepoThreeCommit', 'RepoThreeTag',
                                  '3.2.0', '2.2.1', [])
      source_info = SourceInfo('BuildThree', summary)
      builder.add_repository(repository, source_info)
      self.assertEquals(prefix[which], builder.determine_most_common_prefix())
Пример #2
0
 def test_patchable_false(self):
   tests = [('1.3.0', '1.2.0'),
            ('1.3.0', '1.2.1'),
            ('1.3.1', '1.2.0')]
   for test in tests:
     summary = RepositorySummary('abcd', 'tag-123', test[0], test[1], [])
     self.assertFalse(summary.patchable)
Пример #3
0
 def test_patchable_true(self):
   tests = [('1.2.3', '1.2.2'),
            ('1.2.1', '1.2.0'),
            ('1.2.10', '1.2.9')]
   for test in tests:
     summary = RepositorySummary('abcd', 'tag-123', test[0], test[1], [])
     self.assertTrue(summary.patchable)
Пример #4
0
  def test_to_yaml(self):
    summary = RepositorySummary(
        'abcd1234', 'mytag-987', '0.0.1', '0.0.0',
        [CommitMessage('commit-abc', 'author', 'date', 'commit message')])

    expect = """commit_id: {id}
prev_version: {prev}
tag: {tag}
version: {version}
""".format(id=summary.commit_id, tag=summary.tag, version=summary.version,
           prev=summary.prev_version)
    self.assertEqual(expect, summary.to_yaml(with_commit_messages=False))
Пример #5
0
    def test_determine_most_common_prefix(self):
        options = self.options
        builder = BomBuilder(options, self.scm, MetricsManager.singleton())
        self.assertIsNone(builder.determine_most_common_prefix())

        prefix = ["http://github.com/one", "/local/source/path/two"]

        # Test two vs one in from different repo prefix
        # run the test twice changing the ordering the desired prefix is visible.
        for which in [0, 1]:
            repository = GitRepositorySpec("RepoOne",
                                           origin=prefix[0] + "/RepoOne",
                                           commit_id="RepoOneCommit")
            summary = RepositorySummary("RepoOneCommit", "RepoOneTag", "1.2.3",
                                        [])
            source_info = SourceInfo("BuildOne", summary)
            builder.add_repository(repository, source_info)
            self.assertEqual(prefix[0], builder.determine_most_common_prefix())

            repository = GitRepositorySpec("RepoTwo",
                                           origin=prefix[which] + "/RepoTwo",
                                           commit_id="RepoTwoCommit")
            summary = RepositorySummary("RepoTwoCommit", "RepoTwoTag", "2.2.3",
                                        [])
            source_info = SourceInfo("BuildTwo", summary)
            builder.add_repository(repository, source_info)

            repository = GitRepositorySpec(
                "RepoThree",
                origin=prefix[1] + "/RepoThree",
                commit_id="RepoThreeCommit",
            )
            summary = RepositorySummary("RepoThreeCommit", "RepoThreeTag",
                                        "3.2.0", [])
            source_info = SourceInfo("BuildThree", summary)
            builder.add_repository(repository, source_info)
            self.assertEqual(prefix[which],
                             builder.determine_most_common_prefix())
Пример #6
0
 def test_yamilfy(self):
     # The summary values are arbitrary. Just verifying we can go in and out
     # of yaml.
     summary = RepositorySummary('abcd', 'tag-123', '1.2.0', '1.1.5', [
         CommitMessage('commitB', 'authorB', 'dateB', 'messageB'),
         CommitMessage('commitA', 'authorA', 'dateA', 'messageA')
     ])
     yamlized = yaml.safe_load(summary.to_yaml())
     self.assertEqual(summary.commit_id, yamlized['commit_id'])
     self.assertEqual(summary.tag, yamlized['tag'])
     self.assertEqual(summary.version, yamlized['version'])
     self.assertEqual(summary.prev_version, yamlized['prev_version'])
     self.assertEqual([{
         'commit_id': 'commit' + x,
         'author': 'author' + x,
         'date': 'date' + x,
         'message': 'message' + x
     } for x in ['B', 'A']], yamlized['commit_messages'])
     self.assertEqual(summary, RepositorySummary.from_dict(yamlized))
Пример #7
0
    def test_bom_command(self):
        """Make sure when we run "build_bom" we actually get what we meant."""
        defaults = vars(make_default_options(self.options))
        defaults.update({
            'bom_path': 'MY PATH',
            'github_owner': 'TestOwner',
            'input_dir': 'TestInputRoot'
        })
        defaults.update({
            'bintray_org': 'TestBintrayOrg',
            'bintray_debian_repository': 'TestDebianRepo',
            'docker_registry': 'TestDockerRegistry',
            'publish_gce_image_project': 'TestGceProject'
        })
        del defaults['github_filesystem_root']
        parser = argparse.ArgumentParser()
        registry = bomtool_main.make_registry([buildtool.bom_commands], parser,
                                              defaults)
        bomtool_main.add_standard_parser_args(parser, defaults)
        options = parser.parse_args(['build_bom'])

        prefix = 'http://test-domain.com/test-owner'

        make_fake = self.patch_method

        # When asked to filter the normal bom repos to determine source_repositories
        # we'll return our own fake repository as if we configured the original
        # command for it. This will also make it easier to test just the one
        # repo rather than all, and that there are no assumptions.
        mock_filter = make_fake(BuildBomCommand, 'filter_repositories')
        test_repository = GitRepositorySpec('clouddriver',
                                            commit_id='CommitA',
                                            origin=prefix + '/TestRepoA')
        mock_filter.return_value = [test_repository]

        # When the base command ensures the local repository exists, we'll
        # intercept that call and do nothing rather than the git checkouts, etc.
        make_fake(BranchSourceCodeManager, 'ensure_local_repository')

        # When the base command asks for the repository metadata, we'll return
        # this hardcoded info, then look for it later in the generated om.
        mock_lookup = make_fake(BranchSourceCodeManager, 'lookup_source_info')
        summary = RepositorySummary('CommitA', 'TagA', '9.8.7', '44.55.66', [])
        source_info = SourceInfo('MyBuildNumber', summary)
        mock_lookup.return_value = source_info

        # When asked to write the bom out, do nothing.
        # We'll verify the bom later when looking at the mock call sequencing.
        mock_write = self.patch_function(
            'buildtool.bom_commands.write_to_path')

        mock_now = self.patch_function('buildtool.bom_commands.now')
        mock_now.return_value = datetime.datetime(2018, 1, 2, 3, 4, 5)

        factory = registry['build_bom']
        command = factory.make_command(options)
        command()

        # Verify source repositories were filtered
        self.assertEquals([test_repository], command.source_repositories)

        # Verify that the filter was called with the original bom repos,
        # and these repos were coming from the configured github_owner's repo.
        bom_repo_list = [
            GitRepositorySpec(name,
                              git_dir=os.path.join('TestInputRoot',
                                                   'build_bom', name),
                              origin='https://%s/TestOwner/%s' %
                              (options.github_hostname, name),
                              upstream='https://github.com/spinnaker/' + name)
            for name in sorted([
                'clouddriver', 'deck', 'echo', 'fiat', 'front50', 'gate',
                'igor', 'orca', 'rosco', 'spinnaker', 'spinnaker-monitoring'
            ])
        ]
        mock_filter.assert_called_once_with(bom_repo_list)
        mock_lookup.assert_called_once_with(test_repository)
        bom_text, bom_path = mock_write.call_args_list[0][0]

        self.assertEquals(bom_path, 'MY PATH')
        bom = yaml.load(bom_text)

        golden_text = textwrap.dedent("""\
        artifactSources:
          debianRepository: https://dl.bintray.com/TestBintrayOrg/TestDebianRepo
          dockerRegistry: TestDockerRegistry
          gitPrefix: http://test-domain.com/test-owner
          googleImageProject: TestGceProject
        dependencies:
        services:
          clouddriver:
            commit: CommitA
            version: 9.8.7-MyBuildNumber
        timestamp: '2018-01-02 03:04:05'
        version: OptionBranch-OptionBuildNumber
    """)
        golden_bom = yaml.load(golden_text)
        golden_bom['dependencies'] = load_default_bom_dependencies()

        for key, value in golden_bom.items():
            self.assertEquals(value, bom[key])
Пример #8
0
    def test_bom_command(self):
        """Make sure when we run "build_bom" we actually get what we meant."""
        defaults = vars(make_default_options(self.options))
        defaults.update({
            "bom_path": "MY PATH",
            "github_owner": "TestOwner",
            "input_dir": "TestInputRoot",
        })
        del defaults["github_repository_root"]
        parser = argparse.ArgumentParser()
        registry = bomtool_main.make_registry([buildtool.bom_commands], parser,
                                              defaults)
        bomtool_main.add_standard_parser_args(parser, defaults)
        options = parser.parse_args(["build_bom"])

        prefix = "http://test-domain.com/test-owner"

        make_fake = self.patch_method

        # When asked to filter the normal bom repos to determine source_repositories
        # we'll return our own fake repository as if we configured the original
        # command for it. This will also make it easier to test just the one
        # repo rather than all, and that there are no assumptions.
        mock_filter = make_fake(BuildBomCommand, "filter_repositories")
        test_repository = GitRepositorySpec("clouddriver",
                                            commit_id="CommitA",
                                            origin=prefix + "/TestRepoA")
        mock_filter.return_value = [test_repository]

        # When the base command ensures the local repository exists, we'll
        # intercept that call and do nothing rather than the git checkouts, etc.
        make_fake(BranchSourceCodeManager, "ensure_local_repository")

        # When the base command asks for the repository metadata, we'll return
        # this hardcoded info, then look for it later in the generated om.
        mock_refresh = make_fake(BranchSourceCodeManager,
                                 "refresh_source_info")
        summary = RepositorySummary("CommitA", "TagA", "9.8.7", [])
        source_info = SourceInfo("MyBuildNumber", summary)
        mock_refresh.return_value = source_info

        # When asked to write the bom out, do nothing.
        # We'll verify the bom later when looking at the mock call sequencing.
        mock_write = self.patch_function(
            "buildtool.bom_commands.write_to_path")

        mock_now = self.patch_function("buildtool.bom_commands.now")
        mock_now.return_value = datetime.datetime(2018, 1, 2, 3, 4, 5)

        factory = registry["build_bom"]
        command = factory.make_command(options)
        command()

        # Verify source repositories were filtered
        self.assertEqual([test_repository], command.source_repositories)

        # Verify that the filter was called with the original bom repos,
        # and these repos were coming from the configured github_owner's repo.
        bom_repo_list = [
            GitRepositorySpec(
                name,
                git_dir=os.path.join("TestInputRoot", "build_bom", name),
                origin="https://%s/TestOwner/%s" %
                (options.github_hostname, name),
                upstream="https://github.com/spinnaker/" + name,
            ) for name in sorted([
                "clouddriver",
                "deck",
                "echo",
                "fiat",
                "front50",
                "gate",
                "igor",
                "kayenta",
                "orca",
                "rosco",
                "spinnaker-monitoring",
            ])
        ]
        mock_filter.assert_called_once_with(bom_repo_list)
        mock_refresh.assert_called_once_with(test_repository,
                                             "OptionBuildNumber")
        bom_text, bom_path = mock_write.call_args_list[0][0]

        self.assertEqual(bom_path, "MY PATH")
        bom = yaml.safe_load(bom_text)

        golden_text = (textwrap.dedent("""\
        artifactSources:
          gitPrefix: http://test-domain.com/test-owner
          debianRepository: %s
          dockerRegistry: %s
          googleImageProject: %s
        dependencies:
        services:
          clouddriver:
            commit: CommitA
            version: 9.8.7
        timestamp: '2018-01-02 03:04:05'
        version: OptionBuildNumber
    """) % (
            SPINNAKER_DEBIAN_REPOSITORY,
            SPINNAKER_DOCKER_REGISTRY,
            SPINNAKER_GOOGLE_IMAGE_PROJECT,
        ))
        golden_bom = yaml.safe_load(golden_text.format())
        golden_bom["dependencies"] = load_default_bom_dependencies()

        for key, value in golden_bom.items():
            self.assertEqual(value, bom[key])