Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.openframe.data.repository.device.MachineRepository;
import com.openframe.data.service.TenantIdProvider;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Arrays;
Expand All @@ -21,6 +22,7 @@

import static org.springframework.util.CollectionUtils.isEmpty;

@Slf4j
@Component
@RequiredArgsConstructor
public class PackageManagerAvailability {
Expand Down Expand Up @@ -61,9 +63,10 @@ public void requireSoftwareManageable(Collection<String> machineIds, Collection<
List<String> notYetUsable = machines.stream()
.flatMap(machine -> notYetUsable(machine, packageManagers))
.toList();
// A MISSING or UNKNOWN state changes over time (user logs in, bootstrap finishes),
// so one such device must not block the whole request.
if (!notYetUsable.isEmpty()) {
throw new BadRequestException("Package manager not yet usable on these devices: " + notYetUsable
+ ". Wait for the bootstrap to finish or remove the devices.");
log.info("Package manager not yet usable on these devices, accepting anyway: {}", notYetUsable);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,15 @@ void requireSoftwareManageable_unmanageableDevice_badRequestNamesOnlyIt() {

@ParameterizedTest
@EnumSource(value = PackageManagerState.class, names = {"MISSING", "UNKNOWN"})
void requireSoftwareManageable_packageManagerNotYetUsable_badRequestNamesDeviceAndManager(PackageManagerState state) {
void requireSoftwareManageable_packageManagerNotYetUsable_passes(PackageManagerState state) {
// setup
Machine arm = machine("m-arm", Map.of(BREW, state, WINGET, UNSUPPORTED, CHOCO, UNSUPPORTED));
stubMachines(Set.of("m-arm"), arm);
List<String> machineIds = List.of("m-arm");
List<PackageManagerType> managers = List.of(BREW);

// execution + verifications
assertThatThrownBy(() -> availability.requireSoftwareManageable(machineIds, managers))
.isInstanceOf(BadRequestException.class)
.hasMessageContaining("m-arm BREW=" + state);
assertThatCode(() -> availability.requireSoftwareManageable(machineIds, managers)).doesNotThrowAnyException();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public void testSubmitInstallNow() {
HOSTNAME + " is " + device.getStatus() + "; an install submitted now would wait for it and land after this run");
String winget = DeviceApi.getPackageManagerState(device.getMachineId(), "winget");
assumeTrue(winget == null || "PRESENT".equals(winget),
HOSTNAME + "'s agent reports winget=" + winget + "; submit refuses a package manager that is not yet usable (MISSING or UNKNOWN)");
HOSTNAME + "'s agent reports winget=" + winget + "; an install cannot run while the package manager is not yet usable (MISSING or UNKNOWN)");
assumeTrue(MachineConfig.isConfigured() && HOSTNAME.equalsIgnoreCase(MachineConfig.getHostname()),
"No SSH channel to " + HOSTNAME + " (TARGET_* / test.machine); it is needed to check the package is absent first and to uninstall it after");
assumeTrue(!new SshMachineVerifier().windowsProgramInstalled(PROGRAM),
Expand Down
Loading