RESTify cluster template tests
Change-Id: Id8d00657f714e9dee7f42fe1fc6b9e151964e1ae
This commit is contained in:
parent
f32591ab21
commit
360a87fe16
@ -11,7 +11,6 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
|
||||||
import mock
|
|
||||||
import munch
|
import munch
|
||||||
|
|
||||||
import shade
|
import shade
|
||||||
@ -72,86 +71,126 @@ class TestClusterTemplates(base.RequestsMockTestCase):
|
|||||||
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],
|
||||||
self.cloud._normalize_cluster_template(
|
self.cloud._normalize_cluster_template(cluster_template_obj))
|
||||||
cluster_template_obj))
|
|
||||||
self.assert_calls()
|
self.assert_calls()
|
||||||
|
|
||||||
@mock.patch.object(shade.OpenStackCloud, 'magnum_client')
|
def test_search_cluster_templates_by_name(self):
|
||||||
def test_search_cluster_templates_by_name(self, mock_magnum):
|
self.register_uris([dict(
|
||||||
mock_magnum.baymodels.list.return_value = [
|
method='GET',
|
||||||
cluster_template_obj]
|
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')
|
||||||
mock_magnum.baymodels.list.assert_called_with(detail=True)
|
|
||||||
|
|
||||||
self.assertEqual(1, len(cluster_templates))
|
self.assertEqual(1, len(cluster_templates))
|
||||||
self.assertEqual('fake-uuid', cluster_templates[0]['uuid'])
|
self.assertEqual('fake-uuid', cluster_templates[0]['uuid'])
|
||||||
|
self.assert_calls()
|
||||||
|
|
||||||
@mock.patch.object(shade.OpenStackCloud, 'magnum_client')
|
def test_search_cluster_templates_not_found(self):
|
||||||
def test_search_cluster_templates_not_found(self, mock_magnum):
|
|
||||||
mock_magnum.baymodels.list.return_value = [
|
self.register_uris([dict(
|
||||||
cluster_template_obj]
|
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')
|
||||||
|
|
||||||
mock_magnum.baymodels.list.assert_called_with(detail=True)
|
|
||||||
self.assertEqual(0, len(cluster_templates))
|
self.assertEqual(0, len(cluster_templates))
|
||||||
|
self.assert_calls()
|
||||||
|
|
||||||
|
def test_get_cluster_template(self):
|
||||||
|
self.register_uris([dict(
|
||||||
|
method='GET',
|
||||||
|
uri='https://container-infra.example.com/v1/baymodels/detail',
|
||||||
|
json=dict(baymodels=[cluster_template_obj.toDict()]))])
|
||||||
|
|
||||||
@mock.patch.object(shade.OpenStackCloud, 'search_cluster_templates')
|
|
||||||
def test_get_cluster_template(self, mock_search):
|
|
||||||
mock_search.return_value = [cluster_template_obj, ]
|
|
||||||
r = self.cloud.get_cluster_template('fake-cluster-template')
|
r = self.cloud.get_cluster_template('fake-cluster-template')
|
||||||
self.assertIsNotNone(r)
|
self.assertIsNotNone(r)
|
||||||
self.assertDictEqual(cluster_template_obj, r)
|
self.assertDictEqual(
|
||||||
|
r, self.cloud._normalize_cluster_template(cluster_template_obj))
|
||||||
|
self.assert_calls()
|
||||||
|
|
||||||
@mock.patch.object(shade.OpenStackCloud, 'search_cluster_templates')
|
def test_get_cluster_template_not_found(self):
|
||||||
def test_get_cluster_template_not_found(self, mock_search):
|
self.register_uris([dict(
|
||||||
mock_search.return_value = []
|
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()
|
||||||
|
|
||||||
@mock.patch.object(shade.OpenStackCloud, 'magnum_client')
|
def test_create_cluster_template(self):
|
||||||
def test_create_cluster_template(self, mock_magnum):
|
self.register_uris([dict(
|
||||||
|
method='POST',
|
||||||
|
uri='https://container-infra.example.com/v1/baymodels',
|
||||||
|
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,
|
||||||
keypair_id=cluster_template_obj.keypair_id,
|
keypair_id=cluster_template_obj.keypair_id,
|
||||||
coe=cluster_template_obj.coe)
|
coe=cluster_template_obj.coe)
|
||||||
mock_magnum.baymodels.create.assert_called_once_with(
|
self.assert_calls()
|
||||||
name=cluster_template_obj.name,
|
|
||||||
image_id=cluster_template_obj.image_id,
|
|
||||||
keypair_id=cluster_template_obj.keypair_id,
|
|
||||||
coe=cluster_template_obj.coe
|
|
||||||
)
|
|
||||||
|
|
||||||
@mock.patch.object(shade.OpenStackCloud, 'magnum_client')
|
def test_create_cluster_template_exception(self):
|
||||||
def test_create_cluster_template_exception(self, mock_magnum):
|
self.register_uris([dict(
|
||||||
mock_magnum.baymodels.create.side_effect = Exception()
|
method='POST',
|
||||||
|
uri='https://container-infra.example.com/v1/baymodels',
|
||||||
|
status_code=403)])
|
||||||
with testtools.ExpectedException(
|
with testtools.ExpectedException(
|
||||||
shade.OpenStackCloudException,
|
shade.OpenStackCloudException,
|
||||||
"Error creating cluster template of name fake-cluster-template"
|
"Error creating cluster template of name fake-cluster-template"
|
||||||
):
|
):
|
||||||
self.cloud.create_cluster_template('fake-cluster-template')
|
self.cloud.create_cluster_template('fake-cluster-template')
|
||||||
|
self.assert_calls()
|
||||||
|
|
||||||
@mock.patch.object(shade.OpenStackCloud, 'magnum_client')
|
def test_delete_cluster_template(self):
|
||||||
def test_delete_cluster_template(self, mock_magnum):
|
uri = 'https://container-infra.example.com/v1/baymodels/fake-uuid'
|
||||||
mock_magnum.baymodels.list.return_value = [
|
self.register_uris([
|
||||||
cluster_template_obj]
|
dict(
|
||||||
|
method='GET',
|
||||||
|
uri='https://container-infra.example.com/v1/baymodels/detail',
|
||||||
|
json=dict(baymodels=[cluster_template_obj.toDict()])),
|
||||||
|
dict(
|
||||||
|
method='DELETE',
|
||||||
|
uri=uri),
|
||||||
|
])
|
||||||
self.cloud.delete_cluster_template('fake-uuid')
|
self.cloud.delete_cluster_template('fake-uuid')
|
||||||
mock_magnum.baymodels.delete.assert_called_once_with(
|
self.assert_calls()
|
||||||
'fake-uuid'
|
|
||||||
)
|
|
||||||
|
|
||||||
@mock.patch.object(shade.OpenStackCloud, 'magnum_client')
|
def test_update_cluster_template(self):
|
||||||
def test_update_cluster_template(self, mock_magnum):
|
uri = 'https://container-infra.example.com/v1/baymodels/fake-uuid'
|
||||||
|
self.register_uris([
|
||||||
|
dict(
|
||||||
|
method='GET',
|
||||||
|
uri='https://container-infra.example.com/v1/baymodels/detail',
|
||||||
|
json=dict(baymodels=[cluster_template_obj.toDict()])),
|
||||||
|
dict(
|
||||||
|
method='PATCH',
|
||||||
|
uri=uri,
|
||||||
|
status_code=200,
|
||||||
|
validate=dict(
|
||||||
|
json=[{
|
||||||
|
u'op': u'replace',
|
||||||
|
u'path': u'/name',
|
||||||
|
u'value': u'new-cluster-template'
|
||||||
|
}]
|
||||||
|
)),
|
||||||
|
dict(
|
||||||
|
method='GET',
|
||||||
|
uri='https://container-infra.example.com/v1/baymodels/detail',
|
||||||
|
# This json value is not meaningful to the test - it just has
|
||||||
|
# to be valid.
|
||||||
|
json=dict(baymodels=[cluster_template_obj.toDict()])),
|
||||||
|
])
|
||||||
new_name = 'new-cluster-template'
|
new_name = 'new-cluster-template'
|
||||||
mock_magnum.baymodels.list.return_value = [
|
|
||||||
cluster_template_obj]
|
|
||||||
self.cloud.update_cluster_template(
|
self.cloud.update_cluster_template(
|
||||||
'fake-uuid', 'replace', name=new_name)
|
'fake-uuid', 'replace', name=new_name)
|
||||||
mock_magnum.baymodels.update.assert_called_once_with(
|
self.assert_calls()
|
||||||
'fake-uuid', [{'path': '/name', 'op': 'replace',
|
|
||||||
'value': 'new-cluster-template'}]
|
|
||||||
)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user