Enable to get flavor_metadata without creating cluster.
1.Add "list_flavors" and "get_flavor" in api. 2.User "get_flavor" to get flavor name. 3.Add unittest for the new api function. 4.remove "ha_proxy" from package_matadata/openstack.conf 5.add flavor_config_validates Change-Id: Ib17b851f5d8ac14b6d2bb13b0f44b575936c9f74
This commit is contained in:
parent
8aad3ef970
commit
5345a81470
@ -1379,12 +1379,11 @@ def convert_flavor_metadata(flavor_id):
|
||||
flavor_id, user=current_user
|
||||
)
|
||||
metadata = metadatas['flavor_config']
|
||||
clusters = cluster_api.list_clusters(
|
||||
flavor = metadata_api.get_flavor(
|
||||
flavor_id,
|
||||
user=current_user
|
||||
)
|
||||
for cluster in clusters:
|
||||
if cluster['flavor']['id'] == flavor_id:
|
||||
flavor_name = cluster['flavor_name'].replace('-', '_')
|
||||
flavor_name = flavor['name'].replace('-', '_')
|
||||
configs = util.load_configs(setting.FLAVOR_MAPPING_DIR)
|
||||
for item in configs:
|
||||
if flavor_name in item.keys():
|
||||
|
@ -467,8 +467,8 @@ def update_cluster_config(cluster_id, user=None, session=None, **kwargs):
|
||||
)
|
||||
|
||||
def package_config_validates(config):
|
||||
metadata_api.validate_package_config(
|
||||
session, config, adapter_id=cluster.adapter_id
|
||||
metadata_api.validate_flavor_config(
|
||||
session, config, flavor_id=cluster.flavor.id
|
||||
)
|
||||
|
||||
@utils.input_validates(
|
||||
@ -511,8 +511,8 @@ def patch_cluster_config(cluster_id, user=None, session=None, **kwargs):
|
||||
)
|
||||
|
||||
def package_config_validates(config):
|
||||
metadata_api.validate_package_config(
|
||||
session, config, adapter_id=cluster.adapter_id
|
||||
metadata_api.validate_flavor_config(
|
||||
session, config, flavor_id=cluster.flavor.id
|
||||
)
|
||||
|
||||
@utils.output_validates(
|
||||
@ -1081,8 +1081,8 @@ def _update_clusterhost_config(session, user, clusterhost, **kwargs):
|
||||
def package_config_validates(package_config):
|
||||
cluster = clusterhost.cluster
|
||||
is_cluster_editable(session, cluster, user)
|
||||
metadata_api.validate_package_config(
|
||||
session, package_config, cluster.adapter_id
|
||||
metadata_api.validate_flavor_config(
|
||||
session, package_config, cluster.flavor.id
|
||||
)
|
||||
|
||||
@utils.supported_filters(
|
||||
@ -1241,8 +1241,8 @@ def _patch_clusterhost_config(session, user, clusterhost, **kwargs):
|
||||
def package_config_validates(package_config):
|
||||
cluster = clusterhost.cluster
|
||||
is_cluster_editable(session, cluster, user)
|
||||
metadata_api.validate_package_config(
|
||||
session, package_config, cluster.adapter_id
|
||||
metadata_api.validate_flavor_config(
|
||||
session, package_config, cluster.flavor.id
|
||||
)
|
||||
|
||||
@utils.supported_filters(
|
||||
@ -1528,8 +1528,8 @@ def review_cluster(cluster_id, review={}, user=None, session=None, **kwargs):
|
||||
cluster=cluster
|
||||
)
|
||||
if package_config:
|
||||
metadata_api.validate_package_config(
|
||||
session, package_config, cluster.adapter_id, True
|
||||
metadata_api.validate_flavor_config(
|
||||
session, package_config, cluster.flavor.id, True
|
||||
)
|
||||
for clusterhost in clusterhosts:
|
||||
clusterhost_package_config = copy.deepcopy(
|
||||
@ -1542,9 +1542,9 @@ def review_cluster(cluster_id, review={}, user=None, session=None, **kwargs):
|
||||
deployed_package_config = util.merge_dict(
|
||||
package_config, clusterhost_package_config
|
||||
)
|
||||
metadata_api.validate_package_config(
|
||||
metadata_api.validate_flavor_config(
|
||||
session, deployed_package_config,
|
||||
cluster.adapter_id, True
|
||||
cluster.flavor.id, True
|
||||
)
|
||||
validate_clusterhost(session, clusterhost)
|
||||
utils.update_db_object(
|
||||
|
@ -21,6 +21,7 @@ from compass.db.api import permission
|
||||
from compass.db.api import user as user_api
|
||||
from compass.db.api import utils
|
||||
from compass.db import exception
|
||||
from compass.db import models
|
||||
from compass.utils import setting_wrapper as setting
|
||||
from compass.utils import util
|
||||
|
||||
@ -28,6 +29,9 @@ from compass.utils import util
|
||||
RESP_METADATA_FIELDS = [
|
||||
'os_config', 'package_config', 'flavor_config'
|
||||
]
|
||||
RESP_FLAVORS_FIELDS = [
|
||||
'id', 'name', 'display_name', 'template', 'roles'
|
||||
]
|
||||
|
||||
|
||||
@database.run_in_session()
|
||||
@ -99,6 +103,17 @@ def validate_package_config(
|
||||
)
|
||||
|
||||
|
||||
def validate_flavor_config(
|
||||
session, config, flavor_id, whole_check=False, **kwargs
|
||||
):
|
||||
if not FLAVOR_METADATA_MAPPING:
|
||||
load_flavor_metadatas_internal(session)
|
||||
_validate_config(
|
||||
config, flavor_id, 'flavor', FLAVOR_METADATA_MAPPING,
|
||||
whole_check, session=session, **kwargs
|
||||
)
|
||||
|
||||
|
||||
def _filter_metadata(metadata, **kwargs):
|
||||
if not isinstance(metadata, dict):
|
||||
return metadata
|
||||
@ -176,6 +191,32 @@ def get_flavor_metadata(flavor_id, user=None, session=None, **kwargs):
|
||||
}
|
||||
|
||||
|
||||
@utils.supported_filters([])
|
||||
@database.run_in_session()
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_LIST_METADATAS
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FLAVORS_FIELDS)
|
||||
def list_flavors(user=None, session=None, **filters):
|
||||
"""List flavors."""
|
||||
return utils.list_db_objects(
|
||||
session, models.AdapterFlavor, **filters
|
||||
)
|
||||
|
||||
|
||||
@utils.supported_filters([])
|
||||
@database.run_in_session()
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_LIST_METADATAS
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FLAVORS_FIELDS)
|
||||
def get_flavor(flavor_id, user=None, session=None, **kwargs):
|
||||
"""Get flavor."""
|
||||
return utils.get_db_object(
|
||||
session, models.AdapterFlavor, id=flavor_id
|
||||
)
|
||||
|
||||
|
||||
def get_os_metadata_internal(session, os_id):
|
||||
"""get os metadata internal."""
|
||||
if not OS_METADATA_MAPPING:
|
||||
|
@ -310,6 +310,55 @@ class TestGetPackageOsMetadata(MetadataTestCase):
|
||||
)
|
||||
|
||||
|
||||
class TestListFlavors(MetadataTestCase):
|
||||
def setUp(self):
|
||||
super(TestListFlavors, self).setUp()
|
||||
|
||||
def tesrDown(self):
|
||||
super(TestListFlavors, self).tearDown()
|
||||
|
||||
def test_list_flavors(self):
|
||||
"""Test list flavors."""
|
||||
flavors = metadata.list_flavors(
|
||||
user=self.user_object
|
||||
)
|
||||
flavor_name = []
|
||||
for flavor in flavors:
|
||||
flavor_name.append(flavor['name'])
|
||||
expected = [
|
||||
'allinone',
|
||||
'multiroles',
|
||||
'HA-multinodes',
|
||||
'single-contoller-multi-compute'
|
||||
]
|
||||
for expect in expected:
|
||||
self.assertIn(expect, flavor_name)
|
||||
|
||||
|
||||
class TestGetFlavors(MetadataTestCase):
|
||||
def setUp(self):
|
||||
super(TestGetFlavors, self).setUp()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestGetFlavors, self).tearDown()
|
||||
|
||||
def test_get_flavor(self):
|
||||
"""Test get a flavor."""
|
||||
flavor = metadata.get_flavor(
|
||||
self.flavor_id,
|
||||
user=self.user_object
|
||||
)
|
||||
expected = {
|
||||
'display_name': 'Multi-node Cluster with HA',
|
||||
'id': 3,
|
||||
'template': 'ha_multinodes.tmpl',
|
||||
'name': 'HA-multinodes'
|
||||
}
|
||||
self.assertTrue(
|
||||
all(item in flavor.items() for item in expected.items())
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
flags.init()
|
||||
logsetting.init()
|
||||
|
@ -135,15 +135,4 @@ METADATA = {
|
||||
}
|
||||
}
|
||||
},
|
||||
'ha_proxy': {
|
||||
'_self': {
|
||||
},
|
||||
'vip': {
|
||||
'_self': {
|
||||
'is_required': True,
|
||||
'field': 'general',
|
||||
'mapping_to': 'ha_vip'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user