sirmordred 1.0.4__tar.gz → 1.1.3rc1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/PKG-INFO +4 -5
  2. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/pyproject.toml +6 -6
  3. sirmordred-1.1.3rc1/sirmordred/_version.py +2 -0
  4. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/sirmordred/sirmordred.py +34 -5
  5. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/sirmordred/task.py +4 -13
  6. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/sirmordred/task_autorefresh.py +2 -2
  7. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/sirmordred/task_collection.py +2 -2
  8. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/sirmordred/task_enrich.py +2 -2
  9. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/sirmordred/task_identities.py +2 -2
  10. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/sirmordred/task_manager.py +3 -2
  11. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/sirmordred/task_panels.py +4 -4
  12. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/sirmordred/utils/micro.py +42 -6
  13. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/test_task.py +19 -13
  14. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/test_task_autorefresh.py +19 -15
  15. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/test_task_collection.py +4 -2
  16. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/test_task_enrich.py +66 -45
  17. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/test_task_identities.py +21 -10
  18. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/test_task_manager.py +19 -6
  19. sirmordred-1.0.4/sirmordred/_version.py +0 -2
  20. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/LICENSE +0 -0
  21. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/README.md +0 -0
  22. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/menu.yaml +0 -0
  23. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/sirmordred/__init__.py +0 -0
  24. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/sirmordred/bin/sirmordred.py +0 -0
  25. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/sirmordred/config.py +0 -0
  26. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/sirmordred/error.py +0 -0
  27. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/sirmordred/github.py +0 -0
  28. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/sirmordred/task_projects.py +0 -0
  29. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/sirmordred/utils/find_affiliation_conflicts.py +0 -0
  30. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/sirmordred/utils/grimoirelab_valid.yml +0 -0
  31. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/sirmordred/utils/healthcheck.py +0 -0
  32. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/sirmordred/utils/logs/all.log +0 -0
  33. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/sirmordred/utils/panels_config.py +0 -0
  34. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/sirmordred/utils/projects.json +0 -0
  35. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/sirmordred/utils/projects_json2yml.py +0 -0
  36. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/sirmordred/utils/setup.cfg +0 -0
  37. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/aliases.json +0 -0
  38. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/askbot.archive +0 -0
  39. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/bugzilla.archive +0 -0
  40. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/bugzillarest.archive +0 -0
  41. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/confluence.archive +0 -0
  42. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/crates.archive +0 -0
  43. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/discourse.archive +0 -0
  44. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/dockerhub.archive +0 -0
  45. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/functest.archive +0 -0
  46. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/gerrit.archive +0 -0
  47. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/github-issue.archive +0 -0
  48. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/github-pull.archive +0 -0
  49. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/gitlab-issue.archive +0 -0
  50. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/gitlab-merge.archive +0 -0
  51. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/googlehits.archive +0 -0
  52. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/jenkins.archive +0 -0
  53. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/jira.archive +0 -0
  54. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/launchpad.archive +0 -0
  55. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/mediawiki-1.23.archive +0 -0
  56. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/mediawiki-1.28.archive +0 -0
  57. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/meetup.archive +0 -0
  58. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/mozillaclub.archive +0 -0
  59. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/nntp.archive +0 -0
  60. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/phabricator.archive +0 -0
  61. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/redmine.archive +0 -0
  62. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/remo.archive +0 -0
  63. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/rss.archive +0 -0
  64. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/slack.archive +0 -0
  65. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/stackexchange.archive +0 -0
  66. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/telegram.archive +0 -0
  67. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives/twitter.archive +0 -0
  68. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives-test-projects.json +0 -0
  69. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/archives-test.cfg +0 -0
  70. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/data/eclipse-projects.json +0 -0
  71. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/data/healthcheck_cache_invalid.json +0 -0
  72. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/data/healthcheck_cache_valid.json +0 -0
  73. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/data/healthcheck_cache_wrong_key.json +0 -0
  74. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/data/mordred.log +0 -0
  75. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/data/orgs_sortinghat.json +0 -0
  76. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/data/perceval_identities_sortinghat.json +0 -0
  77. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/data/remote_identities_sortinghat.json +0 -0
  78. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/data/task-identities-data.json +0 -0
  79. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/data/task-params-expected +0 -0
  80. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/data/task-params-test-projects.json +0 -0
  81. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/data/task-params-test.cfg +0 -0
  82. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/data/url-projects.json +0 -0
  83. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/run_tests.py +0 -0
  84. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/sortinghat_settings.py +0 -0
  85. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/test-no-collection.cfg +0 -0
  86. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/test-no-sh.cfg +0 -0
  87. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/test-projects-no-collection.json +0 -0
  88. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/test-projects.json +0 -0
  89. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/test-repos-projects.json +0 -0
  90. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/test-repos.cfg +0 -0
  91. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/test.cfg +0 -0
  92. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/test_config.py +0 -0
  93. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/test_github.py +0 -0
  94. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/test_healthcheck.py +0 -0
  95. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/test_sirmordred.py +0 -0
  96. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/test_studies.cfg +0 -0
  97. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/test_task_panels.py +0 -0
  98. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/test_task_projects.py +0 -0
  99. {sirmordred-1.0.4 → sirmordred-1.1.3rc1}/tests/test_wrong.cfg +0 -0
