deployv 0.9.230__tar.gz → 0.9.232__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 (63) hide show
  1. {deployv-0.9.230 → deployv-0.9.232}/PKG-INFO +1 -1
  2. {deployv-0.9.230 → deployv-0.9.232}/deployv/__init__.py +1 -1
  3. {deployv-0.9.230 → deployv-0.9.232}/deployv/base/clonev.py +1 -2
  4. {deployv-0.9.230 → deployv-0.9.232}/deployv/base/commandv.py +105 -9
  5. {deployv-0.9.230 → deployv-0.9.232}/deployv/base/postgresv.py +36 -0
  6. {deployv-0.9.230 → deployv-0.9.232}/deployv/commands/deployvcmd.py +3 -1
  7. {deployv-0.9.230 → deployv-0.9.232}/deployv/helpers/database_helper.py +54 -6
  8. {deployv-0.9.230 → deployv-0.9.232}/deployv/helpers/utils.py +42 -4
  9. {deployv-0.9.230 → deployv-0.9.232}/deployv/instance/instancev.py +52 -0
  10. {deployv-0.9.230 → deployv-0.9.232}/deployv.egg-info/PKG-INFO +1 -1
  11. {deployv-0.9.230 → deployv-0.9.232}/setup.py +1 -1
  12. {deployv-0.9.230 → deployv-0.9.232}/AUTHORS.rst +0 -0
  13. {deployv-0.9.230 → deployv-0.9.232}/CONTRIBUTING.rst +0 -0
  14. {deployv-0.9.230 → deployv-0.9.232}/LICENSE +0 -0
  15. {deployv-0.9.230 → deployv-0.9.232}/MANIFEST.in +0 -0
  16. {deployv-0.9.230 → deployv-0.9.232}/README.md +0 -0
  17. {deployv-0.9.230 → deployv-0.9.232}/deployv/base/__init__.py +0 -0
  18. {deployv-0.9.230 → deployv-0.9.232}/deployv/base/dockerv.py +0 -0
  19. {deployv-0.9.230 → deployv-0.9.232}/deployv/base/errors.py +0 -0
  20. {deployv-0.9.230 → deployv-0.9.232}/deployv/base/extensions_core.py +0 -0
  21. {deployv-0.9.230 → deployv-0.9.232}/deployv/base/nginxv.py +0 -0
  22. {deployv-0.9.230 → deployv-0.9.232}/deployv/base/update_production.py +0 -0
  23. {deployv-0.9.230 → deployv-0.9.232}/deployv/base/worker.py +0 -0
  24. {deployv-0.9.230 → deployv-0.9.232}/deployv/commands/__init__.py +0 -0
  25. {deployv-0.9.230 → deployv-0.9.232}/deployv/commands/updatev.py +0 -0
  26. {deployv-0.9.230 → deployv-0.9.232}/deployv/commands/workerv.py +0 -0
  27. {deployv-0.9.230 → deployv-0.9.232}/deployv/extensions/__init__.py +0 -0
  28. {deployv-0.9.230 → deployv-0.9.232}/deployv/extensions/checkers.py +0 -0
  29. {deployv-0.9.230 → deployv-0.9.232}/deployv/helpers/__init__.py +0 -0
  30. {deployv-0.9.230 → deployv-0.9.232}/deployv/helpers/backup.py +0 -0
  31. {deployv-0.9.230 → deployv-0.9.232}/deployv/helpers/build_helper.py +0 -0
  32. {deployv-0.9.230 → deployv-0.9.232}/deployv/helpers/clone_oca_dependencies.py +0 -0
  33. {deployv-0.9.230 → deployv-0.9.232}/deployv/helpers/configuration_helper.py +0 -0
  34. {deployv-0.9.230 → deployv-0.9.232}/deployv/helpers/container.py +0 -0
  35. {deployv-0.9.230 → deployv-0.9.232}/deployv/helpers/decompress_helper.py +0 -0
  36. {deployv-0.9.230 → deployv-0.9.232}/deployv/helpers/git_helper.py +0 -0
  37. {deployv-0.9.230 → deployv-0.9.232}/deployv/helpers/json_helper.py +0 -0
  38. {deployv-0.9.230 → deployv-0.9.232}/deployv/helpers/json_schemas/base.json +0 -0
  39. {deployv-0.9.230 → deployv-0.9.232}/deployv/helpers/json_schemas/deploy_deploy.json +0 -0
  40. {deployv-0.9.230 → deployv-0.9.232}/deployv/helpers/pg_anon.py +0 -0
  41. {deployv-0.9.230 → deployv-0.9.232}/deployv/helpers/sender_message.py +0 -0
  42. {deployv-0.9.230 → deployv-0.9.232}/deployv/instance/__init__.py +0 -0
  43. {deployv-0.9.230 → deployv-0.9.232}/deployv/messaging/__init__.py +0 -0
  44. {deployv-0.9.230 → deployv-0.9.232}/deployv/messaging/basemsg.py +0 -0
  45. {deployv-0.9.230 → deployv-0.9.232}/deployv/messaging/http/__init__.py +0 -0
  46. {deployv-0.9.230 → deployv-0.9.232}/deployv/messaging/http/httpv.py +0 -0
  47. {deployv-0.9.230 → deployv-0.9.232}/deployv/messaging/http/receiverv.py +0 -0
  48. {deployv-0.9.230 → deployv-0.9.232}/deployv/messaging/http/senderv.py +0 -0
  49. {deployv-0.9.230 → deployv-0.9.232}/deployv/messaging/http/worker.py +0 -0
  50. {deployv-0.9.230 → deployv-0.9.232}/deployv/messaging/rabbit/__init__.py +0 -0
  51. {deployv-0.9.230 → deployv-0.9.232}/deployv/messaging/rabbit/rabbitv.py +0 -0
  52. {deployv-0.9.230 → deployv-0.9.232}/deployv/messaging/rabbit/receiverv.py +0 -0
  53. {deployv-0.9.230 → deployv-0.9.232}/deployv/messaging/rabbit/senderv.py +0 -0
  54. {deployv-0.9.230 → deployv-0.9.232}/deployv/messaging/rabbit/worker.py +0 -0
  55. {deployv-0.9.230 → deployv-0.9.232}/deployv.egg-info/SOURCES.txt +0 -0
  56. {deployv-0.9.230 → deployv-0.9.232}/deployv.egg-info/dependency_links.txt +0 -0
  57. {deployv-0.9.230 → deployv-0.9.232}/deployv.egg-info/entry_points.txt +0 -0
  58. {deployv-0.9.230 → deployv-0.9.232}/deployv.egg-info/not-zip-safe +0 -0
  59. {deployv-0.9.230 → deployv-0.9.232}/deployv.egg-info/requires.txt +0 -0
  60. {deployv-0.9.230 → deployv-0.9.232}/deployv.egg-info/top_level.txt +0 -0
  61. {deployv-0.9.230 → deployv-0.9.232}/requirements.txt +0 -0
  62. {deployv-0.9.230 → deployv-0.9.232}/setup.cfg +0 -0
  63. {deployv-0.9.230 → deployv-0.9.232}/test-requirements.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: deployv
