Support updating datastore version

Change-Id: Ie6f22493d1722f41db5aa1a601a652e7eefa29c4
This commit is contained in:
Lingxian Kong 2020-10-09 00:40:52 +13:00
parent bf20c93428
commit 28d7981eac
5 changed files with 125 additions and 18 deletions

View File

@ -0,0 +1,3 @@
---
features:
- Support updating datastore version.

View File

@ -105,6 +105,7 @@ openstack.database.v1 =
datastore_version_list = troveclient.osc.v1.datastores:ListDatastoreVersions datastore_version_list = troveclient.osc.v1.datastores:ListDatastoreVersions
datastore_version_show = troveclient.osc.v1.datastores:ShowDatastoreVersion datastore_version_show = troveclient.osc.v1.datastores:ShowDatastoreVersion
datastore_version_delete = troveclient.osc.v1.datastores:DeleteDatastoreVersion datastore_version_delete = troveclient.osc.v1.datastores:DeleteDatastoreVersion
datastore_version_set = troveclient.osc.v1.datastores:UpdateDatastoreVersion
database_backup_strategy_list = troveclient.osc.v1.database_backup_strategy:ListDatabaseBackupStrategies database_backup_strategy_list = troveclient.osc.v1.database_backup_strategy:ListDatabaseBackupStrategies
database_backup_strategy_create = troveclient.osc.v1.database_backup_strategy:CreateDatabaseBackupStrategy database_backup_strategy_create = troveclient.osc.v1.database_backup_strategy:CreateDatabaseBackupStrategy
database_backup_strategy_delete = troveclient.osc.v1.database_backup_strategy:DeleteDatabaseBackupStrategy database_backup_strategy_delete = troveclient.osc.v1.database_backup_strategy:DeleteDatabaseBackupStrategy

View File