@@ -1,27 +1,26 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sirmordred
3
- Version: 1.0.4
3
+ Version: 1.1.3rc1
4
4
  Summary: Drive GrimoireLab tools to produce a dashboard
5
5
  Home-page: https://chaoss.github.io/grimoirelab/
6
6
  License: GPL-3.0+
7
7
  Keywords: development,grimoirelab
8
8
  Author: GrimoireLab Developers
9
- Requires-Python: >=3.8,<4.0
9
+ Requires-Python: >=3.9,<4.0
10
10
  Classifier: Development Status :: 5 - Production/Stable
11
11
  Classifier: Intended Audience :: Developers
12
12
  Classifier: Intended Audience :: Science/Research
13
13
  Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
14
14
  Classifier: Programming Language :: Python :: 3
15
- Classifier: Programming Language :: Python :: 3.8
16
15
  Classifier: Programming Language :: Python :: 3.9
17
16
  Classifier: Programming Language :: Python :: 3.10
18
17
  Classifier: Programming Language :: Python :: 3.11
19
18
  Classifier: Topic :: Software Development
20
19
  Requires-Dist: cereslib (>=0.3)
21
- Requires-Dist: colorlog (==4.1.0)
20
+ Requires-Dist: colorlog (>=6.4.1,<7.0.0)
22
21
  Requires-Dist: elasticsearch (==6.3.1)
23
22
  Requires-Dist: elasticsearch-dsl (==6.3.1)
24
- Requires-Dist: file-read-backwards (==2.0.0)
23
+ Requires-Dist: file-read-backwards (>=3.1.0,<4.0.0)
25
24
  Requires-Dist: graal (>=0.3)
26
25
  Requires-Dist: grimoire-elk (>=0.102)
27
26
  Requires-Dist: grimoirelab-panels (>=0.1)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "sirmordred"
3
- version = "1.0.4"
3
+ version = "1.1.3-rc.1"
4
4
  description = "Drive GrimoireLab tools to produce a dashboard"
