Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1157 from blrm/vm_power_distributed
Browse files Browse the repository at this point in the history
Added replication VM power control test
  • Loading branch information
dajohnso committed Jan 5, 2015
2 parents 5e880a7 + 38dfb9d commit b3a3c56
Showing 1 changed file with 104 additions and 33 deletions.
137 changes: 104 additions & 33 deletions cfme/tests/distributed/test_appliance_replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,48 @@
import cfme.web_ui.flash as flash
from cfme.configure import configuration as conf
from cfme.infrastructure.provider import wait_for_a_provider
from cfme.infrastructure.virtual_machines import Vm
import cfme.fixtures.pytest_selenium as sel
from time import sleep
from urlparse import urlparse
from utils import testgen, version
from utils.appliance import provision_appliance
from utils.conf import credentials
from utils.log import logger
from utils.ssh import SSHClient
from utils.providers import setup_provider
from utils.randomness import generate_random_string
from utils.wait import wait_for

pytest_generate_tests = testgen.generate(testgen.infra_providers, scope="module")
pytestmark = [pytest.mark.long_running]

random_provider = []
random_vm_test = []


def pytest_generate_tests(metafunc):
# Filter out providers without provisioning data or hosts defined
argnames, argvalues, idlist = testgen.infra_providers(metafunc)
argnames, argvalues, idlist = testgen.provider_by_type(
metafunc, ['virtualcenter'], choose_random=True)
if not idlist:
return
new_idlist = []
new_argvalues = []
if 'random_provider' in metafunc.fixturenames:
if random_provider:
argnames, new_argvalues, new_idlist = random_provider
if 'random_pwr_ctl_vm' in metafunc.fixturenames:
if random_vm_test:
argnames, new_argvalues, new_idlist = random_vm_test
else:
single_index = random.choice(range(len(idlist)))
new_idlist = ['random_provider']
new_argvalues = argvalues[single_index]
argnames.append('random_provider')
argnames.append('random_pwr_ctl_vm')
new_argvalues.append('')
new_argvalues = [new_argvalues]
random_provider.append(argnames)
random_provider.append(new_argvalues)
random_provider.append(new_idlist)
random_vm_test.append(argnames)
random_vm_test.append(new_argvalues)
random_vm_test.append(new_idlist)
else:
new_idlist = idlist
new_argvalues = argvalues
testgen.parametrize(metafunc, argnames, new_argvalues, ids=new_idlist, scope="module")
metafunc.parametrize(argnames, argvalues, ids=idlist, scope='module')


def get_ssh_client(hostname):
Expand Down Expand Up @@ -76,8 +80,8 @@ def get_replication_appliances():
appl1 = provision_appliance(ver_to_prov, 'test_repl_A')
appl2 = provision_appliance(ver_to_prov, 'test_repl_B')
appl1.configure(region=1, patch_ajax_wait=False)
appl2.configure(region=2, patch_ajax_wait=False, key_address=appl1.address)
appl1.ipapp.wait_for_web_ui()
appl2.configure(region=2, patch_ajax_wait=False, key_address=appl1.address)
appl2.ipapp.wait_for_web_ui()
return (appl1, appl2)

Expand All @@ -98,9 +102,38 @@ def configure_db_replication(db_address):
num_sec=120, delay=10, fail_func=sel.refresh)


@pytest.mark.usefixtures("random_provider")
@pytest.fixture
def provider_init(provider_key):
"""cfme/infrastructure/provider.py provider object."""
try:
setup_provider(provider_key)
except Exception:
pytest.skip("It's not possible to set up this provider, therefore skipping")


@pytest.fixture(scope="module")
def vm_name():
return "test_repl_pwrctl_" + generate_random_string()


@pytest.fixture(scope="class")
def test_vm(request, provider_crud, provider_mgmt, vm_name):
"""Fixture to provision appliance to the provider being tested if necessary"""
vm = Vm(vm_name, provider_crud)

request.addfinalizer(vm.delete_from_provider)

if not provider_mgmt.does_vm_exist(vm_name):
logger.info("deploying {} on provider {}".format(vm_name, provider_crud.key))
vm.create_on_provider()
else:
logger.info("recycling deployed vm {} on provider {}".format(vm_name, provider_crud.key))
vm.provider_crud.refresh_provider_relationships()
vm.wait_to_appear()
return vm