3
- Version: 0.9.230
3
+ Version: 0.9.232
4
4
  Summary: Base for all clases and scripts in VauxooTools
5
5
  Home-page: https://git.vauxoo.com/deployv/deployv
6
6
  Download-URL: https://git.vauxoo.com/deployv/deployv
@@ -9,7 +9,7 @@ start, update and build instances.
9
9
  import logging
10
10
 
11
11
  __author__ = 'Tulio Ruiz <tulio@vauxoo.com>'
12
- __version__ = '0.9.230'
12
+ __version__ = '0.9.232'
13
13
  __all__ = ['base', 'helpers', 'instance', 'messaging']
14
14
 
15
15
  logging.basicConfig(
@@ -68,8 +68,7 @@ class CloneV:
68
68
  if not self.instance_manager.config_variables.get('version'):
69
69
  raise BuildError('You need to specify a version in '
70
70
  ' your "variables.sh" file in the repository')
71
- odoo_url = 'https://github.com/%s.git' % (
72
- self.instance_manager.config_variables.get('odoo_repo'))
71
+ odoo_url = utils.odoo_repo_url(self.instance_manager.config_variables.get('odoo_repo'))
73
72
  # TODO: it's easier to create the dict directly with these values instead of
74
73
  # adding and calling a method to do so (utils.add_repo())
75
74
  extra_repos = [('odoo', odoo_url, 'odoo',
@@ -72,6 +72,8 @@ STATES = [
72
72
  DEPLOYV_SOCKET = '/var/run/deployv/deployv.sock'
73
73
  ORCHESTSH_SOCKET = '/var/run/orchestsh/orchestsh.sock'
74
74
  ORCHESTSH_NOT_RUNNING = 'orchestsh socketserver is not running on this server'
75
+ # The UID OrchestSh gives the filestore to, the one the images it builds have.
76
+ ORCHESTSH_ODOO_UID = 5410
75
77
 
76
78
 
77
79
  def _as_list(value):
@@ -80,6 +82,45 @@ def _as_list(value):
80
82
  return [value] if isinstance(value, str) else list(value)
81
83
 
82
84
 
85
+ def orchestsh_operation_id(answer):
86
+ """Returns the ID of the OrchestSh operation that answered a request to
87
+ `orchestsh socketserver`. Socket servers older than the operation tracing do not send it.
88
+
89
+ :param answer: The JSON answer of the socket.
90
+ :type answer: dict
91
+ :return: The operation ID (`op_...`), or an empty string when the answer has none.
92
+ :rtype: str
93
+ """
94
+ if not isinstance(answer, dict):
95
+ return ''
96
+ operation_id = answer.get('operation_id')
97
+ if not isinstance(operation_id, str):
98
+ return ''
99
+ return operation_id.strip()
100
+
101
+
102
+ def with_orchestsh_operation(message, answer):
103
+ """Adds the OrchestSh operation of `answer` to an error message, so the user who sees the
104
+ failed task has an ID to report and to follow in OrchestSh.
105
+
106
+ :param message: The error message, may be empty or None.
107
+ :type message: str
108
+ :param answer: The JSON answer of the socket the error came from.
109
+ :type answer: dict
110
+ :return: `message` followed by ` (OrchestSh operation <operation_id>)`, or `message`
111
+ unchanged when it is empty, the answer has no operation ID or the message already
112
+ ends with it.
113
+ :rtype: str
114
+ """
115
+ operation_id = orchestsh_operation_id(answer)
116
+ if not message or not operation_id:
117
+ return message
118
+ suffix = ' (OrchestSh operation {})'.format(operation_id)
119
+ if message.endswith(suffix):
120
+ return message
121
+ return message + suffix
122
+
123
+
83
124
  def add_orchestsh_transitions(transitions):
84
125
  """Makes the `orchestsh` backup type follow the same transitions as `zfs`.
85
126
 
@@ -771,7 +812,9 @@ class CommandV(Extensible):
771
812
 
772
813
  For orchestsh, a socket that is missing, refuses the connection or does not answer JSON
773
814
  gives `{'code': 503, 'error': ...}` instead of an exception, so the user gets a message
774
- and not a stack trace. btrfs and zfs behave as before.
815
+ and not a stack trace. When the answer has an `operation_id`, it is logged with the
816
+ `lease_id` and `workflow_id` of the answer, and the `error` of an error answer ends with
817
+ the operation (see :func:`with_orchestsh_operation`). btrfs and zfs behave as before.
775
818
 
776
819
  :param method: `post` (create the database) or `delete` (drop it).
777
820
  :param restore_type: See :meth:`_make_socket_request`.
@@ -787,12 +830,21 @@ class CommandV(Extensible):
787
830
  logger.error('%s (%s): %s', ORCHESTSH_NOT_RUNNING, ORCHESTSH_SOCKET, error)
788
831
  return {'code': 503, 'error': ORCHESTSH_NOT_RUNNING}
789
832
  try:
790
- return response.json()
833
+ answer = response.json()
791
834
  except ValueError:
792
835
  logger.error('orchestsh socketserver answered HTTP %s without JSON: %s',
793
836
  response.status_code, response.text)
794
837
  return {'code': 503, 'error': 'orchestsh socketserver answered HTTP {} without JSON'
795
838
  .format(response.status_code)}
839
+ operation_id = orchestsh_operation_id(answer)
840
+ if operation_id:
841
+ logger.info('orchestsh operation %s (lease %s, workflow %s): %s /restore of task %s '
842
+ 'answered %s', operation_id, answer.get('lease_id') or '-',
843
+ answer.get('workflow_id') or '-', method.upper(),
844
+ self.__config.instance_config.get('task_id'), answer.get('code'))
845
+ if answer.get('code') and answer.get('code') != 200 and answer.get('error'):
846
+ answer['error'] = with_orchestsh_operation(answer['error'], answer)
847
+ return answer
796
848
 
797
849
  def _use_orchestsh_data(self, answer):
798
850
  """Points the instance at the database and filestore that `orchestsh socketserver`
@@ -824,6 +876,37 @@ class CommandV(Extensible):
824
876
  vol=filestore_volume)})
825
877
  return db_host, db_port, volumes
826
878
 
879
+ def _check_orchestsh_filestore_access(self, answer, volumes):
880
+ """Nothing changes the owner of a filestore of orchestsh: a chown through its overlay
881
+ would copy every file up. So an image built with deployv, whose odoo user has any UID,
882
+ could not write there unless the lease opened the permissions. Without this check that
883
+ only shows up later, as attachments Odoo cannot save.
884
+
885
+ :param answer: Answer of POST /restore with code 200.
886
+ :type answer: dict
887
+ :param volumes: The docker volumes of the filestore, empty without filestore.
888
+ :type volumes: dict
889
+ :return: The error message, or None when the image can use the filestore.
890
+ :rtype: str or None
891
+ """
892
+ if not volumes or answer.get('filestore_open_permissions'):
893
+ return None
894
+ uid_res = self.instance_manager.exec_cmd_image('id -u odoo', volumes)
895
+ if uid_res.get('error'):
896
+ return 'Could not read the UID of the odoo user of the image: {}'.format(
897
+ uid_res.get('error'))
898
+ # The entrypoint of the image may log something before the command.
899
+ output = uid_res.get('result', '').split()
900
+ if not output or not output[-1].isdigit():
901
+ return 'Could not read the UID of the odoo user of the image: {}'.format(
902
+ uid_res.get('result'))
903
+ if int(output[-1]) == ORCHESTSH_ODOO_UID:
904
+ return None
905
+ return ('The odoo user of the image has UID {uid}, so it cannot write in the filestore '
906
+ 'of OrchestSh, which belongs to UID {owner}. Use an image built with OrchestSh '
907
+ 'or turn on "Open Filestore Permissions" in the instance and restore '
908
+ 'again.').format(uid=output[-1], owner=ORCHESTSH_ODOO_UID)
909
+
827
910
  def _reload_orchestsh_data(self):
828
911
  """On a reload_config with backup_type orchestsh no restore runs, so the database and
829
912
  filestore the task already has are asked to orchestsh socketserver (W_KEEPDB answers the
@@ -836,11 +919,14 @@ class CommandV(Extensible):
836
919
  return None
837
920
  answer = self._socket_restore('post', restore_type='W_KEEPDB')
838
921
  if answer.get('code') and answer.get('code') != 200:
839
- return answer.get('error') or 'orchestsh socketserver answered {}'.format(
840
- answer.get('code'))
841
- if not self._use_orchestsh_data(answer):
842
- return 'orchestsh socketserver did not return db_host and db_port'
843
- return None
922
+ return answer.get('error') or with_orchestsh_operation(
923
+ 'orchestsh socketserver answered {}'.format(answer.get('code')), answer)
924
+ orchestsh_data = self._use_orchestsh_data(answer)
925
+ if not orchestsh_data:
926
+ return with_orchestsh_operation(
927
+ 'orchestsh socketserver did not return db_host and db_port', answer)
928
+ return with_orchestsh_operation(
929
+ self._check_orchestsh_filestore_access(answer, orchestsh_data[2]), answer)
844
930
 
845
931
  @events
846
932
  def restore_snapshot(self):
@@ -864,10 +950,19 @@ class CommandV(Extensible):
864
950
  if self.use_orchestsh():
865
951
  orchestsh_data = self._use_orchestsh_data(request_res)
866
952
  if not orchestsh_data:
867
- res.update({'error': 'orchestsh socketserver did not return db_host and db_port'})
953
+ res.update({'error': with_orchestsh_operation(
954
+ 'orchestsh socketserver did not return db_host and db_port', request_res)})
868
955
  self.send_message_error(res, ['restore', 'total_process'])
869
956
  return res
870
957
  db_host, db_port, volumes = orchestsh_data
958
+ access_error = self._check_orchestsh_filestore_access(request_res, volumes)
959
+ if access_error:
960
+ # Turning on the option only helps a new lease, and a lease left
961
+ # behind would only be replaced by the next restore.
962
+ self._socket_restore('delete')
963
+ res.update({'error': with_orchestsh_operation(access_error, request_res)})
964
+ self.send_message_error(res, ['restore', 'total_process'])
965
+ return res
871
966
  else:
872
967
  # The zfs socket does not return the abs path of the filestore.
873
968
  if not os.path.isabs(res['result'].get('filestore_path')):
@@ -901,7 +996,8 @@ class CommandV(Extensible):
901
996
  'database.type': self.instance_manager.instance_type}
902
997
  self.instance_manager.set_parameters(database_name, params)
903
998
  self.new_deactivate(db_config)
904
- if volumes:
999
+ # Never for orchestsh: a chown through its overlay would copy every file up.
1000
+ if volumes and not self.use_orchestsh():
905
1001
  bash_lines = ["chown -R odoo:odoo /home/odoo/.local"]
906
1002
  cmd_res = self.instance_manager.execute_in_auxiliary_container(database_name,
907
1003
  bash_lines, volumes)
@@ -340,6 +340,42 @@ class PostgresShell:
340
340
  logger.info('Creating extension unaccent in the database %s', database_name)
341
341
  self.create_extension(database_name, 'unaccent')
342
342
 
343
+ def prepare_unaccent(self, database_name):
344
+ """ Marks unaccent IMMUTABLE in database_name and tells whether the database
345
+ can hold the indexes Odoo builds over unaccent() with gin_trgm_ops.
346
+
347
+ pg_dump does not carry the volatility of an extension's functions, so every
348
+ restored database needs it again before pg_restore creates those indexes.
349
+ ALTER FUNCTION needs the owner of the function, generally a superuser; when
350
+ it fails, or the connection does, the error is logged and the returned state
351
+ says so.
352
+
353
+ :param database_name: The database to prepare
354
+ :return: Dict with ``immutable`` (unaccent(text) is IMMUTABLE) and ``trgm``
355
+ (pg_trgm is installed)
356
+ :rtype: dict
357
+ """
358
+ config = self.__config.copy()
359
+ config.update({'dbname': database_name})
360
+ try:
361
+ with PostgresConnector(config) as db:
362
+ for signature in ('unaccent(text)', 'unaccent(regdictionary, text)'):
363
+ try:
364
+ db.execute("ALTER FUNCTION {} IMMUTABLE;".format(signature))
365
+ except psycopg2.Error as error:
366
+ logger.error('Unable to mark %s IMMUTABLE in the database %s: %s',
367
+ signature, database_name,
368
+ utils.get_error_message(error).strip())
369
+ res = db.execute(
370
+ "SELECT coalesce((SELECT provolatile = 'i' FROM pg_proc"
371
+ " WHERE oid = to_regprocedure('unaccent(text)')), false) AS immutable,"
372
+ " EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'pg_trgm') AS trgm;")
373
+ except OperationalError as error:
374
+ logger.error('Unable to prepare unaccent in the database %s: %s',
375
+ database_name, utils.get_error_message(error).strip())
376
+ return {'immutable': False, 'trgm': False}
377
+ return res[0]
378
+
343
379
  def create_extension(self, database_name, extension_name):
344
380
  """ Creates the given extension_name in the database_name.
345
381
  The credentials must have permission to create extensions, generally a superuser.
@@ -446,7 +446,9 @@ def deactivate_backup(ctx, prefix, store_path, backup_src, admin_password,
446
446
  help="Removes the working folder if it already exists before creating it again")
447
447
  @click.option("-O", "--odoo-repo",
448
448
  help=("Specific odoo repository to be cloned instead of the default one, must be"
449
- " in the format namespace/reponame#branch. Example: odoo/odoo#8.0"))
449
+ " in the format namespace/reponame#branch or a full git URL followed by"
450
+ " #branch. Examples: odoo/odoo#8.0,"
451
+ " git@github.com:Vauxoo/odoo-eol.git#15.0"))
450
452
  @click.option("-T", "--tag", default=False,
451
453
  help="Custom name for the new image, if not specified a name will be generated")