@ -191,12 +191,17 @@ class CreateDatastoreVersion(command.Command):
) )
parser.add_argument( parser.add_argument(
'image_id', 'image_id',
help=_('ID of the datastore image in Glance.'), help=_('ID of the datastore image in Glance. This can be empty '
'string if --image-tags is specified.'),
) )
parser.add_argument( parser.add_argument(
'--active', '--active',
action='store_true', action='store_true',
help=_('Enable the datastore version or not.'), help=_('Enable the datastore version.'),
)
parser.add_argument(
'--image-tags',
help=_('List of image tags separated by comma, e.g. trove,mysql'),
) )
parser.add_argument( parser.add_argument(
'--default', '--default',
@ -207,12 +212,18 @@ class CreateDatastoreVersion(command.Command):
def take_action(self, parsed_args): def take_action(self, parsed_args):
client = self.app.client_manager.database.mgmt_ds_versions client = self.app.client_manager.database.mgmt_ds_versions
image_tags = []
if parsed_args.image_tags:
image_tags = parsed_args.image_tags.split(',')
try: try:
client.create( client.create(
parsed_args.version_name, parsed_args.version_name,
parsed_args.datastore_name, parsed_args.datastore_name,
parsed_args.datastore_manager, parsed_args.datastore_manager,
parsed_args.image_id, parsed_args.image_id,
image_tags=image_tags,
active='true' if parsed_args.active else 'false', active='true' if parsed_args.active else 'false',
default='true' if parsed_args.default else 'false' default='true' if parsed_args.default else 'false'
) )
@ -220,3 +231,71 @@ class CreateDatastoreVersion(command.Command):
msg = (_("Failed to create datastore version %(version)s: %(e)s") msg = (_("Failed to create datastore version %(version)s: %(e)s")
% {'version': parsed_args.version_name, 'e': e}) % {'version': parsed_args.version_name, 'e': e})
raise exceptions.CommandError(msg) raise exceptions.CommandError(msg)
class UpdateDatastoreVersion(command.Command):
_description = _("Updates a datastore version.")
def get_parser(self, prog_name):
parser = super(UpdateDatastoreVersion, self).get_parser(prog_name)
parser.add_argument(
'datastore_version_id',
help=_('Datastore version ID.'),
)
parser.add_argument(
'--datastore-manager',
default=None,
help=_("Datastore manager name."),
)
parser.add_argument(
'--image',
default=None,
help=_('ID of the datastore image in Glance.'),
)
parser.add_argument(
'--image-tags',
default=None,
help=_('List of image tags separated by comma, e.g. trove,mysql'),
)
enable_group = parser.add_mutually_exclusive_group()
enable_group.add_argument('--enable', dest='enable',
default=None,
action='store_const',
const='true')
enable_group.add_argument('--disable', dest='enable',
default=None,
action='store_const',
const='false')
default_group = parser.add_mutually_exclusive_group()
default_group.add_argument('--default', dest='default',
default=None,
action='store_const',
const='true')
default_group.add_argument('--non-default', dest='default',
default=None,
action='store_const',
const='false')
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.database.mgmt_ds_versions
image_tags = None
if parsed_args.image_tags is not None:
image_tags = parsed_args.image_tags.split(',')
try:
client.edit(
parsed_args.datastore_version_id,
datastore_manager=parsed_args.datastore_manager,
image=parsed_args.image,
image_tags=image_tags,
active=parsed_args.enable, default=parsed_args.default
)
except Exception as e:
msg = (_("Failed to update datastore version %(version)s: %(e)s")
% {'version': parsed_args.datastore_version_id, 'e': e})
raise exceptions.CommandError(msg)

View File

@ -166,11 +166,29 @@ class TestCreateDatastoreVersion(TestDatastores):
def test_create_datastore_version(self): def test_create_datastore_version(self):
image_id = uuidutils.generate_uuid() image_id = uuidutils.generate_uuid()
args = ['new_name', 'ds_name', 'ds_manager', image_id, '--active', args = ['new_name', 'ds_name', 'ds_manager', image_id, '--active',
'--default'] '--default', '--image-tags', 'trove,mysql']
parsed_args = self.check_parser(self.cmd, args, []) parsed_args = self.check_parser(self.cmd, args, [])
self.cmd.take_action(parsed_args) self.cmd.take_action(parsed_args)
self.dsversion_mgmt_client.create.assert_called_once_with( self.dsversion_mgmt_client.create.assert_called_once_with(
'new_name', 'ds_name', 'ds_manager', image_id, active='true', 'new_name', 'ds_name', 'ds_manager', image_id, active='true',
default='true') default='true', image_tags=['trove', 'mysql'])
class TestUpdateDatastoreVersion(TestDatastores):
def setUp(self):
super(TestUpdateDatastoreVersion, self).setUp()
self.cmd = datastores.UpdateDatastoreVersion(self.app, None)
def test_update_datastore_version(self):
version_id = uuidutils.generate_uuid()
args = [version_id, '--image-tags', 'trove,mysql', '--enable',
'--non-default']
parsed_args = self.check_parser(self.cmd, args, [])
self.cmd.take_action(parsed_args)
self.dsversion_mgmt_client.edit.assert_called_once_with(
version_id, datastore_manager=None, image=None,
active='true', default='false', image_tags=['trove', 'mysql'])

View File

@ -229,29 +229,32 @@ class MgmtDatastoreVersions(base.ManagerWithFind):
"version") "version")
def create(self, name, datastore_name, datastore_manager, image, def create(self, name, datastore_name, datastore_manager, image,
packages=None, active='true', default='false'): packages=None, active='true', default='false', image_tags=[]):
packages = packages or []
"""Create a new datastore version.""" """Create a new datastore version."""
body = {"version": { packages = packages or []
"name": name, body = {
"datastore_name": datastore_name, "version": {
"datastore_manager": datastore_manager, "name": name,
"image": image, "datastore_name": datastore_name,
"packages": packages, "datastore_manager": datastore_manager,
"active": json.loads(active), "image": image,
"default": json.loads(default) "image_tags": image_tags,
}} "packages": packages,
"active": json.loads(active),
"default": json.loads(default)
}
}
return self._create("/mgmt/datastore-versions", body, None, True) return self._create("/mgmt/datastore-versions", body, None, True)
def edit(self, datastore_version_id, datastore_manager=None, image=None, def edit(self, datastore_version_id, datastore_manager=None, image=None,
packages=None, active=None, default=None): packages=None, active=None, default=None, image_tags=None):
packages = packages or []
"""Update a datastore-version.""" """Update a datastore-version."""
packages = packages or []
body = {} body = {}
if datastore_manager is not None: if datastore_manager is not None:
body['datastore_manager'] = datastore_manager body['datastore_manager'] = datastore_manager
if image: if image is not None:
body['image'] = image body['image'] = image
if packages: if packages:
body['packages'] = packages body['packages'] = packages
@ -259,6 +262,9 @@ class MgmtDatastoreVersions(base.ManagerWithFind):
body['active'] = json.loads(active) body['active'] = json.loads(active)
if default is not None: if default is not None:
body['default'] = json.loads(default) body['default'] = json.loads(default)
if image_tags is not None:
body['image_tags'] = image_tags
url = ("/mgmt/datastore-versions/%s" % datastore_version_id) url = ("/mgmt/datastore-versions/%s" % datastore_version_id)
resp, body = self.api.client.patch(url, body=body) resp, body = self.api.client.patch(url, body=body)
common.check_for_exceptions(resp, body, url) common.check_for_exceptions(resp, body, url)