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', '1.2.2', []) 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', '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.assertEqual(prefix[which], builder.determine_most_common_prefix())
def test_inject_dependencies(self): dependencies = { 'DependencyA': { 'version': 'vA' }, 'DependencyB': { 'version': 'vB' } } fd, path = tempfile.mkstemp(prefix='bomdeps') os.close(fd) with open(path, 'w') as stream: yaml.dump(dependencies, stream) options = self.options options.bom_dependencies_path = path try: builder = BomBuilder(options, self.scm) bom = builder.build() finally: os.remove(path) self.assertEquals(dependencies, bom['dependencies']) self.assertEquals({}, bom['services'])
def test_inject_dependencies(self): dependencies = { "DependencyA": { "version": "vA" }, "DependencyB": { "version": "vB" }, } fd, path = tempfile.mkstemp(prefix="bomdeps") os.close(fd) with open(path, "w") as stream: yaml.safe_dump(dependencies, stream) options = self.options options.bom_dependencies_path = path try: builder = BomBuilder(options, self.scm, MetricsManager.singleton()) bom = builder.build() finally: os.remove(path) self.assertEqual(dependencies, bom["dependencies"]) self.assertEqual({}, bom["services"])
def test_default_build(self): builder = BomBuilder(self.options, self.scm) bom = builder.build() self.assertEquals(bom['dependencies'], load_default_bom_dependencies()) # There are no services because we never added any. # Although the builder takes an SCM, you still need to explicitly add repos. self.assertEquals({}, bom['services'])
def test_default_build(self): builder = BomBuilder(self.options, self.scm, MetricsManager.singleton()) bom = builder.build() self.assertEqual(bom["dependencies"], load_default_bom_dependencies()) # There are no services because we never added any. # Although the builder takes an SCM, you still need to explicitly add repos. self.assertEqual({}, bom["services"])
def test_default_build(self): builder = BomBuilder(self.options, self.scm, MetricsManager.singleton()) bom = builder.build() self.assertEqual( bom['dependencies'], load_default_bom_dependencies()) # There are no services because we never added any. # Although the builder takes an SCM, you still need to explicitly add repos. self.assertEqual({}, bom['services'])
def test_inject_dependencies(self): dependencies = { 'DependencyA': {'version': 'vA'}, 'DependencyB': {'version': 'vB'} } fd, path = tempfile.mkstemp(prefix='bomdeps') os.close(fd) with open(path, 'w') as stream: yaml.safe_dump(dependencies, stream) options = self.options options.bom_dependencies_path = path try: builder = BomBuilder(options, self.scm, MetricsManager.singleton()) bom = builder.build() finally: os.remove(path) self.assertEqual(dependencies, bom['dependencies']) self.assertEqual({}, bom['services'])
def test_build(self): test_root = self.test_root options = self.options options.git_branch = PATCH_BRANCH options.github_owner = 'default' options.github_disable_upstream_push = True scm = BranchSourceCodeManager(options, test_root) golden_bom = dict(self.golden_bom) builder = BomBuilder.new_from_bom(options, scm, golden_bom) source_repositories = [ scm.make_repository_spec(name) for name in ALL_STANDARD_TEST_BOM_REPO_NAMES ] for repository in source_repositories: scm.ensure_git_path(repository) summary = scm.git.collect_repository_summary(repository.git_dir) source_info = SourceInfo('SourceInfoBuildNumber', summary) builder.add_repository(repository, source_info) with patch('buildtool.bom_commands.now') as mock_now: mock_now.return_value = datetime.datetime(2018, 1, 2, 3, 4, 5) bom = builder.build() golden_bom['version'] = 'patch-OptionBuildNumber' golden_bom['timestamp'] = '2018-01-02 03:04:05' golden_bom['services'][NORMAL_SERVICE]['version'] = ( PATCH_VERSION_NUMBER + '-SourceInfoBuildNumber') golden_bom['services'][OUTLIER_SERVICE]['version'] = ( PATCH_VERSION_NUMBER + '-SourceInfoBuildNumber') golden_bom['services']['monitoring-third-party']['version'] = ( PATCH_VERSION_NUMBER + '-SourceInfoBuildNumber') golden_bom['artifactSources'] = { 'debianRepository': 'https://dl.bintray.com/%s/%s' % (options.bintray_org, options.bintray_debian_repository), 'dockerRegistry': options.docker_registry, 'googleImageProject': options.publish_gce_image_project, 'gitPrefix': os.path.dirname(self.repo_commit_map[NORMAL_REPO]['ORIGIN']) } for key, value in bom['services'].items(): print '**** {0} -> {1}'.format(key, value) print ' ==>> {0}'.format(golden_bom['services'][key]) self.assertEquals(value, golden_bom['services'][key]) for key, value in bom.items(): self.assertEquals(value, golden_bom[key]) self.assertEquals(golden_bom, bom)
def test_rebuild(self): test_root = self.test_root options = self.options options.git_branch = 'master' options.github_owner = 'default' options.github_disable_upstream_push = True options.build_number = 'UpdatedBuildNumber' scm = BranchSourceCodeManager(options, test_root) builder = BomBuilder.new_from_bom(options, scm, MetricsManager.singleton(), self.golden_bom) repository = scm.make_repository_spec(OUTLIER_REPO) scm.ensure_git_path(repository) scm.git.check_run(repository.git_dir, 'checkout ' + PATCH_BRANCH) summary = scm.git.collect_repository_summary(repository.git_dir) source_info = SourceInfo('SourceInfoBuildNumber', summary) builder.add_repository(repository, source_info) with patch('buildtool.bom_commands.now') as mock_now: mock_now.return_value = datetime.datetime(2018, 1, 2, 3, 4, 5) bom = builder.build() updated_service = bom['services'][OUTLIER_SERVICE] self.assertEqual( updated_service, { 'commit': self.repo_commit_map[OUTLIER_REPO][PATCH_BRANCH], 'version': PATCH_VERSION_NUMBER + '-SourceInfoBuildNumber' }) # The bom should be the same as before, but with new timestamp/version # and our service updated. And the artifactSources to our configs. updated_bom = dict(self.golden_bom) updated_bom['timestamp'] = '2018-01-02 03:04:05' updated_bom['version'] = 'master-UpdatedBuildNumber' updated_bom['services'][OUTLIER_SERVICE] = updated_service updated_bom['artifactSources'] = { 'debianRepository': 'https://dl.bintray.com/%s/%s' % (options.bintray_org, options.bintray_debian_repository), 'dockerRegistry': options.docker_registry, 'googleImageProject': options.publish_gce_image_project, 'gitPrefix': self.golden_bom['artifactSources']['gitPrefix'] } for key, value in updated_bom.items(): self.assertEqual(value, bom[key]) self.assertEqual(updated_bom, bom)
def test_rebuild(self): test_root = self.test_root options = self.options options.git_branch = 'master' options.github_owner = 'default' options.github_disable_upstream_push = True options.build_number = 'UpdatedBuildNumber' scm = BranchSourceCodeManager(options, test_root) builder = BomBuilder.new_from_bom( options, scm, MetricsManager.singleton(), self.golden_bom) repository = scm.make_repository_spec(OUTLIER_REPO) scm.ensure_git_path(repository) scm.git.check_run(repository.git_dir, 'checkout ' + PATCH_BRANCH) summary = scm.git.collect_repository_summary(repository.git_dir) source_info = SourceInfo('SourceInfoBuildNumber', summary) builder.add_repository(repository, source_info) with patch('buildtool.bom_commands.now') as mock_now: mock_now.return_value = datetime.datetime(2018, 1, 2, 3, 4, 5) bom = builder.build() updated_service = bom['services'][OUTLIER_SERVICE] self.assertEqual(updated_service, { 'commit': self.repo_commit_map[OUTLIER_REPO][PATCH_BRANCH], 'version': PATCH_VERSION_NUMBER + '-SourceInfoBuildNumber' }) # The bom should be the same as before, but with new timestamp/version # and our service updated. And the artifactSources to our configs. updated_bom = dict(self.golden_bom) updated_bom['timestamp'] = '2018-01-02 03:04:05' updated_bom['version'] = 'master-UpdatedBuildNumber' updated_bom['services'][OUTLIER_SERVICE] = updated_service updated_bom['artifactSources'] = { 'debianRepository': 'https://dl.bintray.com/%s/%s' % ( options.bintray_org, options.bintray_debian_repository), 'dockerRegistry': options.docker_registry, 'googleImageProject': options.publish_gce_image_project, 'gitPrefix': self.golden_bom['artifactSources']['gitPrefix'] } for key, value in updated_bom.items(): self.assertEqual(value, bom[key]) self.assertEqual(updated_bom, bom)
def test_build(self): test_root = self.test_root options = self.options options.git_branch = PATCH_BRANCH options.github_owner = 'default' options.github_disable_upstream_push = True scm = BranchSourceCodeManager(options, test_root) golden_bom = dict(self.golden_bom) builder = BomBuilder.new_from_bom( options, scm, MetricsManager.singleton(), golden_bom) source_repositories = [scm.make_repository_spec(name) for name in ALL_STANDARD_TEST_BOM_REPO_NAMES] for repository in source_repositories: scm.ensure_git_path(repository) summary = scm.git.collect_repository_summary(repository.git_dir) source_info = SourceInfo('SourceInfoBuildNumber', summary) builder.add_repository(repository, source_info) with patch('buildtool.bom_commands.now') as mock_now: mock_now.return_value = datetime.datetime(2018, 1, 2, 3, 4, 5) bom = builder.build() golden_bom['version'] = 'patch-OptionBuildNumber' golden_bom['timestamp'] = '2018-01-02 03:04:05' golden_bom['services'][NORMAL_SERVICE]['version'] = ( PATCH_VERSION_NUMBER + '-SourceInfoBuildNumber') golden_bom['services'][OUTLIER_SERVICE]['version'] = ( PATCH_VERSION_NUMBER + '-SourceInfoBuildNumber') golden_bom['services']['monitoring-third-party']['version'] = ( PATCH_VERSION_NUMBER + '-SourceInfoBuildNumber') golden_bom['artifactSources'] = { 'debianRepository': 'https://dl.bintray.com/%s/%s' % ( options.bintray_org, options.bintray_debian_repository), 'dockerRegistry': options.docker_registry, 'googleImageProject': options.publish_gce_image_project, 'gitPrefix': os.path.dirname(self.repo_commit_map[NORMAL_REPO]['ORIGIN']) } for key, value in bom['services'].items(): self.assertEqual(value, golden_bom['services'][key]) for key, value in bom.items(): self.assertEqual(value, golden_bom[key]) self.assertEqual(golden_bom, bom)
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())
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())
def test_rebuild(self): test_root = self.test_root options = self.options options.git_branch = "master" options.github_owner = "default" options.github_disable_upstream_push = True options.build_number = "UpdatedBuildNumber" scm = BranchSourceCodeManager(options, test_root) builder = BomBuilder.new_from_bom(options, scm, MetricsManager.singleton(), self.golden_bom) repository = scm.make_repository_spec(OUTLIER_REPO) scm.ensure_git_path(repository) scm.git.check_run(repository.git_dir, "checkout " + PATCH_BRANCH) summary = scm.git.collect_repository_summary(repository.git_dir) source_info = SourceInfo("SourceInfoBuildNumber", summary) builder.add_repository(repository, source_info) with patch("buildtool.bom_commands.now") as mock_now: mock_now.return_value = datetime.datetime(2018, 1, 2, 3, 4, 5) bom = builder.build() updated_service = bom["services"][OUTLIER_SERVICE] # OUTLIER_REPO hasn't been tagged since extra commits so bom should be same self.assertNotEqual( updated_service, { "commit": self.repo_commit_map[OUTLIER_REPO][PATCH_BRANCH], "version": BASE_VERSION_NUMBER, }, ) # The bom should be the same as before, but with new timestamp/version # and our service unchanged. And the artifactSources to our configs. updated_bom = dict(self.golden_bom) updated_bom["timestamp"] = "2018-01-02 03:04:05" updated_bom["version"] = "UpdatedBuildNumber" updated_bom["artifactSources"] = { "gitPrefix": self.golden_bom["artifactSources"]["gitPrefix"], "debianRepository": SPINNAKER_DEBIAN_REPOSITORY, "dockerRegistry": SPINNAKER_DOCKER_REGISTRY, "googleImageProject": SPINNAKER_GOOGLE_IMAGE_PROJECT, } for key, value in bom["services"].items(): # monitoring-daemon has extra commit on branch so commit id's should not match if key in ["monitoring-daemon", "monitoring-third-party"]: self.assertNotEqual( value, updated_bom["services"][key], msg="key: {} - value: {}".format(key, value), ) else: self.assertEqual( value, updated_bom["services"][key], msg="key: {} - value: {}".format(key, value), ) for key, value in bom.items(): if key != "services": self.assertEqual(value, updated_bom[key])
def test_build(self): test_root = self.test_root options = self.options options.git_branch = PATCH_BRANCH options.github_owner = "default" options.github_disable_upstream_push = True scm = BranchSourceCodeManager(options, test_root) golden_bom = dict(self.golden_bom) builder = BomBuilder.new_from_bom(options, scm, MetricsManager.singleton(), golden_bom) source_repositories = [ scm.make_repository_spec(name) for name in ALL_STANDARD_TEST_BOM_REPO_NAMES ] for repository in source_repositories: scm.ensure_git_path(repository) summary = scm.git.collect_repository_summary(repository.git_dir) source_info = SourceInfo("SourceInfoBuildNumber", summary) builder.add_repository(repository, source_info) with patch("buildtool.bom_commands.now") as mock_now: mock_now.return_value = datetime.datetime(2018, 1, 2, 3, 4, 5) bom = builder.build() golden_bom["version"] = "OptionBuildNumber" golden_bom["timestamp"] = "2018-01-02 03:04:05" golden_bom["services"][NORMAL_SERVICE]["version"] = BASE_VERSION_NUMBER golden_bom["services"][OUTLIER_SERVICE][ "version"] = BASE_VERSION_NUMBER golden_bom["services"]["monitoring-third-party"][ "version"] = BASE_VERSION_NUMBER golden_bom["artifactSources"] = { "gitPrefix": os.path.dirname(self.repo_commit_map[NORMAL_REPO]["ORIGIN"]), "debianRepository": SPINNAKER_DEBIAN_REPOSITORY, "dockerRegistry": SPINNAKER_DOCKER_REGISTRY, "googleImageProject": SPINNAKER_GOOGLE_IMAGE_PROJECT, } for key, value in bom["services"].items(): # gate has extra commit on branch so commit id's should not match if key in ["gate", "monitoring-daemon", "monitoring-third-party"]: self.assertNotEqual( value, golden_bom["services"][key], msg="key: {} - value: {}".format(key, value), ) else: self.assertEqual( value, golden_bom["services"][key], msg="key: {} - value: {}".format(key, value), ) for key, value in bom.items(): if key != "services": self.assertEqual(value, golden_bom[key])