Skip to content

Commit

Permalink
Resume info (#369)
Browse files Browse the repository at this point in the history
* If there is no upgrade run to resume print a message and bail
* Make sure the database is created with 0o177 permissions
  • Loading branch information
shaded-enmity authored and vinzenz committed Nov 9, 2018
1 parent 788616f commit 3be3abd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ install:
install -m 0744 etc/leapp/leapp.conf ${CONFDIR}
install -m 0744 etc/leapp/logger.conf ${CONFDIR}
install -dm 0755 ${LIBDIR}
python -c "import sqlite3; sqlite3.connect('${LIBDIR}/audit.db').executescript(open('res/audit-layout.sql', 'r').read())"
umask 177 && python -c "import sqlite3; sqlite3.connect('${LIBDIR}/audit.db').executescript(open('res/audit-layout.sql', 'r').read())"

install-container-test:
docker pull ${CONTAINER}
Expand Down
5 changes: 4 additions & 1 deletion leapp/cli/upgrade/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import sys
from leapp.config import get_config
from leapp.exceptions import LeappError, CommandError
from leapp.exceptions import CommandError, LeappError
from leapp.logger import configure_logger
from leapp.repository.scan import find_and_scan_repositories
from leapp.utils.audit import Execution, get_connection, get_checkpoints
Expand Down Expand Up @@ -57,6 +57,9 @@ def upgrade(args):
context = str(uuid.uuid4())
if args.resume:
context = fetch_last_upgrade_context()
if not context:
raise CommandError('No previous upgrade run to continue, remove `--resume` from leapp invocation to'
'start a new upgrade flow')
skip_phases_until = get_last_phase(context)
else:
e = Execution(context=context, kind='upgrade', configuration={})
Expand Down
12 changes: 11 additions & 1 deletion leapp/utils/audit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from contextlib import contextmanager
import datetime
import json
import os
import sqlite3

import six
Expand All @@ -8,6 +10,13 @@
from leapp.utils.schemas import CURRENT_SCHEMA, MIGRATIONS


@contextmanager
def _umask(new_mask):
cur_mask = os.umask(new_mask)
yield
os.umask(cur_mask)


def _initialize_database(db):
"""
Checks that the latest schema of the database has been applied or initializes the database
Expand Down Expand Up @@ -39,7 +48,8 @@ def create_connection(path):
:param path: Path to the database
:return: Connection object
"""
return _initialize_database(sqlite3.connect(path))
with _umask(0o177):
return _initialize_database(sqlite3.connect(path))


def get_connection(db):
Expand Down

0 comments on commit 3be3abd

Please sign in to comment.