5
5
  authors = [
6
6
  "GrimoireLab Developers"
@@ -41,12 +41,12 @@ classifiers = [
41
41
  'panels_config.py' = 'sirmordred.utils.panels_config:main'
42
42
 
43
43
  [tool.poetry.dependencies]
44
- python = "^3.8"
44
+ python = "^3.9"
45
45
 
46
- colorlog = "4.1.0"
46
+ colorlog = "^6.4.1"
47
47
  elasticsearch = "6.3.1"
48
48
  elasticsearch-dsl = "6.3.1"
49
- file-read-backwards = "2.0.0"
49
+ file-read-backwards = "^3.1.0"
50
50
  grimoirelab-toolkit = { version = ">=0.3", allow-prereleases = true}
51
51
  sortinghat = { version = ">=0.7.20", allow-prereleases = true}
52
52
  kidash = { version = ">=0.5", allow-prereleases = true}
@@ -62,8 +62,8 @@ graal = { version = ">=0.3", allow-prereleases = true}
62
62
 
63
63
  [tool.poetry.dev-dependencies]
64
64
  httpretty = "^1.1.4"
65
- flake8 = "^4.0.1"
66
- coverage = "^6.3.2"
65
+ flake8 = "^7.1.1"
66
+ coverage = "^7.2.3"
67
67
 
68
68
  [build-system]
69
69
  requires = ["poetry-core>=1.0.0"]
@@ -0,0 +1,2 @@
1
+ # File auto-generated by semverup on 2024-11-13 15:02:50.234434
2
+ __version__ = "1.1.3-rc.1"
@@ -50,6 +50,7 @@ from sirmordred.task_identities import TaskIdentitiesMerge
50
50
  from sirmordred.task_manager import TasksManager
51
51
  from sirmordred.task_panels import TaskPanels, TaskPanelsMenu
52
52
  from sirmordred.task_projects import TaskProjects
53
+ from sortinghat.cli.client import SortingHatClient
53
54
 
54
55
  logger = logging.getLogger(__name__)
55
56
 
@@ -198,7 +199,7 @@ class SirMordred:
198
199
  repos_backend = self._get_repos_by_backend()
199
200
  for backend in repos_backend:
200
201
  # Start new Threads and add them to the threads list to complete
201
- t = TasksManager(backend_tasks, backend, stopper, self.config, small_delay)
202
+ t = TasksManager(backend_tasks, backend, stopper, self.config, self.client, small_delay)
202
203
  threads.append(t)
203
204
  t.start()
204
205
 
@@ -206,7 +207,7 @@ class SirMordred:
206
207
  if len(global_tasks) > 0:
207
208
  # FIXME timer is applied to all global_tasks, does it make sense?
208
209
  # All tasks are executed in the same thread sequentially
209
- gt = TasksManager(global_tasks, "Global tasks", stopper, self.config, big_delay)
210
+ gt = TasksManager(global_tasks, "Global tasks", stopper, self.config, self.client, big_delay)
210
211
  threads.append(gt)
211
212
  gt.start()
212
213
  if big_delay > 0:
@@ -248,14 +249,14 @@ class SirMordred:
248
249
  if self.conf['phases']['panels']:
249
250
  tasks = [TaskPanels, TaskPanelsMenu]
250
251
  stopper.set()
251
- tm = TasksManager(tasks, "Global tasks", stopper, self.config)
252
+ tm = TasksManager(tasks, "Global tasks", stopper, self.config, self.client)
252
253
  tm.start()
253
254
  tm.join()
254
255
 
255
256
  logger.info("Loading projects")
256
257
  tasks = [TaskProjects]
257
258
  stopper.set()
258
- tm = TasksManager(tasks, "Global tasks", stopper, self.config)
259
+ tm = TasksManager(tasks, "Global tasks", stopper, self.config, self.client)
259
260
  tm.start()
260
261
  tm.join()
261
262
  logger.info("Projects loaded")
@@ -280,7 +281,7 @@ class SirMordred:
280
281
 
281
282
  # check we have access to the needed ES
282
283
  if not self.check_es_access():
283
- print('Can not access Elasticsearch service. Exiting sirmordred ...')
284
+ print('Can not access ElasticSearch/OpenSearch service. Exiting sirmordred ...')
284
285
  sys.exit(1)
285
286
 
286
287
  # If bestiary is configured check that it is working
@@ -289,6 +290,9 @@ class SirMordred:
289
290
  print('Can not access bestiary service. Exiting sirmordred ...')
290
291
  sys.exit(1)
291
292
 
293
+ # Create SortingHat Client
294
+ self.__create_sh_client(self.config)
295
+
292
296
  # Initial round: panels and projects loading
293
297
  self.__execute_initial_load()
294
298
 
@@ -336,3 +340,28 @@ class SirMordred:
336
340
  logger.error(var)
337
341
 
338
342
  logger.info("Finished SirMordred engine ...")
343
+
344
+ def __create_sh_client(self, config):
345
+ self.config = config
346
+ self.conf = config.get_conf()
347
+
348
+ sortinghat = self.conf.get('sortinghat', None)
349
+ self.db_sh = sortinghat['database'] if sortinghat else None
350
+ self.db_user = sortinghat['user'] if sortinghat else None
351
+ self.db_password = sortinghat['password'] if sortinghat else None
352
+ self.db_host = sortinghat['host'] if sortinghat else '127.0.0.1'
353
+ self.db_path = sortinghat.get('path', None) if sortinghat else None
354
+ self.db_port = sortinghat.get('port', None) if sortinghat else None
355
+ self.db_ssl = sortinghat.get('ssl', False) if sortinghat else False
356
+ self.db_verify_ssl = sortinghat.get('verify_ssl', True) if sortinghat else True
357
+ self.db_tenant = sortinghat.get('tenant', True) if sortinghat else None
358
+ self.db_unaffiliate_group = sortinghat['unaffiliated_group'] if sortinghat else None
359
+ if sortinghat and not hasattr(self, 'client'):
360
+ self.client = SortingHatClient(host=self.db_host, port=self.db_port,
361
+ path=self.db_path, ssl=self.db_ssl,
362
+ user=self.db_user, password=self.db_password,
363
+ verify_ssl=self.db_verify_ssl,
364
+ tenant=self.db_tenant)
365
+ self.client.connect()
366
+ elif not sortinghat:
367
+ self.client = None
@@ -29,7 +29,6 @@ import re
29
29
  from grimoire_elk.elk import get_ocean_backend
30
30
  from grimoire_elk.utils import get_connector_from_name, get_elastic
31
31
  from grimoire_elk.enriched.utils import grimoire_con
32
- from sortinghat.cli.client import SortingHatClient
33
32
 
34
33
  logger = logging.getLogger(__name__)
35
34
 
@@ -42,10 +41,11 @@ class Task():
42
41
  'studies', 'node_regex', 'anonymize']
43
42
  PARAMS_WITH_SPACES = ['blacklist-jobs']
44
43
 
45
- def __init__(self, config):
44
+ def __init__(self, config, sortinghat_client=None):
46
45
  self.backend_section = None
47
46
  self.config = config
48
47
  self.conf = config.get_conf()
48
+ self.client = sortinghat_client
49
49
 
50
50
  sortinghat = self.conf.get('sortinghat', None)
51
51
  self.db_sh = sortinghat['database'] if sortinghat else None
@@ -58,15 +58,6 @@ class Task():
58
58
  self.db_verify_ssl = sortinghat.get('verify_ssl', True) if sortinghat else True
59
59
  self.db_tenant = sortinghat.get('tenant', True) if sortinghat else None
60
60
  self.db_unaffiliate_group = sortinghat['unaffiliated_group'] if sortinghat else None
61
- if sortinghat:
62
- self.client = SortingHatClient(host=self.db_host, port=self.db_port,
63
- path=self.db_path, ssl=self.db_ssl,
64
- user=self.db_user, password=self.db_password,
65
- verify_ssl=self.db_verify_ssl,
66
- tenant=self.db_tenant)
67
- self.client.connect()
68
- else:
69
- self.client = None
70
61
 
71
62
  self.grimoire_con = grimoire_con(conn_retries=12) # 30m retry
72
63
 
@@ -156,9 +147,9 @@ class Task():
156
147
  continue
157
148
 
158
149
  # If param is boolean, no values must be added
159
- if type(section_param) == bool:
150
+ if isinstance(section_param, bool):
160
151
  params.append("--" + p) if section_param else None
161
- elif type(section_param) == list:
152
+ elif isinstance(section_param, list):
162
153
  # '--blacklist-jobs', 'a', 'b', 'c'
163
154
  # 'a', 'b', 'c' must be added as items in the list
164
155
  params.append("--" + p)
@@ -43,8 +43,8 @@ logger = logging.getLogger(__name__)
43
43
  class TaskAutorefresh(Task):
44
44
  """Refresh the last modified identities for all the backends."""
45
45
 
46
- def __init__(self, config):
47
- super().__init__(config)
46
+ def __init__(self, config, sortinghat_client):
47
+ super().__init__(config, sortinghat_client)
48
48
 
49
49
  self.last_autorefresh_backend = {}
50
50
 
@@ -41,8 +41,8 @@ logger = logging.getLogger(__name__)
41
41
  class TaskRawDataCollection(Task):
42
42
  """ Basic class shared by all collection tasks """
43
43
 
44
- def __init__(self, config, backend_section=None, allowed_repos=None):
45
- super().__init__(config)
44
+ def __init__(self, config, sortinghat_client=None, backend_section=None, allowed_repos=None):
45
+ super().__init__(config, sortinghat_client)
46
46
 
47
47
  self.backend_section = backend_section
48
48
  self.allowed_repos = set(allowed_repos) if allowed_repos else None
@@ -53,8 +53,8 @@ logger = logging.getLogger(__name__)
53
53
  class TaskEnrich(Task):
54
54
  """ Basic class shared by all enriching tasks """
55
55
 
56
- def __init__(self, config, backend_section=None, allowed_repos=None):
57
- super().__init__(config)
56
+ def __init__(self, config, sortinghat_client, backend_section=None, allowed_repos=None):
57
+ super().__init__(config, sortinghat_client)
58
58
  self.backend_section = backend_section
59
59
  self.allowed_repos = set(allowed_repos) if allowed_repos else None
60
60
  # This will be options in next iteration
@@ -38,8 +38,8 @@ logger = logging.getLogger(__name__)
38
38
  class TaskIdentitiesMerge(Task):
39
39
  """ Task for processing identities in SortingHat """
40
40
 
41
- def __init__(self, conf):
42
- super().__init__(conf)
41
+ def __init__(self, conf, sortinghat_client):
42
+ super().__init__(conf, sortinghat_client)
43
43
  self.last_autorefresh = datetime.utcnow() # Last autorefresh date
44
44
 
45
45
  def is_backend_task(self):
@@ -50,7 +50,7 @@ class TasksManager(threading.Thread):
50
50
  IDENTITIES_TASKS_ON_LOCK = threading.Lock()
51
51
  IDENTITIES_TASKS_ON = False
52
52
 
53
- def __init__(self, tasks_cls, backend_section, stopper, config, timer=0):
53
+ def __init__(self, tasks_cls, backend_section, stopper, config, sortinghat_client, timer=0):
54
54
  """
55
55
  :tasks_cls : tasks classes to be executed using the backend
56
56
  :backend_section: perceval backend section name
@@ -64,6 +64,7 @@ class TasksManager(threading.Thread):
64
64
  self.stopper = stopper # To stop the thread from parent
65
65
  self.timer = timer
66
66
  self.thread_id = None
67
+ self.client = sortinghat_client
67
68
 
68
69
  def add_task(self, task):
69
70
  self.tasks.append(task)
@@ -80,7 +81,7 @@ class TasksManager(threading.Thread):
80
81
  logger.debug(self.tasks_cls)
81
82
  for tc in self.tasks_cls:
82
83
  # create the real Task from the class
83
- task = tc(self.config)
84
+ task = tc(self.config, self.client)
84
85
  task.set_backend_section(self.backend_section)
85
86
  self.tasks.append(task)
86
87
 
@@ -264,8 +264,8 @@ class TaskPanels(Task):
264
264
  # Panels to be uploaded always, no matter the data sources configured
265
265
  panels_common = panels_multi_ds + ["panels/json/about.json"]
266
266
 
267
- def __init__(self, conf):
268
- super().__init__(conf)
267
+ def __init__(self, conf, sortinghat_client=None):
268
+ super().__init__(conf, sortinghat_client)
269
269
  # Read panels and menu description from yaml file
270
270
  with open(self.conf['general']['menu_file'], 'r') as f:
271
271
  try:
@@ -473,8 +473,8 @@ class TaskPanelsMenu(Task):
473
473
  }
474
474
  }
475
475
 
476
- def __init__(self, conf):
477
- super().__init__(conf)
476
+ def __init__(self, conf, sortinghat_client=None):
477
+ super().__init__(conf, sortinghat_client)
478
478
  # Read panels and menu description from yaml file """
479
479
  with open(self.conf['general']['menu_file'], 'r') as f:
480
480
  try:
@@ -33,6 +33,7 @@ from sirmordred.task_identities import TaskIdentitiesMerge
33
33
  from sirmordred.task_enrich import TaskEnrich
34
34
  from sirmordred.task_panels import TaskPanels, TaskPanelsMenu
35
35
  from sirmordred.task_projects import TaskProjects
36
+ from sortinghat.cli.client import SortingHatClient
36
37
 
37
38
  COLOR_LOG_FORMAT_SUFFIX = "\033[1m %(log_color)s "
38
39
  LOG_COLORS = {'DEBUG': 'white', 'INFO': 'cyan', 'WARNING': 'yellow', 'ERROR': 'red', 'CRITICAL': 'red,bg_white'}
@@ -50,6 +51,34 @@ def main():
50
51
  args.panels)
