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.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()
def run(self):
@ -230,9 +226,6 @@ class Emulator:
self.parameters[key] = value
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()
if obj_params != self.parameters:
errmsg = ("Object %s already exists with conflicting "
@ -251,6 +244,9 @@ class Emulator:
else:
self.cdist_object.create()
self.cdist_object.parameters = self.parameters
# Do the following recording even if object exists, but with
# different requirements.
# record the created object in typeorder file
with open(self.typeorder_path, 'a') as typeorderfile:
print(self.cdist_object.name, file=typeorderfile)
@ -322,8 +318,6 @@ class Emulator:
# This ensures pattern matching is done against sanitised list
self.cdist_object.requirements.append(cdist_object.name)
return cdist_object.name
def _order_dep_on(self):
return os.path.exists(self.order_dep_state_path)
@ -392,7 +386,6 @@ class Emulator:
# so do not set a requirement
pass
reqs = set()
if "require" in self.env:
requirements = self.env['require']
self.log.debug("reqs = " + requirements)
@ -400,23 +393,7 @@ class Emulator:
# Ignore empty fields - probably the only field anyway
if len(requirement) == 0:
continue
object_name = 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)
self.record_requirement(requirement)
def record_auto_requirements(self):
"""An object shall automatically depend on all objects that it