Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exists=exists, size=size,
parents=parents,
sysfsPath=sysfsPath)
try:
self.level = level
except errors.DeviceError as e:
# Could not set the level, so set loose the parents that were
# added in superclass constructor.
for dev in self.parents:
dev.removeChild()
raise e
self.uuid = uuid
self._totalDevices = util.numeric_type(totalDevices)
self.memberDevices = util.numeric_type(memberDevices)
self.chunkSize = mdraid.MD_CHUNK_SIZE
if not self.exists and not isinstance(metadataVersion, str):
self.metadataVersion = "default"
else:
self.metadataVersion = metadataVersion
self.format = fmt
if self.parents and self.parents[0].type == "mdcontainer" and self.type != "mdbiosraidarray":
raise errors.DeviceError("A device with mdcontainer member must be mdbiosraidarray.")
if self.exists and self.mdadmFormatUUID and not flags.testing:
# this is a hack to work around mdadm's insistence on giving
# really high minors to arrays it has no config entry for
def do_task(self):
""" Check the filesystem.
:raises FSError: on failure
"""
error_msgs = self.availability_errors
if error_msgs:
raise FSError("\n".join(error_msgs))
try:
rc = util.run_program(self._fsck_command)
except OSError as e:
raise FSError("filesystem check failed: %s" % e)
error_msg = self._error_message(rc)
if error_msg is not None:
hdr = "%(type)s filesystem check failure on %(device)s: " % \
{"type": self.fs.type, "device": self.fs.device}
raise FSError(hdr + error_msg)
if not data:
break
sha256.update(data)
filesum = sha256.hexdigest()
log.debug("sha256 of %s is %s" % (self.data.method.url, filesum))
if self.data.method.checksum.lower() != filesum:
log.error("%s does not match checksum." % self.data.method.checksum)
exn = PayloadInstallError("Checksum of image does not match")
if errorHandler.cb(exn) == ERROR_RAISE:
raise exn
# Mount the image and check to see if it is a LiveOS/*.img
# style squashfs image. If so, move it to IMAGE_DIR and mount the real
# root image on INSTALL_TREE
blivet.util.mount(self.image_path, INSTALL_TREE, fstype="auto", options="ro")
if os.path.exists(INSTALL_TREE+"/LiveOS"):
# Find the first .img in the directory and mount that on INSTALL_TREE
img_files = glob.glob(INSTALL_TREE+"/LiveOS/*.img")
if img_files:
img_file = os.path.basename(sorted(img_files)[0])
# move the mount to IMAGE_DIR
os.makedirs(IMAGE_DIR, 0755)
# work around inability to move shared filesystems
iutil.execWithRedirect("mount",
["--make-rprivate", "/"])
iutil.execWithRedirect("mount",
["--move", INSTALL_TREE, IMAGE_DIR])
blivet.util.mount(IMAGE_DIR+"/LiveOS/"+img_file, INSTALL_TREE,
fstype="auto", options="ro")
from pyanaconda.constants import shortProductName # pylint: disable=redefined-outer-name
from pyanaconda.bootloader import get_bootloader # pylint: disable=redefined-outer-name
from pyanaconda.errors import errorHandler # pylint: disable=redefined-outer-name
from pyanaconda.errors import ERROR_RAISE # pylint: disable=redefined-outer-name
if hasattr(iutil, 'getTargetPhysicalRoot'):
# For anaconda versions > 21.43
_storageRoot = iutil.getTargetPhysicalRoot() # pylint: disable=no-name-in-module
_sysroot = iutil.getSysroot()
else:
# For prior anaconda versions
from pyanaconda.constants import ROOT_PATH # pylint: disable=redefined-outer-name,no-name-in-module
_storageRoot = _sysroot = ROOT_PATH
from pyanaconda.anaconda_log import program_log_lock
util.program_log_lock = program_log_lock
flags.installer_mode = True
except ValueError:
name = _("Linux on %s") % device.name
else:
# I'd like to make this finer grained, but it'd be very difficult
# to translate.
if not product or not version or not architecture:
name = _("Unknown Linux")
elif "linux" in product.lower():
name = _("%(product)s %(version)s for %(arch)s") % \
{"product": product, "version": version, "arch": architecture}
else:
name = _("%(product)s Linux %(version)s for %(arch)s") % \
{"product": product, "version": version, "arch": architecture}
(mounts, swaps) = _parse_fstab(devicetree, chroot=sysroot)
blivet_util.umount(mountpoint=sysroot)
if not mounts and not swaps:
# empty /etc/fstab. weird, but I've seen it happen.
continue
roots.append(Root(mounts=mounts, swaps=swaps, name=name))
return roots
def __deepcopy__(self, memo):
return util.variable_copy(self, memo, shallow=('_pyudev_observer'))
def verify_swap(storage, constraints, report_error, report_warning):
""" Verify the existence of swap.
:param storage: a storage to check
:param constraints: a dictionary of constraints
:param report_error: a function for error reporting
:param report_warning: a function for warning reporting
"""
swaps = storage.fsset.swap_devices
if not swaps:
installed = util.total_memory()
required = Size("%s MiB" % (constraints[STORAGE_MIN_RAM] + isys.NO_SWAP_EXTRA_RAM))
if not constraints[STORAGE_SWAP_IS_RECOMMENDED]:
if installed < required:
report_warning(_("You have not specified a swap partition. "
"%(requiredMem)s of memory is recommended to continue "
"installation without a swap partition, but you only "
"have %(installedMem)s.")
% {"requiredMem": required, "installedMem": installed})
else:
if installed < required:
report_error(_("You have not specified a swap partition. "
"%(requiredMem)s of memory is required to continue "
"installation without a swap partition, but you only "
"have %(installedMem)s.")
% {"requiredMem": required, "installedMem": installed})
def do_task(self):
error_msgs = self.availability_errors
if error_msgs:
raise FSError("\n".join(error_msgs))
try:
(ret, out) = util.run_program_and_capture_output(self._size_command)
if ret:
raise FSError("Failed to execute command %s." % self._size_command)
except OSError:
raise FSError("Failed to execute command %s." % self._size_command)
lines = out.splitlines()
if len(lines) != 2 or lines[0].strip() != "1K-blocks":
raise FSError("Failed to parse output of command %s." % self._size_command)
return Size("%s KiB" % lines[1])
"""
Post install activities, first copy the answer file
from location given in kickstart. Second copy cirrios
image and rabbitmq public key (both needed for offline packstack run)
"""
# Create Answers file from given URL TODO:Copy the answer file to host
if self.state == "True" and self.env == "anaconda":
os.mkdir(ROOT_PATH + ADDON_DIRECTORY)
# if (self.lines is not None) and not (self.lines == "") :
# answer_file = os.path.normpath(ROOT_PATH + ADDON_DIRECTORY + "answer-file.txt")
# with open(answer_file, "w") as fobj:
# fobj.write("%s\n" % self.lines)
# Copying repodata, cirrios image & rabbitmq public key to Host system from media
tmpdirectory = tempfile.mkdtemp()
util.mount(device="/dev/disk/by-label/CentOS\\x207\\x20x86_64", mountpoint=tmpdirectory, fstype="auto")
copy_tree(tmpdirectory + "/Packages/RDO", os.path.normcase(ROOT_PATH + ADDON_DIRECTORY))
util.umount(tmpdirectory)
shutil.rmtree(tmpdirectory)
with open(ROOT_PATH + '/etc/hosts', 'a') as file:
file.write('127.0.0.1 www.rabbitmq.com\n')
file.close()
# Copy Addon itself to /usr/share/anaconda/addons
#TODO: Once Packaged remove this step
if os.path.exists(ROOT_PATH + "/usr/share/anaconda/addons/org_centos_cloud"):
os.mkdir(ROOT_PATH + "/usr/share/anaconda/addons/org_centos_cloud")
shutil.copytree("/usr/share/anaconda/addons/org_centos_cloud",
os.path.normcase(ROOT_PATH + "/usr/share/anaconda/addons/org_centos_cloud"))
# Enabling initial-setup-text service,
# TODO: Check if Graphical OR Text Service to Enable
#initial-setup-text.service: Adding $HOME=/root ENV Variable & Enabling
def writeEscrowPackets(storage):
escrowDevices = [d for d in storage.devices if d.format.type == 'luks' and
d.format.escrow_cert]
if not escrowDevices:
return
log.debug("escrow: writeEscrowPackets start")
backupPassphrase = blockdev.crypto.generate_backup_passphrase()
try:
escrowDir = getSysroot() + "/root"
log.debug("escrow: writing escrow packets to %s", escrowDir)
util.makedirs(escrowDir)
for device in escrowDevices:
log.debug("escrow: device %s: %s",
repr(device.path), repr(device.format.type))
device.format.escrow(escrowDir,
backupPassphrase)
except (IOError, RuntimeError) as e:
# TODO: real error handling
log.error("failed to store encryption key: %s", e)
log.debug("escrow: writeEscrowPackets done")