Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vSphere: config.guestId/guestFullName changed to guest.guestId/guestFullName #263

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions vsphere/stackstate_checks/vsphere/vsphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,8 @@ def _collect_mors_and_attributes(self, server_instance):
property_spec.pathSet.append("runtime.host")
property_spec.pathSet.append("guest.hostName")
# Topology property collection as we did previously
property_spec.pathSet.append("config.guestId")
property_spec.pathSet.append("config.guestFullName")
property_spec.pathSet.append("guest.guestId")
property_spec.pathSet.append("guest.guestFullName")
property_spec.pathSet.append("config.hardware.numCPU")
property_spec.pathSet.append("config.hardware.memoryMB")
property_spec.pathSet.append("datastore")
Expand Down Expand Up @@ -1057,8 +1057,8 @@ def get_topology_items(self, server_instance, domain="Unspecified", regexes=None
datastores.append(ds._moId)
topology_tags["datastore"] = datastores
add_label_pair(labels, "name", topology_tags["name"])
add_label_pair(labels, "guestId", properties.get("config.guestId", ""))
add_label_pair(labels, "guestFullName", properties.get("config.guestFullName", ""))
add_label_pair(labels, "guestId", properties.get("guest.guestId", ""))
add_label_pair(labels, "guestFullName", properties.get("guest.guestFullName", ""))
add_label_pair(labels, "numCPU", properties.get("config.hardware.numCPU", ""))
add_label_pair(labels, "memoryMB", properties.get("config.hardware.memoryMB", ""))
topology_tags["labels"] = labels
Expand Down
59 changes: 54 additions & 5 deletions vsphere/tests/test_vsphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ def test_get_topology_items_vms_hosts(vsphere, instance):
"name": "mocked_vm",
"parent": mocked_host,
"runtime.powerState": vim.VirtualMachinePowerState.poweredOn,
"config.guestId": "other3xLinux64Guest",
"guest.guestId": "other3xLinux64Guest",
"config.hardware.numCPU": "2"
},
mocked_host: {"name": "mocked_host", "parent": None},
Expand Down Expand Up @@ -884,7 +884,7 @@ def test_get_topology_items_regex_vms(vsphere, instance):
"name": "mocked_vm",
"parent": None,
"runtime.powerState": vim.VirtualMachinePowerState.poweredOn,
"config.guestId": "other3xLinux64Guest",
"guest.guestId": "other3xLinux64Guest",
"config.hardware.numCPU": "2"
}
}
Expand Down Expand Up @@ -923,7 +923,7 @@ def test_check_vsphere_topology_with_vm_host(instance, topology):
"name": "mocked_vm",
"parent": mocked_host,
"runtime.powerState": vim.VirtualMachinePowerState.poweredOn,
"config.guestId": "other3xLinux64Guest",
"guest.guestId": "other3xLinux64Guest",
"config.hardware.numCPU": "2"
},
mocked_host: {"name": "mocked_host", "parent": None, "vm": [mocked_vm]},
Expand Down Expand Up @@ -1012,7 +1012,7 @@ def test_check_vsphere_full_topology(instance, topology):
"name": "mocked_vm",
"parent": mocked_host,
"runtime.powerState": vim.VirtualMachinePowerState.poweredOn,
"config.guestId": "other3xLinux64Guest",
"guest.guestId": "other3xLinux64Guest",
"config.hardware.numCPU": "2"
},
mocked_host: {"name": "mocked_host", "parent": None, "vm": [mocked_vm], "childEntity": [mocked_cr]},
Expand Down Expand Up @@ -1169,7 +1169,7 @@ def test_get_topology_items_vms_no_unicode(instance, topology):
"name": "mocked_vm",
"parent": None,
"runtime.powerState": vim.VirtualMachinePowerState.poweredOn,
"config.guestId": "other3xLinux64Guest",
"guest.guestId": "other3xLinux64Guest",
"config.hardware.numCPU": "2"
}
}
Expand All @@ -1196,6 +1196,55 @@ def test_get_topology_items_vms_no_unicode(instance, topology):
assert type(tag) is str


def test_vm_guestid_and_guestfullname(instance, topology):
"""
Test if VMs collected use guest.guestId/guestFullName instead of config.guestId/guestFullName
config.guestId/guestFullName is defined in the VMX (initial/chosen at creation)
guest.guestId/guestFullName is provided by VMWare Tools.
If VMWare tools is not installed, guest.guestId/guestFullName is set to config.guestId/guestFullName
"""
vsphere_check = VSphereCheck('vsphere', {}, [instance])
vsphere_check.vsphere_client_connect = MagicMock()
vsphere_check.session = None
# get the client
client = vsphere_client()

# list_attached_tags method returns empty list of tags
client.tagging.TagAssociation.list_attached_tags = MagicMock(return_value=[])

# assign the vsphere client object to the vsphere check client object
vsphere_check.client = client
mocked_vm = MockedMOR(spec="VirtualMachine", _moId="vm-1")
mocked_mors_attrs = {
mocked_vm: {
"name": "mocked_vm",
"parent": None,
"runtime.powerState": vim.VirtualMachinePowerState.poweredOn,
"config.guestId": 'centos64Guest',
"config.guestFullName": 'CentOS 4/5 (64-bit)',
"guest.guestId": 'centos7_64Guest',
"guest.guestFullName": 'CentOS 7 (64-bit)',
}
}

with mock.patch('stackstate_checks.vsphere.vsphere.vmodl'):
with mock.patch('stackstate_checks.vsphere.vsphere.connect.SmartConnect') as SmartConnect:
SmartConnect.return_value = get_mocked_server()
vsphere_check._collect_mors_and_attributes = mock.MagicMock(return_value=mocked_mors_attrs)
vsphere_check.collect_topology(instance)
snapshot = topology.get_snapshot(vsphere_check.check_id)
# only vm component should be created in the snapshot
assert len(snapshot['components']) == 1
# there should be no relations
assert len(snapshot['relations']) == 0

# assert the collected component has every property as str type
component = snapshot['components'][0]

assert 'guestFullName:CentOS 7 (64-bit)' in component['data']['labels']
assert 'guestId:centos7_64Guest' in component['data']['labels']


def test_missing_host_conf(instance):
"""
Test to check if DataError raised for missing host
Expand Down