Adds loadbalancer amphora configure to OSC

This patch adds the "loadbalancer amphora configure" command to the
OpenStack Client for Octavia. It allows the user to refresh the
configuration of a running amphora agent.

Change-Id: Idf842c6193db0199f575920a853ec9ed996f8556
Story: 1685225
Task: 29155
This commit is contained in:
Michael Johnson 2019-01-28 15:58:02 -08:00 committed by Carlos Goncalves
parent 4bf8454acf
commit bd339e1b02
7 changed files with 79 additions and 0 deletions

View File

@ -44,6 +44,7 @@ BASE_QUOTA_DEFAULT_URL = BASE_QUOTA_URL + '/defaults'
BASE_AMPHORA_URL = BASE_OCTAVIA_ENDPOINT + "/amphorae" BASE_AMPHORA_URL = BASE_OCTAVIA_ENDPOINT + "/amphorae"
BASE_SINGLE_AMPHORA_URL = BASE_AMPHORA_URL + "/{uuid}" BASE_SINGLE_AMPHORA_URL = BASE_AMPHORA_URL + "/{uuid}"
BASE_AMPHORA_CONFIGURE_URL = BASE_SINGLE_AMPHORA_URL + '/config'
BASE_AMPHORA_FAILOVER_URL = BASE_SINGLE_AMPHORA_URL + '/failover' BASE_AMPHORA_FAILOVER_URL = BASE_SINGLE_AMPHORA_URL + '/failover'
BASE_PROVIDER_URL = BASE_LBAAS_ENDPOINT + "/providers" BASE_PROVIDER_URL = BASE_LBAAS_ENDPOINT + "/providers"

View File

@ -713,6 +713,20 @@ class OctaviaAPI(api.BaseAPI):
return response return response
@correct_return_codes
def amphora_configure(self, amphora_id):
"""Update the amphora agent configuration
:param string amphora_id:
ID of the amphora to configure
:return:
Response Code from the API
"""
url = const.BASE_AMPHORA_CONFIGURE_URL.format(uuid=amphora_id)
response = self.create(url, method='PUT')
return response
@correct_return_codes @correct_return_codes
def amphora_failover(self, amphora_id): def amphora_failover(self, amphora_id):
"""Force failover an amphorae """Force failover an amphorae

View File

@ -117,6 +117,28 @@ class ShowAmphora(command.ShowOne):
formatters=formatters)) formatters=formatters))
class ConfigureAmphora(command.Command):
"""Update the amphora agent configuration"""
def get_parser(self, prog_name):
parser = super(ConfigureAmphora, self).get_parser(prog_name)
parser.add_argument(
'amphora_id',
metavar='<amphora-id>',
help='UUID of the amphora to configure.',
)
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_configure(
amphora_id=attrs.pop('amphora_id'))
class FailoverAmphora(command.Command): class FailoverAmphora(command.Command):
"""Force failover an amphora""" """Force failover an amphora"""

View File

@ -909,6 +909,27 @@ class TestLoadBalancer(TestOctaviaClient):
ret = self.api.amphora_show(FAKE_AMP) ret = self.api.amphora_show(FAKE_AMP)
self.assertEqual(SINGLB_AMP_RESP['amphora'], ret) self.assertEqual(SINGLB_AMP_RESP['amphora'], ret)
def test_configure_amphora(self):
self.requests_mock.register_uri(
'PUT',
FAKE_OCTAVIA_URL + 'amphorae/' + FAKE_AMP + '/config',
status_code=202,
)
ret = self.api.amphora_configure(FAKE_AMP)
self.assertEqual(202, ret.status_code)
def test_configure_amphora_error(self):
self.requests_mock.register_uri(
'PUT',
FAKE_OCTAVIA_URL + 'amphorae/' + FAKE_AMP + '/config',
text='{"faultstring": "%s"}' % self._error_message,
status_code=409,
)
self.assertRaisesRegex(octavia.OctaviaClientException,
self._error_message,
self.api.amphora_configure,
FAKE_AMP)
def test_failover_amphora(self): def test_failover_amphora(self):
self.requests_mock.register_uri( self.requests_mock.register_uri(
'PUT', 'PUT',

View File

@ -116,6 +116,21 @@ class TestAmphoraShow(TestAmphora):
self.api_mock.amphora_show.assert_called_with(amphora_id=self._amp.id) self.api_mock.amphora_show.assert_called_with(amphora_id=self._amp.id)
class TestAmphoraConfigure(TestAmphora):
def setUp(self):
super(TestAmphoraConfigure, self).setUp()
self.cmd = amphora.ConfigureAmphora(self.app, None)
def test_amphora_configure(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_configure.assert_called_with(
amphora_id=self._amp.id)
class TestAmphoraFailover(TestAmphora): class TestAmphoraFailover(TestAmphora):
def setUp(self): def setUp(self):
super(TestAmphoraFailover, self).setUp() super(TestAmphoraFailover, self).setUp()

View File

@ -0,0 +1,5 @@
---
features:
- |
Adds the ability to refresh the configuration of an amphora agent with the
``loadbalancer amphora configure`` command.

View File

@ -74,6 +74,7 @@ openstack.load_balancer.v2 =
loadbalancer_quota_set = octaviaclient.osc.v2.quota:SetQuota loadbalancer_quota_set = octaviaclient.osc.v2.quota:SetQuota
loadbalancer_amphora_list = octaviaclient.osc.v2.amphora:ListAmphora loadbalancer_amphora_list = octaviaclient.osc.v2.amphora:ListAmphora
loadbalancer_amphora_show = octaviaclient.osc.v2.amphora:ShowAmphora loadbalancer_amphora_show = octaviaclient.osc.v2.amphora:ShowAmphora
loadbalancer_amphora_configure = octaviaclient.osc.v2.amphora:ConfigureAmphora
loadbalancer_amphora_failover = octaviaclient.osc.v2.amphora:FailoverAmphora loadbalancer_amphora_failover = octaviaclient.osc.v2.amphora:FailoverAmphora
loadbalancer_provider_list = octaviaclient.osc.v2.provider:ListProvider loadbalancer_provider_list = octaviaclient.osc.v2.provider:ListProvider
loadbalancer_provider_capability_list = octaviaclient.osc.v2.provider:ListProviderFlavorCapability loadbalancer_provider_capability_list = octaviaclient.osc.v2.provider:ListProviderFlavorCapability