Merge "Fixes an issue with Rackspace tenant IDs and Swift regions. Also fixes tests that simply do not work with certain Rackspace/OpenStack implementations."

This commit is contained in:
Jenkins 2014-05-08 13:50:48 +00:00 committed by Gerrit Code Review
commit 7035fa4ade
11 changed files with 102 additions and 166 deletions

1
.gitignore vendored
View File

@ -5,4 +5,5 @@ vendor/
.DS_Store
composer.lock
composer.phar
phpunit.xml
tests/settings.ini*

View File

@ -18,4 +18,4 @@
"OpenStack\\Tests\\": "tests/Tests"
}
}
}
}

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true">
<phpunit colors="true" bootstrap="./tests/bootstrap.php">
<testsuites>
<testsuite name="PHPUnit">
<directory>tests/Tests/</directory>
<directory>tests/Tests/</directory>
</testsuite>
</testsuites>
<logging>
@ -16,6 +16,6 @@
highLowerBound="70"
showUncoveredFiles="true"
/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>
</phpunit>

View File

@ -1467,18 +1467,9 @@ class StreamWrapper
$serviceCatalog = $ident->serviceCatalog();
self::$serviceCatalogCache[$token] = $serviceCatalog;
$this->store = ObjectStorage::newFromServiceCatalog($serviceCatalog, $token, \OpenStack\ObjectStore\v1\ObjectStorage::DEFAULT_REGION, $client);
$region = $this->cxt('openstack.swift.region') ?: ObjectStorage::DEFAULT_REGION;
/*
$catalog = $ident->serviceCatalog(ObjectStorage::SERVICE_TYPE);
if (empty($catalog) || empty($catalog[0]['endpoints'][0]['publicURL'])) {
//throw new \OpenStack\Common\Exception('No object storage services could be found for this tenant ID.' . print_r($catalog, true));
throw new \OpenStack\Common\Exception('No object storage services could be found for this tenant ID.');
}
$serviceURL = $catalog[0]['endpoints'][0]['publicURL'];
$this->store = new ObjectStorage($token, $serviceURL);
*/
$this->store = ObjectStorage::newFromServiceCatalog($serviceCatalog, $token, $region, $client);
}
return !empty($this->store);

View File

@ -21,7 +21,7 @@
*/
$base = dirname(__DIR__);
require_once $base . '/src/OpenStack/Autoloader.php';
require_once $base . '/vendor/autoloader.php';
use \OpenStack\ObjectStore\v1\ObjectStorage;
use \OpenStack\Identity\v2\IdentityService;

View File

@ -77,11 +77,6 @@ class IdentityServicesTest extends \OpenStack\Tests\TestCase
$tok = $service->authenticate($auth);
$this->assertNotEmpty($tok);
// We should get the same token if we request again.
$service = new IdentityService(self::conf('openstack.identity.url'), $this->getTransportClient());
$tok2 = $service->authenticate($auth);
$this->assertEquals($tok, $tok2);
// Again with no tenant ID.
$auth = array(
'passwordCredentials' => array(
@ -106,19 +101,21 @@ class IdentityServicesTest extends \OpenStack\Tests\TestCase
$tenantId = self::conf('openstack.identity.tenantId');
$tok = $service->authenticateAsUser($user, $pass, $tenantId);
$this->assertNotEmpty($tok);
// Try again, this time with no tenant ID.
$tok2 = $service->authenticateAsUser($user, $pass);
$this->assertNotEmpty($tok2);
$details = $service->tokenDetails();
$this->assertFalse(isset($details['tenant']));
return $service;
}
public function testAuthenticatingAsUserWithoutTenant()
{
$service = new IdentityService(self::conf('openstack.identity.url'), $this->getTransportClient());
$username = self::conf('openstack.identity.username');
$password = self::conf('openstack.identity.password');
$this->assertNotEmpty($service->authenticateAsUser($username, $password));
}
/**
* @depends testAuthenticateAsUser
*/
@ -236,7 +233,6 @@ class IdentityServicesTest extends \OpenStack\Tests\TestCase
}
}
$this->assertEquals('Identity', $idService['name']);
$this->assertNotEmpty($idService['endpoints']);
$this->assertNotEmpty($idService['endpoints'][0]['publicURL']);
@ -245,7 +241,6 @@ class IdentityServicesTest extends \OpenStack\Tests\TestCase
$this->assertEquals(1, count($justID));
$idService = $justID[0];
$this->assertEquals('Identity', $idService['name']);
$this->assertNotEmpty($idService['endpoints']);
$this->assertNotEmpty($idService['endpoints'][0]['publicURL']);
@ -441,4 +436,4 @@ class IdentityServicesTest extends \OpenStack\Tests\TestCase
$is = Bootstrap::identity(true);
$this->assertInstanceOf('\OpenStack\Identity\v2\IdentityService', $is);
}
}
}

