Add failover an amphora client support
Story: 2004659 Task: 28624 Change-Id: Ia37b54dfc5b02db3065ceed5c01791dfa30082c1
This commit is contained in:
parent
8c2dd7efa9
commit
15a47068d0
|
@ -43,4 +43,5 @@ BASE_SINGLE_QUOTA_URL = BASE_QUOTA_URL + '/{uuid}'
|
|||
BASE_QUOTA_DEFAULT_URL = BASE_QUOTA_URL + '/defaults'
|
||||
|
||||
BASE_AMPHORA_URL = BASE_OCTAVIA_ENDPOINT + "/amphorae"
|
||||
BASE_SINGLE_AMPHORA_URL = BASE_AMPHORA_URL + "/{amphora_id}"
|
||||
BASE_SINGLE_AMPHORA_URL = BASE_AMPHORA_URL + "/{uuid}"
|
||||
BASE_AMPHORA_FAILOVER_URL = BASE_SINGLE_AMPHORA_URL + '/failover'
|
||||
|
|
|
@ -713,6 +713,20 @@ class OctaviaAPI(api.BaseAPI):
|
|||
|
||||
return response
|
||||
|
||||
@correct_return_codes
|
||||
def amphora_failover(self, amphora_id):
|
||||
"""Force failover an amphorae
|
||||
|
||||
:param string amphora_id:
|
||||
ID of the amphora to failover
|
||||
:return:
|
||||
Response Code from the API
|
||||
"""
|
||||
url = const.BASE_AMPHORA_FAILOVER_URL.format(uuid=amphora_id)
|
||||
response = self.create(url, method='PUT')
|
||||
|
||||
return response
|
||||
|
||||
|
||||
class OctaviaClientException(Exception):
|
||||
"""The base exception class for all exceptions this library raises."""
|
||||
|
|
|
@ -115,3 +115,25 @@ class ShowAmphora(command.ShowOne):
|
|||
|
||||
return (rows, utils.get_dict_properties(data, rows,
|
||||
formatters=formatters))
|
||||
|
||||
|
||||
class FailoverAmphora(command.Command):
|
||||
"""Force failover an amphora"""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(FailoverAmphora, self).get_parser(prog_name)
|
||||
|
||||
parser.add_argument(
|
||||
'amphora_id',
|
||||
metavar='<amphora-id>',
|
||||
help='UUID of the amphora.',
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
attrs = v2_utils.get_amphora_attrs(self.app.client_manager,
|
||||
parsed_args)
|
||||
|
||||
self.app.client_manager.load_balancer.amphora_failover(
|
||||
amphora_id=attrs.pop('amphora_id'))
|
||||
|
|
|
@ -25,6 +25,7 @@ FAKE_ACCOUNT = 'q12we34r'
|
|||
FAKE_AUTH = '11223344556677889900'
|
||||
FAKE_URL = 'http://example.com/v2.0/'
|
||||
FAKE_LBAAS_URL = FAKE_URL + 'lbaas/'
|
||||
FAKE_OCTAVIA_URL = FAKE_URL + 'octavia/'
|
||||
|
||||
FAKE_LB = uuidutils.generate_uuid()
|
||||
FAKE_LI = uuidutils.generate_uuid()
|
||||
|
@ -34,6 +35,7 @@ FAKE_L7PO = uuidutils.generate_uuid()
|
|||
FAKE_L7RU = uuidutils.generate_uuid()
|
||||
FAKE_HM = uuidutils.generate_uuid()
|
||||
FAKE_PRJ = uuidutils.generate_uuid()
|
||||
FAKE_AMP = uuidutils.generate_uuid()
|
||||
|
||||
|
||||
LIST_LB_RESP = {
|
||||
|
@ -87,6 +89,12 @@ LIST_QT_RESP = {
|
|||
{'project': uuidutils.generate_uuid()}]
|
||||
}
|
||||
|
||||
LIST_AMP_RESP = {
|
||||
'amphorae':
|
||||
[{'id': uuidutils.generate_uuid()},
|
||||
{'id': uuidutils.generate_uuid()}]
|
||||
}
|
||||
|
||||
SINGLE_LB_RESP = {'loadbalancer': {'id': FAKE_LB, 'name': 'lb1'}}
|
||||
SINGLE_LB_UPDATE = {"loadbalancer": {"admin_state_up": False}}
|
||||
SINGLE_LB_STATS_RESP = {'bytes_in': '0'}
|
||||
|
@ -113,6 +121,7 @@ SINGLE_HM_UPDATE = {'healthmonitor': {'admin_state_up': False}}
|
|||
|
||||
SINGLE_QT_RESP = {'quota': {'pool': -1}}
|
||||
SINGLE_QT_UPDATE = {'quota': {'pool': -1}}
|
||||
SINGLB_AMP_RESP = {'amphora': {'id': FAKE_AMP}}
|
||||
|
||||
|
||||
class TestOctaviaClient(utils.TestCase):
|
||||
|
@ -849,3 +858,44 @@ class TestLoadBalancer(TestOctaviaClient):
|
|||
self._error_message,
|
||||
self.api.quota_reset,
|
||||
FAKE_PRJ)
|
||||
|
||||
def test_list_amphora_no_options(self):
|
||||
self.requests_mock.register_uri(
|
||||
'GET',
|
||||
FAKE_OCTAVIA_URL + 'amphorae?/' + FAKE_LB,
|
||||
json=LIST_AMP_RESP,
|
||||
status_code=200,
|
||||
)
|
||||
ret = self.api.amphora_list()
|
||||
self.assertEqual(LIST_AMP_RESP, ret)
|
||||
|
||||
def test_show_amphora(self):
|
||||
self.requests_mock.register_uri(
|
||||
'GET',
|
||||
FAKE_OCTAVIA_URL + 'amphorae/' + FAKE_AMP,
|
||||
json=SINGLB_AMP_RESP,
|
||||
status_code=200
|
||||
)
|
||||
ret = self.api.amphora_show(FAKE_AMP)
|
||||
self.assertEqual(SINGLB_AMP_RESP['amphora'], ret)
|
||||
|
||||
def test_failover_amphora(self):
|
||||
self.requests_mock.register_uri(
|
||||
'PUT',
|
||||
FAKE_OCTAVIA_URL + 'amphorae/' + FAKE_AMP + '/failover',
|
||||
status_code=202,
|
||||
)
|
||||
ret = self.api.amphora_failover(FAKE_AMP)
|
||||
self.assertEqual(202, ret.status_code)
|
||||
|
||||
def test_failover_amphora_error(self):
|
||||
self.requests_mock.register_uri(
|
||||
'PUT',
|
||||
FAKE_OCTAVIA_URL + 'amphorae/' + FAKE_AMP + '/failover',
|
||||
text='{"faultstring": "%s"}' % self._error_message,
|
||||
status_code=409,
|
||||
)
|
||||
self.assertRaisesRegex(octavia.OctaviaClientException,
|
||||
self._error_message,
|
||||
self.api.amphora_failover,
|
||||
FAKE_AMP)
|
||||
|
|
|
@ -114,3 +114,18 @@ class TestAmphoraShow(TestAmphora):
|
|||
rows, data = self.cmd.take_action(parsed_args)
|
||||
self.assertEqual(self.rows, rows)
|
||||
self.api_mock.amphora_show.assert_called_with(amphora_id=self._amp.id)
|
||||
|
||||
|
||||
class TestAmphoraFailover(TestAmphora):
|
||||
def setUp(self):
|
||||
super(TestAmphoraFailover, self).setUp()
|
||||
self.cmd = amphora.FailoverAmphora(self.app, None)
|
||||
|
||||
def test_amphora_failover(self):
|
||||
arglist = [self._amp.id]
|
||||
verify_list = [('amphora_id', self._amp.id)]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verify_list)
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.api_mock.amphora_failover.assert_called_with(
|
||||
amphora_id=self._amp.id)
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
features:
|
||||
- |
|
||||
Add force failover an amphora command ``loadbalancer amphora failover``.
|
|
@ -74,6 +74,7 @@ openstack.load_balancer.v2 =
|
|||
loadbalancer_quota_set = octaviaclient.osc.v2.quota:SetQuota
|
||||
loadbalancer_amphora_list = octaviaclient.osc.v2.amphora:ListAmphora
|
||||
loadbalancer_amphora_show = octaviaclient.osc.v2.amphora:ShowAmphora
|
||||
loadbalancer_amphora_failover = octaviaclient.osc.v2.amphora:FailoverAmphora
|
||||
|
||||
[build_sphinx]
|
||||
source-dir = doc/source
|
||||
|
|
Loading…
Reference in New Issue