Skip to content

Commit

Permalink
update opencloud functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasmure committed Jan 15, 2018
1 parent 0e564d8 commit abb35bc
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 29 deletions.
7 changes: 4 additions & 3 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ AZURE_ACCOUNT=
AZURE_KEY=
AZURE_CONTAINER=

RACKSPACE_USER=
RACKSPACE_APIKEY=
RACKSPACE_CONTAINER=
RACKSPACE_USERNAME=
RACKSPACE_PASSWORD=
RACKSPACE_TENANT_ID=
RACKSPACE_REGION=
63 changes: 56 additions & 7 deletions doc/adapters/open-cloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,26 @@ composer require gaufrette/opencloud-adapter
To use the OpenCloud adapter you will need to create a connection using the
[OpenCloud SDK](https://github.com/php-opencloud/openstack).

## Usage with Identity API v3

For services using the [OpenStack Identity API v3](https://developer.openstack.org/api-ref/identity/v3/index.html) :

```php
use Gaufrette\Adapter\OpenCloud as OpenCloudAdapter;
use Gaufrette\Filesystem;
use OpenStack\OpenStack;

$openstack = new OpenStack([
'username' => 'your username',
'password' => 'your Keystone password',
'tenantName' => 'your tenant (project) name',
'authUrl' => 'https://example.com/v2/identity',
]);
$objectStore = (new OpenStack([
'username' => 'your username',
'password' => 'your Keystone password',
'tenantName' => 'your tenant (project) name',
'authUrl' => 'https://example.com/v3/identity',
]))
->objectStoreV1()
;

$adapter = new OpenCloudAdapter(
$openstack->objectStoreV1(),
$objectStore,
'container-name',
true // optional, indicates whether to create the container or not
// if it does not exist, default to false
Expand All @@ -36,3 +42,46 @@ $filesystem = new Filesystem($adapter);

See [here](https://github.com/php-opencloud/openstack/blob/master/src/OpenStack.php)
for all OpenStack connection options.

## Usage with Identity API v2

For services using the [OpenStack Identity API v2](https://developer.openstack.org/api-ref/identity/v2/),
such as [rackspace.com](https://www.rackspace.com/) :

```php
use Gaufrette\Adapter\OpenCloud as OpenCloudAdapter;
use Gaufrette\Filesystem;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use OpenStack\Identity\v2\Service as IdentityService;
use OpenStack\OpenStack;

$objectStore = new (OpenStack([
'username' => 'your username',
'password' => 'your password',
'tenantId' => 'your tenant Id (also known as account Id)'
'authUrl' => 'https://example.com/v2/identity',
'region' => 'the cloud region (eg "LON" for London)',
'identityService' => IdentityService::factory(
new Client([
'base_uri' => 'https://example.com/v2/identity',
'handler' => HandlerStack::create(),
])
),
]))
->objectStoreV1([
'catalogName' => 'cloudFiles', // default to "swift", use "cloudFiles" for rackspace,
// or find the catalog name of your cloud service
// associated with the "object-store" catalog type
])
;

$adapter = new OpenCloudAdapter(
$objectStore,
'container-name',
true // optional, indicates whether to create the container or not
// if it does not exist, default to false
);

$filesystem = new Filesystem($adapter);
```
7 changes: 4 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@
<env name="AZURE_CONTAINER" value="" />-->

<!-- Configuration for OpenCloud/Rackspace adapter -->
<!--<env name="RACKSPACE_USER" value="" />
<env name="RACKSPACE_APIKEY" value="" />
<env name="RACKSPACE_CONTAINER" value="" />-->
<!--<env name="RACKSPACE_USERNAME" value="" />
<env name="RACKSPACE_PASSWORD" value="" />
<env name="RACKSPACE_TENANT_ID" value="" />
<env name="RACKSPACE_REGION" value="" />-->
</php>

<testsuites>
Expand Down
1 change: 0 additions & 1 deletion tests/Gaufrette/Functional/Adapter/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public function shouldCheckIfFileExists()

$this->assertTrue($this->filesystem->has('foo'));
$this->assertFalse($this->filesystem->has('test/somefile'));
$this->assertFalse($this->filesystem->has('test/somefile'));
}

/**
Expand Down
77 changes: 62 additions & 15 deletions tests/Gaufrette/Functional/Adapter/OpenCloudTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,57 @@

use Gaufrette\Adapter\OpenCloud;
use Gaufrette\Filesystem;
use OpenCloud\Rackspace;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use OpenStack\Identity\v2\Service as IdentityService;
use OpenStack\OpenStack;

class OpenCloudTest extends FunctionalTestCase
{
/** @var \OpenCloud\ObjectStore\Service */
/** @var \OpenStack\ObjectStore\v1\Service */
private $objectStore;

/** @var string */
private $container;

public function setUp()
{
$username = getenv('RACKSPACE_USER') ?: '';
$apiKey = getenv('RACKSPACE_APIKEY') ?: '';
$container = getenv('RACKSPACE_CONTAINER') ?: '';
$username = getenv('RACKSPACE_USERNAME') ?: '';
$password = getenv('RACKSPACE_PASSWORD') ?: '';
$tenantId = getenv('RACKSPACE_TENANT_ID') ?: '';
$region = getenv('RACKSPACE_REGION') ?: '';

if (empty($username) || empty($apiKey) || empty($container)) {
$this->markTestSkipped('Either RACKSPACE_USER, RACKSPACE_APIKEY and/or RACKSPACE_CONTAINER env vars are missing.');
if (empty($username) || empty($password) || empty($tenantId) || empty($region)) {
$this->markTestSkipped('Either RACKSPACE_USERNAME, RACKSPACE_PASSWORD, RACKSPACE_TENANT_ID and/or RACKSPACE_REGION env vars are missing.');
}

$connection = new Rackspace('https://identity.api.rackspacecloud.com/v2.0/', [
'username' => $username,
'apiKey' => $apiKey,
]);
$authUrl = 'https://identity.api.rackspacecloud.com/v2.0/';

$this->container = uniqid($container);
$this->objectStore = $connection->objectStoreService('cloudFiles', 'IAD', 'publicURL');
$this->objectStore->createContainer($this->container);
/*
* Rackspace uses OpenStack Identity v2
* @see https://github.com/php-opencloud/openstack/issues/127
*/
$this->container = uniqid('gaufretteci');
$this->objectStore = (new OpenStack([
'username' => $username,
'password' => $password,
'tenantId' => $tenantId,
'authUrl' => $authUrl,
'region' => $region,
'identityService' => IdentityService::factory(
new Client([
'base_uri' => $authUrl,
'handler' => HandlerStack::create(),
])
),
]))
->objectStoreV1([
'catalogName' => 'cloudFiles',
]);

$this->objectStore->createContainer([
'name' => $this->container,
]);
$adapter = new OpenCloud($this->objectStore, $this->container);
$this->filesystem = new Filesystem($adapter);
}
Expand All @@ -43,6 +65,31 @@ public function tearDown()
return;
}

$this->objectStore->getContainer($this->container)->delete(true);
// rackspace container must be empty to be deleted
array_map(function ($key) {
$this->filesystem->delete($key);
}, $this->filesystem->keys());

$this->objectStore->getContainer($this->container)->delete();
}


/*
* OVERWRITE PARENT FUNCTIONS
* @TODO : REMOVE THE BELOW OVERWRITES WHEN
* https://github.com/KnpLabs/Gaufrette/pull/521 WILL BE MERGED.
*/

/**
* @test
* @group functional
*/
public function shouldWriteAndRead()
{
$this->filesystem->write('foo', 'Some content');
$this->filesystem->write('test/subdir/foo', 'Some content1', true);

$this->assertEquals('Some content', $this->filesystem->read('foo'));
$this->assertEquals('Some content1', $this->filesystem->read('test/subdir/foo'));
}
}

0 comments on commit abb35bc

Please sign in to comment.