Skip to content

Commit

Permalink
Merge branch '3.8-devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtechtrefny committed Aug 2, 2023
2 parents ece1db8 + 8e0514e commit b9a1646
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 59 deletions.
56 changes: 53 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
PYTHON=python3
PKG_INSTALL?=dnf

L10N_REPOSITORY[email protected]:storaged-project/blivet-weblate.git
L10N_BRANCH=master

PKGNAME=blivet
SPECFILE=python-blivet.spec
VERSION=$(shell $(PYTHON) setup.py --version)
RPMVERSION=$(shell rpmspec -q --queryformat "%{version}\n" $(SPECFILE) | head -1)
RPMRELEASE=$(shell rpmspec --undefine '%dist' -q --queryformat "%{release}\n" $(SPECFILE) | head -1)
RC_RELEASE ?= $(shell date -u +0.1.%Y%m%d%H%M%S)
RELEASE_TAG=$(PKGNAME)-$(RPMVERSION)-$(RPMRELEASE)
VERSION_TAG=$(PKGNAME)-$(VERSION)

COVERAGE=$(PYTHON) -m coverage

MOCKCHROOT ?= fedora-rawhide-$(shell uname -m)

all:
$(MAKE) -C po
Expand Down Expand Up @@ -118,9 +124,17 @@ ChangeLog:
(GIT_DIR=.git git log > .changelog.tmp && mv .changelog.tmp ChangeLog; rm -f .changelog.tmp) || (touch ChangeLog; echo 'git directory not found: installing possibly empty changelog.' >&2)

tag:
tag='$(VERSION_TAG)' ; \
git tag -a -s -m "Tag as $$tag" -f $$tag && \
echo "Tagged as $$tag"
@if test $(VERSION) != $(RPMVERSION) ; then \
tags='$(VERSION_TAG) $(RELEASE_TAG)' ; \
elif test $(RPMRELEASE) = "1" ; then \
tags='$(VERSION_TAG) $(RELEASE_TAG)' ; \
else \
tags='$(RELEASE_TAG)' ; \
fi ; \
for tag in $$tags ; do \
git tag -a -s -m "Tag as $$tag" -f $$tag ; \
echo "Tagged as $$tag" ; \
done

release: tag archive

Expand All @@ -146,6 +160,10 @@ local: po-pull
git ls-files tests/ | tar -T- -czf $(PKGNAME)-$(VERSION)-tests.tar.gz
@echo "The test archive is in $(PKGNAME)-$(VERSION)-tests.tar.gz"

rpmlog:
@git log --pretty="format:- %s (%ae)" $(RELEASE_TAG).. |sed -e 's/@.*)/)/'
@echo

bumpver: po-pull
@opts="-n $(PKGNAME) -v $(VERSION) -r $(RPMRELEASE)" ; \
if [ ! -z "$(IGNORE)" ]; then \
Expand All @@ -162,6 +180,38 @@ bumpver: po-pull
fi ; \
( scripts/makebumpver $${opts} ) || exit 1 ; \

scratch-bumpver:
@opts="-n $(PKGNAME) -v $(RPMVERSION) -r $(RPMRELEASE) --newrelease $(RC_RELEASE)" ; \
if [ ! -z "$(IGNORE)" ]; then \
opts="$${opts} -i $(IGNORE)" ; \
fi ; \
if [ ! -z "$(MAP)" ]; then \
opts="$${opts} -m $(MAP)" ; \
fi ; \
if [ ! -z "$(SKIP_ACKS)" ]; then \
opts="$${opts} -s" ; \
fi ; \
if [ ! -z "$(BZDEBUG)" ]; then \
opts="$${opts} -d" ; \
fi ; \
( scripts/makebumpver $${opts} ) || exit 1 ; \

