diff --git a/magnum/api/controllers/link.py b/magnum/api/controllers/link.py index 5007b1cb7..6ff22f68f 100644 --- a/magnum/api/controllers/link.py +++ b/magnum/api/controllers/link.py @@ -21,7 +21,7 @@ def build_url(resource, resource_args, bookmark=False, base_url=None): if base_url is None: - base_url = pecan.request.host_url + base_url = pecan.request.application_url template = '%(url)s/%(res)s' if bookmark else '%(url)s/v1/%(res)s' # FIXME(lucasagomes): I'm getting a 404 when doing a GET on diff --git a/magnum/api/controllers/root.py b/magnum/api/controllers/root.py index 64eaf9979..396a8ab07 100644 --- a/magnum/api/controllers/root.py +++ b/magnum/api/controllers/root.py @@ -45,8 +45,9 @@ class Version(base.APIBase): def convert(id, status, max, min): version = Version() version.id = id - version.links = [link.Link.make_link('self', pecan.request.host_url, - id, '', bookmark=True)] + version.links = [ + link.Link.make_link( + 'self', pecan.request.application_url, id, '', bookmark=True)] version.status = status version.max_version = max version.min_version = min diff --git a/magnum/api/controllers/v1/__init__.py b/magnum/api/controllers/v1/__init__.py index 871092f0a..d62604536 100644 --- a/magnum/api/controllers/v1/__init__.py +++ b/magnum/api/controllers/v1/__init__.py @@ -106,72 +106,73 @@ class V1(controllers_base.APIBase): def convert(): v1 = V1() v1.id = "v1" - v1.links = [link.Link.make_link('self', pecan.request.host_url, - 'v1', '', bookmark=True), - link.Link.make_link('describedby', - 'http://docs.openstack.org', - 'developer/magnum/dev', - 'api-spec-v1.html', - bookmark=True, type='text/html')] - v1.media_types = [MediaType('application/json', - 'application/vnd.openstack.magnum.v1+json')] - v1.clustertemplates = [link.Link.make_link('self', - pecan.request.host_url, - 'clustertemplates', ''), - link.Link.make_link('bookmark', - pecan.request.host_url, - 'clustertemplates', '', - bookmark=True)] - v1.clusters = [link.Link.make_link('self', pecan.request.host_url, - 'clusters', ''), - link.Link.make_link('bookmark', - pecan.request.host_url, - 'clusters', '', - bookmark=True)] - v1.quotas = [link.Link.make_link('self', pecan.request.host_url, - 'quotas', ''), - link.Link.make_link('bookmark', - pecan.request.host_url, - 'quotas', '', - bookmark=True)] - v1.certificates = [link.Link.make_link('self', pecan.request.host_url, - 'certificates', ''), - link.Link.make_link('bookmark', - pecan.request.host_url, - 'certificates', '', - bookmark=True)] - v1.mservices = [link.Link.make_link('self', pecan.request.host_url, - 'mservices', ''), - link.Link.make_link('bookmark', - pecan.request.host_url, - 'mservices', '', - bookmark=True)] - v1.stats = [link.Link.make_link('self', pecan.request.host_url, - 'stats', ''), - link.Link.make_link('bookmark', - pecan.request.host_url, - 'stats', '', - bookmark=True)] - v1.federations = [link.Link.make_link('self', pecan.request.host_url, - 'federations', ''), - link.Link.make_link('bookmark', - pecan.request.host_url, - 'federations', '', - bookmark=True)] - v1.nodegroups = [link.Link.make_link('self', pecan.request.host_url, - 'clusters/{cluster_id}', - 'nodegroups'), - link.Link.make_link('bookmark', - pecan.request.host_url, - 'clusters/{cluster_id}', - 'nodegroups', - bookmark=True)] - v1.credentials = [link.Link.make_link('self', pecan.request.host_url, - 'credentials', ''), - link.Link.make_link('bookmark', - pecan.request.host_url, - 'credentials', '', - bookmark=True)] + v1.links = [ + link.Link.make_link( + 'self', pecan.request.application_url, 'v1', '', + bookmark=True), + link.Link.make_link( + 'describedby', 'http://docs.openstack.org', + 'developer/magnum/dev', 'api-spec-v1.html', bookmark=True, + type='text/html')] + v1.media_types = [ + MediaType( + 'application/json', + 'application/vnd.openstack.magnum.v1+json')] + v1.clustertemplates = [ + link.Link.make_link( + 'self', pecan.request.application_url, 'clustertemplates', ''), + link.Link.make_link( + 'bookmark', pecan.request.application_url, 'clustertemplates', + '', bookmark=True)] + v1.clusters = [ + link.Link.make_link( + 'self', pecan.request.application_url, 'clusters', ''), + link.Link.make_link( + 'bookmark', pecan.request.application_url, 'clusters', '', + bookmark=True)] + v1.quotas = [ + link.Link.make_link( + 'self', pecan.request.application_url, 'quotas', ''), + link.Link.make_link( + 'bookmark', pecan.request.application_url, 'quotas', '', + bookmark=True)] + v1.certificates = [ + link.Link.make_link( + 'self', pecan.request.application_url, 'certificates', ''), + link.Link.make_link( + 'bookmark', pecan.request.application_url, 'certificates', '', + bookmark=True)] + v1.mservices = [ + link.Link.make_link( + 'self', pecan.request.application_url, 'mservices', ''), + link.Link.make_link( + 'bookmark', pecan.request.application_url, 'mservices', '', + bookmark=True)] + v1.stats = [ + link.Link.make_link( + 'self', pecan.request.application_url, 'stats', ''), + link.Link.make_link( + 'bookmark', pecan.request.application_url, 'stats', '', + bookmark=True)] + v1.federations = [ + link.Link.make_link( + 'self', pecan.request.application_url, 'federations', ''), + link.Link.make_link( + 'bookmark', pecan.request.application_url, 'federations', '', + bookmark=True)] + v1.nodegroups = [ + link.Link.make_link( + 'self', pecan.request.application_url, 'clusters/{cluster_id}', + 'nodegroups'), + link.Link.make_link( + 'bookmark', pecan.request.application_url, + 'clusters/{cluster_id}', 'nodegroups', bookmark=True)] + v1.credentials = [ + link.Link.make_link( + 'self', pecan.request.application_url, 'credentials', ''), + link.Link.make_link( + 'bookmark', pecan.request.application_url, 'credentials', '', + bookmark=True)] return v1 diff --git a/magnum/api/controllers/v1/certificate.py b/magnum/api/controllers/v1/certificate.py index 24f76c529..e2d9fea4b 100644 --- a/magnum/api/controllers/v1/certificate.py +++ b/magnum/api/controllers/v1/certificate.py @@ -122,8 +122,8 @@ def _convert_with_links(certificate, url, expand=True): @classmethod def convert_with_links(cls, rpc_cert, expand=True): cert = Certificate(**rpc_cert.as_dict()) - return cls._convert_with_links(cert, - pecan.request.host_url, expand) + return cls._convert_with_links( + cert, pecan.request.application_url, expand) @classmethod def sample(cls, expand=True): diff --git a/magnum/api/controllers/v1/cluster.py b/magnum/api/controllers/v1/cluster.py index 68e02c5bb..14bc56149 100644 --- a/magnum/api/controllers/v1/cluster.py +++ b/magnum/api/controllers/v1/cluster.py @@ -229,8 +229,8 @@ def _convert_with_links(cluster, url, expand=True, parent_labels=None): def convert_with_links(cls, rpc_cluster, expand=True): cluster = Cluster(**rpc_cluster.as_dict()) parent_labels = rpc_cluster.cluster_template.labels - return cls._convert_with_links(cluster, pecan.request.host_url, expand, - parent_labels) + return cls._convert_with_links( + cluster, pecan.request.application_url, expand, parent_labels) @classmethod def sample(cls, expand=True): diff --git a/magnum/api/controllers/v1/cluster_template.py b/magnum/api/controllers/v1/cluster_template.py index 59c5a1d67..ab278668d 100644 --- a/magnum/api/controllers/v1/cluster_template.py +++ b/magnum/api/controllers/v1/cluster_template.py @@ -188,8 +188,8 @@ def _convert_with_links(cluster_template, url): @classmethod def convert_with_links(cls, rpc_cluster_template): cluster_template = ClusterTemplate(**rpc_cluster_template.as_dict()) - return cls._convert_with_links(cluster_template, - pecan.request.host_url) + return cls._convert_with_links( + cluster_template, pecan.request.application_url) @classmethod def sample(cls): diff --git a/magnum/api/controllers/v1/collection.py b/magnum/api/controllers/v1/collection.py index c17251e56..73cda4e6b 100644 --- a/magnum/api/controllers/v1/collection.py +++ b/magnum/api/controllers/v1/collection.py @@ -44,5 +44,6 @@ def get_next(self, limit, url=None, marker_attribute='uuid', **kwargs): 'args': q_args, 'limit': limit, 'marker': getattr(self.collection[-1], marker_attribute)} - return link.Link.make_link('next', pecan.request.host_url, - resource_url, next_args).href + return link.Link.make_link( + 'next', pecan.request.application_url, resource_url, next_args + ).href diff --git a/magnum/api/controllers/v1/federation.py b/magnum/api/controllers/v1/federation.py index c02995c2c..0ad97ceef 100644 --- a/magnum/api/controllers/v1/federation.py +++ b/magnum/api/controllers/v1/federation.py @@ -111,8 +111,8 @@ def _convert_with_links(federation, url, expand=True): @classmethod def convert_with_links(cls, rpc_federation, expand=True): federation = Federation(**rpc_federation.as_dict()) - return cls._convert_with_links(federation, pecan.request.host_url, - expand) + return cls._convert_with_links( + federation, pecan.request.application_url, expand) @classmethod def sample(cls, expand=True): diff --git a/magnum/api/controllers/v1/nodegroup.py b/magnum/api/controllers/v1/nodegroup.py index ef8ddd6b8..f575ada84 100644 --- a/magnum/api/controllers/v1/nodegroup.py +++ b/magnum/api/controllers/v1/nodegroup.py @@ -163,7 +163,7 @@ def __init__(self, **kwargs): @classmethod def convert(cls, nodegroup, expand=True): - url = pecan.request.host_url + url = pecan.request.application_url cluster_path = 'clusters/%s' % nodegroup.cluster_id nodegroup_path = 'nodegroups/%s' % nodegroup.uuid diff --git a/magnum/service/periodic.py b/magnum/service/periodic.py index f6ce5d09a..5c2b4c07b 100644 --- a/magnum/service/periodic.py +++ b/magnum/service/periodic.py @@ -213,9 +213,15 @@ def sync_cluster_health_status(self, ctx): try: LOG.debug('Starting to sync up cluster health status') - status = [objects.fields.ClusterStatus.CREATE_COMPLETE, - objects.fields.ClusterStatus.UPDATE_COMPLETE, + status = [ + objects.fields.ClusterStatus.CREATE_IN_PROGRESS, + objects.fields.ClusterStatus.CREATE_FAILED, + objects.fields.ClusterStatus.CREATE_COMPLETE, objects.fields.ClusterStatus.UPDATE_IN_PROGRESS, + objects.fields.ClusterStatus.UPDATE_COMPLETE, + objects.fields.ClusterStatus.UPDATE_FAILED, + objects.fields.ClusterStatus.DELETE_IN_PROGRESS, + objects.fields.ClusterStatus.DELETE_FAILED, objects.fields.ClusterStatus.ROLLBACK_IN_PROGRESS] filters = {'status': status} clusters = objects.Cluster.list(ctx, filters=filters) diff --git a/magnum/tests/fakes.py b/magnum/tests/fakes.py index 3a64078ce..f940e658e 100644 --- a/magnum/tests/fakes.py +++ b/magnum/tests/fakes.py @@ -36,7 +36,8 @@ class FakePecanRequest(mock.Mock): def __init__(self, **kwargs): super(FakePecanRequest, self).__init__(**kwargs) - self.host_url = 'http://test_url:8080/test' + self.host_url = 'http://test_url:8080' + self.application_url = f'{self.host_url}/test' self.context = {} self.body = '' self.content_type = 'text/unicode' diff --git a/magnum/tests/unit/api/controllers/v1/test_cluster.py b/magnum/tests/unit/api/controllers/v1/test_cluster.py index 9c37ff40e..503758488 100644 --- a/magnum/tests/unit/api/controllers/v1/test_cluster.py +++ b/magnum/tests/unit/api/controllers/v1/test_cluster.py @@ -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, @@ -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, @@ -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', @@ -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) diff --git a/magnum/tests/unit/api/controllers/v1/test_federation.py b/magnum/tests/unit/api/controllers/v1/test_federation.py index c321e3ef8..97bd65586 100644 --- a/magnum/tests/unit/api/controllers/v1/test_federation.py +++ b/magnum/tests/unit/api/controllers/v1/test_federation.py @@ -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 @@ -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) diff --git a/magnum/tests/unit/api/controllers/v1/test_nodegroup.py b/magnum/tests/unit/api/controllers/v1/test_nodegroup.py index a2b757c97..de6ab0eb3 100644 --- a/magnum/tests/unit/api/controllers/v1/test_nodegroup.py +++ b/magnum/tests/unit/api/controllers/v1/test_nodegroup.py @@ -293,11 +293,8 @@ 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) @@ -305,12 +302,9 @@ def test_create_nodegroup(self, mock_utcnow): 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) @@ -318,13 +312,10 @@ def test_create_nodegroup_without_node_count(self, mock_utcnow): # 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) @@ -332,67 +323,49 @@ def test_create_nodegroup_with_zero_nodes(self, mock_utcnow): # 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) @@ -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) @@ -710,11 +680,7 @@ 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) @@ -722,11 +688,7 @@ def test_remove_internal_attr(self, mock_utcnow): 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) diff --git a/releasenotes/source/2024.1.rst b/releasenotes/source/2024.1.rst index 4977a4f1a..6896656be 100644 --- a/releasenotes/source/2024.1.rst +++ b/releasenotes/source/2024.1.rst @@ -3,4 +3,4 @@ =========================== .. release-notes:: - :branch: stable/2024.1 + :branch: unmaintained/2024.1 diff --git a/setup.cfg b/setup.cfg index 4e9f4be41..707f924b7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -37,9 +37,6 @@ console_scripts = magnum-driver-manage = magnum.cmd.driver_manage:main magnum-status = magnum.cmd.status:main -wsgi_scripts = - magnum-api-wsgi = magnum.api.app:build_wsgi_app - oslo.config.opts = magnum = magnum.opts:list_opts magnum.conf = magnum.conf.opts:list_opts