Skip to content

Commit 513c535

Browse files
committed
dxcli-1121 lb pools
1 parent b2e3380 commit 513c535

3 files changed

Lines changed: 326 additions & 0 deletions

File tree

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Copyright 2012-2013 OpenStack, LLC.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
#
15+
16+
"""Load Balancer pool action implementations"""
17+
18+
from neutronclient.neutron.v2_0.lb import pool as neu2
19+
from openstackclient.network import v2_0 as v2_0
20+
21+
22+
class CreatePool(v2_0.CreateCommand):
23+
"""Create a load balancer pool"""
24+
25+
clazz = neu2.CreatePool
26+
27+
def get_parser(self, prog_name):
28+
parser = super(CreatePool, self).get_parser(prog_name)
29+
parser.add_argument(
30+
'name',
31+
help='The name of the pool')
32+
parser.add_argument(
33+
'--admin-state-down',
34+
dest='admin_state', action='store_false',
35+
help='Set admin state up to false')
36+
parser.add_argument(
37+
'--description',
38+
help='Description of the pool')
39+
parser.add_argument(
40+
'--lb-method',
41+
required=True,
42+
choices=['ROUND_ROBIN', 'LEAST_CONNECTIONS', 'SOURCE_IP'],
43+
help='The algorithm used to distribute load between the members '
44+
'of the pool')
45+
parser.add_argument(
46+
'--protocol',
47+
required=True,
48+
choices=['HTTP', 'HTTPS', 'TCP'],
49+
help='Protocol for balancing')
50+
parser.add_argument(
51+
'--subnet-id', metavar='SUBNET',
52+
required=True,
53+
help='The subnet on which the members of the pool will be located')
54+
parser.add_argument(
55+
'--provider',
56+
help='Provider name of loadbalancer service')
57+
return parser
58+
59+
60+
class DeletePool(v2_0.DeleteCommand):
61+
"""Delete a load balancer pool"""
62+
63+
clazz = neu2.DeletePool
64+
name = 'pool'
65+
metavar = '<pool>'
66+
help_text = 'Name or ID of load balancer pool to delete'
67+
68+
69+
class ListPool(v2_0.ListCommand):
70+
"""List load balancer pool"""
71+
72+
clazz = neu2.ListPool
73+
74+
75+
class SetPool(v2_0.SetCommand):
76+
"""Set load balancer pool values"""
77+
78+
clazz = neu2.UpdatePool
79+
name = 'pool'
80+
metavar = '<pool>'
81+
help_text = 'Name or ID of load balancer pool to update'
82+
83+
84+
class ShowPool(v2_0.ShowCommand):
85+
"""Show a load balancer pool"""
86+
87+
clazz = neu2.ShowPool
88+
name = 'pool'
89+
metavar = '<pool>'
90+
help_text = 'Name or ID of pool to show'
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Copyright 2013 OpenStack, LLC.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
#
15+
16+
from openstackclient.network.v2_0.lb import pool
17+
from openstackclient.tests.network.v2_0 import common
18+
19+
20+
class TestCreateLbPool(common.TestNetworkBase):
21+
def test_get_parser_nothing(self):
22+
given = "--lb-method ROUND_ROBIN --protocol HTTP --subnet-id 34" + \
23+
" pool1" + self.given_default_show_options()
24+
parsed = self.given_args(pool.CreatePool, given)
25+
self.assertEqual('pool1', parsed.name)
26+
self.assertEqual('ROUND_ROBIN', parsed.lb_method)
27+
self.assertEqual('HTTP', parsed.protocol)
28+
self.assertEqual('34', parsed.subnet_id)
29+
self.assertEqual(True, parsed.admin_state)
30+
self.assertEqual(None, parsed.description)
31+
self.assertEqual(None, parsed.provider)
32+
self.assertEqual(None, parsed.tenant_id)
33+
self.then_default_show_options(parsed)
34+
35+
def test_get_parser_all(self):
36+
allargs = "--lb-method SOURCE_IP --protocol HTTPS --subnet-id 123" + \
37+
" --admin-state-down --description foo --provider ride" + \
38+
" pool2 --project sneed "
39+
allargs += self.given_all_show_options()
40+
parsed = self.given_args(pool.CreatePool, allargs)
41+
self.assertEqual('pool2', parsed.name)
42+
self.assertEqual('SOURCE_IP', parsed.lb_method)
43+
self.assertEqual('HTTPS', parsed.protocol)
44+
self.assertEqual('123', parsed.subnet_id)
45+
self.assertEqual(False, parsed.admin_state)
46+
self.assertEqual('foo', parsed.description)
47+
self.assertEqual('ride', parsed.provider)
48+
self.assertEqual('sneed', parsed.tenant_id)
49+
self.then_all_show_options(parsed)
50+
51+
52+
class TestDeleteLbPool(common.TestNetworkBase):
53+
def test_get_parser_nothing(self):
54+
parsed = self.given_args(pool.DeletePool, "noo")
55+
self.assertEqual('noo', parsed.pool)
56+
57+
58+
class TestListLbPool(common.TestNetworkBase):
59+
def test_get_parser_nothing(self):
60+
given = "" + self.given_default_list_options()
61+
parsed = self.given_args(pool.ListPool, given)
62+
self.assertEqual(False, parsed.show_details)
63+
self.then_default_list_options(parsed)
64+
65+
def test_get_parser_all(self):
66+
allargs = "--long" + self.given_all_list_options()
67+
parsed = self.given_args(pool.ListPool, allargs)
68+
self.assertEqual(True, parsed.show_details)
69+
self.then_all_list_options(parsed)
70+
71+
72+
class TestSetLbPool(common.TestNetworkBase):
73+
def test_get_parser_nothing(self):
74+
parsed = self.given_args(pool.SetPool, "noo")
75+
self.assertEqual('noo', parsed.pool)
76+
77+
78+
class TestShowLbPool(common.TestNetworkBase):
79+
def test_get_parser_nothing(self):
80+
given = "noo" + self.given_default_show_options()
81+
parsed = self.given_args(pool.ShowPool, given)
82+
self.assertEqual('noo', parsed.pool)
83+
self.then_default_show_options(parsed)
84+
85+
def test_get_parser_all(self):
86+
allargs = "too" + self.given_all_show_options()
87+
parsed = self.given_args(pool.ShowPool, allargs)
88+
self.assertEqual('too', parsed.pool)
89+
self.then_all_show_options(parsed)
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# Copyright 2013 OpenStack, LLC.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
#
15+
16+
import httpretty
17+
18+
from openstackclient.network.v2_0.lb import pool
19+
from openstackclient.tests.network.v2_0 import common
20+
21+
22+
class TestPoolIntegration(common.TestIntegrationBase):
23+
HOSTESS = common.TestIntegrationBase.HOST + common.TestIntegrationBase.VER
24+
POOLS_URL = HOSTESS + "/lb/pools.json"
25+
POOLS = '{ "pools": [{ "id": "1111111" }] }'
26+
SUBNETS_URL = HOSTESS + "/subnets.json"
27+
SUBNETS = '{ "subnets": [{ "id": "222222" }] }'
28+
CREATE_URL = HOSTESS + "/lb/pools.json"
29+
CREATE = """
30+
{
31+
"pool":
32+
{
33+
"status": "ACTIVE",
34+
"name": "nameo",
35+
"tenant_id": "33a40233",
36+
"id": "a9254bdb"
37+
}
38+
}"""
39+
DELETE_URL = HOSTESS + "/lb/pools/a9254bdb.json"
40+
DELETE = "{}"
41+
LIST_URL = HOSTESS + "/lb/pools.json"
42+
LIST_ONE = '{ "pools": [{ "id": "a9254bdb" }] }'
43+
LIST = """
44+
{
45+
"pools": [
46+
{
47+
"status": "ACTIVE",
48+
"name": "nameo",
49+
"tenant_id": "33a40233",
50+
"id": "a9254bdb"
51+
},
52+
{
53+
"status": "ACTIVE",
54+
"name": "croc",
55+
"tenant_id": "33a40233",
56+
"id": "b8408dgd"
57+
}
58+
]
59+
}"""
60+
SHOW_URL = HOSTESS + "/lb/pools/a9254bdb.json"
61+
SHOW = CREATE
62+
ADD_REMOVE_URL = HOSTESS + "/floatingips/127.0.0.1.json"
63+
ADD_REMOVE = "{}"
64+
65+
@httpretty.activate
66+
def test_create(self):
67+
pargs = common.FakeParsedArgs()
68+
pargs.name = 'nameo'
69+
pargs.admin_state = True
70+
pargs.description = None
71+
pargs.lb_method = 'LEAST_CONNECTIONS'
72+
pargs.protocol = 'TCP'
73+
pargs.subnet_id = 'subby'
74+
pargs.provider = 'ryder'
75+
pargs.tenant_id = '33a40233'
76+
#httpretty.register_uri(httpretty.GET, self.POOLS_URL,
77+
# body=self.POOLS)
78+
httpretty.register_uri(httpretty.GET, self.SUBNETS_URL,
79+
body=self.SUBNETS)
80+
httpretty.register_uri(httpretty.POST, self.CREATE_URL,
81+
body=self.CREATE)
82+
self.when_run(pool.CreatePool, pargs)
83+
self.assertEqual('', self.stderr())
84+
self.assertEqual(u"""\
85+
Created a new pool:
86+
id="a9254bdb"
87+
name="nameo"
88+
status="ACTIVE"
89+
tenant_id="33a40233"
90+
""", self.stdout())
91+
92+
@httpretty.activate
93+
def test_delete(self):
94+
pargs = common.FakeParsedArgs()
95+
pargs.id = 'nameo'
96+
httpretty.register_uri(httpretty.GET, self.LIST_URL,
97+
body=self.LIST_ONE)
98+
httpretty.register_uri(httpretty.DELETE, self.DELETE_URL,
99+
body=self.DELETE)
100+
self.when_run(pool.DeletePool, pargs)
101+
self.assertEqual('', self.stderr())
102+
self.assertEqual(u'Deleted pool: nameo\n',
103+
self.stdout())
104+
105+
@httpretty.activate
106+
def test_list(self):
107+
pargs = common.FakeParsedArgs()
108+
pargs.page_size = None
109+
pargs.sort_key = []
110+
pargs.sort_dir = []
111+
pargs.formatter = 'csv'
112+
httpretty.register_uri(httpretty.GET, self.LIST_URL,
113+
body=self.LIST)
114+
self.when_run(pool.ListPool, pargs)
115+
self.assertEqual('', self.stderr())
116+
self.assertEqual("""\
117+
id,name,status
118+
a9254bdb,nameo,ACTIVE
119+
b8408dgd,croc,ACTIVE
120+
""", self.stdout())
121+
122+
@httpretty.activate
123+
def test_set(self):
124+
pargs = common.FakeParsedArgs()
125+
pargs.name = 'nameo'
126+
httpretty.register_uri(httpretty.GET, self.LIST_URL,
127+
body=self.LIST_ONE)
128+
self.when_run(pool.SetPool, pargs)
129+
self.assertEqual('', self.stderr())
130+
self.assertEqual('', self.stdout())
131+
132+
@httpretty.activate
133+
def test_show(self):
134+
pargs = common.FakeParsedArgs()
135+
pargs.id = 'nameo'
136+
httpretty.register_uri(httpretty.GET, self.LIST_URL,
137+
body=self.LIST_ONE)
138+
httpretty.register_uri(httpretty.GET, self.SHOW_URL,
139+
body=self.SHOW)
140+
self.when_run(pool.ShowPool, pargs)
141+
self.assertEqual('', self.stderr())
142+
self.assertEqual(u"""\
143+
id="a9254bdb"
144+
name="nameo"
145+
status="ACTIVE"
146+
tenant_id="33a40233"
147+
""", self.stdout())

0 commit comments

Comments
 (0)