Pass API microversion to Client class
Change-Id: If6ac21330cb6c8303f62eec6ee5082f523ff73a1
This commit is contained in:
parent
abea1a8815
commit
df57eb800d
watcherclient
@ -182,4 +182,11 @@ def Client(version, *args, **kwargs):
|
||||
python-watcherclient's doc.
|
||||
"""
|
||||
api_version, client_class = _get_client_class_and_version(version)
|
||||
|
||||
kw_api = kwargs.get('os_infra_optim_api_version')
|
||||
endpoint = kwargs.get('endpoint')
|
||||
# If both os_infra_optim_api_version and endpoint are not provided, get
|
||||
# API version from arg.
|
||||
if not kw_api and not endpoint:
|
||||
kwargs['os_infra_optim_api_version'] = api_version.get_string()
|
||||
return client_class(*args, **kwargs)
|
||||
|
@ -207,5 +207,6 @@ def main(argv=sys.argv[1:]):
|
||||
watcher_app = WatcherShell()
|
||||
return watcher_app.run(argv)
|
||||
|
||||
|
||||
if __name__ == '__main__': # pragma: no cover
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
|
@ -64,10 +64,13 @@ class TestCase(testtools.TestCase):
|
||||
|
||||
delimiter_line = re.compile('^\+\-[\+\-]+\-\+$')
|
||||
|
||||
api_version = 1.0
|
||||
|
||||
@classmethod
|
||||
def watcher(cls, cmd, fail_ok=False):
|
||||
"""Executes watcherclient command for the given action."""
|
||||
return execute('watcher {0}'.format(cmd), fail_ok=fail_ok)
|
||||
return execute('watcher --os-infra-optim-api-version {0} {1}'.format(
|
||||
cls.api_version, cmd), fail_ok=fail_ok)
|
||||
|
||||
@classmethod
|
||||
def get_opts(cls, fields, format='value'):
|
||||
|
@ -13,10 +13,11 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from datetime import datetime
|
||||
from dateutil import tz
|
||||
import functools
|
||||
|
||||
from oslo_utils import uuidutils
|
||||
from tempest.lib.common.utils import test_utils
|
||||
|
||||
from watcherclient.tests.functional.v1 import base
|
||||
@ -79,6 +80,36 @@ class AuditTests(base.TestCase):
|
||||
assert int(audit_output['Interval']) == 2
|
||||
|
||||
|
||||
class AuditTestsV11(AuditTests):
|
||||
"""This class tests v1.1 of Watcher API"""
|
||||
|
||||
api_version = 1.1
|
||||
|
||||
detailed_list_fields = AuditTests.list_fields + [
|
||||
'Created At', 'Updated At', 'Deleted At', 'Parameters', 'Interval',
|
||||
'Audit Scope', 'Next Run Time', 'Hostname', 'Start Time', 'End Time']
|
||||
|
||||
def test_audit_detailed_list(self):
|
||||
raw_output = self.watcher('audit list --detail')
|
||||
self.assert_table_structure([raw_output], self.detailed_list_fields)
|
||||
|
||||
def test_audit_show(self):
|
||||
audit = self.watcher('audit show ' + self.audit_uuid)
|
||||
self.assertIn(self.audit_uuid, audit)
|
||||
self.assert_table_structure([audit], self.detailed_list_fields)
|
||||
|
||||
def test_audit_update(self):
|
||||
local_time = datetime.now(tz.tzlocal())
|
||||
local_time_str = local_time.strftime("%Y-%m-%dT%H:%M:%S")
|
||||
utc_time = (local_time - local_time.utcoffset())
|
||||
utc_time_str = utc_time.strftime("%Y-%m-%dT%H:%M:%S")
|
||||
audit_raw_output = self.watcher(
|
||||
'audit update {0} replace end_time="{1}"'.format(self.audit_uuid,
|
||||
local_time_str))
|
||||
audit_output = self.parse_show_as_object(audit_raw_output)
|
||||
assert audit_output['End Time'] == utc_time_str
|
||||
|
||||
|
||||
class AuditActiveTests(base.TestCase):
|
||||
|
||||
list_fields = ['UUID', 'Name', 'Audit Type', 'State', 'Goal', 'Strategy']
|
||||
|
Loading…
x
Reference in New Issue
Block a user