Skip to content

Commit c04e3be

Browse files
committed
Setting up tests
1 parent 58d4f8c commit c04e3be

File tree

4 files changed

+181
-3
lines changed

4 files changed

+181
-3
lines changed

src/Compute/v2/Models/Hypervisor.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace OpenStack\Compute\v2\Models;
4+
5+
use OpenStack\Common\Resource\Listable;
6+
use OpenStack\Common\Resource\OperatorResource;
7+
8+
/**
9+
* @property \OpenStack\Compute\v2\Api $api
10+
*/
11+
class Hypervisor extends OperatorResource implements
12+
Listable
13+
{
14+
/** @var string */
15+
public $id;
16+
17+
/** @var string */
18+
public $status;
19+
20+
/** @var string */
21+
public $state;
22+
23+
/** @var string */
24+
public $host_ip;
25+
26+
/** @var int */
27+
public $free_disk_gb;
28+
29+
/** @var int */
30+
public $free_ram_mb;
31+
32+
/** @var string */
33+
public $hypervisor_hostname;
34+
35+
/** @var string */
36+
public $hypervisor_type;
37+
38+
/** @var string */
39+
public $hypervisor_version;
40+
41+
/** @var int */
42+
public $local_gb;
43+
44+
/** @var int */
45+
public $local_gb_used;
46+
47+
/** @var int */
48+
public $memory_mb;
49+
50+
/** @var int */
51+
public $memory_mb_used;
52+
53+
/** @var int */
54+
public $running_vms;
55+
56+
/** @var int */
57+
public $vcpus;
58+
59+
/** @var int */
60+
public $vcpus_used;
61+
62+
/** @var array */
63+
public $service;
64+
65+
protected $resourceKey = 'hypervisor';
66+
protected $resourcesKey = 'hypervisors';
67+
protected $markerKey = 'id';
68+
69+
}

tests/integration/Compute/v2/CoreTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use OpenStack\BlockStorage\v2\Models\Volume;
66
use OpenStack\Compute\v2\Models\Flavor;
77
use OpenStack\Compute\v2\Models\HypervisorStatistic;
8+
use OpenStack\Compute\v2\Models\Hypervisor;
89
use OpenStack\Compute\v2\Models\Image;
910
use OpenStack\Compute\v2\Models\Keypair;
1011
use OpenStack\Compute\v2\Models\Limit;
@@ -66,7 +67,7 @@ private function getNetworkService()
6667

