Skip to content

Commit

Permalink
Add support to update iso file for set_boot_order
Browse files Browse the repository at this point in the history
Added iso file path when user change the boot order.
It will allow us in a cluster to boot nodes with different iso files
uscases:
 - Day2 master must be in the same network as day1 masters, we can re-use
   one of the existing nodes to become a day2 master by overriding iso file
 - Static network changes requires to download the iso again but we dont want
    to override all nodes iso path
 - Validate re-download iso file when different configurations (proxy)
 - Add support for re-usable nodes plus check how we manage multiple iso in
   a cluster deployment

In case we want to re-use the node with same network params.
node.set_boot_order(cd_first=True, cdrom_iso_path="/tmp/test.iso)
node.start()
  • Loading branch information
bkopilov committed Jul 2, 2023
1 parent 8310bc2 commit 5a6cf5e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def _wait_till_domain_has_ips(self, domain, timeout=600, interval=10):
)

@staticmethod
def _clean_domain_os_boot_data(node_xml):
def _clean_domain_os_boot_data(node_xml: minidom.Document) -> None:
os_element = node_xml.getElementsByTagName("os")[0]

for el in os_element.getElementsByTagName("boot"):
Expand All @@ -519,6 +519,16 @@ def _clean_domain_os_boot_data(node_xml):
for boot in disk.getElementsByTagName("boot"):
disk.removeChild(boot)

@staticmethod
def _update_cdrom_file_path(node_xml: minidom.Document, cdrom_iso_path: str) -> None:
cdrom_element = []
for disk in node_xml.getElementsByTagName("disk"):
if '<disk type="file" device="cdrom">' in disk.toxml():
cdrom_element.append(disk)
assert len(cdrom_element) == 1, "Expecting for a cdrom device - not found"
source_file_element = cdrom_element[0].getElementsByTagName("source")[0]
source_file_element.setAttribute("file", cdrom_iso_path)

def set_per_device_boot_order(self, node_name, key: Callable[[Disk], int]):
log.info(f"Changing boot order for node: {node_name}")
node = self.libvirt_connection.lookupByName(node_name)
Expand All @@ -543,7 +553,7 @@ def set_per_device_boot_order(self, node_name, key: Callable[[Disk], int]):
self.shutdown_node(node_name)
self.start_node(node_name)

def set_boot_order(self, node_name, cd_first=False):
def set_boot_order(self, node_name: str, cd_first: bool = False, cdrom_iso_path: str = None) -> None:
log.info(f"Going to set the following boot order: cd_first: {cd_first}, " f"for node: {node_name}")
node = self.libvirt_connection.lookupByName(node_name)
current_xml = node.XMLDesc(0)
Expand All @@ -557,6 +567,10 @@ def set_boot_order(self, node_name, cd_first=False):
second = xml.createElement("boot")
second.setAttribute("dev", "hd" if cd_first else "cdrom")
os_element.appendChild(second)

if cdrom_iso_path:
self._update_cdrom_file_path(xml, cdrom_iso_path)

# Apply new machine xml
dom = self.libvirt_connection.defineXML(xml.toprettyxml())
if dom is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ def is_service_active(self, service):
output = self.run_command(f"sudo systemctl is-active {service}.service || true")
return output.strip() == "active"

def set_boot_order(self, cd_first=False):
def set_boot_order(self, cd_first=False, cdrom_iso_path=None) -> None:
log.info("Setting boot order with cd_first=%s on %s", cd_first, self.name)
self.node_controller.set_boot_order(node_name=self.name, cd_first=cd_first)
self.node_controller.set_boot_order(node_name=self.name, cd_first=cd_first, cdrom_iso_path=cdrom_iso_path)

def set_per_device_boot_order(self, key: Callable[[Disk], int]):
log.info("Setting boot order on %s", self.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def prepare_nodes(self):
def is_active(self, node_name) -> bool:
pass

def set_boot_order(self, node_name, cd_first=False) -> None:
def set_boot_order(self, node_name: str, cd_first: bool = False, cdrom_iso_path: str = None) -> None:
pass

@abstractmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,14 @@ def get_ingress_and_api_vips(self):
log.info(f"Found 2 optional VIPs: {free_ips}")
return {"api_vip": free_ips.pop(), "ingress_vip": free_ips.pop()}

def set_boot_order(self, node_name, cd_first=False) -> None:
def set_boot_order(self, node_name, cd_first=False, cdrom_iso_path=None) -> None:
vm = self._get_provider_vm(tf_vm_name=node_name)
if cd_first:
vm.update_boot_order(VMBootDevices.default_boot_order())
else:
vm.update_boot_order([VMBootDevices.DISK, VMBootDevices.CDROM, VMBootDevices.NETWORK])
if cdrom_iso_path:
raise NotImplementedError("Updating cdrom iso file path is not implemented")

@property
def terraform_vm_resource_type(self) -> str:
Expand Down

0 comments on commit 5a6cf5e

Please sign in to comment.