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

Add proper teardown of VMware client #14799

Merged
merged 1 commit into from
Apr 23, 2024
Merged
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
12 changes: 12 additions & 0 deletions pytest_fixtures/component/provision_vmware.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from fauxfactory import gen_string
import pytest
from wrapanapi import VMWareSystem

from robottelo.config import settings

Expand All @@ -13,6 +14,17 @@ def vmware(request):
return versions[getattr(request, 'param', 'vmware8')]


@pytest.fixture
def vmwareclient(vmware):
vmwareclient = VMWareSystem(
hostname=vmware.hostname,
username=settings.vmware.username,
password=settings.vmware.password,
)
yield vmwareclient
vmwareclient.disconnect()


@pytest.fixture(scope='module')
def module_vmware_cr(module_provisioning_sat, module_sca_manifest_org, module_location, vmware):
return module_provisioning_sat.sat.api.VMWareComputeResource(
Expand Down
9 changes: 2 additions & 7 deletions tests/foreman/cli/test_computeresource_vmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from fauxfactory import gen_string
import pytest
from wait_for import wait_for
from wrapanapi import VMWareSystem

from robottelo.config import settings
from robottelo.constants import FOREMAN_PROVIDERS
Expand Down Expand Up @@ -93,6 +92,7 @@ def test_positive_provision_end_to_end(
module_vmware_hostgroup,
provision_method,
vmware,
vmwareclient,
):
"""Provision a host on vmware compute resource with
the help of hostgroup.
Expand Down Expand Up @@ -139,12 +139,7 @@ def test_positive_provision_end_to_end(
hostname = f'{hostname}.{module_provisioning_sat.domain.name}'
assert hostname == host['name']
# check if vm is created on vmware
vmware = VMWareSystem(
hostname=vmware.hostname,
username=settings.vmware.username,
password=settings.vmware.password,
)
assert vmware.does_vm_exist(hostname) is True
assert vmwareclient.does_vm_exist(hostname) is True
wait_for(
lambda: sat.cli.Host.info({'name': hostname})['status']['build-status']
!= 'Pending installation',
Expand Down
23 changes: 11 additions & 12 deletions tests/foreman/ui/test_computeresource_vmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import pytest
from wait_for import TimedOutError, wait_for
from wrapanapi.systems.virtualcenter import VMWareSystem, vim
from wrapanapi.systems.virtualcenter import vim

from robottelo.config import settings
from robottelo.constants import (
Expand Down Expand Up @@ -56,28 +56,26 @@ def _get_normalized_size(size):
return f'{size} {suffixes[suffix_index]}'


def _get_vmware_datastore_summary_string(data_store_name=settings.vmware.datastore, vmware=None):
@pytest.fixture
def get_vmware_datastore_summary_string(vmware, vmwareclient):
"""Return the datastore string summary for data_store_name

For "Local-Ironforge" datastore the string looks Like:

"Local-Ironforge (free: 1.66 TB, prov: 2.29 TB, total: 2.72 TB)"
"""
system = VMWareSystem(
hostname=vmware.hostname,
username=settings.vmware.username,
password=settings.vmware.password,
)
data_store_summary = [
h for h in system.get_obj_list(vim.Datastore) if h.host and h.name == data_store_name
h
for h in vmwareclient.get_obj_list(vim.Datastore)
if h.host and h.name == settings.vmware.datastore
][0].summary
uncommitted = data_store_summary.uncommitted or 0
capacity = _get_normalized_size(data_store_summary.capacity)
free_space = _get_normalized_size(data_store_summary.freeSpace)
prov = _get_normalized_size(
data_store_summary.capacity + uncommitted - data_store_summary.freeSpace
)
return f'{data_store_name} (free: {free_space}, prov: {prov}, total: {capacity})'
return f'{settings.vmware.datastore} (free: {free_space}, prov: {prov}, total: {capacity})'


@pytest.mark.e2e
Expand Down Expand Up @@ -295,7 +293,9 @@ def test_positive_resource_vm_power_management(session, vmware):
@pytest.mark.upgrade
@pytest.mark.tier2
@pytest.mark.parametrize('vmware', ['vmware7', 'vmware8'], indirect=True)
def test_positive_vmware_custom_profile_end_to_end(session, vmware, request, target_sat):
def test_positive_vmware_custom_profile_end_to_end(
session, vmware, request, target_sat, get_vmware_datastore_summary_string
):
"""Perform end to end testing for VMware compute profile.

:id: 24f7bb5f-2aaf-48cb-9a56-d2d0713dfe3d
Expand Down Expand Up @@ -330,13 +330,12 @@ def test_positive_vmware_custom_profile_end_to_end(session, vmware, request, tar
cdrom_drive = True
disk_size = '10 GB'
network = 'VLAN 1001' # hardcoding network here as this test won't be doing actual provisioning
data_store_summary_string = _get_vmware_datastore_summary_string(vmware=vmware)
storage_data = {
'storage': {
'controller': VMWARE_CONSTANTS['scsicontroller'],
'disks': [
{
'data_store': data_store_summary_string,
'data_store': get_vmware_datastore_summary_string,
'size': disk_size,
'thin_provision': True,
}
Expand Down
Loading