scratch:
@rm -f ChangeLog
@make ChangeLog
@rm -rf $(PKGNAME)-$(VERSION).tar.gz
@rm -rf /tmp/$(PKGNAME)-$(VERSION) /tmp/$(PKGNAME)
@dir=$$PWD; cp -a $$dir /tmp/$(PKGNAME)-$(VERSION)
@cd /tmp/$(PKGNAME)-$(VERSION) ; $(PYTHON) setup.py -q sdist
@cp /tmp/$(PKGNAME)-$(VERSION)/dist/$(PKGNAME)-$(VERSION).tar.gz .
@rm -rf /tmp/$(PKGNAME)-$(VERSION)
@echo "The archive is in $(PKGNAME)-$(VERSION).tar.gz"

rc-release: scratch-bumpver scratch
mock -r $(MOCKCHROOT) --scrub all || exit 1
mock -r $(MOCKCHROOT) --buildsrpm --spec ./$(SPECFILE) --sources . --resultdir $(PWD) || exit 1
mock -r $(MOCKCHROOT) --rebuild *src.rpm --resultdir $(PWD) || exit 1

srpm: local
rpmbuild -bs --nodeps $(SPECFILE) --define "_sourcedir `pwd`"
rm -f $(PKGNAME)-$(VERSION).tar.gz $(PKGNAME)-$(VERSION)-tests.tar.gz
Expand Down
4 changes: 2 additions & 2 deletions blivet/devices/stratis.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def _set_passphrase(self, passphrase):

@property
def has_key(self):
return ((self.__passphrase not in ["", None]) or
(self._key_file and os.access(self._key_file, os.R_OK)))
return bool((self.__passphrase not in ["", None]) or
(self._key_file and os.access(self._key_file, os.R_OK)))

def _pre_create(self):
super(StratisPoolDevice, self)._pre_create()
Expand Down
38 changes: 23 additions & 15 deletions blivet/devicetree.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ def get_device_by_id(self, id_num, incomplete=False, hidden=False):
log_method_return(self, result)
return result

def resolve_device(self, devspec, blkid_tab=None, crypt_tab=None, options=None):
def resolve_device(self, devspec, blkid_tab=None, crypt_tab=None, options=None, subvolspec=None):
""" Return the device matching the provided device specification.
The spec can be anything from a device name (eg: 'sda3') to a device
Expand All @@ -615,6 +615,8 @@ def resolve_device(self, devspec, blkid_tab=None, crypt_tab=None, options=None):
:type crypt_tab: :class:`~.CryptTab`
:keyword options: mount options
:type options: str
:keyword subvolspec: btrfs subvolume specification
:type subvolspec: str
:returns: the device
:rtype: :class:`~.devices.StorageDevice` or None
"""
Expand Down Expand Up @@ -727,26 +729,32 @@ def resolve_device(self, devspec, blkid_tab=None, crypt_tab=None, options=None):
device = self.get_device_by_name(lv)

# check mount options for btrfs volumes in case it's a subvol
if device and device.type.startswith("btrfs") and options:
if device and device.type.startswith("btrfs") and (subvolspec or options):
# start with the volume -- not a subvolume
device = getattr(device, "volume", device)

attr = None
if "subvol=" in options:
attr = "name"
val = util.get_option_value("subvol", options)
elif "subvolid=" in options:
attr = "vol_id"
val = util.get_option_value("subvolid", options)
elif device.default_subvolume:
# default subvolume
device = device.default_subvolume

if attr and val:
if subvolspec:
for subvol in device.subvolumes:
if getattr(subvol, attr, None) == val:
if subvol.format.subvolspec == subvolspec:
device = subvol
break
elif options:
attr = None
if "subvol=" in options:
attr = "name"
val = util.get_option_value("subvol", options)
elif "subvolid=" in options:
attr = "vol_id"
val = util.get_option_value("subvolid", options)
elif device.default_subvolume:
# default subvolume
device = device.default_subvolume

if attr and val:
for subvol in device.subvolumes:
if getattr(subvol, attr, None) == val:
device = subvol
break

if device:
log.debug("resolved '%s' to '%s' (%s)", devspec, device.name, device.type)
Expand Down
4 changes: 2 additions & 2 deletions blivet/formats/luks.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ def _set_passphrase(self, passphrase):