@pytest.mark.ignore_stream("upstream")
@pytest.mark.long_running
def test_appliance_replicate_between_regions(request, provider_crud):
"""Tests that a provider added to an appliance in one region
is replicated to the parent appliance in another region.
Expand All @@ -111,27 +144,28 @@ def finalize():
appl1.destroy()
appl2.destroy()
request.addfinalizer(finalize)
with appl1.browser_session():
appl1.ipapp.browser_steal = True
with appl1.ipapp:
configure_db_replication(appl2.address)
provider_crud.create()
wait_for_a_provider()

with appl2.browser_session():
appl2.ipapp.browser_steal = True
with appl2.ipapp:
wait_for_a_provider()
assert provider_crud.exists


@pytest.mark.usefixtures("random_provider")
@pytest.mark.ignore_stream("upstream")
@pytest.mark.long_running
def test_appliance_replicate_sync_role_change(request, provider_crud):
appl1, appl2 = get_replication_appliances()

def finalize():
appl1.destroy()
appl2.destroy()
request.addfinalizer(finalize)
with appl1.browser_session():
appl1.ipapp.browser_steal = True
with appl1.ipapp:
configure_db_replication(appl2.address)
# Replication is up and running, now disable DB sync role
conf.set_server_roles(database_synchronization=False)
Expand All @@ -146,22 +180,22 @@ def finalize():
provider_crud.create()
wait_for_a_provider()

with appl2.browser_session():
appl2.ipapp.browser_steal = True
with appl2.ipapp:
wait_for_a_provider()
assert provider_crud.exists


@pytest.mark.usefixtures("random_provider")
@pytest.mark.ignore_stream("upstream")
@pytest.mark.long_running
def test_appliance_replicate_sync_role_change_with_backlog(request, provider_crud):
appl1, appl2 = get_replication_appliances()

def finalize():
appl1.destroy()
appl2.destroy()
request.addfinalizer(finalize)
with appl1.browser_session():
appl1.ipapp.browser_steal = True
with appl1.ipapp:
configure_db_replication(appl2.address)
# Replication is up and running, now disable DB sync role
provider_crud.create()
Expand All @@ -176,22 +210,22 @@ def finalize():
assert conf.get_replication_status()
wait_for_a_provider()

with appl2.browser_session():
appl2.ipapp.browser_steal = True
with appl2.ipapp:
wait_for_a_provider()
assert provider_crud.exists


@pytest.mark.usefixtures("random_provider")
@pytest.mark.ignore_stream("upstream")
@pytest.mark.long_running
def test_appliance_replicate_database_disconnection(request, provider_crud):
appl1, appl2 = get_replication_appliances()

def finalize():
appl1.destroy()
appl2.destroy()
request.addfinalizer(finalize)
with appl1.browser_session():
appl1.ipapp.browser_steal = True
with appl1.ipapp:
configure_db_replication(appl2.address)
# Replication is up and running, now stop the DB on the replication parent
stop_db_process(appl2.address)
Expand All @@ -204,22 +238,22 @@ def finalize():
provider_crud.create()
wait_for_a_provider()

with appl2.browser_session():
appl2.ipapp.browser_steal = True
with appl2.ipapp:
wait_for_a_provider()
assert provider_crud.exists


@pytest.mark.usefixtures("random_provider")
@pytest.mark.ignore_stream("upstream")
@pytest.mark.long_running
def test_appliance_replicate_database_disconnection_with_backlog(request, provider_crud):
appl1, appl2 = get_replication_appliances()

def finalize():
appl1.destroy()
appl2.destroy()
request.addfinalizer(finalize)
with appl1.browser_session():
appl1.ipapp.browser_steal = True
with appl1.ipapp:
configure_db_replication(appl2.address)
# Replication is up and running, now stop the DB on the replication parent
provider_crud.create()
Expand All @@ -232,6 +266,43 @@ def finalize():
assert conf.get_replication_status()
wait_for_a_provider()

with appl2.browser_session():
appl2.ipapp.browser_steal = True
with appl2.ipapp:
wait_for_a_provider()
assert provider_crud.exists


@pytest.mark.usefixtures("random_pwr_ctl_vm")
@pytest.mark.usefixtures("provider_init")
@pytest.mark.ignore_stream("upstream")
def test_distributed_vm_power_control(request, test_vm, provider_crud,
verify_vm_running, register_event, soft_assert):
"""Tests that a replication parent appliance can control the power state of a
VM being managed by a replication child appliance.
"""
appl1, appl2 = get_replication_appliances()

def finalize():
appl1.destroy()
appl2.destroy()
request.addfinalizer(finalize)
appl1.ipapp.browser_steal = True
with appl1.ipapp:
configure_db_replication(appl2.address)
provider_crud.create()
wait_for_a_provider()

appl2.ipapp.browser_steal = True
with appl2.ipapp:
register_event(
test_vm.provider_crud.get_yaml_data()['type'],
"vm", test_vm.name, ["vm_power_off_req", "vm_power_off"])
test_vm.power_control_from_cfme(option=Vm.POWER_OFF, cancel=False)
flash.assert_message_contain("Stop initiated")
pytest.sel.force_navigate(
'infrastructure_provider', context={'provider': test_vm.provider_crud})
test_vm.wait_for_vm_state_change(desired_state=Vm.STATE_OFF, timeout=900)
soft_assert(test_vm.find_quadicon().state == 'currentstate-off')
soft_assert(
not test_vm.provider_crud.get_mgmt_system().is_vm_running(test_vm.name),
"vm running")

0 comments on commit b3a3c56

Please sign in to comment.