Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NXDRIVE-2844: Nuxeo Drive transfer failed after removing hardware (Sourcery refactored) #4047

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b3e1523
NXDRIVE-2844: Nuxeo Drive transfer failed after removing hardware
gitofanindya Jul 27, 2023
21a4bea
NXDRIVE-2844: Nuxeo Drive transfer failed after removing hardware upd…
gitofanindya Jul 27, 2023
dff6f12
NXDRIVE-2844: Nuxeo Drive transfer failed after removing hardware upd…
gitofanindya Jul 27, 2023
c9caed5
NXDRIVE-2844: Nuxeo Drive transfer failed after removing hardware upd…
gitofanindya Jul 27, 2023
80de1c7
NXDRIVE-2844: Nuxeo Drive transfer failed after removing hardware wor…
gitofanindya Jul 27, 2023
270556e
NXDRIVE-2844: Nuxeo Drive transfer failed after removing hardware wor…
gitofanindya Jul 27, 2023
c07fc6e
NXDRIVE-2844: Nuxeo Drive transfer failed after removing hardware wor…
gitofanindya Jul 27, 2023
be322c2
NXDRIVE-2844: Nuxeo Drive transfer failed after removing hardware wor…
gitofanindya Jul 27, 2023
4a4cda2
NXDRIVE-2844: Nuxeo Drive transfer failed after removing hardware wor…
gitofanindya Jul 27, 2023
e347ac9
NXDRIVE-2844: Nuxeo Drive transfer failed after removing hardware wor…
gitofanindya Jul 27, 2023
5b65684
NXDRIVE-2844: Nuxeo Drive transfer failed after removing hardware wor…
gitofanindya Jul 27, 2023
ecc1113
NXDRIVE-2844: Nuxeo Drive transfer failed after removing hardware wor…
gitofanindya Jul 27, 2023
87932f7
NXDRIVE-2844: Nuxeo Drive transfer failed after removing hardware wor…
gitofanindya Jul 27, 2023
e2b9df1
NXDRIVE-2844: Nuxeo Drive transfer failed after removing hardware wor…
gitofanindya Jul 27, 2023
54adb44
NXDRIVE-2844: Nuxeo Drive transfer failed after removing hardware wor…
gitofanindya Jul 27, 2023
112d4e5
NXDRIVE-2844: Nuxeo Drive transfer failed after removing hardware wor…
gitofanindya Jul 27, 2023
f25ef9c
NXDRIVE-2844: Nuxeo Drive transfer failed after removing hardware wor…
gitofanindya Jul 27, 2023
a13f41b
NXDRIVE-2844: Nuxeo Drive transfer failed after removing hardware wor…
gitofanindya Jul 28, 2023
92bc486
NXDRIVE-2844: Nuxeo Drive transfer failed after removing hardware wor…
gitofanindya Jul 28, 2023
1f01d64
'Refactored by Sourcery'
Jul 28, 2023
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
1 change: 1 addition & 0 deletions docs/changes/5.3.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Release date: `2023-xx-xx`

