[SOLVED] Pb with getHostGroupTree_hash in opsi 4.2 ?

Antworten
nicolaslebrun
Beiträge: 98
Registriert: 18 Apr 2011, 11:43

[SOLVED] Pb with getHostGroupTree_hash in opsi 4.2 ?

Beitrag von nicolaslebrun »

Hi,

I'm studying migration to 4.2 version of Opsi (still on debian stretch version).
In an extendd conf, I use getHostGroupTree_hash.
It seems there's a pb with that function.
Am I missing something ?

Code: Alles auswählen

9:34:02 root@opsi0363636a ~ opsi-admin -d method getHostGroupTree_hash
[3] [2021-10-11 09:34:12.277] [               ] Failed to execute method getHostGroupTree_hash: dictionary changed size during iteration   (opsiadmin.py:777)
Traceback (most recent call last):
  File "opsiutils/opsiadmin.py", line 774, in execute
  File "opsiutils/opsiadmin.py", line 1206, in execute
  File "<string>", line 1, in getHostGroupTree_hash
  File "OPSI/Backend/Base/Extended.py", line 123, in _executeMethod
  File "<string>", line 208, in getHostGroupTree_hash
RuntimeError: dictionary changed size during iteration
[3] [2021-10-11 09:34:12.277] [               ] Failed to execute method getHostGroupTree_hash: dictionary changed size during iteration   (opsiadmin.py:387)
Traceback (most recent call last):
  File "opsiutils/opsiadmin.py", line 774, in execute
  File "opsiutils/opsiadmin.py", line 1206, in execute
  File "<string>", line 1, in getHostGroupTree_hash
  File "OPSI/Backend/Base/Extended.py", line 123, in _executeMethod
  File "<string>", line 208, in getHostGroupTree_hash
RuntimeError: dictionary changed size during iteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "opsiutils/opsiadmin.py", line 375, in shell_main
  File "opsiutils/opsiadmin.py", line 778, in execute
RuntimeError: Failed to execute method getHostGroupTree_hash: dictionary changed size during iteration
[3] [2021-10-11 09:34:12.281] [               ] Error during execution: Failed to execute method getHostGroupTree_hash: dictionary changed size during iteration   (opsiadmin.py:1753)
Traceback (most recent call last):
  File "opsiutils/opsiadmin.py", line 774, in execute
  File "opsiutils/opsiadmin.py", line 1206, in execute
  File "<string>", line 1, in getHostGroupTree_hash
  File "OPSI/Backend/Base/Extended.py", line 123, in _executeMethod
  File "<string>", line 208, in getHostGroupTree_hash
RuntimeError: dictionary changed size during iteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "opsiutils/opsiadmin.py", line 1746, in main
  File "opsiutils/opsiadmin.py", line 388, in shell_main
  File "opsiutils/opsiadmin.py", line 375, in shell_main
  File "opsiutils/opsiadmin.py", line 778, in execute
RuntimeError: Failed to execute method getHostGroupTree_hash: dictionary changed size during iteration

Regards,
Nico
Zuletzt geändert von nicolaslebrun am 12 Okt 2021, 11:36, insgesamt 1-mal geändert.
Benutzeravatar
fkalweit
uib-Team
Beiträge: 57
Registriert: 23 Okt 2020, 16:14

Re: Pb with getHostGroupTree_hash in opsi 4.2 ?

Beitrag von fkalweit »

Hello,

you can use the function groups_getObjetcs:

Code: Alles auswählen

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "group_getObjects",
  "params": [
    [],
    {
      "type": "HostGroup"
    }
  ]
}
getHostGroupTree_hash is a lagacy function.

I hope this helps.

Regards,
Fabian
nicolaslebrun
Beiträge: 98
Registriert: 18 Apr 2011, 11:43

Re: Pb with getHostGroupTree_hash in opsi 4.2 ?

Beitrag von nicolaslebrun »

Thanks Fabian for your answer,

I haven't seen it was a legacy function.

I just tried :

Code: Alles auswählen

opsi-admin -d method group_getObjects '[]'  '{"type":"HostGroup"}'
it does work, but the result is really not the same as

Code: Alles auswählen

opsi-admin -d method getHostGroupTree_hash
Is the support of getHostGroupTree_hash planned, or must I change my extend.d function to use group_getObjects ?

Thanks for your answer

Nico
Benutzeravatar
fkalweit
uib-Team
Beiträge: 57
Registriert: 23 Okt 2020, 16:14

Re: Pb with getHostGroupTree_hash in opsi 4.2 ?

Beitrag von fkalweit »

Hi,

I fixed the function getHostGroupTree_hash for opsi 4.2.
It will be in one of the next opsi-server releases.

For now you can fix it your self or create your own function host_groups_tress() or sth.

Code: Alles auswählen

def getHostGroupTree_hash(self):
	groups = {}
	childs = {}
	for group in self.group_getObjects(attributes=['id', 'parentGroupId']):
		if group.getParentGroupId():
			if group.getParentGroupId() not in childs:
				childs[group.getParentGroupId()] = {}
			childs[group.getParentGroupId()][group.getId()] = {}
		else:
			groups[group.getId()] = {}

	def insertGroup(gid, g, gs):
		if gid in gs:
			gs[gid] = g
			return True
		for ng in list(gs.keys()):
			if insertGroup(gid, g, gs[ng]):
				return True
		return False

	while list(childs.keys()):
		left = len(childs.keys())
		for groupId in list(childs.keys()):
			if insertGroup(groupId, childs[groupId], groups):
				del childs[groupId]
		if left == len(childs.keys()):
			from OPSI.Exceptions import BackendUnaccomplishableError
			raise BackendUnaccomplishableError("Error in host groups")
	return groups
Regards,
Fabian
nicolaslebrun
Beiträge: 98
Registriert: 18 Apr 2011, 11:43

Re: Pb with getHostGroupTree_hash in opsi 4.2 ?

Beitrag von nicolaslebrun »

Hi Fabian !

Just for my test, I've changed it in 20_legacy.conf, and it works like a charm.

Thanks a lot,
Nico
Antworten