1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

Fail in a more comprehensible way when a WorkingCopy lease omits or mangles "repositories.map"

Summary: Ref T13676. When the required "repositories.map" attribute is omitted, `bin/drydock lease` currently fatals in an unhelpful way when trying to lease a working copy.

Test Plan:
Ran `bin/drydock lease --type working-copy` with no attributes, after following steps in T13676.

```
<Allocation Failed> One or more blueprints promised a new resource, but failed when allocating: [PhutilAggregateException] All blueprints failed to allocate a suitable new resource when trying to allocate lease ("PHID-DRYL-orbtwtlinksm3xqpyhmw").
    - Exception: Working copy lease is missing required attribute "repositories.map".

      Attribute "repositories.map" should be a map of repository specifications.
```

Subscribers: yelirekim, PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13676

Differential Revision: https://secure.phabricator.com/D21796
This commit is contained in:
epriestley 2022-05-03 11:31:26 -07:00
parent 00a20d3cdc
commit d1fd2975b0

View file

@ -135,14 +135,7 @@ final class DrydockWorkingCopyBlueprintImplementation
->setAllowedBlueprintPHIDs($blueprint_phids);
$resource->setAttribute('host.leasePHID', $host_lease->getPHID());
$map = $lease->getAttribute('repositories.map');
foreach ($map as $key => $value) {
$map[$key] = array_select_keys(
$value,
array(
'phid',
));
}
$map = $this->getWorkingCopyRepositoryMap($lease);
$resource->setAttribute('repositories.map', $map);
$slot_lock = $this->getConcurrentResourceLimitSlotLock($blueprint);
@ -157,6 +150,44 @@ final class DrydockWorkingCopyBlueprintImplementation
return $resource;
}
private function getWorkingCopyRepositoryMap(DrydockLease $lease) {
$attribute = 'repositories.map';
$map = $lease->getAttribute($attribute);
// TODO: Leases should validate their attributes more formally.
if (!is_array($map) || !$map) {
$message = array();
if ($map === null) {
$message[] = pht(
'Working copy lease is missing required attribute "%s".',
$attribute);
} else {
$message[] = pht(
'Working copy lease has invalid attribute "%s".',
$attribute);
}
$message[] = pht(
'Attribute "repositories.map" should be a map of repository '.
'specifications.');
$message = implode("\n\n", $message);
throw new Exception($message);
}
foreach ($map as $key => $value) {
$map[$key] = array_select_keys(
$value,
array(
'phid',
));
}
return $map;
}
public function activateResource(
DrydockBlueprint $blueprint,
DrydockResource $resource) {