View File

@ -24,26 +24,11 @@ use \OpenStack\ObjectStore\v1\Resource\ACL;
class ObjectStorageTest extends \OpenStack\Tests\TestCase
{
/**
* Canary test.
*/
public function testSettings()
{
$this->assertTrue(!empty(self::$settings));
}
/**
* Test Swift-based authentication.
* @group deprecated
*/
public function testSwiftAuthentication()
{
$ostore = $this->swiftAuth();
$this->assertInstanceOf('\OpenStack\ObjectStore\v1\ObjectStorage', $ostore);
$this->assertTrue(strlen($ostore->token()) > 0);
}
/**
* @group auth
*/
@ -94,18 +79,6 @@ class ObjectStorageTest extends \OpenStack\Tests\TestCase
$this->assertTrue(strlen($ostore->token()) > 0);
}
public function testNewFromIdentityAltRegion()
{
$ident = $this->identity();
$ostore = \OpenStack\ObjectStore\v1\ObjectStorage::newFromIdentity($ident, 'region-b.geo-1', $this->getTransportClient());
$this->assertInstanceOf('\OpenStack\ObjectStore\v1\ObjectStorage', $ostore);
$this->assertTrue(strlen($ostore->token()) > 0);
// Make sure the store is not the same as the default region.
$ostoreDefault = \OpenStack\ObjectStore\v1\ObjectStorage::newFromIdentity($ident, self::$settings['openstack.swift.region'], $this->getTransportClient());
$this->assertNotEquals($ostore, $ostoreDefault);
}
/**
* @group auth
* @ group acl

View File

@ -19,38 +19,25 @@
*/
namespace OpenStack\Tests\ObjectStore\v1\Resource;
use \OpenStack\ObjectStore\v1\Resource\StreamWrapperFS;
use \OpenStack\ObjectStore\v1\Resource\Container;
use \OpenStack\ObjectStore\v1\Resource\Object;
use OpenStack\Common\Transport\Exception\FileNotFoundException;
use OpenStack\ObjectStore\v1\Resource\StreamWrapperFS;
use OpenStack\Tests\TestCase;
/**
* @group streamWrapper
*/
class StreamWrapperFSTest extends \OpenStack\Tests\TestCase
class StreamWrapperFSTest extends TestCase
{
const FNAME = 'streamTest.txt';
const FTYPE = 'application/x-tuna-fish; charset=iso-8859-13';
/*public static function setUpBeforeClass() {
}*/
/**
* Cleaning up the test container so we can reuse it for other tests.
*/
public static function tearDownAfterClass()
{
// First we get an identity
$user = self::conf('openstack.identity.username');
$pass = self::conf('openstack.identity.password');
$tenantId = self::conf('openstack.identity.tenantId');
$url = self::conf('openstack.identity.url');
$ident = new \OpenStack\Identity\v2\IdentityService($url, self::getTransportClient());
$token = $ident->authenticateAsUser($user, $pass, $tenantId);
// Then we need to get an instance of storage
$store = \OpenStack\ObjectStore\v1\ObjectStorage::newFromIdentity($ident, self::conf('openstack.swift.region'), self::getTransportClient());
/** @var \OpenStack\ObjectStore\v1\ObjectStore $store */
$store = self::createObjectStoreService();
// Delete the container and all the contents.
$cname = self::$settings['openstack.swift.container'];
@ -59,7 +46,7 @@ class StreamWrapperFSTest extends \OpenStack\Tests\TestCase
$container = $store->container($cname);
}
// The container was never created.
catch (\OpenStack\Common\Transport\Exception\FileNotFoundException $e) {
catch (FileNotFoundException $e) {
return;
}
@ -121,30 +108,24 @@ class StreamWrapperFSTest extends \OpenStack\Tests\TestCase
* UPDATE: This now users IdentityService instead of deprecated
* swauth.
*/
protected function authSwiftContext($add = array(), $scheme = null)
protected function authSwiftContext(array $params = [], $scheme = null)
{
$cname = self::$settings['openstack.swift.container'];
$username = self::$settings['openstack.identity.username'];
$password = self::$settings['openstack.identity.password'];
$tenant = self::$settings['openstack.identity.tenantId'];
$baseURL = self::$settings['openstack.identity.url'];
if (empty($scheme)) {
$scheme = StreamWrapperFS::DEFAULT_SCHEME;
}
$params = $add + array(
'username' => $username,
'password' => $password,
'endpoint' => $baseURL,
'tenantid' => $tenant,
$params += [
'username' => self::$settings['openstack.identity.username'],
'password' => self::$settings['openstack.identity.password'],
'endpoint' => self::$settings['openstack.identity.url'],
'tenantid' => self::$settings['openstack.identity.tenantId'],
'content_type' => self::FTYPE,
'transport_client' => $this->getTransportClient(),
);
$cxt = array($scheme => $params);
return stream_context_create($cxt);
];
return stream_context_create([
$scheme => $params
]);
}
/**
@ -162,7 +143,7 @@ class StreamWrapperFSTest extends \OpenStack\Tests\TestCase
'password' => self::$settings['openstack.identity.password'],
'endpoint' => self::$settings['openstack.identity.url'],
'tenantid' => self::$settings['openstack.identity.tenantId'],
'token' => $this->objectStore()->token(),
'token' => $this->objectStore()->token(),
'swift_endpoint' => $this->objectStore()->url(),
);
\OpenStack\Bootstrap::setConfiguration($opts);

View File

@ -17,46 +17,33 @@
/**
* Unit tests for the stream wrapper.
*/
namespace OpenStack\Tests\ObjectStore\v1\Resource;
use \OpenStack\ObjectStore\v1\Resource\StreamWrapper;
use \OpenStack\ObjectStore\v1\Resource\Container;
use \OpenStack\ObjectStore\v1\Resource\Object;
use OpenStack\Common\Transport\Exception\FileNotFoundException;
use OpenStack\ObjectStore\v1\Resource\StreamWrapper;
use OpenStack\Tests\TestCase;
/**
* @group streamWrapper
*/
class StreamWrapperTest extends \OpenStack\Tests\TestCase
class StreamWrapperTest extends TestCase
{
const FNAME = 'streamTest.txt';
const FTYPE = 'application/x-tuna-fish; charset=iso-8859-13';
/**
* Cleaning up the test container so we can reuse it for other tests.
*/
public static function tearDownAfterClass()
{
// First we get an identity
$user = self::conf('openstack.identity.username');
$pass = self::conf('openstack.identity.password');
$tenantId = self::conf('openstack.identity.tenantId');
$url = self::conf('openstack.identity.url');
$ident = new \OpenStack\Identity\v2\IdentityService($url, self::getTransportClient());
$token = $ident->authenticateAsUser($user, $pass, $tenantId);
// Then we need to get an instance of storage
$store = \OpenStack\ObjectStore\v1\ObjectStorage::newFromIdentity($ident, self::conf('openstack.swift.region'), self::getTransportClient());
/** @var \OpenStack\ObjectStore\v1\ObjectStorage $store */
$store = self::createObjectStoreService();
// Delete the container and all the contents.
$cname = self::$settings['openstack.swift.container'];
try {
$container = $store->container($cname);
}
// The container was never created.
catch (\OpenStack\Common\Transport\Exception\FileNotFoundException $e) {
} catch (FileNotFoundException $e) {
// The container was never created.
return;
}
@ -115,30 +102,24 @@ class StreamWrapperTest extends \OpenStack\Tests\TestCase
/**
* This performs authentication via context.
*/
protected function authSwiftContext($add = array(), $scheme = null)
protected function authSwiftContext(array $params = [], $scheme = null)
{
$cname = self::$settings['openstack.swift.container'];
$username = self::$settings['openstack.identity.username'];
$password = self::$settings['openstack.identity.password'];
$tenant = self::$settings['openstack.identity.tenantId'];
$baseURL = self::$settings['openstack.identity.url'];
if (empty($scheme)) {
$scheme = StreamWrapper::DEFAULT_SCHEME;
}
$params = $add + array(
'username' => $username,
'password' => $password,
'endpoint' => $baseURL,
'tenantid' => $tenant,
$params += [
'username' => self::$settings['openstack.identity.username'],
'password' => self::$settings['openstack.identity.password'],
'endpoint' => self::$settings['openstack.identity.url'],
'tenantid' => self::$settings['openstack.identity.tenantId'],
'content_type' => self::FTYPE,
'transport_client' => $this->getTransportClient(),
);
$cxt = array($scheme => $params);
return stream_context_create($cxt);
'transport_client' => $this->getTransportClient()
];
return stream_context_create([
$scheme => $params
]);
}
/**

View File

@ -27,6 +27,9 @@
namespace OpenStack\Tests;
use OpenStack\Identity\v2\IdentityService;
use OpenStack\ObjectStore\v1\ObjectStorage;
/**
* @ingroup Tests
*/
@ -43,7 +46,8 @@ class TestCase extends \PHPUnit_Framework_TestCase
public static $httpClient = null;
//public function __construct(score $score = null, locale $locale = null, adapter $adapter = null) {
protected $containerFixture = null;
public static function setUpBeforeClass()
{
global $bootstrap_settings;
@ -81,19 +85,26 @@ class TestCase extends \PHPUnit_Framework_TestCase
return $default;
}
protected $containerFixture = null;
/**
* @deprecated
*/
protected function swiftAuth()
protected static function createIdentityService()
{
$user = self::$settings['openstack.swift.account'];
$key = self::$settings['openstack.swift.key'];
$url = self::$settings['openstack.swift.url'];
//$url = self::$settings['openstack.identity.url'];
return \OpenStack\ObjectStore\v1\ObjectStorage::newFromSwiftAuth($user, $key, $url, $this->getTransportClient());
$username = self::conf('openstack.identity.username');
$password = self::conf('openstack.identity.password');
$url = self::conf('openstack.identity.url');
$tenantId = self::conf('openstack.identity.tenantId');
$service = new IdentityService($url);
$service->authenticateAsUser($username, $password, $tenantId);
return $service;
}
protected static function createObjectStoreService()
{
return ObjectStorage::newFromIdentity(
self::createIdentityService(),
self::$settings['openstack.swift.region'],
self::getTransportClient()
);
}
/**
@ -110,17 +121,7 @@ class TestCase extends \PHPUnit_Framework_TestCase
protected function identity($reset = false)
{
if ($reset || empty(self::$ident)) {
$user = self::conf('openstack.identity.username');
$pass = self::conf('openstack.identity.password');
$tenantId = self::conf('openstack.identity.tenantId');
$url = self::conf('openstack.identity.url');
$is = new \OpenStack\Identity\v2\IdentityService($url);
$token = $is->authenticateAsUser($user, $pass, $tenantId);
self::$ident = $is;
self::$ident = self::createIdentityService();
}
return self::$ident;
@ -129,12 +130,7 @@ class TestCase extends \PHPUnit_Framework_TestCase
protected function objectStore($reset = false)
{
if ($reset || empty(self::$ostore)) {
$ident = $this->identity($reset);
$objStore = \OpenStack\ObjectStore\v1\ObjectStorage::newFromIdentity($ident, self::$settings['openstack.swift.region'], $this->getTransportClient());
self::$ostore = $objStore;
self::$ostore = self::createObjectStoreService();
}
return self::$ostore;
@ -200,7 +196,7 @@ class TestCase extends \PHPUnit_Framework_TestCase
/**
* Retrieve the HTTP Transport Client
*
* @return \OpenStack\Transport\ClientInterface A transport client.
* @return \OpenStack\Common\Transport\ClientInterface A transport client.
*/
public static function getTransportClient()
{

18
tests/bootstrap.php Normal file
View File

@ -0,0 +1,18 @@
<?php
/**
* Copyright 2014 OpenStack Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
require dirname(__DIR__) . '/vendor/autoload.php';