Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

ensure VM IDs are unique before calling Azure reimage/delete APIs #1023

Merged
merged 3 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/api-service/__app__/onefuzzlib/azure/vmss.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import logging
import os
from typing import Any, Dict, List, Optional, Union, cast
from typing import Any, Dict, List, Optional, Set, Union, cast
from uuid import UUID

from azure.core.exceptions import (
Expand Down Expand Up @@ -151,50 +151,52 @@ def check_can_update(name: UUID) -> Any:
return vmss


def reimage_vmss_nodes(name: UUID, vm_ids: List[UUID]) -> Optional[Error]:
def reimage_vmss_nodes(name: UUID, vm_ids: Set[UUID]) -> Optional[Error]:
check_can_update(name)

resource_group = get_base_resource_group()
logging.info("reimaging scaleset VM - name: %s vm_ids:%s", name, vm_ids)
compute_client = get_compute_client()

instance_ids = []
instance_ids = set()
machine_to_id = list_instance_ids(name)
for vm_id in vm_ids:
if vm_id in machine_to_id:
instance_ids.append(machine_to_id[vm_id])
instance_ids.add(machine_to_id[vm_id])
else:
logging.info("unable to find vm_id for %s:%s", name, vm_id)

if instance_ids:
compute_client.virtual_machine_scale_sets.begin_reimage_all(
resource_group,
str(name),
VirtualMachineScaleSetVMInstanceIDs(instance_ids=instance_ids),
VirtualMachineScaleSetVMInstanceIDs(instance_ids=list(instance_ids)),
)
return None


def delete_vmss_nodes(name: UUID, vm_ids: List[UUID]) -> Optional[Error]:
def delete_vmss_nodes(name: UUID, vm_ids: Set[UUID]) -> Optional[Error]:
check_can_update(name)

resource_group = get_base_resource_group()
logging.info("deleting scaleset VM - name: %s vm_ids:%s", name, vm_ids)
compute_client = get_compute_client()

instance_ids = []
instance_ids = set()
machine_to_id = list_instance_ids(name)
for vm_id in vm_ids:
if vm_id in machine_to_id:
instance_ids.append(machine_to_id[vm_id])
instance_ids.add(machine_to_id[vm_id])
else:
logging.info("unable to find vm_id for %s:%s", name, vm_id)

if instance_ids:
compute_client.virtual_machine_scale_sets.begin_delete_instances(
resource_group,
str(name),
VirtualMachineScaleSetVMInstanceRequiredIDs(instance_ids=instance_ids),
VirtualMachineScaleSetVMInstanceRequiredIDs(
instance_ids=list(instance_ids)
),
)
return None

Expand Down
8 changes: 4 additions & 4 deletions src/api-service/__app__/onefuzzlib/workers/scalesets.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ def delete_nodes(self, nodes: List[Node]) -> None:
)
return

machine_ids = []
machine_ids = set()
for node in nodes:
if node.debug_keep_node:
logging.warning(
Expand All @@ -547,7 +547,7 @@ def delete_nodes(self, nodes: List[Node]) -> None:
node.machine_id,
)
else:
machine_ids.append(node.machine_id)
machine_ids.add(node.machine_id)

logging.info(
SCALESET_LOG_PREFIX + "deleting nodes scaleset_id:%s machine_id:%s",
Expand Down Expand Up @@ -585,7 +585,7 @@ def reimage_nodes(self, nodes: List[Node]) -> None:
)
return

machine_ids = []
machine_ids = set()
for node in nodes:
if node.debug_keep_node:
logging.warning(
Expand All @@ -595,7 +595,7 @@ def reimage_nodes(self, nodes: List[Node]) -> None:
node.machine_id,
)
else:
machine_ids.append(node.machine_id)
machine_ids.add(node.machine_id)

if not machine_ids:
logging.info(
Expand Down