Skip to content
This repository was archived by the owner on Mar 29, 2022. It is now read-only.
Open
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
28 changes: 28 additions & 0 deletions tests/test_director.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,34 @@ def test_60_register_vehicle(self):



def test_61_delete_existing_vehicle(self):

vin = 'democar'

self.assertTrue(inventory.ecus_by_vin)
self.assertTrue(inventory.ecu_public_keys)
self.assertTrue(inventory.primary_ecus_by_vin)
self.assertTrue(inventory.vehicle_manifests)
self.assertTrue(inventory.ecu_manifests)

self.assertIsNotNone(inventory.get_last_vehicle_manifest(vin))

#Delete the vehicle
TestDirector.instance.remove_vehicle(vin)
os.chdir(uptane.WORKING_DIR)

self.assertNotIn(vin, inventory.ecus_by_vin)
self.assertNotIn(vin, inventory.primary_ecus_by_vin)

with self.assertRaises(uptane.UnknownVehicle):
inventory.get_last_vehicle_manifest(vin)

#check vin no longer exists in the repo
self.assertNotIn(vin, TestDirector.instance.vehicle_repositories)





# Run unit test.
if __name__ == '__main__':
Expand Down
29 changes: 29 additions & 0 deletions uptane/services/director.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

import os
import hashlib
import shutil

from uptane.encoding.asn1_codec import DATATYPE_TIME_ATTESTATION
from uptane.encoding.asn1_codec import DATATYPE_ECU_MANIFEST
Expand Down Expand Up @@ -464,6 +465,16 @@ def add_new_vehicle(self, vin, primary_ecu_serial=None):



def remove_vehicle(self, vin):

inventory.deregister_vehicle(vin)

self.delete_director_repo_for_vehicle(vin)





def create_director_repo_for_vehicle(self, vin):
"""
Creates a separate repository object for a given vehicle identifier.
Expand Down Expand Up @@ -526,6 +537,24 @@ def create_director_repo_for_vehicle(self, vin):




def delete_director_repo_for_vehicle(self, vin):
uptane.formats.VIN_SCHEMA.check_match(vin)
os.chdir(self.director_repos_dir)

vin = uptane.common.scrub_filename(vin, self.director_repos_dir)
vin = os.path.relpath(vin, self.director_repos_dir)

existing_vehicle_repo = self.vehicle_repositories.get(vin)

if existing_vehicle_repo:
shutil.rmtree(existing_vehicle_repo.repository_name)
self.vehicle_repositories.pop(vin)





def add_target_for_ecu(self, vin, ecu_serial, target_filepath):
"""
Add a target to the repository for a vehicle, marked as being for a
Expand Down
13 changes: 13 additions & 0 deletions uptane/services/inventorydb.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,19 @@ def register_vehicle(vin, primary_ecu_serial=None, overwrite=True):



def deregister_vehicle(vin):

_check_registration_is_sane(vin)
check_vin_registered(vin)

#If no error is found, delete from dictionaries
ecus_by_vin.pop(vin)
vehicle_manifests.pop(vin)
primary_ecus_by_vin.pop(vin)





def check_vin_registered(vin):

Expand Down