Rename 'dependency' to 'link'
Change-Id: I68d9b8d23b5feae2e0fde4490ce0b544a180b96f
This commit is contained in:
parent
15638ffbd9
commit
e0f63c887e
@ -434,24 +434,24 @@ class BaseArtifact(base.VersionedObject):
|
|||||||
else:
|
else:
|
||||||
action = cls.activate
|
action = cls.activate
|
||||||
|
|
||||||
# check updates for dependencies and validate them
|
# check updates for links and validate them
|
||||||
try:
|
try:
|
||||||
for key, value in six.iteritems(updates):
|
for key, value in six.iteritems(updates):
|
||||||
if cls.fields.get(key) is glare_fields.Dependency \
|
if cls.fields.get(key) is glare_fields.Link \
|
||||||
and value is not None:
|
and value is not None:
|
||||||
# check format
|
# check format
|
||||||
glare_fields.DependencyFieldType.coerce(None, key, value)
|
glare_fields.LinkFieldType.coerce(None, key, value)
|
||||||
# check containment
|
# check containment
|
||||||
if glare_fields.DependencyFieldType.is_external(value):
|
if glare_fields.LinkFieldType.is_external(value):
|
||||||
# validate external dependency
|
# validate external link
|
||||||
cls._validate_external_dependency(value)
|
cls._validate_external_link(value)
|
||||||
else:
|
else:
|
||||||
type_name = (glare_fields.DependencyFieldType.
|
type_name = (glare_fields.LinkFieldType.
|
||||||
get_type_name(value))
|
get_type_name(value))
|
||||||
af_type = registry.get_artifact_type(type_name)
|
af_type = registry.get_artifact_type(type_name)
|
||||||
cls._validate_soft_dependency(context, value, af_type)
|
cls._validate_soft_link(context, value, af_type)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = (_("Bad dependency in artifact %(af)s: %(msg)s")
|
msg = (_("Bad link in artifact %(af)s: %(msg)s")
|
||||||
% {"af": artifact.id, "msg": str(e)})
|
% {"af": artifact.id, "msg": str(e)})
|
||||||
raise exception.BadRequest(msg)
|
raise exception.BadRequest(msg)
|
||||||
|
|
||||||
@ -461,12 +461,12 @@ class BaseArtifact(base.VersionedObject):
|
|||||||
return action
|
return action
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _validate_external_dependency(cls, link):
|
def _validate_external_link(cls, link):
|
||||||
with urlrequest.urlopen(link) as data:
|
with urlrequest.urlopen(link) as data:
|
||||||
data.read(1)
|
data.read(1)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _validate_soft_dependency(cls, context, link, af_type):
|
def _validate_soft_link(cls, context, link, af_type):
|
||||||
af_id = link.split('/')[3]
|
af_id = link.split('/')[3]
|
||||||
af_type.get(context, af_id)
|
af_type.get(context, af_id)
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ BlobDict = attribute.BlobDictAttribute.init
|
|||||||
class HeatTemplate(base.BaseArtifact):
|
class HeatTemplate(base.BaseArtifact):
|
||||||
|
|
||||||
fields = {
|
fields = {
|
||||||
'environments': Dict(glare_fields.Dependency,
|
'environments': Dict(glare_fields.Link,
|
||||||
mutable=True,
|
mutable=True,
|
||||||
description="References to Heat Environments "
|
description="References to Heat Environments "
|
||||||
"that can be used with current "
|
"that can be used with current "
|
||||||
|
@ -112,8 +112,8 @@ class BlobField(fields.AutoTypedField):
|
|||||||
AUTO_TYPE = BlobFieldType()
|
AUTO_TYPE = BlobFieldType()
|
||||||
|
|
||||||
|
|
||||||
class DependencyFieldType(fields.FieldType):
|
class LinkFieldType(fields.FieldType):
|
||||||
"""Dependency field specifies Artifact dependency on other artifact or some
|
"""Link field specifies Artifact dependency on other artifact or some
|
||||||
external resource. From technical perspective it is just soft link to Glare
|
external resource. From technical perspective it is just soft link to Glare
|
||||||
Artifact or https/http resource. So Artifact users can download the
|
Artifact or https/http resource. So Artifact users can download the
|
||||||
referenced file by that link.
|
referenced file by that link.
|
||||||
@ -134,7 +134,7 @@ class DependencyFieldType(fields.FieldType):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def coerce(obj, attr, value):
|
def coerce(obj, attr, value):
|
||||||
# to remove the existing dependency user sets its value to None,
|
# to remove the existing link user sets its value to None,
|
||||||
# we have to consider this case.
|
# we have to consider this case.
|
||||||
if value is None:
|
if value is None:
|
||||||
return value
|
return value
|
||||||
@ -144,7 +144,7 @@ class DependencyFieldType(fields.FieldType):
|
|||||||
'not a %(type)s') %
|
'not a %(type)s') %
|
||||||
{'attr': attr, 'type': type(value).__name__})
|
{'attr': attr, 'type': type(value).__name__})
|
||||||
# determine if link is external or internal
|
# determine if link is external or internal
|
||||||
external = DependencyFieldType.is_external(value)
|
external = LinkFieldType.is_external(value)
|
||||||
# validate link itself
|
# validate link itself
|
||||||
if external:
|
if external:
|
||||||
link = urlparse.urlparse(value)
|
link = urlparse.urlparse(value)
|
||||||
@ -155,7 +155,7 @@ class DependencyFieldType(fields.FieldType):
|
|||||||
result = value.split('/')
|
result = value.split('/')
|
||||||
if len(result) != 4 or result[1] != 'artifacts':
|
if len(result) != 4 or result[1] != 'artifacts':
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
_('Dependency link %(link)s is not valid in field '
|
_('Link %(link)s is not valid in field '
|
||||||
'%(attr)s. The link must be either valid url or '
|
'%(attr)s. The link must be either valid url or '
|
||||||
'reference to artifact. Example: '
|
'reference to artifact. Example: '
|
||||||
'/artifacts/<artifact_type>/<artifact_id>'
|
'/artifacts/<artifact_type>/<artifact_id>'
|
||||||
@ -163,8 +163,8 @@ class DependencyFieldType(fields.FieldType):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
class Dependency(fields.AutoTypedField):
|
class Link(fields.AutoTypedField):
|
||||||
AUTO_TYPE = DependencyFieldType()
|
AUTO_TYPE = LinkFieldType()
|
||||||
|
|
||||||
|
|
||||||
class List(fields.AutoTypedField):
|
class List(fields.AutoTypedField):
|
||||||
|
@ -50,7 +50,7 @@ class MuranoPackage(base.BaseArtifact):
|
|||||||
"the package."),
|
"the package."),
|
||||||
'inherits': Dict(fields.String),
|
'inherits': Dict(fields.String),
|
||||||
'keywords': List(fields.String, mutable=True),
|
'keywords': List(fields.String, mutable=True),
|
||||||
'dependencies': List(glare_fields.Dependency,
|
'dependencies': List(glare_fields.Link,
|
||||||
required_on_activate=False,
|
required_on_activate=False,
|
||||||
description="List of package dependencies for "
|
description="List of package dependencies for "
|
||||||
"this package."),
|
"this package."),
|
||||||
|
@ -36,10 +36,10 @@ class SampleArtifact(base_artifact.BaseArtifact):
|
|||||||
description="I am Blob"),
|
description="I am Blob"),
|
||||||
'small_blob': Blob(max_blob_size=10, required_on_activate=False,
|
'small_blob': Blob(max_blob_size=10, required_on_activate=False,
|
||||||
mutable=True, filter_ops=[]),
|
mutable=True, filter_ops=[]),
|
||||||
'dependency1': Field(glare_fields.Dependency,
|
'link1': Field(glare_fields.Link,
|
||||||
required_on_activate=False,
|
required_on_activate=False,
|
||||||
filter_ops=[]),
|
filter_ops=[]),
|
||||||
'dependency2': Field(glare_fields.Dependency,
|
'link2': Field(glare_fields.Link,
|
||||||
required_on_activate=False,
|
required_on_activate=False,
|
||||||
filter_ops=[]),
|
filter_ops=[]),
|
||||||
'bool1': Field(fields.FlexibleBooleanField,
|
'bool1': Field(fields.FlexibleBooleanField,
|
||||||
|
@ -983,7 +983,7 @@ class TestArtifactOps(base.TestArtifact):
|
|||||||
# (except blobs and system)
|
# (except blobs and system)
|
||||||
expected = {
|
expected = {
|
||||||
"name": "test_big_create",
|
"name": "test_big_create",
|
||||||
"dependency1": "/artifacts/sample_artifact/%s" % some_af['id'],
|
"link1": "/artifacts/sample_artifact/%s" % some_af['id'],
|
||||||
"bool1": True,
|
"bool1": True,
|
||||||
"int1": 2323,
|
"int1": 2323,
|
||||||
"float1": 0.1,
|
"float1": 0.1,
|
||||||
@ -1099,14 +1099,14 @@ class TestArtifactOps(base.TestArtifact):
|
|||||||
url = '/sample_artifact/111111'
|
url = '/sample_artifact/111111'
|
||||||
self.delete(url=url, status=404)
|
self.delete(url=url, status=404)
|
||||||
|
|
||||||
# check that we can delete artifact with soft dependency
|
# check that we can delete artifact with soft link
|
||||||
art = self.create_artifact(
|
art = self.create_artifact(
|
||||||
data={"name": "test_af", "string_required": "test_str",
|
data={"name": "test_af", "string_required": "test_str",
|
||||||
"version": "0.0.1"})
|
"version": "0.0.1"})
|
||||||
artd = self.create_artifact(
|
artd = self.create_artifact(
|
||||||
data={"name": "test_afd", "string_required": "test_str",
|
data={"name": "test_afd", "string_required": "test_str",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"dependency1": '/artifacts/sample_artifact/%s' % art['id']})
|
"link1": '/artifacts/sample_artifact/%s' % art['id']})
|
||||||
|
|
||||||
url = '/sample_artifact/%s' % artd['id']
|
url = '/sample_artifact/%s' % artd['id']
|
||||||
self.delete(url=url, status=204)
|
self.delete(url=url, status=204)
|
||||||
@ -2109,23 +2109,23 @@ class TestUpdate(base.TestArtifact):
|
|||||||
self.patch(url=url, data=data, status=400)
|
self.patch(url=url, data=data, status=400)
|
||||||
|
|
||||||
|
|
||||||
class TestDependencies(base.TestArtifact):
|
class TestLinks(base.TestArtifact):
|
||||||
def test_manage_dependencies(self):
|
def test_manage_links(self):
|
||||||
some_af = self.create_artifact(data={"name": "test_af"})
|
some_af = self.create_artifact(data={"name": "test_af"})
|
||||||
dep_af = self.create_artifact(data={"name": "test_dep_af"})
|
dep_af = self.create_artifact(data={"name": "test_dep_af"})
|
||||||
dep_url = "/artifacts/sample_artifact/%s" % some_af['id']
|
dep_url = "/artifacts/sample_artifact/%s" % some_af['id']
|
||||||
|
|
||||||
# set valid dependency
|
# set valid link
|
||||||
patch = [{"op": "replace", "path": "/dependency1", "value": dep_url}]
|
patch = [{"op": "replace", "path": "/link1", "value": dep_url}]
|
||||||
url = '/sample_artifact/%s' % dep_af['id']
|
url = '/sample_artifact/%s' % dep_af['id']
|
||||||
af = self.patch(url=url, data=patch)
|
af = self.patch(url=url, data=patch)
|
||||||
self.assertEqual(af['dependency1'], dep_url)
|
self.assertEqual(af['link1'], dep_url)
|
||||||
|
|
||||||
# remove dependency from artifact
|
# remove link from artifact
|
||||||
patch = [{"op": "replace", "path": "/dependency1", "value": None}]
|
patch = [{"op": "replace", "path": "/link1", "value": None}]
|
||||||
af = self.patch(url=url, data=patch)
|
af = self.patch(url=url, data=patch)
|
||||||
self.assertIsNone(af['dependency1'])
|
self.assertIsNone(af['link1'])
|
||||||
|
|
||||||
# try to set invalid dependency
|
# try to set invalid link
|
||||||
patch = [{"op": "replace", "path": "/dependency1", "value": "Invalid"}]
|
patch = [{"op": "replace", "path": "/link1", "value": "Invalid"}]
|
||||||
self.patch(url=url, data=patch, status=400)
|
self.patch(url=url, data=patch, status=400)
|
||||||
|
@ -277,13 +277,13 @@ fixtures = {
|
|||||||
u'required_on_activate': False,
|
u'required_on_activate': False,
|
||||||
u'type': [u'string',
|
u'type': [u'string',
|
||||||
u'null']},
|
u'null']},
|
||||||
u'dependency1': {u'filter_ops': [u'eq',
|
u'link1': {u'filter_ops': [u'eq',
|
||||||
u'neq',
|
u'neq',
|
||||||
u'in'],
|
u'in'],
|
||||||
u'required_on_activate': False,
|
u'required_on_activate': False,
|
||||||
u'type': [u'string',
|
u'type': [u'string',
|
||||||
u'null']},
|
u'null']},
|
||||||
u'dependency2': {u'filter_ops': [u'eq',
|
u'link2': {u'filter_ops': [u'eq',
|
||||||
u'neq',
|
u'neq',
|
||||||
u'in'],
|
u'in'],
|
||||||
u'required_on_activate': False,
|
u'required_on_activate': False,
|
||||||
|
Loading…
Reference in New Issue
Block a user