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
2 changes: 1 addition & 1 deletion magnum/api/controllers/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions magnum/api/controllers/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
133 changes: 67 additions & 66 deletions magnum/api/controllers/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions magnum/api/controllers/v1/certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions magnum/api/controllers/v1/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions magnum/api/controllers/v1/cluster_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions magnum/api/controllers/v1/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions magnum/api/controllers/v1/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion magnum/api/controllers/v1/nodegroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions magnum/service/periodic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion magnum/tests/fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
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
Loading