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

Commit

Permalink
ensure VM IDs are unique before calling Azure reimage/delete APIs (#1023
Browse files Browse the repository at this point in the history
)
  • Loading branch information
bmc-msft authored Jun 25, 2021
1 parent 880039a commit 883c93a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
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

0 comments on commit 883c93a

Please sign in to comment.