@property
def has_key(self):
return ((self.__passphrase not in ["", None]) or
(self._key_file and os.access(self._key_file, os.R_OK)))
return bool((self.__passphrase not in ["", None]) or
(self._key_file and os.access(self._key_file, os.R_OK)))

@property
def formattable(self):
Expand Down
4 changes: 2 additions & 2 deletions blivet/formats/stratis.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def _set_passphrase(self, passphrase):

@property
def has_key(self):
return ((self.__passphrase not in ["", None]) or
(self._key_file and os.access(self._key_file, os.R_OK)))
return bool((self.__passphrase not in ["", None]) or
(self._key_file and os.access(self._key_file, os.R_OK)))

def unlock_pool(self):
if not self.locked_pool:
Expand Down
52 changes: 30 additions & 22 deletions blivet/iscsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
ISCSI_MODULES = ['cxgb3i', 'bnx2i', 'be2iscsi']


STORAGED_SERVICE = "org.freedesktop.UDisks2"
STORAGED_PATH = "/org/freedesktop/UDisks2"
STORAGED_MANAGER_PATH = "/org/freedesktop/UDisks2/Manager"
UDISKS_SERVICE = "org.freedesktop.UDisks2"
UDISKS_PATH = "/org/freedesktop/UDisks2"
UDISKS_MANAGER_PATH = "/org/freedesktop/UDisks2/Manager"
MANAGER_IFACE = "org.freedesktop.UDisks2.Manager"
INITIATOR_IFACE = MANAGER_IFACE + ".ISCSI.Initiator"
SESSION_IFACE = STORAGED_SERVICE + ".ISCSI.Session"
SESSION_IFACE = UDISKS_SERVICE + ".ISCSI.Session"


def has_iscsi():
Expand Down Expand Up @@ -89,7 +89,7 @@ def __init__(self, name, tpgt, address, port, iface):
@property
def conn_info(self):
"""The 5-tuple of connection info (no auth info). This form
is useful for interacting with storaged.
is useful for interacting with udisks.
"""
return (self.name, self.tpgt, self.address, self.port, self.iface)

Expand All @@ -110,18 +110,17 @@ class iSCSIDependencyGuard(util.DependencyGuard):

def _check_avail(self):
try:
if not safe_dbus.check_object_available(STORAGED_SERVICE, STORAGED_MANAGER_PATH, MANAGER_IFACE):
if not safe_dbus.check_object_available(UDISKS_SERVICE, UDISKS_MANAGER_PATH, MANAGER_IFACE):
return False
# storaged is modular and we need to make sure it has the iSCSI module
# loaded (this also autostarts storaged if it isn't running already)
safe_dbus.call_sync(STORAGED_SERVICE, STORAGED_MANAGER_PATH, MANAGER_IFACE,
"EnableModules", GLib.Variant("(b)", (True,)))
# Load the iscsi UDisks module (this also autostarts udisksd if needed)
safe_dbus.call_sync(UDISKS_SERVICE, UDISKS_MANAGER_PATH, MANAGER_IFACE,
"EnableModule", GLib.Variant("(sb)", ("iscsi", True,)))
except safe_dbus.DBusCallError:
return False
return safe_dbus.check_object_available(STORAGED_SERVICE, STORAGED_MANAGER_PATH, INITIATOR_IFACE)
return safe_dbus.check_object_available(UDISKS_SERVICE, UDISKS_MANAGER_PATH, INITIATOR_IFACE)


storaged_iscsi_required = iSCSIDependencyGuard()
udisks_iscsi_required = iSCSIDependencyGuard()


class iSCSI(object):
Expand Down Expand Up @@ -160,6 +159,11 @@ def __init__(self):
self._initiator = initiatorname
except Exception as e: # pylint: disable=broad-except
log.info("failed to get initiator name from iscsi firmware: %s", str(e))
else:
# write the firmware initiator to /etc/iscsi/initiatorname.iscsi
log.info("Setting up firmware iSCSI initiator name %s", self.initiator)
args = GLib.Variant("(sa{sv})", (initiatorname, None))
self._call_initiator_method("SetInitiatorName", args)

