This repository was archived by the owner on Aug 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Migration tool #27
Open
karottenreibe
wants to merge
92
commits into
master
Choose a base branch
from
migration-tool
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Migration tool #27
Changes from 54 commits
Commits
Show all changes
92 commits
Select commit
Hold shift + click to select a range
73b9c61
Add Pylint report format
nihathrael 1ac9cda
Update to 3.8
nihathrael 707b2f9
Attempt to fix travis-sphinx build
nihathrael f0ba73a
enable new movetolastcommit parameter for report uploads
karottenreibe 515842f
Merge pull request #25 from cqse/coverage_upload_parameters
nihathrael 24d6c6c
added path suffix to connector config
alexrhein 666dc40
Fix whitespaces
nihathrael d0f6c1d
Merge pull request #26 from alexrhein/path_suffix_in_connector_config
nihathrael d2a4278
Prepare for 3.9.0
nihathrael 60f54cc
Added a migration tool (works for tasks and blacklist)
Macariel 254785d
Fixed some typos
Macariel 99fed95
fix typo
karottenreibe 203e4a9
fix typo
karottenreibe e47b73e
Reworked the migrating tools
Macariel 5f7fae6
Added warning and mitigations for migrating between different TS-Vers…
Macariel 2f5da64
Added an exemplary test
Macariel f4f4115
Fixed some findings
Macariel 3939ac3
Changed module name
Macariel 9e2a569
Added fallback for missing service call
Macariel 2bb2f34
Disabled api check. Not working for 3.6 even though 3.2 should be fine
Macariel 3a9821b
Revert Change
Macariel c858ef6
Changed module import
Macariel 9b5aa1e
Revert "Changed module import"
Macariel 7f093ea
Revert "Revert Change"
Macariel 91dd8b2
Revert "Disabled api check. Not working for 3.6 even though 3.2 shoul…
Macariel f025220
Revert "Added fallback for missing service call"
Macariel 08232c9
Changed import and added pytest cache to gitignore
Macariel 24d5cf0
Added handling of missing findings
Macariel 1d5625d
Fixed bug
Macariel 0776b88
Added a dry-run option
Macariel dd2b524
Added more logs
Macariel 7d77d82
Added logging level print
Macariel 1e401f9
Added more logging
Macariel 31ff7f0
Fixed id
Macariel 81f305b
Logging
Macariel 759234e
Modified logging
Macariel 6282c8e
Fixed wrong method call
Macariel ddd2a37
Changed the task migration
Macariel 623b54b
Stringified path suffix
Macariel 086c7c2
Changed the task migration
Macariel b3133ee
Changed comparison of tasks
Macariel 8e07e8f
Removed task pre-filtering
Macariel f702e91
Added the step by step option
Macariel 95c78a4
Removing print statement
Macariel 10aa956
Removed dead code and added a few comments
Macariel 254954b
Added a check if a project exists
Macariel 7395a89
Added a scripts which allows the batch migration of blacklists and tasks
Macariel c89a099
Changed output and made it clearer
b63d213
Merge branch 'migration-tool' of https://github.com/cqse/teamscale-cl…
Macariel 7efce70
Added logging%
Macariel 1511ecd
Merge branch 'migration-tool' of https://github.com/cqse/teamscale-cl…
Macariel 6871d06
Fixed the double logging
Macariel 02167b5
Merge branch 'migration-tool' of https://github.com/cqse/teamscale-cl…
Macariel 8d7e3a0
Merge branch 'master' into migration-tool
mpdeimos 56de09b
Changed according to review
Macariel 1514245
Added path prefix transformation
Macariel 44f8a5d
Deleted the wrong config file
Macariel 7c46c2c
Changed findings comparison
Macariel 1410c86
Path transformation fix
Macariel e2039ee
Removed version check
Macariel 5eea5d8
Made findings comparision more robust
Macariel 738f322
Added a description on how to use the migration tools
Macariel ee49bb1
tmp
Macariel 6ad3205
Changed the findings comparison
Macariel 88fc7cb
Reset client to master
Macariel 24c3224
Small fixes
Macariel 0db5463
Added upload of finding-groups and -descriptions
Macariel c07c755
Path prefix transformation is defined in the 'new_instance'.
r2h2 a64d7ce
Merge pull request #37 from cqse/fix_path_prefix_transformation
Macariel b8e3988
Adjust README
Macariel 435cb44
Merge branch 'master' into migration-tool
Macariel 99824fb
Simplified exception logging
Macariel 8dbd489
Merge branch 'master' into migration-tool
da3579a
Fixes
c4af488
Add socks proxy support
e45475a
Improvements
0dd0472
manually generate the correct service url when fetching tasks
ke-kx b8e1e41
Merge branch 'migration-tool' into get_tasks_dirty_fix
ke-kx 6fe13a7
workaround for posting task comments
ke-kx d3389e8
add blacklisted parameter to get_findings to enable fetching false po…
0a70622
Merge branch 'master' into migration-tool
albertsteckermeier 873a952
add functionality for querying findings counts and descriptions
73b2d87
remove unnecessary proxy parameter
748d059
Merge branch 'master' into a_team_branch
9535834
Merge branch 'a_team_branch' into migration-tool
bcf4f37
Support code for ongoing work on temp findings script
cea5a61
Added new supporting methods to get finding churn by commit timestamp
c94609b
Support code for ongoing work on temp findings script
82ae08e
Refactoring the solution and changing output
b229c08
Fixed a bug
9cef908
test gap analysis work
baralCqse cb5cbf3
Added helper method in merge_request data class
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| from __future__ import absolute_import | ||
| from __future__ import unicode_literals | ||
|
|
||
| import responses | ||
| from tools.migration.task_migrator import TaskMigrator | ||
| from test_utils import get_global_service_mock | ||
| from copy import deepcopy | ||
|
|
||
| URL = "http://localhost:8080" | ||
| CONFIG = { | ||
| "old_instance": { | ||
| "url": URL, | ||
| "project": "old", | ||
| "user": "admin", | ||
| "token": "token" | ||
| }, | ||
| "new_instance": { | ||
| "url": URL, | ||
| "project": "new", | ||
| "user": "admin", | ||
| "token": "token" | ||
| } | ||
| } | ||
|
|
||
|
|
||
| class TestTaskMigrator: | ||
| """ Simple class for bundling the test for the task migration. """ | ||
| @staticmethod | ||
| def get_migrator(config): | ||
| """ | ||
| Returns a task migrator with the given config. | ||
| For an example config look at CONFIG | ||
| """ | ||
| TestTaskMigrator.create_necessary_client_responses(URL) | ||
| return TaskMigrator(config, False) | ||
|
|
||
| @staticmethod | ||
| def create_necessary_client_responses(url, version=40000): | ||
| """ Creates responses which are necessary to create a client """ | ||
| responses.add(responses.GET, get_global_service_mock(url, "service-api-info"), | ||
| status=200, content_type="application/json", body='{ "apiVersion": 3 }') | ||
| responses.add(responses.GET, get_global_service_mock(url, "health-metrics"), | ||
| status=200, content_type="text/plain", body="version %s 0" % version) | ||
|
|
||
| def get_default_migrator(self): | ||
| """ Returns the migrator with the default settings """ | ||
| return self.get_migrator(CONFIG) | ||
|
|
||
| @responses.activate | ||
| def test_different_versions(self, caplog): | ||
| """ Tests the case where we want to migrate between two TS-instances with a different | ||
| version. A warning should be logged and the version_match flag should be False. | ||
| """ | ||
| config = deepcopy(CONFIG) | ||
| new_url = "http://localhost:8081" | ||
| config["new_instance"]["url"] = new_url | ||
| self.create_necessary_client_responses(new_url, version=30000) | ||
| migrator = self.get_migrator(config) | ||
|
|
||
| warning = list(filter(lambda x: x.levelname == "WARNING" and "version" in x.message, caplog.records)) | ||
| assert len(warning) == 1, "Missing warning about version mismatch" | ||
| assert not migrator.versions_match, "Flag 'versions_match' should be False" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import re | ||
|
|
||
| def get_global_service_mock(url, service_id): | ||
| """ Creates a url for a global service with the given url and service """ | ||
| return re.compile(r'%s/%s/.*' % (url, service_id)) |
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "old_instance" : { | ||
| "url": "http://localhost:8080", | ||
| "user": "user", | ||
| "token": "tokentoken" | ||
| }, | ||
| "new_instance" : { | ||
| "url": "http://localhost:8080", | ||
| "user": "user", | ||
| "token": "tokentoken" | ||
| }, | ||
| "project_mappings": [ | ||
| {"from": "a", "to": "b"}, | ||
| {"from": "c", "to": "d"} | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import argparse | ||
| import json | ||
|
|
||
| from pathlib import Path | ||
| from task_migrator import TaskMigrator | ||
| from blacklist_migrator import BlacklistMigrator | ||
| from migrator_base import create_logger | ||
|
|
||
|
|
||
| def main(): | ||
| """ Migrates the blacklists and tasks of multiple projects from one server to the projects to the other. | ||
| It automatically reads the arguments from the command line. """ | ||
| parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter) | ||
| parser.add_argument("config", help="The path to the config file. Needs to be in a specific format, " | ||
| "see batch_config.template.") | ||
| args = parser.parse_args() | ||
| logger = create_logger(name="batch") | ||
| config_file = Path(args.config) | ||
| if not config_file.exists(): | ||
| logger.error("Config file does not exist") | ||
|
|
||
| with config_file.open() as file: | ||
| data = json.load(file) | ||
| base_config = {x: data[x] for x in ["old_instance", "new_instance"]} | ||
|
|
||
| for mapping in data["project_mappings"]: | ||
| migrate(base_config, mapping, logger) | ||
|
|
||
|
|
||
| def migrate(base_config, mapping, logger): | ||
| """ Migrates the blacklist and the tasks of between the projects defined in the mapping. | ||
| The servers containing the project are defined in the base config. | ||
| """ | ||
| if not all(key in mapping for key in ("from", "to")): | ||
| logger.error("Project mapping is malformed: %s" % mapping) | ||
| return None | ||
|
|
||
| base_config["old_instance"]["project"] = mapping["from"] | ||
| base_config["new_instance"]["project"] = mapping["to"] | ||
|
|
||
| logger.info("Migrating from '{from}' to '{to}'".format(**mapping)) | ||
| BlacklistMigrator(base_config).migrate() | ||
| TaskMigrator(base_config).migrate() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.