Merge "Improve Magnum cluster templates functions"
This commit is contained in:
commit
7f88a79624
|
@ -8777,11 +8777,21 @@ class OpenStackCloud(
|
||||||
the OpenStack API call.
|
the OpenStack API call.
|
||||||
"""
|
"""
|
||||||
with _utils.shade_exceptions("Error fetching cluster template list"):
|
with _utils.shade_exceptions("Error fetching cluster template list"):
|
||||||
data = self._container_infra_client.get(
|
try:
|
||||||
'/baymodels/detail')
|
data = self._container_infra_client.get('/clustertemplates')
|
||||||
return self._normalize_cluster_templates(
|
# NOTE(flwang): Magnum adds /clustertemplates and /cluster
|
||||||
self._get_and_munchify('baymodels', data))
|
# to deprecate /baymodels and /bay since Newton release. So
|
||||||
|
# we're using a small tag to indicate if current
|
||||||
|
# cloud has those two new API endpoints.
|
||||||
|
self._container_infra_client._has_magnum_after_newton = True
|
||||||
|
return self._normalize_cluster_templates(
|
||||||
|
self._get_and_munchify('clustertemplates', data))
|
||||||
|
except exc.OpenStackCloudURINotFound:
|
||||||
|
data = self._container_infra_client.get('/baymodels/detail')
|
||||||
|
return self._normalize_cluster_templates(
|
||||||
|
self._get_and_munchify('baymodels', data))
|
||||||
list_baymodels = list_cluster_templates
|
list_baymodels = list_cluster_templates
|
||||||
|
list_coe_cluster_templates = list_cluster_templates
|
||||||
|
|
||||||
def search_cluster_templates(
|
def search_cluster_templates(
|
||||||
self, name_or_id=None, filters=None, detail=False):
|
self, name_or_id=None, filters=None, detail=False):
|
||||||
|
@ -8801,6 +8811,7 @@ class OpenStackCloud(
|
||||||
return _utils._filter_list(
|
return _utils._filter_list(
|
||||||
cluster_templates, name_or_id, filters)
|
cluster_templates, name_or_id, filters)
|
||||||
search_baymodels = search_cluster_templates
|
search_baymodels = search_cluster_templates
|
||||||
|
search_coe_cluster_templates = search_cluster_templates
|
||||||
|
|
||||||
def get_cluster_template(self, name_or_id, filters=None, detail=False):
|
def get_cluster_template(self, name_or_id, filters=None, detail=False):
|
||||||
"""Get a cluster template by name or ID.
|
"""Get a cluster template by name or ID.
|
||||||
|
@ -8827,6 +8838,7 @@ class OpenStackCloud(
|
||||||
return _utils._get_entity(self, 'cluster_template', name_or_id,
|
return _utils._get_entity(self, 'cluster_template', name_or_id,
|
||||||
filters=filters, detail=detail)
|
filters=filters, detail=detail)
|
||||||
get_baymodel = get_cluster_template
|
get_baymodel = get_cluster_template
|
||||||
|
get_coe_cluster_template = get_cluster_template
|
||||||
|
|
||||||
def create_cluster_template(
|
def create_cluster_template(
|
||||||
self, name, image_id=None, keypair_id=None, coe=None, **kwargs):
|
self, name, image_id=None, keypair_id=None, coe=None, **kwargs):
|
||||||
|
@ -8854,12 +8866,18 @@ class OpenStackCloud(
|
||||||
body['keypair_id'] = keypair_id
|
body['keypair_id'] = keypair_id
|
||||||
body['coe'] = coe
|
body['coe'] = coe
|
||||||
|
|
||||||
cluster_template = self._container_infra_client.post(
|
try:
|
||||||
'/baymodels', json=body)
|
cluster_template = self._container_infra_client.post(
|
||||||
|
'/clustertemplates', json=body)
|
||||||
|
self._container_infra_client._has_magnum_after_newton = True
|
||||||
|
except exc.OpenStackCloudURINotFound:
|
||||||
|
cluster_template = self._container_infra_client.post(
|
||||||
|
'/baymodels', json=body)
|
||||||
|
|
||||||
self.list_cluster_templates.invalidate(self)
|
self.list_cluster_templates.invalidate(self)
|
||||||
return cluster_template
|
return cluster_template
|
||||||
create_baymodel = create_cluster_template
|
create_baymodel = create_cluster_template
|
||||||
|
create_coe_cluster_template = create_cluster_template
|
||||||
|
|
||||||
def delete_cluster_template(self, name_or_id):
|
def delete_cluster_template(self, name_or_id):
|
||||||
"""Delete a cluster template.
|
"""Delete a cluster template.
|
||||||
|
@ -8881,12 +8899,18 @@ class OpenStackCloud(
|
||||||
return False
|
return False
|
||||||
|
|
||||||
with _utils.shade_exceptions("Error in deleting cluster template"):
|
with _utils.shade_exceptions("Error in deleting cluster template"):
|
||||||
self._container_infra_client.delete(
|
if getattr(self._container_infra_client,
|
||||||
'/baymodels/{id}'.format(id=cluster_template['id']))
|
'_has_magnum_after_newton', False):
|
||||||
|
self._container_infra_client.delete(
|
||||||
|
'/clustertemplates/{id}'.format(id=cluster_template['id']))
|
||||||
|
else:
|
||||||
|
self._container_infra_client.delete(
|
||||||
|
'/baymodels/{id}'.format(id=cluster_template['id']))
|
||||||
self.list_cluster_templates.invalidate(self)
|
self.list_cluster_templates.invalidate(self)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
delete_baymodel = delete_cluster_template
|
delete_baymodel = delete_cluster_template
|
||||||
|
delete_coe_cluster_template = delete_cluster_template
|
||||||
|
|
||||||
@_utils.valid_kwargs('name', 'image_id', 'flavor_id', 'master_flavor_id',
|
@_utils.valid_kwargs('name', 'image_id', 'flavor_id', 'master_flavor_id',
|
||||||
'keypair_id', 'external_network_id', 'fixed_network',
|
'keypair_id', 'external_network_id', 'fixed_network',
|
||||||
|
@ -8923,13 +8947,20 @@ class OpenStackCloud(
|
||||||
|
|
||||||
with _utils.shade_exceptions(
|
with _utils.shade_exceptions(
|
||||||
"Error updating cluster template {0}".format(name_or_id)):
|
"Error updating cluster template {0}".format(name_or_id)):
|
||||||
self._container_infra_client.patch(
|
if getattr(self._container_infra_client,
|
||||||
'/baymodels/{id}'.format(id=cluster_template['id']),
|
'_has_magnum_after_newton', False):
|
||||||
json=patches)
|
self._container_infra_client.patch(
|
||||||
|
'/clustertemplates/{id}'.format(id=cluster_template['id']),
|
||||||
|
json=patches)
|
||||||
|
else:
|
||||||
|
self._container_infra_client.patch(
|
||||||
|
'/baymodels/{id}'.format(id=cluster_template['id']),
|
||||||
|
json=patches)
|
||||||
|
|
||||||
new_cluster_template = self.get_cluster_template(name_or_id)
|
new_cluster_template = self.get_cluster_template(name_or_id)
|
||||||
return new_cluster_template
|
return new_cluster_template
|
||||||
update_baymodel = update_cluster_template
|
update_baymodel = update_cluster_template
|
||||||
|
update_coe_cluster_template = update_cluster_template
|
||||||
|
|
||||||
def list_nics(self):
|
def list_nics(self):
|
||||||
msg = "Error fetching machine port list"
|
msg = "Error fetching machine port list"
|
||||||
|
|
|
@ -53,10 +53,15 @@ class TestClusterTemplates(base.RequestsMockTestCase):
|
||||||
|
|
||||||
def test_list_cluster_templates_without_detail(self):
|
def test_list_cluster_templates_without_detail(self):
|
||||||
|
|
||||||
self.register_uris([dict(
|
self.register_uris([
|
||||||
method='GET',
|
dict(
|
||||||
uri='https://container-infra.example.com/v1/baymodels/detail',
|
method='GET',
|
||||||
json=dict(baymodels=[cluster_template_obj.toDict()]))])
|
uri='https://container-infra.example.com/v1/clustertemplates',
|
||||||
|
status_code=404),
|
||||||
|
dict(
|
||||||
|
method='GET',
|
||||||
|
uri='https://container-infra.example.com/v1/baymodels/detail',
|
||||||
|
json=dict(baymodels=[cluster_template_obj.toDict()]))])
|
||||||
cluster_templates_list = self.cloud.list_cluster_templates()
|
cluster_templates_list = self.cloud.list_cluster_templates()
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
cluster_templates_list[0],
|
cluster_templates_list[0],
|
||||||
|
@ -64,10 +69,15 @@ class TestClusterTemplates(base.RequestsMockTestCase):
|
||||||
self.assert_calls()
|
self.assert_calls()
|
||||||
|
|
||||||
def test_list_cluster_templates_with_detail(self):
|
def test_list_cluster_templates_with_detail(self):
|
||||||
self.register_uris([dict(
|
self.register_uris([
|
||||||
method='GET',
|
dict(
|
||||||
uri='https://container-infra.example.com/v1/baymodels/detail',
|
method='GET',
|
||||||
json=dict(baymodels=[cluster_template_obj.toDict()]))])
|
uri='https://container-infra.example.com/v1/clustertemplates',
|
||||||
|
status_code=404),
|
||||||
|
dict(
|
||||||
|
method='GET',
|
||||||
|
uri='https://container-infra.example.com/v1/baymodels/detail',
|
||||||
|
json=dict(baymodels=[cluster_template_obj.toDict()]))])
|
||||||
cluster_templates_list = self.cloud.list_cluster_templates(detail=True)
|
cluster_templates_list = self.cloud.list_cluster_templates(detail=True)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
cluster_templates_list[0],
|
cluster_templates_list[0],
|
||||||
|
@ -75,10 +85,15 @@ class TestClusterTemplates(base.RequestsMockTestCase):
|
||||||
self.assert_calls()
|
self.assert_calls()
|
||||||
|
|
||||||
def test_search_cluster_templates_by_name(self):
|
def test_search_cluster_templates_by_name(self):
|
||||||
self.register_uris([dict(
|
self.register_uris([
|
||||||
method='GET',
|
dict(
|
||||||
uri='https://container-infra.example.com/v1/baymodels/detail',
|
method='GET',
|
||||||
json=dict(baymodels=[cluster_template_obj.toDict()]))])
|
uri='https://container-infra.example.com/v1/clustertemplates',
|
||||||
|
status_code=404),
|
||||||
|
dict(
|
||||||
|
method='GET',
|
||||||
|
uri='https://container-infra.example.com/v1/baymodels/detail',
|
||||||
|
json=dict(baymodels=[cluster_template_obj.toDict()]))])
|
||||||
|
|
||||||
cluster_templates = self.cloud.search_cluster_templates(
|
cluster_templates = self.cloud.search_cluster_templates(
|
||||||
name_or_id='fake-cluster-template')
|
name_or_id='fake-cluster-template')
|
||||||
|
@ -89,10 +104,15 @@ class TestClusterTemplates(base.RequestsMockTestCase):
|
||||||
|
|
||||||
def test_search_cluster_templates_not_found(self):
|
def test_search_cluster_templates_not_found(self):
|
||||||
|
|
||||||
self.register_uris([dict(
|
self.register_uris([
|
||||||
method='GET',
|
dict(
|
||||||
uri='https://container-infra.example.com/v1/baymodels/detail',
|
method='GET',
|
||||||
json=dict(baymodels=[cluster_template_obj.toDict()]))])
|
uri='https://container-infra.example.com/v1/clustertemplates',
|
||||||
|
status_code=404),
|
||||||
|
dict(
|
||||||
|
method='GET',
|
||||||
|
uri='https://container-infra.example.com/v1/baymodels/detail',
|
||||||
|
json=dict(baymodels=[cluster_template_obj.toDict()]))])
|
||||||
|
|
||||||
cluster_templates = self.cloud.search_cluster_templates(
|
cluster_templates = self.cloud.search_cluster_templates(
|
||||||
name_or_id='non-existent')
|
name_or_id='non-existent')
|
||||||
|
@ -101,10 +121,15 @@ class TestClusterTemplates(base.RequestsMockTestCase):
|
||||||
self.assert_calls()
|
self.assert_calls()
|
||||||
|
|
||||||
def test_get_cluster_template(self):
|
def test_get_cluster_template(self):
|
||||||
self.register_uris([dict(
|
self.register_uris([
|
||||||
method='GET',
|
dict(
|
||||||
uri='https://container-infra.example.com/v1/baymodels/detail',
|
method='GET',
|
||||||
json=dict(baymodels=[cluster_template_obj.toDict()]))])
|
uri='https://container-infra.example.com/v1/clustertemplates',
|
||||||
|
status_code=404),
|
||||||
|
dict(
|
||||||
|
method='GET',
|
||||||
|
uri='https://container-infra.example.com/v1/baymodels/detail',
|
||||||
|
json=dict(baymodels=[cluster_template_obj.toDict()]))])
|
||||||
|
|
||||||
r = self.cloud.get_cluster_template('fake-cluster-template')
|
r = self.cloud.get_cluster_template('fake-cluster-template')
|
||||||
self.assertIsNotNone(r)
|
self.assertIsNotNone(r)
|
||||||
|
@ -113,25 +138,34 @@ class TestClusterTemplates(base.RequestsMockTestCase):
|
||||||
self.assert_calls()
|
self.assert_calls()
|
||||||
|
|
||||||
def test_get_cluster_template_not_found(self):
|
def test_get_cluster_template_not_found(self):
|
||||||
self.register_uris([dict(
|
self.register_uris([
|
||||||
method='GET',
|
dict(
|
||||||
uri='https://container-infra.example.com/v1/baymodels/detail',
|
method='GET',
|
||||||
json=dict(baymodels=[]))])
|
uri='https://container-infra.example.com/v1/clustertemplates',
|
||||||
|
status_code=404),
|
||||||
|
dict(
|
||||||
|
method='GET',
|
||||||
|
uri='https://container-infra.example.com/v1/baymodels/detail',
|
||||||
|
json=dict(baymodels=[]))])
|
||||||
r = self.cloud.get_cluster_template('doesNotExist')
|
r = self.cloud.get_cluster_template('doesNotExist')
|
||||||
self.assertIsNone(r)
|
self.assertIsNone(r)
|
||||||
self.assert_calls()
|
self.assert_calls()
|
||||||
|
|
||||||
def test_create_cluster_template(self):
|
def test_create_cluster_template(self):
|
||||||
self.register_uris([dict(
|
self.register_uris([
|
||||||
method='POST',
|
dict(
|
||||||
uri='https://container-infra.example.com/v1/baymodels',
|
method='POST',
|
||||||
json=dict(baymodels=[cluster_template_obj.toDict()]),
|
uri='https://container-infra.example.com/v1/clustertemplates',
|
||||||
validate=dict(json={
|
status_code=404),
|
||||||
'coe': 'fake-coe',
|
dict(
|
||||||
'image_id': 'fake-image',
|
method='POST',
|
||||||
'keypair_id': 'fake-key',
|
uri='https://container-infra.example.com/v1/baymodels',
|
||||||
'name': 'fake-cluster-template'}),
|
json=dict(baymodels=[cluster_template_obj.toDict()]),
|
||||||
)])
|
validate=dict(json={
|
||||||
|
'coe': 'fake-coe',
|
||||||
|
'image_id': 'fake-image',
|
||||||
|
'keypair_id': 'fake-key',
|
||||||
|
'name': 'fake-cluster-template'}),)])
|
||||||
self.cloud.create_cluster_template(
|
self.cloud.create_cluster_template(
|
||||||
name=cluster_template_obj.name,
|
name=cluster_template_obj.name,
|
||||||
image_id=cluster_template_obj.image_id,
|
image_id=cluster_template_obj.image_id,
|
||||||
|
@ -140,10 +174,15 @@ class TestClusterTemplates(base.RequestsMockTestCase):
|
||||||
self.assert_calls()
|
self.assert_calls()
|
||||||
|
|
||||||
def test_create_cluster_template_exception(self):
|
def test_create_cluster_template_exception(self):
|
||||||
self.register_uris([dict(
|
self.register_uris([
|
||||||
method='POST',
|
dict(
|
||||||
uri='https://container-infra.example.com/v1/baymodels',
|
method='POST',
|
||||||
status_code=403)])
|
uri='https://container-infra.example.com/v1/clustertemplates',
|
||||||
|
status_code=404),
|
||||||
|
dict(
|
||||||
|
method='POST',
|
||||||
|
uri='https://container-infra.example.com/v1/baymodels',
|
||||||
|
status_code=403)])
|
||||||
# TODO(mordred) requests here doens't give us a great story
|
# TODO(mordred) requests here doens't give us a great story
|
||||||
# for matching the old error message text. Investigate plumbing
|
# for matching the old error message text. Investigate plumbing
|
||||||
# an error message in to the adapter call so that we can give a
|
# an error message in to the adapter call so that we can give a
|
||||||
|
@ -158,6 +197,10 @@ class TestClusterTemplates(base.RequestsMockTestCase):
|
||||||
def test_delete_cluster_template(self):
|
def test_delete_cluster_template(self):
|
||||||
uri = 'https://container-infra.example.com/v1/baymodels/fake-uuid'
|
uri = 'https://container-infra.example.com/v1/baymodels/fake-uuid'
|
||||||
self.register_uris([
|
self.register_uris([
|
||||||
|
dict(
|
||||||
|
method='GET',
|
||||||
|
uri='https://container-infra.example.com/v1/clustertemplates',
|
||||||
|
status_code=404),
|
||||||
dict(
|
dict(
|
||||||
method='GET',
|
method='GET',
|
||||||
uri='https://container-infra.example.com/v1/baymodels/detail',
|
uri='https://container-infra.example.com/v1/baymodels/detail',
|
||||||
|
@ -172,6 +215,10 @@ class TestClusterTemplates(base.RequestsMockTestCase):
|
||||||
def test_update_cluster_template(self):
|
def test_update_cluster_template(self):
|
||||||
uri = 'https://container-infra.example.com/v1/baymodels/fake-uuid'
|
uri = 'https://container-infra.example.com/v1/baymodels/fake-uuid'
|
||||||
self.register_uris([
|
self.register_uris([
|
||||||
|
dict(
|
||||||
|
method='GET',
|
||||||
|
uri='https://container-infra.example.com/v1/clustertemplates',
|
||||||
|
status_code=404),
|
||||||
dict(
|
dict(
|
||||||
method='GET',
|
method='GET',
|
||||||
uri='https://container-infra.example.com/v1/baymodels/detail',
|
uri='https://container-infra.example.com/v1/baymodels/detail',
|
||||||
|
@ -189,7 +236,7 @@ class TestClusterTemplates(base.RequestsMockTestCase):
|
||||||
)),
|
)),
|
||||||
dict(
|
dict(
|
||||||
method='GET',
|
method='GET',
|
||||||
uri='https://container-infra.example.com/v1/baymodels/detail',
|
uri='https://container-infra.example.com/v1/clustertemplates',
|
||||||
# This json value is not meaningful to the test - it just has
|
# This json value is not meaningful to the test - it just has
|
||||||
# to be valid.
|
# to be valid.
|
||||||
json=dict(baymodels=[cluster_template_obj.toDict()])),
|
json=dict(baymodels=[cluster_template_obj.toDict()])),
|
||||||
|
@ -198,3 +245,16 @@ class TestClusterTemplates(base.RequestsMockTestCase):
|
||||||
self.cloud.update_cluster_template(
|
self.cloud.update_cluster_template(
|
||||||
'fake-uuid', 'replace', name=new_name)
|
'fake-uuid', 'replace', name=new_name)
|
||||||
self.assert_calls()
|
self.assert_calls()
|
||||||
|
|
||||||
|
def test_get_coe_cluster_template(self):
|
||||||
|
self.register_uris([
|
||||||
|
dict(
|
||||||
|
method='GET',
|
||||||
|
uri='https://container-infra.example.com/v1/clustertemplates',
|
||||||
|
json=dict(clustertemplates=[cluster_template_obj.toDict()]))])
|
||||||
|
|
||||||
|
r = self.cloud.get_coe_cluster_template('fake-cluster-template')
|
||||||
|
self.assertIsNotNone(r)
|
||||||
|
self.assertDictEqual(
|
||||||
|
r, self.cloud._normalize_cluster_template(cluster_template_obj))
|
||||||
|
self.assert_calls()
|
||||||
|
|
Loading…
Reference in New Issue