51
52
 
52
53
 
54
+ def create_sortinghat_client(config):
55
+ """Create a SortingHat client"""
56
+
57
+ conf = config.get_conf()
58
+
59
+ sortinghat = conf.get('sortinghat', None)
60
+ if not sortinghat:
61
+ return None
62
+
63
+ db_user = sortinghat['user'] if sortinghat else None
64
+ db_password = sortinghat['password'] if sortinghat else None
65
+ db_host = sortinghat['host'] if sortinghat else '127.0.0.1'
66
+ db_path = sortinghat.get('path', None) if sortinghat else None
67
+ db_port = sortinghat.get('port', None) if sortinghat else None
68
+ db_ssl = sortinghat.get('ssl', False) if sortinghat else False
69
+ db_verify_ssl = sortinghat.get('verify_ssl', True) if sortinghat else True
70
+ db_tenant = sortinghat.get('tenant', True) if sortinghat else None
71
+
72
+ client = SortingHatClient(host=db_host, port=db_port,
73
+ path=db_path, ssl=db_ssl,
74
+ user=db_user, password=db_password,
75
+ verify_ssl=db_verify_ssl,
76
+ tenant=db_tenant)
77
+ client.connect()
78
+
79
+ return client
80
+
81
+
53
82
  def micro_mordred(config, backend_sections, repos_to_check, raw, identities_merge, enrich, panels):