6768
return $this->networkService;
6869
}
69-
70+
7071
private function getBlockStorageService()
7172
{
7273
if (!$this->blockStorageService) {
@@ -179,6 +180,9 @@ public function runTests()
179180

180181
// Limits
181182
$this->getLimits();
183+
184+
// Hypervisors
185+
$this->listHypervisors();
182186
$this->getHypervisorsStatistics();
183187

184188
// Console
@@ -549,6 +553,13 @@ private function deleteKeypair()
549553
$this->logStep('Deleted keypair name {name}', ['{name}' => $this->keypairName]);
550554
}
551555

556+
private function listHypervisors()
557+
{
558+
require_once $this->sampleFile([], 'hypervisors/list_hypervisors.php');
559+
560+
$this->logStep('Listed all available hypervisors');
561+
}
562+
552563
private function getHypervisorsStatistics()
553564
{
554565
require_once $this->sampleFile([], 'hypervisors/get_hypervisors_statistics.php');
@@ -575,7 +586,7 @@ private function addSecurityGroupToServer()
575586
'{serverId}' => $this->serverId,
576587
'{secGroupName}' => 'default'
577588
];
578-
589+
579590
require_once $this->sampleFile($replacements, 'servers/add_security_group.php');
580591

581592
/**@var Server $server*/
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
HTTP/1.1 200 OK
2+
Content-Type: application/json
3+
4+
{
5+
"hypervisors": [
6+
{
7+
"cpu_info": {
8+
"arch": "x86_64",
9+
"model": "Nehalem",
10+
"vendor": "Intel",
11+
"features": [
12+
"pge",
13+
"clflush"
14+
],
15+
"topology": {
16+
"cores": 1,
17+
"threads": 1,
18+
"sockets": 4
19+
}
20+
},
21+
"current_workload": 0,
22+
"status": "enabled",
23+
"state": "up",
24+
"disk_available_least": 0,
25+
"host_ip": "1.1.1.1",
26+
"free_disk_gb": 1028,
27+
"free_ram_mb": 7680,
28+
"hypervisor_hostname": "fake-mini",
29+
"hypervisor_type": "fake",
30+
"hypervisor_version": 1000,
31+
"id": 1,
32+
"local_gb": 1028,
33+
"local_gb_used": 0,
34+
"memory_mb": 8192,
35+
"memory_mb_used": 512,
36+
"running_vms": 0,
37+
"service": {
38+
"host": "e6a37ee802d74863ab8b91ade8f12a67",
39+
"id": 2,
40+
"disabled_reason": null
41+
},
42+
"vcpus": 1,
43+
"vcpus_used": 0
44+
},
45+
{
46+
"cpu_info": {
47+
"arch": "x86_64",
48+
"model": "Nehalem",
49+
"vendor": "Intel",
50+
"features": [
51+
"pge",
52+
"clflush"
53+
],
54+
"topology": {
55+
"cores": 1,
56+
"threads": 1,
57+
"sockets": 4
58+
}
59+
},
60+
"current_workload": 2,
61+
"status": "disabled",
62+
"state": "up",
63+
"disk_available_least": 0,
64+
"host_ip": "1.1.1.2",
65+
"free_disk_gb": 2048,
66+
"free_ram_mb": 8192,
67+
"hypervisor_hostname": "qemu-1",
68+
"hypervisor_type": "QEMU",
69+
"hypervisor_version": 1000,
70+
"id": 1,
71+
"local_gb": 10280,
72+
"local_gb_used": 1024,
73+
"memory_mb": 8192,
74+
"memory_mb_used": 512,
75+
"running_vms": 1,
76+
"service": {
77+
"host": "e6a37ee802d74863ab8b91ade8f1aaab",
78+
"id": 3,
79+
"disabled_reason": null
80+
},
81+
"vcpus": 4,
82+
"vcpus_used": 1
83+
}
84+
]
85+
}

tests/unit/Compute/v2/ServiceTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use OpenStack\Compute\v2\Models\Image;
1010
use OpenStack\Compute\v2\Models\Keypair;
1111
use OpenStack\Compute\v2\Models\Server;
12+
use OpenStack\Compute\v2\Models\Hypervisor;
1213
use OpenStack\Compute\v2\Service;
1314
use OpenStack\Test\TestCase;
1415
use Prophecy\Argument;
@@ -127,7 +128,7 @@ public function test_it_lists_keypairs()
127128
$this->assertInstanceOf(Keypair::class, $keypair);
128129
}
129130
}
130-
131+
131132
public function test_it_gets_hypervisor_statistics()
132133
{
133134
$this->client
@@ -139,4 +140,16 @@ public function test_it_gets_hypervisor_statistics()
139140

140141
$this->assertInstanceOf(HypervisorStatistic::class, $hypervisorStats);
141142
}
143+
144+
public function test_it_lists_hypervisors()
145+
{
146+
$this->client
147+
->request('GET', 'os-hypervisors', ['query' => ['limit' => 2], 'headers' => []])
148+
->shouldBeCalled()
149+
->willReturn($this->getFixture('hypervisors-get'));
150+
151+
foreach ($this->service->listHypervisors(false, ['limit' => 2]) as $hypervisor) {
152+
$this->assertInstanceOf(Hypervisor::class, $hypervisor);
153+
}
154+
}
142155
}

0 commit comments

Comments
 (0)