- [NXDRIVE-2812](https://jira.nuxeo.com/browse/NXDRIVE-2812): Update Github Action for set-output and save-state
- [NXDRIVE-2838](https://jira.nuxeo.com/browse/NXDRIVE-2838): Fix Release build
- [NXDRIVE-2844](https://jira.nuxeo.com/browse/NXDRIVE-2844): Nuxeo Drive transfer failed after removing hardware
- [NXDRIVE-2363](https://jira.nuxeo.com/browse/NXDRIVE-2363): MacOS Application auto-restart does not work since 4.3.0

### Direct Edit
Expand Down
59 changes: 28 additions & 31 deletions nxdrive/engine/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@
try:
return self.dao.acquire_state(self.thread_id, item.id)
except sqlite3.OperationalError:
state = self.dao.get_state_from_id(item.id)
if state:
if state := self.dao.get_state_from_id(item.id):

Check warning on line 294 in nxdrive/engine/processor.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/engine/processor.py#L294

Added line #L294 was not covered by tests
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Processor._get_next_doc_pair refactored with the following changes:

if (
WINDOWS
and state.pair_state == "locally_moved"
Expand Down Expand Up @@ -460,9 +459,7 @@
log.info("The document does not exist anymore locally")
self.dao.remove_state(doc_pair)
elif error in LONG_FILE_ERRORS:
self.dao.remove_filter(
doc_pair.remote_parent_path + "/" + doc_pair.remote_ref
)
self.dao.remove_filter(f"{doc_pair.remote_parent_path}/{doc_pair.remote_ref}")

Check warning on line 462 in nxdrive/engine/processor.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/engine/processor.py#L462

Added line #L462 was not covered by tests
Comment on lines -463 to +462
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Processor._execute refactored with the following changes:

self.engine.longPathError.emit(doc_pair)
elif hasattr(exc, "trash_issue"):
"""
Expand All @@ -475,18 +472,19 @@
else:
self._handle_pair_handler_exception(doc_pair, handler_name, exc)
except RuntimeError as exc:
if "but the refreshed credentials are still expired" in str(exc):
log.warning(
"AWS credentials were refreshed, but the refreshed credentials are still expired"
)
log.info("Reinitializing the upload")
self.dao.remove_transfer(
"upload",
doc_pair=doc_pair.id,
is_direct_transfer=doc_pair.local_state == "direct",
)
else:
if "but the refreshed credentials are still expired" not in str(

Check warning on line 475 in nxdrive/engine/processor.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/engine/processor.py#L475

Added line #L475 was not covered by tests
exc
):
raise
log.warning(

Check warning on line 479 in nxdrive/engine/processor.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/engine/processor.py#L479

Added line #L479 was not covered by tests
"AWS credentials were refreshed, but the refreshed credentials are still expired"
)
log.info("Reinitializing the upload")
self.dao.remove_transfer(

Check warning on line 483 in nxdrive/engine/processor.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/engine/processor.py#L482-L483

Added lines #L482 - L483 were not covered by tests
"upload",
doc_pair=doc_pair.id,
is_direct_transfer=doc_pair.local_state == "direct",
)
except Exception as exc:
# Workaround to forward unhandled exceptions to sys.excepthook between all Qthreads
sys.excepthook(*sys.exc_info())
Expand Down Expand Up @@ -562,18 +560,20 @@
log.debug(f"The session is paused, skipping <DocPair[{doc_pair.id}]>")
return

if WINDOWS:
path = doc_pair.local_path
else:
# The path retrieved from the database will have its starting slash trimmed, restore it
path = Path(f"/{doc_pair.local_path}")

path = doc_pair.local_path if WINDOWS else Path(f"/{doc_pair.local_path}")
Comment on lines -565 to +563
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Processor._synchronize_direct_transfer refactored with the following changes:

This removes the following comments ( why? ):

# The path retrieved from the database will have its starting slash trimmed, restore it

if not path.exists():
log.warning(
f"Cancelling Direct Transfer of {path!r} because it does not exist anymore"
)
self._direct_transfer_cancel(doc_pair)
self.engine.directTranferError.emit(path)
if session:
log.warning(
f"Pausing Direct Transfer of {path!r} because it does not exist. \
Please validate the path and resume."
)
self.dao.pause_session(session.uid)
else:
log.warning(
f"Cancelling Direct Transfer of {path!r} because it does not exist."
)
self._direct_transfer_cancel(doc_pair)
return

# Do the upload
Expand Down Expand Up @@ -608,9 +608,7 @@
# Clean-up
self.dao.remove_state(doc_pair, recursive=recursive)

# Update session then handle the status
session = self.dao.get_session(doc_pair.session)
if session:
if session := self.dao.get_session(doc_pair.session):

Check warning on line 611 in nxdrive/engine/processor.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/engine/processor.py#L611

Added line #L611 was not covered by tests
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Processor._direct_transfer_end refactored with the following changes:

This removes the following comments ( why? ):

# Update session then handle the status

if (
not cancelled_transfer
and session.status is not TransferStatus.CANCELLED
Expand Down Expand Up @@ -649,8 +647,7 @@
remote_info.name != doc_pair.local_name
or remote_info.digest != doc_pair.local_digest
):
modified = self.dao.get_state_from_local(doc_pair.local_path)
if modified:
if modified := self.dao.get_state_from_local(doc_pair.local_path):

Check warning on line 650 in nxdrive/engine/processor.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/engine/processor.py#L650

Added line #L650 was not covered by tests
Comment on lines -652 to +650
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Processor._synchronize_if_not_remotely_dirty refactored with the following changes:

log.info(
f"Forcing remotely_modified for pair={modified!r} "
f"with info={remote_info!r}"
Expand Down
52 changes: 52 additions & 0 deletions tests/functional/test_processor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from collections import namedtuple
from pathlib import Path
from unittest.mock import patch

from nxdrive.engine.processor import Processor


def test_synchronize_direct_transfer(manager_factory):
manager, engine = manager_factory()
dao = engine.dao
remote = engine.remote
Mocked_Session = namedtuple(
"session",
"status, uid",
defaults=("ok", "1"),
)
session = Mocked_Session()
str_path = "unknownPath"
path = Path(str_path)
DocPair = namedtuple(
"DocPair",
"local_path, session",
defaults=(path, session),
)
doc_pair = DocPair()

def mocked_get_session(*args, **kwargs):
return session

def mocked_get_none_session(*args, **kwargs):
return None

def mocked_upload(*args, **kwargs):
return

def mocked_direct_transfer_end(*args, **kwargs):
return

def mocked_pause_session(*args, **kwargs):
return

processor = Processor(engine, True)

with patch.object(dao, "pause_session", new=mocked_pause_session):
with patch.object(remote, "upload", new=mocked_upload):
with patch.object(
processor, "_direct_transfer_end", new=mocked_direct_transfer_end
):
with patch.object(dao, "get_session", new=mocked_get_session):
assert processor._synchronize_direct_transfer(doc_pair) is None
with patch.object(dao, "get_session", new=mocked_get_none_session):
assert processor._synchronize_direct_transfer(doc_pair) is None
Loading