From bd339e1b0274d1398cdf54c707af59012cc5b605 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Mon, 28 Jan 2019 15:58:02 -0800 Subject: [PATCH] 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 --- octaviaclient/api/constants.py | 1 + octaviaclient/api/v2/octavia.py | 14 ++++++++++++ octaviaclient/osc/v2/amphora.py | 22 +++++++++++++++++++ octaviaclient/tests/unit/api/test_octavia.py | 21 ++++++++++++++++++ .../tests/unit/osc/v2/test_amphora.py | 15 +++++++++++++ ...ra-configure-command-cda75053a72c0cdf.yaml | 5 +++++ setup.cfg | 1 + 7 files changed, 79 insertions(+) create mode 100644 releasenotes/notes/add-amphora-configure-command-cda75053a72c0cdf.yaml diff --git a/octaviaclient/api/constants.py b/octaviaclient/api/constants.py index 025fb02..ab39171 100644 --- a/octaviaclient/api/constants.py +++ b/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" diff --git a/octaviaclient/api/v2/octavia.py b/octaviaclient/api/v2/octavia.py index fd2ba17..a1980ce 100644 --- a/octaviaclient/api/v2/octavia.py +++ b/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 diff --git a/octaviaclient/osc/v2/amphora.py b/octaviaclient/osc/v2/amphora.py index d6d41aa..20162a9 100644 --- a/octaviaclient/osc/v2/amphora.py +++ b/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='', + 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""" diff --git a/octaviaclient/tests/unit/api/test_octavia.py b/octaviaclient/tests/unit/api/test_octavia.py index 39ac4ea..71ae8e0 100644 --- a/octaviaclient/tests/unit/api/test_octavia.py +++ b/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', diff --git a/octaviaclient/tests/unit/osc/v2/test_amphora.py b/octaviaclient/tests/unit/osc/v2/test_amphora.py index f4eb577..05e2a8d 100644 --- a/octaviaclient/tests/unit/osc/v2/test_amphora.py +++ b/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() diff --git a/releasenotes/notes/add-amphora-configure-command-cda75053a72c0cdf.yaml b/releasenotes/notes/add-amphora-configure-command-cda75053a72c0cdf.yaml new file mode 100644 index 0000000..eb2a461 --- /dev/null +++ b/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. diff --git a/setup.cfg b/setup.cfg index 40b7016..e5396e3 100644 --- a/setup.cfg +++ b/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