Skip to content

Commit 7035fa4

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Fixes an issue with Rackspace tenant IDs and Swift regions. Also fixes tests that simply do not work with certain Rackspace/OpenStack implementations."
2 parents 2e0a364 + f908955 commit 7035fa4

11 files changed

Lines changed: 101 additions & 165 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ vendor/
55
.DS_Store
66
composer.lock
77
composer.phar
8+
phpunit.xml
89
tests/settings.ini*

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
"OpenStack\\Tests\\": "tests/Tests"
1919
}
2020
}
21-
}
21+
}

phpunit.xml.dist

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit colors="true">
2+
<phpunit colors="true" bootstrap="./tests/bootstrap.php">
33
<testsuites>
44
<testsuite name="PHPUnit">
5-
<directory>tests/Tests/</directory>
5+
<directory>tests/Tests/</directory>
66
</testsuite>
77
</testsuites>
88
<logging>
@@ -16,6 +16,6 @@
1616
highLowerBound="70"
1717
showUncoveredFiles="true"
1818
/>
19-
<log type="coverage-clover" target="build/logs/clover.xml"/>
19+
<log type="coverage-clover" target="build/logs/clover.xml"/>
2020
</logging>
21-
</phpunit>
21+
</phpunit>

src/OpenStack/ObjectStore/v1/Resource/StreamWrapper.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,18 +1467,9 @@ protected function initializeObjectStorage()
14671467
$serviceCatalog = $ident->serviceCatalog();
14681468
self::$serviceCatalogCache[$token] = $serviceCatalog;
14691469

1470-
$this->store = ObjectStorage::newFromServiceCatalog($serviceCatalog, $token, \OpenStack\ObjectStore\v1\ObjectStorage::DEFAULT_REGION, $client);
1470+
$region = $this->cxt('openstack.swift.region') ?: ObjectStorage::DEFAULT_REGION;
14711471

1472-
/*
1473-
$catalog = $ident->serviceCatalog(ObjectStorage::SERVICE_TYPE);
1474-
if (empty($catalog) || empty($catalog[0]['endpoints'][0]['publicURL'])) {
1475-
//throw new \OpenStack\Common\Exception('No object storage services could be found for this tenant ID.' . print_r($catalog, true));
1476-
throw new \OpenStack\Common\Exception('No object storage services could be found for this tenant ID.');
1477-
}
1478-
$serviceURL = $catalog[0]['endpoints'][0]['publicURL'];
1479-
1480-
$this->store = new ObjectStorage($token, $serviceURL);
1481-
*/
1472+
$this->store = ObjectStorage::newFromServiceCatalog($serviceCatalog, $token, $region, $client);
14821473
}
14831474

14841475
return !empty($this->store);

tests/AuthTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222

2323
$base = dirname(__DIR__);
24-
require_once $base . '/src/OpenStack/Autoloader.php';
24+
require_once $base . '/vendor/autoloader.php';
2525

2626
use \OpenStack\ObjectStore\v1\ObjectStorage;
2727
use \OpenStack\Identity\v2\IdentityService;

tests/Tests/Identity/v2/IdentityServicesTest.php

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ public function testAuthenticate($service)
7777
$tok = $service->authenticate($auth);
7878
$this->assertNotEmpty($tok);
7979

