def migrate_vm(all_hosts_hostnames, ansible_by_hostname, system_service):
    vm_service = test_utils.get_vm_service(system_service, VM0_NAME)
    vm_id = vm_service.get().id
    hosts_service = system_service.hosts_service()

    def _current_running_host():
        host_id = vm_service.get().host.id
        host = hosts_service.list(search='id={}'.format(host_id))[0]
        return host.name

    src_host = _current_running_host()
    dst_host = next(iter(all_hosts_hostnames - {src_host}))

    LOGGER.debug('source host: {}'.format(src_host))
    LOGGER.debug('destination host: {}'.format(dst_host))

    correlation_id = uuid.uuid4()
    vm_service.migrate(host=Host(name=dst_host), query={'correlation_id': correlation_id})
    assert assert_utils.true_within_long(lambda: test_utils.all_jobs_finished(system_service, correlation_id))

    # Verify that VDSM cleaned the vm in the source host
    def vm_is_not_on_host():
        ansible_src_host = ansible_by_hostname(src_host)
        out = ansible_src_host.shell('vdsm-client Host getVMList')["stdout"]
        vms = json.loads(out)
        return vm_id not in [vm["vmId"] for vm in vms]

    assert assert_utils.true_within_short(vm_is_not_on_host)

    assert assert_utils.equals_within_short(lambda: vm_service.get().status, VmStatus.UP)

    assert _current_running_host() == dst_host
Beispiel #2
0
def test_clear_global_maintenance(ansible_host0):
    logging.info('Waiting For System Stability...')
    he_utils.wait_until_engine_vm_is_not_migrating(ansible_host0)

    he_utils.set_and_test_global_maintenance_mode(ansible_host0, False)

    assert assert_utils.true_within_long(lambda: he_utils.no_hosts_state_global_maintenance(ansible_host0))
    logging.info('Global maintenance state cleared on all hosts')
Beispiel #3
0
def _restart_services(ansible_host):
    logging.info('Stopping services...')
    ansible_host.shell('systemctl stop vdsmd supervdsmd ovirt-ha-broker ovirt-ha-agent')

    logging.info('Starting services...')
    ansible_host.shell('systemctl start vdsmd supervdsmd ovirt-ha-broker ovirt-ha-agent')

    logging.info('Waiting for agent to be ready...')
    assert assert_utils.true_within_long(lambda: _ha_agent_is_ready(ansible_host))
    logging.info('Agent is ready.')
Beispiel #4
0
def _shutdown_he_vm(ansible_host):
    ansible_host.shell('hosted-engine --vm-shutdown')
    logging.info('Waiting for the engine VM to be down...')
    assert assert_utils.true_within_long(lambda: he_utils.engine_vm_is_down(ansible_host))
Beispiel #5
0
def wait_until_engine_vm_is_not_migrating(ansible_host):
    assert assert_utils.true_within_long(
        lambda: not engine_vm_is_migrating(ansible_host))
def test_local_maintenance(hosts_service, get_vm_service_for_vm,
                           ansible_host0):
    logging.info('Waiting For System Stability...')
    he_utils.wait_until_engine_vm_is_not_migrating(ansible_host0)

    vm_service = get_vm_service_for_vm(VM_HE_NAME)
    he_host_id = vm_service.get().host.id
    host_service = hosts_service.host_service(id=he_host_id)
    host_name = host_service.get().name

    logging.info(f'Performing Deactivation on {host_name}...')

    def _do_deactivate():
        logging.debug(f'Trying to deactivate host {host_name}')
        try:
            host_service.deactivate()
        except ovirtsdk4.Error:
            return False
        return True

    assert assert_utils.true_within_short(_do_deactivate)

    def _is_in_maintenance():
        logging.debug(f'Checking if host {host_name} is in maintenance')
        status = host_service.get().status
        hosted_engine = host_service.get(all_content=True).hosted_engine
        logging.debug(f'status={status}')
        logging.debug(f'hosted_engine={_hosted_engine_info(hosted_engine)}')
        # Original test was:
        #   (
        #       status == types.HostStatus.MAINTENANCE or
        #       hosted_engine.local_maintenance
        #   )
        # But this does not test local_maintenance (presumably the "local
        # maintenance" status as reported by the HA daemons?).
        # So I tried to change the "or" to "and" (require both), and it
        # never happened - local_maintenance always remained False.
        # Giving up on this for now and checking only status.
        # TODO: Find out why, fix what's needed, change the code to require
        # both. Also for do_verified_activation below.
        return status == types.HostStatus.MAINTENANCE

    assert assert_utils.true_within_long(_is_in_maintenance)

    logging.info('Performing Activation...')

    def _do_activate():
        logging.debug(f'Trying to activate host {host_name}')
        try:
            host_service.activate()
        except ovirtsdk4.Error:
            return False
        return True

    assert assert_utils.true_within_short(_do_activate)

    def _is_active():
        logging.info(f'Checking if host {host_name} is active')
        status = host_service.get().status
        hosted_engine = host_service.get(all_content=True).hosted_engine
        logging.debug(f'status={status}')
        logging.debug(f'hosted_engine={_hosted_engine_info(hosted_engine)}')
        # TODO See comment above
        return status == types.HostStatus.UP

    assert assert_utils.true_within_long(_is_active)

    logging.info('Verifying that all hosts have score higher than 0...')
    assert assert_utils.true_within_long(
        lambda: host_service.get(all_content=True).hosted_engine.score > 0)

    logging.info('Validating Migration...')
    prev_host_id = he_host_id
    he_host_id = vm_service.get().host.id
    assert prev_host_id != he_host_id