2
2
3
3
namespace OpenStack \Integration \Networking \v2 ;
4
4
5
+ use Guzzle \Tests \Service \Mock \Command \Sub \Sub ;
5
6
use OpenCloud \Integration \TestCase ;
6
7
use OpenStack \Networking \v2 \Extensions \Layer3 \Models \FloatingIp ;
7
8
use OpenStack \Networking \v2 \Models \Network ;
@@ -36,50 +37,89 @@ public function teardown()
36
37
$ this ->deleteItems ($ this ->getService ()->listFloatingIps ());
37
38
}
38
39
39
- private function createNetwork (): Network
40
+ private function createNetwork (bool $ routerAccessible = true ): Network
40
41
{
41
- $ network = $ this ->getV2Service ()->createNetwork (['name ' => $ this ->randomStr (), 'routerAccessible ' => true ]);
42
+ $ network = $ this ->getV2Service ()->createNetwork ([
43
+ 'name ' => $ this ->randomStr (),
44
+ 'routerAccessible ' => $ routerAccessible ,
45
+ ]);
42
46
$ network ->waitUntilActive ();
43
47
return $ network ;
44
48
}
45
49
46
- private function createSubnet (Network $ network ): Subnet
50
+ private function createSubnet (Network $ network, string $ cidr = ' 192.168.199.0/24 ' ): Subnet
47
51
{
48
52
return $ this ->getV2Service ()->createSubnet ([
49
53
'networkId ' => $ network ->id ,
50
54
'name ' => $ this ->randomStr (),
51
55
'ipVersion ' => 4 ,
52
- 'cidr ' => ' 192.168.199.0/24 ' ,
56
+ 'cidr ' => $ cidr ,
53
57
]);
54
58
}
55
59
56
60
private function createPort (Network $ network ): Port
57
61
{
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 '' ;
59
77
}
60
78
61
79
public function floatingIps ()
62
80
{
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 ' );
65
86
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 );
68
89
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 );
71
110
72
111
$ replacements = [
73
- '{networkId} ' => $ network ->id ,
74
- '{portId} ' => $ port1 ->id ,
112
+ '{networkId} ' => $ externalNetwork ->id ,
113
+ '{portId} ' => $ port1 ->id ,
114
+ '{fixedIpAddress} ' => $ fixedIp ,
75
115
];
76
116
77
117
$ this ->logStep ('Create floating IP ' );
78
118
/** @var FloatingIp $ip */
79
119
$ path = $ this ->sampleFile ($ replacements , 'floatingIPs/create.php ' );
80
120
require_once $ path ;
81
121
$ this ->assertInstanceOf (FloatingIp::class, $ ip );
82
- $ this ->assertEquals ($ network ->id , $ ip ->floatingNetworkId );
122
+ $ this ->assertEquals ($ externalNetwork ->id , $ ip ->floatingNetworkId );
83
123
$ this ->assertEquals ($ port1 ->id , $ ip ->portId );
84
124
85
125
$ this ->logStep ('List floating IPs ' );
@@ -93,17 +133,26 @@ public function floatingIps()
93
133
$ this ->assertInstanceOf (FloatingIp::class, $ ip );
94
134
95
135
$ this ->logStep ('Update floating IP ' );
96
- $ port2 = $ this ->createPort ($ network );
136
+ $ port2 = $ this ->createPort ($ internalNetwork );
97
137
$ replacements ['{newPortId} ' ] = $ port2 ->id ;
98
138
$ path = $ this ->sampleFile ($ replacements , 'floatingIPs/update.php ' );
99
139
require_once $ path ;
100
140
101
141
$ this ->logStep ('Delete floating IP ' );
102
- $ path = $ this ->sampleFile ($ replacements , 'floatingIPs/update .php ' );
142
+ $ path = $ this ->sampleFile ($ replacements , 'floatingIPs/delete .php ' );
103
143
require_once $ path ;
104
144
145
+ $ router ->removeInterface (['subnetId ' => $ subnet ->id ]);
146
+ $ router ->delete ();
147
+ $ router ->waitUntilDeleted ();
148
+
105
149
$ port1 ->delete ();
106
150
$ port2 ->delete ();
107
- $ network ->delete ();
151
+
152
+ $ internalNetwork ->delete ();
153
+ $ internalNetwork ->waitUntilDeleted ();
154
+
155
+ $ externalNetwork ->delete ();
156
+ $ externalNetwork ->waitUntilDeleted ();
108
157
}
109
158
}
0 commit comments