Merge branch 'bugfix/make-code-consistent' into 'master'

Make code consistent

See merge request ungleich-public/cdist!904
This commit is contained in:
poljakowski 2020-07-10 21:01:42 +02:00
commit 506a0f3f47

View file

@ -91,10 +91,6 @@ class Emulator:
self.type_name = os.path.basename(argv[0]) self.type_name = os.path.basename(argv[0])
self.cdist_type = core.CdistType(self.type_base_path, self.type_name) self.cdist_type = core.CdistType(self.type_base_path, self.type_name)
# If set then object alreay exists and this var holds existing
# requirements.
self._existing_reqs = None
self.__init_log() self.__init_log()
def run(self): def run(self):
@ -230,9 +226,6 @@ class Emulator:
self.parameters[key] = value self.parameters[key] = value
if self.cdist_object.exists and 'CDIST_OVERRIDE' not in self.env: if self.cdist_object.exists and 'CDIST_OVERRIDE' not in self.env:
# Make existing requirements a set so that we can compare it
# later with new requirements.
self._existing_reqs = set(self.cdist_object.requirements)
obj_params = self._object_params_in_context() obj_params = self._object_params_in_context()
if obj_params != self.parameters: if obj_params != self.parameters:
errmsg = ("Object %s already exists with conflicting " errmsg = ("Object %s already exists with conflicting "
@ -251,23 +244,26 @@ class Emulator:
else: else:
self.cdist_object.create() self.cdist_object.create()
self.cdist_object.parameters = self.parameters self.cdist_object.parameters = self.parameters
# record the created object in typeorder file # Do the following recording even if object exists, but with
with open(self.typeorder_path, 'a') as typeorderfile: # different requirements.
print(self.cdist_object.name, file=typeorderfile)
# record the created object in parent object typeorder file # record the created object in typeorder file
__object_name = self.env.get('__object_name', None) with open(self.typeorder_path, 'a') as typeorderfile:
depname = self.cdist_object.name print(self.cdist_object.name, file=typeorderfile)
if __object_name: # record the created object in parent object typeorder file
parent = self.cdist_object.object_from_name(__object_name) __object_name = self.env.get('__object_name', None)
parent.typeorder.append(self.cdist_object.name) depname = self.cdist_object.name
if self._order_dep_on(): if __object_name:
self.log.trace(('[ORDER_DEP] Adding %s to typeorder dep' parent = self.cdist_object.object_from_name(__object_name)
' for %s'), depname, parent.name) parent.typeorder.append(self.cdist_object.name)
parent.typeorder_dep.append(depname) if self._order_dep_on():
elif self._order_dep_on(): self.log.trace(('[ORDER_DEP] Adding %s to typeorder dep'
self.log.trace('[ORDER_DEP] Adding %s to global typeorder dep', ' for %s'), depname, parent.name)
depname) parent.typeorder_dep.append(depname)
self._add_typeorder_dep(depname) elif self._order_dep_on():
self.log.trace('[ORDER_DEP] Adding %s to global typeorder dep',
depname)
self._add_typeorder_dep(depname)
# Record / Append source # Record / Append source
self.cdist_object.source.append(self.object_source) self.cdist_object.source.append(self.object_source)
@ -322,8 +318,6 @@ class Emulator:
# This ensures pattern matching is done against sanitised list # This ensures pattern matching is done against sanitised list
self.cdist_object.requirements.append(cdist_object.name) self.cdist_object.requirements.append(cdist_object.name)
return cdist_object.name
def _order_dep_on(self): def _order_dep_on(self):
return os.path.exists(self.order_dep_state_path) return os.path.exists(self.order_dep_state_path)
@ -392,7 +386,6 @@ class Emulator:
# so do not set a requirement # so do not set a requirement
pass pass
reqs = set()
if "require" in self.env: if "require" in self.env:
requirements = self.env['require'] requirements = self.env['require']
self.log.debug("reqs = " + requirements) self.log.debug("reqs = " + requirements)
@ -400,23 +393,7 @@ class Emulator:
# Ignore empty fields - probably the only field anyway # Ignore empty fields - probably the only field anyway
if len(requirement) == 0: if len(requirement) == 0:
continue continue
object_name = self.record_requirement(requirement) self.record_requirement(requirement)
reqs.add(object_name)
if self._existing_reqs is not None:
# If object exists then compare existing and new requirements.
if self._existing_reqs != reqs:
warnmsg = ("Object {} already exists with requirements:\n"
"{}: {}\n"
"{}: {}\n"
"Dependency resolver could not handle dependencies "
"as expected.".format(
self.cdist_object.name,
" ".join(self.cdist_object.source),
self._existing_reqs,
self.object_source,
reqs
))
self.log.warning(warnmsg)
def record_auto_requirements(self): def record_auto_requirements(self):
"""An object shall automatically depend on all objects that it """An object shall automatically depend on all objects that it