# So that users can write iscsi() to get the singleton instance
def __call__(self):
Expand All @@ -170,7 +174,7 @@ def __deepcopy__(self, memo_dict):
return self

@property
@storaged_iscsi_required(critical=False, eval_mode=util.EvalMode.onetime)
@udisks_iscsi_required(critical=False, eval_mode=util.EvalMode.onetime)
def available(self):
return True

Expand All @@ -181,7 +185,7 @@ def _connection(self):

return self.__connection

@storaged_iscsi_required(critical=True, eval_mode=util.EvalMode.onetime)
@udisks_iscsi_required(critical=True, eval_mode=util.EvalMode.onetime)
def _call_initiator_method(self, method, args=None):
"""Class a method of the ISCSI.Initiator DBus object
Expand All @@ -190,7 +194,7 @@ def _call_initiator_method(self, method, args=None):
:type params: GLib.Variant
"""
return safe_dbus.call_sync(STORAGED_SERVICE, STORAGED_MANAGER_PATH,
return safe_dbus.call_sync(UDISKS_SERVICE, UDISKS_MANAGER_PATH,
INITIATOR_IFACE, method, args,
connection=self._connection)

Expand All @@ -200,7 +204,7 @@ def initiator_set(self):
return self._initiator != ""

@property
@storaged_iscsi_required(critical=False, eval_mode=util.EvalMode.onetime)
@udisks_iscsi_required(critical=False, eval_mode=util.EvalMode.onetime)
def initiator(self):
if self._initiator != "":
return self._initiator
Expand All @@ -210,7 +214,7 @@ def initiator(self):
return raw_initiator.decode("utf-8", errors="replace")

@initiator.setter
@storaged_iscsi_required(critical=True, eval_mode=util.EvalMode.onetime)
@udisks_iscsi_required(critical=True, eval_mode=util.EvalMode.onetime)
def initiator(self, val):
if len(val) == 0:
raise ValueError(_("Must provide an iSCSI initiator name"))
Expand Down Expand Up @@ -273,16 +277,16 @@ def _login(self, node_info, extra=None):
if extra is None:
extra = dict()
extra["node.startup"] = GLib.Variant("s", "automatic")
extra["node.session.auth.chap_algs"] = GLib.Variant("s", "SHA3-256,SHA256,SHA1,MD5")
extra["node.session.auth.chap_algs"] = GLib.Variant("s", "SHA1,MD5")

args = GLib.Variant("(sisisa{sv})", node_info.conn_info + (extra,))
self._call_initiator_method("Login", args)

@storaged_iscsi_required(critical=False, eval_mode=util.EvalMode.onetime)
@udisks_iscsi_required(critical=False, eval_mode=util.EvalMode.onetime)
def _get_active_sessions(self):
try:
objects = safe_dbus.call_sync(STORAGED_SERVICE,
STORAGED_PATH,
objects = safe_dbus.call_sync(UDISKS_SERVICE,
UDISKS_PATH,
'org.freedesktop.DBus.ObjectManager',
'GetManagedObjects',
None)[0]
Expand All @@ -303,11 +307,15 @@ def _get_active_sessions(self):

return active

@storaged_iscsi_required(critical=False, eval_mode=util.EvalMode.onetime)
@udisks_iscsi_required(critical=False, eval_mode=util.EvalMode.onetime)
def _start_ibft(self):
if not flags.ibft:
return

# Make sure iscsi_ibft is loaded otherwise any atttempts will fail with
# 'Could not get list of targets from firmware. (err 21)'
util.run_program(['modprobe', '-a', 'iscsi_ibft'])

args = GLib.Variant("(a{sv})", ([], ))
try:
found_nodes, _n_nodes = self._call_initiator_method("DiscoverFirmware", args)
Expand Down
Loading

0 comments on commit b9a1646

Please sign in to comment.