Skip to content

Commit b63ea2c

Browse files
authored
Merge pull request #8235 from nextcloud/swift-primairy-ci
Add ci for swift primary storage
2 parents 26e0c14 + 2e3ed7d commit b63ea2c

8 files changed

Lines changed: 62 additions & 3 deletions

File tree

.drone.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ pipeline:
596596
image: nextcloudci/php7.0:php7.0-19
597597
commands:
598598
- phpenmod xdebug
599+
- ./tests/drone-wait-objectstore.sh
599600
- TEST_SELECTION=PRIMARY-${OBJECT_STORE} ./autotest.sh sqlite
600601
- wget https://codecov.io/bash -O codecov.sh
601602
- sh -c "if [ '$DRONE_BUILD_EVENT' = 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -P $DRONE_PULL_REQUEST -t 117641e2-a9e8-4b7b-984b-ae872d9b05f5 -f tests/autotest-clover-sqlite.xml; fi"
@@ -743,6 +744,8 @@ matrix:
743744
- TESTS: carddavtester-old-endpoint
744745
- TESTS: object-store
745746
OBJECT_STORE: s3
747+
- TESTS: object-store
748+
OBJECT_STORE: swift
746749
- TESTS: sqlite-php7.0-samba-native
747750
- TESTS: sqlite-php7.0-samba-non-native
748751
- TEST: memcache-memcached
@@ -838,6 +841,14 @@ services:
838841
when:
839842
matrix:
840843
OBJECT_STORE: s3
844+
dockswift:
845+
image: icewind1991/dockswift
846+
environment:
847+
- INITIALIZE=yes
848+
- IPADDRESS=dockswift
849+
when:
850+
matrix:
851+
OBJECT_STORE: swift
841852
selenium:
842853
image: selenium/standalone-firefox:2.53.1-beryllium
843854
environment:

autotest.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,9 @@ function execute_tests {
369369
if [ "$TEST_SELECTION" == "PRIMARY-s3" ]; then
370370
GROUP='--group PRIMARY-s3'
371371
fi
372+
if [ "$TEST_SELECTION" == "PRIMARY-swift" ]; then
373+
GROUP='--group PRIMARY-swift'
374+
fi
372375

373376
COVER=''
374377
if [ -z "$NOCOVERAGE" ]; then

lib/private/Files/Mount/ObjectHomeMountProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@ private function getSingleBucketObjectStoreConfig(IUser $user) {
8484
if (!isset($config['arguments'])) {
8585
$config['arguments'] = [];
8686
}
87-
$config['arguments']['user'] = $user;
8887
// instantiate object store implementation
8988
$config['arguments']['objectstore'] = new $config['class']($config['arguments']);
9089

90+
$config['arguments']['user'] = $user;
91+
9192
return $config;
9293
}
9394

lib/private/Files/ObjectStore/ObjectStoreStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ public function touch($path, $mtime = null) {
369369
'app' => 'objectstore',
370370
'message' => 'Could not create object for ' . $path,
371371
]);
372-
return false;
372+
throw $ex;
373373
}
374374
}
375375
return true;

lib/private/Files/ObjectStore/Swift.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
namespace OC\Files\ObjectStore;
2727

2828
use Guzzle\Http\Exception\ClientErrorResponseException;
29+
use Guzzle\Http\Exception\CurlException;
2930
use Icewind\Streams\RetryWrapper;
3031
use OCP\Files\ObjectStore\IObjectStore;
3132
use OCP\Files\StorageAuthException;
@@ -87,6 +88,9 @@ public function __construct($params) {
8788
$this->params = $params;
8889
}
8990

91+
/**
92+
* @suppress PhanNonClassMethodCall
93+
*/
9094
protected function init() {
9195
if ($this->container) {
9296
return;
@@ -117,6 +121,10 @@ protected function init() {
117121
/** @var Catalog $catalog */
118122
$catalog = $this->client->getCatalog();
119123

124+
if (count($catalog->getItems()) === 0) {
125+
throw new StorageAuthException('Keystone did not provide a valid catalog, verify the credentials');
126+
}
127+
120128
if (isset($this->params['serviceName'])) {
121129
$serviceName = $this->params['serviceName'];
122130
} else {
@@ -153,6 +161,13 @@ protected function init() {
153161
} else {
154162
throw $ex;
155163
}
164+
} catch (CurlException $e) {
165+
if ($e->getErrorNo() === 7) {
166+
$host = $e->getCurlHandle()->getUrl()->getHost() . ':' . $e->getCurlHandle()->getUrl()->getPort();
167+
\OC::$server->getLogger()->error("Can't connect to object storage server at $host");
168+
throw new StorageNotAvailableException("Can't connect to object storage server at $host", StorageNotAvailableException::STATUS_ERROR, $e);
169+
}
170+
throw $e;
156171
}
157172
}
158173

@@ -176,7 +191,7 @@ private function importToken() {
176191
$itemClass = new \stdClass();
177192
$itemClass->name = $item['name'];
178193
$itemClass->endpoints = array_map(function (array $endpoint) {
179-
return (object) $endpoint;
194+
return (object)$endpoint;
180195
}, $item['endpoints']);
181196
$itemClass->type = $item['type'];
182197

tests/drone-wait-objectstore.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
if [ "$OBJECT_STORE" == "swift" ]; then
4+
echo "waiting for swift"
5+
until curl -I http://dockswift:5000/v3
6+
do
7+
sleep 2
8+
done
9+
sleep 60
10+
fi

tests/lib/Files/ObjectStore/SwiftTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
use OC\Files\ObjectStore\Swift;
2525

26+
/**
27+
* @group PRIMARY-swift
28+
*/
2629
class SwiftTest extends ObjectStoreTest {
2730
/**
2831
* @return \OCP\Files\ObjectStore\IObjectStore

tests/preseed-config.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,19 @@
3434
)
3535
];
3636
}
37+
if (getenv('OBJECT_STORE') === 'swift') {
38+
$swiftHost = getenv('DRONE') === 'true' ? 'dockswift' : 'localhost';
39+
$CONFIG['objectstore'] = [
40+
'class' => 'OC\\Files\\ObjectStore\\Swift',
41+
'arguments' => array(
42+
'autocreate' => true,
43+
'username' => 'swift',
44+
'tenantName' => 'service',
45+
'password' => 'swift',
46+
'serviceName' => 'swift',
47+
'region' => 'regionOne',
48+
'url' => "http://$swiftHost:5000/v2.0",
49+
'bucket' => 'nextcloud'
50+
)
51+
];
52+
}

0 commit comments

Comments
 (0)