Skip to content

Commit 8fa7be4

Browse files
committed
Unit test and integration test for os-hypervisors/statistics
1 parent 8e5122f commit 8fa7be4

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
use OpenStack\Compute\v2\Models\HypervisorStatistic;
4+
5+
require 'vendor/autoload.php';
6+
7+
$openstack = new OpenStack\OpenStack([
8+
'authUrl' => '{authUrl}',
9+
'region' => '{region}',
10+
'user' => [
11+
'id' => '{userId}',
12+
'password' => '{password}'
13+
],
14+
'scope' => ['project' => ['id' => '{projectId}']]
15+
]);
16+
17+
$compute = $openstack->computeV2(['region' => '{region}']);
18+
19+
/** @var HypervisorStatistic $hypervisorStatistics */
20+
$hypervisorStatistics = $compute->getHypervisorStatistics();

tests/integration/Compute/v2/CoreTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use OpenStack\BlockStorage\v2\Models\Volume;
66
use OpenStack\Compute\v2\Models\Flavor;
7+
use OpenStack\Compute\v2\Models\HypervisorStatistic;
78
use OpenStack\Compute\v2\Models\Image;
89
use OpenStack\Compute\v2\Models\Keypair;
910
use OpenStack\Compute\v2\Models\Limit;
@@ -170,6 +171,7 @@ public function runTests()
170171

171172
// Limits
172173
$this->getLimits();
174+
$this->getHypervisorsStatistics();
173175
} finally {
174176
// Teardown
175177
$this->deleteServer();
@@ -506,6 +508,16 @@ private function deleteKeypair()
506508
$this->logStep('Deleted keypair name {name}', ['{name}' => $this->keypairName]);
507509
}
508510

511+
private function getHypervisorsStatistics()
512+
{
513+
require_once $this->sampleFile([], 'hypervisors/get_hypervisors_statistics.php');
514+
515+
/**@var HypervisorStatistic $hypervisorStatistics */
516+
$this->assertInstanceOf(HypervisorStatistic::class, $hypervisorStatistics);
517+
518+
$this->logStep('Retrieved hypervisors statistics');
519+
}
520+
509521
private function getLimits()
510522
{
511523
require_once $this->sampleFile([], 'limits/get_limits.php');
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
HTTP/1.1 200 OK
2+
Content-Type: application/json
3+
4+
{
5+
"hypervisor_statistics": {
6+
"count": 1,
7+
"vcpus_used": 0,
8+
"local_gb_used": 0,
9+
"memory_mb": 7980,
10+
"current_workload": 0,
11+
"vcpus": 8,
12+
"running_vms": 0,
13+
"free_disk_gb": 157,
14+
"disk_available_least": 140,
15+
"local_gb": 157,
16+
"free_ram_mb": 7468,
17+
"memory_mb_used": 512
18+
}
19+
}

tests/unit/Compute/v2/ServiceTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use GuzzleHttp\Psr7\Response;
66
use OpenStack\Compute\v2\Api;
77
use OpenStack\Compute\v2\Models\Flavor;
8+
use OpenStack\Compute\v2\Models\HypervisorStatistic;
89
use OpenStack\Compute\v2\Models\Image;
910
use OpenStack\Compute\v2\Models\Keypair;
1011
use OpenStack\Compute\v2\Models\Server;
@@ -126,4 +127,16 @@ public function test_it_lists_keypairs()
126127
$this->assertInstanceOf(Keypair::class, $keypair);
127128
}
128129
}
130+
131+
public function test_it_gets_hypervisor_statistics()
132+
{
133+
$this->client
134+
->request('GET', 'os-hypervisors/statistics', ['headers' => []])
135+
->shouldBeCalled()
136+
->willReturn($this->getFixture('hypervisor-get'));
137+
138+
$hypervisorStats = $this->service->getHypervisorStatistics();
139+
140+
$this->assertInstanceOf(HypervisorStatistic::class, $hypervisorStats);
141+
}
129142
}

0 commit comments

Comments
 (0)