80-
// We should get the same token if we request again.
81-
$service = new IdentityService(self::conf('openstack.identity.url'), $this->getTransportClient());
82-
$tok2 = $service->authenticate($auth);
83-
$this->assertEquals($tok, $tok2);
84-
8580
// Again with no tenant ID.
8681
$auth = array(
8782
'passwordCredentials' => array(
@@ -106,17 +101,19 @@ public function testAuthenticateAsUser()
106101
$tenantId = self::conf('openstack.identity.tenantId');
107102

108103
$tok = $service->authenticateAsUser($user, $pass, $tenantId);
109-
110104
$this->assertNotEmpty($tok);
111105

112-
// Try again, this time with no tenant ID.
113-
$tok2 = $service->authenticateAsUser($user, $pass);
114-
$this->assertNotEmpty($tok2);
106+
return $service;
107+
}
115108

116-
$details = $service->tokenDetails();
117-
$this->assertFalse(isset($details['tenant']));
109+
public function testAuthenticatingAsUserWithoutTenant()
110+
{
111+
$service = new IdentityService(self::conf('openstack.identity.url'), $this->getTransportClient());
118112

119-
return $service;
113+
$username = self::conf('openstack.identity.username');
114+
$password = self::conf('openstack.identity.password');
115+
116+
$this->assertNotEmpty($service->authenticateAsUser($username, $password));
120117
}
121118

122119
/**
@@ -236,7 +233,6 @@ public function testServiceCatalog($service)
236233
}
237234
}
238235

239-
$this->assertEquals('Identity', $idService['name']);
240236
$this->assertNotEmpty($idService['endpoints']);
241237
$this->assertNotEmpty($idService['endpoints'][0]['publicURL']);
242238

@@ -245,7 +241,6 @@ public function testServiceCatalog($service)
245241
$this->assertEquals(1, count($justID));
246242

247243
$idService = $justID[0];
248-
$this->assertEquals('Identity', $idService['name']);
249244
$this->assertNotEmpty($idService['endpoints']);
250245
$this->assertNotEmpty($idService['endpoints'][0]['publicURL']);
251246

@@ -441,4 +436,4 @@ public function testBootstrap()
441436
$is = Bootstrap::identity(true);
442437
$this->assertInstanceOf('\OpenStack\Identity\v2\IdentityService', $is);
443438
}
444-
}
439+
}

tests/Tests/ObjectStore/v1/ObjectStorageTest.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,11 @@
2424

2525
class ObjectStorageTest extends \OpenStack\Tests\TestCase
2626
{
27-
/**
28-
* Canary test.
29-
*/
3027
public function testSettings()
3128
{
3229
$this->assertTrue(!empty(self::$settings));
3330
}
3431

35-
/**
36-
* Test Swift-based authentication.
37-
* @group deprecated
38-
*/
39-
public function testSwiftAuthentication()
40-
{
41-
$ostore = $this->swiftAuth();
42-
43-
$this->assertInstanceOf('\OpenStack\ObjectStore\v1\ObjectStorage', $ostore);
44-
$this->assertTrue(strlen($ostore->token()) > 0);
45-
}
46-
4732
/**
4833
* @group auth
4934
*/
@@ -94,18 +79,6 @@ public function testNewFromIdnetity()
9479
$this->assertTrue(strlen($ostore->token()) > 0);
9580
}
9681

97-
public function testNewFromIdentityAltRegion()
98-
{
99-
$ident = $this->identity();
100-
$ostore = \OpenStack\ObjectStore\v1\ObjectStorage::newFromIdentity($ident, 'region-b.geo-1', $this->getTransportClient());
101-
$this->assertInstanceOf('\OpenStack\ObjectStore\v1\ObjectStorage', $ostore);
102-
$this->assertTrue(strlen($ostore->token()) > 0);
103-
104-
// Make sure the store is not the same as the default region.
105-
$ostoreDefault = \OpenStack\ObjectStore\v1\ObjectStorage::newFromIdentity($ident, self::$settings['openstack.swift.region'], $this->getTransportClient());
106-
$this->assertNotEquals($ostore, $ostoreDefault);
107-
}
108-
10982
/**
11083
* @group auth
11184
* @ group acl

tests/Tests/ObjectStore/v1/StreamWrapperFSTest.php

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,25 @@
1919
*/
2020
namespace OpenStack\Tests\ObjectStore\v1\Resource;
2121

22-
use \OpenStack\ObjectStore\v1\Resource\StreamWrapperFS;
23-
use \OpenStack\ObjectStore\v1\Resource\Container;
24-
use \OpenStack\ObjectStore\v1\Resource\Object;
22+
use OpenStack\Common\Transport\Exception\FileNotFoundException;
23+
use OpenStack\ObjectStore\v1\Resource\StreamWrapperFS;
24+
use OpenStack\Tests\TestCase;
2525