452
454
  @click.option("--skip-push", is_flag=True, default=False,
@@ -7,6 +7,10 @@ import zipfile
7
7
 
8
8
  _logger = logging.getLogger(__name__)
9
9
 
10
+ # Extensions every restored database gets, before the configured ones: Odoo's search
11
+ # indexes use them, and dumps made without superuser do not create them.
12
+ BASE_EXTENSIONS = ['unaccent', 'pg_trgm']
13
+
10
14
 
11
15
  class DatabaseHelper:
12
16
 
@@ -92,8 +96,9 @@ class RestoreBackup(DatabaseHelper):
92
96
  _logger.warning('the backup was not created with parallel jobs')
93
97
  elif os.path.isdir(dump):
94
98
  jobs = kwargs.get("jobs") or 5
95
- self._restore_backup(dump, db_name, db_owner, db_owner_password, jobs=jobs)
96
- return (True, db_name)
99
+ unaccent_immutable = utils.read_manifest(dest_dir).get('unaccent_immutable', False)
100
+ return self._restore_backup(dump, db_name, db_owner, db_owner_password, jobs=jobs,
101
+ unaccent_immutable=unaccent_immutable)
97
102
 
98
103
  def _check_backup_folder(self, backup_src, customer_id):
99
104
  valid_backups = ['dump.sql', 'database_dump.sql', 'database_dump.b64', "database_dump"]
@@ -141,17 +146,60 @@ class RestoreBackup(DatabaseHelper):
141
146
  return dump_name
142
147
 
143
148
  def _create_extensions(self, database_name):
149
+ """ Creates BASE_EXTENSIONS and the configured extensions in database_name, then
150
+ marks unaccent IMMUTABLE.
151
+
152
+ :return: The state returned by PostgresShell.prepare_unaccent
153
+ :rtype: dict
154
+ """
144
155
  postgres_admin = postgresv.PostgresShell(self.db_admin_config)
145
- for ext in self.db_extensions:
156
+ extensions = BASE_EXTENSIONS + [ext for ext in self.db_extensions
157
+ if ext not in BASE_EXTENSIONS]
158
+ for ext in extensions:
146
159
  postgres_admin.create_extension(database_name, ext)
160
+ return postgres_admin.prepare_unaccent(database_name)
161
+
162
+ @staticmethod
163
+ def _unaccent_missing(state):
164
+ """ Says what the database lacks for the indexes Odoo builds over unaccent().
165
+
166
+ :param state: The state returned by PostgresShell.prepare_unaccent
167
+ :return: The missing pieces, empty when there are none
168
+ :rtype: list
169
+ """
170
+ missing = []
171
+ if not state.get('immutable'):
172
+ missing.append('unaccent(text) is not IMMUTABLE (ALTER FUNCTION needs the owner'
173
+ ' of the function, a superuser)')
174
+ if not state.get('trgm'):
175
+ missing.append('the pg_trgm extension is missing')
176
+ return missing
147
177
 
148
178
  def _restore_backup(self, dump_name, database_name, db_owner, db_owner_password,
149
- jobs=False):
179
+ jobs=False, unaccent_immutable=False):
180
+ """ Recreates database_name and restores dump_name into it.
181
+
182
+ When the backup recorded unaccent as IMMUTABLE, its dump has indexes over
183
+ unaccent() with gin_trgm_ops that pg_restore rejects unless the database is
184
+ prepared, so the restore is not attempted if it could not be. Other backups
185
+ are restored anyway and the missing pieces are only logged.
186
+
187
+ :return: (True, database_name), or (False, reason) when the restore was not attempted
188
+ :rtype: tuple
189
+ """
150
190
  self.db_config.update({'database': database_name, 'owner': db_owner,
151
191
  'owner_password': db_owner_password})
