summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Gomes <tiago.gomes@codethink.co.uk>2015-11-11 16:52:45 (GMT)
committerBaserock Gerrit <gerrit@baserock.org>2015-12-21 10:45:52 (GMT)
commit740609fe194e0be2a8dc7ceab4872f62920f716f (patch)
tree497976f283a7bdf504af937dcee0860efd029170
parent52bfd9cd5b711badf2c5fb3b7929235269bb9cb8 (diff)
downloadmorph-740609fe194e0be2a8dc7ceab4872f62920f716f.tar.gz
morphloader: remove obsolete fields
Change-Id: If7bf7af93eb404be48f752ed64e8b038a3073668
-rw-r--r--morphlib/morphloader.py75
-rw-r--r--morphlib/morphloader_tests.py87
2 files changed, 2 insertions, 160 deletions
diff --git a/morphlib/morphloader.py b/morphlib/morphloader.py
index ba48b77..144afe9 100644
--- a/morphlib/morphloader.py
+++ b/morphlib/morphloader.py
@@ -22,21 +22,6 @@ import yaml
import morphlib
-class MorphologyObsoleteFieldWarning(UserWarning):
-
- def __init__(self, morphology, spec, field):
- self.kind = morphology['kind']
- self.morphology_name = morphology.get('name', '<unknown>')
- self.stratum_name = spec.get('alias', spec['morph'])
- self.field = field
-
- def __str__(self):
- format_string = ('%(kind)s morphology %(morphology_name)s refers to '
- 'stratum %(stratum_name)s with the %(field)s field. '
- 'Defaulting to null.')
- return format_string % self.__dict__
-
-
class MorphologySyntaxError(morphlib.Error):
pass
@@ -94,14 +79,6 @@ class InvalidTypeError(MorphologyValidationError):
(field, expected, actual, morphology_name))
-class ObsoleteFieldsError(MorphologyValidationError):
-
- def __init__(self, fields, morph_filename):
- self.msg = (
- 'Morphology %s uses obsolete fields: %s' %
- (morph_filename, ' '.join(fields)))
-
-
class UnknownArchitectureError(MorphologyValidationError):
def __init__(self, arch, morph_filename):
@@ -361,13 +338,6 @@ class MorphologyLoader(object):
],
}
- _obsolete_fields = {
- 'system': [
- 'system-kind',
- 'disk-size',
- ],
- }
-
_static_defaults = {
'chunk': {
'description': '',
@@ -496,10 +466,8 @@ class MorphologyLoader(object):
raise UnknownKindError(morph['kind'], morph.filename)
required = ['kind'] + self._required_fields[kind]
- obsolete = self._obsolete_fields.get(kind, [])
allowed = self._static_defaults[kind].keys()
self._require_fields(required, morph)
- self._deny_obsolete_fields(obsolete, morph)
self._deny_unknown_fields(required + allowed, morph)
getattr(self, '_validate_%s' % kind)(morph)
@@ -546,9 +514,6 @@ class MorphologyLoader(object):
raise DuplicateStratumError(morph['name'], name)
names.add(name)
- # Validate stratum spec fields
- self._validate_stratum_specs_fields(morph, 'strata')
-
# We allow the ARMv7 little-endian architecture to be specified
# as armv7 and armv7l. Normalise.
if morph['arch'] == 'armv7':
@@ -581,9 +546,6 @@ class MorphologyLoader(object):
raise NoStratumBuildDependenciesError(
morph['name'], morph.filename)
- # Validate build-dependencies if specified
- self._validate_stratum_specs_fields(morph, 'build-depends')
-
# All chunk names must be unique within a stratum.
names = set()
for spec in morph['chunks']:
@@ -700,18 +662,6 @@ class MorphologyLoader(object):
type(pattern), morphology_name)
errors.append(e)
- @classmethod
- def _warn_obsolete_field(cls, morphology, spec, field):
- warnings.warn(MorphologyObsoleteFieldWarning(morphology, spec, field),
- stacklevel=2)
-
- @classmethod
- def _validate_stratum_specs_fields(cls, morphology, specs_field):
- for spec in morphology.get(specs_field, None) or []:
- for obsolete_field in ('repo', 'ref'):
- if obsolete_field in spec:
- cls._warn_obsolete_field(morphology, spec, obsolete_field)
-
def _require_field(self, field, morphology):
if field not in morphology:
raise MissingFieldError(field, morphology.filename)
@@ -720,11 +670,6 @@ class MorphologyLoader(object):
for field in fields:
self._require_field(field, morphology)
- def _deny_obsolete_fields(self, fields, morphology):
- obsolete_ones = [x for x in morphology if x in fields]
- if obsolete_ones:
- raise ObsoleteFieldsError(obsolete_ones, morphology.filename)
-
def _deny_unknown_fields(self, allowed, morphology):
for field in morphology:
if field not in allowed:
@@ -760,20 +705,6 @@ class MorphologyLoader(object):
getattr(self, '_unset_%s_defaults' % kind)(morphology)
- @classmethod
- def _set_stratum_specs_defaults(cls, morphology, specs_field):
- for spec in morphology.get(specs_field, None) or []:
- for obsolete_field in ('repo', 'ref'):
- if obsolete_field in spec:
- del spec[obsolete_field]
-
- @classmethod
- def _unset_stratum_specs_defaults(cls, morphology, specs_field):
- for spec in morphology.get(specs_field, []):
- for obsolete_field in ('repo', 'ref'):
- if obsolete_field in spec:
- del spec[obsolete_field]
-
def _set_cluster_defaults(self, morph):
for system in morph.get('systems', []):
if 'deploy-defaults' not in system:
@@ -789,10 +720,10 @@ class MorphologyLoader(object):
del system['deploy']
def _set_system_defaults(self, morph):
- self._set_stratum_specs_defaults(morph, 'strata')
+ pass
def _unset_system_defaults(self, morph):
- self._unset_stratum_specs_defaults(morph, 'strata')
+ pass
def _set_stratum_defaults(self, morph):
for spec in morph['chunks']:
@@ -804,7 +735,6 @@ class MorphologyLoader(object):
if 'prefix' not in spec:
spec['prefix'] = \
self._static_defaults['chunk']['prefix']
- self._set_stratum_specs_defaults(morph, 'build-depends')
def _unset_stratum_defaults(self, morph):
for spec in morph['chunks']:
@@ -816,7 +746,6 @@ class MorphologyLoader(object):
if 'prefix' in spec and spec['prefix'] == \
self._static_defaults['chunk']['prefix']:
del spec['prefix']
- self._unset_stratum_specs_defaults(morph, 'strata')
def _set_chunk_defaults(self, morph):
if morph['max-jobs'] is not None:
diff --git a/morphlib/morphloader_tests.py b/morphlib/morphloader_tests.py
index 392b0cb..1a75b51 100644
--- a/morphlib/morphloader_tests.py
+++ b/morphlib/morphloader_tests.py
@@ -23,7 +23,6 @@ import unittest
import warnings
import morphlib
-from morphlib.morphloader import MorphologyObsoleteFieldWarning
def stratum_template(name):
@@ -259,32 +258,6 @@ chunks:
morphlib.morphloader.DependsOnSelfError,
self.loader.load_from_string, text, 'strata/bad-stratum.morph')
- def test_fails_to_validate_system_with_obsolete_system_kind_field(self):
- m = morphlib.morphology.Morphology({
- 'kind': 'system',
- 'name': 'foo',
- 'arch': 'x86_64',
- 'strata': [
- {'morph': 'bar'},
- ],
- 'system-kind': 'foo',
- })
- self.assertRaises(
- morphlib.morphloader.ObsoleteFieldsError, self.loader.validate, m)
-
- def test_fails_to_validate_system_with_obsolete_disk_size_field(self):
- m = morphlib.morphology.Morphology({
- 'kind': 'system',
- 'name': 'foo',
- 'arch': 'x86_64',
- 'strata': [
- {'morph': 'bar'},
- ],
- 'disk-size': 'over 9000',
- })
- self.assertRaises(
- morphlib.morphloader.ObsoleteFieldsError, self.loader.validate, m)
-
def test_fails_to_validate_system_with_no_fields(self):
m = morphlib.morphology.Morphology({
'kind': 'system',
@@ -694,8 +667,6 @@ build-system: manual
strata=[
{
'morph': 'bar',
- 'repo': 'obsolete',
- 'ref': 'obsolete',
},
])
self.loader.set_defaults(m)
@@ -724,8 +695,6 @@ build-system: manual
'strata': [
{
'morph': 'bar',
- 'repo': None,
- 'ref': None,
},
],
'configuration-extensions': [],
@@ -848,62 +817,6 @@ build-system: manual
warnings.simplefilter("always", warning_class)
yield caught_warnings
- def test_warns_when_systems_refer_to_strata_with_repo_or_ref(self):
- for obsolete_field in ('repo', 'ref'):
- m = morphlib.morphology.Morphology(
- name="foo",
- kind="system",
- arch="testarch",
- strata=[
- {
- 'morph': 'bar',
- obsolete_field: 'obsolete',
- }])
-
- with self.catch_warnings(MorphologyObsoleteFieldWarning) \
- as caught_warnings:
-
- self.loader.validate(m)
- self.assertEqual(len(caught_warnings), 1)
- warning = caught_warnings[0].message
- self.assertEqual(warning.kind, 'system')
- self.assertEqual(warning.morphology_name, 'foo')
- self.assertEqual(warning.stratum_name, 'bar')
- self.assertEqual(warning.field, obsolete_field)
-
- def test_warns_when_strata_refer_to_build_depends_with_repo_or_ref(self):
- for obsolete_field in ('repo', 'ref'):
- m = morphlib.morphology.Morphology(
- {
- 'name': 'foo',
- 'kind': 'stratum',
- 'build-depends': [
- {
- 'morph': 'bar',
- obsolete_field: 'obsolete'
- },
- ],
- 'chunks': [
- {
- 'morph': 'chunk',
- 'name': 'chunk',
- 'build-mode': 'test',
- 'build-depends': [],
- },
- ],
- })
-
- with self.catch_warnings(MorphologyObsoleteFieldWarning) \
- as caught_warnings:
-
- self.loader.validate(m)
- self.assertEqual(len(caught_warnings), 1)
- warning = caught_warnings[0].message
- self.assertEqual(warning.kind, 'stratum')
- self.assertEqual(warning.morphology_name, 'foo')
- self.assertEqual(warning.stratum_name, 'bar')
- self.assertEqual(warning.field, obsolete_field)
-
def test_unordered_asciibetically_after_ordered(self):
# We only get morphologies with arbitrary keys in clusters
m = morphlib.morphology.Morphology(