Skip to content

Commit 5d22feb

Browse files
committed
Fix CS issues and refactor LoadBalancerStatus::retrieve()
1 parent 7fc5f00 commit 5d22feb

File tree

7 files changed

+83
-101
lines changed

7 files changed

+83
-101
lines changed

src/Networking/v2/Api.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ public function getLoadBalancers(): array
355355
{
356356
return [
357357
'method' => 'GET',
358-
'path' => $this->pathPrefix . '/lbaas/loadbalancers',
358+
'path' => $this->pathPrefix . '/lbaas/loadbalancers',
359359
'params' => []
360360
];
361361
}
@@ -364,7 +364,7 @@ public function getLoadBalancer(): array
364364
{
365365
return [
366366
'method' => 'GET',
367-
'path' => $this->pathPrefix . '/lbaas/loadbalancers/{id}',
367+
'path' => $this->pathPrefix . '/lbaas/loadbalancers/{id}',
368368
'params' => []
369369
];
370370
}
@@ -417,7 +417,7 @@ public function getLoadBalancerListeners(): array
417417
{
418418
return [
419419
'method' => 'GET',
420-
'path' => $this->pathPrefix . '/lbaas/listeners',
420+
'path' => $this->pathPrefix . '/lbaas/listeners',
421421
'params' => []
422422
];
423423
}
@@ -426,7 +426,7 @@ public function getLoadBalancerListener(): array
426426
{
427427
return [
428428
'method' => 'GET',
429-
'path' => $this->pathPrefix . '/lbaas/listeners/{id}',
429+
'path' => $this->pathPrefix . '/lbaas/listeners/{id}',
430430
'params' => []
431431
];
432432
}
@@ -481,7 +481,7 @@ public function getLoadBalancerPools(): array
481481
{
482482
return [
483483
'method' => 'GET',
484-
'path' => $this->pathPrefix . '/lbaas/pools',
484+
'path' => $this->pathPrefix . '/lbaas/pools',
485485
'params' => []
486486
];
487487
}
@@ -490,7 +490,7 @@ public function getLoadBalancerPool(): array
490490
{
491491
return [
492492
'method' => 'GET',
493-
'path' => $this->pathPrefix . '/lbaas/pools/{id}',
493+
'path' => $this->pathPrefix . '/lbaas/pools/{id}',
494494
'params' => []
495495
];
496496
}
@@ -545,7 +545,7 @@ public function getLoadBalancerMembers(): array
545545
{
546546
return [
547547
'method' => 'GET',
548-
'path' => $this->pathPrefix . '/lbaas/pools/{poolId}/members',
548+
'path' => $this->pathPrefix . '/lbaas/pools/{poolId}/members',
549549
'params' => [
550550
'poolId' => $this->params->poolId()
551551
]
@@ -556,7 +556,7 @@ public function getLoadBalancerMember(): array
556556
{
557557
return [
558558
'method' => 'GET',
559-
'path' => $this->pathPrefix . '/lbaas/pools/{poolId}/members/{id}',
559+
'path' => $this->pathPrefix . '/lbaas/pools/{poolId}/members/{id}',
560560
'params' => [
561561
'id' => $this->params->idPath('member'),
562562
'poolId' => $this->params->poolId()
@@ -612,7 +612,7 @@ public function getLoadBalancerStats(): array
612612
{
613613
return [
614614
'method' => 'GET',
615-
'path' => $this->pathPrefix . '/lbaas/loadbalancers/{loadbalancerId}/stats',
615+
'path' => $this->pathPrefix . '/lbaas/loadbalancers/{loadbalancerId}/stats',
616616
'params' => [
617617
'loadbalancerId' => $this->params->loadBalancerIdUrl()
618618
]
@@ -623,7 +623,7 @@ public function getLoadBalancerStatuses(): array
623623
{
624624
return [
625625
'method' => 'GET',
626-
'path' => $this->pathPrefix . '/lbaas/loadbalancers/{loadbalancerId}/statuses',
626+
'path' => $this->pathPrefix . '/lbaas/loadbalancers/{loadbalancerId}/statuses',
627627
'params' => [
628628
'loadbalancerId' => $this->params->loadBalancerIdUrl()
629629
]
@@ -634,7 +634,7 @@ public function getLoadBalancerHealthMonitors(): array
634634
{
635635
return [
636636
'method' => 'GET',
637-
'path' => $this->pathPrefix . '/lbaas/healthmonitors',
637+
'path' => $this->pathPrefix . '/lbaas/healthmonitors',
638638
'params' => []
639639
];
640640
}
@@ -643,7 +643,7 @@ public function getLoadBalancerHealthMonitor(): array
643643
{
644644
return [
645645
'method' => 'GET',
646-
'path' => $this->pathPrefix . '/lbaas/healthmonitors/{id}',
646+
'path' => $this->pathPrefix . '/lbaas/healthmonitors/{id}',
647647
'params' => [
648648
'id' => $this->params->idPath()
649649
]
@@ -696,7 +696,7 @@ public function deleteLoadBalancerHealthMonitor() : array
696696
'method' => 'DELETE',
697697
'path' => $this->pathPrefix . '/lbaas/healthmonitors/{id}',
698698
'params' => [
699-
'id' => $this->params->idPath()
699+
'id' => $this->params->idPath()
700700
]
701701
];
702702
}

src/Networking/v2/Models/LoadBalancerStatus.php

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,12 @@ class LoadBalancerStatus extends OperatorResource implements Retrievable
4343
*/
4444
public $listeners;
4545

46-
/**
47-
* @var LoadBalancer
48-
*/
49-
public $loadbalancer;
50-
5146
protected $resourceKey = 'statuses';
5247

5348
protected $aliases = [
54-
'loadbalancer_id' => 'loadbalancerId'
49+
'loadbalancer_id' => 'loadbalancerId',
50+
'operating_status' => 'operatingStatus',
51+
'provisioning_status' => 'provisioningStatus'
5552
];
5653

5754
/**
@@ -60,22 +57,7 @@ class LoadBalancerStatus extends OperatorResource implements Retrievable
6057
public function retrieve()
6158
{
6259
$response = $this->execute($this->api->getLoadBalancerStatuses(), ['loadbalancerId' => (string)$this->loadbalancerId]);
63-
$this->populateFromResponse($response);
64-
$this->flattenStatus();
65-
}
66-
67-
/**
68-
* Flatten this class to something more usable
69-
*/
70-
private function flattenStatus()
71-
{
72-
if ($this->loadbalancer instanceof LoadBalancer) {
73-
$this->name = $this->loadbalancer->name;
74-
$this->id = $this->loadbalancer->id;
75-
$this->operatingStatus = $this->loadbalancer->operatingStatus;
76-
$this->provisioningStatus = $this->loadbalancer->provisioningStatus;
77-
$this->listeners = $this->loadbalancer->listeners;
78-
unset($this->loadbalancer);
79-
}
60+
$json = Utils::jsonDecode($response);
61+
$this->populateFromArray($json[$this->resourceKey]['loadbalancer']);
8062
}
8163
}

tests/unit/Networking/v2/Models/LoadBalancerHealthMonitorTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ public function test_it_creates()
3737

3838
$expectedJson = ['healthmonitor' => [
3939
'admin_state_up' => $opts['adminStateUp'],
40-
'tenant_id' => $opts['tenantId'],
41-
'delay' => $opts['delay'],
42-
'type' => $opts['type'],
40+
'tenant_id' => $opts['tenantId'],
41+
'delay' => $opts['delay'],
42+
'type' => $opts['type'],
4343
'expected_codes' => $opts['expectedCodes'],
44-
'max_retries' => $opts['maxRetries'],
45-
'http_method' => $opts['httpMethod'],
46-
'url_path' => $opts['urlPath'],
47-
'timeout' => $opts['timeout']
44+
'max_retries' => $opts['maxRetries'],
45+
'http_method' => $opts['httpMethod'],
46+
'url_path' => $opts['urlPath'],
47+
'timeout' => $opts['timeout']
4848
]];
4949

5050
$this->setupMock('POST', 'v2.0/lbaas/healthmonitors', $expectedJson, [], 'loadbalancer-healthmonitor-post');
@@ -64,11 +64,11 @@ public function test_it_updates()
6464
$this->healthmonitor->adminStateUp = true;
6565

6666
$expectedJson = ['healthmonitor' => [
67-
'delay' => 48,
68-
'timeout' => 54,
69-
'max_retries' => 11,
70-
'http_method' => 'POST',
71-
'url_path' => 'test2',
67+
'delay' => 48,
68+
'timeout' => 54,
69+
'max_retries' => 11,
70+
'http_method' => 'POST',
71+
'url_path' => 'test2',
7272
'expected_codes' => '200,201,202',
7373
'admin_state_up' => true
7474
]];

tests/unit/Networking/v2/Models/LoadBalancerListenerTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ public function test_it_creates()
3434
];
3535

3636
$expectedJson = ['listener' => [
37-
'name' => $opts['name'],
38-
'description' => $opts['description'],
39-
'tenant_id' => $opts['tenantId'],
40-
'protocol' => $opts['protocol'],
41-
'protocol_port' => $opts['protocolPort'],
42-
'admin_state_up' => $opts['adminStateUp'],
37+
'name' => $opts['name'],
38+
'description' => $opts['description'],
39+
'tenant_id' => $opts['tenantId'],
40+
'protocol' => $opts['protocol'],
41+
'protocol_port' => $opts['protocolPort'],
42+
'admin_state_up' => $opts['adminStateUp'],
4343
'connection_limit' => $opts['connectionLimit']
4444
]];
4545

@@ -57,10 +57,10 @@ public function test_it_updates()
5757
$this->listener->adminStateUp = false;
5858

5959
$expectedJson = ['listener' => [
60-
'name' => 'foo',
61-
'description' => 'bar',
60+
'name' => 'foo',
61+
'description' => 'bar',
6262
'connection_limit' => 999,
63-
'admin_state_up' => false
63+
'admin_state_up' => false
6464
]];
6565

6666
$this->setupMock('PUT', 'v2.0/lbaas/listeners/listenerId', $expectedJson, [], 'loadbalancer-listener-put');

tests/unit/Networking/v2/Models/LoadBalancerMemberTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public function test_it_creates()
3333
];
3434

3535
$expectedJson = ['member' => [
36-
'address' => $opts['address'],
37-
'protocol_port' => $opts['protocolPort'],
38-
'weight' => $opts['weight'],
39-
'subnet_id' => $opts['subnetId'],
36+
'address' => $opts['address'],
37+
'protocol_port' => $opts['protocolPort'],
38+
'weight' => $opts['weight'],
39+
'subnet_id' => $opts['subnetId'],
4040
'admin_state_up' => $opts['adminStateUp']
4141
]];
4242

@@ -52,7 +52,7 @@ public function test_it_updates()
5252
$this->member->adminStateUp = false;
5353

5454
$expectedJson = ['member' => [
55-
'weight' => 154,
55+
'weight' => 154,
5656
'admin_state_up' => false
5757
]];
5858

tests/unit/Networking/v2/Models/LoadBalancerPoolTest.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ public function test_it_creates()
3232
'lbAlgorithm' => 'ROUND_ROBIN',
3333
'listenerId' => 'listener1',
3434
'sessionPersistence' => [
35-
'type' => 'APP_COOKIE',
35+
'type' => 'APP_COOKIE',
3636
'cookie_name' => 'my_cookie'
3737
],
3838
'adminStateUp' => true
3939
];
4040

4141
$expectedJson = ['pool' => [
42-
'name' => $opts['name'],
43-
'description' => $opts['description'],
44-
'protocol' => $opts['protocol'],
45-
'lb_algorithm' => $opts['lbAlgorithm'],
46-
'listener_id' => $opts['listenerId'],
42+
'name' => $opts['name'],
43+
'description' => $opts['description'],
44+
'protocol' => $opts['protocol'],
45+
'lb_algorithm' => $opts['lbAlgorithm'],
46+
'listener_id' => $opts['listenerId'],
4747
'session_persistence' => $opts['sessionPersistence'],
48-
'admin_state_up' => $opts['adminStateUp']
48+
'admin_state_up' => $opts['adminStateUp']
4949
]];
5050

5151
$this->setupMock('POST', 'v2.0/lbaas/pools', $expectedJson, [], 'loadbalancer-pool-post');
@@ -60,20 +60,20 @@ public function test_it_updates()
6060
$this->pool->description = 'bar';
6161
$this->pool->lbAlgorithm = 'LEAST_CONNECTIONS';
6262
$this->pool->sessionPersistence = [
63-
'type' => 'APP_COOKIE',
63+
'type' => 'APP_COOKIE',
6464
'cookie_name' => 'new_cookie'
6565
];
6666
$this->pool->adminStateUp = false;
6767

6868
$expectedJson = ['pool' => [
69-
'name' => 'foo',
70-
'description' => 'bar',
71-
'lb_algorithm' => 'LEAST_CONNECTIONS',
69+
'name' => 'foo',
70+
'description' => 'bar',
71+
'lb_algorithm' => 'LEAST_CONNECTIONS',
7272
'session_persistence' => [
73-
'type' => 'APP_COOKIE',
73+
'type' => 'APP_COOKIE',
7474
'cookie_name' => 'new_cookie'
7575
],
76-
'admin_state_up' => false
76+
'admin_state_up' => false
7777
]];
7878

7979
$this->setupMock('PUT', 'v2.0/lbaas/pools/poolId', $expectedJson, [], 'loadbalancer-pool-put');
@@ -110,11 +110,11 @@ public function test_add_member()
110110
];
111111

112112
$expectedJson = ['member' => [
113-
'address' => $opts['address'],
114-
'protocol_port' => $opts['protocolPort'],
115-
'subnet_id' => $opts['subnetId'],
113+
'address' => $opts['address'],
114+
'protocol_port' => $opts['protocolPort'],
115+
'subnet_id' => $opts['subnetId'],
116116
'admin_state_up' => $opts['adminStateUp'],
117-
'weight' => $opts['weight']
117+
'weight' => $opts['weight']
118118
]];
119119

120120
$this->setupMock('POST', 'v2.0/lbaas/pools/poolId/members', $expectedJson, [], 'loadbalancer-member-post');
@@ -152,15 +152,15 @@ public function test_add_health_monitor()
152152

153153
$expectedJson = ['healthmonitor' => [
154154
'admin_state_up' => $opts['adminStateUp'],
155-
'tenant_id' => $opts['tenantId'],
156-
'delay' => $opts['delay'],
157-
'type' => $opts['type'],
155+
'tenant_id' => $opts['tenantId'],
156+
'delay' => $opts['delay'],
157+
'type' => $opts['type'],
158158
'expected_codes' => $opts['expectedCodes'],
159-
'max_retries' => $opts['maxRetries'],
160-
'http_method' => $opts['httpMethod'],
161-
'url_path' => $opts['urlPath'],
162-
'timeout' => $opts['timeout'],
163-
'pool_id' => $this->pool->id
159+
'max_retries' => $opts['maxRetries'],
160+
'http_method' => $opts['httpMethod'],
161+
'url_path' => $opts['urlPath'],
162+
'timeout' => $opts['timeout'],
163+
'pool_id' => $this->pool->id
164164
]];
165165

166166
$this->setupMock('POST', 'v2.0/lbaas/healthmonitors', $expectedJson, [], 'loadbalancer-healthmonitor-post');

0 commit comments

Comments
 (0)