152
192
  postgres = postgresv.PostgresShell(self.db_config)
153
193
  postgres.drop(database_name, force=True)
154
194
  postgres.create(database_name)
155
- self._create_extensions(database_name)
195
+ missing = self._unaccent_missing(self._create_extensions(database_name))
196
+ if missing and unaccent_immutable:
197
+ return (False, 'The backup has indexes over unaccent() with gin_trgm_ops, which'
198
+ ' pg_restore would reject, and the database {db} could not be'
199
+ ' prepared: {missing}. Check that the postgres user of deployv.conf'
200
+ ' is a superuser.'.format(db=database_name, missing='; '.join(missing)))
201
+ if missing:
202
+ _logger.warning('The database %s may not restore the indexes over unaccent(): %s',
203
+ database_name, '; '.join(missing))
156
204
  postgres.restore(database_name, dump_name, jobs=jobs)
157
- return True
205
+ return (True, database_name)
@@ -29,6 +29,7 @@ import socket
29
29
  import fcntl
30
30
  import struct
31
31
  import ipaddress
32
+ from urllib.parse import urlsplit
32
33
 
33
34
  _AVAILABLES = {
34
35
  "production": ['update_production', 'post_process', 'restart_instance',
@@ -936,6 +937,40 @@ def parse_repo_url(repo_url):
936
937
  return values
937
938
 
938
939
 
940
+ def odoo_repo_url(odoo_repo):
941
+ """Returns the URL to clone Odoo from the ``ODOO_REPO`` value.
942
+
943
+ A full git URL (with a scheme such as ``https://`` or ``ssh://``, or the scp-like
944
+ ``git@host:owner/repo.git``) is returned as it is, so a private repository is cloned with the
945
+ same SSH key as the private repositories of ``oca_dependencies.txt``. Anything else is a GitHub
946
+ ``owner/repo`` shorthand.
947
+
948
+ A URL that carries credentials is rejected, because the clone URL is kept in the
949
+ ``.git/config`` of the image and printed in the build log.
950
+
951
+ :param odoo_repo: Value of ``ODOO_REPO``, e.g. ``vauxoo/odoo`` or
952
+ ``git@github.com:Vauxoo/odoo-eol.git``
953
+ :return: The URL to clone
954
+ :raises BuildError: If the value carries credentials
955
+ """
956
+ if odoo_repo.startswith('git@'):
957
+ return odoo_repo
958
+ credentials_error = base.errors.BuildError(
959
+ 'ODOO_REPO must not carry credentials; use the SSH form,'
960
+ ' e.g. git@github.com:owner/repo.git')
961
+ if '://' not in odoo_repo:
962
+ if '@' in odoo_repo:
963
+ raise credentials_error
964
+ return 'https://github.com/%s.git' % odoo_repo
965
+ try:
966
+ parts = urlsplit(odoo_repo)
967
+ except ValueError:
968
+ raise base.errors.BuildError('ODOO_REPO is not a valid URL') from None
969
+ if parts.password is not None or parts.username and parts.scheme in ('http', 'https'):
970
+ raise credentials_error
971
+ return odoo_repo
972
+
973
+
939
974
  def read_lines(filename):
940
975
  """Returns a file content as a list, no blank lines and stipped
941
976
 
@@ -981,8 +1016,9 @@ def read_manifest(backup_path):
981
1016
  manifest shape: a copy of its `manifest` sub-object (or ``{}`` when it is
982
1017
  missing or null) with `database_extensions` set from its
983
1018
  `postgresql.extensions` sub-object (or ``{}`` when it is missing or
984
- null). When no `metadata.json` exists, the legacy `manifest.json` is read
985
- and returned unchanged.
1019
+ null), plus `unaccent_immutable` set to True when
1020
+ `postgresql.unaccent_immutable` is. When no `metadata.json` exists, the
1021
+ legacy `manifest.json` is read and returned unchanged.
986
1022
 
987
1023
  This method is used to avoid adding more complexity to the
988
1024
  `InstanceV.restore_database` method.
@@ -1000,8 +1036,10 @@ def read_manifest(backup_path):
1000
1036
  logger.warning("Could not parse metadata file %s", metadata_file)
1001
1037
  return {}
1002
1038
  manifest_data = dict(metadata.get('manifest') or {})
1003
- extensions = (metadata.get('postgresql') or {}).get('extensions') or {}
1004
- manifest_data['database_extensions'] = dict(extensions)
1039
+ postgresql = metadata.get('postgresql') or {}
1040
+ manifest_data['database_extensions'] = dict(postgresql.get('extensions') or {})
1041
+ if postgresql.get('unaccent_immutable'):
1042
+ manifest_data['unaccent_immutable'] = True
1005
1043
  return manifest_data
1006
1044
  logger.debug("Searching for a manifest.json in the path %s", backup_path)
1007
1045
  manifest_file = os.path.join(backup_path, 'manifest.json')
@@ -82,6 +82,7 @@ from os import path, mkdir
82
82
  from uuid import uuid4
83
83
  import shutil
84
84
  import time
85
+ import re
85
86
  import psycopg2
86
87
  from psycopg2 import sql as psycopg2_sql
87
88
  from docker.errors import APIError, ContainerError
@@ -1847,6 +1848,53 @@ class InstanceV(DockerV):
1847
1848
  else:
1848
1849
  raise error
1849
1850
 
1851
+ def neutralize_odoo(self, db_name):
1852
+ """Executes the Odoo's neutralize command over the provided database. The command was
1853
+ added in Odoo 16.0, so it is skipped for older versions, and any failure is only logged
1854
+ to let the deactivation continue.
1855
+
1856
+ :param db_name: Name of the database to be neutralized
1857
+ :return: dict with the result of the command, or with the key error when it fails
1858
+ """
1859
+ version = str(self.config_variables.get('version') or '')
1860
+ major_version = re.search(r'\d+', version)
1861
+ if major_version and int(major_version.group()) < 16:
1862
+ logger.info('Odoo %s does not support the neutralize command, skipping it', version)
1863
+ return {}
1864
+ image_name = self.config.get('image_name') or self.basic_info.get('image_name')
1865
+ working_folder = path.join(self.config.get("working_folder"),
1866
+ self.config.get('container_name'))
1867
+ data_dir = self.get_data_dir()
1868
+ working_folder = data_dir.replace('filestore', '') if data_dir else working_folder
1869
+ for entrypoint in ['/entry_point', '/entrypoint', '/entry_point.py']:
1870
+ entrypoint_exists = self.exec_cmd_image(
1871
+ 'test -x %s' % entrypoint, self.config.get('volumes'),
1872
+ working_folder, image=image_name)
1873
+ if not entrypoint_exists.get('error'):
1874
+ break
1875
+ odoo_conf_exists = self.exec_cmd_image(
1876
+ 'test -f /home/odoo/.odoorc', self.config.get('volumes'),
1877
+ working_folder, image=image_name)
1878
+ odoo_conf_file = ('/home/odoo/.odoorc' if not odoo_conf_exists.get('error') else
1879
+ '/home/odoo/.openerp_serverrc')
1880
+ neutralize_command = (
1881
+ "{entrypoint} run --user odoo '/home/odoo/instance/odoo/{odoo}"
1882
+ " neutralize -c {odoo_conf} {db_args} -d {database}'"
1883
+ .format(entrypoint=entrypoint, odoo=self.odoo_binary, database=db_name,
1884
+ odoo_conf=odoo_conf_file, db_args=self.direct_db_args))
1885
+ try:
1886
+ res = self.exec_cmd_image(neutralize_command, self.config.get('volumes'),
1887
+ working_folder, image_name)
1888
+ except (ContainerError, APIError) as error:
1889
+ res = {'error': utils.get_error_message(error)}
1890
+ if res.get('error'):
1891
+ if 'Unknown command' in res.get('error'):
1892
+ logger.info('The neutralize command is not available in this Odoo version')
1893
+ return {}
1894
+ logger.warning('Odoo neutralize command failed, continuing the deactivation: %s',
1895
+ res.get('error'))
1896
+ return res
1897
+
1850
1898
  def neutralize_db(self, db_config_user, db_config_owner):
1851
1899
  """This method was created to avoid increasing complexity of method deactivate_database"""
1852
1900
  neutr_sqls = self.extras_neutralize()
@@ -1955,6 +2003,10 @@ class InstanceV(DockerV):
1955
2003
  message = error.message
1956
2004
  logger.exception('Could not deactivate the database: %s', message)
1957
2005
 
2006
+ # Neutralize database with the Odoo's neutralize command (Odoo 16.0+), errors are ignored
2007
+ logger.info("Neutralize database using the Odoo's neutralize command")
2008
+ self.neutralize_odoo(db_name)
2009
+
1958
2010
  # Neutralize database by execute sql queries from neutralize_deactivate.sql file
1959
2011
  logger.info("Neutralize database (whether sql file exist)")
1960
2012
  neutr_res = self.neutralize_db(db_config_user, db_config_owner)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: deployv
3
- Version: 0.9.230
3
+ Version: 0.9.232
4
4
  Summary: Base for all clases and scripts in VauxooTools
5
5
  Home-page: https://git.vauxoo.com/deployv/deployv
6
6
  Download-URL: https://git.vauxoo.com/deployv/deployv
@@ -48,7 +48,7 @@ test_requirements = open('test-requirements.txt').readlines()
48
48
 
49
49
  setup(
50
50
  name='deployv',
51
- version='0.9.230',
51
+ version='0.9.232',
52
52
  description='Base for all clases and scripts in VauxooTools',
53
53
  long_description=readme,
54
54
  author='Tulio Ruiz',
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes