Example #1
0
def main(filename):
    """ Main loop."""
    init_logging()
    init_db()
    db_instance = DatabaseHandler.get_connection()
    data = JsonPkgTree(db_instance, filename)
    data.dump()
Example #2
0
    def run_task(*args, **kwargs):
        """Function to import all repositories from input list to the DB."""
        try:
            products = kwargs.get("products", None)
            repos = kwargs.get("repos", None)
            init_logging()
            init_db()

            if products:
                product_store = ProductStore()
                product_store.store(products)

            if repos:
                repository_controller = RepositoryController()
                # Sync repos from input
                for repo_url, content_set, basearch, releasever, cert_name, ca_cert, cert, key in repos:
                    repository_controller.add_repository(repo_url,
                                                         content_set,
                                                         basearch,
                                                         releasever,
                                                         cert_name=cert_name,
                                                         ca_cert=ca_cert,
                                                         cert=cert,
                                                         key=key)
                repository_controller.import_repositories()
        except Exception as err:  # pylint: disable=broad-except
            msg = "Internal server error <%s>" % err.__hash__()
            LOGGER.exception(msg)
            DatabaseHandler.rollback()
            return "ERROR"
        return "OK"
Example #3
0
def exporter_db_conn():
    """Fixture for db connection."""
    def _handler(postgresql):
        """Init DB with data."""
        conn = psycopg2.connect(**postgresql.dsn())
        cursor = conn.cursor()
        with open("../database/vmaas_user_create_postgresql.sql",
                  "r") as psql_user:
            cursor.execute(psql_user.read())
        with open("../database/vmaas_db_postgresql.sql", "r") as vmaas_db:
            cursor.execute(vmaas_db.read())
        with open("test_data/exporter/exporter_test_data.sql",
                  "r") as test_data:
            cursor.execute(test_data.read())
        cursor.close()
        conn.commit()
        conn.close()

    # Create temporary posgresql server
    # pylint: disable=invalid-name
    Postgresql = testing.postgresql.PostgresqlFactory(
        cache_initialized_db=True, on_initialized=_handler)
    postgresql = Postgresql()

    os.environ["POSTGRESQL_PORT"] = str(postgresql.dsn()["port"])
    DatabaseHandler.close_connection()
    init_db()
    conn = psycopg2.connect(**postgresql.dsn())
    yield conn

    # teardown - close connection, stop postgresql
    conn.close()
    postgresql.stop()
Example #4
0
    def run_task(*args, **kwargs):
        """Function to import all repositories from input list to the DB."""
        try:
            products = kwargs.get("products", None)
            repos = kwargs.get("repos", None)
            git_sync = kwargs.get("git_sync", False)
            init_logging()
            init_db()

            if products:
                product_store = ProductStore()
                product_store.store(products)

            if repos:
                repository_controller = RepositoryController()
                repos_in_db = repository_controller.repo_store.list_repositories()
                # Sync repos from input
                for repo_url, content_set, basearch, releasever, cert_name, ca_cert, cert, key in repos:
                    repository_controller.add_repository(repo_url, content_set, basearch, releasever,
                                                         cert_name=cert_name, ca_cert=ca_cert,
                                                         cert=cert, key=key)
                    repos_in_db.pop((content_set, basearch, releasever), None)
                if git_sync:  # Warn about extra repos in DB when syncing main repolist from git
                    for content_set, basearch, releasever in repos_in_db:
                        LOGGER.warning("Repository in DB but not in git repolist: %s", ", ".join(
                                       filter(None, (content_set, basearch, releasever))))
                repository_controller.import_repositories()
        except Exception as err:  # pylint: disable=broad-except
            msg = "Internal server error <%s>" % err.__hash__()
            LOGGER.exception(msg)
            DatabaseHandler.rollback()
            return "ERROR"
        finally:
            DatabaseHandler.close_connection()
        return "OK"
Example #5
0
def main(filename):
    """ Main loop."""
    init_logging()
    init_db()
    db_instance = DatabaseHandler.get_connection()
    #data = DataDump(db.cursor(), filename)
    data = DataDump(db_instance, filename)
    data.dump()
Example #6
0
def db_conn():
    """Fixture for db connection."""
    postgresql = create_pg()
    init_db()
    conn = psycopg2.connect(**postgresql.dsn())
    yield conn

    # teardown - close connection, stop postgresql
    conn.close()
    postgresql.stop()
Example #7
0
    def process(self):
        """Processes the dbchange get request. """
        init_db()
        self.db_instance = DatabaseHandler.get_connection()
        result = {}

        with self.db_instance.cursor() as crs:
            crs.execute("select pkgtree_change from dbchange")
            timestamp = crs.fetchone()

        result["pkgtree_change"] = str(timestamp[0])
        return result
Example #8
0
 def run_task(*args, **kwargs):
     """Function to start syncing all CVEs."""
     try:
         init_logging()
         init_db()
         controller = CvemapController()
         controller.store()
     except Exception as err:  # pylint: disable=broad-except
         msg = "Internal server error <%s>" % err.__hash__()
         LOGGER.exception(msg)
         DatabaseHandler.rollback()
         return "ERROR"
     return "OK"
Example #9
0
    def __init__(self):
        LOGGER.info('DatabaseUpgrade initializing.')

        init_db()

        # get upgrade sql scripts directory
        self.scripts_dir = os.getenv('DB_UPGRADE_SCRIPTS_DIR',
                                     DB_UPGRADES_PATH)
        if not self.scripts_dir.endswith('/'):
            self.scripts_dir += '/'

        # load the version2file_map and version_max
        self.version2file_map, self.version_max = self._load_upgrade_file_list(self.scripts_dir)
Example #10
0
 def run_task(*args, **kwargs):
     """Function to start syncing all repositories available from database."""
     try:
         init_logging()
         init_db()
         repository_controller = RepositoryController()
         repository_controller.add_db_repositories()
         repository_controller.store()
     except Exception as err:  # pylint: disable=broad-except
         msg = "Internal server error <%s>" % err.__hash__()
         LOGGER.exception(msg)
         DatabaseHandler.rollback()
         return "ERROR"
     return "OK"
Example #11
0
 def run_task(*args, **kwargs):
     """Function to start deleting repos."""
     try:
         repo = kwargs.get("repo", None)
         init_logging()
         init_db()
         repository_controller = RepositoryController()
         repository_controller.delete_content_set(repo)
     except Exception as err:  # pylint: disable=broad-except
         msg = "Internal server error <%s>" % err.__hash__()
         LOGGER.exception(msg)
         DatabaseHandler.rollback()
         return "ERROR"
     return "OK"
Example #12
0
 def run_task(*args, **kwargs):
     """Function to start syncing OVALs."""
     try:
         init_logging()
         init_db()
         controller = OvalController()
         controller.store()
     except Exception as err:  # pylint: disable=broad-except
         msg = "Internal server error <%s>" % err.__hash__()
         LOGGER.exception(msg)
         FAILED_IMPORT_OVAL.inc()
         DatabaseHandler.rollback()
         return "ERROR"
     finally:
         DatabaseHandler.close_connection()
     return "OK"