2626
/**
2727
* @group streamWrapper
2828
*/
29-
class StreamWrapperFSTest extends \OpenStack\Tests\TestCase
29+
class StreamWrapperFSTest extends TestCase
3030
{
3131
const FNAME = 'streamTest.txt';
3232
const FTYPE = 'application/x-tuna-fish; charset=iso-8859-13';
3333

34-
/*public static function setUpBeforeClass() {
35-
}*/
36-
3734
/**
3835
* Cleaning up the test container so we can reuse it for other tests.
3936
*/
4037
public static function tearDownAfterClass()
4138
{
42-
// First we get an identity
43-
$user = self::conf('openstack.identity.username');
44-
$pass = self::conf('openstack.identity.password');
45-
$tenantId = self::conf('openstack.identity.tenantId');
46-
$url = self::conf('openstack.identity.url');
47-
48-
$ident = new \OpenStack\Identity\v2\IdentityService($url, self::getTransportClient());
49-
50-
$token = $ident->authenticateAsUser($user, $pass, $tenantId);
51-
52-
// Then we need to get an instance of storage
53-
$store = \OpenStack\ObjectStore\v1\ObjectStorage::newFromIdentity($ident, self::conf('openstack.swift.region'), self::getTransportClient());
39+
/** @var \OpenStack\ObjectStore\v1\ObjectStore $store */
40+
$store = self::createObjectStoreService();
5441

5542
// Delete the container and all the contents.
5643
$cname = self::$settings['openstack.swift.container'];
@@ -59,7 +46,7 @@ public static function tearDownAfterClass()
5946
$container = $store->container($cname);
6047
}
6148
// The container was never created.
62-
catch (\OpenStack\Common\Transport\Exception\FileNotFoundException $e) {
49+
catch (FileNotFoundException $e) {
6350
return;
6451
}
6552

@@ -121,30 +108,24 @@ protected function basicSwiftContext($add = array(), $scheme = null)
121108
* UPDATE: This now users IdentityService instead of deprecated
122109
* swauth.
123110
*/
124-
protected function authSwiftContext($add = array(), $scheme = null)
111+
protected function authSwiftContext(array $params = [], $scheme = null)
125112
{
126-
$cname = self::$settings['openstack.swift.container'];
127-
$username = self::$settings['openstack.identity.username'];
128-
$password = self::$settings['openstack.identity.password'];
129-
$tenant = self::$settings['openstack.identity.tenantId'];
130-
$baseURL = self::$settings['openstack.identity.url'];
131-
132113
if (empty($scheme)) {
133114
$scheme = StreamWrapperFS::DEFAULT_SCHEME;
134115
}
135116

136-
$params = $add + array(
137-
'username' => $username,
138-
'password' => $password,
139-
'endpoint' => $baseURL,
140-
'tenantid' => $tenant,
117+
$params += [
118+
'username' => self::$settings['openstack.identity.username'],
119+
'password' => self::$settings['openstack.identity.password'],
120+
'endpoint' => self::$settings['openstack.identity.url'],
121+
'tenantid' => self::$settings['openstack.identity.tenantId'],
141122
'content_type' => self::FTYPE,
142123
'transport_client' => $this->getTransportClient(),
143-
);
144-
$cxt = array($scheme => $params);
145-
146-
return stream_context_create($cxt);
124+
];
147125

126+
return stream_context_create([
127+
$scheme => $params
128+
]);
148129
}
149130

150131
/**
@@ -162,7 +143,7 @@ protected function addBootstrapConfig()
162143
'password' => self::$settings['openstack.identity.password'],
163144
'endpoint' => self::$settings['openstack.identity.url'],
164145
'tenantid' => self::$settings['openstack.identity.tenantId'],
165-
'token' => $this->objectStore()->token(),
146+
'token' => $this->objectStore()->token(),
166147
'swift_endpoint' => $this->objectStore()->url(),
167148
);
168149
\OpenStack\Bootstrap::setConfiguration($opts);

tests/Tests/ObjectStore/v1/StreamWrapperTest.php

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,33 @@
1717
/**
1818
* Unit tests for the stream wrapper.
1919
*/
20+
2021
namespace OpenStack\Tests\ObjectStore\v1\Resource;
2122

22-
use \OpenStack\ObjectStore\v1\Resource\StreamWrapper;
23-
use \OpenStack\ObjectStore\v1\Resource\Container;
24-
use \OpenStack\ObjectStore\v1\Resource\Object;
23+
use OpenStack\Common\Transport\Exception\FileNotFoundException;
24+
use OpenStack\ObjectStore\v1\Resource\StreamWrapper;
25+
use OpenStack\Tests\TestCase;
2526

2627
/**
2728
* @group streamWrapper
2829
*/
29-
class StreamWrapperTest extends \OpenStack\Tests\TestCase
30+
class StreamWrapperTest extends TestCase
3031
{
3132
const FNAME = 'streamTest.txt';
3233
const FTYPE = 'application/x-tuna-fish; charset=iso-8859-13';
3334

34-
/**
35-
* Cleaning up the test container so we can reuse it for other tests.
36-
*/
3735
public static function tearDownAfterClass()
3836
{
39-
// First we get an identity
40-
$user = self::conf('openstack.identity.username');
41-
$pass = self::conf('openstack.identity.password');
42-
$tenantId = self::conf('openstack.identity.tenantId');
43-
$url = self::conf('openstack.identity.url');
44-
45-
$ident = new \OpenStack\Identity\v2\IdentityService($url, self::getTransportClient());
46-
47-
$token = $ident->authenticateAsUser($user, $pass, $tenantId);
48-
49-
// Then we need to get an instance of storage
50-
$store = \OpenStack\ObjectStore\v1\ObjectStorage::newFromIdentity($ident, self::conf('openstack.swift.region'), self::getTransportClient());
37+
/** @var \OpenStack\ObjectStore\v1\ObjectStorage $store */
38+
$store = self::createObjectStoreService();
5139

5240
// Delete the container and all the contents.
5341
$cname = self::$settings['openstack.swift.container'];
5442

5543
try {
5644
$container = $store->container($cname);
57-
}
58-
// The container was never created.
59-
catch (\OpenStack\Common\Transport\Exception\FileNotFoundException $e) {
45+
} catch (FileNotFoundException $e) {
46+
// The container was never created.
6047
return;
6148
}
6249

@@ -115,30 +102,24 @@ protected function basicSwiftContext($add = array(), $scheme = null)
115102
/**
116103
* This performs authentication via context.
117104
*/
118-
protected function authSwiftContext($add = array(), $scheme = null)
105+
protected function authSwiftContext(array $params = [], $scheme = null)
119106
{
120-
$cname = self::$settings['openstack.swift.container'];
121-
$username = self::$settings['openstack.identity.username'];
122-
$password = self::$settings['openstack.identity.password'];
123-
$tenant = self::$settings['openstack.identity.tenantId'];
124-
$baseURL = self::$settings['openstack.identity.url'];
125-
126107
if (empty($scheme)) {
127108
$scheme = StreamWrapper::DEFAULT_SCHEME;
128109
}
129110

130-
$params = $add + array(
131-
'username' => $username,
132-
'password' => $password,
133-
'endpoint' => $baseURL,
134-
'tenantid' => $tenant,
111+
$params += [
112+
'username' => self::$settings['openstack.identity.username'],
113+
'password' => self::$settings['openstack.identity.password'],
114+
'endpoint' => self::$settings['openstack.identity.url'],
115+
'tenantid' => self::$settings['openstack.identity.tenantId'],
135116
'content_type' => self::FTYPE,
136-
'transport_client' => $this->getTransportClient(),
137-
);
138-
$cxt = array($scheme => $params);
139-
140-
return stream_context_create($cxt);
117+
'transport_client' => $this->getTransportClient()
118+
];
141119

120+
return stream_context_create([
121+
$scheme => $params
122+
]);
142123
}
143124

144125
/**

0 commit comments

Comments
 (0)