Hello community, here is the log from the commit of package python3-azuremetadata for openSUSE:Leap:15.2 checked in at 2020-04-25 19:06:24 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Leap:15.2/python3-azuremetadata (Old) and /work/SRC/openSUSE:Leap:15.2/.python3-azuremetadata.new.2738 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python3-azuremetadata" Sat Apr 25 19:06:24 2020 rev:2 rq:797167 version:5.0.1 Changes: -------- --- /work/SRC/openSUSE:Leap:15.2/python3-azuremetadata/python3-azuremetadata.changes 2020-04-14 14:21:39.441304772 +0200 +++ /work/SRC/openSUSE:Leap:15.2/.python3-azuremetadata.new.2738/python3-azuremetadata.changes 2020-04-25 19:06:26.383770526 +0200 @@ -1,0 +2,6 @@ +Tue Apr 21 04:24:27 UTC 2020 - Ivan Kapelyukhin <ikapelyuk...@suse.com> + +- Version 5.0.1 +- Use lsblk for root device detection (bsc#1169921) + +------------------------------------------------------------------- Old: ---- python3-azuremetadata-5.0.0.tar.bz2 New: ---- python3-azuremetadata-5.0.1.tar.bz2 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python3-azuremetadata.spec ++++++ --- /var/tmp/diff_new_pack.OsqdPH/_old 2020-04-25 19:06:26.679771163 +0200 +++ /var/tmp/diff_new_pack.OsqdPH/_new 2020-04-25 19:06:26.683771171 +0200 @@ -18,7 +18,7 @@ %define upstream_name azuremetadata Name: python3-azuremetadata -Version: 5.0.0 +Version: 5.0.1 # Packaged renamed in SLE15 Provides: azuremetadata Obsoletes: azuremetadata < 5.0.0 ++++++ python3-azuremetadata-5.0.0.tar.bz2 -> python3-azuremetadata-5.0.1.tar.bz2 ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python3-azuremetadata-5.0.0/lib/azuremetadata/VERSION new/python3-azuremetadata-5.0.1/lib/azuremetadata/VERSION --- old/python3-azuremetadata-5.0.0/lib/azuremetadata/VERSION 2020-03-31 12:39:15.552001739 +0200 +++ new/python3-azuremetadata-5.0.1/lib/azuremetadata/VERSION 2020-04-21 14:42:42.873454534 +0200 @@ -1 +1 @@ -5.0.0 \ No newline at end of file +5.0.1 \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python3-azuremetadata-5.0.0/lib/azuremetadata/azuremetadata.py new/python3-azuremetadata-5.0.1/lib/azuremetadata/azuremetadata.py --- old/python3-azuremetadata-5.0.0/lib/azuremetadata/azuremetadata.py 2020-03-31 12:39:15.552001739 +0200 +++ new/python3-azuremetadata-5.0.1/lib/azuremetadata/azuremetadata.py 2020-04-21 14:42:42.873454534 +0200 @@ -50,7 +50,7 @@ def get_disk_tag(self, device=None): if not device: - device = self._find_root_device() + device = self._find_block_device() if not device: return '' @@ -65,19 +65,46 @@ return '' @staticmethod - def _find_root_device(): + def _find_block_device(mountpoint="/"): """Returns detected root device path or None if detection failed.""" + + out, err = AzureMetadata._get_lsblk_output() + + if err or not out: + return None + else: + try: + data = json.loads(out.decode("utf-8")) + except json.decoder.JSONDecodeError: + return None + + for blockdevice in data.get("blockdevices", []): + if AzureMetadata._blockdevice_has_mountpoint(blockdevice, mountpoint): + return str.format("/dev/{}", blockdevice["name"]) + + return None + + @staticmethod + def _get_lsblk_output(): proc = subprocess.Popen( - ["findmnt", "--first-only", "--noheadings", "--output=SOURCE", "--nofsroot", "/"], + ["lsblk", "--json"], stdout=subprocess.PIPE, stderr=subprocess.PIPE ) out, err = proc.communicate() - if err or not out: - return None - else: - return out.decode("utf-8").strip() + return out, err + + @staticmethod + def _blockdevice_has_mountpoint(item, mountpoint): + for child in item.get("children", []): + if child["mountpoint"] == mountpoint: + return True + + if AzureMetadata._blockdevice_has_mountpoint(child, mountpoint): + return True + + return False @staticmethod def _make_request(url):