54
83
  """Execute the Mordred tasks using the configuration file.
55
84
 
@@ -66,12 +95,17 @@ def micro_mordred(config, backend_sections, repos_to_check, raw, identities_merg
66
95
  for backend in backend_sections:
67
96
  get_raw(config, backend, repos_to_check)
68
97
 
98
+ if identities_merge or enrich:
99
+ sortinghat_client = create_sortinghat_client(config)
100
+ else:
101
+ sortinghat_client = None
102
+
69
103
  if identities_merge:
70
- get_identities_merge(config)
104
+ get_identities_merge(config, sortinghat_client)
71
105
 
72
106
  if enrich:
73
107
  for backend in backend_sections:
74
- get_enrich(config, backend, repos_to_check)
108
+ get_enrich(config, sortinghat_client, backend, repos_to_check)
75
109
 
76
110
  if panels:
77
111
  get_panels(config)
@@ -97,29 +131,31 @@ def get_raw(config, backend_section, repos_to_check=None):
97
131
  sys.exit(-1)
98
132
 
99
133
 
100
- def get_identities_merge(config):
134
+ def get_identities_merge(config, sortinghat_client):
101
135
  """Execute the merge identities phase
102
136
 
137
+ :param sortinghat_client: a SortingHat client
103
138
  :param config: a Mordred config object
