Example #1
0
    def _checkSupportedVersionsPresent(self):
        # TODO: figure out a better way to do this for the future
        statement = database.Statement(environment=self.environment)
        dcVersions = statement.execute(
            statement="""
                SELECT compatibility_version FROM storage_pool;
            """,
            ownConnection=True,
            transaction=False,
        )
        clusterVersions = statement.execute(
            statement="""
                SELECT compatibility_version FROM vds_groups;;
            """,
            ownConnection=True,
            transaction=False,
        )

        versions = set(
            [x['compatibility_version'] for x in dcVersions + clusterVersions])
        supported = set([
            x.strip() for x in self.environment[
                osetupcons.CoreEnv.UPGRADE_SUPPORTED_VERSIONS].split(',')
            if x.strip()
        ])

        if versions - supported:
            raise RuntimeError(
                _('Trying to upgrade from unsupported versions: {versions}').
                format(versions=' '.join(versions - supported)))
Example #2
0
 def _customization(self):
     dbovirtutils = database.OvirtUtils(plugin=self)
     dbovirtutils.tryDatabaseConnect()
     dbstatement = database.Statement(environment=self.environment)
     rows = dbstatement.execute(
         statement="""
             select
                 id,
                 storage,
                 storage_name
             from storage_domain_static
             where
                 storage_type=%(storage_type)s and
                 storage_domain_type=%(storage_domain_type)s
         """,
         args=dict(
             storage_type=domains.StorageType.NFS,
             storage_domain_type=domains.StorageDomainType.ISO,
         ),
         ownConnection=True,
     )
     for domain in rows:
         conn_row = dbstatement.execute(
             statement="""
                 select
                     connection
                 from storage_server_connections
                 where
                     id=%(storage)s
             """,
             args=dict(storage=domain['storage']),
             ownConnection=True,
         )[0]
         #returns only one line, can't exists duplicate and must exist one
         host, path = conn_row['connection'].split(':')
         if host == self.environment[osetupcons.ConfigEnv.FQDN]:
             self.environment[osetupcons.ConfigEnv.ISO_DOMAIN_EXISTS] = True
             self.environment[
                 osetupcons.SystemEnv.NFS_CONFIG_ENABLED] = True
             self.environment[
                 osetupcons.ConfigEnv.ISO_DOMAIN_NFS_MOUNT_POINT] = path
             self.environment[osetupcons.ConfigEnv.
                              ISO_DOMAIN_NAME] = domain['storage_name']
             self.environment[
                 osetupcons.ConfigEnv.ISO_DOMAIN_SD_UUID] = domain['id']
             self.environment[
                 osetupcons.ConfigEnv.
                 ISO_DOMAIN_STORAGE_DIR] = os.path.join(
                     self.environment[
                         osetupcons.ConfigEnv.ISO_DOMAIN_NFS_MOUNT_POINT],
                     self.environment[
                         osetupcons.ConfigEnv.ISO_DOMAIN_SD_UUID],
                     'images',
                     osetupcons.Const.ISO_DOMAIN_IMAGE_UID,
                 )
             break
Example #3
0
 def _connection(self):
     # must be here as we do not have database at validation
     self.environment[osetupcons.DBEnv.CONNECTION] = psycopg2.connect(
         host=self.environment[osetupcons.DBEnv.HOST],
         port=self.environment[osetupcons.DBEnv.PORT],
         user=self.environment[osetupcons.DBEnv.USER],
         password=self.environment[osetupcons.DBEnv.PASSWORD],
         database=self.environment[osetupcons.DBEnv.DATABASE],
     )
     self.environment[osetupcons.DBEnv.STATEMENT] = database.Statement(
         environment=self.environment, )
Example #4
0
 def _validateAsyncTasks(self):
     self.logger.info(_('Cleaning async tasks and compensations'))
     runningTasks, compensations = self._checkRunningTasks()
     if runningTasks or compensations:
         self._askUserToStopTasks(runningTasks, compensations)
         dbstatement = database.Statement(self.environment)
         try:
             self._waitForTasksToClear(dbstatement)
         except KeyboardInterrupt:
             self.logger.error(
                 _('Upgrade cannot be completed; asynchronious tasks '
                   'or compensations are still running. Please make '
                   'sure that there are no running tasks before you '
                   'continue.'))
             raise RuntimeError(
                 _('Upgrade cannot be completed due to running tasks.'))
Example #5
0
    def _setDatabaseResources(self, environment):
        dbstatement = database.Statement(environment=environment, )
        hasDatabase = dbstatement.execute(
            statement="""
                select count(*) as count
                from pg_database
                where datname = %(database)s
            """,
            args=dict(database=self.environment[osetupcons.DBEnv.DATABASE], ),
            ownConnection=True,
            transaction=False,
        )[0]['count'] != 0
        hasUser = dbstatement.execute(
            statement="""
                select count(*) as count
                from pg_user
                where usename = %(user)s
            """,
            args=dict(user=self.environment[osetupcons.DBEnv.USER], ),
            ownConnection=True,
            transaction=False,
        )[0]['count'] != 0

        generate = hasDatabase or hasUser
        existing = False

        if hasDatabase and hasUser:
            dbovirtutils = database.OvirtUtils(
                plugin=self,
                environment=environment,
            )
            if dbovirtutils.isNewDatabase(
                    database=self.environment[osetupcons.DBEnv.DATABASE], ):
                self.logger.debug('Found empty database')
                generate = False
                existing = True
            else:
                generate = True

        if generate:
            self.logger.debug('Existing resources found, generating names')
            suffix = '_%s' % datetime.datetime.now().strftime('%Y%m%d%H%M%S')
            self.environment[osetupcons.DBEnv.DATABASE] += suffix
            self.environment[osetupcons.DBEnv.USER] += suffix
            self._renamedDBResources = True

        return existing
Example #6
0
    def _checkDbEncoding(self, environment):

        statement = database.Statement(environment=environment)
        encoding = statement.execute(
            statement="""
                show server_encoding
            """,
            ownConnection=True,
            transaction=False,
        )[0]['server_encoding']
        if encoding.lower() != 'utf8':
            raise RuntimeError(
                _('Encoding of the engine database is {encoding}. '
                  'Engine installation is only supported on servers '
                  'with default encoding set to UTF8. Please fix the '
                  'default DB encoding before you continue').format(
                      encoding=encoding, ))
Example #7
0
    def _performDatabase(
        self,
        environment,
        op,
        user,
        password,
        databaseName,
    ):
        statements = [
            ("""
                    {op} role {user}
                    with
                        login
                        encrypted password %(password)s
                """).format(
                op=op,
                user=user,
            ),
            ("""
                    {op} database {database}
                    owner {to} {user}
                    {encoding}
                """).format(
                op=op,
                to='to' if op == 'alter' else '',
                database=databaseName,
                user=user,
                encoding="""
                    template template0
                    encoding 'UTF8'
                    lc_collate 'en_US.UTF-8'
                    lc_ctype 'en_US.UTF-8'
                """ if op != 'alter' else '',
            ),
        ]

        dbstatement = database.Statement(environment=environment, )
        for statement in statements:
            dbstatement.execute(
                statement=statement,
                args=dict(password=password, ),
                ownConnection=True,
                transaction=False,
            )
Example #8
0
 def _customization(self):
     dbovirtutils = database.OvirtUtils(plugin=self)
     dbovirtutils.tryDatabaseConnect()
     dbstatement = database.Statement(environment=self.environment)
     rows = dbstatement.execute(
         statement="""
             select
                 id,
                 storage,
                 storage_name
             from storage_domain_static
             where
                 storage_type=%(storage_type)s and
                 storage_domain_type=%(storage_domain_type)s
         """,
         args=dict(
             storage_type=domains.StorageType.LOCALFS,
             storage_domain_type=domains.StorageDomainType.MASTER,
         ),
         ownConnection=True,
     )
     for domain in rows:
         conn_row = dbstatement.execute(
             statement="""
                 select
                     connection
                 from storage_server_connections
                 where
                     id=%(storage)s
             """,
             args=dict(storage=domain['storage']),
             ownConnection=True,
         )[0]
         #returns only one line, can't exists duplicate and must exist one
         path = conn_row['connection']
         self.environment[osetupcons.AIOEnv.CONFIGURE] = False
         self.environment[osetupcons.AIOEnv.ENABLE] = False
         self.environment[osetupcons.AIOEnv.STORAGE_DOMAIN_DIR] = path
         self.environment[
             osetupcons.AIOEnv.STORAGE_DOMAIN_NAME] = domain['storage_name']
         self._aio_already_configured = True
         break
Example #9
0
 def _validation(self):
     dbovirtutils = database.OvirtUtils(plugin=self)
     dbovirtutils.tryDatabaseConnect()
     dbstatement = database.Statement(environment=self.environment)
     my_domains = []
     rows = dbstatement.execute(
         statement="""
             select
                 storage_name,
                 connection
             from
                 storage_domain_static s,
                 storage_server_connections c
             where
                 s.storage = c.id and
                 s.storage_type=%(storage_type)s and
                 s.storage_domain_type=%(storage_domain_type)s
         """,
         args=dict(
             storage_type=domains.StorageType.NFS,
             storage_domain_type=domains.StorageDomainType.ISO,
         ),
         ownConnection=True,
     )
     for row in rows:
         host, path = row['connection'].split(':', 1)
         if host == self.environment[osetupcons.ConfigEnv.FQDN]:
             my_domains.append(row['storage_name'])
     if my_domains:
         self.logger.warning(_('Engine host hosting Storage Domains'))
         self.dialog.note(text=_(
             'The following Storage Domains use the engine host\n'
             'as an NFS server:\n'
             '\n'
             '{domains}\n'
             '\n'
             'Cannot rename the engine host. Please backup relevant\n'
             'data if needed, remove all of these domains, and then\n'
             'run this utility again.\n').format(
                 domains='\n'.join(sorted(my_domains))), )
         raise RuntimeError(_('Cannot rename host hosting Storage Domains'))
Example #10
0
 def _checkRunningTasks(self):
     dbstatement = database.Statement(self.environment)
     return (
         self._getRunningTasks(dbstatement),
         self._getCompensations(dbstatement),
     )