def check_if_required(self):
     """The hack is required if we're going to upgrade from 5.0.1
     and only repo path for 5.0.1 is exists
     """
     return (self.config.from_version == '5.0.1' and
             utils.file_exists(self.repo_path) and
             utils.file_exists(self.yum_repo_file))
    def check_if_required(self):
        """Checks if it's required to run upgrade

        :returns: True - if it is required to run this hook
                  False - if it is not required to run this hook
        """
        return all([
            utils.file_exists(self.ubuntu_x86_64_old),
            not utils.file_exists(self.ubuntu_x86_64_new)])
Ejemplo n.º 3
0
    def check_if_required(self):
        """Checks if it's required to run upgrade

        :returns: True - if it is required to run this hook
                  False - if it is not required to run this hook
        """
        return all([
            utils.file_exists(self.ubuntu_x86_64_old),
            not utils.file_exists(self.ubuntu_x86_64_new)])
Ejemplo n.º 4
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
Ejemplo n.º 5
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
Ejemplo n.º 6
0
 def save_astute_keys(self):
     """Copy any astute generated keys."""
     container_name = self.make_container_name('astute', self.from_version)
     utils.remove(self.config.astute_keys_path)
     try:
         utils.exec_cmd('docker cp {0}:{1} {2}'.format(
             container_name,
             self.config.astute_container_keys_path,
             self.config.working_directory))
     except errors.ExecutedErrorNonZeroExitCode as exc:
         # If there was error, mostly it's because of error
         #
         #   Error: Could not find the file /var/lib/astute
         #   in container fuel-core-5.0-astute
         #
         # It means that user didn't run deployment on his
         # env, because this directory is created by orchestrator
         # during the first deployment.
         # Also it can fail if there was no running container
         # in both case we should create empty directory to copy
         # it in after container creation section
         logger.debug(
             'Cannot copy astute keys, creating empty directory '
             '%s: %s', self.config.astute_keys_path, exc)
         if not utils.file_exists(self.config.astute_keys_path):
             os.mkdir(self.config.astute_keys_path)
Ejemplo n.º 7
0
    def run(self):
        """Move files to new directory
        """
        if not utils.file_exists(self.dst_path):
            os.makedirs(self.dst_path)

        container_name = '{0}{1}-astute'.format(self.config.container_prefix,
                                                self.config.from_version)
        try:
            utils.exec_cmd('docker cp {0}:{1} {2}'.format(
                container_name, self.src_path, self.dst_path))
            # we need move and remove folder, because docker copy also folder
            # not only content
            utils.exec_cmd('mv {0}astute/* {0}'.format(self.dst_path))
            utils.exec_cmd('rm -r {0}astute/'.format(self.dst_path))
        except errors.ExecutedErrorNonZeroExitCode as exc:
            # Error means that user didn't run deployment on his
            # env, because this directory is created only then
            logger.warning('Cannot copy astute keys %s', exc)
    def run(self):
        """Move files to new directory"""
        if not utils.file_exists(self.dst_path):
            os.makedirs(self.dst_path)

        container_name = '{0}{1}-astute'.format(
            self.config.container_prefix, self.config.from_version)
        try:
            utils.exec_cmd('docker cp {0}:{1} {2}'.format(
                container_name,
                self.src_path,
                self.dst_path))
            # we need move and remove folder, because docker copy also folder
            # not only content
            utils.exec_cmd('mv {0}astute/* {0}'.format(self.dst_path))
            utils.exec_cmd('rm -r {0}astute/'.format(self.dst_path))
        except errors.ExecutedErrorNonZeroExitCode as exc:
                # Error means that user didn't run deployment on his
                # env, because this directory is created only then
                logger.warning(
                    'Cannot copy astute keys %s',
                    exc)
Ejemplo n.º 9
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))
Ejemplo n.º 10
0
 def test_file_exists_returns_false(self, exists_mock):
     self.assertFalse(utils.file_exists('path'))
     exists_mock.assert_called_once_with('path')
Ejemplo n.º 11
0
 def test_file_exists_returns_false(self, exists_mock):
     self.assertFalse(utils.file_exists('path'))
     exists_mock.assert_called_once_with('path')