Beispiel #1
0
 def revert(self):
     main_conf = os.path.join(self.pg_data, 'postgresql.conf')
     main_conf_backup = main_conf + '.backup'
     hba_conf = os.path.join(self.pg_data, 'pg_hba.conf')
     hba_conf_backup = hba_conf + '.backup'
     main_config_reverted = fabricio.move_file(
         path_from=main_conf_backup,
         path_to=main_conf,
         ignore_errors=True,
         sudo=True,
     ).succeeded
     hba_config_reverted = fabricio.move_file(
         path_from=hba_conf_backup,
         path_to=hba_conf,
         ignore_errors=True,
         sudo=True,
     ).succeeded
     try:
         super(PostgresqlContainer, self).revert()
     except RuntimeError:
         if main_config_reverted:
             self.reload()
         elif hba_config_reverted:
             self.signal('HUP')
         else:
             raise
Beispiel #2
0
 def revert(self):
     main_conf = os.path.join(self.pg_data, 'postgresql.conf')
     main_conf_backup = main_conf + '.backup'
     hba_conf = os.path.join(self.pg_data, 'pg_hba.conf')
     hba_conf_backup = hba_conf + '.backup'
     main_config_reverted = fabricio.move_file(
         path_from=main_conf_backup,
         path_to=main_conf,
         ignore_errors=True,
         sudo=self.sudo,
     ).succeeded
     hba_config_reverted = fabricio.move_file(
         path_from=hba_conf_backup,
         path_to=hba_conf,
         ignore_errors=True,
         sudo=self.sudo,
     ).succeeded
     try:
         super(PostgresqlContainer, self).revert()
     except docker.ContainerError:
         if main_config_reverted:
             self.reload()
         elif hba_config_reverted:
             self.signal('HUP')
         else:
             raise
Beispiel #3
0
 def update_recovery_config(self, tag=None, registry=None, account=None):
     db_exists = self.db_exists()
     recovery_conf_file = os.path.join(self.pg_data, 'recovery.conf')
     if db_exists:
         self.multiprocessing_data.db_exists = True
         if not files.exists(recovery_conf_file, use_sudo=self.sudo):
             # master founded
             self.set_master_info()
             return False
     fabricio.log('Waiting for master info ({seconds} seconds)...'.format(
         seconds=self.pg_recovery_wait_for_master_seconds,
     ))
     self.master_obtained.wait(self.pg_recovery_wait_for_master_seconds)
     if not self.master_obtained.is_set():
         if db_exists and not self.pg_recovery_master_promotion_enabled:
             fab.abort(
                 'Database exists but master not found. This probably '
                 'means master failure. New master promotion disabled '
                 'by default, but can be enabled by setting attribute '
                 '\'pg_recovery_master_promotion_enabled\' to True.'
             )
         self.master_lock.acquire()
         if not self.master_obtained.is_set():
             if db_exists:
                 fabricio.move_file(
                     path_from=recovery_conf_file,
                     path_to=recovery_conf_file + '.backup',
                     sudo=self.sudo,
                 )
                 self.set_master_info()
                 return True
             elif not self.multiprocessing_data.db_exists:
                 self.set_master_info()
                 return False
         self.master_lock.release()
         self.master_obtained.wait()
     if not db_exists:
         self.copy_data_from_master(
             tag=tag,
             registry=registry,
             account=account,
         )
     return self.update_config(
         content=self.get_recovery_config(),
         path=os.path.join(self.pg_data, 'recovery.conf'),
     )
Beispiel #4
0
 def update_recovery_config(self, tag=None, registry=None, account=None):
     db_exists = self.db_exists()
     recovery_conf_file = os.path.join(self.pg_data, 'recovery.conf')
     if db_exists:
         self.multiprocessing_data.db_exists = True
         if not files.exists(recovery_conf_file, use_sudo=True):
             # master founded
             self.set_master_info()
             return False
     fabricio.log('Waiting for master info ({seconds} seconds)...'.format(
         seconds=self.pg_recovery_wait_for_master_seconds, ))
     self.master_obtained.wait(self.pg_recovery_wait_for_master_seconds)
     if not self.master_obtained.is_set():
         if db_exists and not self.pg_recovery_master_promotion_enabled:
             fab.abort(
                 'Database exists but master not found. This probably '
                 'means master failure. New master promotion disabled '
                 'by default, but can be enabled by setting attribute '
                 '\'pg_recovery_master_promotion_enabled\' to True.')
         self.master_lock.acquire()
         if not self.master_obtained.is_set():
             if db_exists:
                 fabricio.move_file(
                     path_from=recovery_conf_file,
                     path_to=recovery_conf_file + '.backup',
                     sudo=True,
                 )
                 self.set_master_info()
                 return True
             elif not self.multiprocessing_data.db_exists:
                 self.set_master_info()
                 return False
         self.master_lock.release()
         self.master_obtained.wait()
     if not db_exists:
         self.copy_data_from_master(
             tag=tag,
             registry=registry,
             account=account,
         )
     recovery_config = self.get_recovery_config()
     return self.update_config(
         content=recovery_config,
         path=os.path.join(self.pg_data, 'recovery.conf'),
     )
Beispiel #5
0
 def update_config(content, path):
     old_file = six.BytesIO()
     if files.exists(path, use_sudo=True):
         fab.get(remote_path=path, local_path=old_file, use_sudo=True)
     old_content = old_file.getvalue()
     need_update = content != old_content
     if need_update:
         fabricio.move_file(
             path_from=path,
             path_to=path + '.backup',
             sudo=True,
             ignore_errors=True,
         )
         fab.put(six.BytesIO(content), path, use_sudo=True, mode='0644')
         fabricio.log('{path} updated'.format(path=path))
     else:
         fabricio.log('{path} not changed'.format(path=path))
     return need_update
Beispiel #6
0
 def update_config(self, content, path):
     old_file = six.BytesIO()
     if files.exists(path, use_sudo=self.sudo):
         fab.get(remote_path=path, local_path=old_file, use_sudo=self.sudo)
     old_content = old_file.getvalue()
     need_update = content != old_content
     if need_update:
         fabricio.move_file(
             path_from=path,
             path_to=path + '.backup',
             sudo=self.sudo,
             ignore_errors=True,
         )
         fab.put(six.BytesIO(content), path, use_sudo=self.sudo, mode='0644')
         fabricio.log('{path} updated'.format(path=path))
     else:
         fabricio.log('{path} not changed'.format(path=path))
     return need_update