Skip to content

Commit

Permalink
Adds loadbalancer amphora configure to OSC
Browse files Browse the repository at this point in the history
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
  • Loading branch information
johnsom authored and cgoncalves committed Feb 24, 2019
1 parent 4bf8454 commit bd339e1
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions octaviaclient/api/constants.py
Expand Up @@ -44,6 +44,7 @@

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"
Expand Down
14 changes: 14 additions & 0 deletions octaviaclient/api/v2/octavia.py
Expand Up @@ -713,6 +713,20 @@ def amphora_list(self, **kwargs):

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
Expand Down
22 changes: 22 additions & 0 deletions octaviaclient/osc/v2/amphora.py
Expand Up @@ -117,6 +117,28 @@ def take_action(self, parsed_args):
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"""

Expand Down
21 changes: 21 additions & 0 deletions octaviaclient/tests/unit/api/test_octavia.py
Expand Up @@ -909,6 +909,27 @@ def test_show_amphora(self):
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',
Expand Down
15 changes: 15 additions & 0 deletions octaviaclient/tests/unit/osc/v2/test_amphora.py
Expand Up @@ -116,6 +116,21 @@ def test_amphora_show(self, mock_client):
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()
Expand Down
@@ -0,0 +1,5 @@
---
features:
- |
Adds the ability to refresh the configuration of an amphora agent with the
``loadbalancer amphora configure`` command.
1 change: 1 addition & 0 deletions setup.cfg
Expand Up @@ -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
Expand Down

0 comments on commit bd339e1

Please sign in to comment.