Browse Source

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
changes/26/633626/2
Michael Johnson 3 years ago
committed by Carlos Goncalves
parent
commit
bd339e1b02
  1. 1
      octaviaclient/api/constants.py
  2. 14
      octaviaclient/api/v2/octavia.py
  3. 22
      octaviaclient/osc/v2/amphora.py
  4. 21
      octaviaclient/tests/unit/api/test_octavia.py
  5. 15
      octaviaclient/tests/unit/osc/v2/test_amphora.py
  6. 5
      releasenotes/notes/add-amphora-configure-command-cda75053a72c0cdf.yaml
  7. 1
      setup.cfg

1
octaviaclient/api/constants.py

@ -44,6 +44,7 @@ BASE_QUOTA_DEFAULT_URL = BASE_QUOTA_URL + '/defaults'
BASE_AMPHORA_URL = BASE_OCTAVIA_ENDPOINT + "/amphorae"
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_PROVIDER_URL = BASE_LBAAS_ENDPOINT + "/providers"

14
octaviaclient/api/v2/octavia.py

@ -713,6 +713,20 @@ class OctaviaAPI(api.BaseAPI):
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
def amphora_failover(self, amphora_id):
"""Force failover an amphorae

22
octaviaclient/osc/v2/amphora.py

@ -117,6 +117,28 @@ class ShowAmphora(command.ShowOne):
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):
"""Force failover an amphora"""

21
octaviaclient/tests/unit/api/test_octavia.py

@ -909,6 +909,27 @@ class TestLoadBalancer(TestOctaviaClient):
ret = self.api.amphora_show(FAKE_AMP)
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):
self.requests_mock.register_uri(
'PUT',

15
octaviaclient/tests/unit/osc/v2/test_amphora.py

@ -116,6 +116,21 @@ class TestAmphoraShow(TestAmphora):
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):
def setUp(self):
super(TestAmphoraFailover, self).setUp()

5
releasenotes/notes/add-amphora-configure-command-cda75053a72c0cdf.yaml

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

1
setup.cfg

@ -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_configure = octaviaclient.osc.v2.amphora:ConfigureAmphora
loadbalancer_amphora_failover = octaviaclient.osc.v2.amphora:FailoverAmphora
loadbalancer_provider_list = octaviaclient.osc.v2.provider:ListProvider
loadbalancer_provider_capability_list = octaviaclient.osc.v2.provider:ListProviderFlavorCapability

Loading…
Cancel
Save