Skip to content

Commit 2066717

Browse files
author
Jamie Hannaford
committed
add layer-3 integration tests; add fixes
1 parent 94d784a commit 2066717

File tree

4 files changed

+75
-20
lines changed

4 files changed

+75
-20
lines changed

samples/networking/v2/floatingIPs/create.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
'region' => '{region}',
88
'user' => [
99
'id' => '{userId}',
10-
'password' => '{password}'
10+
'password' => '{password}',
1111
],
12-
'scope' => ['project' => ['id' => '{projectId}']]
12+
'scope' => ['project' => ['id' => '{projectId}']],
1313
]);
1414

1515
$networking = $openstack->networkingV2ExtLayer3();
@@ -18,4 +18,5 @@
1818
$ip = $networking->createFloatingIp([
1919
"floatingNetworkId" => "{networkId}",
2020
"portId" => "{portId}",
21+
'fixedIpAddress' => '{fixedIpAddress}',
2122
]);

src/Networking/v2/Extensions/Layer3/Api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function putFloatingIp(): array
4646
'jsonKey' => 'floatingip',
4747
'params' => [
4848
'id' => $this->params->idPath(),
49-
'floatingNetworkId' => $this->params->floatingNetworkIdJson(),
49+
'floatingNetworkId' => $this->notRequired($this->params->floatingNetworkIdJson()),
5050
'fixedIpAddress' => $this->params->fixedIpAddressJson(),
5151
'floatingIpAddress' => $this->params->floatingIpAddressJson(),
5252
'portId' => $this->params->portIdJson(),

src/Networking/v2/Extensions/Layer3/Models/Router.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace OpenStack\Networking\v2\Extensions\Layer3\Models;
44

5+
use OpenCloud\Common\Resource\HasWaiterTrait;
56
use OpenCloud\Common\Resource\OperatorResource;
67
use OpenCloud\Common\Resource\Creatable;
78
use OpenCloud\Common\Resource\Deletable;
@@ -15,6 +16,8 @@
1516
*/
1617
class Router extends OperatorResource implements Listable, Creatable, Retrievable, Updateable, Deletable
1718
{
19+
use HasWaiterTrait;
20+
1821
/** @var string */
1922
public $status;
2023

@@ -36,6 +39,8 @@ class Router extends OperatorResource implements Listable, Creatable, Retrievabl
3639
/** @var string */
3740
public $id;
3841

42+
protected $resourceKey = 'router';
43+
3944
protected $aliases = [
4045
'external_gateway_info' => 'externalGatewayInfo',
4146
'admin_state_up' => 'adminStateUp',

tests/integration/Networking/v2/Layer3Test.php

Lines changed: 66 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace OpenStack\Integration\Networking\v2;
44

5+
use Guzzle\Tests\Service\Mock\Command\Sub\Sub;
56
use OpenCloud\Integration\TestCase;
67
use OpenStack\Networking\v2\Extensions\Layer3\Models\FloatingIp;
78
use OpenStack\Networking\v2\Models\Network;
@@ -36,50 +37,89 @@ public function teardown()
3637
$this->deleteItems($this->getService()->listFloatingIps());
3738
}
3839

39-
private function createNetwork(): Network
40+
private function createNetwork(bool $routerAccessible = true): Network
4041
{
41-
$network = $this->getV2Service()->createNetwork(['name' => $this->randomStr(), 'routerAccessible' => true]);
42+
$network = $this->getV2Service()->createNetwork([
43+
'name' => $this->randomStr(),
44+
'routerAccessible' => $routerAccessible,
45+
]);
4246
$network->waitUntilActive();
4347
return $network;
4448
}
4549

46-
private function createSubnet(Network $network): Subnet
50+
private function createSubnet(Network $network, string $cidr = '192.168.199.0/24'): Subnet
4751
{
4852
return $this->getV2Service()->createSubnet([
4953
'networkId' => $network->id,
5054
'name' => $this->randomStr(),
5155
'ipVersion' => 4,
52-
'cidr' => '192.168.199.0/24',
56+
'cidr' => $cidr,
5357
]);
5458
}
5559

5660
private function createPort(Network $network): Port
5761
{
58-
return $this->getV2Service()->createPort(['networkId' => $network->id, 'name' => $this->randomStr()]);
62+
return $this->getV2Service()->createPort([
63+
'networkId' => $network->id,
64+
'name' => $this->randomStr(),
65+
]);
66+
}
67+
68+
private function findSubnetIp(Port $port, Subnet $subnet): string
69+
{
70+
foreach ($port->fixedIps as $fixedIp) {
71+
if ($fixedIp['subnet_id'] == $subnet->id) {
72+
return $fixedIp['ip_address'];
73+
}
74+
}
75+
76+
return '';
5977
}
6078

6179
public function floatingIps()
6280
{
63-
$this->logStep('Creating network');
64-
$network = $this->createNetwork();
81+
$this->logStep('Creating external network');
82+
$externalNetwork = $this->createNetwork();
83+
84+
$this->logStep('Creating subnet for external network %id%', ['%id%' => $externalNetwork->id]);
85+
$this->createSubnet($externalNetwork, '10.0.0.0/24');
6586

66-
$this->logStep('Creating subnet for network %id%', ['%id%' => $network->id]);
67-
$this->createSubnet($network);
87+
$this->logStep('Creating internal network');
88+
$internalNetwork = $this->createNetwork(false);
6889

69-
$this->logStep('Creating port for network %id%', ['%id%' => $network->id]);
70-
$port1 = $this->createPort($network);
90+
$this->logStep('Creating subnet for internal network %id%', ['%id%' => $internalNetwork->id]);
91+
$subnet = $this->createSubnet($internalNetwork);
92+
93+
$this->logStep('Creating router for external network %id%', ['%id%' => $externalNetwork->id]);
94+
$router = $this->getService()->createRouter([
95+
'name' => $this->randomStr(),
96+
'externalGatewayInfo' => [
97+
'networkId' => $externalNetwork->id,
98+
'enableSnat' => true,
99+
],
100+
]);
101+
102+
$this->logStep('Create interface for subnet %subnet% and router %router%', [
103+
'%subnet%' => $subnet->id, '%router%' => $router->id,
104+
]);
105+
$router->addInterface(['subnetId' => $subnet->id]);
106+
107+
$this->logStep('Creating port for internal network %id%', ['%id%' => $internalNetwork->id]);
108+
$port1 = $this->createPort($internalNetwork);
109+
$fixedIp = $this->findSubnetIp($port1, $subnet);
71110

72111
$replacements = [
73-
'{networkId}' => $network->id,
74-
'{portId}' => $port1->id,
112+
'{networkId}' => $externalNetwork->id,
113+
'{portId}' => $port1->id,
114+
'{fixedIpAddress}' => $fixedIp,
75115
];
76116

77117
$this->logStep('Create floating IP');
78118
/** @var FloatingIp $ip */
79119
$path = $this->sampleFile($replacements, 'floatingIPs/create.php');
80120
require_once $path;
81121
$this->assertInstanceOf(FloatingIp::class, $ip);
82-
$this->assertEquals($network->id, $ip->floatingNetworkId);
122+
$this->assertEquals($externalNetwork->id, $ip->floatingNetworkId);
83123
$this->assertEquals($port1->id, $ip->portId);
84124

85125
$this->logStep('List floating IPs');
@@ -93,17 +133,26 @@ public function floatingIps()
93133
$this->assertInstanceOf(FloatingIp::class, $ip);
94134

95135
$this->logStep('Update floating IP');
96-
$port2 = $this->createPort($network);
136+
$port2 = $this->createPort($internalNetwork);
97137
$replacements['{newPortId}'] = $port2->id;
98138
$path = $this->sampleFile($replacements, 'floatingIPs/update.php');
99139
require_once $path;
100140

101141
$this->logStep('Delete floating IP');
102-
$path = $this->sampleFile($replacements, 'floatingIPs/update.php');
142+
$path = $this->sampleFile($replacements, 'floatingIPs/delete.php');
103143
require_once $path;
104144

145+
$router->removeInterface(['subnetId' => $subnet->id]);
146+
$router->delete();
147+
$router->waitUntilDeleted();
148+
105149
$port1->delete();
106150
$port2->delete();
107-
$network->delete();
151+
152+
$internalNetwork->delete();
153+
$internalNetwork->waitUntilDeleted();
154+
155+
$externalNetwork->delete();
156+
$externalNetwork->waitUntilDeleted();
108157
}
109158
}

0 commit comments

Comments
 (0)