Example #1
0
    def make_pg_dump(self, pg_dump_tmp_path, pg_dump_path):
        """Run postgresql dump in container

        :param str pg_dump_tmp_path: path to temporary dump file
        :param str pg_dump_path: path to dump which will be restored
                                 in the new container, if this file is
                                 exists, it means the user already
                                 ran upgrade and for some reasons it
                                 failed
        :returns: True if db was successfully dumped or if dump exists
                  False if container isn't running or dump isn't succeed
        """
        try:
            container_name = self.make_container_name(
                'postgres', self.from_version)

            self.exec_cmd_in_container(
                container_name,
                u"su postgres -c 'pg_dumpall --clean' > {0}".format(
                    pg_dump_tmp_path))
        except (errors.ExecutedErrorNonZeroExitCode,
                errors.CannotFindContainerError) as exc:
            utils.remove_if_exists(pg_dump_tmp_path)
            if not utils.file_exists(pg_dump_path):
                logger.debug('Failed to make database dump %s', exc)
                return False

            logger.debug(
                u'Failed to make database dump, '
                'will be used dump from previous run: %s', exc)

        return True
Example #2
0
    def make_pg_dump(self, pg_dump_tmp_path, pg_dump_path):
        """Run postgresql dump in container

        :param str pg_dump_tmp_path: path to temporary dump file
        :param str pg_dump_path: path to dump which will be restored
                                 in the new container, if this file is
                                 exists, it means the user already
                                 ran upgrade and for some reasons it
                                 failed
        :returns: True if db was successfully dumped or if dump exists
                  False if container isn't running or dump isn't succeed
        """
        try:
            container_name = self.make_container_name('postgres',
                                                      self.from_version)

            self.exec_cmd_in_container(
                container_name,
                u"su postgres -c 'pg_dumpall --clean' > {0}".format(
                    pg_dump_tmp_path))
        except (errors.ExecutedErrorNonZeroExitCode,
                errors.CannotFindContainerError) as exc:
            utils.remove_if_exists(pg_dump_tmp_path)
            if not utils.file_exists(pg_dump_path):
                logger.debug('Failed to make database dump %s', exc)
                return False

            logger.debug(
                u'Failed to make database dump, '
                'will be used dump from previous run: %s', exc)

        return True
Example #3
0
    def remove_repo_config(self):
        """Remove yum repository config
        """
        utils.remove_if_exists(self.repo_config_path)

        # One more damn hack! We have to remove auxiliary repo config
        # if we're rollbacking to the Fuel version that doesn't have
        # auxiliary repo at all.
        if utils.compare_version(self.config.from_version, '6.1') > 0:
            utils.remove_if_exists(
                self.host_system_config['repo_aux_config_path'])
Example #4
0
    def remove_repo_config(self):
        """Remove yum repository config
        """
        utils.remove_if_exists(self.repo_config_path)

        # One more damn hack! We have to remove auxiliary repo config
        # if we're rollbacking to the Fuel version that doesn't have
        # auxiliary repo at all.
        if utils.compare_version(self.config.from_version, '6.1') > 0:
            utils.remove_if_exists(
                self.host_system_config['repo_aux_config_path'])
Example #5
0
    def save_db(self):
        """Saves postgresql database into the file
        """
        logger.debug(u'Backup database')
        pg_dump_path = os.path.join(self.working_directory, 'pg_dump_all.sql')
        pg_dump_files = utils.VersionedFile(pg_dump_path)
        pg_dump_tmp_path = pg_dump_files.next_file_name()

        try:
            container_name = self.make_container_name(
                'postgres', self.from_version)

            self.exec_cmd_in_container(
                container_name,
                u"su postgres -c 'pg_dumpall --clean' > {0}".format(
                    pg_dump_tmp_path))
        except (errors.ExecutedErrorNonZeroExitCode,
                errors.CannotFindContainerError) as exc:
            utils.remove_if_exists(pg_dump_tmp_path)
            if not utils.file_exists(pg_dump_path):
                raise

            logger.debug(
                u'Failed to make database dump, '
                'will be used dump from previous run: %s', exc)

        valid_dumps = filter(utils.verify_postgres_dump,
                             pg_dump_files.sorted_files())
        if valid_dumps:
            utils.hardlink(valid_dumps[0], pg_dump_path, overwrite=True)
            map(utils.remove_if_exists,
                valid_dumps[self.config.keep_db_backups_count:])
        else:
            raise errors.DatabaseDumpError(
                u'Failed to make database dump, there '
                'are no valid database backup '
                'files, {0}'.format(pg_dump_path))
Example #6
0
    def remove_repo_config(self):
        """Remove yum repository config"""
        utils.remove_if_exists(self.repo_config_path)

        # One more damn hack! We have to remove auxiliary repo config
        # if we're rollbacking to the Fuel version that doesn't have
        # auxiliary repo at all.
        if utils.compare_version(self.config.from_version, '6.1') > 0:
            utils.remove_if_exists(
                self.host_system_config['repo_aux_config_path'])
        else:
            # By some pity reason we're managing auxiliary repo in puppet
            # manifests, but there's no management code for rollbacking.
            # Therefore, we need to clean-up its artifacts in case of
            # upgrade rollback procedure here; otherwise another try
            # of upgrade will fail.
            path, name = os.path.split(
                self.host_system_config['repo_aux_config_path'])
            utils.remove_if_exists(os.path.join(path, '{0}_{1}'.format(
                self.config.new_version,
                name)))
Example #7
0
    def remove_repo_config(self):
        """Remove yum repository config
        """
        utils.remove_if_exists(self.repo_config_path)

        # One more damn hack! We have to remove auxiliary repo config
        # if we're rollbacking to the Fuel version that doesn't have
        # auxiliary repo at all.
        if utils.compare_version(self.config.from_version, '6.1') > 0:
            utils.remove_if_exists(
                self.host_system_config['repo_aux_config_path'])
        else:
            # By some pity reason we're managing auxiliary repo in puppet
            # manifests, but there's no management code for rollbacking.
            # Therefore, we need to clean-up its artifacts in case of
            # upgrade rollback procedure here; otherwise another try
            # of upgrade will fail.
            path, name = os.path.split(
                self.host_system_config['repo_aux_config_path'])
            utils.remove_if_exists(os.path.join(path, '{0}_{1}'.format(
                self.config.new_version,
                name)))
 def test_remove_if_exists(self, remove_mock, exists_mock):
     path = '/tmp/some/path'
     utils.remove_if_exists(path)
     remove_mock.assert_called_once_with(path)
     exists_mock.assert_called_once_with(path)
Example #9
0
 def remove_repo_config(self):
     """Remove yum repository config
     """
     utils.remove_if_exists(self.repo_config_path)
Example #10
0
 def test_remove_if_exists(self, remove_mock, exists_mock):
     path = '/tmp/some/path'
     utils.remove_if_exists(path)
     remove_mock.assert_called_once_with(path)
     exists_mock.assert_called_once_with(path)
Example #11
0
 def remove_repo_config(self):
     """Remove yum repository config
     """
     utils.remove_if_exists(self.repo_config_path)