104
139
  """
105
140
  TaskProjects(config).execute()
106
- task = TaskIdentitiesMerge(config)
141
+ task = TaskIdentitiesMerge(config, sortinghat_client)
107
142
  task.execute()
108
143
  logging.info("Merging identities finished!")
109
144
 
110
145
 
111
- def get_enrich(config, backend_section, repos_to_check=None):
146
+ def get_enrich(config, sortinghat_client, backend_section, repos_to_check=None):
112
147
  """Execute the enrich phase for a given backend section
113
148
 
114
149
  Repos are only checked if they are in BOTH `repos_to_check` and the `projects.json`
115
150
 
116
151
  :param config: a Mordred config object
152
+ :param sortinghat_client: a SortingHat client
117
153
  :param backend_section: the backend section where the enrich phase is executed
118
154
  :param repos_to_check: A list of repo URLs to check, or None to check all repos
119
155
  """
120
156
 
121
157
  TaskProjects(config).execute()
122
- task = TaskEnrich(config, backend_section=backend_section, allowed_repos=repos_to_check)
158
+ task = TaskEnrich(config, sortinghat_client, backend_section=backend_section, allowed_repos=repos_to_check)
123
159
  try:
124
160
  task.execute()
125
161
  logging.info("Loading enriched data finished!")
@@ -33,6 +33,8 @@ sys.path.insert(0, '..')
33
33
  from sirmordred.config import Config
34
34
  from sirmordred.task import Task
35
35
 
36
+ from sortinghat.cli.client import SortingHatClient
37
+
36
38
  CONF_FILE = 'test.cfg'
37
39
  BACKEND_NAME = 'stackexchange'
38
40
  COLLECTION_URL_STACKEXCHANGE = 'http://127.0.0.1:9200'
@@ -47,14 +49,23 @@ def read_file(filename, mode='r'):
47
49
 
48
50
  class TestTask(unittest.TestCase):
49
51
  """Task tests"""
52
+ def setUp(self):
53
+ self.config = Config(CONF_FILE)
54
+ self.conf = self.config.get_conf()
55
+ sh = self.conf.get('sortinghat')
56
+ self.sortinghat_client = SortingHatClient(host=sh['host'], port=sh.get('port', None),
57
+ path=sh.get('path', None), ssl=sh.get('ssl', False),
58
+ user=sh['user'], password=sh['password'],
59
+ verify_ssl=sh.get('verify_ssl', True),
60
+ tenant=sh.get('tenant', True))
61
+ self.sortinghat_client.connect()
50
62
 
51
63
  def test_initialization(self):
52
64
  """Test whether attributes are initializated"""
53
65
 
54
- config = Config(CONF_FILE)
55
- task = Task(config)
66
+ task = Task(self.config, self.sortinghat_client)
56
67
 
57
- self.assertEqual(task.config, config)
68
+ self.assertEqual(task.config, self.config)
58
69
  self.assertEqual(task.db_sh, task.conf['sortinghat']['database'])
59
70
  self.assertEqual(task.db_user, task.conf['sortinghat']['user'])
60
71
  self.assertEqual(task.db_password, task.conf['sortinghat']['password'])
@@ -63,15 +74,13 @@ class TestTask(unittest.TestCase):
63
74
  def test_run(self):
64
75
  """Test whether the Task could be run"""
65
76
 
66
- config = Config(CONF_FILE)
67
- task = Task(config)
77
+ task = Task(self.config, self.sortinghat_client)
68
78
  self.assertEqual(task.execute(), None)
69
79
 
70
80
  def test_compose_p2o_params(self):
71
81
  """Test whether p2o params are built correctly for a backend and a repository"""
72
82
 
73
- config = Config(CONF_FILE)
74
- task = Task(config)
83
+ task = Task(self.config, self.sortinghat_client)
75
84
  params = task._compose_p2o_params("stackexchange", "https://stackoverflow.com/questions/tagged/example")
76
85
  self.assertDictEqual(params, {'url': "https://stackoverflow.com/questions/tagged/example"})
77
86
 
@@ -92,8 +101,7 @@ class TestTask(unittest.TestCase):
92
101
  def test_extract_repo_tags(self):
93
102
  """Test the extraction of tags in repositories"""
94
103
 
95
- config = Config(CONF_FILE)
96
- task = Task(config)
104
+ task = Task(self.config, self.sortinghat_client)
97
105
  url, tags = task._extract_repo_tags("git", "https://github.com/zhquan_example/repo --labels=[ENG, SUPP]")
98
106
  self.assertEqual(url, "https://github.com/zhquan_example/repo")
99
107
  self.assertListEqual(tags, ["ENG", "SUPP"])
@@ -113,8 +121,7 @@ class TestTask(unittest.TestCase):
113
121
 
114
122
  expected_repo_params = json.loads(read_file('data/task-params-expected'))
115
123
 
116
- config = Config(CONF_FILE)
117
- task = Task(config)
124
+ task = Task(self.config, self.sortinghat_client)
118
125
 
119
126
  for backend in expected_repo_params.keys():
120
127
  repo = expected_repo_params.get(backend)['repo']
@@ -126,8 +133,7 @@ class TestTask(unittest.TestCase):
126
133
  def test_get_collection_url(self):
127
134
  """Test whether the collection url could be overwritten in a backend"""
128
135
 
129
- config = Config(CONF_FILE)
130
- task = Task(config)
136
+ task = Task(self.config, self.sortinghat_client)
131
137
  task.backend_section = "stackexchange"
132
138
 
133
139
  self.assertEqual(task._get_collection_url(), COLLECTION_URL_STACKEXCHANGE)
@@ -39,7 +39,7 @@ from sirmordred.task_collection import TaskRawDataCollection
39
39
  from sirmordred.task_enrich import TaskEnrich
40
40
  from sirmordred.task_projects import TaskProjects
41
41
 
42
- from sortinghat.cli.client import SortingHatSchema
42
+ from sortinghat.cli.client import SortingHatClient, SortingHatSchema
43
43
 
44
44
  from sgqlc.operation import Operation
45
45
 
@@ -131,8 +131,16 @@ class TestTaskAutorefresh(unittest.TestCase):
131
131
  client.execute(op)
132
132
 
133
133
  def setUp(self):
134
- config = Config(CONF_FILE)
135
- task = TaskAutorefresh(config)
134
+ self.config = Config(CONF_FILE)
135
+ self.conf = self.config.get_conf()
136
+ sh = self.conf.get('sortinghat')
137
+ self.sortinghat_client = SortingHatClient(host=sh['host'], port=sh.get('port', None),
138
+ path=sh.get('path', None), ssl=sh.get('ssl', False),
139
+ user=sh['user'], password=sh['password'],
140
+ verify_ssl=sh.get('verify_ssl', True),
141
+ tenant=sh.get('tenant', True))
142
+ self.sortinghat_client.connect()
143
+ task = TaskAutorefresh(self.config, self.sortinghat_client)
136
144
 
137
145
  # Clean database
138
146
  entities = SortingHat.unique_identities(task.client)
@@ -162,16 +170,14 @@ class TestTaskAutorefresh(unittest.TestCase):
162
170
  def test_initialization(self):
163
171
  """Test whether attributes are initialized"""
164
172
 
165
- config = Config(CONF_FILE)
166
- task = TaskAutorefresh(config)
173
+ task = TaskAutorefresh(self.config, self.sortinghat_client)
167
174
 
168
- self.assertEqual(task.config, config)
175
+ self.assertEqual(task.config, self.config)
169
176
 
170
177
  def test_is_backend_task(self):
171
178
  """Test whether the Task is not a backend task"""
172
179
 
173
- config = Config(CONF_FILE)
174
- task = TaskAutorefresh(config)
180
+ task = TaskAutorefresh(self.config, self.sortinghat_client)
175
181
 
176
182
  self.assertFalse(task.is_backend_task())
177
183
 
@@ -179,18 +185,16 @@ class TestTaskAutorefresh(unittest.TestCase):
179
185
  """Test whether the Task could be run"""
180
186
 
181
187
  # Create a raw and enriched indexes
182
- config = Config(CONF_FILE)
183
-
184
- TaskProjects(config).execute()
188
+ TaskProjects(self.config, self.sortinghat_client).execute()
185
189
  backend_section = GIT_BACKEND_SECTION
186
190
 
187
- task_collection = TaskRawDataCollection(config, backend_section=backend_section)
191
+ task_collection = TaskRawDataCollection(self.config, backend_section=backend_section)
188
192
  task_collection.execute()
189
193
 
190
- task_enrich = TaskEnrich(config, backend_section=backend_section)
194
+ task_enrich = TaskEnrich(self.config, self.sortinghat_client, backend_section=backend_section)
191
195
  task_enrich.execute()
192
196
 
193
- task_autorefresh = TaskAutorefresh(config)
197
+ task_autorefresh = TaskAutorefresh(self.config, self.sortinghat_client)
194
198
  task_autorefresh.config.set_param('es_enrichment', 'autorefresh', True)
195
199
  # This does nothing because it uses now as from_date:
196
200
  task_autorefresh.execute()
@@ -205,7 +209,7 @@ class TestTaskAutorefresh(unittest.TestCase):
205
209
  self.assertIsNone(task_autorefresh.execute())
206
210
 
207
211
  # Check that the autorefresh went well
208
- cfg = config.get_conf()
212
+ cfg = self.conf
209
213
  es_enrichment = cfg['es_enrichment']['url']
210
214
  enrich_index = es_enrichment + "/" + cfg[GIT_BACKEND_SECTION]['enriched_index']
211
215
 
@@ -111,7 +111,8 @@ class TestTaskRawDataCollection(unittest.TestCase):
111
111
  raw_index = es_collection + "/" + cfg[GIT_BACKEND_SECTION]['raw_index']
112
112
 
113
113
  r = requests.get(raw_index + "/_search?size=0", verify=False)
114
- raw_items = r.json()['hits']['total']
114
+ total = r.json()['hits']['total']
115
+ raw_items = total['value'] if isinstance(total, dict) else total
115
116
  self.assertEqual(raw_items, 3603)
116
117
 
117
118
  def test_execute_no_collection(self):
@@ -130,7 +131,8 @@ class TestTaskRawDataCollection(unittest.TestCase):
130
131
  raw_index = es_collection + "/" + cfg[GIT_BACKEND_SECTION]['raw_index']
131
132
 
132
133
  r = requests.get(raw_index + "/_search?size=0", verify=False)
133
- raw_items = r.json()['hits']['total']
134
+ total = r.json()['hits']['total']
135
+ raw_items = total['value'] if isinstance(total, dict) else total
134
136
  self.assertEqual(raw_items, 40)
135
137
 
136
138
  def test_execute_filter_no_collection(self):