Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 5 additions & 21 deletions magnum/tests/unit/api/controllers/v1/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,8 @@ def test_replace_ok_by_name(self, mock_utcnow):
self.assertEqual(self.cluster_obj.cluster_template_id,
response['cluster_template_id'])

@mock.patch('oslo_utils.timeutils.utcnow')
def test_replace_ok_by_name_not_found(self, mock_utcnow):
def test_replace_ok_by_name_not_found(self):
name = 'not_found'
test_time = datetime.datetime(2000, 1, 1, 0, 0)
mock_utcnow.return_value = test_time

response = self.patch_json('/clusters/%s' % name,
[{'path': '/name', 'value': name,
Expand All @@ -399,11 +396,8 @@ def test_replace_ok_by_name_not_found(self, mock_utcnow):
self.assertEqual('application/json', response.content_type)
self.assertEqual(404, response.status_code)

@mock.patch('oslo_utils.timeutils.utcnow')
def test_replace_ok_by_uuid_not_found(self, mock_utcnow):
def test_replace_ok_by_uuid_not_found(self):
uuid = uuidutils.generate_uuid()
test_time = datetime.datetime(2000, 1, 1, 0, 0)
mock_utcnow.return_value = test_time

response = self.patch_json('/clusters/%s' % uuid,
[{'path': '/cluster_id', 'value': uuid,
Expand All @@ -425,11 +419,7 @@ def test_replace_cluster_template_id_failed(self):
self.assertEqual(400, response.status_code)
self.assertTrue(response.json['errors'])

@mock.patch('oslo_utils.timeutils.utcnow')
def test_replace_ok_by_name_multiple_cluster(self, mock_utcnow):
test_time = datetime.datetime(2000, 1, 1, 0, 0)
mock_utcnow.return_value = test_time

def test_replace_ok_by_name_multiple_cluster(self):
obj_utils.create_test_cluster(self.context, name='test_cluster',
uuid=uuidutils.generate_uuid())
obj_utils.create_test_cluster(self.context, name='test_cluster',
Expand Down Expand Up @@ -626,25 +616,19 @@ def _simulate_cluster_create(self, cluster, master_count, node_count,
cluster.create()
return cluster

@mock.patch('oslo_utils.timeutils.utcnow')
def test_create_cluster(self, mock_utcnow):
def test_create_cluster(self):
bdict = apiutils.cluster_post_data()
test_time = datetime.datetime(2000, 1, 1, 0, 0)
mock_utcnow.return_value = test_time

response = self.post_json('/clusters', bdict)
self.assertEqual('application/json', response.content_type)
self.assertEqual(202, response.status_int)
self.assertTrue(uuidutils.is_uuid_like(response.json['uuid']))

@mock.patch('oslo_utils.timeutils.utcnow')
def test_create_cluster_resource_limit_reached(self, mock_utcnow):
def test_create_cluster_resource_limit_reached(self):
# override max_cluster_per_project to 1
CONF.set_override('max_clusters_per_project', 1, group='quotas')

bdict = apiutils.cluster_post_data()
test_time = datetime.datetime(2000, 1, 1, 0, 0)
mock_utcnow.return_value = test_time

# create first cluster
response = self.post_json('/clusters', bdict)
Expand Down
6 changes: 1 addition & 5 deletions magnum/tests/unit/api/controllers/v1/test_federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.

import datetime
from unittest import mock

from oslo_config import cfg
Expand Down Expand Up @@ -285,13 +284,10 @@ def _simulate_federation_create(self, federation, create_timeout):
federation.create()
return federation

@mock.patch('oslo_utils.timeutils.utcnow')
def test_create_federation(self, mock_utcnow):
def test_create_federation(self):
bdict = apiutils.federation_post_data(
uuid=uuidutils.generate_uuid(),
hostcluster_id=self.hostcluster.uuid)
test_time = datetime.datetime(2000, 1, 1, 0, 0)
mock_utcnow.return_value = test_time

response = self.post_json('/federations', bdict)
self.assertEqual('application/json', response.content_type)
Expand Down
62 changes: 12 additions & 50 deletions magnum/tests/unit/api/controllers/v1/test_nodegroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,106 +293,79 @@ def _simulate_nodegroup_create(self, cluster, nodegroup):
nodegroup.create()
return nodegroup

@mock.patch('oslo_utils.timeutils.utcnow')
def test_create_nodegroup(self, mock_utcnow):
def test_create_nodegroup(self):
ng_dict = apiutils.nodegroup_post_data()
test_time = datetime.datetime(2000, 1, 1, 0, 0)
mock_utcnow.return_value = test_time

response = self.post_json(self.url, ng_dict)
self.assertEqual('application/json', response.content_type)
self.assertEqual(202, response.status_int)
self.assertTrue(uuidutils.is_uuid_like(response.json['uuid']))
self.assertFalse(response.json['is_default'])

@mock.patch('oslo_utils.timeutils.utcnow')
def test_create_nodegroup_without_node_count(self, mock_utcnow):
def test_create_nodegroup_without_node_count(self):
ng_dict = apiutils.nodegroup_post_data()
del ng_dict['node_count']
test_time = datetime.datetime(2000, 1, 1, 0, 0)
mock_utcnow.return_value = test_time

response = self.post_json(self.url, ng_dict)
self.assertEqual('application/json', response.content_type)
self.assertEqual(202, response.status_int)
# Verify node_count defaults to 1
self.assertEqual(1, response.json['node_count'])

@mock.patch('oslo_utils.timeutils.utcnow')
def test_create_nodegroup_with_zero_nodes(self, mock_utcnow):
def test_create_nodegroup_with_zero_nodes(self):
ng_dict = apiutils.nodegroup_post_data()
ng_dict['node_count'] = 0
ng_dict['min_node_count'] = 0
test_time = datetime.datetime(2000, 1, 1, 0, 0)
mock_utcnow.return_value = test_time

response = self.post_json(self.url, ng_dict)
self.assertEqual('application/json', response.content_type)
self.assertEqual(202, response.status_int)
# Verify node_count is set to zero
self.assertEqual(0, response.json['node_count'])

@mock.patch('oslo_utils.timeutils.utcnow')
def test_create_nodegroup_with_max_node_count(self, mock_utcnow):
def test_create_nodegroup_with_max_node_count(self):
ng_dict = apiutils.nodegroup_post_data(max_node_count=5)
test_time = datetime.datetime(2000, 1, 1, 0, 0)
mock_utcnow.return_value = test_time

response = self.post_json(self.url, ng_dict)
self.assertEqual('application/json', response.content_type)
self.assertEqual(202, response.status_int)
self.assertEqual(5, response.json['max_node_count'])

@mock.patch('oslo_utils.timeutils.utcnow')
def test_create_nodegroup_with_role(self, mock_utcnow):
def test_create_nodegroup_with_role(self):
ng_dict = apiutils.nodegroup_post_data(role='test-role')
test_time = datetime.datetime(2000, 1, 1, 0, 0)
mock_utcnow.return_value = test_time

response = self.post_json(self.url, ng_dict)
self.assertEqual('application/json', response.content_type)
self.assertEqual(202, response.status_int)
self.assertEqual('test-role', response.json['role'])

@mock.patch('oslo_utils.timeutils.utcnow')
def test_create_nodegroup_with_labels(self, mock_utcnow):
def test_create_nodegroup_with_labels(self):
labels = {'label1': 'value1'}
ng_dict = apiutils.nodegroup_post_data(labels=labels)
test_time = datetime.datetime(2000, 1, 1, 0, 0)
mock_utcnow.return_value = test_time

response = self.post_json(self.url, ng_dict)
self.assertEqual('application/json', response.content_type)
self.assertEqual(202, response.status_int)
self.assertEqual(labels, response.json['labels'])

@mock.patch('oslo_utils.timeutils.utcnow')
def test_create_nodegroup_with_image_id(self, mock_utcnow):
def test_create_nodegroup_with_image_id(self):
ng_dict = apiutils.nodegroup_post_data(image_id='test_image')
test_time = datetime.datetime(2000, 1, 1, 0, 0)
mock_utcnow.return_value = test_time

response = self.post_json(self.url, ng_dict)
self.assertEqual('application/json', response.content_type)
self.assertEqual(202, response.status_int)
self.assertEqual('test_image', response.json['image_id'])

@mock.patch('oslo_utils.timeutils.utcnow')
def test_create_nodegroup_with_flavor(self, mock_utcnow):
def test_create_nodegroup_with_flavor(self):
ng_dict = apiutils.nodegroup_post_data(flavor_id='test_flavor')
test_time = datetime.datetime(2000, 1, 1, 0, 0)
mock_utcnow.return_value = test_time

response = self.post_json(self.url, ng_dict)
self.assertEqual('application/json', response.content_type)
self.assertEqual(202, response.status_int)
self.assertEqual('test_flavor', response.json['flavor_id'])

@mock.patch('oslo_utils.timeutils.utcnow')
def test_create_nodegroup_only_name(self, mock_utcnow):
def test_create_nodegroup_only_name(self):
ng_dict = {'name': 'test_ng'}
test_time = datetime.datetime(2000, 1, 1, 0, 0)
mock_utcnow.return_value = test_time

response = self.post_json(self.url, ng_dict)
self.assertEqual('application/json', response.content_type)
Expand All @@ -409,11 +382,8 @@ def test_create_nodegroup_only_name(self, mock_utcnow):
self.assertEqual(1, response.json['node_count'])
self.assertIsNone(response.json['max_node_count'])

@mock.patch('oslo_utils.timeutils.utcnow')
def test_create_nodegroup_invalid_node_count(self, mock_utcnow):
def test_create_nodegroup_invalid_node_count(self):
ng_dict = apiutils.nodegroup_post_data(node_count=7, max_node_count=5)
test_time = datetime.datetime(2000, 1, 1, 0, 0)
mock_utcnow.return_value = test_time

response = self.post_json(self.url, ng_dict, expect_errors=True)
self.assertEqual('application/json', response.content_type)
Expand Down Expand Up @@ -710,23 +680,15 @@ def test_remove_min_node_count(self, mock_utcnow):
response['updated_at']).replace(tzinfo=None)
self.assertEqual(test_time, return_updated_at)

@mock.patch('oslo_utils.timeutils.utcnow')
def test_remove_internal_attr(self, mock_utcnow):
test_time = datetime.datetime(2000, 1, 1, 0, 0)
mock_utcnow.return_value = test_time

def test_remove_internal_attr(self):
response = self.patch_json(self.url + self.nodegroup.name,
[{'path': '/node_count',
'op': 'remove'}], expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertIsNotNone(response.json['errors'])

@mock.patch('oslo_utils.timeutils.utcnow')
def test_remove_non_existent_property(self, mock_utcnow):
test_time = datetime.datetime(2000, 1, 1, 0, 0)
mock_utcnow.return_value = test_time

def test_remove_non_existent_property(self):
response = self.patch_json(self.url + self.nodegroup.name,
[{'path': '/not_there',
'op': 'remove'}], expect_errors=True)
Expand Down
2 changes: 1 addition & 1 deletion releasenotes/source/2024.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
===========================

.. release-notes::
:branch: stable/2024.1
:branch: unmaintained/2024.1