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
30 changes: 30 additions & 0 deletions tests/test_director.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,36 @@ def test_03_add_new_vehicle(self):



def test_04_remove_vehicle(self):

# Register a new vehicle, to remove it afterwards
vin = 'testcar'
TestDirector.instance.add_new_vehicle(vin)
os.chdir(uptane.WORKING_DIR)

# The vin should be present in the inventory db.
self.assertIn(vin, TestDirector.instance.vehicle_repositories)

# Remove the new vehicle
# This also removes the TUF repository of the vehicle containing
# the director metadata for that vehicle
TestDirector.instance.remove_vehicle(vin)

# Check resulting contents of the Director
self.assertNotIn(vin, TestDirector.instance.vehicle_repositories)
self.assertNotIn(vin, os.walk(TestDirector.instance.director_repos_dir))

# Check resulting contents of the inventorydb
self.assertNotIn(vin, inventory.ecus_by_vin)
self.assertNotIn(vin, inventory.primary_ecus_by_vin)
self.assertNotIn(vin, inventory.vehicle_manifests)
self.assertNotIn(vin, inventory.ecu_manifests)
self.assertNotIn(vin, inventory.ecu_public_keys)






def test_05_register_ecu_serial(self):

Expand Down
33 changes: 33 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 @@ -463,6 +464,18 @@ def add_new_vehicle(self, vin, primary_ecu_serial=None):



def remove_vehicle(self, vin):
"""
For removing vehicles and all the ECU registered under that vehicle

"""
inventory.deregister_vehicle(vin)

self.remove_director_repo_for_vehicle(vin)





def create_director_repo_for_vehicle(self, vin):
"""
Expand Down Expand Up @@ -526,6 +539,26 @@ def create_director_repo_for_vehicle(self, vin):



def remove_director_repo_for_vehicle(self, vin):
"""
Remove the repository object and corresponding keys
for a given vehicle identifier.

"""

uptane.formats.VIN_SCHEMA.check_match(vin)

# Remove the VIN repository for the Director repository
vin_dir = uptane.common.scrub_filename(vin, self.director_repos_dir)
shutil.rmtree(vin_dir)

# Remove the reference of the repository from the Director
buff = 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
18 changes: 18 additions & 0 deletions uptane/services/inventorydb.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,24 @@ def register_vehicle(vin, primary_ecu_serial=None, overwrite=True):



def deregister_vehicle(vin):

if vin not in ecus_by_vin:
raise uptane.UnknownVehicle('The given VIN, ' + repr(vin) + ', is not '
'registered.')


buff = ecus_by_vin.pop(vin)
buff = vehicle_manifests.pop(vin)
buff = primary_ecus_by_vin.pop(vin)
if vin in ecu_manifests:
buff = ecu_manifests.pop(vin)
if vin in ecu_public_keys:
buff = ecu_public_keys.pop(vin)





def check_vin_registered(vin):

Expand Down