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

Fix quota with federated sharing #29220

Merged
merged 5 commits into from
Oct 23, 2017
Merged

Fix quota with federated sharing #29220

merged 5 commits into from
Oct 23, 2017

Conversation

PVince81
Copy link
Contributor

Description

Fix quota with federated sharing and add tests for that.

  • quota check needs to ignore -3 (unlimited) quota value (returned by federated shares with no quota)
  • if unknown quota when checking a file on a federated share, check the parent
  • when not checking the parent, uploading a file to a federated share through DAV upload should still properly forward the insufficient storage exception and others

Related Issue

Fixes #29169

Motivation and Context

How Has This Been Tested?

Run federation_features/federated.feature:240 and quota.feature.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@PVince81
Copy link
Contributor Author

Note: I might want to move the DAV additions to a separate PR as I currently don't know how to properly automatically test this without commenting out the "check the parent instead" logic.

@PVince81
Copy link
Contributor Author

  • remove commented out code

At least this way we'll let the remote server decide in some cases whether there is enough quota when the quota is not retrievable. For that we need to properly forward the 507 error in the DAV code.

@PVince81
Copy link
Contributor Author

  • suspicious entries when running the tests:
[Thu Oct 12 16:45:52 2017] 127.0.0.1:51582 [201]: /public.php/webdav/testquota.txt-olddav-regular
[Thu Oct 12 16:45:53 2017] 127.0.0.1:51586 [207]: /public.php/webdav/testquota.txt-olddav-regular
[Thu Oct 12 16:45:53 2017] 127.0.0.1:51590 [207]: /public.php/webdav/
[Thu Oct 12 16:45:53 2017] Undefined index: size at /srv/www/htdocs/owncloud/lib/private/Files/View.php#1296

I didn't see this View warning on master, but also master doesn't have this one test.

@PVince81
Copy link
Contributor Author

Why can't I catch this with ??

diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php
index 3e4af7cf3d..9cb9bb482f 100644
--- a/lib/private/Files/View.php
+++ b/lib/private/Files/View.php
@@ -1294,6 +1294,10 @@ class View {
                try {
                        // if the file is not in the cache or needs to be updated, trigger the scanner and reload the data
                        if (!$data || $data['size'] === -1) {
+                               if (!!$data && !isset($data['size'])) {
+                                       $stack = json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 50));
+                                       \OCP\Util::writeLog('DEBUG', 'Size not set: Stack: ' . $stack, \OCP\Util::WARN);
+                               }
                                $this->lockFile($relativePath, ILockingProvider::LOCK_SHARED);

@PVince81
Copy link
Contributor Author

PVince81 commented Oct 12, 2017

Stack trace:

[Thu Oct 12 17:26:49 2017] Undefined index: size at /srv/www/htdocs/owncloud/lib/private/Files/View.php#1296
[Thu Oct 12 17:26:49 2017] $data is {"checksum":"","mimetype":"application\/octet-stream","parent":"2147483987"}
[Thu Oct 12 17:26:49 2017] $internalPath: files_versions/PARENT (2)/testquota.txt-newdav-regular.v1507822008
[Thu Oct 12 17:26:49 2017] $relativePath: files_versions//PARENT (2)/testquota.txt-newdav-regular.v1507822008
[Thu Oct 12 17:26:49 2017] Size not set: Stack:
[
  {
    "file": "\\/srv\\/www\\/htdocs\\/owncloud\\/lib\\/private\\/Files\\/View.php",
    "line": 1353,
    "function": "getCacheEntry",
    "class": "OC\\Files\\View",
    "type": "->"
  },
  {
    "file": "\\/srv\\/www\\/htdocs\\/owncloud\\/apps\\/files_versions\\/lib\\/Storage.php",
    "line": 195,
    "function": "getFileInfo",
    "class": "OC\\Files\\View",
    "type": "->"
  },
  {
    "file": "\\/srv\\/www\\/htdocs\\/owncloud\\/apps\\/files_versions\\/lib\\/Hooks.php",
    "line": 60,
    "function": "store",
    "class": "OCA\\Files_Versions\\Storage",
    "type": "::"
  },
  {
    "file": "\\/srv\\/www\\/htdocs\\/owncloud\\/lib\\/private\\/legacy\\/hook.php",
    "line": 105,
    "function": "write_hook",
    "class": "OCA\\Files_Versions\\Hooks",
    "type": "::"
  },
  {
    "file": "\\/srv\\/www\\/htdocs\\/owncloud\\/apps\\/dav\\/lib\\/Connector\\/Sabre\\/File.php",
    "line": 283,
    "function": "emit",
    "class": "OC_Hook",
    "type": "::"
  },
  {
    "file": "\\/srv\\/www\\/htdocs\\/owncloud\\/apps\\/dav\\/lib\\/Connector\\/Sabre\\/File.php",
    "line": 189,
    "function": "emitPreHooks",
    "class": "OCA\\DAV\\Connector\\Sabre\\File",
    "type": "->"
  },
  {
    "file": "\\/srv\\/www\\/htdocs\\/owncloud\\/apps\\/dav\\/lib\\/Connector\\/Sabre\\/Directory.php",
    "line": 162,
    "function": "put",
    "class": "OCA\\DAV\\Connector\\Sabre\\File",
    "type": "->"
  },
  {
    "file": "\\/srv\\/www\\/htdocs\\/owncloud\\/lib\\/composer\\/sabre\\/dav\\/lib\\/DAV\\/Server.php",
    "line": 1095,
    "function": "createFile",
    "class": "OCA\\DAV\\Connector\\Sabre\\Directory",
    "type": "->"
  },
  {
    "file": "\\/srv\\/www\\/htdocs\\/owncloud\\/lib\\/composer\\/sabre\\/dav\\/lib\\/DAV\\/CorePlugin.php",
    "line": 525,
    "function": "createFile",
    "class": "Sabre\\DAV\\Server",
    "type": "->"
  },
  {
    "function": "httpPut",
    "class": "Sabre\\DAV\\CorePlugin",
    "type": "->"
  },
  {
    "file": "\\/srv\\/www\\/htdocs\\/owncloud\\/lib\\/composer\\/sabre\\/event\\/lib\\/EventEmitterTrait.php",
    "line": 105,
    "function": "call_user_func_array"
  },
  {
    "file": "\\/srv\\/www\\/htdocs\\/owncloud\\/lib\\/composer\\/sabre\\/dav\\/lib\\/DAV\\/Server.php",
    "line": 479,
    "function": "emit",
    "class": "Sabre\\Event\\EventEmitter",
    "type": "->"
  },
  {
    "file": "\\/srv\\/www\\/htdocs\\/owncloud\\/lib\\/composer\\/sabre\\/dav\\/lib\\/DAV\\/Server.php",
    "line": 254,
    "function": "invokeMethod",
    "class": "Sabre\\DAV\\Server",
    "type": "->"
  },
  {
    "file": "\\/srv\\/www\\/htdocs\\/owncloud\\/apps\\/dav\\/lib\\/Server.php",
    "line": 236,
    "function": "exec",
    "class": "Sabre\\DAV\\Server",
    "type": "->"
  },
  {
    "file": "\\/srv\\/www\\/htdocs\\/owncloud\\/apps\\/dav\\/appinfo\\/v2\\/remote.php",
    "line": 31,
    "function": "exec",
    "class": "OCA\\DAV\\Server",
    "type": "->"
  },
  {
    "file": "\\/srv\\/www\\/htdocs\\/owncloud\\/remote.php",
    "line": 175,
    "args": [
      "\\/srv\\/www\\/htdocs\\/owncloud\\/apps\\/dav\\/appinfo\\/v2\\/remote.php"
    ],
    "function": "require_once"
  }
]

Seems to be about versions...

@PVince81
Copy link
Contributor Author

If I remove the quota from the integration test, the warning disappears... Weird.

@PVince81
Copy link
Contributor Author

also if I set the quota high enough in the test, the warning disappears as well.

@PVince81
Copy link
Contributor Author

If I revert every code change and keep the test, the error appears... so this existed before.

@PVince81
Copy link
Contributor Author

I've raised #29245 to explain and analyze this bug. It seems unrelated to this PR. It's just that adding the new tests brought it into view.

@PVince81
Copy link
Contributor Author

Ok, now that we know the warning is unrelated, let's focus on finishing this.

Copy link
Member

@jvillafanez jvillafanez left a comment

Choose a reason for hiding this comment

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

Code looks good, but tests are failing

@PVince81
Copy link
Contributor Author

Relevant failing tests:

19:19:53     /var/lib/jenkins/workspace/owncloud-core_core_PR-29220-7DOBZKU5OFHAVV4BVOWUOKNOOB2WEMRXAXPN3EVSUD4HDB6XAU2Q/tests/integration/features/external-storage.feature:63
19:19:53     /var/lib/jenkins/workspace/owncloud-core_core_PR-29220-7DOBZKU5OFHAVV4BVOWUOKNOOB2WEMRXAXPN3EVSUD4HDB6XAU2Q/tests/integration/features/sharing-v1.feature:597

@PVince81
Copy link
Contributor Author

Ha... failing tests are failing because I added an extra check to assert that setting the quota worked. And apparently here it didn't but the test still passed.

@PVince81
Copy link
Contributor Author

stable10: #29259

@codecov
Copy link

codecov bot commented Oct 18, 2017

Codecov Report

Merging #29220 into master will increase coverage by 0.6%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##             master   #29220     +/-   ##
===========================================
+ Coverage     59.59%    60.2%   +0.6%     
- Complexity    17169    17182     +13     
===========================================
  Files          1029     1030      +1     
  Lines         57235    57270     +35     
===========================================
+ Hits          34111    34477    +366     
+ Misses        23124    22793    -331
Impacted Files Coverage Δ Complexity Δ
lib/private/Server.php 82.44% <100%> (+0.34%) 118 <2> (+3) ⬆️
lib/private/Files/Storage/DAV.php 88.81% <100%> (+77.75%) 163 <5> (+2) ⬆️
lib/private/Http/Client/WebdavClientService.php 100% <100%> (ø) 7 <7> (?)
apps/dav/lib/Connector/Sabre/QuotaPlugin.php 88.52% <100%> (ø) 26 <0> (+1) ⬆️
lib/private/Security/CertificateManager.php 94.5% <0%> (+1.09%) 36% <0%> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3103c29...4ba6cda. Read the comment docs.

@PVince81
Copy link
Contributor Author

I went through great lengths to make codecov happy: 5b5689c

  • make the DAV class testable by introducing a WebdavClientService and IWebdavClientService in core to be able to mock an instance of the Sabre Client
  • add tests for the exceptions

Now waiting to see the new coverage and I'll continue adding tests for that.

@PVince81
Copy link
Contributor Author

Added moar tests

@PVince81
Copy link
Contributor Author

Let's watch the test coverage for the DAV class increase now!

@PVince81
Copy link
Contributor Author

@jvillafanez @DeepDiver1975 please review again. To make codecov happy I had to go to great length and bootstrap unit tests for the Storage\DAV class. In my way of doing this I decided to cover all methods and discovered some small issues on the way which I fixed right away, some others which I will raise later.

* ownCloud
*
* @author Robin Appelman
* @copyright 2012 Robin Appelman icewind@owncloud.com
Copy link
Contributor Author

Choose a reason for hiding this comment

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

going to fix that right away...

Vincent Petry added 4 commits October 20, 2017 17:02
Properly detect SPACE_UNLIMITED in quota check.
Improve error handling when receiving errors like 507 when uploading
files to a remote server.
@PVince81
Copy link
Contributor Author

Rebased and squashed the DAV test (+fix) commits together into one.

DAV.php coverage is now 88%

/**
* Instantiate new Sabre client
*
* @param array $settings
Copy link
Member

Choose a reason for hiding this comment

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

Valid settings should be known both here and in the interface

Added tests for all FS methods of the Storage\DAV class and also fixed
some related issues.
@PVince81
Copy link
Contributor Author

I've copied the Sabre client settings PHPDoc into the interface and WebdavClientService.

Since CI was all green and the PHPDoc will not affect it, I'm merging this directly.

@PVince81 PVince81 merged commit fe7802e into master Oct 23, 2017
@PVince81 PVince81 deleted the fix-quota-fedsharing branch October 23, 2017 10:16
@DeepDiver1975
Copy link
Member

I was still right in the middle of review ....

@PVince81
Copy link
Contributor Author

stable10: #29325

@PVince81
Copy link
Contributor Author

@DeepDiver1975 sorry, please continue then. I'll adjust in a subsequent PR.

*
* @package OC\Http
*/
class WebdavClientService implements IWebdavClientService {
Copy link
Member

Choose a reason for hiding this comment

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

Should be named WebDav

$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->overwriteService('TimeFactory', $this->timeFactory);

$this->httpClient = $this->createMock(IClient::class);
Copy link
Member

Choose a reason for hiding this comment

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

missing use of IClient

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

/**
* @expectedException OCP\Files\StorageNotAvailableException
Copy link
Member

Choose a reason for hiding this comment

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

namespace looks strange

bildschirmfoto von 2017-10-23 12-20-52

private $webdavClientService;

/**
* @var Client
Copy link
Member

Choose a reason for hiding this comment

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

please add | PHPUnit_Framework_MockObject_MockObject - this will fix issues with calling mock methods on these objects

bildschirmfoto von 2017-10-23 12-23-03

@DeepDiver1975
Copy link
Member

@DeepDiver1975 sorry, please continue then. I'll adjust in a subsequent PR.

done

@PVince81
Copy link
Contributor Author

Follow up PR for the review items: #29327

@PVince81
Copy link
Contributor Author

PVince81 commented Nov 8, 2017

regression: #29422

@lock
Copy link

lock bot commented Aug 2, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Federation: Upload reports insufficient storage but we are far from any limit
4 participants