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
24 changes: 20 additions & 4 deletions framework/python/src/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,21 @@ async def save_device(self, request: Request, response: Response):
response.status_code = status.HTTP_400_BAD_REQUEST
return self._generate_msg(False, "Invalid request received")

# Check if device with same MAC exists
device = self._session.get_device(device_json.get(DEVICE_MAC_ADDR_KEY))

if device is not None:

response.status_code = status.HTTP_409_CONFLICT
return self._generate_msg(
False, "A device with that MAC address already exists")

# Check if device with same manufacturer and model exists
device = self._session.get_device_by_make_and_model(
device_json.get(DEVICE_MANUFACTURER_KEY),
device_json.get(DEVICE_MODEL_KEY)
)

if device is None:

# Create new device
Expand All @@ -468,7 +481,7 @@ async def save_device(self, request: Request, response: Response):

response.status_code = status.HTTP_409_CONFLICT
return self._generate_msg(
False, "A device with that " + "MAC address already exists")
False, "A device with that manufacturer and model already exists")

return device.to_config_json()

Expand Down Expand Up @@ -543,14 +556,17 @@ async def get_report(self, response: Response, device_name, timestamp):
device = self._session.get_device_by_name(device_name)

# 1.3 file path
file_path = os.path.join(DEVICES_PATH, device_name, "reports", timestamp,'test',
device.mac_addr.replace(':',''),
file_path = os.path.join(
DEVICES_PATH,
device_name,
"reports",
timestamp,"test",
device.mac_addr.replace(":",""),
"report.pdf")
if not os.path.isfile(file_path):
# pre 1.3 file path
file_path = os.path.join(DEVICES_PATH, device_name, "reports", timestamp,
"report.pdf")


LOGGER.debug(f"Received get report request for {device_name} / {timestamp}")
if os.path.isfile(file_path):
Expand Down
5 changes: 5 additions & 0 deletions framework/python/src/common/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ def get_device_by_name(self, device_name):
return device
return None

def get_device_by_make_and_model(self, make, model):
for device in self._device_repository:
if device.manufacturer == make and device.model == model:
return device

def get_device_repository(self):
return self._device_repository

Expand Down