diff --git a/.gitattributes b/.gitattributes
index 5041178c0..8146c84cf 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -4,7 +4,8 @@
/tests export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
-/.php_cs.dist export-ignore
+/.php-cs-fixer.dist.php export-ignore
+/.readthedocs.yaml export-ignore
/.scrutinizer.yml export-ignore
-/.travis.yml export-ignore
+/phpunit.sample.xml.dist export-ignore
/phpunit.xml.dist export-ignore
\ No newline at end of file
diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml
index b94f81843..f00c019f8 100644
--- a/.github/workflows/integration_tests.yml
+++ b/.github/workflows/integration_tests.yml
@@ -96,19 +96,9 @@ jobs:
echo OS_FLAVOR=1
echo OS_DOMAIN_ID=default
} >> "$GITHUB_ENV"
- - name: Execute Block Storage v2 tests
+ - name: Check if Block Storage API v2 must be tested
if: matrix.block_storage_v2 == true
- run: php ./tests/integration/run.php -s=BlockStorage -v=v2
- - name: Execute Block Storage v3 tests
- run: php ./tests/integration/run.php -s=BlockStorage -v=v3
- - name: Execute Compute tests
- run: php ./tests/integration/run.php -s=Compute
- - name: Execute Identity tests
- run: php ./tests/integration/run.php -s=Identity
- - name: Execute Images tests
- run: php ./tests/integration/run.php -s=Images
- - name: Execute Networking tests
- run: php ./tests/integration/run.php -s=Networking
- - name: Execute Object Storage tests
- run: php ./tests/integration/run.php -s=ObjectStore
+ run: echo "OS_BLOCK_STORAGE_V2=1" >> "$GITHUB_ENV"
+ - name: Execute Integration tests via PhpUnit
+ run: vendor/bin/phpunit --configuration ./phpunit.sample.xml.dist
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 91f83d70c..000000000
--- a/.travis.yml
+++ /dev/null
@@ -1,40 +0,0 @@
-language: php
-
-dist: bionic
-
-cache:
- directories:
- - $HOME/.composer/cache
-
-matrix:
- include:
- - php: 7.2
- - php: 7.3
- - php: 7.4
- - php: 8.0
- - php: nightly
- allow_failures:
- - php: nightly
- fast_finish: true
-
-before_install:
- - cat $HOME/.phpenv/versions/$TRAVIS_PHP_VERSION/etc/conf.d/xdebug.ini > ./xdebug.ini
- - phpenv config-rm xdebug.ini || true
- - composer self-update
- - if [ -n "$GH_TOKEN" ]; then composer config github-oauth.github.com ${GH_TOKEN}; fi;
-
-before_script:
- - composer install --prefer-source
- - vendor/bin/parallel-lint --exclude vendor .
- - vendor/bin/php-cs-fixer fix --dry-run --diff
- - phpenv config-add ./xdebug.ini
-
-after_script:
- - php vendor/bin/coveralls -v
-
-after_success:
- - travis_retry php vendor/bin/php-coveralls -v
-
-notifications:
- email:
- - thanhha.work@gmail.com
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 8661ec7e7..a7705d30b 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -185,7 +185,7 @@ The second argument to `setupMockResponse` is an external file, storing a string
We use phpunit, so you run this at the project root:
```bash
-phpunit
+vendor/bin/phpunit
```
### Integration tests
@@ -203,29 +203,46 @@ service charges from your provider. Although most tests handle their own
teardown procedures, it is always worth manually checking that resources are
deleted after the test suite finishes.
+It is recommended to run integration test in a separate OpenStack project, so that you can easily clean up all resources.
+
We use all of our sample files as live integration tests, achieving the dual aim of reducing code duplication and
ensuring that our samples actually work.
+### Setting up dev environment
+
+In order to run integration tests, you need to have a working OpenStack environment.
+You can use [DevStack](http://docs.openstack.org/developer/devstack/) to set up a local OpenStack environment.
+DevStack will make substantial changes to your system during installation. Only run DevStack on servers or
+virtual machines that are dedicated to this purpose.
+
+Installation is pretty straightforward. You can use guide on their [website](http://docs.openstack.org/developer/devstack/).
+
+Here is currently used `local.conf` for DevStack:
+
+```ini
+[[local|localrc]]
+ADMIN_PASSWORD=secret
+DATABASE_PASSWORD=root
+RABBIT_PASSWORD=secret
+SERVICE_PASSWORD=secret
+SWIFT_HASH=1234123412341234
+LOGFILE=/tmp/devstack-logs/devstack.log
+USE_PYTHON3=True
+INSTALL_TEMPEST=False
+GIT_BASE=https://github.com
+ENABLED_SERVICES+=,-horizon,-dstat,-tempest,s-account,s-container,s-object,s-proxy,s-bak
+SWIFT_ENABLE_TEMPURLS=True
+SWIFT_TEMPURL_KEY=secretkey
+
+[[post-config|$SWIFT_CONFIG_PROXY_SERVER]]
+[filter:versioned_writes]
+allow_object_versioning = true
+```
+
### Setting up environment variables
Rename `env_test.sh.dist` as `env_test.sh` and replace values according to your OpenStack instance configuration.
-Completed file may look as following.
-
-
-```bash
-#!/usr/bin/env bash
-export OS_AUTH_URL="http://1.2.3.4:5000/v3"
-export OS_REGION="RegionOne"
-export OS_REGION_NAME="RegionOne"
-export OS_USER_ID="536068bcb1b946ff8e2f10eff6543f9c"
-export OS_USERNAME="admin"
-export OS_PASSWORD="2251639ecaea442b"
-export OS_PROJECT_ID="b62b3bebf9e84e4eb11aafcd8c58db3f"
-export OS_PROJECT_NAME="admin"
-export OS_RESIZE_FLAVOR=2 #Must be a valid flavor ID
-export OS_FLAVOR=1 #Must be a valid flavor ID
-export OS_DOMAIN_ID="default"
-```
+If you are using DevStack with config file above, the values would be filled automatically.
To export environment variables, run
```bash
@@ -236,23 +253,12 @@ Additionally, integration tests require image called `cirros` exists.
### Running integration tests
-You interact with integration tests through a runner script:
+We use phpunit, so you run this at the project root:
```bash
-php ./tests/integration/run.php [-s=BlockStorage|Compute|Identity|Images|Networking|ObjectStore] [--debug=1|2]
+vendor/bin/phpunit --configuration ./phpunit.sample.xml.dist
```
-It supports these command-line flags:
-
-| Flag | Description | Example |
-| ---- | ----------- | ------- |
-| `-s` `--service` | Allows you to refine tests by a particular service. A service corresponds to top-level directories in the `./integration` directory, meaning that `compute` and `identity` are services because they exist as sub-directories there. If omitted, all services are run.|Run compute service: `php ./tests/integration/run.php -s compute` Run all tests: `php ./tests/integration/run.php`|
-| `-v` `--version` | Allows you to refine by a particular service version. A version corresponds to the sub-directories inside a service directory, meaning that `v2` is a supported version of `compute` because it exists as a sub-directory inside the `compute` directory. If omitted, all versions are run.|Run v2 Compute tests: `php ./tests/integration/run.php -s compute -v v2` Run all compute tests: `php ./tests/integration/run.php -s compute`|
-| `-t` `--test` | Allows you to refine by a particular test. Tests are defined in classes like `integration\OpenStack\Compute\v2`. Each test method manually references a sample file. To refine which tests are run, list the name of the method in this class. If omitted, all tests are run.|Run create server test: `php ./tests/integration/run.php -s compute -v v2 -t createServer` Run all compute v2 tests: `php ./tests/integration/run.php -s compute -v v2`|
-| `--debug` |||
-| `--help` | A help screen is returned and no tests run | `php ./tests/integration/run.php --help`
-
-
## Style guide
We follow [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) for our
@@ -281,14 +287,11 @@ required to adhere to:
### 1. Providing feedback
-On of the easiest ways to get readily involved in our project is to let us know
+One of the easiest ways to get readily involved in our project is to let us know
about your experiences using our SDK. Feedback like this is incredibly useful
to us, because it allows us to refine and change features based on what our
-users want and expect of us. There are a bunch of ways to get in contact! You
-can [ping us](https://developer.rackspace.com/support/) via e-mail, talk to us on irc
-(#rackspace-dev on freenode), [tweet us](https://twitter.com/rackspace), or
-submit an issue on our [bug tracker](/issues). Things you might like to tell us
-are:
+users want and expect of us. You can submit an issue on our [bug tracker](/issues).
+Things you might like to tell us are:
* how easy was it to start using our SDK?
* did it meet your expectations? If not, why not?
@@ -309,8 +312,7 @@ breakthroughs on it so far.
We have three forms of documentation:
* short README documents that briefly introduce a topic
-* reference documentation
-* user documentation on http://docs.php-opencloud.com that includes
+* user documentation on https://php-openstack-sdk.readthedocs.io that includes
getting started guides, installation guides and code samples
If you feel that a certain section could be improved - whether it's to clarify
diff --git a/composer.json b/composer.json
index 6d460aadf..d0e78e252 100644
--- a/composer.json
+++ b/composer.json
@@ -50,6 +50,7 @@
"autoload-dev": {
"psr-4": {
"OpenStack\\Integration\\": "tests/integration/",
+ "OpenStack\\Sample\\": "tests/sample/",
"OpenStack\\Test\\": "tests/unit/"
}
},
diff --git a/doc/services/compute/v2/servers.rst b/doc/services/compute/v2/servers.rst
index a80fc4b99..eb6ed7ea9 100644
--- a/doc/services/compute/v2/servers.rst
+++ b/doc/services/compute/v2/servers.rst
@@ -229,8 +229,8 @@ This operation will reset the state of the server.
Reboot server
-------------
-This operation will reboot a server. Please be aware that you must specify whether you want to initiate a HARD or
-SOFT reboot (you specify this as a string argument).
+This operation will reboot a server. You can specify HARD reboot by passing argument Enum::REBOOT_HARD to the function.
+Otherwise, the default is a SOFT reboot.
.. sample:: Compute/v2/servers/reboot_server.php
.. refdoc:: OpenStack/Compute/v2/Models/Server.html#method_reboot
diff --git a/env_test.sh.dist b/env_test.sh.dist
index 1abaec35c..e9fcb762a 100644
--- a/env_test.sh.dist
+++ b/env_test.sh.dist
@@ -1,12 +1,13 @@
#!/usr/bin/env bash
-export OS_AUTH_URL=""
-export OS_REGION=""
-export OS_REGION_NAME=""
-export OS_USER_ID=""
-export OS_USERNAME=""
-export OS_PASSWORD=""
-export OS_PROJECT_ID=""
-export OS_PROJECT_NAME=""
-export OS_RESIZE_FLAVOR=""
-export OS_FLAVOR=""
+
+export OS_AUTH_URL="$(grep -oP -m 1 "(?<=auth_url: )(.*)\$" /etc/openstack/clouds.yaml)/v3"
+export OS_REGION="RegionOne"
+export OS_REGION_NAME="RegionOne"
+export OS_USER_ID=$(openstack --os-cloud=devstack-admin user show admin -f value -c id)
+export OS_USERNAME="admin"
+export OS_PASSWORD="secret"
+export OS_PROJECT_ID=$(openstack --os-cloud=devstack-admin project show admin -f value -c id)
+export OS_PROJECT_NAME="admin"
+export OS_RESIZE_FLAVOR="c1"
+export OS_FLAVOR=1
export OS_DOMAIN_ID="default"
diff --git a/phpunit.sample.xml.dist b/phpunit.sample.xml.dist
new file mode 100644
index 000000000..d2048c5f3
--- /dev/null
+++ b/phpunit.sample.xml.dist
@@ -0,0 +1,23 @@
+
+
+
+
+ tests/sample
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 22694ff40..e77fdd4c3 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,10 +1,13 @@
-
-
-
-
+
-
+
tests/unit
@@ -13,14 +16,4 @@
-
-
- ./src
-
- ./src
- ./src
- ./src
-
-
-
\ No newline at end of file
diff --git a/samples/BlockStorage/v3/snapshots/list.php b/samples/BlockStorage/v3/snapshots/list.php
index 5d58bda95..fdf3f66d1 100644
--- a/samples/BlockStorage/v3/snapshots/list.php
+++ b/samples/BlockStorage/v3/snapshots/list.php
@@ -14,5 +14,5 @@
$snapshots = $service->listSnapshots();
foreach ($snapshots as $snapshot) {
- /** @var $snapshot \OpenStack\BlockStorage\v2\Models\Snapshot */
+ /** @var \OpenStack\BlockStorage\v2\Models\Snapshot $snapshot */
}
diff --git a/samples/BlockStorage/v3/snapshots/list_sorted.php b/samples/BlockStorage/v3/snapshots/list_sorted.php
index 1f01301d3..ce9a50bf4 100644
--- a/samples/BlockStorage/v3/snapshots/list_sorted.php
+++ b/samples/BlockStorage/v3/snapshots/list_sorted.php
@@ -14,5 +14,5 @@
$snapshots = $service->listSnapshots(false, ['sortKey' => '{sortKey}', 'sortDir' => '{sortDir}']);
foreach ($snapshots as $snapshot) {
- /** @var $snapshot \OpenStack\BlockStorage\v2\Models\Snapshot */
+ /** @var \OpenStack\BlockStorage\v2\Models\Snapshot $snapshot */
}
diff --git a/samples/BlockStorage/v3/volume_types/list.php b/samples/BlockStorage/v3/volume_types/list.php
index 3c6d3bf80..288a183ee 100644
--- a/samples/BlockStorage/v3/volume_types/list.php
+++ b/samples/BlockStorage/v3/volume_types/list.php
@@ -14,5 +14,5 @@
$volumeTypes = $service->listVolumeTypes();
foreach ($volumeTypes as $volumeType) {
- /** @var $volumeType \OpenStack\BlockStorage\v2\VolumeType */
+ /** @var \OpenStack\BlockStorage\v2\Models\VolumeType $volumeType */
}
diff --git a/samples/BlockStorage/v3/volumes/list.php b/samples/BlockStorage/v3/volumes/list.php
index 0b1d5c83a..a067b304a 100644
--- a/samples/BlockStorage/v3/volumes/list.php
+++ b/samples/BlockStorage/v3/volumes/list.php
@@ -14,5 +14,5 @@
$volumes = $service->listVolumes();
foreach ($volumes as $volume) {
- /** @var $volume \OpenStack\BlockStorage\v2\Models\Volume */
+ /** @var \OpenStack\BlockStorage\v2\Models\Volume $volume */
}
diff --git a/samples/BlockStorage/v3/volumes/update.php b/samples/BlockStorage/v3/volumes/update.php
index d9de1d53c..371d12e87 100644
--- a/samples/BlockStorage/v3/volumes/update.php
+++ b/samples/BlockStorage/v3/volumes/update.php
@@ -6,14 +6,14 @@
'authUrl' => '{authUrl}',
'region' => '{region}',
'user' => ['id' => '{userId}', 'password' => '{password}'],
- 'scope' => ['project' => ['id' => '{projectId}']]
+ 'scope' => ['project' => ['id' => '{projectId}']],
]);
$service = $openstack->blockStorageV3();
$volume = $service->getVolume('{volumeId}');
-$volume->name = '{newName}';
+$volume->name = '{newName}';
$volume->description = '{newDescription}';
$volume->update();
diff --git a/samples/Compute/v2/flavors/list_flavors.php b/samples/Compute/v2/flavors/list_flavors.php
index 570af2d06..b14eaaeec 100644
--- a/samples/Compute/v2/flavors/list_flavors.php
+++ b/samples/Compute/v2/flavors/list_flavors.php
@@ -17,4 +17,5 @@
$flavors = $compute->listFlavors();
foreach ($flavors as $flavor) {
+ /** @var \OpenStack\Compute\v2\Models\Flavor $flavor */
}
diff --git a/samples/Compute/v2/hypervisors/get_hypervisors_statistics.php b/samples/Compute/v2/hypervisors/get_hypervisors_statistics.php
index c4e78e35e..b702b4d54 100644
--- a/samples/Compute/v2/hypervisors/get_hypervisors_statistics.php
+++ b/samples/Compute/v2/hypervisors/get_hypervisors_statistics.php
@@ -16,5 +16,4 @@
$compute = $openstack->computeV2(['region' => '{region}']);
-/** @var HypervisorStatistic $hypervisorStatistics */
$hypervisorStatistics = $compute->getHypervisorStatistics();
diff --git a/samples/Compute/v2/hypervisors/list_hypervisors.php b/samples/Compute/v2/hypervisors/list_hypervisors.php
index dee1eaf9e..4dd7b3849 100644
--- a/samples/Compute/v2/hypervisors/list_hypervisors.php
+++ b/samples/Compute/v2/hypervisors/list_hypervisors.php
@@ -1,7 +1,5 @@
listHypervisors();
foreach ($hypervisors as $hypervisor) {
- /**@var Hypervisor $hypervisor*/
+ /** @var \OpenStack\Compute\v2\Models\Hypervisor $hypervisor */
}
diff --git a/samples/Compute/v2/images/delete_image_metadata_item.php b/samples/Compute/v2/images/delete_image_metadata_item.php
index 31e89e0d9..442fd3204 100644
--- a/samples/Compute/v2/images/delete_image_metadata_item.php
+++ b/samples/Compute/v2/images/delete_image_metadata_item.php
@@ -16,4 +16,4 @@
$image = $compute->getImage(['id' => '{imageId}']);
-$image->deleteMetadataItem('key');
+$image->deleteMetadataItem('{key}');
diff --git a/samples/Compute/v2/images/list_images.php b/samples/Compute/v2/images/list_images.php
index 0c7f56385..d0353c8d8 100644
--- a/samples/Compute/v2/images/list_images.php
+++ b/samples/Compute/v2/images/list_images.php
@@ -17,4 +17,5 @@
$images = $compute->listImages(['status' => 'ACTIVE']);
foreach ($images as $image) {
+ /** @var \OpenStack\Compute\v2\Models\Image $image */
}
diff --git a/samples/Compute/v2/images/merge_image_metadata.php b/samples/Compute/v2/images/merge_image_metadata.php
new file mode 100644
index 000000000..c2b9151b0
--- /dev/null
+++ b/samples/Compute/v2/images/merge_image_metadata.php
@@ -0,0 +1,21 @@
+ '{authUrl}',
+ 'region' => '{region}',
+ 'user' => [
+ 'id' => '{userId}',
+ 'password' => '{password}'
+ ],
+ 'scope' => ['project' => ['id' => '{projectId}']]
+]);
+
+$compute = $openstack->computeV2(['region' => '{region}']);
+
+$image = $compute->getImage(['id' => '{imageId}']);
+
+$image->mergeMetadata([
+ '{key}' => '{value}',
+]);
diff --git a/samples/Compute/v2/images/reset_image_metadata.php b/samples/Compute/v2/images/reset_image_metadata.php
index 790f8e5a5..176dc948c 100644
--- a/samples/Compute/v2/images/reset_image_metadata.php
+++ b/samples/Compute/v2/images/reset_image_metadata.php
@@ -17,5 +17,5 @@
$image = $compute->getImage(['id' => '{imageId}']);
$image->resetMetadata([
- 'key' => 'value',
+ '{key}' => '{value}',
]);
diff --git a/samples/Compute/v2/images/retrieve_image_metadata.php b/samples/Compute/v2/images/retrieve_image_metadata.php
index 44600436b..e2316f680 100644
--- a/samples/Compute/v2/images/retrieve_image_metadata.php
+++ b/samples/Compute/v2/images/retrieve_image_metadata.php
@@ -16,6 +16,4 @@
$image = $compute->getImage(['id' => '{imageId}']);
-$metadata = $image->getMetadata([
- 'key' => 'value'
-]);
+$metadata = $image->getMetadata();
diff --git a/samples/Compute/v2/keypairs/get_keypair.php b/samples/Compute/v2/keypairs/get_keypair.php
index 9ed0fb5e1..bbfc0ba1d 100644
--- a/samples/Compute/v2/keypairs/get_keypair.php
+++ b/samples/Compute/v2/keypairs/get_keypair.php
@@ -14,7 +14,6 @@
$compute = $openstack->computeV2(['region' => '{region}']);
-/** @var \OpenStack\Compute\v2\Models\Keypair $keypair */
$keypair = $compute->getKeypair(['name' => '{name}']);
$keypair->retrieve();
diff --git a/samples/Compute/v2/keypairs/list_keypairs.php b/samples/Compute/v2/keypairs/list_keypairs.php
index c1b88ae60..dedf9bbeb 100644
--- a/samples/Compute/v2/keypairs/list_keypairs.php
+++ b/samples/Compute/v2/keypairs/list_keypairs.php
@@ -1,7 +1,5 @@
listKeypairs();
foreach ($keypairs as $keypair) {
- /**@var Keypair $keypair */
+ /** @var \OpenStack\Compute\v2\Models\Keypair $keypair */
}
diff --git a/samples/Compute/v2/limits/get_limits.php b/samples/Compute/v2/limits/get_limits.php
index 15aa6e162..2123995f9 100644
--- a/samples/Compute/v2/limits/get_limits.php
+++ b/samples/Compute/v2/limits/get_limits.php
@@ -14,5 +14,4 @@
$compute = $openstack->computeV2(['region' => '{region}']);
-/** @var \OpenStack\Compute\v2\Models\Limit $limit */
$limit = $compute->getLimits();
diff --git a/samples/Compute/v2/servers/add_security_group.php b/samples/Compute/v2/servers/add_security_group.php
index 429d5207a..1b4713060 100644
--- a/samples/Compute/v2/servers/add_security_group.php
+++ b/samples/Compute/v2/servers/add_security_group.php
@@ -14,9 +14,6 @@
$compute = $openstack->computeV2(['region' => '{region}']);
-/**@var OpenStack\Compute\v2\Models\Server $server */
-$server = $compute->getServer([
- 'id' => '{serverId}',
-]);
+$server = $compute->getServer(['id' => '{serverId}']);
$server->addSecurityGroup(['name' => '{secGroupName}']);
diff --git a/samples/Compute/v2/servers/attach_volume_attachment.php b/samples/Compute/v2/servers/attach_volume_attachment.php
index fb803c6a2..e072d3322 100644
--- a/samples/Compute/v2/servers/attach_volume_attachment.php
+++ b/samples/Compute/v2/servers/attach_volume_attachment.php
@@ -18,8 +18,6 @@
$compute = $openstack->computeV2(['region' => '{region}']);
-/**@var OpenStack\Compute\v2\Models\Server $server */
$server = $compute->getServer(['id' => '{serverId}']);
-/**@var VolumeAttachment $volumeAttachment*/
$volumeAttachment = $server->attachVolume('{volumeId}');
diff --git a/samples/Compute/v2/servers/change_server_password.php b/samples/Compute/v2/servers/change_server_password.php
index c2330a2e6..f3f22ed31 100644
--- a/samples/Compute/v2/servers/change_server_password.php
+++ b/samples/Compute/v2/servers/change_server_password.php
@@ -14,8 +14,6 @@
$compute = $openstack->computeV2(['region' => '{region}']);
-$server = $compute->getServer([
- 'id' => '{serverId}',
-]);
+$server = $compute->getServer(['id' => '{serverId}']);
$server->changePassword('{newPassword}');
diff --git a/samples/Compute/v2/servers/create_interface_attachment.php b/samples/Compute/v2/servers/create_interface_attachment.php
index f87d99293..430e0cc73 100644
--- a/samples/Compute/v2/servers/create_interface_attachment.php
+++ b/samples/Compute/v2/servers/create_interface_attachment.php
@@ -16,7 +16,4 @@
$server = $compute->getServer(['id' => '{serverId}']);
-/**@var OpenStack\Networking\v2\Models\InterfaceAttachment $interface */
-$interface = $server->createInterfaceAttachment([
- 'networkId' => '{networkId}',
-]);
+$interfaceAttachment = $server->createInterfaceAttachment(['networkId' => '{networkId}']);
diff --git a/samples/Compute/v2/servers/create_server.php b/samples/Compute/v2/servers/create_server.php
index 41190f5de..73a9fc06a 100644
--- a/samples/Compute/v2/servers/create_server.php
+++ b/samples/Compute/v2/servers/create_server.php
@@ -31,5 +31,4 @@
];
// Create the server
-/**@var OpenStack\Compute\v2\Models\Server $server */
$server = $compute->createServer($options);
diff --git a/samples/Compute/v2/servers/delete_server.php b/samples/Compute/v2/servers/delete_server.php
index 650ae209d..48bf850f5 100644
--- a/samples/Compute/v2/servers/delete_server.php
+++ b/samples/Compute/v2/servers/delete_server.php
@@ -14,7 +14,6 @@
$compute = $openstack->computeV2(['region' => '{region}']);
-/**@var OpenStack\Compute\v2\Models\Server $server */
$server = $compute->getServer(['id' => '{serverId}']);
$server->delete();
diff --git a/samples/Compute/v2/servers/delete_server_metadata_item.php b/samples/Compute/v2/servers/delete_server_metadata_item.php
index 318f1d32c..2b51dd638 100644
--- a/samples/Compute/v2/servers/delete_server_metadata_item.php
+++ b/samples/Compute/v2/servers/delete_server_metadata_item.php
@@ -16,4 +16,4 @@
$server = $compute->getServer(['id' => '{serverId}']);
-$server->deleteMetadataItem('key');
+$server->deleteMetadataItem('{key}');
diff --git a/samples/Compute/v2/servers/get_server_console_output.php b/samples/Compute/v2/servers/get_server_console_output.php
index e579f367a..4a9118c89 100644
--- a/samples/Compute/v2/servers/get_server_console_output.php
+++ b/samples/Compute/v2/servers/get_server_console_output.php
@@ -16,5 +16,4 @@
$server = $compute->getServer(['id' => '{serverId}']);
-/** @var string $consoleOutput */
$consoleOutput = $server->getConsoleOutput();
diff --git a/samples/Compute/v2/servers/get_server_vnc_console.php b/samples/Compute/v2/servers/get_server_vnc_console.php
index fc1bcf2c3..d662c4811 100644
--- a/samples/Compute/v2/servers/get_server_vnc_console.php
+++ b/samples/Compute/v2/servers/get_server_vnc_console.php
@@ -16,5 +16,4 @@
$server = $compute->getServer(['id' => '{serverId}']);
-/** @var array $console */
$console = $server->getVncConsole();
diff --git a/samples/Compute/v2/servers/list_security_groups.php b/samples/Compute/v2/servers/list_security_groups.php
index f215a3e38..d7743c25a 100644
--- a/samples/Compute/v2/servers/list_security_groups.php
+++ b/samples/Compute/v2/servers/list_security_groups.php
@@ -1,8 +1,5 @@
listSecurityGroups();
foreach ($securityGroups as $securityGroup) {
- /**@var SecurityGroup $securityGroup */
- $rules = $securityGroup->securityGroupRules;
-
- foreach ($rules as $rule) {
- /**@var SecurityGroupRule $rule */
- }
+ /** @var \OpenStack\Networking\v2\Extensions\SecurityGroups\Models\SecurityGroup $securityGroup */
}
diff --git a/samples/Compute/v2/servers/list_volume_attachments.php b/samples/Compute/v2/servers/list_volume_attachments.php
index 518e93642..683e47402 100644
--- a/samples/Compute/v2/servers/list_volume_attachments.php
+++ b/samples/Compute/v2/servers/list_volume_attachments.php
@@ -1,9 +1,5 @@
'{region}',
'user' => [
'id' => '{userId}',
- 'password' => '{password}'
+ 'password' => '{password}',
],
- 'scope' => ['project' => ['id' => '{projectId}']]
+ 'scope' => ['project' => ['id' => '{projectId}']],
]);
$compute = $openstack->computeV2(['region' => '{region}']);
@@ -21,5 +17,5 @@
$server = $compute->getServer(['id' => '{serverId}']);
foreach ($server->listVolumeAttachments() as $volumeAttachment) {
- /**@var VolumeAttachment $volumeAttachment*/
+ /** @var \OpenStack\BlockStorage\v2\Models\VolumeAttachment $volumeAttachment */
}
diff --git a/samples/Compute/v2/servers/merge_server_metadata.php b/samples/Compute/v2/servers/merge_server_metadata.php
index e67cf8b51..447e05fc0 100644
--- a/samples/Compute/v2/servers/merge_server_metadata.php
+++ b/samples/Compute/v2/servers/merge_server_metadata.php
@@ -17,5 +17,5 @@
$server = $compute->getServer(['id' => '{serverId}']);
$server->mergeMetadata([
- 'key' => 'value'
+ '{key}' => '{value}'
]);
diff --git a/samples/Compute/v2/servers/reboot_server.php b/samples/Compute/v2/servers/reboot_server.php
index ac4a50cab..a341cc4f3 100644
--- a/samples/Compute/v2/servers/reboot_server.php
+++ b/samples/Compute/v2/servers/reboot_server.php
@@ -14,8 +14,6 @@
$compute = $openstack->computeV2(['region' => '{region}']);
-$server = $compute->getServer([
- 'id' => '{serverId}',
-]);
+$server = $compute->getServer(['id' => '{serverId}']);
-$server->reboot();
+$server->reboot(\OpenStack\Compute\v2\Enum::REBOOT_HARD);
diff --git a/samples/Compute/v2/servers/rebuild_server.php b/samples/Compute/v2/servers/rebuild_server.php
index 0867abdb3..26f8ba19c 100644
--- a/samples/Compute/v2/servers/rebuild_server.php
+++ b/samples/Compute/v2/servers/rebuild_server.php
@@ -14,9 +14,7 @@
$compute = $openstack->computeV2(['region' => '{region}']);
-$server = $compute->getServer([
- 'id' => '{serverId}',
-]);
+$server = $compute->getServer(['id' => '{serverId}']);
$server->rebuild([
'imageId' => '{imageId}',
diff --git a/samples/Compute/v2/servers/rescue_server.php b/samples/Compute/v2/servers/rescue_server.php
index d4c6516a8..38a28abd3 100644
--- a/samples/Compute/v2/servers/rescue_server.php
+++ b/samples/Compute/v2/servers/rescue_server.php
@@ -14,9 +14,7 @@
$compute = $openstack->computeV2(['region' => '{region}']);
-$server = $compute->getServer([
- 'id' => '{serverId}',
-]);
+$server = $compute->getServer(['id' => '{serverId}']);
$server->rescue([
'imageId' => '{imageId}',
diff --git a/samples/Compute/v2/servers/reset_server_metadata.php b/samples/Compute/v2/servers/reset_server_metadata.php
index 37748a4c2..0a3036e15 100644
--- a/samples/Compute/v2/servers/reset_server_metadata.php
+++ b/samples/Compute/v2/servers/reset_server_metadata.php
@@ -7,17 +7,15 @@
'region' => '{region}',
'user' => [
'id' => '{userId}',
- 'password' => '{password}'
+ 'password' => '{password}',
],
- 'scope' => ['project' => ['id' => '{projectId}']]
+ 'scope' => ['project' => ['id' => '{projectId}']],
]);
$compute = $openstack->computeV2(['region' => '{region}']);
-$server = $compute->getServer([
- 'id' => '{serverId}',
-]);
+$server = $compute->getServer(['id' => '{serverId}']);
$server->resetMetadata([
- 'key' => 'value',
+ '{key}' => '{value}',
]);
diff --git a/samples/Compute/v2/servers/revert_server_resize.php b/samples/Compute/v2/servers/revert_server_resize.php
index ee116d5b4..2b0390a7e 100644
--- a/samples/Compute/v2/servers/revert_server_resize.php
+++ b/samples/Compute/v2/servers/revert_server_resize.php
@@ -18,4 +18,5 @@
'id' => '{serverId}',
]);
+$server->waitUntil('VERIFY_RESIZE');
$server->revertResize();
diff --git a/samples/Compute/v2/servers/unrescue_server.php b/samples/Compute/v2/servers/unrescue_server.php
index 4148ac9f4..34f1527d3 100644
--- a/samples/Compute/v2/servers/unrescue_server.php
+++ b/samples/Compute/v2/servers/unrescue_server.php
@@ -14,9 +14,7 @@
$compute = $openstack->computeV2(['region' => '{region}']);
-$server = $compute->getServer([
- 'id' => '{serverId}',
-]);
+$server = $compute->getServer(['id' => '{serverId}']);
$server->waitUntil('RESCUE');
$server->unrescue();
diff --git a/samples/Identity/v3/domains/list_domains.php b/samples/Identity/v3/domains/list_domains.php
index f971e421f..d08cc1c83 100644
--- a/samples/Identity/v3/domains/list_domains.php
+++ b/samples/Identity/v3/domains/list_domains.php
@@ -19,4 +19,5 @@
$identity = $openstack->identityV3(['region' => '{region}']);
foreach ($identity->listDomains() as $domain) {
+ /** @var $domain \OpenStack\Identity\v3\Models\Domain */
}
diff --git a/samples/Identity/v3/domains/list_group_roles.php b/samples/Identity/v3/domains/list_group_roles.php
index b0ed10d89..1b7b89c3d 100644
--- a/samples/Identity/v3/domains/list_group_roles.php
+++ b/samples/Identity/v3/domains/list_group_roles.php
@@ -21,4 +21,5 @@
$domain = $identity->getDomain('{domainId}');
foreach ($domain->listGroupRoles(['groupId' => '{groupId}']) as $role) {
+ /** @var $role \OpenStack\Identity\v3\Models\Role */
}
diff --git a/samples/Identity/v3/domains/list_user_roles.php b/samples/Identity/v3/domains/list_user_roles.php
index 7d5381588..d9a7cfb17 100644
--- a/samples/Identity/v3/domains/list_user_roles.php
+++ b/samples/Identity/v3/domains/list_user_roles.php
@@ -21,4 +21,5 @@
$domain = $identity->getDomain('{domainId}');
foreach ($domain->listUserRoles(['userId' => '{domainUserId}']) as $role) {
+ /** @var $role \OpenStack\Identity\v3\Models\Role */
}
diff --git a/samples/Identity/v3/endpoints/list_endpoints.php b/samples/Identity/v3/endpoints/list_endpoints.php
index ed4669704..24d39a0e4 100644
--- a/samples/Identity/v3/endpoints/list_endpoints.php
+++ b/samples/Identity/v3/endpoints/list_endpoints.php
@@ -19,4 +19,5 @@
$identity = $openstack->identityV3(['region' => '{region}']);
foreach ($identity->listEndpoints() as $endpoint) {
+ /** @var $endpoint \OpenStack\Identity\v3\Models\Endpoint */
}
diff --git a/samples/Identity/v3/groups/list_groups.php b/samples/Identity/v3/groups/list_groups.php
index f889f3bc3..cee3577e1 100644
--- a/samples/Identity/v3/groups/list_groups.php
+++ b/samples/Identity/v3/groups/list_groups.php
@@ -19,4 +19,5 @@
$identity = $openstack->identityV3(['region' => '{region}']);
foreach ($identity->listGroups() as $group) {
+ /** @var $group \OpenStack\Identity\v3\Models\Group */
}
diff --git a/samples/Identity/v3/groups/list_users.php b/samples/Identity/v3/groups/list_users.php
index 0b186c225..40dc45c03 100644
--- a/samples/Identity/v3/groups/list_users.php
+++ b/samples/Identity/v3/groups/list_users.php
@@ -21,4 +21,5 @@
$group = $identity->getGroup('{groupId}');
foreach ($group->listUsers() as $user) {
+ /** @var $user \OpenStack\Identity\v3\Models\User */
}
diff --git a/samples/Identity/v3/groups/update_group.php b/samples/Identity/v3/groups/update_group.php
index ee48d9c65..71f8234de 100644
--- a/samples/Identity/v3/groups/update_group.php
+++ b/samples/Identity/v3/groups/update_group.php
@@ -20,7 +20,7 @@
$group = $identity->getGroup('{groupId}');
-$group->description = 'foo';
-$group->name = 'bar';
+$group->description = '{description}';
+$group->name = '{name}';
$group->update();
diff --git a/samples/Identity/v3/projects/list_group_roles.php b/samples/Identity/v3/projects/list_group_roles.php
index dc1e8641a..b678e0a78 100644
--- a/samples/Identity/v3/projects/list_group_roles.php
+++ b/samples/Identity/v3/projects/list_group_roles.php
@@ -21,4 +21,5 @@
$project = $identity->getProject('{id}');
foreach ($project->listGroupRoles(['groupId' => '{groupId}']) as $role) {
+ /** @var $role \OpenStack\Identity\v3\Models\Role */
}
diff --git a/samples/Identity/v3/projects/list_user_roles.php b/samples/Identity/v3/projects/list_user_roles.php
index 93efacaa1..11d96f495 100644
--- a/samples/Identity/v3/projects/list_user_roles.php
+++ b/samples/Identity/v3/projects/list_user_roles.php
@@ -21,4 +21,5 @@
$project = $identity->getProject('{id}');
foreach ($project->listUserRoles(['userId' => '{projectUserId}']) as $role) {
+ /** @var $role \OpenStack\Identity\v3\Models\Role */
}
diff --git a/samples/Identity/v3/roles/list_assignments.php b/samples/Identity/v3/roles/list_assignments.php
index 74279e6be..b39543b01 100644
--- a/samples/Identity/v3/roles/list_assignments.php
+++ b/samples/Identity/v3/roles/list_assignments.php
@@ -19,4 +19,5 @@
$identity = $openstack->identityV3();
foreach ($identity->listRoleAssignments() as $assignment) {
+ /** @var $assignment \OpenStack\Identity\v3\Models\Assignment */
}
diff --git a/samples/Identity/v3/roles/list_roles.php b/samples/Identity/v3/roles/list_roles.php
index 4036c2708..a5388a36f 100644
--- a/samples/Identity/v3/roles/list_roles.php
+++ b/samples/Identity/v3/roles/list_roles.php
@@ -19,4 +19,5 @@
$identity = $openstack->identityV3();
foreach ($identity->listRoles() as $role) {
+ /** @var $role \OpenStack\Identity\v3\Models\Role */
}
diff --git a/samples/Identity/v3/services/get_service.php b/samples/Identity/v3/services/get_service.php
index 1b8991a66..f8cf19499 100644
--- a/samples/Identity/v3/services/get_service.php
+++ b/samples/Identity/v3/services/get_service.php
@@ -19,3 +19,4 @@
$identity = $openstack->identityV3(['region' => '{region}']);
$service = $identity->getService('{serviceId}');
+$service->retrieve();
diff --git a/samples/Identity/v3/services/list_services.php b/samples/Identity/v3/services/list_services.php
index f72c22cf8..8b501e1a7 100644
--- a/samples/Identity/v3/services/list_services.php
+++ b/samples/Identity/v3/services/list_services.php
@@ -19,4 +19,5 @@
$identity = $openstack->identityV3(['region' => '{region}']);
foreach ($identity->listServices() as $service) {
+ /** @var $service \OpenStack\Identity\v3\Models\Service */
}
diff --git a/samples/Identity/v3/users/list_groups.php b/samples/Identity/v3/users/list_groups.php
index 5ec919ed0..af554436c 100644
--- a/samples/Identity/v3/users/list_groups.php
+++ b/samples/Identity/v3/users/list_groups.php
@@ -21,4 +21,5 @@
$user = $identity->getUser('{id}');
foreach ($user->listGroups() as $group) {
+ /** @var $group \OpenStack\Identity\v3\Models\Group */
}
diff --git a/samples/Identity/v3/users/list_projects.php b/samples/Identity/v3/users/list_projects.php
index 7f665325e..9e36f21eb 100644
--- a/samples/Identity/v3/users/list_projects.php
+++ b/samples/Identity/v3/users/list_projects.php
@@ -21,4 +21,5 @@
$user = $identity->getUser('{id}');
foreach ($user->listProjects() as $project) {
+ /** @var $project \OpenStack\Identity\v3\Models\Project */
}
diff --git a/samples/Identity/v3/users/list_users.php b/samples/Identity/v3/users/list_users.php
index 340255db5..b03b3a736 100644
--- a/samples/Identity/v3/users/list_users.php
+++ b/samples/Identity/v3/users/list_users.php
@@ -19,4 +19,5 @@
$identity = $openstack->identityV3();
foreach ($identity->listUsers() as $user) {
+ /** @var $user \OpenStack\Identity\v3\Models\User */
}
diff --git a/samples/Images/v2/images/get.php b/samples/Images/v2/images/get.php
index 98c95671d..680dc80b9 100644
--- a/samples/Images/v2/images/get.php
+++ b/samples/Images/v2/images/get.php
@@ -12,3 +12,4 @@
$service = $openstack->imagesV2();
$image = $service->getImage('{imageId}');
+$image->retrieve();
diff --git a/samples/Images/v2/members/add.php b/samples/Images/v2/members/add.php
index e62f12399..092fdbba3 100644
--- a/samples/Images/v2/members/add.php
+++ b/samples/Images/v2/members/add.php
@@ -6,9 +6,9 @@
'authUrl' => '{authUrl}',
'region' => '{region}',
'user' => ['id' => '{userId}', 'password' => '{password}'],
- 'scope' => ['project' => ['id' => '{projectId}']]
+ 'scope' => ['project' => ['id' => '{projectId}']],
]);
$member = $openstack->imagesV2()
- ->getImage('{imageId}')
- ->addMember('{projectId}');
+ ->getImage('{imageId}')
+ ->addMember('{projectId}');
diff --git a/samples/Networking/v2/floatingIPs/create.php b/samples/Networking/v2/floatingIPs/create.php
index 1ec2628cc..0880fbdf3 100644
--- a/samples/Networking/v2/floatingIPs/create.php
+++ b/samples/Networking/v2/floatingIPs/create.php
@@ -14,8 +14,7 @@
$networking = $openstack->networkingV2ExtLayer3();
-/** @var \OpenStack\Networking\v2\Extensions\Layer3\Models\FloatingIp $ip */
-$ip = $networking->createFloatingIp([
+$floatingIp = $networking->createFloatingIp([
"floatingNetworkId" => "{networkId}",
"portId" => "{portId}",
'fixedIpAddress' => '{fixedIpAddress}',
diff --git a/samples/Networking/v2/floatingIPs/delete.php b/samples/Networking/v2/floatingIPs/delete.php
index 6accb0155..9bbe8d0a8 100644
--- a/samples/Networking/v2/floatingIPs/delete.php
+++ b/samples/Networking/v2/floatingIPs/delete.php
@@ -7,11 +7,11 @@
'region' => '{region}',
'user' => [
'id' => '{userId}',
- 'password' => '{password}'
+ 'password' => '{password}',
],
- 'scope' => ['project' => ['id' => '{projectId}']]
+ 'scope' => ['project' => ['id' => '{projectId}']],
]);
$openstack->networkingV2ExtLayer3()
- ->getFloatingIp('{id}')
- ->delete();
+ ->getFloatingIp('{id}')
+ ->delete();
diff --git a/samples/Networking/v2/floatingIPs/get.php b/samples/Networking/v2/floatingIPs/get.php
index 54ff62ca4..759a3318d 100644
--- a/samples/Networking/v2/floatingIPs/get.php
+++ b/samples/Networking/v2/floatingIPs/get.php
@@ -7,11 +7,10 @@
'region' => '{region}',
'user' => [
'id' => '{userId}',
- 'password' => '{password}'
+ 'password' => '{password}',
],
- 'scope' => ['project' => ['id' => '{projectId}']]
+ 'scope' => ['project' => ['id' => '{projectId}']],
]);
-/** @var \OpenStack\Networking\v2\Extensions\Layer3\Models\FloatingIp $ip */
-$ip = $openstack->networkingV2ExtLayer3()
- ->getFloatingIp('{id}');
+$floatingIp = $openstack->networkingV2ExtLayer3()
+ ->getFloatingIp('{id}');
diff --git a/samples/Networking/v2/floatingIPs/list.php b/samples/Networking/v2/floatingIPs/list.php
index da87c8191..82065d955 100644
--- a/samples/Networking/v2/floatingIPs/list.php
+++ b/samples/Networking/v2/floatingIPs/list.php
@@ -7,13 +7,13 @@
'region' => '{region}',
'user' => [
'id' => '{userId}',
- 'password' => '{password}'
+ 'password' => '{password}',
],
- 'scope' => ['project' => ['id' => '{projectId}']]
+ 'scope' => ['project' => ['id' => '{projectId}']],
]);
$floatingIps = $openstack->networkingV2ExtLayer3()
- ->listFloatingIps();
+ ->listFloatingIps();
foreach ($floatingIps as $floatingIp) {
/** @var \OpenStack\Networking\v2\Extensions\Layer3\Models\FloatingIp $floatingIp */
diff --git a/samples/Networking/v2/floatingIPs/update.php b/samples/Networking/v2/floatingIPs/update.php
index 9698d30d3..4813006ec 100644
--- a/samples/Networking/v2/floatingIPs/update.php
+++ b/samples/Networking/v2/floatingIPs/update.php
@@ -7,13 +7,13 @@
'region' => '{region}',
'user' => [
'id' => '{userId}',
- 'password' => '{password}'
+ 'password' => '{password}',
],
- 'scope' => ['project' => ['id' => '{projectId}']]
+ 'scope' => ['project' => ['id' => '{projectId}']],
]);
$floatingIp = $openstack->networkingV2ExtLayer3()
- ->getFloatingIp('{id}');
+ ->getFloatingIp('{id}');
$floatingIp->portId = '{newPortId}';
$floatingIp->update();
diff --git a/samples/Networking/v2/ports/create.php b/samples/Networking/v2/ports/create.php
index 69635ed13..285ed6522 100644
--- a/samples/Networking/v2/ports/create.php
+++ b/samples/Networking/v2/ports/create.php
@@ -12,7 +12,7 @@
$networking = $openstack->networkingV2();
$port = $networking->createPort([
- 'name' => 'portName',
+ 'name' => '{portName}',
'networkId' => '{networkId}',
'adminStateUp' => true
]);
diff --git a/samples/Networking/v2/ports/create_batch.php b/samples/Networking/v2/ports/create_batch.php
index 669703888..f5206a1e8 100644
--- a/samples/Networking/v2/ports/create_batch.php
+++ b/samples/Networking/v2/ports/create_batch.php
@@ -13,13 +13,13 @@
$ports = $networking->createPorts([
[
- 'name' => 'port1',
- 'networkId' => '{networkId}',
+ 'name' => '{name1}',
+ 'networkId' => '{networkId1}',
'adminStateUp' => true
],
[
- 'name' => 'port2',
- 'networkId' => '{networkId}',
+ 'name' => '{name2}',
+ 'networkId' => '{networkId2}',
'adminStateUp' => true
],
]);
diff --git a/samples/Networking/v2/ports/create_with_fixed_ips.php b/samples/Networking/v2/ports/create_with_fixed_ips.php
index 921bf1b6a..ae28661ab 100644
--- a/samples/Networking/v2/ports/create_with_fixed_ips.php
+++ b/samples/Networking/v2/ports/create_with_fixed_ips.php
@@ -12,7 +12,7 @@
$networking = $openstack->networkingV2();
$port = $networking->createPort([
- 'name' => 'portName',
+ 'name' => '{portName}',
'networkId' => '{networkId}',
'adminStateUp' => true,
'fixedIps' => [
diff --git a/samples/Networking/v2/ports/list.php b/samples/Networking/v2/ports/list.php
index 2ab4bc53d..0442d5662 100644
--- a/samples/Networking/v2/ports/list.php
+++ b/samples/Networking/v2/ports/list.php
@@ -12,4 +12,5 @@
$networking = $openstack->networkingV2();
foreach ($networking->listPorts() as $port) {
+ /** @var \OpenStack\Networking\v2\Models\Port $port */
}
diff --git a/samples/Networking/v2/ports/update.php b/samples/Networking/v2/ports/update.php
index 170b9b631..a8f39e650 100644
--- a/samples/Networking/v2/ports/update.php
+++ b/samples/Networking/v2/ports/update.php
@@ -12,5 +12,5 @@
$networking = $openstack->networkingV2();
$port = $networking->getPort('{portId}');
-$port->name = 'newName';
+$port->name = '{newName}';
$port->update();
diff --git a/samples/Networking/v2/subnets/create_with_gateway_ip.php b/samples/Networking/v2/subnets/create_with_gateway_ip.php
index 769b214c4..168837f34 100644
--- a/samples/Networking/v2/subnets/create_with_gateway_ip.php
+++ b/samples/Networking/v2/subnets/create_with_gateway_ip.php
@@ -19,7 +19,7 @@
$networking = $openstack->networkingV2();
$options = [
- 'name' => 'My subnet',
+ 'name' => '{subnetName}',
'networkId' => '{networkId}',
'ipVersion' => 4,
'cidr' => '192.168.199.0/25',
diff --git a/samples/Networking/v2/subnets/create_with_host_routes.php b/samples/Networking/v2/subnets/create_with_host_routes.php
index ffca710ba..a58ed79a4 100644
--- a/samples/Networking/v2/subnets/create_with_host_routes.php
+++ b/samples/Networking/v2/subnets/create_with_host_routes.php
@@ -19,7 +19,7 @@
$networking = $openstack->networkingV2();
$options = [
- 'name' => 'My subnet',
+ 'name' => '{subnetName}',
'networkId' => '{networkId}',
'ipVersion' => 4,
'cidr' => '192.168.199.0/24',
diff --git a/samples/ObjectStore/v1/containers/get.php b/samples/ObjectStore/v1/containers/get.php
index fe056e915..8d764cd5d 100644
--- a/samples/ObjectStore/v1/containers/get.php
+++ b/samples/ObjectStore/v1/containers/get.php
@@ -7,10 +7,11 @@
'region' => '{region}',
'user' => [
'id' => '{userId}',
- 'password' => '{password}'
+ 'password' => '{password}',
],
- 'scope' => ['project' => ['id' => '{projectId}']]
+ 'scope' => ['project' => ['id' => '{projectId}']],
]);
$container = $openstack->objectStoreV1()
- ->getContainer('{containerName}');
+ ->getContainer('{containerName}');
+$container->retrieve();
diff --git a/samples/ObjectStore/v1/containers/list.php b/samples/ObjectStore/v1/containers/list.php
index c0c05c8d6..2cf9d401c 100644
--- a/samples/ObjectStore/v1/containers/list.php
+++ b/samples/ObjectStore/v1/containers/list.php
@@ -15,5 +15,5 @@
$service = $openstack->objectStoreV1();
foreach ($service->listContainers() as $container) {
- /** @var $container \OpenStack\ObjectStore\v1\Models\Container */
+ /** @var \OpenStack\ObjectStore\v1\Models\Container $container */
}
diff --git a/samples/ObjectStore/v1/objects/check_exists.php b/samples/ObjectStore/v1/objects/check_exists.php
index 48a9f0608..50b3b65ea 100644
--- a/samples/ObjectStore/v1/objects/check_exists.php
+++ b/samples/ObjectStore/v1/objects/check_exists.php
@@ -7,12 +7,11 @@
'region' => '{region}',
'user' => [
'id' => '{userId}',
- 'password' => '{password}'
+ 'password' => '{password}',
],
- 'scope' => ['project' => ['id' => '{projectId}']]
+ 'scope' => ['project' => ['id' => '{projectId}']],
]);
-/** @var bool $exists */
$exists = $openstack->objectStoreV1()
- ->getContainer('{containerName}')
- ->objectExists('{objectName}');
+ ->getContainer('{containerName}')
+ ->objectExists('{objectName}');
diff --git a/samples/ObjectStore/v1/objects/copy.php b/samples/ObjectStore/v1/objects/copy.php
index 15a08f52b..0790be82f 100644
--- a/samples/ObjectStore/v1/objects/copy.php
+++ b/samples/ObjectStore/v1/objects/copy.php
@@ -7,14 +7,14 @@
'region' => '{region}',
'user' => [
'id' => '{userId}',
- 'password' => '{password}'
+ 'password' => '{password}',
],
- 'scope' => ['project' => ['id' => '{projectId}']]
+ 'scope' => ['project' => ['id' => '{projectId}']],
]);
$openstack->objectStoreV1()
- ->getContainer('{containerName}')
- ->getObject('{objectName}')
- ->copy([
- 'destination' => '{newContainerName}/{newObjectName}'
- ]);
+ ->getContainer('{containerName}')
+ ->getObject('{objectName}')
+ ->copy([
+ 'destination' => '{newContainerName}/{newObjectName}',
+ ]);
diff --git a/samples/ObjectStore/v1/objects/create.php b/samples/ObjectStore/v1/objects/create.php
index 1541c22ca..65be7f884 100644
--- a/samples/ObjectStore/v1/objects/create.php
+++ b/samples/ObjectStore/v1/objects/create.php
@@ -7,17 +7,15 @@
'region' => '{region}',
'user' => [
'id' => '{userId}',
- 'password' => '{password}'
+ 'password' => '{password}',
],
- 'scope' => ['project' => ['id' => '{projectId}']]
+ 'scope' => ['project' => ['id' => '{projectId}']],
]);
-$options = [
- 'name' => '{objectName}',
- 'content' => '{objectContent}',
-];
-
/** @var \OpenStack\ObjectStore\v1\Models\StorageObject $object */
$object = $openstack->objectStoreV1()
- ->getContainer('{containerName}')
- ->createObject($options);
+ ->getContainer('{containerName}')
+ ->createObject([
+ 'name' => '{objectName}',
+ 'content' => '{objectContent}',
+ ]);
diff --git a/samples/ObjectStore/v1/objects/delete.php b/samples/ObjectStore/v1/objects/delete.php
index d66d5b7b6..548e53bd8 100644
--- a/samples/ObjectStore/v1/objects/delete.php
+++ b/samples/ObjectStore/v1/objects/delete.php
@@ -7,12 +7,12 @@
'region' => '{region}',
'user' => [
'id' => '{userId}',
- 'password' => '{password}'
+ 'password' => '{password}',
],
- 'scope' => ['project' => ['id' => '{projectId}']]
+ 'scope' => ['project' => ['id' => '{projectId}']],
]);
$openstack->objectStoreV1()
- ->getContainer('{containerName}')
- ->getObject('{objectName}')
- ->delete();
+ ->getContainer('{containerName}')
+ ->getObject('{objectName}')
+ ->delete();
diff --git a/samples/ObjectStore/v1/objects/download.php b/samples/ObjectStore/v1/objects/download.php
index 6129f6359..158c096ae 100644
--- a/samples/ObjectStore/v1/objects/download.php
+++ b/samples/ObjectStore/v1/objects/download.php
@@ -7,13 +7,12 @@
'region' => '{region}',
'user' => [
'id' => '{userId}',
- 'password' => '{password}'
+ 'password' => '{password}',
],
- 'scope' => ['project' => ['id' => '{projectId}']]
+ 'scope' => ['project' => ['id' => '{projectId}']],
]);
-/** @var \GuzzleHttp\Stream\Stream $stream */
$stream = $openstack->objectStoreV1()
- ->getContainer('{containerName}')
- ->getObject('{objectName}')
- ->download();
+ ->getContainer('{containerName}')
+ ->getObject('{objectName}')
+ ->download();
diff --git a/samples/ObjectStore/v1/objects/download_stream.php b/samples/ObjectStore/v1/objects/download_stream.php
index 8280b16cf..3d235b24e 100644
--- a/samples/ObjectStore/v1/objects/download_stream.php
+++ b/samples/ObjectStore/v1/objects/download_stream.php
@@ -7,13 +7,12 @@
'region' => '{region}',
'user' => [
'id' => '{userId}',
- 'password' => '{password}'
+ 'password' => '{password}',
],
- 'scope' => ['project' => ['id' => '{projectId}']]
+ 'scope' => ['project' => ['id' => '{projectId}']],
]);
-/** @var \GuzzleHttp\Stream\Stream $stream */
$stream = $openstack->objectStoreV1()
- ->getContainer('{containerName}')
- ->getObject('{objectName}')
- ->download(['requestOptions' => ['stream' => true]]);
+ ->getContainer('{containerName}')
+ ->getObject('{objectName}')
+ ->download(['requestOptions' => ['stream' => true]]);
diff --git a/samples/ObjectStore/v1/objects/get.php b/samples/ObjectStore/v1/objects/get.php
index b7b42f3a5..aeae0ad7d 100644
--- a/samples/ObjectStore/v1/objects/get.php
+++ b/samples/ObjectStore/v1/objects/get.php
@@ -7,12 +7,11 @@
'region' => '{region}',
'user' => [
'id' => '{userId}',
- 'password' => '{password}'
+ 'password' => '{password}',
],
- 'scope' => ['project' => ['id' => '{projectId}']]
+ 'scope' => ['project' => ['id' => '{projectId}']],
]);
-/** @var \OpenStack\ObjectStore\v1\Models\StorageObject $object */
$object = $openstack->objectStoreV1()
- ->getContainer('{containerName}')
- ->getObject('{objectName}');
+ ->getContainer('{containerName}')
+ ->getObject('{objectName}');
diff --git a/samples/ObjectStore/v1/objects/get_metadata.php b/samples/ObjectStore/v1/objects/get_metadata.php
index 0e09b71ff..dbb871a5a 100644
--- a/samples/ObjectStore/v1/objects/get_metadata.php
+++ b/samples/ObjectStore/v1/objects/get_metadata.php
@@ -7,13 +7,12 @@
'region' => '{region}',
'user' => [
'id' => '{userId}',
- 'password' => '{password}'
+ 'password' => '{password}',
],
- 'scope' => ['project' => ['id' => '{projectId}']]
+ 'scope' => ['project' => ['id' => '{projectId}']],
]);
-/** @var array $metadata */
$metadata = $openstack->objectStoreV1()
- ->getContainer('{containerName}')
- ->getObject('{objectName}')
- ->getMetadata();
+ ->getContainer('{containerName}')
+ ->getObject('{objectName}')
+ ->getMetadata();
diff --git a/samples/ObjectStore/v1/objects/list.php b/samples/ObjectStore/v1/objects/list.php
index 8d08cf0d4..713cacec5 100644
--- a/samples/ObjectStore/v1/objects/list.php
+++ b/samples/ObjectStore/v1/objects/list.php
@@ -7,13 +7,13 @@
'region' => '{region}',
'user' => [
'id' => '{userId}',
- 'password' => '{password}'
+ 'password' => '{password}',
],
- 'scope' => ['project' => ['id' => '{projectId}']]
+ 'scope' => ['project' => ['id' => '{projectId}']],
]);
$container = $openstack->objectStoreV1()
- ->getContainer('{containerName}');
+ ->getContainer('{containerName}');
foreach ($container->listObjects() as $object) {
/** @var \OpenStack\ObjectStore\v1\Models\StorageObject $object */
diff --git a/src/BlockStorage/v2/Models/VolumeType.php b/src/BlockStorage/v2/Models/VolumeType.php
index c54425e2f..120cfa732 100644
--- a/src/BlockStorage/v2/Models/VolumeType.php
+++ b/src/BlockStorage/v2/Models/VolumeType.php
@@ -8,12 +8,13 @@
use OpenStack\Common\Resource\Deletable;
use OpenStack\Common\Resource\Listable;
use OpenStack\Common\Resource\OperatorResource;
+use OpenStack\Common\Resource\Retrievable;
use OpenStack\Common\Resource\Updateable;
/**
* @property \OpenStack\BlockStorage\v2\Api $api
*/
-class VolumeType extends OperatorResource implements Listable, Creatable, Updateable, Deletable
+class VolumeType extends OperatorResource implements Listable, Creatable, Updateable, Deletable, Retrievable
{
/** @var string */
public $id;
@@ -34,6 +35,12 @@ public function create(array $userOptions): Creatable
return $this->populateFromResponse($response);
}
+ public function retrieve()
+ {
+ $response = $this->executeWithState($this->api->getType());
+ $this->populateFromResponse($response);
+ }
+
public function update()
{
$this->executeWithState($this->api->putType());
diff --git a/src/Compute/v2/Models/Image.php b/src/Compute/v2/Models/Image.php
index e4614cdde..55fd3e58d 100644
--- a/src/Compute/v2/Models/Image.php
+++ b/src/Compute/v2/Models/Image.php
@@ -7,6 +7,7 @@
use OpenStack\Common\Resource\Alias;
use OpenStack\Common\Resource\Deletable;
use OpenStack\Common\Resource\HasMetadata;
+use OpenStack\Common\Resource\HasWaiterTrait;
use OpenStack\Common\Resource\Listable;
use OpenStack\Common\Resource\OperatorResource;
use OpenStack\Common\Resource\Retrievable;
@@ -20,6 +21,8 @@
*/
class Image extends OperatorResource implements Listable, Retrievable, Deletable, HasMetadata
{
+ use HasWaiterTrait;
+
/** @var string */
public $id;
diff --git a/src/Compute/v2/Models/Keypair.php b/src/Compute/v2/Models/Keypair.php
index f5c37c763..8584be847 100644
--- a/src/Compute/v2/Models/Keypair.php
+++ b/src/Compute/v2/Models/Keypair.php
@@ -40,7 +40,11 @@ class Keypair extends OperatorResource implements Listable, Retrievable, Deletab
/** @var string */
public $type;
- /** @var string */
+ /**
+ * @var string
+ *
+ * @deprecated Left for backward compatibility only. It is not retrieved from the API.
+ */
public $id;
/** @var \DateTimeImmutable */
diff --git a/src/Compute/v2/Models/Server.php b/src/Compute/v2/Models/Server.php
index 96a88b126..a9e25cbd9 100644
--- a/src/Compute/v2/Models/Server.php
+++ b/src/Compute/v2/Models/Server.php
@@ -185,7 +185,7 @@ public function resetState()
*/
public function reboot(string $type = Enum::REBOOT_SOFT)
{
- if (!in_array($type, ['SOFT', 'HARD'])) {
+ if (!in_array($type, [Enum::REBOOT_SOFT, Enum::REBOOT_HARD])) {
throw new \RuntimeException('Reboot type must either be SOFT or HARD');
}
@@ -458,8 +458,6 @@ public function resetMetadata(array $metadata)
* existing keys will remain unaffected.
*
* @param array $metadata {@see \OpenStack\Compute\v2\Api::postServerMetadata}
- *
- * @return array
*/
public function mergeMetadata(array $metadata)
{
diff --git a/src/Compute/v2/Service.php b/src/Compute/v2/Service.php
index 05e7149ee..8090d8d0d 100644
--- a/src/Compute/v2/Service.php
+++ b/src/Compute/v2/Service.php
@@ -114,8 +114,8 @@ public function createFlavor(array $options = []): Flavor
/**
* List images.
*
- * @param array $options {@see \OpenStack\Compute\v2\Api::getImages}
- * @param callable $mapFn a callable function that will be invoked on every iteration of the list
+ * @param array $options {@see \OpenStack\Compute\v2\Api::getImages}
+ * @param callable|null $mapFn a callable function that will be invoked on every iteration of the list
*
* @return \Generator
*/
diff --git a/src/Identity/v3/Api.php b/src/Identity/v3/Api.php
index cd664668d..8f07da58d 100644
--- a/src/Identity/v3/Api.php
+++ b/src/Identity/v3/Api.php
@@ -555,6 +555,7 @@ public function patchUser(): array
'description' => $this->params->desc('user'),
'email' => $this->params->email(),
'enabled' => $this->params->enabled('user'),
+ 'name' => $this->params->name('user'),
'password' => $this->params->password(),
],
];
diff --git a/src/Identity/v3/Models/Token.php b/src/Identity/v3/Models/Token.php
index 6794b7f8a..7a7c23f2e 100644
--- a/src/Identity/v3/Models/Token.php
+++ b/src/Identity/v3/Models/Token.php
@@ -5,6 +5,7 @@
namespace OpenStack\Identity\v3\Models;
use InvalidArgumentException;
+use OpenStack\Common\Error\BadResponseError;
use OpenStack\Common\Resource\Alias;
use OpenStack\Common\Resource\Creatable;
use OpenStack\Common\Resource\OperatorResource;
@@ -130,4 +131,20 @@ public function export(): array
{
return $this->cachedToken;
}
+
+ /**
+ * Checks if the token is valid.
+ *
+ * @return bool TRUE if the token is valid; FALSE otherwise
+ */
+ public function validate(): bool
+ {
+ try {
+ $this->execute($this->api->headTokens(), ['tokenId' => $this->id]);
+
+ return true;
+ } catch (BadResponseError $e) {
+ return false;
+ }
+ }
}
diff --git a/tests/integration/BlockStorage/v2/CoreTest.php b/tests/integration/BlockStorage/v2/CoreTest.php
deleted file mode 100644
index 41b47a81d..000000000
--- a/tests/integration/BlockStorage/v2/CoreTest.php
+++ /dev/null
@@ -1,29 +0,0 @@
-service) {
- $this->service = Utils::getOpenStack()->blockStorageV2();
- }
-
- return $this->service;
- }
-
- protected function sampleFile($path, array $replacements = [])
- {
- return parent::sampleFile(
- '../v3/' . $path,
- array_merge(
- $replacements,
- ['$openstack->blockStorageV3()' => '$openstack->blockStorageV2()']
- ));
- }
-}
diff --git a/tests/integration/BlockStorage/v3/CoreV2Test.php b/tests/integration/BlockStorage/v3/CoreV2Test.php
deleted file mode 100644
index a60884eea..000000000
--- a/tests/integration/BlockStorage/v3/CoreV2Test.php
+++ /dev/null
@@ -1,252 +0,0 @@
-service) {
- $this->service = Utils::getOpenStack()->blockStorageV3();
- }
-
- return $this->service;
- }
-
- public function runTests()
- {
- $this->startTimer();
-
- $this->logger->info('-> Volumes');
- $this->volumes();
- $this->logger->info('-> Volume Types');
- $this->volumeTypes();
- $this->logger->info('-> Snapshots');
- $this->snapshots();
- $this->logger->info('-> Snapshot list');
- $this->snapshotList();
-
- $this->outputTimeTaken();
- }
-
- public function volumes()
- {
- $this->logStep('Creating volume type');
- $volumeType = $this->getService()->createVolumeType(['name' => $this->randomStr()]);
-
- $replacements = [
- '{description}' => $this->randomStr(),
- "'{size}'" => 1,
- '{name}' => $this->randomStr(),
- '{volumeType}' => $volumeType->id,
- '{key1}' => $this->randomStr(),
- '{val1}' => $this->randomStr(),
- ];
-
- $this->logStep('Creating volume');
- /** @var Volume $volume */
- require_once $this->sampleFile('volumes/create.php', $replacements);
- self::assertInstanceOf(Volume::class, $volume);
- self::assertEquals($replacements['{name}'], $volume->name);
- self::assertEquals(1, $volume->size);
- self::assertEquals($volumeType->name, $volume->volumeTypeName);
-
- $volumeId = $volume->id;
- $replacements = ['{volumeId}' => $volumeId];
-
- $this->logStep('Getting volume');
- /** @var Volume $volume */
- require_once $this->sampleFile('volumes/get.php', $replacements);
- self::assertInstanceOf(Volume::class, $volume);
-
- $replacements += [
- '{newName}' => $this->randomStr(),
- '{newDescription}' => $this->randomStr(),
- ];
-
- $this->logStep('Updating volume');
- /** @var Volume $volume */
- require_once $this->sampleFile('volumes/update.php', $replacements);
- self::assertInstanceOf(Volume::class, $volume);
-
- $this->logStep('Listing volumes');
- /** @var \Generator $volumes */
- require_once $this->sampleFile('volumes/list.php', $replacements);
-
- $volume = $this->getService()->getVolume($volumeId);
- $volume->waitUntil('available');
-
- $this->logStep('Deleting volume');
- require_once $this->sampleFile('volumes/delete.php', $replacements);
-
- $volume = $this->getService()->getVolume($volumeId);
- $volume->waitUntilDeleted();
-
- $this->logStep('Deleting volume type');
- $volumeType->delete();
- }
-
- public function volumeTypes()
- {
- $replacements = [
- '{name}' => $this->randomStr(),
- ];
-
- $this->logStep('Creating volume type');
- /** @var VolumeType $volumeType */
- require_once $this->sampleFile('volume_types/create.php', $replacements);
- self::assertInstanceOf(VolumeType::class, $volumeType);
- self::assertEquals($replacements['{name}'], $volumeType->name);
-
- $replacements = ['{volumeTypeId}' => $volumeType->id];
-
- $this->logStep('Getting volume type');
- /** @var VolumeType $volumeType */
- require_once $this->sampleFile('volume_types/get.php', $replacements);
- self::assertInstanceOf(VolumeType::class, $volumeType);
-
- $replacements += ['{newName}' => $this->randomStr()];
-
- $this->logStep('Updating volume type');
- /** @var VolumeType $volumeType */
- require_once $this->sampleFile('volume_types/update.php', $replacements);
- self::assertInstanceOf(VolumeType::class, $volumeType);
-
- $this->logStep('Listing volume types');
- /** @var \Generator $volumeTypes */
- require_once $this->sampleFile('volume_types/list.php', $replacements);
-
- $this->logStep('Deleting volume type');
- require_once $this->sampleFile('volume_types/delete.php', $replacements);
- }
-
- public function snapshots()
- {
- $this->logStep('Creating volume');
- $volume = $this->getService()->createVolume(['name' => $this->randomStr(), 'size' => 1]);
- $volume->waitUntil('available', 60);
-
- $replacements = [
- '{volumeId}' => $volume->id,
- '{name}' => $this->randomStr(),
- '{description}' => $this->randomStr(),
- ];
-
- $this->logStep('Creating snapshot');
- /** @var Snapshot $snapshot */
- require_once $this->sampleFile('snapshots/create.php', $replacements);
- self::assertInstanceOf(Snapshot::class, $snapshot);
- self::assertEquals($replacements['{name}'], $snapshot->name);
- $volume->waitUntil('available', 60);
-
- $snapshotId = $snapshot->id;
- $replacements = ['{snapshotId}' => $snapshotId];
-
- $this->logStep('Getting snapshot');
- /** @var Snapshot $snapshot */
- require_once $this->sampleFile('snapshots/get.php', $replacements);
- self::assertInstanceOf(Snapshot::class, $snapshot);
-
- $this->getService()
- ->getSnapshot($snapshot->id)
- ->mergeMetadata(['key1' => 'val1']);
-
- $replacements += ['{key}' => 'key2', '{val}' => 'val2'];
- $this->logStep('Adding metadata');
- require_once $this->sampleFile('snapshots/merge_metadata.php', $replacements);
-
- $this->logStep('Retrieving metadata');
- /** @var array $metadata */
- require_once $this->sampleFile('snapshots/get_metadata.php', $replacements);
- self::assertEquals(['key1' => 'val1', 'key2' => 'val2'], $metadata);
-
- $replacements = ['{snapshotId}' => $snapshot->id, '{key}' => 'key3', '{val}' => 'val3'];
- $this->logStep('Resetting metadata');
- require_once $this->sampleFile('snapshots/reset_metadata.php', $replacements);
-
- $this->logStep('Retrieving metadata');
- /** @var array $metadata */
- require_once $this->sampleFile('snapshots/get_metadata.php', $replacements);
- self::assertEquals(['key3' => 'val3'], $metadata);
-
- $replacements += ['{newName}' => $this->randomStr(), '{newDescription}' => $this->randomStr()];
- $this->logStep('Updating snapshot');
- require_once $this->sampleFile('snapshots/update.php', $replacements);
-
- $snapshot->waitUntil('available', 60);
-
- $this->logStep('Listing snapshots');
- require_once $this->sampleFile('snapshots/list.php', $replacements);
-
- $this->logStep('Deleting snapshot');
- require_once $this->sampleFile('snapshots/delete.php', $replacements);
- $snapshot->waitUntilDeleted();
-
- $this->logStep('Deleting volume');
- $volume->delete();
- }
-
- public function snapshotList()
- {
- $this->logStep('Creating volume');
- $volume = $this->getService()->createVolume(['name' => $this->randomStr(), 'size' => 1]);
- $volume->waitUntil('available', 60);
-
- $names = ['b' . $this->randomStr(), 'a' . $this->randomStr(), 'd' . $this->randomStr(), 'c' . $this->randomStr()];
- $createdSnapshots = [];
- foreach ($names as $name) {
- $this->logStep('Creating snapshot ' . $name);
- $snapshot = $this->getService()->createSnapshot([
- 'volumeId' => $volume->id,
- 'name' => $name,
- ]);
-
- self::assertInstanceOf(Snapshot::class, $snapshot);
-
- $createdSnapshots[] = $snapshot;
- $snapshot->waitUntil('available', 60);
- }
-
- try {
- $replacements = [
- '{sortKey}' => 'display_name',
- '{sortDir}' => 'asc',
- ];
-
- $this->logStep('Listing snapshots');
- require_once $this->sampleFile('snapshots/list.php', $replacements);
-
- $this->logStep('Listing snapshots sorted asc');
- /** @var Snapshot $snapshot */
- require_once $this->sampleFile('snapshots/list_sorted.php', $replacements);
- self::assertInstanceOf(Snapshot::class, $snapshot);
- self::assertEquals($names[2], $snapshot->name);
-
- $this->logStep('Listing snapshots sorted desc');
- $replacements['{sortDir}'] = 'desc';
- /** @var Snapshot $snapshot */
- require_once $this->sampleFile('snapshots/list_sorted.php', $replacements);
- self::assertInstanceOf(Snapshot::class, $snapshot);
- self::assertEquals($names[1], $snapshot->name);
- } finally {
- foreach ($createdSnapshots as $snapshot) {
- $this->logStep('Deleting snapshot ' . $snapshot->name);
- $snapshot->delete();
- $snapshot->waitUntilDeleted();
- }
-
- $this->logStep('Deleting volume');
- $volume->delete();
- }
- }
-
-}
\ No newline at end of file
diff --git a/tests/integration/Compute/v2/CoreTest.php b/tests/integration/Compute/v2/CoreTest.php
deleted file mode 100644
index 4bb035fd8..000000000
--- a/tests/integration/Compute/v2/CoreTest.php
+++ /dev/null
@@ -1,757 +0,0 @@
-service) {
- $this->service = Utils::getOpenStack()->computeV2();
- }
-
- return $this->service;
- }
-
- private function getNetworkService() : \OpenStack\Networking\v2\Service
- {
- if (!$this->networkService) {
- $this->networkService = Utils::getOpenStack()->networkingV2();
- }
-
- return $this->networkService;
- }
-
- private function getSecurityGroupService(): SecurityGroupService
- {
- $this->secgroupService = $this->secgroupService ?? Utils::getOpenStack()->networkingV2ExtSecGroups();
- return $this->secgroupService;
- }
-
- private function getBlockStorageService()
- {
- if (!$this->blockStorageService) {
- $this->blockStorageService = Utils::getOpenStack()->blockStorageV3();
- }
-
- return $this->blockStorageService;
- }
-
- private function searchImages($name)
- {
- foreach ($this->getService()->listImages() as $image) {
- if (strpos($image->name, $name) !== false) {
- $this->imageId = $image->id;
- break;
- }
- }
-
- if (!$this->imageId) {
- throw new RuntimeException(sprintf('Unable to find image "%s". Make sure this image is available for integration test.', $name));
- }
- }
-
- protected function setUp(): void
- {
- $this->network = $this->getNetworkService()->createNetwork(
- [
- 'name' => self::NETWORK,
- 'adminStateUp' => true,
- ]
- );
-
- $this->logStep('Created network {name} with {id}', ['name' => $this->network->name, 'id' => $this->network->id]);
-
- $this->subnet = $this->getNetworkService()->createSubnet(
- [
- 'name' => self::SUBNET,
- 'networkId' => $this->network->id,
- 'ipVersion' => 4,
- 'cidr' => '10.20.30.0/24',
- ]
- );
-
- $this->logStep('Created subnet {name} with {id}', ['name' => $this->subnet->name, 'id' => $this->subnet->id]);
-
- $this->volume = $this->getBlockStorageService()->createVolume(
- [
- 'name' => self::VOLUME,
- 'description' => '',
- 'size' => 1
- ]
- );
-
- $this->logStep('Created volume {name} with {id}', ['name' => $this->volume->name, 'id' => $this->volume->id]);
-
- $this->secgroup = $this->getSecurityGroupService()->createSecurityGroup(['name' => self::SECGROUP]);
-
- $this->logStep('Created security group {secgroup}', ['secgroup' => self::SECGROUP]);
- }
-
- public function runTests()
- {
- $this->startTimer();
-
- // Manually trigger setUp
- $this->setUp();
-
- $this->searchImages(self::IMAGE);
-
- // Servers
- $this->createServer();
-
- try {
- $this->updateServer();
- $this->retrieveServer();
- $this->serverMetadata();
-
- // Server actions
- //$this->changeServerPassword();
- $this->stopServer();
- $this->startServer();
- $this->resizeServer();
- $this->confirmServerResize();
- $this->rebuildServer();
- $this->rescueServer();
- $this->createServerImage();
- $this->rebootServer();
-
- // Security groups
- $this->addSecurityGroupToServer();
- $this->listServerSecurityGroups();
- $this->removeServerSecurityGroup();
-
- // Volume attachments
- $this->attachVolumeToServer();
- $this->listVolumeAttachmentsForServer();
- $this->detachVolumeFromServer();
-
- // Flavors
- $this->createFlavor();
- $this->listFlavors();
- $this->getFlavor();
-
- // Images
- $this->listImages();
- $this->getImage();
- $this->imageMetadata();
- $this->deleteServerImage();
-
- // Keypairs
- $this->listKeypairs();
- $this->createKeypair();
- $this->getKeypair();
- $this->deleteKeypair();
-
- // Limits
- $this->getLimits();
-
- // Hypervisors
- $this->listHypervisors();
- $this->getHypervisorsStatistics();
- $this->getHypervisor();
-
- // Console
- $this->getVncConsole();
-
- // Interface attachments
- $this->createInterfaceAttachment();
- } finally {
- $this->logger->info('Tearing down');
- // Teardown
- $this->deleteServer();
- $this->deleteFlavor();
- $this->subnet->delete();
- $this->network->delete();
- $this->volume->delete();
- $this->secgroup->delete();
- }
-
- $this->outputTimeTaken();
- }
-
- private function createServer()
- {
- $flavorId = getenv('OS_FLAVOR');
-
- if (!$flavorId) {
- throw new RuntimeException('OS_FLAVOR env var must be set');
- }
-
- $replacements = [
- '{serverName}' => $this->randomStr(),
- '{imageId}' => $this->imageId,
- '{flavorId}' => $flavorId,
- '{networkId}' => $this->network->id
- ];
-
- /** @var $server \OpenStack\Compute\v2\Models\Server */
- require_once $this->sampleFile('servers/create_server.php', $replacements);
-
- $server->waitUntilActive();
-
- self::assertInstanceOf('OpenStack\Compute\v2\Models\Server', $server);
- self::assertNotEmpty($server->id);
- self::assertNotEmpty($server->adminPass);
-
- $this->serverId = $server->id;
- $this->adminPass = $server->adminPass;
-
- $this->logStep('Created server {id}', ['{id}' => $server->id]);
- }
-
- private function updateServer()
- {
- $name = $this->randomStr();
-
- $replacements = [
- '{serverId}' => $this->serverId,
- '{newName}' => $name,
- ];
-
- /** @var $server \OpenStack\Compute\v2\Models\Server */
- require_once $this->sampleFile('servers/update_server.php', $replacements);
-
- self::assertInstanceOf('OpenStack\Compute\v2\Models\Server', $server);
- self::assertEquals($name, $server->name);
-
- $server->waitUntilActive(false);
-
- $this->logStep('Updated server ID to use this name: NAME', ['ID' => $this->serverId, 'NAME' => $name]);
- }
-
- private function deleteServer()
- {
- $replacements = ['{serverId}' => $this->serverId];
-
- /** @var $server \OpenStack\Compute\v2\Models\Server */
- require_once $this->sampleFile('servers/delete_server.php', $replacements);
-
- // Needed so that subnet and network can be removed
- $server->waitUntilDeleted();
- $this->logStep('Deleted server ID', ['ID' => $this->serverId]);
- }
-
- private function retrieveServer()
- {
- $replacements = ['{serverId}' => $this->serverId];
-
- /** @var $server \OpenStack\Compute\v2\Models\Server */
- require_once $this->sampleFile('servers/get_server.php', $replacements);
-
- self::assertInstanceOf('OpenStack\Compute\v2\Models\Server', $server);
- self::assertEquals($this->serverId, $server->id);
- self::assertNotNull($server->created);
- self::assertNotNull($server->updated);
- self::assertNotNull($server->name);
- self::assertNotNull($server->ipv4);
- self::assertNotNull($server->status);
- self::assertInstanceOf(Image::class, $server->image);
- self::assertInstanceOf(Flavor::class, $server->flavor);
-
- $this->logStep('Retrieved the details of server ID', ['ID' => $this->serverId]);
- }
-
- private function serverMetadata()
- {
- $replacements = ['{serverId}' => $this->serverId];
-
- /** @var $server \OpenStack\Compute\v2\Models\Server */
- require_once $this->sampleFile('servers/reset_server_metadata.php', $replacements);
- $this->logStep('Reset metadata of server {serverId}', $replacements);
-
- require_once $this->sampleFile('servers/get_server_metadata.php', $replacements);
- $this->logStep('Retrieved metadata of server {serverId}', $replacements);
-
- require_once $this->sampleFile('servers/delete_server_metadata_item.php', $replacements);
- $this->logStep('Deleted metadata key of server {serverId}', $replacements);
- }
-
- private function changeServerPassword()
- {
- $this->adminPass = $this->randomStr();
-
- $replacements = [
- '{serverId}' => $this->serverId,
- '{newPassword}' => $this->adminPass,
- ];
-
- require_once $this->sampleFile('servers/change_server_password.php', $replacements);
-
- $this->logStep('Changed root password of server {serverId} to {newPassword}', $replacements);
- }
-
- private function resizeServer()
- {
- $resizeFlavorId = getenv('OS_RESIZE_FLAVOR');
- if (!$resizeFlavorId) {
- throw new RuntimeException('OS_RESIZE_FLAVOR env var must be set');
- }
-
- $replacements = [
- '{serverId}' => $this->serverId,
- '{flavorId}' => $resizeFlavorId,
- ];
-
- /** @var $server \OpenStack\Compute\v2\Models\Server */
- require_once $this->sampleFile('servers/resize_server.php', $replacements);
-
- $server->waitUntil('VERIFY_RESIZE');
-
- $this->logStep('Resized server {serverId} to flavor {flavorId}', $replacements);
- }
-
- private function confirmServerResize()
- {
- $this->logger->info('Waiting for status VERIFY_RESIZE');
- $replacements = ['{serverId}' => $this->serverId];
-
- /** @var $server \OpenStack\Compute\v2\Models\Server */
- require_once $this->sampleFile('servers/confirm_server_resize.php', $replacements);
-
- $server->waitUntilActive();
-
- $this->logStep('Confirmed resize of server {serverId}', $replacements);
- }
-
- private function rebuildServer()
- {
- $replacements = [
- '{serverId}' => $this->serverId,
- '{imageId}' => $this->imageId,
- '{adminPass}' => $this->adminPass,
- ];
-
- /** @var $server \OpenStack\Compute\v2\Models\Server */
- require_once $this->sampleFile('servers/rebuild_server.php', $replacements);
-
- $server->waitUntilActive();
-
- $this->logStep('Rebuilt server {serverId}', $replacements);
- }
-
- private function rescueServer()
- {
- $replacements = [
- '{serverId}' => $this->serverId,
- '{imageId}' => $this->imageId,
- '{adminPass}' => $this->adminPass,
- ];
-
- /** @var $server \OpenStack\Compute\v2\Models\Server */
- require_once $this->sampleFile('servers/rescue_server.php', $replacements);
-
- $server->waitUntil('RESCUE');
-
- require_once $this->sampleFile('servers/unrescue_server.php', $replacements);
-
- $server->waitUntilActive();
-
- $this->logStep('Rescued server {serverId}', $replacements);
- }
-
- private function rebootServer()
- {
- $replacements = ['{serverId}' => $this->serverId];
-
- /** @var $server \OpenStack\Compute\v2\Models\Server */
- require_once $this->sampleFile('servers/reboot_server.php', $replacements);
-
- $server->waitUntilActive();
-
- $this->logStep('Rebooted server {serverId}', $replacements);
- }
-
- private function stopServer()
- {
- $replacements = ['{serverId}' => $this->serverId];
-
- /** @var $server \OpenStack\Compute\v2\Models\Server */
- require_once $this->sampleFile('servers/stop_server.php', $replacements);
-
- $server->waitUntil('SHUTOFF', false);
-
- $this->logStep('Stopped server {serverId}', $replacements);
- }
-
- private function startServer()
- {
- $replacements = ['{serverId}' => $this->serverId];
-
- /** @var $server \OpenStack\Compute\v2\Models\Server */
- require_once $this->sampleFile('servers/start_server.php', $replacements);
-
- $server->waitUntilActive();
-
- $this->logStep('Started server {serverId}', $replacements);
- }
-
- private function createFlavor()
- {
- $replacements = [
- '{flavorName}' => $this->randomStr()
- ];
-
- /** @var $flavor \OpenStack\Compute\v2\Models\Flavor */
- require_once $this->sampleFile('flavors/create_flavor.php', $replacements);
-
- self::assertInstanceOf('\OpenStack\Compute\v2\Models\Flavor', $flavor);
-
- $this->flavorId = $flavor->id;
- $this->logStep('Created flavor {id}', ['{id}' => $flavor->id]);
- }
-
- private function deleteFlavor()
- {
- $replacements = ['{flavorId}' => $this->flavorId];
-
- require_once $this->sampleFile('flavors/delete_flavor.php', $replacements);
-
- $this->logStep('Deleted flavor ID', ['ID' => $this->flavorId]);
- }
-
- private function listFlavors()
- {
- require_once $this->sampleFile('flavors/list_flavors.php', []);
-
- $this->logStep('Listed all available flavors');
- }
-
- private function getFlavor()
- {
- $replacements = ['{flavorId}' => 1];
-
- require_once $this->sampleFile('flavors/get_flavor.php', $replacements);
-
- $this->logStep('Retrieved details for flavor {flavorId}', $replacements);
- }
-
- private function createServerImage()
- {
- $name = $this->randomStr();
-
- $replacements = [
- '{serverId}' => $this->serverId,
- '{imageName}' => $name,
- ];
-
- /** @var $server \OpenStack\Compute\v2\Models\Server */
- require_once $this->sampleFile('images/create_server_image.php', $replacements);
-
- $server->waitWithCallback(function (Server $server) {
- return !$server->taskState;
- }, false);
-
- $this->searchImages($name);
-
- $this->logStep('Created an image for server {serverId} with name {imageName}', $replacements);
- }
-
- private function listImages()
- {
- require_once $this->sampleFile('images/list_images.php', []);
-
- $this->logStep('Listed all available images');
- }
-
- private function getImage()
- {
- $replacements = ['{imageId}' => $this->imageId];
-
- require_once $this->sampleFile('images/get_image.php', $replacements);
-
- $this->logStep('Retrieved details for image {imageId}', $replacements);
- }
-
- private function imageMetadata()
- {
- $replacements = ['{imageId}' => $this->imageId];
-
- /** @var $image \OpenStack\Compute\v2\Models\Image */
- require_once $this->sampleFile('images/reset_image_metadata.php', $replacements);
- $this->logStep('Reset metadata of image {imageId}', $replacements);
-
- require_once $this->sampleFile('images/retrieve_image_metadata.php', $replacements);
- $this->logStep('Retrieved metadata of image {imageId}', $replacements);
-
- require_once $this->sampleFile('images/delete_image_metadata_item.php', $replacements + ['{metadataKey}']);
- $this->logStep('Deleted metadata key of image {imageId}', $replacements);
- }
-
- private function deleteServerImage()
- {
- $replacements = ['{imageId}' => $this->imageId];
- require_once $this->sampleFile('images/delete_image.php', $replacements);
- $this->logStep('Deleted image {imageId}', $replacements);
- }
-
- private function listKeypairs()
- {
- /** @var $keypairs \Generator */
- require_once $this->sampleFile('keypairs/list_keypairs.php', []);
-
- self::assertInstanceOf(\Generator::class, $keypairs);
-
- $this->logStep('Listed all keypairs');
- }
-
- private function createKeypair()
- {
- $replacements = [
- '{name}' => $this->randomStr(),
- '{publicKey}' => 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCp4H/vDGnLi0QgWgMsQkv//FEz0xgv/mujVX+XCh6fHXxc/PbaASY+MsoI2Xr238cG9eaeAAUvbpJuEuHQ0M9WX97bvsWaWzLQ9F6hzLAwUBGxcG8cSh1nB3Ah7alR2nbIZ1N94yE72hXLb1AGogJ97NBVIph438BCXUNejqoOBsXL8UBP3RGdPnTHJ/6XSMaNTQAJruQMoQwecyGFQmuS2IEy2mBOmSldD6JZirHpj7PTCKJY4CS89QChGpKIeOymKn4tEQQVVtNFUyULEMdin88H1yMftPfq7QqH+ULFT2X2XvP3CI+sESq84lrIcVu7LjJCRIwlKsnMu2ESYCdz foo@bar.com'
- ];
-
- require_once $this->sampleFile('keypairs/create_keypair.php', $replacements);
- /**@var Keypair $keypair */
-
- self::assertInstanceOf(Keypair::class, $keypair);
- self::assertEquals($replacements['{name}'], $keypair->name);
- self::assertEquals($replacements['{publicKey}'], $keypair->publicKey);
-
- $this->keypairName = $keypair->name;
- $this->logStep('Created keypair name {name}', ['{name}' => $keypair->name]);
- }
-
- private function getKeypair()
- {
- $replacements = [
- '{name}' => $this->keypairName,
- ];
-
- require_once $this->sampleFile('keypairs/get_keypair.php', $replacements);
-
- /**@var Keypair $keypair */
- self::assertInstanceOf(Keypair::class, $keypair);
-
- self::assertEquals($replacements['{name}'], $keypair->name);
-
- $this->logStep('Retrieved details for keypair {name}', $replacements);
- }
-
- private function deleteKeypair()
- {
- $replacements = [
- '{name}' => $this->keypairName,
- ];
-
- require_once $this->sampleFile('keypairs/delete_keypair.php', $replacements);
- $this->logStep('Deleted keypair name {name}', ['{name}' => $this->keypairName]);
- }
-
- private function listHypervisors()
- {
- require_once $this->sampleFile('hypervisors/list_hypervisors.php', []);
-
- $this->logStep('Listed all available hypervisors');
- }
-
- private function getHypervisor()
- {
- $replacements = [
- '{hypervisorId}' => '1',
- ];
-
- require_once $this->sampleFile('hypervisors/get_hypervisor.php', $replacements);
-
- /**@var Hypervisor $hypervisor */
- self::assertInstanceOf(Hypervisor::class, $hypervisor);
- self::assertEquals($replacements['{hypervisorId}'], $hypervisor->id);
-
- $this->logStep('Retrieved details for hypervisor id {hypervisorId}', $replacements);
- }
-
- private function getHypervisorsStatistics()
- {
- require_once $this->sampleFile('hypervisors/get_hypervisors_statistics.php', []);
-
- /**@var HypervisorStatistic $hypervisorStatistics */
- self::assertInstanceOf(HypervisorStatistic::class, $hypervisorStatistics);
-
- $this->logStep('Retrieved hypervisors statistics');
- }
-
- private function getLimits()
- {
- require_once $this->sampleFile('limits/get_limits.php', []);
-
- /**@var Limit $limit */
- self::assertInstanceOf(Limit::class, $limit);
-
- $this->logStep('Retrieved tenant limit');
- }
-
- private function addSecurityGroupToServer()
- {
- $replacements = [
- '{serverId}' => $this->serverId,
- '{secGroupName}' => self::SECGROUP,
- ];
-
- require_once $this->sampleFile('servers/add_security_group.php', $replacements);
-
- /**@var Server $server*/
- $this->logStep('Added security group {secGroupName} to server {serverId}', $replacements);
- }
-
- private function listServerSecurityGroups()
- {
- $replacements = [
- '{serverId}' => $this->serverId
- ];
-
- require_once $this->sampleFile('servers/list_security_groups.php', $replacements);
-
- /**@var \Generator $securityGroups */
- self::assertInstanceOf(\Generator::class, $securityGroups);
-
- $this->logStep('Listed all security groups attached to server {serverId}', $replacements);
- }
-
- private function removeServerSecurityGroup()
- {
- $replacements = [
- '{serverId}' => $this->serverId,
- '{secGroupName}' => self::SECGROUP,
- ];
-
- require_once $this->sampleFile('servers/remove_security_group.php', $replacements);
-
- $this->logStep(/** @lang text */ 'Delete security group {secGroupName} from server {serverId}', $replacements);
- }
-
- private function attachVolumeToServer()
- {
- $replacements = [
- '{serverId}' => $this->serverId,
- '{volumeId}' => $this->volume->id
- ];
-
- require_once $this->sampleFile('servers/attach_volume_attachment.php', $replacements);
- /** @var \OpenStack\BlockStorage\v2\Models\VolumeAttachment $volumeAttachment */
- $this->volumeAttachmentId = $volumeAttachment->id;
-
- $this->volume->waitUntil('in-use');
-
- $this->logStep(
- 'Attached volume {volumeId} to server {serverId} with volume attachment id {volumeAttachmentId}',
- array_merge($replacements, ['{volumeAttachmentId}' => $volumeAttachment->id])
- );
- }
-
- private function listVolumeAttachmentsForServer()
- {
- $replacements = [
- '{serverId}' => $this->serverId
- ];
-
- require_once $this->sampleFile('servers/list_volume_attachments.php', $replacements);
-
- $this->logStep('Retrieved volume attachments for server {serverId}', $replacements);
- }
-
- private function detachVolumeFromServer()
- {
- $replacements = [
- '{serverId}' => $this->serverId,
- '{volumeAttachmentId}' => $this->volumeAttachmentId,
- ];
-
- require_once $this->sampleFile('servers/detach_volume_attachment.php', $replacements);
-
- $this->volume->waitUntil('available');
-
- $this->logStep('Detached volume attachments for server {serverId}', $replacements);
- }
-
- private function getVncConsole()
- {
- $replacements = [
- '{serverId}' => $this->serverId
- ];
-
- require_once $this->sampleFile('servers/get_server_vnc_console.php', $replacements);
-
- $this->logStep('Get VNC console for server {serverId}', $replacements);
- }
-
- private function createInterfaceAttachment()
- {
- $replacements = [
- '{serverId}' => $this->serverId,
- '{networkId}' => $this->network->id
- ];
-
- require_once $this->sampleFile('servers/create_interface_attachment.php', $replacements);
-
- $this->logStep('Create interface attachment for server {serverId}', $replacements);
- }
-
- private function getConsoleOutput()
- {
- $replacements = [
- '{serverId}' => $this->serverId
- ];
-
- require_once $this->sampleFile('servers/get_server_console_output.php', $replacements);
-
- $this->logStep('Get console output for server {serverId}', $replacements);
- }
-}
diff --git a/tests/integration/Identity/v2/CoreTest.php b/tests/integration/Identity/v2/CoreTest.php
deleted file mode 100644
index 39045dad9..000000000
--- a/tests/integration/Identity/v2/CoreTest.php
+++ /dev/null
@@ -1,12 +0,0 @@
-service) {
- $this->service = Utils::getOpenStack()->identityV3();
- }
-
- return $this->service;
- }
-
- public function runTests()
- {
- $this->startTimer();
-
- $this->logger->info('-> Generate token');
- $this->token();
-
- $this->outputTimeTaken();
- }
-
- public function token()
- {
- $this->logStep('Create application credential');
-
- $name = $this->randomStr();
- $description = $this->randomStr();
-
- /** @var $applicationCredential \OpenStack\Identity\v3\Models\ApplicationCredential */
- require_once $this->sampleFile(
- 'application_credentials/add_application_credential.php',
- [
- '{name}' => $name,
- '{description}' => $description,
- ]
- );
- self::assertInstanceOf(Models\ApplicationCredential::class, $applicationCredential);
- self::assertEquals($name, $applicationCredential->name);
- self::assertEquals($description, $applicationCredential->description);
-
- $this->logStep('Create token with id');
-
- /** @var $token \OpenStack\Identity\v3\Models\Token */
- require_once $this->sampleFile(
- 'tokens/generate_token_with_application_credential_id.php',
- [
- '{applicationCredentialId}' => $applicationCredential->id,
- '{secret}' => $applicationCredential->secret
- ]
- );
- self::assertInstanceOf(Models\Token::class, $token);
-
- /** @var $result bool */
- require_once $this->sampleFile('tokens/validate_token.php', ['{tokenId}' => $token->id]);
- self::assertTrue($result);
-
-
- $this->logStep('Retrieve application credential');
- $applicationCredentialId = $applicationCredential->id;
- $applicationCredential = null;
-
- /** @var $applicationCredential \OpenStack\Identity\v3\Models\ApplicationCredential */
- require_once $this->sampleFile(
- 'application_credentials/show_application_credential.php',
- ['{applicationCredentialId}' => $applicationCredentialId]
- );
- self::assertInstanceOf(Models\ApplicationCredential::class, $applicationCredential);
- self::assertEquals($name, $applicationCredential->name);
- self::assertEquals($description, $applicationCredential->description);
-
-
- $this->logStep('Delete application credential');
- require_once $this->sampleFile(
- 'application_credentials/delete_application_credential.php',
- [
- '{applicationCredentialId}' => $applicationCredential->id,
- ]
- );
-
- /** @var $result bool */
- require_once $this->sampleFile('tokens/validate_token.php', ['{tokenId}' => $token->id]);
- self::assertFalse($result);
- }
-}
\ No newline at end of file
diff --git a/tests/integration/Identity/v3/CoreTest.php b/tests/integration/Identity/v3/CoreTest.php
deleted file mode 100644
index 1e92c45b2..000000000
--- a/tests/integration/Identity/v3/CoreTest.php
+++ /dev/null
@@ -1,392 +0,0 @@
-service) {
- $this->service = Utils::getOpenStack()->identityV3();
- }
-
- return $this->service;
- }
-
- public function runTests()
- {
- $this->startTimer();
-
- $this->logger->info('-> Tokens');
- $this->tokens();
-
- $this->logger->info('-> Domains');
- $this->domains();
-
- $this->logger->info('-> Endpoints');
- $this->endpoints();
-
- $this->logger->info('-> Services');
- $this->services();
-
- $this->logger->info('-> Groups');
- $this->groups();
-
- $this->logger->info('-> Projects');
- $this->projects();
-
- $this->logger->info('-> Roles');
- $this->roles();
-
- $this->logger->info('-> Users');
- $this->users();
-
- $this->outputTimeTaken();
- }
-
- public function tokens()
- {
- $this->logStep('Generate token with user name');
-
- /** @var $token \OpenStack\Identity\v3\Models\Token */
- require_once $this->sampleFile('tokens/generate_token_with_username.php');
- self::assertInstanceOf(Models\Token::class, $token);
-
- /** @var $result bool */
- require_once $this->sampleFile('tokens/validate_token.php', ['{tokenId}' => $token->id]);
- self::assertTrue($result);
-
-
- $this->logStep('Generate token with user id');
-
- /** @var $token \OpenStack\Identity\v3\Models\Token */
- require_once $this->sampleFile('tokens/generate_token_with_user_id.php');
- self::assertInstanceOf(Models\Token::class, $token);
-
- /** @var $result bool */
- require_once $this->sampleFile('tokens/validate_token.php', ['{tokenId}' => $token->id]);
- self::assertTrue($result);
-
-
- $this->logStep('Generate token scoped to project id');
- /** @var $token \OpenStack\Identity\v3\Models\Token */
- require_once $this->sampleFile('tokens/generate_token_scoped_to_project_id.php');
- self::assertInstanceOf(Models\Token::class, $token);
-
- /** @var $result bool */
- require_once $this->sampleFile('tokens/validate_token.php', ['{tokenId}' => $token->id]);
- self::assertTrue($result);
-
-
- $this->logStep('Generate token scoped to project name');
-
- /** @var $token \OpenStack\Identity\v3\Models\Token */
- require_once $this->sampleFile('tokens/generate_token_scoped_to_project_name.php');
- self::assertInstanceOf(Models\Token::class, $token);
-
- /** @var $result bool */
- require_once $this->sampleFile('tokens/validate_token.php', ['{tokenId}' => $token->id]);
- self::assertTrue($result);
-
-
- $this->logStep('Generate token from id');
- /** @var $token \OpenStack\Identity\v3\Models\Token */
- require_once $this->sampleFile('tokens/generate_token_from_id.php', ['{tokenId}' => $token->id]);
- self::assertInstanceOf(Models\Token::class, $token);
-
- /** @var $result bool */
- require_once $this->sampleFile('tokens/validate_token.php', ['{tokenId}' => $token->id]);
- self::assertTrue($result);
-
-
- $this->logStep('Revoke token');
-
- require_once $this->sampleFile('tokens/revoke_token.php', ['{tokenId}' => $token->id]);
-
- /** @var $result bool */
- require_once $this->sampleFile('tokens/validate_token.php', ['{tokenId}' => $token->id]);
- self::assertFalse($result);
- }
-
- public function domains()
- {
- $this->logStep('Create domain');
-
- $replacements = [
- '{name}' => $this->randomStr(),
- '{description}' => $this->randomStr(),
- ];
-
- /** @var $domain \OpenStack\Identity\v3\Models\Domain */
- require_once $this->sampleFile('domains/add_domain.php', $replacements);
- self::assertInstanceOf(Models\Domain::class, $domain);
-
-
- $this->logStep('List domains');
-
- $replacements['{domainId}'] = $domain->id;
-
- require_once $this->sampleFile('domains/list_domains.php', []);
-
-
- $this->logStep('Show domain');
-
- /** @var $domain \OpenStack\Identity\v3\Models\Domain */
- require_once $this->sampleFile('domains/show_domain.php', $replacements);
- self::assertInstanceOf(Models\Domain::class, $domain);
-
-
- $this->logStep('Grant and revoke group role');
-
- $parentRole = $this->getService()->createRole(['name' => $this->randomStr()]);
- $group = $this->getService()->createGroup(['name' => $this->randomStr(), 'domainId' => $domain->id]);
-
- require_once $this->sampleFile('domains/grant_group_role.php', $replacements + ['{groupId}' => $group->id, '{roleId}' => $parentRole->id]);
-
- /** @var $result bool */
- require_once $this->sampleFile('domains/check_group_role.php', $replacements + ['{groupId}' => $group->id, '{roleId}' => $parentRole->id]);
- self::assertTrue($result);
-
- require_once $this->sampleFile('domains/list_group_roles.php', $replacements + ['{groupId}' => $group->id]);
-
- require_once $this->sampleFile('domains/revoke_group_role.php', $replacements + ['{groupId}' => $group->id, '{roleId}' => $parentRole->id]);
-
- $group->delete();
-
-
- $this->logStep('Grant and revoke user role');
-
- $user = $this->getService()->createUser(['name' => $this->randomStr(), 'domainId' => $domain->id]);
-
- require_once $this->sampleFile('domains/grant_user_role.php', $replacements + ['{domainUserId}' => $user->id, '{roleId}' => $parentRole->id]);
-
- /** @var $result bool */
- require_once $this->sampleFile('domains/check_user_role.php', $replacements + ['{domainUserId}' => $user->id, '{roleId}' => $parentRole->id]);
- self::assertTrue($result);
-
- require_once $this->sampleFile('domains/list_user_roles.php', $replacements + ['{domainUserId}' => $user->id]);
-
- require_once $this->sampleFile('domains/revoke_user_role.php', $replacements + ['{domainUserId}' => $user->id, '{roleId}' => $parentRole->id]);
-
- $user->delete();
- $parentRole->delete();
-
-
- $this->logStep('Update domain');
-
- /** @var $domain \OpenStack\Identity\v3\Models\Domain */
- require_once $this->sampleFile('domains/update_domain.php', $replacements);
- self::assertInstanceOf(Models\Domain::class, $domain);
-
-
- $this->logStep('Delete domain');
-
- require_once $this->sampleFile('domains/delete_domain.php', $replacements);
- }
-
- public function endpoints()
- {
- $service = $this->getService()->createService(['name' => $this->randomStr(), 'type' => 'volume', 'description' => $this->randomStr()]);
-
- $replacements = [
- '{endpointName}' => $this->randomStr(),
- '{serviceId}' => $service->id,
- '{endpointUrl}' => getenv('OS_AUTH_URL'),
- '{region}' => 'RegionOne',
- ];
-
- /** @var $endpoint \OpenStack\Identity\v3\Models\Endpoint */
- require_once $this->sampleFile('endpoints/add_endpoint.php', $replacements);
- self::assertInstanceOf(Models\Endpoint::class, $endpoint);
-
- $replacements['{endpointId}'] = $endpoint->id;
-
- require_once $this->sampleFile('endpoints/list_endpoints.php', $replacements);
-
- /** @var $endpoint \OpenStack\Identity\v3\Models\Endpoint */
- require_once $this->sampleFile('endpoints/update_endpoint.php', $replacements);
-
- require_once $this->sampleFile('endpoints/delete_endpoint.php', $replacements);
-
- $service->delete();
- }
-
- public function services()
- {
- $replacements = [
- '{serviceName}' => $this->randomStr(),
- '{serviceType}' => $this->randomStr(),
- ];
-
- /** @var $service \OpenStack\Identity\v3\Models\Service */
- require_once $this->sampleFile('services/add_service.php', $replacements);
- self::assertInstanceOf(Models\Service::class, $service);
-
- $replacements['{serviceId}'] = $service->id;
-
- require_once $this->sampleFile('services/list_services.php', $replacements);
-
- /** @var $service \OpenStack\Identity\v3\Models\Service */
- require_once $this->sampleFile('services/update_service.php', $replacements);
- self::assertInstanceOf(Models\Service::class, $service);
-
- /** @var $service \OpenStack\Identity\v3\Models\Service */
- require_once $this->sampleFile('services/get_service.php', $replacements);
- self::assertInstanceOf(Models\Service::class, $service);
-
- require_once $this->sampleFile('services/delete_service.php', $replacements);
- }
-
- public function groups()
- {
- $groupUser = $this->getService()->createUser(['name' => $this->randomStr()]);
-
- /** @var $group \OpenStack\Identity\v3\Models\Group */
- require_once $this->sampleFile('groups/add_group.php', ['{name}' => $this->randomStr(), '{description}' => $this->randomStr()]);
- self::assertInstanceOf(Models\Group::class, $group);
-
- $replacements = ['{groupId}' => $group->id];
-
- require_once $this->sampleFile('groups/add_user.php', $replacements + ['{groupUserId}' => $groupUser->id]);
-
- /** @var $group \OpenStack\Identity\v3\Models\Group */
- require_once $this->sampleFile('groups/get_group.php', $replacements);
- self::assertInstanceOf(Models\Group::class, $group);
-
- /** @var $result bool */
- require_once $this->sampleFile('groups/check_user_membership.php', $replacements + ['{groupUserId}' => $groupUser->id]);
- self::assertTrue($result);
-
- require_once $this->sampleFile('groups/list_users.php', $replacements);
-
- require_once $this->sampleFile('groups/remove_user.php', $replacements + ['{groupUserId}' => $groupUser->id]);
-
- /** @var $result bool */
- require_once $this->sampleFile('groups/check_user_membership.php', $replacements + ['{groupUserId}' => $groupUser->id]);
- self::assertFalse($result);
-
- require_once $this->sampleFile('groups/update_group.php', $replacements + ['{name}' => $this->randomStr(), '{description}' => $this->randomStr()]);
-
- require_once $this->sampleFile('groups/list_groups.php', $replacements);
-
- require_once $this->sampleFile('groups/delete_group.php', $replacements);
-
- $groupUser->delete();
- }
-
- public function projects()
- {
- /** @var $project \OpenStack\Identity\v3\Models\Project */
- require_once $this->sampleFile('projects/add_project.php', ['{name}' => $this->randomStr(), '{description}' => $this->randomStr()]);
- self::assertInstanceOf(Models\Project::class, $project);
-
- $replacements = ['{id}' => $project->id];
-
- /** @var $project \OpenStack\Identity\v3\Models\Project */
- require_once $this->sampleFile('projects/get_project.php', $replacements);
- self::assertInstanceOf(Models\Project::class, $project);
-
- $domain = $this->getService()->createDomain(['name' => $this->randomStr()]);
- $parentRole = $this->getService()->createRole(['name' => $this->randomStr()]);
- $group = $this->getService()->createGroup(['name' => $this->randomStr(), 'domainId' => $domain->id]);
-
- require_once $this->sampleFile('projects/grant_group_role.php', $replacements + ['{groupId}' => $group->id, '{roleId}' => $parentRole->id]);
-
- /** @var $result bool */
- require_once $this->sampleFile('projects/check_group_role.php', $replacements + ['{groupId}' => $group->id, '{roleId}' => $parentRole->id]);
- self::assertTrue($result);
-
- require_once $this->sampleFile('projects/list_group_roles.php', $replacements + ['{groupId}' => $group->id]);
-
- require_once $this->sampleFile('projects/revoke_group_role.php', $replacements + ['{groupId}' => $group->id, '{roleId}' => $parentRole->id]);
-
- $group->delete();
-
- $user = $this->getService()->createUser(['name' => $this->randomStr(), 'domainId' => $domain->id]);
-
- require_once $this->sampleFile('projects/grant_user_role.php', $replacements + ['{projectUserId}' => $user->id, '{roleId}' => $parentRole->id]);
-
- /** @var $result bool */
- require_once $this->sampleFile('projects/check_user_role.php', $replacements + ['{projectUserId}' => $user->id, '{roleId}' => $parentRole->id]);
- self::assertTrue($result);
-
- require_once $this->sampleFile('projects/list_user_roles.php', $replacements + ['{projectUserId}' => $user->id]);
-
- require_once $this->sampleFile('projects/revoke_user_role.php', $replacements + ['{projectUserId}' => $user->id, '{roleId}' => $parentRole->id]);
-
- require_once $this->sampleFile('projects/update_project.php', $replacements);
-
- require_once $this->sampleFile('projects/delete_project.php', $replacements);
-
- $user->delete();
- $parentRole->delete();
-
- $domain->enabled = false;
- $domain->update();
- $domain->delete();
- }
-
- public function roles()
- {
- /** @var $role \OpenStack\Identity\v3\Models\Role */
- require_once $this->sampleFile('roles/add_role.php', ['{name}' => $this->randomStr()]);
- self::assertInstanceOf(Models\Role::class, $role);
-
- require_once $this->sampleFile('roles/list_roles.php', []);
-
- require_once $this->sampleFile('roles/list_assignments.php', []);
- }
-
- public function users()
- {
- $parentDomain = $this->getService()->createDomain(['name' => $this->randomStr()]);
- $parentProject = $this->getService()->createProject(['name' => $this->randomStr(), 'domainId' => $parentDomain->id]);
-
- $replacements = [
- '{defaultProjectId}' => $parentProject->id,
- '{description}' => $this->randomStr(),
- '{domainId}' => $parentDomain->id,
- '{email}' => 'foo@bar.com',
- '{enabled}' => true,
- '{name}' => $this->randomStr(),
- '{userPass}' => $this->randomStr(),
- ];
-
- /** @var $user \OpenStack\Identity\v3\Models\User */
- require_once $this->sampleFile('users/add_user.php', $replacements);
- self::assertInstanceOf(Models\User::class, $user);
-
- $replacements = ['{id}' => $user->id];
-
- /** @var $user \OpenStack\Identity\v3\Models\User */
- require_once $this->sampleFile('users/get_user.php', $replacements);
- self::assertInstanceOf(Models\User::class, $user);
-
- require_once $this->sampleFile('users/list_users.php', []);
-
- require_once $this->sampleFile('users/list_groups.php', $replacements);
-
- require_once $this->sampleFile('users/list_projects.php', $replacements);
-
- /** @var $user \OpenStack\Identity\v3\Models\User */
- require_once $this->sampleFile('users/update_user.php', $replacements + ['{name}' => $this->randomStr(), '{description}' => $this->randomStr()]);
- self::assertInstanceOf(Models\User::class, $user);
-
- require_once $this->sampleFile('users/delete_user.php', $replacements);
-
- $parentProject->delete();
-
- $parentDomain->enabled = false;
- $parentDomain->update();
- $parentDomain->delete();
- }
-}
diff --git a/tests/integration/Images/v2/CoreTest.php b/tests/integration/Images/v2/CoreTest.php
deleted file mode 100644
index 9eec5e7fe..000000000
--- a/tests/integration/Images/v2/CoreTest.php
+++ /dev/null
@@ -1,165 +0,0 @@
-service) {
- $this->service = Utils::getOpenStack()->imagesV2();
- }
-
- return $this->service;
- }
-
- public function runTests()
- {
- $this->startTimer();
-
- $this->logger->info('-> Images');
- $this->images();
-
- $this->logger->info('-> Members');
- $this->members();
-
- $this->logger->info('-> Image list');
- $this->imageList();
-
- $this->outputTimeTaken();
- }
-
- public function images()
- {
- $replacements = [
- '{name}' => 'Ubuntu 12.10',
- '{tag1}' => 'ubuntu',
- '{tag2}' => 'quantal',
- '{containerFormat}' => 'bare',
- '{diskFormat}' => 'qcow2',
- '{visibility}' => 'private',
- ];
-
- $this->logStep('Creating image');
- /** @var Image $image */
- require_once $this->sampleFile('images/create.php', $replacements);
- self::assertInstanceOf(Image::class, $image);
-
- $replacements = ['{imageId}' => $image->id];
-
- $this->logStep('Listing images');
- /** @var \Generator $images */
- require_once $this->sampleFile('images/list.php', $replacements);
-
- $this->logStep('Getting image');
- /** @var Image $image */
- require_once $this->sampleFile('images/get.php', $replacements);
- self::assertInstanceOf(Image::class, $image);
-
- $replacements += [
- '{name}' => 'newName',
- '{visibility}' => 'private',
- ];
-
- $this->logStep('Updating image');
- /** @var Image $image */
- require_once $this->sampleFile('images/update.php', $replacements);
-
- $this->logStep('Deleting image');
- /** @var Image $image */
- require_once $this->sampleFile('images/delete.php', $replacements);
- }
-
- public function members()
- {
- $replacements = [
- '{name}' => 'Ubuntu 12.10',
- '{tag1}' => 'ubuntu',
- '{tag2}' => 'quantal',
- '{containerFormat}' => 'bare',
- '{diskFormat}' => 'qcow2',
- '{visibility}' => 'shared',
- 'true' => 'false',
- ];
-
- $this->logStep('Creating image');
- /** @var Image $image */
- require_once $this->sampleFile('images/create.php', $replacements);
-
- $this->logStep(sprintf('Image created with id=%s', $image->id));
-
- $this->logStep('Adding member');
- $replacements += ['{imageId}' => $image->id];
- /** @var Member $member */
- require_once $this->sampleFile('members/add.php', ['{imageId}' => $image->id,]);
- self::assertInstanceOf(Member::class, $member);
-
- $replacements += ['status' => Member::STATUS_REJECTED];
- $this->logStep('Updating member status');
- /** @var Member $member */
- require_once $this->sampleFile('members/update_status.php', $replacements);
- self::assertInstanceOf(Member::class, $member);
-
- $this->logStep('Deleting member');
- /** @var Member $member */
- require_once $this->sampleFile('members/delete.php', $replacements);
-
- $this->logStep('Deleting image');
- /** @var Image $image */
- require_once $this->sampleFile('images/delete.php', $replacements);
- }
-
- public function imageList()
- {
- $this->logStep('Creating image');
-
- $postfix = $this->randomStr();
- $names = ['b' . $postfix, 'a' . $postfix, 'd' . $postfix, 'c' . $postfix];
- $createdImages = [];
- foreach ($names as $name) {
- $this->logStep("Creating image $name");
- $image = $this->getService()->createImage([
- 'name' => $name,
- ]);
-
- self::assertInstanceOf(Image::class, $image);
- $createdImages[] = $image;
- }
-
-
- $this->logStep('Listing images sorted asc');
-
- $replacements = [
- '{sortKey}' => 'name',
- '{sortDir}' => 'asc',
- ];
-
- /** @var \OpenStack\Images\v2\Models\Image $image */
- require_once $this->sampleFile('images/list_sorted.php', $replacements);
- self::assertInstanceOf(Image::class, $image);
- self::assertEquals($names[2], $image->name);
-
-
- $this->logStep('Listing images sorted desc');
-
- $replacements['{sortDir}'] = 'desc';
- /** @var \OpenStack\Images\v2\Models\Image $image */
- require_once $this->sampleFile('images/list_sorted.php', $replacements);
- self::assertInstanceOf(Image::class, $image);
- self::assertEquals($names[1], $image->name);
-
- foreach ($createdImages as $image) {
- $this->logStep("Deleting image $image->name");
- $image->delete();
- }
- }
-
-}
diff --git a/tests/integration/Networking/v2/CoreTest.php b/tests/integration/Networking/v2/CoreTest.php
deleted file mode 100644
index 08a2266a0..000000000
--- a/tests/integration/Networking/v2/CoreTest.php
+++ /dev/null
@@ -1,326 +0,0 @@
-startTimer();
-
- $this->networks();
- $this->subnets();
- $this->ports();
-
- $this->outputTimeTaken();
- }
-
- public function subnets()
- {
- $this->createSubnetsAndDelete();
- $this->createSubnetWithHostRoutes();
-
- [$subnetId, $networkId] = $this->createSubnet();
-
- $this->updateSubnet($subnetId);
- $this->retrieveSubnet($subnetId);
- $this->deleteSubnet($subnetId);
- $this->deleteNetwork($networkId);
- }
-
- public function networks()
- {
- $this->createNetworksAndDelete();
-
- $networkId = $this->createNetwork();
- $this->updateNetwork($networkId);
- $this->retrieveNetwork($networkId);
- $this->deleteNetwork($networkId);
- }
-
- private function createNetworksAndDelete()
- {
- $replacements = [
- '{networkName1}' => $this->randomStr(),
- '{networkName2}' => $this->randomStr()
- ];
-
- /** @var $networks array */
- require_once $this->sampleFile('networks/create_batch.php', $replacements);
-
- foreach ($networks as $network) {
- self::assertInstanceOf(Network::class, $network);
- self::assertNotEmpty($network->id);
-
- $this->networkId = $network->id;
- $this->logStep('Created network {id}', ['{id}' => $this->networkId]);
-
- $this->deleteNetwork($network->id);
- }
- }
-
- private function createNetwork()
- {
- $replacements = [
- '{networkName}' => $this->randomStr(),
- ];
-
- /** @var $network \OpenStack\Networking\v2\Models\Network */
- require_once $this->sampleFile('networks/create.php', $replacements);
-
- self::assertInstanceOf(Network::class, $network);
- self::assertNotEmpty($network->id);
-
- $this->logStep('Created network {id}', ['{id}' => $this->networkId]);
-
- return $network->id;
- }
-
- private function updateNetwork($networkId)
- {
- $name = $this->randomStr();
-
- $replacements = [
- '{networkId}' => $networkId,
- '{newName}' => $name,
- ];
-
- /** @var $network \OpenStack\Networking\v2\Models\Network */
- require_once $this->sampleFile('networks/update.php', $replacements);
-
- self::assertInstanceOf(Network::class, $network);
- self::assertEquals($name, $network->name);
-
- $this->logStep('Updated network ID to use this name: NAME', ['ID' => $networkId, 'NAME' => $name]);
- }
-
- private function retrieveNetwork($networkId)
- {
- $replacements = ['{networkId}' => $networkId];
-
- /** @var $network \OpenStack\Networking\v2\Models\Network */
- require_once $this->sampleFile('networks/get.php', $replacements);
-
- self::assertInstanceOf(Network::class, $network);
-
- $this->logStep('Retrieved the details of network ID', ['ID' => $networkId]);
- }
-
- private function deleteNetwork($networkId)
- {
- $replacements = ['{networkId}' => $networkId];
-
- /** @var $network \OpenStack\Networking\v2\Models\Network */
- require_once $this->sampleFile('networks/delete.php', $replacements);
-
- $this->logStep('Deleted network ID', ['ID' => $networkId]);
- }
-
- private function createSubnetsAndDelete()
- {
- /** @var $network \OpenStack\Networking\v2\Models\Network */
- require_once $this->sampleFile('networks/create.php', ['{newName}' => $this->randomStr()]);
-
- $replacements = [
- '{subnetName1}' => $this->randomStr(),
- '{subnetName2}' => $this->randomStr(),
- '{networkId1}' => $network->id,
- '{networkId2}' => $network->id,
- ];
-
- /** @var $subnets array */
- require_once $this->sampleFile('subnets/create_batch.php', $replacements);
-
- foreach ($subnets as $subnet) {
- self::assertInstanceOf(Subnet::class, $subnet);
- self::assertNotEmpty($subnet->id);
-
- $this->logStep('Created subnet {id}', ['{id}' => $subnet->id]);
-
- $this->deleteSubnet($subnet->id);
- }
-
- require_once $this->sampleFile('networks/delete.php', ['{networkId}' => $network->id]);
- }
-
- private function createSubnet()
- {
- /** @var $network \OpenStack\Networking\v2\Models\Network */
- require_once $this->sampleFile('networks/create.php', ['{newName}' => $this->randomStr()]);
-
- $replacements = [
- '{subnetName}' => $this->randomStr(),
- '{networkId}' => $network->id,
- ];
-
- /** @var $subnet \OpenStack\Networking\v2\Models\Subnet */
- require_once $this->sampleFile('subnets/create.php', $replacements);
-
- self::assertInstanceOf(Subnet::class, $subnet);
- self::assertNotEmpty($subnet->id);
-
- $this->logStep('Created subnet {id}', ['{id}' => $subnet->id]);
-
- return [$subnet->id, $network->id];
- }
-
- private function createSubnetWithGatewayIp()
- {
- /** @var $network \OpenStack\Networking\v2\Models\Network */
- require_once $this->sampleFile('networks/create.php', ['{newName}' => $this->randomStr()]);
-
- $replacements = [
- '{networkId}' => $network->id,
- ];
-
- /** @var $subnet \OpenStack\Networking\v2\Models\Subnet */
- require_once $this->sampleFile('subnets/create_with_gateway_ip.php', $replacements);
-
- self::assertInstanceOf(Subnet::class, $subnet);
- self::assertNotEmpty($subnet->id);
-
- $this->subnetId = $subnet->id;
-
- $this->logStep('Created subnet {id} with gateway ip', ['{id}' => $this->subnetId]);
-
- require_once $this->sampleFile('networks/delete.php', $replacements);
- }
-
- private function createSubnetWithHostRoutes()
- {
- /** @var $network \OpenStack\Networking\v2\Models\Network */
- require_once $this->sampleFile('networks/create.php', ['{newName}' => $this->randomStr()]);
-
- $replacements = [
- '{networkId}' => $network->id,
- ];
-
- /** @var $subnet \OpenStack\Networking\v2\Models\Subnet */
- require_once $this->sampleFile('subnets/create_with_host_routes.php', $replacements);
-
- self::assertInstanceOf(Subnet::class, $subnet);
- self::assertNotEmpty($subnet->id);
-
- $this->logStep('Created subnet {id} with host routes', ['{id}' => $subnet->id]);
-
- require_once $this->sampleFile('networks/delete.php', $replacements);
- }
-
- private function updateSubnet($subnetId)
- {
- $name = $this->randomStr();
-
- $replacements = [
- '{subnetId}' => $subnetId,
- '{newName}' => $name,
- ];
-
- /** @var $subnet \OpenStack\Networking\v2\Models\Subnet */
- require_once $this->sampleFile('subnets/update.php', $replacements);
-
- self::assertInstanceOf(Subnet::class, $subnet);
- self::assertEquals($name, $subnet->name);
-
- $this->logStep('Updated subnet ID to use this name: NAME', ['ID' => $subnetId, 'NAME' => $name]);
- }
-
-
- private function retrieveSubnet($subnetId)
- {
- $replacements = ['{subnetId}' => $subnetId];
-
- /** @var $subnet \OpenStack\Networking\v2\Models\Subnet */
- require_once $this->sampleFile('subnets/get.php', $replacements);
-
- self::assertInstanceOf(Subnet::class, $subnet);
-
- $this->logStep('Retrieved the details of subnet ID', ['ID' => $subnetId]);
- }
-
- private function deleteSubnet($subnetId)
- {
- $replacements = ['{subnetId}' => $subnetId];
-
- /** @var $subnet \OpenStack\Networking\v2\Models\Subnet */
- require_once $this->sampleFile('subnets/delete.php', $replacements);
-
- $this->logStep('Deleted subnet ID', ['ID' => $subnetId]);
- }
-
- public function ports()
- {
- $this->logStep('Test port');
-
- $replacements = ['{newName}' => $this->randomStr()];
-
- /** @var $network \OpenStack\Networking\v2\Models\Network */
- require_once $this->sampleFile('networks/create.php', $replacements);
-
- $replacements = ['{networkId}' => $network->id];
-
- /** @var $port \OpenStack\Networking\v2\Models\Port */
- require_once $this->sampleFile('ports/create.php', $replacements);
-
- $replacements['{portId}'] = $port->id;
- $port->networkId = $network->id;
-
- /** @var $ports array */
- require_once $this->sampleFile('ports/create_batch.php', $replacements);
- foreach ($ports as $port) {
- self::assertInstanceOf(Port::class, $port);
- $port->delete();
- }
-
- /** @var $port \OpenStack\Networking\v2\Models\Port */
- require_once $this->sampleFile('ports/list.php', $replacements);
-
- /** @var $port \OpenStack\Networking\v2\Models\Port */
- require_once $this->sampleFile('ports/get.php', $replacements);
- self::assertInstanceOf(Port::class, $port);
-
- /** @var $port \OpenStack\Networking\v2\Models\Port */
- require_once $this->sampleFile('ports/update.php', $replacements);
- self::assertInstanceOf(Port::class, $port);
-
- require_once $this->sampleFile('ports/delete.php', $replacements);
-
- require_once $this->sampleFile('networks/delete.php', $replacements);
-
- $this->createPortWithFixedIps();
- }
-
- private function createPortWithFixedIps()
- {
- $this->logStep('Test port with fixed IP');
-
- /** @var $network \OpenStack\Networking\v2\Models\Network */
- require_once $this->sampleFile('networks/create.php', ['{networkName}' => $this->randomStr()]);
- $this->logStep('Created network {id}', ['{id}' => $network->id]);
-
-
- /** @var $subnet \OpenStack\Networking\v2\Models\Subnet */
- require_once $this->sampleFile('subnets/create.php', ['{subnetName}' => $this->randomStr(), '{networkId}' => $network->id]);
- $this->logStep('Created subnet {id}', ['{id}' => $subnet->id]);
-
- /** @var $port \OpenStack\Networking\v2\Models\Port */
- require_once $this->sampleFile('ports/create_with_fixed_ips.php', ['{networkId}' => $network->id]);
- $this->logStep('Created port {id}', ['{id}' => $port->id]);
-
- require_once $this->sampleFile('ports/delete.php', ['{portId}' => $port->id]);
-
- $this->logStep('Deleted port {id}', ['{id}' => $port->id]);
-
- /** @var $subnet \OpenStack\Networking\v2\Models\Subnet */
- require_once $this->sampleFile('subnets/delete.php', ['{subnetId}' => $subnet->id]);
- $this->logStep('Deleted subnet {id}', ['{id}' => $subnet->id]);
-
- /** @var $network \OpenStack\Networking\v2\Models\Network */
- require_once $this->sampleFile('networks/delete.php', ['{networkId}' => $network->id]);
- $this->logStep('Deleted network {id}', ['{id}' => $network->id]);
- }
-}
diff --git a/tests/integration/Networking/v2/Layer3Test.php b/tests/integration/Networking/v2/Layer3Test.php
deleted file mode 100644
index 2360cf9d7..000000000
--- a/tests/integration/Networking/v2/Layer3Test.php
+++ /dev/null
@@ -1,152 +0,0 @@
-getBaseClient()->networkingV2ExtLayer3();
- }
-
- private function getV2Service(): \OpenStack\Networking\v2\Service
- {
- return $this->getBaseClient()->networkingV2();
- }
-
- public function runTests()
- {
- $this->startTimer();
- $this->floatingIps();
- $this->outputTimeTaken();
- }
-
- public function teardown(): void
- {
- parent::teardown();
-
- $this->deleteItems($this->getV2Service()->listPorts());
- $this->deleteItems($this->getV2Service()->listNetworks());
- $this->deleteItems($this->getService()->listFloatingIps());
- }
-
- private function createNetwork(bool $routerAccessible = true): Network
- {
- $network = $this->getV2Service()->createNetwork([
- 'name' => $this->randomStr(),
- 'routerAccessible' => $routerAccessible,
- ]);
- $network->waitUntilActive();
- return $network;
- }
-
- private function createSubnet(Network $network, string $cidr = '192.168.199.0/24'): Subnet
- {
- return $this->getV2Service()->createSubnet([
- 'networkId' => $network->id,
- 'name' => $this->randomStr(),
- 'ipVersion' => 4,
- 'cidr' => $cidr,
- ]);
- }
-
- private function createPort(Network $network): Port
- {
- return $this->getV2Service()->createPort([
- 'networkId' => $network->id,
- 'name' => $this->randomStr(),
- ]);
- }
-
- private function findSubnetIp(Port $port, Subnet $subnet): string
- {
- foreach ($port->fixedIps as $fixedIp) {
- if ($fixedIp['subnet_id'] == $subnet->id) {
- return $fixedIp['ip_address'];
- }
- }
-
- return '';
- }
-
- public function floatingIps()
- {
- $this->logStep('Creating external network');
- $externalNetwork = $this->createNetwork();
-
- $this->logStep('Creating subnet for external network %id%', ['%id%' => $externalNetwork->id]);
- $this->createSubnet($externalNetwork, '10.0.0.0/24');
-
- $this->logStep('Creating internal network');
- $internalNetwork = $this->createNetwork(false);
-
- $this->logStep('Creating subnet for internal network %id%', ['%id%' => $internalNetwork->id]);
- $subnet = $this->createSubnet($internalNetwork);
-
- $this->logStep('Creating router for external network %id%', ['%id%' => $externalNetwork->id]);
- $router = $this->getService()->createRouter([
- 'name' => $this->randomStr(),
- 'externalGatewayInfo' => [
- 'networkId' => $externalNetwork->id,
- 'enableSnat' => true,
- ],
- ]);
-
- $this->logStep('Create interface for subnet %subnet% and router %router%', [
- '%subnet%' => $subnet->id, '%router%' => $router->id,
- ]);
- $router->addInterface(['subnetId' => $subnet->id]);
-
- $this->logStep('Creating port for internal network %id%', ['%id%' => $internalNetwork->id]);
- $port1 = $this->createPort($internalNetwork);
- $fixedIp = $this->findSubnetIp($port1, $subnet);
-
- $replacements = [
- '{networkId}' => $externalNetwork->id,
- '{portId}' => $port1->id,
- '{fixedIpAddress}' => $fixedIp,
- ];
-
- $this->logStep('Create floating IP');
- /** @var FloatingIp $ip */
- require_once $this->sampleFile('floatingIPs/create.php', $replacements);
- self::assertInstanceOf(FloatingIp::class, $ip);
- self::assertEquals($externalNetwork->id, $ip->floatingNetworkId);
- self::assertEquals($port1->id, $ip->portId);
-
- $this->logStep('List floating IPs');
- require_once $this->sampleFile('floatingIPs/list.php', $replacements);
-
- $this->logStep('Get floating IP');
- $replacements['{id}'] = $ip->id;
- require_once $this->sampleFile('floatingIPs/get.php', $replacements);
- self::assertInstanceOf(FloatingIp::class, $ip);
-
- $this->logStep('Update floating IP');
- $port2 = $this->createPort($internalNetwork);
- $replacements['{newPortId}'] = $port2->id;
- require_once $this->sampleFile('floatingIPs/update.php', $replacements);
-
- $this->logStep('Delete floating IP');
- require_once $this->sampleFile('floatingIPs/delete.php', $replacements);
-
- $router->removeInterface(['subnetId' => $subnet->id]);
- $router->delete();
- $router->waitUntilDeleted();
-
- $port1->delete();
- $port2->delete();
-
- $internalNetwork->delete();
- $internalNetwork->waitUntilDeleted();
-
- $externalNetwork->delete();
- $externalNetwork->waitUntilDeleted();
- }
-}
diff --git a/tests/integration/Networking/v2/SecGroupTest.php b/tests/integration/Networking/v2/SecGroupTest.php
deleted file mode 100644
index 6b82dd988..000000000
--- a/tests/integration/Networking/v2/SecGroupTest.php
+++ /dev/null
@@ -1,12 +0,0 @@
-service) {
- $this->service = Utils::getOpenStack()->objectStoreV1();
- }
-
- return $this->service;
- }
-
- public function runTests()
- {
- $this->startTimer();
-
- $this->accountMetadata();
- $this->containers();
- $this->objects();
-
- $this->outputTimeTaken();
- }
-
- public function accountMetadata()
- {
- $this->logStep('Ensure all metadata is wiped');
- $this->getService()->getAccount()->resetMetadata([]);
-
- $replacements = [
- '{key_1}' => 'Foo',
- '{key_2}' => 'Bar',
- '{val_1}' => $this->randomStr(),
- '{val_2}' => $this->randomStr(),
- ];
-
- $this->logStep('Setting account metadata');
- require_once $this->sampleFile('account/merge_metadata.php', $replacements);
-
- $this->logStep('Getting account metadata');
- /** @var array $metadata */
- require_once $this->sampleFile('account/get_metadata.php', $replacements);
- self::assertArraySubset([
- 'Foo' => $replacements['{val_1}'],
- 'Bar' => $replacements['{val_2}'],
- ], $metadata);
-
- $this->logStep('Resetting account metadata');
- $replacements = [
- '{key_1}' => 'Foo1',
- '{key_2}' => 'Bar1',
- '{val_1}' => $this->randomStr(),
- '{val_2}' => $this->randomStr(),
- ];
- require_once $this->sampleFile('account/reset_metadata.php', $replacements);
-
- $this->logStep('Checking account metadata was reset properly');
- /** @var array $metadata */
- require_once $this->sampleFile('account/get_metadata.php', $replacements);
- self::assertEquals([
- 'Foo1' => $replacements['{val_1}'],
- 'Bar1' => $replacements['{val_2}'],
- ], $metadata);
- }
-
- public function containers()
- {
- $containerName = $this->randomStr();
- $replacements = ['{containerName}' => $containerName];
-
- $this->logStep('Create container');
- require_once $this->sampleFile('containers/create.php', $replacements);
-
- $this->logStep('Get container');
- require_once $this->sampleFile('containers/get.php', $replacements);
-
- $this->logStep('Listing containers');
- require_once $this->sampleFile('containers/list.php', $replacements);
-
- $this->logStep('Merging metadata');
- $replacements += [
- '{key_1}' => 'Foo',
- '{key_2}' => 'Bar',
- '{val_1}' => $this->randomStr(),
- '{val_2}' => $this->randomStr(),
- ];
- require_once $this->sampleFile('containers/merge_metadata.php', $replacements);
-
- $this->logStep('Getting metadata');
- /** @var array $metadata */
- require_once $this->sampleFile('containers/get_metadata.php', $replacements);
- self::assertEquals([
- 'Foo' => $replacements['{val_1}'],
- 'Bar' => $replacements['{val_2}'],
- ], $metadata);
-
- $this->logStep('Resetting metadata');
- $replacements['{key_1}'] = 'Foo1';
- $replacements['{key_2}'] = 'Bar1';
-
- /** @var array $metadata */
- require_once $this->sampleFile('containers/reset_metadata.php', $replacements);
- /** @var array $metadata */
- require_once $this->sampleFile('containers/get_metadata.php', $replacements);
- self::assertEquals([
- 'Foo1' => $replacements['{val_1}'],
- 'Bar1' => $replacements['{val_2}'],
- ], $metadata);
-
- $this->logStep('Delete container');
- $replacements = ['{containerName}' => $containerName];
- require_once $this->sampleFile('containers/delete.php', $replacements);
- }
-
- public function objects()
- {
- $containerName = $this->randomStr();
-
- $this->logStep('Create container named {name}', ['{name}' => $containerName]);
- $container = $this->getService()->createContainer(['name' => $containerName]);
-
- $objectName = $this->randomStr();
- $replacements = ['{containerName}' => $container->name, '{objectName}' => $objectName];
-
- $this->logStep('Create object');
- $replacements['{objectContent}'] = str_repeat('A', 1000);
- require_once $this->sampleFile('objects/create.php', $replacements);
-
- $this->logStep('Copy object');
- $newName = $this->randomStr();
- $replacements += ['{newContainerName}' => $containerName, '{newObjectName}' => $newName];
- require_once $this->sampleFile('objects/copy.php', $replacements);
-
- $this->logStep('Check that new object exists');
- /** @var bool $exists */
- require_once $this->sampleFile('objects/check_exists.php', ['{containerName}' => $containerName, '{objectName}' => $newName]);
- self::assertTrue($exists);
-
- $this->logStep('Downloading object');
- /** @var StreamInterface $stream */
- require_once $this->sampleFile('objects/download.php', $replacements);
- self::assertInstanceOf(StreamInterface::class, $stream);
- self::assertEquals(1000, $stream->getSize());
-
- $this->logStep('Downloading object using streaming');
- /** @var StreamInterface $stream */
- require_once $this->sampleFile('objects/download_stream.php', $replacements);
- self::assertInstanceOf(StreamInterface::class, $stream);
-
- $body = '';
- while (!$stream->eof()) {
- $body .= $stream->read(64);
- }
- self::assertEquals(1000, strlen($body));
-
- $this->logStep('Get object');
- require_once $this->sampleFile('objects/get.php', $replacements);
-
- $this->logStep('Listing objects');
- require_once $this->sampleFile('objects/list.php', $replacements);
-
- $this->logStep('Merging metadata');
- $replacements += [
- '{key_1}' => 'Foo',
- '{key_2}' => 'Bar',
- '{val_1}' => $this->randomStr(),
- '{val_2}' => $this->randomStr(),
- ];
- require_once $this->sampleFile('objects/merge_metadata.php', $replacements);
-
- $this->logStep('Getting metadata');
- /** @var array $metadata */
- require_once $this->sampleFile('objects/get_metadata.php', $replacements);
- self::assertEquals([
- 'Foo' => $replacements['{val_1}'],
- 'Bar' => $replacements['{val_2}'],
- ], $metadata);
-
- $this->logStep('Resetting metadata');
- $replacements['{key_1}'] = 'Foo1';
- $replacements['{key_2}'] = 'Bar1';
-
- /** @var array $metadata */
- require_once $this->sampleFile('objects/reset_metadata.php', $replacements);
- /** @var array $metadata */
- require_once $this->sampleFile('objects/get_metadata.php', $replacements);
- self::assertEquals([
- 'Foo1' => $replacements['{val_1}'],
- 'Bar1' => $replacements['{val_2}'],
- ], $metadata);
-
- $this->logStep('Delete object');
- require_once $this->sampleFile('objects/delete.php', $replacements);
- $container->getObject($replacements['{newObjectName}'])->delete();
-
- $this->logStep('Delete container');
- $container->delete();
- }
-}
diff --git a/tests/integration/Runner.php b/tests/integration/Runner.php
deleted file mode 100644
index dc3776384..000000000
--- a/tests/integration/Runner.php
+++ /dev/null
@@ -1,162 +0,0 @@
-samplesDir = $samplesDir;
- $this->testsDir = $testsDir;
- $this->namespace = $testNamespace;
-
- $this->logger = new DefaultLogger();
- $this->assembleTestFiles();
- }
-
- private function traverse(string $path): \DirectoryIterator
- {
- return new \DirectoryIterator($path);
- }
-
- private function assembleTestFiles()
- {
- foreach ($this->traverse($this->testsDir) as $servicePath) {
- if ($servicePath->isDir()) {
- $serviceBn = $servicePath->getBasename();
- foreach ($this->traverse($servicePath->getPathname()) as $versionPath) {
- $versionBn = $versionPath->getBasename();
- if ($servicePath->isDir() && $versionBn[0] == 'v') {
- foreach ($this->traverse($versionPath->getPathname()) as $testPath) {
- if (strpos($testPath->getFilename(), 'Test.php')) {
- $testBn = substr($testPath->getBasename(), 0, -8);
- $this->tests[$serviceBn][strtolower($versionBn)][] = $testBn;
- }
- }
- }
- }
- }
- }
- }
-
- private function getOpts()
- {
- $opts = getopt('s:v:m:t:', ['service:', 'version:', 'module::', 'test::', 'debug::', 'help::']);
-
- $getOpt = function (array $keys, $default) use ($opts) {
- $value = $default;
- foreach ($keys as $key) {
- if (isset($opts[$key])) {
- $value = $opts[$key];
- break;
- }
- }
- return $value;
- };
-
- return [
- $getOpt(['s', 'service'], 'all'),
- $getOpt(['v', 'version'], 'all'),
- $getOpt(['m', 'module'], 'core'),
- $getOpt(['t', 'test'], ''),
- isset($opts['debug']) ? (int)$opts['debug'] : 0,
- ];
- }
-
- private function getRunnableServices($service, $version, $module)
- {
- $tests = $this->tests;
-
- if ($service != 'all') {
- if (!isset($tests[$service])) {
- $this->logger->critical(sprintf("%s is not a valid service", $service));
- exit(1);
- }
-
- $serviceArray = $tests[$service];
- $tests = [$service => $serviceArray];
-
- if ($version != 'all') {
- if (!isset($serviceArray[$version])) {
- $this->logger->critical(sprintf("%s is not a valid version for the %s service", $version, $service));
- exit(1);
- }
-
- $versionArray = $serviceArray[$version];
- if ($module != 'core') {
- if (!in_array($module, $serviceArray[$version])) {
- $this->logger->critical(sprintf("%s is not a valid test class for the %s %s service", $module, $version, $service));
- exit(1);
- }
- $versionArray = [$module];
- }
-
- $tests = [$service => [$version => $versionArray]];
- }
- }
-
- return $tests;
- }
-
- /**
- * @return TestInterface
- */
- private function getTest($service, $version, $test, $verbosity)
- {
- $className = sprintf("%s\\%s\\%s\\%sTest", $this->namespace, Utils::toCamelCase($service), $version, ucfirst($test));
-
- if (!class_exists($className)) {
- throw new \RuntimeException(sprintf("%s does not exist", $className));
- }
-
- $basePath = $this->samplesDir . DIRECTORY_SEPARATOR . $service . DIRECTORY_SEPARATOR . $version;
- $smClass = sprintf("%s\\SampleManager", $this->namespace);
- $class = new $className($this->logger, new $smClass($basePath, $verbosity), $verbosity);
-
- if (!($class instanceof TestInterface)) {
- throw new \RuntimeException(sprintf("%s does not implement TestInterface", $className));
- }
-
- return $class;
- }
-
- public function runServices()
- {
- list($serviceOpt, $versionOpt, $moduleOpt, $testMethodOpt, $verbosityOpt) = $this->getOpts();
-
- foreach ($this->getRunnableServices($serviceOpt, $versionOpt, $moduleOpt) as $serviceName => $serviceArray) {
- foreach ($serviceArray as $versionName => $versionArray) {
- foreach ($versionArray as $testName) {
- $this->logger->info(str_repeat('=', 49));
- $this->logger->info("Starting %s %v %m integration test(s)", [
- '%s' => $serviceName,
- '%v' => $versionName,
- '%m' => $moduleOpt,
- ]);
- $this->logger->info(str_repeat('=', 49));
-
- $testRunner = $this->getTest($serviceName, $versionName, $testName, $verbosityOpt);
-
- try {
- if ($testMethodOpt) {
- $testRunner->runOneTest($testMethodOpt);
- } else {
- $testRunner->runTests();
- }
- } finally {
- $this->logger->info(str_repeat('=', 11));
- $this->logger->info('Cleaning up');
- $this->logger->info(str_repeat('=', 11));
- $testRunner->teardown();
- }
- }
- }
- }
- }
-}
diff --git a/tests/integration/SampleManagerInterface.php b/tests/integration/SampleManagerInterface.php
deleted file mode 100644
index 108f7684f..000000000
--- a/tests/integration/SampleManagerInterface.php
+++ /dev/null
@@ -1,10 +0,0 @@
-logger = $logger;
- $this->sampleManager = $sampleManager;
- }
-
- public function teardown(): void
- {
- $this->sampleManager->deletePaths();
- }
-
- public function runOneTest($name)
- {
- if (!method_exists($this, $name)) {
- throw new \InvalidArgumentException(sprintf("%s method does not exist", $name));
- }
-
- $this->startTimer();
- $this->$name();
- $this->outputTimeTaken();
- }
-
- protected function startTimer()
- {
- $this->startPoint = $this->lastPoint = microtime(true);
- }
-
- private function wrapColor($message, $colorPrefix)
- {
- return sprintf("%s%s", $colorPrefix, $message) . "\033[0m\033[1;0m";
- }
-
- protected function logStep($message, array $context = [])
- {
- $duration = microtime(true) - $this->lastPoint;
-
- $stepTimeTaken = sprintf('(%s)', $this->formatSecDifference($duration));
-
- if ($duration >= 10) {
- $color = "\033[0m\033[1;31m"; // red
- } elseif ($duration >= 2) {
- $color = "\033[0m\033[1;33m"; // yellow
- } else {
- $color = "\033[0m\033[1;32m"; // green
- }
-
- $message = '{timeTaken} ' . $message;
- $context['{timeTaken}'] = $this->wrapColor($stepTimeTaken, $color);
-
- $this->logger->info($message, $context);
-
- $this->lastPoint = microtime(true);
- }
-
- protected function randomStr($length = 5)
- {
- $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
- $charsLen = strlen($chars);
-
- $randomString = '';
- for ($i = 0; $i < $length; $i++) {
- $randomString .= $chars[rand(0, $charsLen - 1)];
- }
-
- return $this->namePrefix . $randomString;
- }
-
- private function formatMinDifference($duration)
- {
- $output = '';
-
- if (($minutes = floor($duration / 60)) > 0) {
- $output .= $minutes . 'min' . (($minutes > 1) ? 's' : '');
- }
-
- if (($seconds = number_format(fmod($duration, 60), 2)) > 0) {
- if ($minutes > 0) {
- $output .= ' ';
- }
- $output .= $seconds . 's';
- }
-
- return $output;
- }
-
- private function formatSecDifference($duration)
- {
- return number_format($duration, 2) . 's';
- }
-
- protected function outputTimeTaken()
- {
- $output = $this->formatMinDifference(microtime(true) - $this->startPoint);
-
- $this->logger->info('Finished all tests! Time taken: {output}.', ['{output}' => $output]);
- }
-
- protected function sampleFile($path, array $replacements = [])
- {
- return $this->sampleManager->write($path, $replacements);
- }
-
- protected function getBaseClient()
- {
- return eval($this->sampleManager->getConnectionStr());
- }
-
- protected function deleteItems(\Generator $items)
- {
- foreach ($items as $item) {
- if ($item instanceof Deletable
- && property_exists($item, 'name')
- && strpos($item->name, $this->namePrefix) === 0
- ) {
- $item->delete();
- }
- }
- }
-}
diff --git a/tests/integration/TestInterface.php b/tests/integration/TestInterface.php
deleted file mode 100644
index abac45f9b..000000000
--- a/tests/integration/TestInterface.php
+++ /dev/null
@@ -1,16 +0,0 @@
- getenv('OS_AUTH_URL'),
- 'region' => getenv('OS_REGION_NAME'),
- 'user' => [
- 'id' => getenv('OS_USER_ID'),
- 'password' => getenv('OS_PASSWORD'),
- ],
- 'scope' => [
- 'project' => [
- 'id' => getenv('OS_PROJECT_ID'),
- ]
- ]
- ];
- }
-
- public static function getAuthOptsV2()
- {
- $httpClient = new Client([
- 'base_uri' => TransportUtils::normalizeUrl(getenv('OS_AUTH_URL')),
- 'handler' => HandlerStack::create(),
- ]);
-
- return [
- 'authUrl' => getenv('OS_AUTH_URL'),
- 'region' => getenv('OS_REGION_NAME'),
- 'username' => getenv('OS_USERNAME'),
- 'password' => getenv('OS_PASSWORD'),
- 'tenantName' => getenv('OS_TENANT_NAME'),
- 'identityService' => Service::factory($httpClient),
- ];
- }
-
- public static function getAuthOpts(array $options = [])
- {
- $authOptions = getenv('OS_IDENTITY_API_VERSION') == '2.0'
- ? self::getAuthOptsV2()
- : self::getAuthOptsV3();
-
- return array_merge($authOptions, $options);
- }
-
- public static function toCamelCase($word, $separator = '_')
- {
- return str_replace($separator, '', ucwords($word, $separator));
- }
-}
diff --git a/tests/integration/run.php b/tests/integration/run.php
deleted file mode 100644
index 959cb117b..000000000
--- a/tests/integration/run.php
+++ /dev/null
@@ -1,12 +0,0 @@
-runServices();
diff --git a/tests/integration/script/compute_v2 b/tests/integration/script/compute_v2
deleted file mode 100755
index 762523eb9..000000000
--- a/tests/integration/script/compute_v2
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/bash
-
-php tests/integration/run.php -s compute -v v2
diff --git a/tests/integration/script/identity_v3 b/tests/integration/script/identity_v3
deleted file mode 100755
index 233bc1089..000000000
--- a/tests/integration/script/identity_v3
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/bash
-
-php tests/integration/run.php -s identity -v v3
diff --git a/tests/integration/script/networking_v2 b/tests/integration/script/networking_v2
deleted file mode 100755
index be95d37b9..000000000
--- a/tests/integration/script/networking_v2
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/bash
-
-php tests/integration/run.php -s networking -v v2
diff --git a/tests/integration/script/objectstore_v2 b/tests/integration/script/objectstore_v2
deleted file mode 100755
index 4bd97a358..000000000
--- a/tests/integration/script/objectstore_v2
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/bash
-
-php tests/integration/run.php -s objectstore -v v2
diff --git a/tests/sample/BlockStorage/v2/ConvertFromV3.php b/tests/sample/BlockStorage/v2/ConvertFromV3.php
new file mode 100644
index 000000000..1b24c55c4
--- /dev/null
+++ b/tests/sample/BlockStorage/v2/ConvertFromV3.php
@@ -0,0 +1,33 @@
+markTestSkipped('Block Storage v2 API is not available');
+ }
+ }
+
+ protected function getService(): Service
+ {
+ return $this->getCachedService(Service::class);
+ }
+
+ protected function sampleFile(string $path, array $replacements = []): string
+ {
+ return parent::sampleFile(
+ $path,
+ array_merge(
+ $replacements,
+ ['$openstack->blockStorageV3()' => '$openstack->blockStorageV2()']
+ )
+ );
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/BlockStorage/v2/SnapshotTest.php b/tests/sample/BlockStorage/v2/SnapshotTest.php
new file mode 100644
index 000000000..1edb8d2ed
--- /dev/null
+++ b/tests/sample/BlockStorage/v2/SnapshotTest.php
@@ -0,0 +1,8 @@
+assertNotInstanceOf(Service::class, $this->getService());
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/BlockStorage/v2/VolumeTypeTest.php b/tests/sample/BlockStorage/v2/VolumeTypeTest.php
new file mode 100644
index 000000000..e9d5ba0af
--- /dev/null
+++ b/tests/sample/BlockStorage/v2/VolumeTypeTest.php
@@ -0,0 +1,8 @@
+getService()->createVolume(['name' => $this->randomStr(), 'size' => 1]);
+ $volume->waitUntil('available');
+
+ $name = $this->randomStr();
+ $description = $this->randomStr();
+
+ /** @var Snapshot $snapshot */
+ require_once $this->sampleFile('snapshots/create.php', [
+ '{volumeId}' => $volume->id,
+ '{name}' => $name,
+ '{description}' => $description,
+ ]);
+
+ $this->assertInstanceOf(Snapshot::class, $snapshot);
+ $this->assertEquals($name, $snapshot->name);
+ $this->assertEquals($description, $snapshot->description);
+
+ $snapshot->waitUntil('available');
+
+ return $snapshot;
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testGet(Snapshot $createdSnapshot)
+ {
+ /** @var Snapshot $snapshot */
+ require_once $this->sampleFile('snapshots/get.php', ['{snapshotId}' => $createdSnapshot->id]);
+
+ $this->assertInstanceOf(Snapshot::class, $snapshot);
+ $this->assertEquals($createdSnapshot->id, $snapshot->id);
+ $this->assertNull($snapshot->name);
+
+ $snapshot->retrieve();
+ $this->assertEquals($createdSnapshot->name, $snapshot->name);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testMergeMetadata(Snapshot $createdSnapshot)
+ {
+ $initVal = $this->randomStr();
+ $fooVal = $this->randomStr();
+
+ $createdSnapshot->mergeMetadata(['Init' => $initVal]);
+
+ require_once $this->sampleFile(
+ 'snapshots/merge_metadata.php',
+ [
+ '{snapshotId}' => $createdSnapshot->id,
+ '{key}' => 'Foo',
+ '{val}' => $fooVal,
+ ]
+ );
+
+ $metadata = $createdSnapshot->getMetadata();
+ $this->assertEquals($initVal, $metadata['Init']);
+ $this->assertEquals($fooVal, $metadata['Foo']);
+ }
+
+ /**
+ * @depends testCreate
+ * @depends testMergeMetadata
+ */
+ public function testGetMetadata(Snapshot $createdSnapshot)
+ {
+ /** @var array $metadata */
+ require_once $this->sampleFile('snapshots/get_metadata.php', ['{snapshotId}' => $createdSnapshot->id]);
+
+ $this->assertArrayHasKey('Init', $metadata);
+ $this->assertArrayHasKey('Foo', $metadata);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testResetMetadata(Snapshot $createdSnapshot)
+ {
+ $initVal = $this->randomStr();
+ $fooVal = $this->randomStr();
+
+ $createdSnapshot->mergeMetadata(['Init' => $initVal]);
+
+ require_once $this->sampleFile(
+ 'snapshots/reset_metadata.php',
+ [
+ '{snapshotId}' => $createdSnapshot->id,
+ '{key}' => 'Foo',
+ '{val}' => $fooVal,
+ ]
+ );
+
+ $metadata = $createdSnapshot->getMetadata();
+ $this->assertEquals($fooVal, $metadata['Foo']);
+ $this->assertArrayNotHasKey('Init', $metadata);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testUpdate(Snapshot $createdSnapshot)
+ {
+ $newName = $this->randomStr();
+ $newDescription = $this->randomStr();
+
+ require_once $this->sampleFile('snapshots/update.php', [
+ '{snapshotId}' => $createdSnapshot->id,
+ '{newName}' => $newName,
+ '{newDescription}' => $newDescription,
+ ]);
+
+ $createdSnapshot->retrieve();
+ $this->assertEquals($newName, $createdSnapshot->name);
+ $this->assertEquals($newDescription, $createdSnapshot->description);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testList(Snapshot $createdSnapshot)
+ {
+ $found = false;
+ require_once $this->sampleFile(
+ 'snapshots/list.php',
+ [
+ '/** @var \OpenStack\BlockStorage\v2\Models\Snapshot $snapshot */' => <<<'PHP'
+/** @var \OpenStack\BlockStorage\v2\Models\Snapshot $snapshot */
+if ($snapshot->id === $createdSnapshot->id) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testDelete(Snapshot $createdSnapshot)
+ {
+ $volume = $this->getService()->getVolume($createdSnapshot->volumeId);
+ require_once $this->sampleFile('snapshots/delete.php', ['{snapshotId}' => $createdSnapshot->id]);
+ $createdSnapshot->waitUntilDeleted();
+
+ $volume->delete();
+ $volume->waitUntilDeleted();
+
+ $this->expectException(BadResponseError::class);
+ $createdSnapshot->retrieve();
+ }
+
+ public function testListAsc()
+ {
+ $volume = $this->getService()->createVolume(['name' => $this->randomStr(), 'size' => 1]);
+ $volume->waitUntil('available');
+
+ $postfix = $this->randomStr();
+ $names = ['b' . $postfix, 'a' . $postfix, 'c' . $postfix];
+ $createdSnapshots = [];
+ foreach ($names as $name) {
+ $snapshot = $this->getService()->createSnapshot([
+ 'volumeId' => $volume->id,
+ 'name' => $name,
+ ]);
+
+ $this->assertInstanceOf(Snapshot::class, $snapshot);
+
+ $createdSnapshots[] = $snapshot;
+ }
+
+ foreach ($createdSnapshots as $snapshot) {
+ $snapshot->waitUntil('available');
+ }
+
+ try {
+ $rightOrder = ['a' . $postfix, 'b' . $postfix, 'c' . $postfix];
+ $i = 0;
+ require_once $this->sampleFile('snapshots/list_sorted.php', [
+ '{sortKey}' => 'display_name',
+ '{sortDir}' => 'asc',
+ '/** @var \OpenStack\BlockStorage\v2\Models\Snapshot $snapshot */' => <<<'PHP'
+/** @var \OpenStack\BlockStorage\v2\Models\Snapshot $snapshot */
+if ($snapshot->name === $rightOrder[$i]) {
+ $i++;
+}
+PHP
+ ,
+ ]);
+ $this->assertEquals(3, $i);
+ } finally {
+ foreach ($createdSnapshots as $snapshot) {
+ $snapshot->delete();
+ }
+
+ foreach ($createdSnapshots as $snapshot) {
+ $snapshot->waitUntilDeleted();
+ }
+
+ $volume->delete();
+ $volume->waitUntilDeleted();
+ }
+ }
+
+ public function testListDesc()
+ {
+ $volume = $this->getService()->createVolume(['name' => $this->randomStr(), 'size' => 1]);
+ $volume->waitUntil('available');
+
+ $postfix = $this->randomStr();
+ $names = ['b' . $postfix, 'a' . $postfix, 'c' . $postfix];
+ $createdSnapshots = [];
+ foreach ($names as $name) {
+ $snapshot = $this->getService()->createSnapshot([
+ 'volumeId' => $volume->id,
+ 'name' => $name,
+ ]);
+
+ $this->assertInstanceOf(Snapshot::class, $snapshot);
+
+ $createdSnapshots[] = $snapshot;
+ }
+
+ foreach ($createdSnapshots as $snapshot) {
+ $snapshot->waitUntil('available');
+ }
+
+ try {
+ $rightOrder = ['c' . $postfix, 'b' . $postfix, 'a' . $postfix];
+ $i = 0;
+ require_once $this->sampleFile('snapshots/list_sorted.php', [
+ '{sortKey}' => 'display_name',
+ '{sortDir}' => 'desc',
+ '/** @var \OpenStack\BlockStorage\v2\Models\Snapshot $snapshot */' => <<<'PHP'
+/** @var \OpenStack\BlockStorage\v2\Models\Snapshot $snapshot */
+if ($snapshot->name === $rightOrder[$i]) {
+ $i++;
+}
+PHP
+ ,
+ ]);
+ $this->assertEquals(3, $i);
+ } finally {
+ foreach ($createdSnapshots as $snapshot) {
+ $snapshot->delete();
+ }
+
+ foreach ($createdSnapshots as $snapshot) {
+ $snapshot->waitUntilDeleted();
+ }
+
+ $volume->delete();
+ $volume->waitUntilDeleted();
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/BlockStorage/v3/TestCase.php b/tests/sample/BlockStorage/v3/TestCase.php
new file mode 100644
index 000000000..6796f7ab7
--- /dev/null
+++ b/tests/sample/BlockStorage/v3/TestCase.php
@@ -0,0 +1,17 @@
+getCachedService(\OpenStack\BlockStorage\v3\Service::class);
+ }
+
+ protected function sampleFile(string $path, array $replacements = []): string
+ {
+ return parent::sampleFile("BlockStorage/v3/$path", $replacements);
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/BlockStorage/v3/VolumeTest.php b/tests/sample/BlockStorage/v3/VolumeTest.php
new file mode 100644
index 000000000..d598c26c9
--- /dev/null
+++ b/tests/sample/BlockStorage/v3/VolumeTest.php
@@ -0,0 +1,117 @@
+randomStr();
+
+ $volumeType = $this->getService()->createVolumeType(['name' => $this->randomStr()]);
+
+ /** @var Volume $volume */
+ require_once $this->sampleFile('volumes/create.php', [
+ '{description}' => $this->randomStr(),
+ "'{size}'" => 1,
+ '{name}' => $name,
+ '{volumeType}' => $volumeType->id,
+ '{key1}' => $this->randomStr(),
+ '{val1}' => $this->randomStr(),
+ ]);
+
+ $this->assertInstanceOf(Volume::class, $volume);
+ $this->assertEquals($name, $volume->name);
+ $this->assertEquals(1, $volume->size);
+ $this->assertEquals($volumeType->name, $volume->volumeTypeName);
+
+ $volume->waitUntil('available');
+
+ return $volume;
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testGet(Volume $createdVolume)
+ {
+ /** @var Volume $volume */
+ require_once $this->sampleFile('volumes/get.php', [
+ '{volumeId}' => $createdVolume->id,
+ ]);
+
+ $this->assertInstanceOf(Volume::class, $volume);
+ $this->assertEquals($createdVolume->id, $volume->id);
+ $this->assertNull($volume->description);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testUpdate(Volume $createdVolume)
+ {
+ $newName = $this->randomStr();
+ $newDescription = $this->randomStr();
+
+ require_once $this->sampleFile('volumes/update.php', [
+ '{volumeId}' => $createdVolume->id,
+ '{newName}' => $newName,
+ '{newDescription}' => $newDescription,
+ ]);
+
+ $createdVolume->retrieve();
+ $this->assertEquals($newName, $createdVolume->name);
+ $this->assertEquals($newDescription, $createdVolume->description);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testList(Volume $createdVolume)
+ {
+ $found = false;
+ require_once $this->sampleFile(
+ 'volumes/list.php',
+ [
+ '/** @var \OpenStack\BlockStorage\v2\Models\Volume $volume */' => <<<'PHP'
+/** @var \OpenStack\BlockStorage\v2\Models\Volume $volume */
+if ($volume->id === $createdVolume->id) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testDelete(Volume $createdVolume)
+ {
+ $volumeTypeName = $createdVolume->volumeTypeName;
+
+ require_once $this->sampleFile('volumes/delete.php', [
+ '{volumeId}' => $createdVolume->id,
+ ]);
+ $createdVolume->waitUntilDeleted();
+
+ $found = false;
+ foreach ($this->getService()->listVolumes() as $volume) {
+ if ($volume->id === $createdVolume->id) {
+ $found = true;
+ }
+ }
+ $this->assertFalse($found);
+
+ foreach ($this->getService()->listVolumeTypes() as $volumeType) {
+ if ($volumeType->name === $volumeTypeName) {
+ $volumeType->delete();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/BlockStorage/v3/VolumeTypeTest.php b/tests/sample/BlockStorage/v3/VolumeTypeTest.php
new file mode 100644
index 000000000..94f8f4abc
--- /dev/null
+++ b/tests/sample/BlockStorage/v3/VolumeTypeTest.php
@@ -0,0 +1,94 @@
+randomStr();
+
+ /** @var VolumeType $volumeType */
+ require_once $this->sampleFile('volume_types/create.php', ['{name}' => $name]);
+
+ $this->assertInstanceOf(VolumeType::class, $volumeType);
+ $this->assertEquals($name, $volumeType->name);
+
+ return $volumeType;
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testGet(VolumeType $createdVolumeType)
+ {
+ /** @var VolumeType $volumeType */
+ require_once $this->sampleFile('volume_types/get.php', ['{volumeTypeId}' => $createdVolumeType->id]);
+
+ $this->assertInstanceOf(VolumeType::class, $volumeType);
+ $this->assertEquals($createdVolumeType->id, $volumeType->id);
+ $this->assertNull($volumeType->name);
+
+ $volumeType->retrieve();
+ $this->assertEquals($createdVolumeType->name, $volumeType->name);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testUpdate(VolumeType $createdVolumeType)
+ {
+ $newName = $this->randomStr();
+
+ require_once $this->sampleFile('volume_types/update.php', [
+ '{volumeTypeId}' => $createdVolumeType->id,
+ '{newName}' => $newName,
+ ]);
+
+ $createdVolumeType->retrieve();
+ $this->assertEquals($newName, $createdVolumeType->name);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testList(VolumeType $createdVolumeType)
+ {
+ $found = false;
+ require_once $this->sampleFile(
+ 'volume_types/list.php',
+ [
+ '/** @var \OpenStack\BlockStorage\v2\Models\VolumeType $volumeType */' => <<<'PHP'
+/** @var \OpenStack\BlockStorage\v2\Models\VolumeType $volumeType */
+if ($volumeType->id === $createdVolumeType->id) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testDelete(VolumeType $createdVolumeType)
+ {
+ require_once $this->sampleFile('volume_types/delete.php', ['{volumeTypeId}' => $createdVolumeType->id]);
+
+ foreach ($this->getService()->listVolumeTypes() as $volumeType) {
+ if ($volumeType->id === $createdVolumeType->id) {
+ $this->fail('Volume type still exists');
+ }
+ }
+
+ $this->expectException(BadResponseError::class);
+ $createdVolumeType->retrieve();
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/Compute/v2/FlavorTest.php b/tests/sample/Compute/v2/FlavorTest.php
new file mode 100644
index 000000000..61a4708b6
--- /dev/null
+++ b/tests/sample/Compute/v2/FlavorTest.php
@@ -0,0 +1,72 @@
+randomStr();
+
+ /** @var $flavor \OpenStack\Compute\v2\Models\Flavor */
+ require_once $this->sampleFile('flavors/create_flavor.php', ['{flavorName}' => $name]);
+
+ $this->assertInstanceOf(Flavor::class, $flavor);
+ $this->assertEquals($name, $flavor->name);
+
+ return $flavor;
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testList(Flavor $createdFlavor)
+ {
+ $found = false;
+ require_once $this->sampleFile(
+ 'flavors/list_flavors.php',
+ [
+ '/** @var \OpenStack\Compute\v2\Models\Flavor $flavor */' => <<<'PHP'
+/** @var \OpenStack\Compute\v2\Models\Flavor $flavor */
+if ($flavor->id === $createdFlavor->id) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testGet(Flavor $createdFlavor)
+ {
+ /** @var \OpenStack\Compute\v2\Models\Flavor $flavor */
+ require_once $this->sampleFile('flavors/get_flavor.php', ['{flavorId}' => $createdFlavor->id]);
+
+ $this->assertInstanceOf(Flavor::class, $flavor);
+ $this->assertEquals($createdFlavor->id, $flavor->id);
+ $this->assertEquals($createdFlavor->name, $flavor->name);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testDelete(Flavor $createdFlavor)
+ {
+ require_once $this->sampleFile('flavors/delete_flavor.php', ['{flavorId}' => $createdFlavor->id]);
+
+ foreach ($this->getService()->listFlavors() as $flavor) {
+ $this->assertNotEquals($createdFlavor->id, $flavor->id);
+ }
+
+ $this->expectException(BadResponseError::class);
+ $createdFlavor->retrieve();
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/Compute/v2/HypervisorTest.php b/tests/sample/Compute/v2/HypervisorTest.php
new file mode 100644
index 000000000..acdcba463
--- /dev/null
+++ b/tests/sample/Compute/v2/HypervisorTest.php
@@ -0,0 +1,40 @@
+sampleFile(
+ 'hypervisors/list_hypervisors.php',
+ [
+ '/** @var \OpenStack\Compute\v2\Models\Hypervisor $hypervisor */' => <<<'PHP'
+/** @var \OpenStack\Compute\v2\Models\Hypervisor $hypervisor */
+$this->assertInstanceOf(\OpenStack\Compute\v2\Models\Hypervisor::class, $hypervisor);
+PHP
+ ,
+ ]
+ );
+ }
+
+ public function testGet()
+ {
+ /** @var \OpenStack\Compute\v2\Models\Hypervisor $hypervisor */
+ require_once $this->sampleFile('hypervisors/get_hypervisor.php', ['{hypervisorId}' => '1']);
+
+ $this->assertInstanceOf(Hypervisor::class, $hypervisor);
+ $this->assertEquals(1, $hypervisor->id);
+ }
+
+ public function testGetStatistics()
+ {
+ /** @var \OpenStack\Compute\v2\Models\HypervisorStatistic $hypervisorStatistics */
+ require_once $this->sampleFile('hypervisors/get_hypervisors_statistics.php', []);
+
+ $this->assertInstanceOf(HypervisorStatistic::class, $hypervisorStatistics);
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/Compute/v2/ImageTest.php b/tests/sample/Compute/v2/ImageTest.php
new file mode 100644
index 000000000..b80fbd08e
--- /dev/null
+++ b/tests/sample/Compute/v2/ImageTest.php
@@ -0,0 +1,171 @@
+createServer();
+
+ $name = $this->randomStr();
+ $replacements = [
+ '{serverId}' => $createdServer->id,
+ '{imageName}' => $name,
+ ];
+
+ require_once $this->sampleFile('images/create_server_image.php', $replacements);
+
+ $createdImage = null;
+ foreach ($this->getService()->listImages() as $image) {
+ if ($image->name === $name) {
+ $createdImage = $image;
+ break;
+ }
+ }
+
+ $this->assertNotNull($createdImage);
+ $createdImage->retrieve();
+
+ $createdImage->waitUntil('ACTIVE');
+ $this->assertEquals('ACTIVE', $createdImage->status);
+
+ $this->deleteServer($createdServer);
+ return $createdImage;
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testList(Image $createdImage)
+ {
+ $found = false;
+ require_once $this->sampleFile(
+ 'images/list_images.php',
+ [
+ '/** @var \OpenStack\Compute\v2\Models\Image $image */' => <<<'PHP'
+/** @var \OpenStack\Compute\v2\Models\Image $image */
+if ($image->id === $createdImage->id) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testGet(Image $createdImage)
+ {
+ /** @var \OpenStack\Compute\v2\Models\Image $image */
+ require_once $this->sampleFile('images/get_image.php', ['{imageId}' => $createdImage->id]);
+
+ $this->assertInstanceOf(Image::class, $image);
+ $this->assertEquals($createdImage->id, $image->id);
+ $this->assertEquals($createdImage->name, $image->name);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testMergeMetadata(Image $createdImage)
+ {
+ $initVal = $this->randomStr();
+ $fooVal = $this->randomStr();
+
+ $createdImage->mergeMetadata(['Init' => $initVal]);
+
+ require_once $this->sampleFile(
+ 'images/merge_image_metadata.php',
+ [
+ '{imageId}' => $createdImage->id,
+ '{key}' => 'Foo',
+ '{value}' => $fooVal,
+ ]
+ );
+
+ $metadata = $createdImage->getMetadata();
+ $this->assertEquals($initVal, $metadata['Init']);
+ $this->assertEquals($fooVal, $metadata['Foo']);
+ }
+
+ /**
+ * @depends testCreate
+ * @depends testMergeMetadata
+ */
+ public function testGetMetadata(Image $createdImage)
+ {
+ /** @var array $metadata */
+ require_once $this->sampleFile('images/retrieve_image_metadata.php', ['{imageId}' => $createdImage->id]);
+
+ $this->assertArrayHasKey('Init', $metadata);
+ $this->assertArrayHasKey('Foo', $metadata);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testResetMetadata(Image $createdImage)
+ {
+ $initVal = $this->randomStr();
+ $fooVal = $this->randomStr();
+
+ $createdImage->mergeMetadata(['Init' => $initVal]);
+
+ require_once $this->sampleFile(
+ 'images/reset_image_metadata.php',
+ [
+ '{imageId}' => $createdImage->id,
+ '{key}' => 'Foo',
+ '{value}' => $fooVal,
+ ]
+ );
+
+ $metadata = $createdImage->getMetadata();
+ $this->assertEquals($fooVal, $metadata['Foo']);
+ $this->assertArrayNotHasKey('Init', $metadata);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testDeleteMetadata(Image $createdImage)
+ {
+ $createdImage->mergeMetadata(['Init' => $this->randomStr(), 'Init2' => $this->randomStr()]);
+
+ require_once $this->sampleFile(
+ 'images/delete_image_metadata_item.php',
+ [
+ '{imageId}' => $createdImage->id,
+ '{key}' => 'Init',
+ ]
+ );
+
+ $metadata = $createdImage->getMetadata();
+ $this->assertArrayNotHasKey('Init', $metadata);
+ $this->assertArrayHasKey('Init2', $metadata);
+ }
+
+
+ /**
+ * @depends testCreate
+ */
+ public function testDelete(Image $createdImage)
+ {
+ require_once $this->sampleFile('images/delete_image.php', ['{imageId}' => $createdImage->id]);
+
+ foreach ($this->getService()->listImages() as $image) {
+ $this->assertNotEquals($createdImage->id, $image->id);
+ }
+
+ $this->expectException(BadResponseError::class);
+ $createdImage->retrieve();
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/Compute/v2/InterfaceAttachmentTest.php b/tests/sample/Compute/v2/InterfaceAttachmentTest.php
new file mode 100644
index 000000000..f635bd7ba
--- /dev/null
+++ b/tests/sample/Compute/v2/InterfaceAttachmentTest.php
@@ -0,0 +1,43 @@
+createServer();
+ $network = $this->getServiceNetwork()->createNetwork(['name' => $this->randomStr()]);
+ $this->getServiceNetwork()->createSubnet(
+ [
+ 'name' => $this->randomStr(),
+ 'networkId' => $network->id,
+ 'ipVersion' => 4,
+ 'cidr' => '10.20.40.0/24',
+ ]
+ );
+
+
+ $replacements = [
+ '{serverId}' => $server->id,
+ '{networkId}' => $network->id,
+ ];
+
+ /** @var \OpenStack\Networking\v2\Models\InterfaceAttachment $interfaceAttachment */
+ require_once $this->sampleFile('servers/create_interface_attachment.php', $replacements);
+
+ $this->assertInstanceOf(InterfaceAttachment::class, $interfaceAttachment);
+ $this->assertEquals($network->id, $interfaceAttachment->netId);
+
+ $port = $this->getServiceNetwork()->getPort($interfaceAttachment->portId);
+ $port->retrieve();
+
+ $server->detachInterface($interfaceAttachment->portId);
+ $port->waitUntilDeleted();
+
+ $this->deleteNetwork($network);
+ $this->deleteServer($server);
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/Compute/v2/KeypairTest.php b/tests/sample/Compute/v2/KeypairTest.php
new file mode 100644
index 000000000..a084e7ef0
--- /dev/null
+++ b/tests/sample/Compute/v2/KeypairTest.php
@@ -0,0 +1,80 @@
+randomStr();
+ $publicKey = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCp4H/vDGnLi0QgWgMsQkv//FEz0xgv/mujVX+XCh6fHXxc/PbaASY+MsoI2Xr238cG9eaeAAUvbpJuEuHQ0M9WX97bvsWaWzLQ9F6hzLAwUBGxcG8cSh1nB3Ah7alR2nbIZ1N94yE72hXLb1AGogJ97NBVIph438BCXUNejqoOBsXL8UBP3RGdPnTHJ/6XSMaNTQAJruQMoQwecyGFQmuS2IEy2mBOmSldD6JZirHpj7PTCKJY4CS89QChGpKIeOymKn4tEQQVVtNFUyULEMdin88H1yMftPfq7QqH+ULFT2X2XvP3CI+sESq84lrIcVu7LjJCRIwlKsnMu2ESYCdz foo@bar.com';
+
+ /** @var Keypair $keypair */
+ require_once $this->sampleFile(
+ 'keypairs/create_keypair.php',
+ [
+ '{name}' => $name,
+ '{publicKey}' => $publicKey,
+ ]
+ );
+
+ $this->assertInstanceOf(Keypair::class, $keypair);
+ $this->assertEquals($name, $keypair->name);
+ $this->assertEquals($publicKey, $keypair->publicKey);
+
+ return $keypair;
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testList(Keypair $createdKeypair)
+ {
+ $found = false;
+ require_once $this->sampleFile(
+ 'keypairs/list_keypairs.php',
+ [
+ '/** @var \OpenStack\Compute\v2\Models\Keypair $keypair */' => <<<'PHP'
+/** @var \OpenStack\Compute\v2\Models\Keypair $keypair */
+if ($keypair->id === $createdKeypair->id) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testGet(Keypair $createdKeypair)
+ {
+ /** @var \OpenStack\Compute\v2\Models\Keypair $keypair */
+ require_once $this->sampleFile('keypairs/get_keypair.php', ['{name}' => $createdKeypair->name]);
+
+ $this->assertInstanceOf(Keypair::class, $keypair);
+ $this->assertEquals($createdKeypair->name, $keypair->name);
+ }
+
+
+ /**
+ * @depends testCreate
+ */
+ public function testDelete(Keypair $createdKeypair)
+ {
+ require_once $this->sampleFile('keypairs/delete_keypair.php', ['{name}' => $createdKeypair->name]);
+
+ foreach ($this->getService()->listKeypairs() as $keypair) {
+ $this->assertNotEquals($createdKeypair->name, $keypair->name);
+ }
+
+ $this->expectException(BadResponseError::class);
+ $createdKeypair->retrieve();
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/Compute/v2/LimitTest.php b/tests/sample/Compute/v2/LimitTest.php
new file mode 100644
index 000000000..92ef30a98
--- /dev/null
+++ b/tests/sample/Compute/v2/LimitTest.php
@@ -0,0 +1,16 @@
+sampleFile('limits/get_limits.php', []);
+
+ $this->assertInstanceOf(Limit::class, $limit);
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/Compute/v2/SecurityGroupTest.php b/tests/sample/Compute/v2/SecurityGroupTest.php
new file mode 100644
index 000000000..13fc26f4b
--- /dev/null
+++ b/tests/sample/Compute/v2/SecurityGroupTest.php
@@ -0,0 +1,82 @@
+createServer();
+ $createdSecurityGroup = $this->getCachedService(Service::class)
+ ->createSecurityGroup(['name' => $this->randomStr()]);
+
+ $replacements = [
+ '{serverId}' => $createdServer->id,
+ '{secGroupName}' => $createdSecurityGroup->name,
+ ];
+
+ require_once $this->sampleFile('servers/add_security_group.php', $replacements);
+
+ $found = false;
+ foreach ($createdServer->listSecurityGroups() as $securityGroup) {
+ if ($securityGroup->name === $createdSecurityGroup->name) {
+ $found = true;
+ }
+ }
+ $this->assertTrue($found);
+
+ return [$createdServer, $createdSecurityGroup];
+ }
+
+
+ /**
+ * @depends testAdd
+ */
+ public function testList(array $data)
+ {
+ $found = false;
+ require_once $this->sampleFile(
+ 'servers/list_security_groups.php',
+ [
+ '{serverId}' => $data[0]->id,
+ '/** @var \OpenStack\Networking\v2\Extensions\SecurityGroups\Models\SecurityGroup $securityGroup */' => <<<'PHP'
+/** @var \OpenStack\Networking\v2\Extensions\SecurityGroups\Models\SecurityGroup $securityGroup */
+if($securityGroup->name === $data[1]->name) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testRemove(array $data)
+ {
+ require_once $this->sampleFile('servers/remove_security_group.php', [
+ '{serverId}' => $data[0]->id,
+ '{secGroupName}' => $data[1]->name,
+ ]);
+
+ $found = false;
+ foreach ($data[0]->listSecurityGroups() as $securityGroup) {
+ if ($securityGroup->name === $data[1]->name) {
+ $found = true;
+ }
+ }
+ $this->assertFalse($found);
+
+ $data[1]->delete();
+ $data[0]->delete();
+ }
+
+}
\ No newline at end of file
diff --git a/tests/sample/Compute/v2/ServerTest.php b/tests/sample/Compute/v2/ServerTest.php
new file mode 100644
index 000000000..e1f1c7a4a
--- /dev/null
+++ b/tests/sample/Compute/v2/ServerTest.php
@@ -0,0 +1,365 @@
+getServiceNetwork()->createNetwork(['name' => $this->randomStr()]);
+ $this->getServiceNetwork()->createSubnet(
+ [
+ 'name' => $this->randomStr(),
+ 'networkId' => $network->id,
+ 'ipVersion' => 4,
+ 'cidr' => '10.20.30.0/24',
+ ]
+ );
+
+ $replacements = [
+ '{serverName}' => $this->randomStr(),
+ '{imageId}' => $this->searchImageId(),
+ '{flavorId}' => $flavorId,
+ '{networkId}' => $network->id,
+ ];
+
+ /** @var $server \OpenStack\Compute\v2\Models\Server */
+ require_once $this->sampleFile('servers/create_server.php', $replacements);
+
+ $server->waitUntilActive();
+
+ $this->assertInstanceOf(Server::class, $server);
+ $this->assertNotEmpty($server->id);
+ $this->assertNotEmpty($server->adminPass);
+
+ return $server;
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testUpdate(Server $createdServer)
+ {
+ $newName = $this->randomStr();
+
+ require_once $this->sampleFile('servers/update_server.php', [
+ '{serverId}' => $createdServer->id,
+ '{newName}' => $newName,
+ ]);
+
+ $createdServer->waitUntilActive(60);
+ $createdServer->retrieve();
+
+ $this->assertEquals($newName, $createdServer->name);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testGet(Server $createdServer)
+ {
+ /** @var \OpenStack\Compute\v2\Models\Server $server */
+ require_once $this->sampleFile('servers/get_server.php', ['{serverId}' => $createdServer->id]);
+
+ $this->assertInstanceOf(Server::class, $server);
+ $this->assertEquals($createdServer->id, $server->id);
+ $this->assertEquals($createdServer->name, $server->name);
+ $this->assertNotNull($server->created);
+ $this->assertNotNull($server->updated);
+ $this->assertNotNull($server->name);
+ $this->assertNotNull($server->ipv4);
+ $this->assertNotNull($server->status);
+ $this->assertInstanceOf(Image::class, $server->image);
+ $this->assertInstanceOf(Flavor::class, $server->flavor);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testMergeMetadata(Server $createdServer)
+ {
+ $initVal = $this->randomStr();
+ $fooVal = $this->randomStr();
+
+ $createdServer->mergeMetadata(['Init' => $initVal]);
+
+ require_once $this->sampleFile(
+ 'servers/merge_server_metadata.php',
+ [
+ '{serverId}' => $createdServer->id,
+ '{key}' => 'Foo',
+ '{value}' => $fooVal,
+ ]
+ );
+
+ $metadata = $createdServer->getMetadata();
+ $this->assertEquals($initVal, $metadata['Init']);
+ $this->assertEquals($fooVal, $metadata['Foo']);
+ }
+
+ /**
+ * @depends testCreate
+ * @depends testMergeMetadata
+ */
+ public function testGetMetadata(Server $createdServer)
+ {
+ /** @var array $metadata */
+ require_once $this->sampleFile('servers/get_server_metadata.php', ['{serverId}' => $createdServer->id]);
+
+ $this->assertArrayHasKey('Init', $metadata);
+ $this->assertArrayHasKey('Foo', $metadata);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testResetMetadata(Server $createdServer)
+ {
+ $initVal = $this->randomStr();
+ $fooVal = $this->randomStr();
+
+ $createdServer->mergeMetadata(['Init' => $initVal]);
+
+ require_once $this->sampleFile(
+ 'servers/reset_server_metadata.php',
+ [
+ '{serverId}' => $createdServer->id,
+ '{key}' => 'Foo',
+ '{value}' => $fooVal,
+ ]
+ );
+
+ $metadata = $createdServer->getMetadata();
+ $this->assertEquals($fooVal, $metadata['Foo']);
+ $this->assertArrayNotHasKey('Init', $metadata);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testDeleteMetadata(Server $createdServer)
+ {
+ $createdServer->mergeMetadata(['Init' => $this->randomStr(), 'Init2' => $this->randomStr()]);
+
+ require_once $this->sampleFile(
+ 'servers/delete_server_metadata_item.php',
+ [
+ '{serverId}' => $createdServer->id,
+ '{key}' => 'Init',
+ ]
+ );
+
+ $metadata = $createdServer->getMetadata();
+ $this->assertArrayNotHasKey('Init', $metadata);
+ $this->assertArrayHasKey('Init2', $metadata);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testStop(Server $createdServer)
+ {
+ require_once $this->sampleFile('servers/stop_server.php', ['{serverId}' => $createdServer->id]);
+
+ $createdServer->waitUntil('SHUTOFF');
+ $this->assertEquals('SHUTOFF', $createdServer->status);
+ }
+
+ /**
+ * @depends testCreate
+ * @depends testStop
+ */
+ public function testStart(Server $createdServer)
+ {
+ require_once $this->sampleFile('servers/start_server.php', ['{serverId}' => $createdServer->id]);
+
+ $createdServer->waitUntil('ACTIVE');
+ $this->assertEquals('ACTIVE', $createdServer->status);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testRevertResize(Server $createdServer)
+ {
+ $flavorId = getenv('OS_RESIZE_FLAVOR');
+
+ if (!$flavorId) {
+ throw new RuntimeException('OS_RESIZE_FLAVOR env var must be set');
+ }
+
+ $createdServer->resize($flavorId);
+ $createdServer->waitUntil('VERIFY_RESIZE');
+
+ require_once $this->sampleFile('servers/revert_server_resize.php', ['{serverId}' => $createdServer->id]);
+
+ $createdServer->waitUntil('ACTIVE');
+ $this->assertEquals('ACTIVE', $createdServer->status);
+ $this->assertEquals($createdServer->flavor->id, getenv('OS_FLAVOR'));
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testResize(Server $createdServer)
+ {
+ $flavorId = getenv('OS_RESIZE_FLAVOR');
+
+ if (!$flavorId) {
+ throw new RuntimeException('OS_RESIZE_FLAVOR env var must be set');
+ }
+
+ require_once $this->sampleFile(
+ 'servers/resize_server.php',
+ [
+ '{serverId}' => $createdServer->id,
+ '{flavorId}' => $flavorId,
+ ]
+ );
+
+ $createdServer->waitUntil('VERIFY_RESIZE');
+ $this->assertEquals('VERIFY_RESIZE', $createdServer->status);
+ }
+
+ /**
+ * @depends testCreate
+ * @depends testResize
+ */
+ public function testConfirmResize(Server $createdServer)
+ {
+ require_once $this->sampleFile('servers/confirm_server_resize.php', ['{serverId}' => $createdServer->id]);
+
+ $createdServer->waitUntil('ACTIVE');
+ $this->assertEquals('ACTIVE', $createdServer->status);
+ $this->assertEquals($createdServer->flavor->id, getenv('OS_RESIZE_FLAVOR'));
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testRebuild(Server $createdServer)
+ {
+ $newName = $this->randomStr();
+
+ require_once $this->sampleFile(
+ 'servers/rebuild_server.php',
+ [
+ '{serverId}' => $createdServer->id,
+ '{imageId}' => $this->searchImageId(),
+ '{newName}' => $newName,
+ '{adminPass}' => $this->randomStr(),
+ ]
+ );
+
+ $createdServer->waitUntilActive(60);
+ $this->assertEquals($newName, $createdServer->name);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testRescue(Server $createdServer)
+ {
+ require_once $this->sampleFile(
+ 'servers/rescue_server.php',
+ [
+ '{serverId}' => $createdServer->id,
+ '{imageId}' => $this->searchImageId(),
+ '{adminPass}' => $this->randomStr(),
+ ]
+ );
+
+ $createdServer->waitUntil('RESCUE');
+ $this->assertEquals('RESCUE', $createdServer->status);
+ }
+
+ /**
+ * @depends testCreate
+ * @depends testRescue
+ */
+ public function testUnrescue(Server $createdServer)
+ {
+ require_once $this->sampleFile('servers/unrescue_server.php', ['{serverId}' => $createdServer->id]);
+
+ $createdServer->waitUntil('ACTIVE');
+ $this->assertEquals('ACTIVE', $createdServer->status);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testReboot(Server $createdServer)
+ {
+ require_once $this->sampleFile('servers/reboot_server.php', ['{serverId}' => $createdServer->id]);
+
+ $createdServer->retrieve();
+ $this->assertEquals('HARD_REBOOT', $createdServer->status);
+
+ $createdServer->waitUntil('ACTIVE', 240);
+ $this->assertEquals('ACTIVE', $createdServer->status);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testGetVncConsole(Server $createdServer)
+ {
+ /** @var array $console */
+ require_once $this->sampleFile('servers/get_server_vnc_console.php', [
+ '{serverId}' => $createdServer->id
+ ]);
+
+ $this->assertIsArray($console);
+ $this->assertArrayHasKey('url', $console);
+ $this->assertArrayHasKey('type', $console);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testGetConsoleOutput(Server $createdServer)
+ {
+ /** @var string $consoleOutput */
+ require_once $this->sampleFile('servers/get_server_console_output.php', ['{serverId}' => $createdServer->id]);
+
+ $this->assertIsString($consoleOutput);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testDelete(Server $createdServer)
+ {
+ require_once $this->sampleFile('servers/delete_server.php', ['{serverId}' => $createdServer->id]);
+
+ // Needed so that subnet and network can be removed
+ $createdServer->waitUntilDeleted();
+
+ foreach ($this->getService()->listServers() as $server) {
+ if ($server->id === $createdServer->id) {
+ $this->fail('Server was not deleted');
+ }
+ }
+
+ foreach (array_keys($createdServer->addresses) as $networkName) {
+ $network = $this->getServiceNetwork()->listNetworks(['name' => $networkName])->current();
+ $this->deleteNetwork($network);
+ }
+
+ $this->expectException(BadResponseError::class);
+ $createdServer->retrieve();
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/Compute/v2/TestCase.php b/tests/sample/Compute/v2/TestCase.php
new file mode 100644
index 000000000..914b939c9
--- /dev/null
+++ b/tests/sample/Compute/v2/TestCase.php
@@ -0,0 +1,111 @@
+getCachedService(Service::class);
+ }
+
+ protected function getServiceNetwork(): \OpenStack\Networking\v2\Service
+ {
+ return $this->getCachedService(\OpenStack\Networking\v2\Service::class);
+ }
+
+ protected function searchImageId(): string
+ {
+ foreach ($this->getService()->listImages() as $image) {
+ if (str_starts_with($image->name, 'cirros')) {
+ return $image->id;
+ }
+ }
+
+ throw new RuntimeException('Unable to find image "cirros". Make sure this image is available for integration test.');
+ }
+
+ protected function sampleFile(string $path, array $replacements = []): string
+ {
+ return parent::sampleFile("Compute/v2/$path", $replacements);
+ }
+
+ /**
+ * Creates a server and all dependencies for testing
+ */
+ protected function createServer(): Server
+ {
+ $flavorId = getenv('OS_FLAVOR');
+
+ if (!$flavorId) {
+ throw new RuntimeException('OS_FLAVOR env var must be set');
+ }
+
+ $network = $this->getServiceNetwork()->createNetwork(['name' => $this->randomStr()]);
+ $this->getServiceNetwork()->createSubnet(
+ [
+ 'name' => $this->randomStr(),
+ 'networkId' => $network->id,
+ 'ipVersion' => 4,
+ 'cidr' => '10.20.30.0/24',
+ ]
+ );
+
+ $server = $this->getService()->createServer(
+ [
+ 'name' => $this->randomStr(),
+ 'imageId' => $this->searchImageId(),
+ 'flavorId' => $flavorId,
+ 'networks' => [
+ ['uuid' => $network->id],
+ ],
+ ]
+ );
+
+ $server->waitUntilActive(60);
+
+ return $server;
+ }
+
+ /**
+ * Deletes server and all dependencies
+ */
+ protected function deleteServer(Server $server): void
+ {
+ $server->delete();
+ $server->waitUntilDeleted();
+
+ foreach (array_keys($server->addresses) as $networkName) {
+ $network = $this->getServiceNetwork()->listNetworks(['name' => $networkName])->current();
+ $this->deleteNetwork($network);
+ }
+ }
+
+ /**
+ * Deletes network and all dependencies
+ */
+ protected function deleteNetwork(Network $network): void
+ {
+ foreach ($network->subnets as $subnetId) {
+ $subnet = $this->getServiceNetwork()->getSubnet($subnetId);
+ $subnet->delete();
+ }
+
+ foreach ($this->getServiceNetwork()->listPorts(['networkId' => $network->id]) as $port) {
+ if ($port->deviceOwner) {
+ continue;
+ }
+
+ $port->delete();
+ $port->waitUntilDeleted();
+ }
+
+ $network->delete();
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/Compute/v2/VolumeAttachmentTest.php b/tests/sample/Compute/v2/VolumeAttachmentTest.php
new file mode 100644
index 000000000..1f11190f4
--- /dev/null
+++ b/tests/sample/Compute/v2/VolumeAttachmentTest.php
@@ -0,0 +1,85 @@
+createServer();
+
+ $volume = $this->getCachedService(Service::class)->createVolume(
+ [
+ 'name' => $this->randomStr(),
+ 'description' => '',
+ 'size' => 1,
+ ]
+ );
+ $volume->waitUntil('available');
+ $this->assertEquals('available', $volume->status);
+
+ /** @var \OpenStack\BlockStorage\v2\Models\VolumeAttachment $volumeAttachment */
+ require_once $this->sampleFile('servers/attach_volume_attachment.php', [
+ '{serverId}' => $server->id,
+ '{volumeId}' => $volume->id,
+ ]);
+
+ $this->assertInstanceOf(VolumeAttachment::class, $volumeAttachment);
+
+ $volume->waitUntil('in-use');
+ $this->assertEquals('in-use', $volume->status);
+
+ return $volumeAttachment;
+ }
+
+ /**
+ * @depends testAttach
+ */
+ public function testList(VolumeAttachment $createdVolumeAttachment)
+ {
+ $found = false;
+ require_once $this->sampleFile(
+ 'servers/list_volume_attachments.php',
+ [
+ '{serverId}' => $createdVolumeAttachment->serverId,
+ '/** @var \OpenStack\BlockStorage\v2\Models\VolumeAttachment $volumeAttachment */' => <<<'PHP'
+/** @var \OpenStack\BlockStorage\v2\Models\VolumeAttachment $volumeAttachment */
+if ($volumeAttachment->id === $createdVolumeAttachment->id) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testAttach
+ */
+ public function testDetach(VolumeAttachment $createdVolumeAttachment)
+ {
+ require_once $this->sampleFile(
+ 'servers/detach_volume_attachment.php',
+ [
+ '{serverId}' => $createdVolumeAttachment->serverId,
+ '{volumeAttachmentId}' => $createdVolumeAttachment->id,
+ ]
+ );
+
+ $volume = $this->getCachedService(Service::class)->getVolume($createdVolumeAttachment->volumeId);
+ $volume->waitUntil('available');
+ $this->assertEquals('available', $volume->status);
+
+ $server = $this->getService()->getServer(['id' => $createdVolumeAttachment->serverId]);
+ foreach ($server->listVolumeAttachments() as $volumeAttachment) {
+ $this->assertNotEquals($createdVolumeAttachment->id, $volumeAttachment->id);
+ }
+
+ $volume->delete();
+ $this->deleteServer($server);
+ }
+}
\ No newline at end of file
diff --git a/tests/integration/DefaultLogger.php b/tests/sample/DefaultLogger.php
similarity index 92%
rename from tests/integration/DefaultLogger.php
rename to tests/sample/DefaultLogger.php
index aa3e1a2c0..b7b87c1ca 100644
--- a/tests/integration/DefaultLogger.php
+++ b/tests/sample/DefaultLogger.php
@@ -1,6 +1,6 @@
randomStr();
+ $description = $this->randomStr();
+
+ /** @var $applicationCredential \OpenStack\Identity\v3\Models\ApplicationCredential */
+ require_once $this->sampleFile(
+ 'application_credentials/add_application_credential.php',
+ [
+ '{name}' => $name,
+ '{description}' => $description,
+ ]
+ );
+
+ $this->assertInstanceOf(Models\ApplicationCredential::class, $applicationCredential);
+ $this->assertEquals($name, $applicationCredential->name);
+ $this->assertEquals($description, $applicationCredential->description);
+
+ return $applicationCredential;
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testGenerateToken(ApplicationCredential $applicationCredential)
+ {
+ /** @var $token \OpenStack\Identity\v3\Models\Token */
+ require_once $this->sampleFile(
+ 'tokens/generate_token_with_application_credential_id.php',
+ [
+ '{applicationCredentialId}' => $applicationCredential->id,
+ '{secret}' => $applicationCredential->secret,
+ ]
+ );
+
+ $this->assertInstanceOf(Models\Token::class, $token);
+ $this->assertTrue($token->validate());
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testRetrieve(ApplicationCredential $originalApplicationCredential)
+ {
+ /** @var $applicationCredential \OpenStack\Identity\v3\Models\ApplicationCredential */
+ require_once $this->sampleFile(
+ 'application_credentials/show_application_credential.php',
+ ['{applicationCredentialId}' => $originalApplicationCredential->id]
+ );
+
+ $this->assertInstanceOf(Models\ApplicationCredential::class, $applicationCredential);
+ $this->assertEquals($originalApplicationCredential->name, $applicationCredential->name);
+ $this->assertEquals($originalApplicationCredential->description, $applicationCredential->description);
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testDelete(ApplicationCredential $applicationCredential)
+ {
+ $token = $this->getService()->generateToken([
+ 'application_credential' => [
+ 'id' => $applicationCredential->id,
+ 'secret' => $applicationCredential->secret,
+ ]
+ ]);
+
+ $this->assertTrue($token->validate());
+
+ require_once $this->sampleFile(
+ 'application_credentials/delete_application_credential.php',
+ [
+ '{applicationCredentialId}' => $applicationCredential->id,
+ ]
+ );
+
+ $this->assertFalse($token->validate());
+ }
+
+}
\ No newline at end of file
diff --git a/tests/sample/Identity/v3/DomainTest.php b/tests/sample/Identity/v3/DomainTest.php
new file mode 100644
index 000000000..d852f2ad7
--- /dev/null
+++ b/tests/sample/Identity/v3/DomainTest.php
@@ -0,0 +1,278 @@
+randomStr();
+ $description = $this->randomStr();
+
+ /** @var $domain \OpenStack\Identity\v3\Models\Domain */
+ require_once $this->sampleFile(
+ 'domains/add_domain.php',
+ [
+ '{name}' => $name,
+ '{description}' => $description,
+ ]
+ );
+ $this->assertInstanceOf(Domain::class, $domain);
+ $this->assertEquals($name, $domain->name);
+ $this->assertEquals($description, $domain->description);
+
+ return $domain;
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testList(Domain $createdDomain)
+ {
+ $found = false;
+ require_once $this->sampleFile(
+ 'domains/list_domains.php',
+ [
+ '/** @var $domain \OpenStack\Identity\v3\Models\Domain */' => <<<'PHP'
+/** @var $domain \OpenStack\Identity\v3\Models\Domain */
+if ($domain->id === $createdDomain->id) {
+ $found = true;
+}
+PHP,
+ ]
+ );
+
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testShow(Domain $createdDomain)
+ {
+ /** @var $domain \OpenStack\Identity\v3\Models\Domain */
+ require_once $this->sampleFile('domains/show_domain.php', ['{domainId}' => $createdDomain->id]);
+ $this->assertInstanceOf(Domain::class, $domain);
+ $this->assertEquals($createdDomain->id, $domain->id);
+ $this->assertEquals($createdDomain->name, $domain->name);
+ $this->assertEquals($createdDomain->description, $domain->description);
+ }
+
+
+ /**
+ * @depends testCreate
+ */
+ public function testGrantGroupRole(Domain $createdDomain): array
+ {
+ $createdRole = $this->getService()->createRole(['name' => $this->randomStr()]);
+ $createdGroup = $this->getService()->createGroup(['name' => $this->randomStr(), 'domainId' => $createdDomain->id]);
+
+ $this->assertFalse($createdDomain->checkGroupRole(['groupId' => $createdGroup->id, 'roleId' => $createdRole->id]));
+
+ require_once $this->sampleFile(
+ 'domains/grant_group_role.php',
+ [
+ '{domainId}' => $createdDomain->id,
+ '{roleId}' => $createdRole->id,
+ '{groupId}' => $createdGroup->id,
+ ]
+ );
+
+ $this->assertTrue($createdDomain->checkGroupRole(['groupId' => $createdGroup->id, 'roleId' => $createdRole->id]));
+
+ return [$createdRole, $createdGroup];
+ }
+
+ /**
+ * @depends testCreate
+ * @depends testGrantGroupRole
+ */
+ public function testCheckGroupRole(Domain $createdDomain, array $createdRoleAndGroup)
+ {
+ [$createdRole, $createdGroup] = $createdRoleAndGroup;
+
+ /** @var $result bool */
+ require_once $this->sampleFile(
+ 'domains/check_group_role.php',
+ [
+ '{domainId}' => $createdDomain->id,
+ '{roleId}' => $createdRole->id,
+ '{groupId}' => $createdGroup->id,
+ ]
+ );
+ self::assertTrue($result);
+ }
+
+ /**
+ * @depends testCreate
+ * @depends testGrantGroupRole
+ */
+ public function testListGroupRole(Domain $createdDomain, array $createdRoleAndGroup)
+ {
+ [$createdRole, $createdGroup] = $createdRoleAndGroup;
+
+ $found = false;
+ require_once $this->sampleFile(
+ 'domains/list_group_roles.php',
+ [
+ '{domainId}' => $createdDomain->id,
+ '{groupId}' => $createdGroup->id,
+ '/** @var $role \OpenStack\Identity\v3\Models\Role */' => <<<'PHP'
+/** @var $role \OpenStack\Identity\v3\Models\Role */
+if ($role->id === $createdRole->id) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testCreate
+ * @depends testGrantGroupRole
+ */
+ public function testRevokeGroupRole(Domain $createdDomain, array $createdRoleAndGroup)
+ {
+ [$createdRole, $createdGroup] = $createdRoleAndGroup;
+
+ $this->assertTrue($createdDomain->checkGroupRole(['groupId' => $createdGroup->id, 'roleId' => $createdRole->id]));
+
+ require_once $this->sampleFile(
+ 'domains/revoke_group_role.php',
+ [
+ '{domainId}' => $createdDomain->id,
+ '{roleId}' => $createdRole->id,
+ '{groupId}' => $createdGroup->id,
+ ]
+ );
+
+ $this->assertFalse($createdDomain->checkGroupRole(['groupId' => $createdGroup->id, 'roleId' => $createdRole->id]));
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testGrantUserRole(Domain $createdDomain): array
+ {
+ $createdRole = $this->getService()->createRole(['name' => $this->randomStr()]);
+ $createdUser = $this->getService()->createUser(['name' => $this->randomStr(), 'domainId' => $createdDomain->id]);
+
+ $this->assertFalse($createdDomain->checkUserRole(['userId' => $createdUser->id, 'roleId' => $createdRole->id]));
+
+ require_once $this->sampleFile(
+ 'domains/grant_user_role.php',
+ [
+ '{domainId}' => $createdDomain->id,
+ '{roleId}' => $createdRole->id,
+ '{domainUserId}' => $createdUser->id,
+ ]
+ );
+
+ $this->assertTrue($createdDomain->checkUserRole(['userId' => $createdUser->id, 'roleId' => $createdRole->id]));
+ return [$createdRole, $createdUser];
+ }
+
+ /**
+ * @depends testCreate
+ * @depends testGrantUserRole
+ */
+ public function testCheckUserRole(Domain $createdDomain, array $createdRoleAndUser)
+ {
+ [$createdRole, $createdUser] = $createdRoleAndUser;
+
+ /** @var $result bool */
+ require_once $this->sampleFile(
+ 'domains/check_user_role.php',
+ [
+ '{domainId}' => $createdDomain->id,
+ '{roleId}' => $createdRole->id,
+ '{domainUserId}' => $createdUser->id,
+ ]
+ );
+ self::assertTrue($result);
+ }
+
+ /**
+ * @depends testCreate
+ * @depends testGrantUserRole
+ */
+ public function testListUserRole(Domain $createdDomain, array $createdRoleAndUser)
+ {
+ [$createdRole, $createdUser] = $createdRoleAndUser;
+
+ $found = false;
+ require_once $this->sampleFile(
+ 'domains/list_user_roles.php',
+ [
+ '{domainId}' => $createdDomain->id,
+ '{domainUserId}' => $createdUser->id,
+ '/** @var $role \OpenStack\Identity\v3\Models\Role */' => <<<'PHP'
+/** @var $role \OpenStack\Identity\v3\Models\Role */
+if ($role->id === $createdRole->id) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testCreate
+ * @depends testGrantUserRole
+ */
+ public function testRevokeUserRole(Domain $createdDomain, array $createdRoleAndUser)
+ {
+ [$createdRole, $createdUser] = $createdRoleAndUser;
+
+ $this->assertTrue($createdDomain->checkUserRole(['userId' => $createdUser->id, 'roleId' => $createdRole->id]));
+
+ require_once $this->sampleFile(
+ 'domains/revoke_user_role.php',
+ [
+ '{domainId}' => $createdDomain->id,
+ '{roleId}' => $createdRole->id,
+ '{domainUserId}' => $createdUser->id,
+ ]
+ );
+
+ $this->assertFalse($createdDomain->checkUserRole(['userId' => $createdUser->id, 'roleId' => $createdRole->id]));
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testUpdate(Domain $createdDomain)
+ {
+ $this->assertTrue($createdDomain->enabled);
+ require_once $this->sampleFile('domains/update_domain.php', ['{domainId}' => $createdDomain->id]);
+ $createdDomain->retrieve();
+ $this->assertFalse($createdDomain->enabled);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testDelete(Domain $createdDomain)
+ {
+ require_once $this->sampleFile('domains/delete_domain.php', ['{domainId}' => $createdDomain->id]);
+ $found = false;
+ foreach ($this->getService()->listDomains() as $domain) {
+ if ($domain->id === $createdDomain->id) {
+ $found = true;
+ }
+ }
+
+ $this->assertFalse($found);
+
+ $this->expectException(BadResponseError::class);
+ $createdDomain->retrieve();
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/Identity/v3/EndpointTest.php b/tests/sample/Identity/v3/EndpointTest.php
new file mode 100644
index 000000000..e9bc4e684
--- /dev/null
+++ b/tests/sample/Identity/v3/EndpointTest.php
@@ -0,0 +1,94 @@
+getService()->createService(['name' => $this->randomStr(), 'type' => 'volume', 'description' => $this->randomStr()]);
+
+ /** @var $endpoint \OpenStack\Identity\v3\Models\Endpoint */
+ require_once $this->sampleFile(
+ 'endpoints/add_endpoint.php',
+ [
+ '{endpointName}' => $this->randomStr(),
+ '{serviceId}' => $service->id,
+ '{endpointUrl}' => getenv('OS_AUTH_URL'),
+ '{region}' => 'RegionOne',
+ ]
+ );
+ self::assertInstanceOf(Endpoint::class, $endpoint);
+
+ return $endpoint;
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testList(Endpoint $createdEndpoint)
+ {
+ $found = false;
+ require_once $this->sampleFile(
+ 'endpoints/list_endpoints.php',
+ [
+ '/** @var $endpoint \OpenStack\Identity\v3\Models\Endpoint */' => <<<'PHP'
+/** @var $endpoint \OpenStack\Identity\v3\Models\Endpoint */
+if ($endpoint->id === $createdEndpoint->id) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testUpdate(Endpoint $createdEndpoint)
+ {
+ $this->assertEquals(Enum::INTERFACE_INTERNAL, $createdEndpoint->interface);
+
+ require_once $this->sampleFile(
+ 'endpoints/update_endpoint.php',
+ [
+ '{endpointId}' => $createdEndpoint->id,
+ ]
+ );
+
+ $createdEndpoint->retrieve();
+ $this->assertEquals(Enum::INTERFACE_PUBLIC, $createdEndpoint->interface);
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testDelete(Endpoint $createdEndpoint)
+ {
+ require_once $this->sampleFile(
+ 'endpoints/delete_endpoint.php',
+ [
+ '{endpointId}' => $createdEndpoint->id,
+ ]
+ );
+
+ $found = false;
+ foreach ($this->getService()->listEndpoints() as $endpoint) {
+ if ($endpoint->id === $createdEndpoint->id) {
+ $found = true;
+ }
+ }
+
+ $this->assertFalse($found);
+
+ $this->expectException(BadResponseError::class);
+ $createdEndpoint->retrieve();
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/Identity/v3/GroupTest.php b/tests/sample/Identity/v3/GroupTest.php
new file mode 100644
index 000000000..602fa7ff7
--- /dev/null
+++ b/tests/sample/Identity/v3/GroupTest.php
@@ -0,0 +1,225 @@
+randomStr();
+ $description = $this->randomStr();
+
+ /** @var $group \OpenStack\Identity\v3\Models\Group */
+ require_once $this->sampleFile(
+ 'groups/add_group.php',
+ [
+ '{name}' => $name,
+ '{description}' => $description,
+ ]
+ );
+
+ $this->assertInstanceOf(Group::class, $group);
+ $this->assertEquals($name, $group->name);
+ $this->assertEquals($description, $group->description);
+
+ $user = $this->getService()->createUser(['name' => $this->randomStr()]);
+
+ return [$group, $user];
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testAddUser(array $groupAndUser): void
+ {
+ /** @var $createdGroup \OpenStack\Identity\v3\Models\Group */
+ /** @var $createdUser \OpenStack\Identity\v3\Models\User */
+ [$createdGroup, $createdUser] = $groupAndUser;
+
+ $this->assertFalse($createdGroup->checkMembership(['userId' => $createdUser->id]));
+
+ require_once $this->sampleFile(
+ 'groups/add_user.php',
+ [
+ '{groupId}' => $createdGroup->id,
+ '{groupUserId}' => $createdUser->id,
+ ]
+ );
+
+ $this->assertTrue($createdGroup->checkMembership(['userId' => $createdUser->id]));
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testCheckMembership(array $groupAndUser): void
+ {
+ /** @var $createdGroup \OpenStack\Identity\v3\Models\Group */
+ /** @var $createdUser \OpenStack\Identity\v3\Models\User */
+ [$createdGroup, $createdUser] = $groupAndUser;
+
+ /** @var $result bool */
+ require_once $this->sampleFile(
+ 'groups/check_user_membership.php',
+ [
+ '{groupId}' => $createdGroup->id,
+ '{groupUserId}' => $createdUser->id,
+ ]
+ );
+
+ $this->assertTrue($result);
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testListUsers(array $groupAndUser): void
+ {
+ /** @var $createdGroup \OpenStack\Identity\v3\Models\Group */
+ /** @var $createdUser \OpenStack\Identity\v3\Models\User */
+ [$createdGroup, $createdUser] = $groupAndUser;
+
+ $found = false;
+ require_once $this->sampleFile(
+ 'groups/list_users.php',
+ [
+ '{groupId}' => $createdGroup->id,
+ '/** @var $user \OpenStack\Identity\v3\Models\User */' => <<<'PHP'
+/** @var $user \OpenStack\Identity\v3\Models\User */
+if ($user->id === $createdUser->id) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testRemoveUser(array $groupAndUser): void
+ {
+ /** @var $createdGroup \OpenStack\Identity\v3\Models\Group */
+ /** @var $createdUser \OpenStack\Identity\v3\Models\User */
+ [$createdGroup, $createdUser] = $groupAndUser;
+
+ $this->assertTrue($createdGroup->checkMembership(['userId' => $createdUser->id]));
+
+ require_once $this->sampleFile(
+ 'groups/remove_user.php',
+ [
+ '{groupId}' => $createdGroup->id,
+ '{groupUserId}' => $createdUser->id,
+ ]
+ );
+
+ $this->assertFalse($createdGroup->checkMembership(['userId' => $createdUser->id]));
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testGet(array $groupAndUser): void
+ {
+ /** @var $createdGroup \OpenStack\Identity\v3\Models\Group */
+ [$createdGroup] = $groupAndUser;
+
+ /** @var $group \OpenStack\Identity\v3\Models\Group */
+ require_once $this->sampleFile(
+ 'groups/get_group.php',
+ [
+ '{groupId}' => $createdGroup->id,
+ ]
+ );
+
+ $this->assertEquals($createdGroup->id, $group->id);
+ $this->assertEquals($createdGroup->name, $group->name);
+ $this->assertEquals($createdGroup->description, $group->description);
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testUpdate(array $groupAndUser): void
+ {
+ /** @var $createdGroup \OpenStack\Identity\v3\Models\Group */
+ [$createdGroup] = $groupAndUser;
+
+ $newName = $this->randomStr();
+ $newDescription = $this->randomStr();
+
+ require_once $this->sampleFile(
+ 'groups/update_group.php',
+ [
+ '{groupId}' => $createdGroup->id,
+ '{name}' => $newName,
+ '{description}' => $newDescription,
+ ]
+ );
+
+ $createdGroup->retrieve();
+ $this->assertEquals($newName, $createdGroup->name);
+ $this->assertEquals($newDescription, $createdGroup->description);
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testList(array $groupAndUser): void
+ {
+ /** @var $createdGroup \OpenStack\Identity\v3\Models\Group */
+ [$createdGroup] = $groupAndUser;
+
+ $found = false;
+ require_once $this->sampleFile(
+ 'groups/list_groups.php',
+ [
+ '{groupId}' => $createdGroup->id,
+ '/** @var $group \OpenStack\Identity\v3\Models\Group */' => <<<'PHP'
+/** @var $group \OpenStack\Identity\v3\Models\Group */
+if ($group->id === $createdGroup->id) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+
+ $this->assertTrue($found);
+ }
+
+
+ /**
+ * @depends testAdd
+ */
+ public function testDelete(array $groupAndUser): void
+ {
+ /** @var $createdGroup \OpenStack\Identity\v3\Models\Group */
+ [$createdGroup] = $groupAndUser;
+
+ require_once $this->sampleFile(
+ 'groups/delete_group.php',
+ [
+ '{groupId}' => $createdGroup->id,
+ ]
+ );
+
+ $found = false;
+ foreach ($this->getService()->listGroups() as $group) {
+ if ($group->id === $createdGroup->id) {
+ $found = true;
+ }
+ }
+
+ $this->assertFalse($found);
+
+ $this->expectException(BadResponseError::class);
+ $createdGroup->retrieve();
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/Identity/v3/ProjectTest.php b/tests/sample/Identity/v3/ProjectTest.php
new file mode 100644
index 000000000..ea72d79ea
--- /dev/null
+++ b/tests/sample/Identity/v3/ProjectTest.php
@@ -0,0 +1,251 @@
+sampleFile(
+ 'projects/add_project.php',
+ ['{name}' => $this->randomStr(), '{description}' => $this->randomStr()]
+ );
+ $this->assertInstanceOf(Project::class, $project);
+
+ return $project;
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testGet(Project $createdProject)
+ {
+ /** @var $project \OpenStack\Identity\v3\Models\Project */
+ require_once $this->sampleFile('projects/get_project.php', ['{id}' => $createdProject->id]);
+ $this->assertInstanceOf(Project::class, $project);
+ $this->assertEquals($createdProject->id, $project->id);
+ $this->assertEquals($createdProject->name, $project->name);
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testGrantGroupRole(Project $createdProject): array
+ {
+ $domain = $this->getService()->createDomain(['name' => $this->randomStr()]);
+ $role = $this->getService()->createRole(['name' => $this->randomStr()]);
+ $group = $this->getService()->createGroup(['name' => $this->randomStr(), 'domainId' => $domain->id]);
+
+ require_once $this->sampleFile(
+ 'projects/grant_group_role.php',
+ [
+ '{id}' => $createdProject->id,
+ '{groupId}' => $group->id,
+ '{roleId}' => $role->id,
+ ]
+ );
+
+ $this->assertTrue($createdProject->checkGroupRole(['groupId' => $group->id, 'roleId' => $role->id]));
+
+ return [$role, $group];
+ }
+
+ /**
+ * @depends testAdd
+ * @depends testGrantGroupRole
+ */
+ public function testCheckGroupRole(Project $createdProject, array $createdRoleAndGroup)
+ {
+ [$createdRole, $createdGroup] = $createdRoleAndGroup;
+
+ /** @var $result bool */
+ require_once $this->sampleFile(
+ 'projects/check_group_role.php',
+ [
+ '{id}' => $createdProject->id,
+ '{groupId}' => $createdGroup->id,
+ '{roleId}' => $createdRole->id,
+ ]
+ );
+
+ $this->assertTrue($result);
+ }
+
+ /**
+ * @depends testAdd
+ * @depends testGrantGroupRole
+ */
+ public function testListGroupRoles(Project $createdProject, array $createdRoleAndGroup)
+ {
+ [$createdRole, $createdGroup] = $createdRoleAndGroup;
+
+ $found = false;
+ require_once $this->sampleFile(
+ 'projects/list_group_roles.php',
+ [
+ '{id}' => $createdProject->id,
+ '{groupId}' => $createdGroup->id,
+ '/** @var $role \OpenStack\Identity\v3\Models\Role */' => <<<'PHP'
+/** @var $role \OpenStack\Identity\v3\Models\Role */
+if ($role->id === $createdRole->id) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testAdd
+ * @depends testGrantGroupRole
+ */
+ public function testRevokeGroupRole(Project $createdProject, array $createdRoleAndGroup)
+ {
+ [$createdRole, $createdGroup] = $createdRoleAndGroup;
+
+ $this->assertTrue($createdProject->checkGroupRole(['groupId' => $createdGroup->id, 'roleId' => $createdRole->id]));
+
+ require_once $this->sampleFile(
+ 'projects/revoke_group_role.php',
+ [
+ '{id}' => $createdProject->id,
+ '{groupId}' => $createdGroup->id,
+ '{roleId}' => $createdRole->id,
+ ]
+ );
+
+ $this->assertFalse($createdProject->checkGroupRole(['groupId' => $createdGroup->id, 'roleId' => $createdRole->id]));
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testGrantUserRole(Project $createdProject): array
+ {
+ $domain = $this->getService()->createDomain(['name' => $this->randomStr()]);
+ $role = $this->getService()->createRole(['name' => $this->randomStr()]);
+ $user = $this->getService()->createUser(['name' => $this->randomStr(), 'domainId' => $domain->id]);
+
+ require_once $this->sampleFile(
+ 'projects/grant_user_role.php',
+ [
+ '{id}' => $createdProject->id,
+ '{projectUserId}' => $user->id,
+ '{roleId}' => $role->id,
+ ]
+ );
+
+ $this->assertTrue($createdProject->checkUserRole(['userId' => $user->id, 'roleId' => $role->id]));
+ return [$role, $user];
+ }
+
+ /**
+ * @depends testAdd
+ * @depends testGrantUserRole
+ */
+ public function testCheckUserRole(Project $createdProject, array $createdRoleAndUser)
+ {
+ [$createdRole, $createdUser] = $createdRoleAndUser;
+
+ /** @var $result bool */
+ require_once $this->sampleFile(
+ 'projects/check_user_role.php',
+ [
+ '{id}' => $createdProject->id,
+ '{projectUserId}' => $createdUser->id,
+ '{roleId}' => $createdRole->id,
+ ]
+ );
+
+ $this->assertTrue($result);
+ }
+
+ /**
+ * @depends testAdd
+ * @depends testGrantUserRole
+ */
+ public function testListUserRoles(Project $createdProject, array $createdRoleAndUser)
+ {
+ [$createdRole, $createdUser] = $createdRoleAndUser;
+
+ $found = false;
+ require_once $this->sampleFile(
+ 'projects/list_user_roles.php',
+ [
+ '{id}' => $createdProject->id,
+ '{projectUserId}' => $createdUser->id,
+ '/** @var $role \OpenStack\Identity\v3\Models\Role */' => <<<'PHP'
+/** @var $role \OpenStack\Identity\v3\Models\Role */
+if ($role->id === $createdRole->id) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testAdd
+ * @depends testGrantUserRole
+ */
+ public function testRevokeUserRole(Project $createdProject, array $createdRoleAndUser)
+ {
+ [$createdRole, $createdUser] = $createdRoleAndUser;
+
+ $this->assertTrue($createdProject->checkUserRole(['userId' => $createdUser->id, 'roleId' => $createdRole->id]));
+
+ require_once $this->sampleFile(
+ 'projects/revoke_user_role.php',
+ [
+ '{id}' => $createdProject->id,
+ '{projectUserId}' => $createdUser->id,
+ '{roleId}' => $createdRole->id,
+ ]
+ );
+
+ $this->assertFalse($createdProject->checkUserRole(['userId' => $createdUser->id, 'roleId' => $createdRole->id]));
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testUpdate(Project $createdProject)
+ {
+ $this->assertTrue($createdProject->enabled);
+
+ require_once $this->sampleFile('projects/update_project.php', ['{id}' => $createdProject->id]);
+
+ $createdProject->retrieve();
+ $this->assertFalse($createdProject->enabled);
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testDelete(Project $createdProject)
+ {
+ require_once $this->sampleFile('projects/delete_project.php', ['{id}' => $createdProject->id]);
+
+ $found = false;
+ foreach ($this->getService()->listProjects() as $project) {
+ if ($project->id === $createdProject->id) {
+ $found = true;
+ }
+ }
+
+ $this->assertFalse($found);
+
+ $this->expectException(BadResponseError::class);
+ $createdProject->retrieve();
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/Identity/v3/RoleTest.php b/tests/sample/Identity/v3/RoleTest.php
new file mode 100644
index 000000000..059a1b669
--- /dev/null
+++ b/tests/sample/Identity/v3/RoleTest.php
@@ -0,0 +1,66 @@
+sampleFile('roles/add_role.php', ['{name}' => $this->randomStr()]);
+ $this->assertInstanceOf(Role::class, $role);
+
+ return $role;
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testList(Role $createdRole): void
+ {
+ $found = false;
+ require_once $this->sampleFile(
+ 'roles/list_roles.php',
+ [
+ '/** @var $role \OpenStack\Identity\v3\Models\Role */' => <<<'PHP'
+/** @var $role \OpenStack\Identity\v3\Models\Role */
+if ($role->id === $createdRole->id) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testListAssignments(Role $createdRole): void
+ {
+ $createdDomain = $this->getService()->createDomain(['name' => $this->randomStr()]);
+ $createdUser = $this->getService()->createUser(['name' => $this->randomStr(), 'domainId' => $createdDomain->id]);
+
+ $createdDomain->grantUserRole(['userId' => $createdUser->id, 'roleId' => $createdRole->id]);
+
+ $found = false;
+ require_once $this->sampleFile(
+ 'roles/list_assignments.php',
+ [
+ '/** @var $assignment \OpenStack\Identity\v3\Models\Assignment */' => <<<'PHP'
+/** @var $assignment \OpenStack\Identity\v3\Models\Assignment */
+if ($assignment->user !== null && $assignment->user->id === $createdUser->id) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+
+ $this->assertTrue($found);
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/Identity/v3/ServiceTest.php b/tests/sample/Identity/v3/ServiceTest.php
new file mode 100644
index 000000000..48e4d11ae
--- /dev/null
+++ b/tests/sample/Identity/v3/ServiceTest.php
@@ -0,0 +1,108 @@
+sampleFile(
+ 'services/add_service.php',
+ [
+ '{serviceName}' => $this->randomStr(),
+ '{serviceType}' => $this->randomStr(),
+ ]
+ );
+ self::assertInstanceOf(\OpenStack\Identity\v3\Models\Service::class, $service);
+
+ return $service;
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testList(\OpenStack\Identity\v3\Models\Service $createdService)
+ {
+ $found = false;
+ require_once $this->sampleFile(
+ 'services/list_services.php',
+ [
+ '/** @var $service \OpenStack\Identity\v3\Models\Service */' => <<<'PHP'
+/** @var $service \OpenStack\Identity\v3\Models\Service */
+if ($service->id === $createdService->id) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testUpdate(\OpenStack\Identity\v3\Models\Service $createdService)
+ {
+ $newDescription = $this->randomStr();
+
+ require_once $this->sampleFile(
+ 'services/update_service.php',
+ [
+ '{serviceId}' => $createdService->id,
+ '{description}' => $newDescription,
+ ]
+ );
+
+ $createdService->retrieve();
+ $this->assertEquals($newDescription, $createdService->description);
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testGet(\OpenStack\Identity\v3\Models\Service $createdService)
+ {
+ /** @var $service \OpenStack\Identity\v3\Models\Service */
+ require_once $this->sampleFile(
+ 'services/get_service.php',
+ [
+ '{serviceId}' => $createdService->id,
+ ]
+ );
+
+ $this->assertEquals($createdService->id, $service->id);
+ $this->assertEquals($createdService->name, $service->name);
+ $this->assertEquals($createdService->description, $service->description);
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testDelete(\OpenStack\Identity\v3\Models\Service $createdService)
+ {
+ require_once $this->sampleFile(
+ 'services/delete_service.php',
+ [
+ '{serviceId}' => $createdService->id,
+ ]
+ );
+
+ $found = false;
+ foreach ($this->getService()->listServices() as $service) {
+ if ($service->id === $createdService->id) {
+ $found = true;
+ }
+ }
+
+ $this->assertFalse($found);
+
+ $this->expectException(BadResponseError::class);
+ $createdService->retrieve();
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/Identity/v3/TestCase.php b/tests/sample/Identity/v3/TestCase.php
new file mode 100644
index 000000000..b7c5b17eb
--- /dev/null
+++ b/tests/sample/Identity/v3/TestCase.php
@@ -0,0 +1,18 @@
+getCachedService(Service::class);
+ }
+
+ protected function sampleFile(string $path, array $replacements = []): string
+ {
+ return parent::sampleFile("Identity/v3/$path", $replacements);
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/Identity/v3/TokenTest.php b/tests/sample/Identity/v3/TokenTest.php
new file mode 100644
index 000000000..85e8ce8c3
--- /dev/null
+++ b/tests/sample/Identity/v3/TokenTest.php
@@ -0,0 +1,76 @@
+sampleFile('tokens/generate_token_with_username.php');
+ $this->assertInstanceOf(Token::class, $token);
+ $this->assertTrue($token->validate());
+ }
+
+ public function testUserId(): void
+ {
+ /** @var $token \OpenStack\Identity\v3\Models\Token */
+ require_once $this->sampleFile('tokens/generate_token_with_user_id.php');
+ $this->assertInstanceOf(Token::class, $token);
+ $this->assertTrue($token->validate());
+ }
+
+ public function testScopedToProjectId(): void
+ {
+ /** @var $token \OpenStack\Identity\v3\Models\Token */
+ require_once $this->sampleFile('tokens/generate_token_scoped_to_project_id.php');
+ $this->assertInstanceOf(Token::class, $token);
+ $this->assertTrue($token->validate());
+ }
+
+ public function testScopedToProjectName(): void
+ {
+ /** @var $token \OpenStack\Identity\v3\Models\Token */
+ require_once $this->sampleFile('tokens/generate_token_scoped_to_project_name.php');
+ $this->assertInstanceOf(Token::class, $token);
+ $this->assertTrue($token->validate());
+ }
+
+ public function testFromId(): void
+ {
+ $tokenId = $this
+ ->getService()
+ ->generateToken([
+ 'user' => [
+ 'id' => getenv('OS_USER_ID'),
+ 'password' => getenv('OS_PASSWORD'),
+ ],
+ ])
+ ->getId();
+
+ /** @var $token \OpenStack\Identity\v3\Models\Token */
+ require_once $this->sampleFile('tokens/generate_token_from_id.php', ['{tokenId}' => $tokenId]);
+ $this->assertInstanceOf(Token::class, $token);
+ $this->assertTrue($token->validate());
+
+ }
+
+ public function testRevoke(): void
+ {
+ $token = $this
+ ->getService()
+ ->generateToken([
+ 'user' => [
+ 'id' => getenv('OS_USER_ID'),
+ 'password' => getenv('OS_PASSWORD'),
+ ],
+ ]);
+
+ require_once $this->sampleFile('tokens/revoke_token.php', ['{tokenId}' => $token->id]);
+
+ $this->assertFalse($token->validate());
+ }
+
+}
\ No newline at end of file
diff --git a/tests/sample/Identity/v3/UserTest.php b/tests/sample/Identity/v3/UserTest.php
new file mode 100644
index 000000000..2fabbe467
--- /dev/null
+++ b/tests/sample/Identity/v3/UserTest.php
@@ -0,0 +1,165 @@
+getService()->createDomain(['name' => $this->randomStr()]);
+ $project = $this->getService()->createProject(['name' => $this->randomStr(), 'domainId' => $domain->id]);
+
+ /** @var $user \OpenStack\Identity\v3\Models\User */
+ require_once $this->sampleFile(
+ 'users/add_user.php',
+ [
+ '{defaultProjectId}' => $project->id,
+ '{description}' => $this->randomStr(),
+ '{domainId}' => $domain->id,
+ '{email}' => 'foo@bar.com',
+ '{enabled}' => true,
+ '{name}' => $this->randomStr(),
+ '{userPass}' => $this->randomStr(),
+ ]
+ );
+ $this->assertInstanceOf(User::class, $user);
+
+ return $user;
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testGet(User $createdUser): void
+ {
+ /** @var $user \OpenStack\Identity\v3\Models\User */
+ require_once $this->sampleFile('users/get_user.php', ['{id}' => $createdUser->id]);
+ $this->assertInstanceOf(User::class, $user);
+
+ $this->assertEquals($createdUser->id, $user->id);
+ $this->assertEquals($createdUser->name, $user->name);
+ $this->assertEquals($createdUser->description, $user->description);
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testList(User $createdUser): void
+ {
+ $found = false;
+ require_once $this->sampleFile(
+ 'users/list_users.php',
+ [
+ '/** @var $user \OpenStack\Identity\v3\Models\User */' => <<<'PHP'
+/** @var $user \OpenStack\Identity\v3\Models\User */
+if ($user->id === $createdUser->id) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testListGroups(User $createdUser): void
+ {
+ $createdGroup = $this->getService()->createGroup(['name' => $this->randomStr(), 'domainId' => $createdUser->domainId]);
+ $createdGroup->addUser(['userId' => $createdUser->id]);
+
+ $found = false;
+ require_once $this->sampleFile(
+ 'users/list_groups.php',
+ [
+ '{id}' => $createdUser->id,
+ '/** @var $group \OpenStack\Identity\v3\Models\Group */' => <<<'PHP'
+/** @var $group \OpenStack\Identity\v3\Models\Group */
+if ($group->id === $createdGroup->id) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testListProjects(User $createdUser): void
+ {
+ $createdRole = $this->getService()->createRole(['name' => $this->randomStr()]);
+
+ $createdProject = $this->getService()->createProject(['name' => $this->randomStr(), 'domainId' => $createdUser->domainId]);
+ $createdProject->grantUserRole(['userId' => $createdUser->id, 'roleId' => $createdRole->id]);
+
+ $found = false;
+ require_once $this->sampleFile(
+ 'users/list_projects.php',
+ [
+ '{id}' => $createdUser->id,
+ '/** @var $project \OpenStack\Identity\v3\Models\Project */' => <<<'PHP'
+/** @var $project \OpenStack\Identity\v3\Models\Project */
+if ($project->id === $createdProject->id) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testUpdate(User $createdUser): void
+ {
+ $newName = $this->randomStr();
+ $newDescription = $this->randomStr();
+
+ require_once $this->sampleFile(
+ 'users/update_user.php',
+ [
+ '{id}' => $createdUser->id,
+ '{name}' => $newName,
+ '{description}' => $newDescription,
+ ]
+ );
+
+ $createdUser->retrieve();
+
+ $this->assertEquals($newName, $createdUser->name);
+ $this->assertEquals($newDescription, $createdUser->description);
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testDelete(User $createdUser): void
+ {
+ require_once $this->sampleFile('users/delete_user.php', ['{id}' => $createdUser->id]);
+
+ $found = false;
+ foreach ($this->getService()->listUsers() as $user) {
+ if ($user->id === $createdUser->id) {
+ $found = true;
+ }
+ }
+
+ $this->assertFalse($found);
+
+ $this->expectException(BadResponseError::class);
+ $createdUser->retrieve();
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/Images/v2/ImageTest.php b/tests/sample/Images/v2/ImageTest.php
new file mode 100644
index 000000000..f8b583ebd
--- /dev/null
+++ b/tests/sample/Images/v2/ImageTest.php
@@ -0,0 +1,192 @@
+sampleFile(
+ 'images/create.php',
+ [
+ '{name}' => $this->randomStr(),
+ '{tag1}' => 'ubuntu',
+ '{tag2}' => 'test',
+ '{containerFormat}' => 'bare',
+ '{diskFormat}' => 'qcow2',
+ '{visibility}' => 'private',
+ ]
+ );
+ $this->assertInstanceOf(Image::class, $image);
+
+ return $image;
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testList(Image $createdImage)
+ {
+ $found = false;
+ require_once $this->sampleFile(
+ 'images/list.php',
+ [
+ '{imageId}' => $createdImage->id,
+ '/** @var \OpenStack\Images\v2\Models\Image $image */' => <<<'PHP'
+/** @var \OpenStack\Images\v2\Models\Image $image */
+if ($image->id === $createdImage->id) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testGet(Image $createdImage)
+ {
+ /** @var Image $image */
+ require_once $this->sampleFile(
+ 'images/get.php',
+ [
+ '{imageId}' => $createdImage->id,
+ ]
+ );
+ $this->assertInstanceOf(Image::class, $image);
+ $this->assertEquals($createdImage->id, $image->id);
+ $this->assertEquals($createdImage->name, $image->name);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testUpdate(Image $createdImage)
+ {
+ $newName = $this->randomStr();
+
+ /** @var Image $image */
+ require_once $this->sampleFile(
+ 'images/update.php',
+ [
+ '{imageId}' => $createdImage->id,
+ '{name}' => $newName,
+ '{visibility}' => 'private',
+ ]
+ );
+ $this->assertInstanceOf(Image::class, $image);
+ $this->assertEquals($newName, $image->name);
+ $this->assertEquals('private', $image->visibility);
+
+ $createdImage->retrieve();
+ $this->assertEquals($newName, $createdImage->name);
+ $this->assertEquals('private', $createdImage->visibility);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testDelete(Image $createdImage)
+ {
+ require_once $this->sampleFile(
+ 'images/delete.php',
+ [
+ '{imageId}' => $createdImage->id,
+ ]
+ );
+
+ $found = false;
+ foreach ($this->getService()->listImages() as $image) {
+ if ($image->id === $createdImage->id) {
+ $found = true;
+ }
+ }
+
+ $this->assertFalse($found);
+
+ $this->expectException(BadResponseError::class);
+ $createdImage->retrieve();
+ }
+
+ public function testSortedAsc()
+ {
+ $postfix = $this->randomStr();
+ $names = ['b' . $postfix, 'a' . $postfix, 'c' . $postfix];
+ $createdImages = [];
+ foreach ($names as $name) {
+ $image = $this->getService()->createImage([
+ 'name' => $name,
+ ]);
+
+ $createdImages[] = $image;
+ }
+
+ $rightOrder = ['a' . $postfix, 'b' . $postfix, 'c' . $postfix];
+ $i = 0;
+ require_once $this->sampleFile(
+ 'images/list_sorted.php',
+ [
+ '{sortKey}' => 'name',
+ '{sortDir}' => 'asc',
+ '/** @var \OpenStack\Images\v2\Models\Image $image */' => <<<'PHP'
+/** @var \OpenStack\Images\v2\Models\Image $image */
+if ($image->name === $rightOrder[$i]) {
+ $i++;
+}
+PHP
+ ,
+ ]
+ );
+
+ $this->assertEquals(3, $i);
+ foreach ($createdImages as $image) {
+ $image->delete();
+ }
+ }
+
+ public function testSortedDesc()
+ {
+ $postfix = $this->randomStr();
+ $names = ['b' . $postfix, 'a' . $postfix, 'c' . $postfix];
+ $createdImages = [];
+ foreach ($names as $name) {
+ $image = $this->getService()->createImage([
+ 'name' => $name,
+ ]);
+
+ $createdImages[] = $image;
+ }
+
+ $rightOrder = ['c' . $postfix, 'b' . $postfix, 'a' . $postfix];
+ $i = 0;
+ require_once $this->sampleFile(
+ 'images/list_sorted.php',
+ [
+ '{sortKey}' => 'name',
+ '{sortDir}' => 'desc',
+ '/** @var \OpenStack\Images\v2\Models\Image $image */' => <<<'PHP'
+/** @var \OpenStack\Images\v2\Models\Image $image */
+if ($image->name === $rightOrder[$i]) {
+ $i++;
+}
+PHP
+ ,
+ ]
+ );
+
+ $this->assertEquals(3, $i);
+ foreach ($createdImages as $image) {
+ $image->delete();
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/Images/v2/MemberTest.php b/tests/sample/Images/v2/MemberTest.php
new file mode 100644
index 000000000..0ebd10f62
--- /dev/null
+++ b/tests/sample/Images/v2/MemberTest.php
@@ -0,0 +1,68 @@
+getService()->createImage([
+ 'name' => $this->randomStr(),
+ 'containerFormat' => 'bare',
+ 'diskFormat' => 'qcow2',
+ 'visibility' => 'shared',
+ ]);
+
+ /** @var Member $member */
+ require_once $this->sampleFile('members/add.php', ['{imageId}' => $image->id,]);
+ $this->assertInstanceOf(Member::class, $member);
+
+ return $member;
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testUpdateStatus(Member $createdMember)
+ {
+ $this->assertEquals(Member::STATUS_PENDING, $createdMember->status);
+
+ require_once $this->sampleFile('members/update_status.php', [
+ '{imageId}' => $createdMember->imageId,
+ '{memberId}' => $createdMember->id,
+ ]);
+
+ $createdMember->retrieve();
+ $this->assertEquals(Member::STATUS_ACCEPTED, $createdMember->status);
+ }
+
+ /**
+ * @depends testAdd
+ */
+ public function testDelete(Member $createdMember)
+ {
+ $image = $this->getService()->getImage($createdMember->imageId);
+
+ require_once $this->sampleFile('members/delete.php', [
+ '{imageId}' => $createdMember->imageId,
+ '{memberId}' => $createdMember->id,
+ ]);
+
+ $found = false;
+ foreach ($image->listMembers() as $member) {
+ if ($member->id === $createdMember->id) {
+ $found = true;
+ }
+ }
+
+ $this->assertFalse($found);
+ $image->delete();
+
+ $this->expectException(BadResponseError::class);
+ $createdMember->retrieve();
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/Images/v2/TestCase.php b/tests/sample/Images/v2/TestCase.php
new file mode 100644
index 000000000..e9915a819
--- /dev/null
+++ b/tests/sample/Images/v2/TestCase.php
@@ -0,0 +1,19 @@
+getCachedService(Service::class);
+ }
+
+ protected function sampleFile(string $path, array $replacements = []): string
+ {
+ return parent::sampleFile("Images/v2/$path", $replacements);
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/Networking/v2/FloatingIpData.php b/tests/sample/Networking/v2/FloatingIpData.php
new file mode 100644
index 000000000..fd1a5d0ac
--- /dev/null
+++ b/tests/sample/Networking/v2/FloatingIpData.php
@@ -0,0 +1,29 @@
+fixedIps as $fixedIp) {
+ if ($fixedIp['subnet_id'] == $subnet->id) {
+ return $fixedIp['ip_address'];
+ }
+ }
+
+ throw new \RuntimeException("Unable to find IP address for port {$port->id} on subnet {$subnet->id}");
+ }
+
+ public function testCreate(): FloatingIpData
+ {
+ $data = new FloatingIpData();
+ $data->externalNetwork = $this->getService()->createNetwork([
+ 'name' => $this->randomStr(),
+ 'routerAccessible' => true,
+ ]);
+ $data->externalSubnet = $this->getService()->createSubnet([
+ 'networkId' => $data->externalNetwork->id,
+ 'name' => $this->randomStr(),
+ 'ipVersion' => 4,
+ 'cidr' => '10.0.0.0/24',
+ ]);
+
+ $data->internalNetwork = $this->getService()->createNetwork([
+ 'name' => $this->randomStr(),
+ 'routerAccessible' => false,
+ ]);
+ $data->internalSubnet = $this->getService()->createSubnet([
+ 'networkId' => $data->internalNetwork->id,
+ 'name' => $this->randomStr(),
+ 'ipVersion' => 4,
+ 'cidr' => '192.168.199.0/24',
+ ]);
+
+
+ $data->externalNetwork->waitUntilActive();
+ $data->internalNetwork->waitUntilActive();
+
+ $data->router = $this->getServiceLayer3()->createRouter([
+ 'name' => $this->randomStr(),
+ 'externalGatewayInfo' => [
+ 'networkId' => $data->externalNetwork->id,
+ 'enableSnat' => true,
+ ],
+ ]);
+ $data->router->addInterface(['subnetId' => $data->internalSubnet->id]);
+
+ $data->port = $this->getService()->createPort([
+ 'networkId' => $data->internalNetwork->id,
+ 'name' => $this->randomStr(),
+ ]);
+ $fixedIp = $this->findSubnetIp($data->port, $data->internalSubnet);
+
+ /** @var FloatingIp $floatingIp */
+ require_once $this->sampleFile('floatingIPs/create.php', [
+ '{networkId}' => $data->externalNetwork->id,
+ '{portId}' => $data->port->id,
+ '{fixedIpAddress}' => $fixedIp,
+ ]);
+ $this->assertInstanceOf(FloatingIp::class, $floatingIp);
+ $this->assertEquals($data->externalNetwork->id, $floatingIp->floatingNetworkId);
+ $this->assertEquals($data->port->id, $floatingIp->portId);
+
+ $data->floatingIp = $floatingIp;
+
+ /*
+ $port->delete();
+ $router->delete();
+ $internalSubnet->delete();
+ $internalNetwork->delete();
+ $externalSubnet->delete();
+ $externalNetwork->delete();
+ */
+
+ return $data;
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testList(FloatingIpData $data)
+ {
+ $found = false;
+ require_once $this->sampleFile(
+ 'floatingIPs/list.php',
+ [
+ '/** @var \OpenStack\Networking\v2\Extensions\Layer3\Models\FloatingIp $floatingIp */' => <<<'PHP'
+/** @var \OpenStack\Networking\v2\Extensions\Layer3\Models\FloatingIp $floatingIp */
+if ($floatingIp->id == $data->floatingIp->id) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+
+ $this->assertTrue($found);
+ }
+
+
+ /**
+ * @depends testCreate
+ */
+ public function testGet(FloatingIpData $data)
+ {
+ /** @var FloatingIp $floatingIp */
+ require_once $this->sampleFile('floatingIPs/get.php', [
+ '{id}' => $data->floatingIp->id,
+ ]);
+ $this->assertInstanceOf(FloatingIp::class, $floatingIp);
+ $this->assertEquals($data->floatingIp->id, $floatingIp->id);
+ $this->assertEmpty($floatingIp->portId);
+
+ $floatingIp->retrieve();
+ $this->assertEquals($data->floatingIp->portId, $floatingIp->portId);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testUpdate(FloatingIpData $data)
+ {
+ $newPort = $this->getService()->createPort([
+ 'networkId' => $data->internalNetwork->id,
+ 'name' => $this->randomStr(),
+ ]);
+
+ $this->assertNotEquals($newPort->id, $data->port->id);
+
+ require_once $this->sampleFile('floatingIPs/update.php', [
+ '{id}' => $data->floatingIp->id,
+ '{newPortId}' => $newPort->id,
+ ]);
+
+ $data->floatingIp->retrieve();
+ $this->assertEquals($newPort->id, $data->floatingIp->portId);
+
+ $data->port->delete();
+ $data->port = $newPort;
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testDelete(FloatingIpData $data)
+ {
+ require_once $this->sampleFile('floatingIPs/delete.php', [
+ '{id}' => $data->floatingIp->id,
+ ]);
+
+ foreach ($this->getServiceLayer3()->listFloatingIps() as $floatingIp) {
+ if ($floatingIp->id == $data->floatingIp->id) {
+ $this->fail('Floating IP still exists');
+ }
+ }
+
+ $data->router->removeInterface(['subnetId' => $data->internalSubnet->id]);
+ $data->router->delete();
+ $data->router->waitUntilDeleted();
+
+ $data->port->delete();
+ $data->internalSubnet->delete();
+ $data->internalNetwork->delete();
+ $data->externalSubnet->delete();
+ $data->externalNetwork->delete();
+
+ $this->expectException(BadResponseError::class);
+ $data->floatingIp->retrieve();
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/tests/sample/Networking/v2/NetworkTest.php b/tests/sample/Networking/v2/NetworkTest.php
new file mode 100644
index 000000000..5b360f0d5
--- /dev/null
+++ b/tests/sample/Networking/v2/NetworkTest.php
@@ -0,0 +1,82 @@
+sampleFile('networks/create_batch.php', [
+ '{networkName1}' => $this->randomStr(),
+ '{networkName2}' => $this->randomStr(),
+ ]);
+
+ foreach ($networks as $network) {
+ $this->assertInstanceOf(Network::class, $network);
+ $this->assertNotEmpty($network->id);
+
+ $this->getService()->getNetwork($network->id)->delete();
+ }
+ }
+
+ public function testCreate(): Network
+ {
+ /** @var \OpenStack\Networking\v2\Models\Network $network */
+ require_once $this->sampleFile('networks/create.php', ['{networkName}' => $this->randomStr()]);
+
+ $this->assertInstanceOf(Network::class, $network);
+ $this->assertNotEmpty($network->id);
+
+ return $network;
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testUpdate(Network $createdNetwork)
+ {
+ $newName = $this->randomStr();
+
+ require_once $this->sampleFile('networks/update.php', [
+ '{networkId}' => $createdNetwork->id,
+ '{newName}' => $newName,
+ ]);
+
+ $createdNetwork->retrieve();
+ $this->assertEquals($newName, $createdNetwork->name);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testRetrieve(Network $createdNetwork)
+ {
+ /** @var \OpenStack\Networking\v2\Models\Network $network */
+ require_once $this->sampleFile('networks/get.php', ['{networkId}' => $createdNetwork->id]);
+
+ $this->assertInstanceOf(Network::class, $network);
+ $this->assertEquals($createdNetwork->id, $network->id);
+ $this->assertEquals($createdNetwork->name, $network->name);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testDelete(Network $createdNetwork)
+ {
+ require_once $this->sampleFile('networks/delete.php', ['{networkId}' => $createdNetwork->id]);
+
+ foreach ($this->getService()->listNetworks() as $network) {
+ if ($network->id == $createdNetwork->id) {
+ $this->fail('The network was not deleted');
+ }
+ }
+
+ $this->expectException(BadResponseError::class);
+ $this->getService()->getNetwork($createdNetwork->id)->retrieve();
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/Networking/v2/PortTest.php b/tests/sample/Networking/v2/PortTest.php
new file mode 100644
index 000000000..040c48791
--- /dev/null
+++ b/tests/sample/Networking/v2/PortTest.php
@@ -0,0 +1,155 @@
+getService()->createNetwork(['name' => $this->randomStr()]);
+
+ /** @var Port[] $ports */
+ require_once $this->sampleFile('ports/create_batch.php', [
+ '{name1}' => $this->randomStr(),
+ '{name2}' => $this->randomStr(),
+ '{networkId1}' => $network->id,
+ '{networkId2}' => $network->id,
+ ]);
+
+ $this->assertCount(2, $ports);
+ foreach ($ports as $port) {
+ $this->assertInstanceOf(Port::class, $port);
+ $this->assertNotEmpty($port->id);
+
+ $port->delete();
+ }
+ $network->delete();
+ }
+
+ public function testCreatePortWithFixedIps()
+ {
+ $network = $this->getService()->createNetwork(['name' => $this->randomStr()]);
+ $subnet = $this->getService()->createSubnet([
+ 'name' => $this->randomStr(),
+ 'networkId' => $network->id,
+ 'ipVersion' => 4,
+ 'cidr' => '192.168.199.0/24',
+ ]);
+
+ /** @var $port \OpenStack\Networking\v2\Models\Port */
+ require_once $this->sampleFile('ports/create_with_fixed_ips.php', ['{networkId}' => $network->id]);
+
+ $this->assertInstanceOf(Port::class, $port);
+ $this->assertCount(2, $port->fixedIps);
+ $this->assertEquals($subnet->id, $port->fixedIps[0]['subnet_id']);
+ $this->assertEquals('192.168.199.100', $port->fixedIps[0]['ip_address']);
+ $this->assertEquals($subnet->id, $port->fixedIps[1]['subnet_id']);
+ $this->assertEquals('192.168.199.200', $port->fixedIps[1]['ip_address']);
+
+ $port->delete();
+ $subnet->delete();
+ $network->delete();
+ }
+
+ public function testCreate(): Port
+ {
+ $network = $this->getService()->createNetwork(['name' => $this->randomStr()]);
+
+ /** @var $port \OpenStack\Networking\v2\Models\Port */
+ require_once $this->sampleFile(
+ 'ports/create.php',
+ [
+ '{name}' => $this->randomStr(),
+ '{networkId}' => $network->id,
+ ]);
+
+ $this->assertInstanceOf(Port::class, $port);
+ $this->assertNotEmpty($port->id);
+
+ return $port;
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testList(Port $createdPort)
+ {
+ $found = false;
+ require_once $this->sampleFile(
+ 'ports/list.php',
+ [
+ '/** @var \OpenStack\Networking\v2\Models\Port $port */' => <<<'PHP'
+/** @var \OpenStack\Networking\v2\Models\Port $port */
+if ($port->id === $createdPort->id) {
+ $found = true;
+}
+PHP
+ ,
+ ]
+ );
+
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testGet(Port $createdPort)
+ {
+ /** @var $port \OpenStack\Networking\v2\Models\Port */
+ require_once $this->sampleFile(
+ 'ports/get.php',
+ [
+ '{portId}' => $createdPort->id,
+ ]);
+
+ $this->assertInstanceOf(Port::class, $port);
+ $this->assertNotEmpty($port->id);
+ $this->assertEmpty($port->name);
+
+ $port->retrieve();
+ $this->assertNotEmpty($port->name);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testUpdate(Port $createdPort)
+ {
+ $newName = $this->randomStr();
+
+ require_once $this->sampleFile('ports/update.php', [
+ '{portId}' => $createdPort->id,
+ '{newName}' => $newName,
+ ]);
+
+ $createdPort->retrieve();
+ $this->assertEquals($newName, $createdPort->name);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testDelete(Port $createdPort)
+ {
+ $network = $this->getService()->getNetwork($createdPort->networkId);
+
+ require_once $this->sampleFile('ports/delete.php', [
+ '{portId}' => $createdPort->id,
+ ]);
+
+ foreach ($this->getService()->listPorts() as $port) {
+ if ($port->id === $createdPort->id) {
+ $this->fail('The port was not deleted');
+ }
+ }
+
+ $network->delete();
+
+ $this->expectException(BadResponseError::class);
+ $this->getService()->getSubnet($createdPort->id)->retrieve();
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/Networking/v2/SubnetTest.php b/tests/sample/Networking/v2/SubnetTest.php
new file mode 100644
index 000000000..05b55b827
--- /dev/null
+++ b/tests/sample/Networking/v2/SubnetTest.php
@@ -0,0 +1,133 @@
+getService()->createNetwork(['name' => $this->randomStr()]);
+
+ /** @var Subnet[] $subnets */
+ require_once $this->sampleFile('subnets/create_batch.php', [
+ '{subnetName1}' => $this->randomStr(),
+ '{subnetName2}' => $this->randomStr(),
+ '{networkId1}' => $network->id,
+ '{networkId2}' => $network->id,
+ ]);
+
+ foreach ($subnets as $subnet) {
+ $this->assertInstanceOf(Subnet::class, $subnet);
+ $this->assertNotEmpty($subnet->id);
+
+ $subnet->delete();
+ }
+ $network->delete();
+ }
+
+ public function testCreateWithHostRoute()
+ {
+ $network = $this->getService()->createNetwork(['name' => $this->randomStr()]);
+
+ /** @var $subnet \OpenStack\Networking\v2\Models\Subnet */
+ require_once $this->sampleFile('subnets/create_with_host_routes.php', [
+ '{subnetName}' => $this->randomStr(),
+ '{networkId}' => $network->id,
+ ]);
+
+ $this->assertInstanceOf(Subnet::class, $subnet);
+ $this->assertNotEmpty($subnet->id);
+
+ $network->delete();
+ }
+
+ public function testCreateWithGatewayIp()
+ {
+ $network = $this->getService()->createNetwork(['name' => $this->randomStr()]);
+
+ /** @var $subnet \OpenStack\Networking\v2\Models\Subnet */
+ require_once $this->sampleFile('subnets/create_with_gateway_ip.php', [
+ '{subnetName}' => $this->randomStr(),
+ '{networkId}' => $network->id,
+ ]);
+
+ $this->assertInstanceOf(Subnet::class, $subnet);
+ $this->assertNotEmpty($subnet->id);
+ $this->assertEquals('192.168.199.128', $subnet->gatewayIp);
+
+ $subnet->delete();
+ $network->delete();
+ }
+
+ public function testCreate(): Subnet
+ {
+ $network = $this->getService()->createNetwork(['name' => $this->randomStr()]);
+
+ /** @var $subnet \OpenStack\Networking\v2\Models\Subnet */
+ require_once $this->sampleFile(
+ 'subnets/create.php',
+ [
+ '{subnetName}' => $this->randomStr(),
+ '{networkId}' => $network->id,
+ ]
+ );
+
+ $this->assertInstanceOf(Subnet::class, $subnet);
+ $this->assertNotEmpty($subnet->id);
+
+ return $subnet;
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testUpdate(Subnet $createdSubnet)
+ {
+ $newName = $this->randomStr();
+
+ require_once $this->sampleFile('subnets/update.php', [
+ '{subnetId}' => $createdSubnet->id,
+ '{newName}' => $newName,
+ ]);
+
+ $createdSubnet->retrieve();
+ $this->assertEquals($newName, $createdSubnet->name);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testRetrieve(Subnet $createdSubnet)
+ {
+ /** @var $subnet \OpenStack\Networking\v2\Models\Subnet */
+ require_once $this->sampleFile('subnets/get.php', ['{subnetId}' => $createdSubnet->id]);
+
+ $this->assertInstanceOf(Subnet::class, $subnet);
+ $this->assertEquals($subnet->id, $subnet->id);
+ $this->assertEquals($subnet->name, $subnet->name);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testDelete(Subnet $createdSubnet)
+ {
+ $network = $this->getService()->getNetwork($createdSubnet->networkId);
+
+ require_once $this->sampleFile('subnets/delete.php', ['{subnetId}' => $createdSubnet->id]);
+
+ foreach ($this->getService()->listSubnets() as $subnet) {
+ if ($subnet->id == $createdSubnet->id) {
+ $this->fail('The deleted subnet still exists');
+ }
+ }
+
+ $network->delete();
+
+ $this->expectException(BadResponseError::class);
+ $this->getService()->getSubnet($createdSubnet->id)->retrieve();
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/Networking/v2/TestCase.php b/tests/sample/Networking/v2/TestCase.php
new file mode 100644
index 000000000..2ac889b3c
--- /dev/null
+++ b/tests/sample/Networking/v2/TestCase.php
@@ -0,0 +1,25 @@
+getCachedService(Service::class);
+ }
+
+ protected function getServiceLayer3(): \OpenStack\Networking\v2\Extensions\Layer3\Service
+ {
+ return $this->getCachedService(\OpenStack\Networking\v2\Extensions\Layer3\Service::class);
+ }
+
+ protected function sampleFile(string $path, array $replacements = []): string
+ {
+ return parent::sampleFile("Networking/v2/$path", $replacements);
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/ObjectStore/v1/AccountTest.php b/tests/sample/ObjectStore/v1/AccountTest.php
new file mode 100644
index 000000000..39eb58aa0
--- /dev/null
+++ b/tests/sample/ObjectStore/v1/AccountTest.php
@@ -0,0 +1,57 @@
+randomStr();
+ $barVal = $this->randomStr();
+
+ require_once $this->sampleFile('account/merge_metadata.php', [
+ '{key_1}' => 'Foo',
+ '{key_2}' => 'Bar',
+ '{val_1}' => $fooVal,
+ '{val_2}' => $barVal,
+ ]);
+
+ $metadata = $this->getService()->getAccount()->getMetadata();
+ $this->assertEquals($fooVal, $metadata['Foo']);
+ $this->assertEquals($barVal, $metadata['Bar']);
+ }
+
+ /**
+ * @depends testMergeMetadata
+ */
+ public function testGetMetadata()
+ {
+ /** @var array $metadata */
+ require_once $this->sampleFile('account/get_metadata.php');
+
+ $this->assertArrayHasKey('Foo', $metadata);
+ $this->assertArrayHasKey('Bar', $metadata);
+ }
+
+ /**
+ * @depends testMergeMetadata
+ */
+ public function testResetMetadata()
+ {
+ $fooVal = $this->randomStr();
+ $barVal = $this->randomStr();
+
+ require_once $this->sampleFile('account/reset_metadata.php', [
+ '{key_1}' => 'Foo1',
+ '{key_2}' => 'Bar1',
+ '{val_1}' => $fooVal,
+ '{val_2}' => $barVal,
+ ]);
+
+ $metadata = $this->getService()->getAccount()->getMetadata();
+ $this->assertEquals($fooVal, $metadata['Foo1']);
+ $this->assertEquals($barVal, $metadata['Bar1']);
+ $this->assertArrayNotHasKey('Foo', $metadata);
+ $this->assertArrayNotHasKey('Bar', $metadata);
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/ObjectStore/v1/ContainerTest.php b/tests/sample/ObjectStore/v1/ContainerTest.php
new file mode 100644
index 000000000..426ae3ca4
--- /dev/null
+++ b/tests/sample/ObjectStore/v1/ContainerTest.php
@@ -0,0 +1,134 @@
+randomStr();
+
+ /** @var \OpenStack\ObjectStore\v1\Models\Container $container */
+ require_once $this->sampleFile('containers/create.php', ['{containerName}' => $containerName]);
+
+ $this->assertInstanceOf(Container::class, $container);
+
+ return $container;
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testGet(Container $createdContainer)
+ {
+ /** @var \OpenStack\ObjectStore\v1\Models\Container $container */
+ require_once $this->sampleFile('containers/get.php', ['{containerName}' => $createdContainer->name]);
+
+ $this->assertInstanceOf(Container::class, $container);
+ $this->assertEquals($createdContainer->name, $container->name);
+ $this->assertEquals([], $container->metadata);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testList(Container $createdContainer)
+ {
+ $found = false;
+ require_once $this->sampleFile('containers/list.php', [
+ '/** @var \OpenStack\ObjectStore\v1\Models\Container $container */' => <<<'PHP'
+/** @var \OpenStack\ObjectStore\v1\Models\Container $container */
+if ($container->name === $createdContainer->name) {
+ $found = true;
+}
+PHP
+ ,
+ ]);
+
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testMergeMetadata(Container $createdContainer)
+ {
+ $initVal = $this->randomStr();
+ $fooVal = $this->randomStr();
+ $barVal = $this->randomStr();
+
+ $createdContainer->mergeMetadata(['Init' => $initVal]);
+
+ require_once $this->sampleFile('containers/merge_metadata.php', [
+ '{key_1}' => 'Foo',
+ '{key_2}' => 'Bar',
+ '{val_1}' => $fooVal,
+ '{val_2}' => $barVal,
+ '{containerName}' => $createdContainer->name,
+ ]);
+
+ $metadata = $createdContainer->getMetadata();
+ $this->assertEquals($initVal, $metadata['Init']);
+ $this->assertEquals($fooVal, $metadata['Foo']);
+ $this->assertEquals($barVal, $metadata['Bar']);
+ }
+
+ /**
+ * @depends testCreate
+ * @depends testMergeMetadata
+ */
+ public function testGetMetadata(Container $createdContainer)
+ {
+ /** @var array $metadata */
+ require_once $this->sampleFile('containers/get_metadata.php', ['{containerName}' => $createdContainer->name]);
+
+ $this->assertArrayHasKey('Init', $metadata);
+ $this->assertArrayHasKey('Foo', $metadata);
+ $this->assertArrayHasKey('Bar', $metadata);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testResetMetadata(Container $createdContainer)
+ {
+ $initVal = $this->randomStr();
+ $fooVal = $this->randomStr();
+ $barVal = $this->randomStr();
+
+ $createdContainer->mergeMetadata(['Init' => $initVal]);
+
+ require_once $this->sampleFile('containers/reset_metadata.php', [
+ '{key_1}' => 'Foo',
+ '{key_2}' => 'Bar',
+ '{val_1}' => $fooVal,
+ '{val_2}' => $barVal,
+ '{containerName}' => $createdContainer->name,
+ ]);
+
+ $metadata = $createdContainer->getMetadata();
+ $this->assertEquals($fooVal, $metadata['Foo']);
+ $this->assertEquals($barVal, $metadata['Bar']);
+ $this->assertArrayNotHasKey('Init', $metadata);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testDelete(Container $createdContainer)
+ {
+ require_once $this->sampleFile('containers/delete.php', ['{containerName}' => $createdContainer->name]);
+
+ foreach ($this->getService()->listContainers() as $container) {
+ if ($container->name === $createdContainer->name) {
+ $this->fail('Container still exists');
+ }
+ }
+
+ $this->expectException(BadResponseError::class);
+ $createdContainer->retrieve();
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/ObjectStore/v1/ObjectTest.php b/tests/sample/ObjectStore/v1/ObjectTest.php
new file mode 100644
index 000000000..731490af6
--- /dev/null
+++ b/tests/sample/ObjectStore/v1/ObjectTest.php
@@ -0,0 +1,227 @@
+randomStr();
+ $objectName = $this->randomStr();
+
+ $this->getService()->createContainer(['name' => $containerName]);
+
+ /** @var StorageObject $object */
+ require_once $this->sampleFile('objects/create.php', [
+ '{containerName}' => $containerName,
+ '{objectName}' => $objectName,
+ '{objectContent}' => str_repeat('A', 1000),
+ ]);
+
+ $this->assertInstanceOf(StorageObject::class, $object);
+
+ return $object;
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testCheckExists(StorageObject $createdObject)
+ {
+ /** @var bool $exists */
+ require_once $this->sampleFile('objects/check_exists.php', [
+ '{containerName}' => $createdObject->containerName,
+ '{objectName}' => $createdObject->name,
+ ]);
+
+ $this->assertTrue($exists);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testCopy(StorageObject $createdObject)
+ {
+ $newName = $this->randomStr();
+ $container = $this->getService()->getContainer($createdObject->containerName);
+
+ $this->assertFalse($container->objectExists($newName));
+
+ require_once $this->sampleFile('objects/copy.php', [
+ '{containerName}' => $container->name,
+ '{objectName}' => $createdObject->name,
+ '{newContainerName}' => $container->name,
+ '{newObjectName}' => $newName,
+ ]);
+
+ $this->assertTrue($container->objectExists($newName));
+ $container->getObject($newName)->delete();
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testDownload(StorageObject $createdObject)
+ {
+ /** @var StreamInterface $stream */
+ require_once $this->sampleFile('objects/download.php', [
+ '{containerName}' => $createdObject->containerName,
+ '{objectName}' => $createdObject->name,
+ ]);
+ $this->assertInstanceOf(StreamInterface::class, $stream);
+ $this->assertEquals(1000, $stream->getSize());
+ $this->assertEquals(str_repeat('A', 1000), $stream->getContents());
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testDownloadStream(StorageObject $createdObject)
+ {
+ /** @var StreamInterface $stream */
+ require_once $this->sampleFile('objects/download_stream.php', [
+ '{containerName}' => $createdObject->containerName,
+ '{objectName}' => $createdObject->name,
+ ]);
+ $this->assertInstanceOf(StreamInterface::class, $stream);
+ $this->assertNull($stream->getSize());
+
+ $body = '';
+ while (!$stream->eof()) {
+ $body .= $stream->read(64);
+ }
+ $this->assertEquals(str_repeat('A', 1000), $body);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testGet(StorageObject $createdObject)
+ {
+ /** @var StorageObject $object */
+ require_once $this->sampleFile('objects/get.php', [
+ '{containerName}' => $createdObject->containerName,
+ '{objectName}' => $createdObject->name,
+ ]);
+
+ $this->assertInstanceOf(StorageObject::class, $object);
+ $this->assertEquals($createdObject->name, $object->name);
+ $this->assertEquals(null, $object->metadata);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testList(StorageObject $createdObject)
+ {
+ $found = false;
+ require_once $this->sampleFile('objects/list.php', [
+ '/** @var \OpenStack\ObjectStore\v1\Models\StorageObject $object */' => <<<'PHP'
+/** @var \OpenStack\ObjectStore\v1\Models\StorageObject $object */
+if ($object->name === $createdObject->name) {
+ $found = true;
+}
+PHP
+ ,
+ '{containerName}' => $createdObject->containerName,
+ ]);
+
+ $this->assertTrue($found);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testMergeMetadata(StorageObject $createdObject)
+ {
+ $initVal = $this->randomStr();
+ $fooVal = $this->randomStr();
+ $barVal = $this->randomStr();
+
+ $createdObject->mergeMetadata(['Init' => $initVal]);
+
+ require_once $this->sampleFile(
+ 'objects/merge_metadata.php',
+ [
+ '{containerName}' => $createdObject->containerName,
+ '{objectName}' => $createdObject->name,
+ '{key_1}' => 'Foo',
+ '{val_1}' => $fooVal,
+ '{key_2}' => 'Bar',
+ '{val_2}' => $barVal,
+ ]
+ );
+
+ $metadata = $createdObject->getMetadata();
+ $this->assertEquals($initVal, $metadata['Init']);
+ $this->assertEquals($fooVal, $metadata['Foo']);
+ $this->assertEquals($barVal, $metadata['Bar']);
+ }
+
+ /**
+ * @depends testCreate
+ * @depends testMergeMetadata
+ */
+ public function testGetMetadata(StorageObject $createdObject)
+ {
+ /** @var array $metadata */
+ require_once $this->sampleFile('objects/get_metadata.php', [
+ '{containerName}' => $createdObject->containerName,
+ '{objectName}' => $createdObject->name,
+ ]);
+
+ $createdObject->retrieve();
+
+ $this->assertEquals($createdObject->metadata['Init'], $metadata['Init']);
+ $this->assertEquals($createdObject->metadata['Foo'], $metadata['Foo']);
+ $this->assertEquals($createdObject->metadata['Bar'], $metadata['Bar']);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testResetMetadata(StorageObject $createdObject)
+ {
+ $initVal = $this->randomStr();
+ $fooVal = $this->randomStr();
+ $barVal = $this->randomStr();
+
+ $createdObject->mergeMetadata(['Init' => $initVal]);
+
+ require_once $this->sampleFile(
+ 'objects/reset_metadata.php',
+ [
+ '{containerName}' => $createdObject->containerName,
+ '{objectName}' => $createdObject->name,
+ '{key_1}' => 'Foo',
+ '{val_1}' => $fooVal,
+ '{key_2}' => 'Bar',
+ '{val_2}' => $barVal,
+ ]
+ );
+
+ $metadata = $createdObject->getMetadata();
+ $this->assertArrayNotHasKey('Init', $metadata);
+ $this->assertEquals($fooVal, $metadata['Foo']);
+ $this->assertEquals($barVal, $metadata['Bar']);
+ }
+
+ /**
+ * @depends testCreate
+ */
+ public function testDelete(StorageObject $createdObject)
+ {
+ $container = $this->getService()->getContainer($createdObject->containerName);
+
+ require_once $this->sampleFile('objects/delete.php', [
+ '{containerName}' => $createdObject->containerName,
+ '{objectName}' => $createdObject->name,
+ ]);
+
+ $this->assertFalse($container->objectExists($createdObject->name));
+ $container->delete();
+ }
+}
\ No newline at end of file
diff --git a/tests/sample/ObjectStore/v1/TestCase.php b/tests/sample/ObjectStore/v1/TestCase.php
new file mode 100644
index 000000000..52312b840
--- /dev/null
+++ b/tests/sample/ObjectStore/v1/TestCase.php
@@ -0,0 +1,19 @@
+getCachedService(Service::class);
+ }
+
+ protected function sampleFile(string $path, array $replacements = []): string
+ {
+ return parent::sampleFile("ObjectStore/v1/$path", $replacements);
+ }
+}
\ No newline at end of file
diff --git a/tests/integration/SampleManager.php b/tests/sample/SampleManager.php
similarity index 75%
rename from tests/integration/SampleManager.php
rename to tests/sample/SampleManager.php
index 14998109c..585c84b04 100644
--- a/tests/integration/SampleManager.php
+++ b/tests/sample/SampleManager.php
@@ -1,8 +1,11 @@
verbosity = $verbosity;
}
- public function deletePaths()
+ public function deletePaths(): void
{
if (!empty($this->paths)) {
foreach ($this->paths as $path) {
@@ -23,7 +26,7 @@ public function deletePaths()
}
}
- protected function getGlobalReplacements()
+ protected function getGlobalReplacements(): array
{
return [
'{userId}' => getenv('OS_USER_ID'),
@@ -38,17 +41,16 @@ protected function getGlobalReplacements()
];
}
- public function getConnectionStr()
+ public function getConnectionStr(): string
{
return str_replace('$openstack =', 'return', $this->getConnectionTemplate());
}
- protected function getConnectionTemplate()
+ protected function getConnectionTemplate(): string
{
if ($this->verbosity === 1) {
$subst = <<<'EOL'
-use OpenStack\Integration\DefaultLogger;
-use OpenStack\Integration\Utils;
+use OpenStack\Sample\DefaultLogger;
use GuzzleHttp\MessageFormatter;
$options = [
@@ -56,12 +58,11 @@ protected function getConnectionTemplate()
'logger' => new DefaultLogger(),
'messageFormatter' => new MessageFormatter(),
];
-$openstack = new OpenStack\OpenStack(Utils::getAuthOpts($options));
+$openstack = $this->getOpenStack($options);
EOL;
} elseif ($this->verbosity === 2) {
$subst = <<<'EOL'
-use OpenStack\Integration\DefaultLogger;
-use OpenStack\Integration\Utils;
+use OpenStack\Sample\DefaultLogger;
use GuzzleHttp\MessageFormatter;
$options = [
@@ -69,31 +70,31 @@ protected function getConnectionTemplate()
'logger' => new DefaultLogger(),
'messageFormatter' => new MessageFormatter(MessageFormatter::DEBUG),
];
-$openstack = new OpenStack\OpenStack(Utils::getAuthOpts($options));
+$openstack = $this->getOpenStack($options);
EOL;
} else {
$subst = <<<'EOL'
use OpenStack\Integration\Utils;
-$openstack = new OpenStack\OpenStack(Utils::getAuthOpts());
+$openstack = $this->getOpenStack();
EOL;
}
return $subst;
}
- public function write($path, array $replacements)
+ public function write(string $path, array $replacements): string
{
$replacements = array_merge($this->getGlobalReplacements(), $replacements);
$sampleFile = rtrim($this->basePath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $path;
if (!file_exists($sampleFile)) {
- throw new \RuntimeException(sprintf("%s does not exist", $sampleFile));
+ throw new RuntimeException(sprintf("%s does not exist", $sampleFile));
}
if(!is_readable($sampleFile)) {
- throw new \RuntimeException(sprintf("%s is not readable", $sampleFile));
+ throw new RuntimeException(sprintf("%s is not readable", $sampleFile));
}
$content = strtr(file_get_contents($sampleFile), $replacements);
diff --git a/tests/sample/TestCase.php b/tests/sample/TestCase.php
new file mode 100644
index 000000000..19d494797
--- /dev/null
+++ b/tests/sample/TestCase.php
@@ -0,0 +1,129 @@
+ */
+ protected $cachedServices = [];
+
+ public function __construct()
+ {
+ parent::__construct();
+ $this->sampleManager = new SampleManager(
+ __DIR__ . '/../../samples',
+ intval(getenv('SAMPLE_VERBOSITY'))
+ );
+ }
+
+ protected function getOpenStack(array $options = []): OpenStack
+ {
+ return new OpenStack($this->getAuthOpts($options));
+ }
+
+ /**
+ * @param class-string $serviceType
+ * @return T
+ * @template T of \OpenStack\Common\Service\AbstractService
+ *
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ protected function getCachedService(string $serviceType): AbstractService
+ {
+ if (isset($this->cachedServices[$serviceType])) {
+ return $this->cachedServices[$serviceType];
+ }
+
+ switch ($serviceType) {
+ case \OpenStack\BlockStorage\v2\Service::class:
+ $service = $this->getOpenStack()->blockStorageV2();
+ break;
+ case \OpenStack\BlockStorage\v3\Service::class:
+ $service = $this->getOpenStack()->blockStorageV3();
+ break;
+ case \OpenStack\Compute\v2\Service::class:
+ $service = $this->getOpenStack()->computeV2();
+ break;
+ case \OpenStack\Identity\v2\Service::class:
+ $service = $this->getOpenStack()->identityV2();
+ break;
+ case \OpenStack\Identity\v3\Service::class:
+ $service = $this->getOpenStack()->identityV3();
+ break;
+ case \OpenStack\Images\v2\Service::class:
+ $service = $this->getOpenStack()->imagesV2();
+ break;
+ case \OpenStack\Networking\v2\Service::class:
+ $service = $this->getOpenStack()->networkingV2();
+ break;
+ case \OpenStack\Networking\v2\Extensions\Layer3\Service::class:
+ $service = $this->getOpenStack()->networkingV2ExtLayer3();
+ break;
+ case \OpenStack\Networking\v2\Extensions\SecurityGroups\Service::class:
+ $service = $this->getOpenStack()->networkingV2ExtSecGroups();
+ break;
+ case \OpenStack\ObjectStore\v1\Service::class:
+ $service = $this->getOpenStack()->objectStoreV1();
+ break;
+ default:
+ throw new InvalidArgumentException("Unknown service type: $serviceType");
+ }
+
+ $this->cachedServices[$serviceType] = $service;
+
+ return $this->cachedServices[$serviceType];
+ }
+
+ protected function getAuthOpts(array $options = []): array
+ {
+ return array_merge(
+ [
+ 'authUrl' => getenv('OS_AUTH_URL'),
+ 'region' => getenv('OS_REGION_NAME'),
+ 'user' => [
+ 'id' => getenv('OS_USER_ID'),
+ 'password' => getenv('OS_PASSWORD'),
+ ],
+ 'scope' => [
+ 'project' => [
+ 'id' => getenv('OS_PROJECT_ID'),
+ ],
+ ],
+ ],
+ $options
+ );
+ }
+
+ /**
+ * Creates random string
+ */
+ protected function randomStr($length = 5): string
+ {
+ $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ $charsLen = strlen($chars);
+
+ $randomString = '';
+ for ($i = 0; $i < $length; $i++) {
+ $randomString .= $chars[rand(0, $charsLen - 1)];
+ }
+
+ return $this->namePrefix . $randomString;
+ }
+
+ /**
+ * Creates a sample file from a template. It must be included to be executed.
+ */
+ protected function sampleFile(string $path, array $replacements = []): string
+ {
+ return $this->sampleManager->write($path, $replacements);
+ }
+}
\ No newline at end of file