Add new options to HealthMonitor CLI

This patch adds 2 options into HealthMonitor CLI.
They are '--http-version' and '--domain-name'.

'--http-version' can be 1.0 or 1.1
'--domain-name' is a valid domain name string.

And the '--domain-name' option will be just avaliable when http version
is 1.1, otherwise the server side will raise ClientError.

Story: 2002160
Depends-On: https://review.openstack.org/#/c/626183/
Change-Id: If834d009599c20fd503f87c9f175275f6aa0c09b
This commit is contained in:
ZhaoBo 2018-12-19 20:01:51 +08:00 committed by Michael Johnson
parent 985835a909
commit a2dfe7c0ea
5 changed files with 49 additions and 6 deletions

View File

@ -212,7 +212,9 @@ MONITOR_ROWS = (
'url_path',
'type',
'id',
'operating_status'
'operating_status',
'http_version',
'domain_name'
)
MONITOR_COLUMNS = (

View File

@ -24,6 +24,7 @@ from octaviaclient.osc.v2 import utils as v2_utils
HTTP_METHODS = ['GET', 'POST', 'DELETE', 'PUT', 'HEAD', 'OPTIONS', 'PATCH',
'CONNECT', 'TRACE']
HTTP_VERSIONS = [1.0, 1.1]
TYPE_CHOICES = ['PING', 'HTTP', 'TCP', 'HTTPS', 'TLS-HELLO',
'UDP-CONNECT']
@ -50,6 +51,12 @@ class CreateHealthMonitor(command.ShowOne):
required=True,
help="Set the time in seconds, between sending probes to members."
)
parser.add_argument(
'--domain-name',
metavar='<domain_name>',
help=("Set the domain name, which be injected into the HTTP Host "
"Header to the backend server for HTTP health check.")
)
parser.add_argument(
'--expected-codes',
metavar='<codes>',
@ -64,6 +71,13 @@ class CreateHealthMonitor(command.ShowOne):
help="Set the HTTP method that the health monitor uses for "
"requests."
)
parser.add_argument(
'--http-version',
metavar='<http_version>',
choices=HTTP_VERSIONS,
type=float,
help="Set the HTTP version."
)
parser.add_argument(
'--timeout',
metavar='<timeout>',
@ -231,6 +245,12 @@ class SetHealthMonitor(command.Command):
metavar='<delay>',
help="Set the time in seconds, between sending probes to members."
)
parser.add_argument(
'--domain-name',
metavar='<domain_name>',
help=("Set the domain name, which be injected into the HTTP Host "
"Header to the backend server for HTTP health check.")
)
parser.add_argument(
'--expected-codes',
metavar='<codes>',
@ -245,6 +265,13 @@ class SetHealthMonitor(command.Command):
help="Set the HTTP method that the health monitor uses for "
"requests."
)
parser.add_argument(
'--http-version',
metavar='<http_version>',
choices=HTTP_VERSIONS,
type=float,
help="Set the HTTP version."
)
parser.add_argument(
'--timeout',
metavar='<timeout>',

View File

@ -410,7 +410,9 @@ def get_health_monitor_attrs(client_manager, parsed_args):
'max_retries_down': ('max_retries_down', int),
'url_path': ('url_path', str),
'enable': ('admin_state_up', lambda x: True),
'disable': ('admin_state_up', lambda x: False)
'disable': ('admin_state_up', lambda x: False),
'http_version': ('http_version', float),
'domain_name': ('domain_name', str)
}
_attrs = vars(parsed_args)

View File

@ -52,6 +52,8 @@ HM_ATTRS = {
"url_path": "/some/custom/path",
"type": "HTTP",
"id": uuidutils.generate_uuid(dashed=True),
"http_version": 1.1,
"domain_name": "testlab.com"
}
LISTENER_ATTRS = {

View File

@ -109,7 +109,9 @@ class TestHealthMonitorCreate(TestHealthMonitor):
'--timeout', str(self._hm.timeout),
'--max-retries', str(self._hm.max_retries),
'--type', self._hm.type.lower(),
'--http-method', self._hm.http_method.lower()]
'--http-method', self._hm.http_method.lower(),
'--http-version', str(self._hm.http_version),
'--domain-name', self._hm.domain_name]
verifylist = [
('pool', 'mock_pool_id'),
('name', self._hm.name),
@ -118,6 +120,8 @@ class TestHealthMonitorCreate(TestHealthMonitor):
('max_retries', self._hm.max_retries),
('type', self._hm.type),
('http_method', self._hm.http_method),
('http_version', self._hm.http_version),
('domain_name', self._hm.domain_name)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -157,13 +161,19 @@ class TestHealthMonitorSet(TestHealthMonitor):
self.cmd = health_monitor.SetHealthMonitor(self.app, None)
def test_health_monitor_set(self):
arglist = [self._hm.id, '--name', 'new_name']
arglist = [self._hm.id, '--name', 'new_name',
'--http-version', str(self._hm.http_version),
'--domain-name', self._hm.domain_name]
verifylist = [
('health_monitor', self._hm.id),
('name', 'new_name')
('name', 'new_name'),
('http_version', self._hm.http_version),
('domain_name', self._hm.domain_name)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self.api_mock.health_monitor_set.assert_called_with(
self._hm.id, json={'healthmonitor': {'name': 'new_name'}})
self._hm.id, json={'healthmonitor': {
'name': 'new_name', 'http_version': self._hm.http_version,
'domain_name': self._hm.domain_name}})