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