コード例 #1
0
def test_template_clone(request, appliance, provider, clone_vm_name):
    """
    Polarion:
        assignee: jhenner
        casecomponent: Provisioning
        initialEstimate: 1/6h
        caseimportance: high
    """
    cloned_template_name = provider.data['provisioning']['template']
    vm = appliance.collections.infra_templates.instantiate(cloned_template_name, provider)

    if provider.one_of(VMwareProvider):
        provision_type = 'VMware'
    else:
        provision_type = 'Native Clone'

    @request.addfinalizer
    def template_clone_cleanup():
        collections = appliance.collections
        if BZ(1797733).blocks:
            cloned_template = collections.infra_vms.instantiate(clone_vm_name, provider)
        else:
            cloned_template = collections.infra_templates.instantiate(clone_vm_name, provider)
        cloned_template.delete()

    vm.clone_template("*****@*****.**", "first", "last", clone_vm_name, provision_type)
    request_row = appliance.collections.requests.instantiate(clone_vm_name, partial_check=True)

    if not BZ(1797706).blocks and provider.one_of(RHEVMProvider):
        check_all_tabs(request_row, provider)
    request_row.wait_for_request(method='ui')
    msg = f"Request failed with the message {request_row.row.last_message.text}"
    assert request_row.is_succeeded(method='ui'), msg
コード例 #2
0
def test_provision_cloud_init_payload(appliance, request, setup_provider,
                                      provider: RHEVMProvider, provisioning,
                                      vm_name, address_mode):
    """
    Tests that options specified in VM provisioning dialog in UI are properly passed as a cloud-init
    payload to the newly provisioned VM.

    Metadata:
        test_flag: cloud_init, provision

    Polarion:
        assignee: jhenner
        initialEstimate: 1/4h
        casecomponent: Provisioning
    """
    image = provisioning.get('ci-image', None)
    if not image:
        pytest.skip('No ci-image found in provider specification.')
    note = (
        'Testing provisioning from image {image} to vm {vm} on provider {provider}'
        .format(image=image, vm=vm_name, provider=provider.key))
    logger.info(note)

    inst_args = {
        'request': {
            'notes': note
        },
        'customize': {
            'customize_type': 'Specification'
        },
        'template_name': image
    }

    inst_args['customize'].update(address_mode.payload)
    logger.info(f'Instance args: {inst_args}')

    # Provision VM
    collection = appliance.provider_based_collection(provider)
    instance: cfme.common.vm.VM = collection.create(vm_name,
                                                    provider,
                                                    form_values=inst_args)
    request.addfinalizer(
        lambda: instance.cleanup_on_provider(handle_cleanup_exception=False))

    provision_request = provider.appliance.collections.requests.instantiate(
        vm_name, partial_check=True)
    check_all_tabs(provision_request, provider)
    provision_request.wait_for_request()

    with address_mode.connect(provider, instance.mgmt) as ssh_client:
        address_mode.checks(ssh_client)
コード例 #3
0
def test_vm_clone(appliance, provider, clone_vm_name, create_vm):
    """
    Polarion:
        assignee: jhenner
        casecomponent: Provisioning
        initialEstimate: 1/6h
    """
    provision_type = 'VMware'
    create_vm.clone_vm("*****@*****.**", "first", "last", clone_vm_name, provision_type)
    request_description = clone_vm_name
    request_row = appliance.collections.requests.instantiate(request_description,
                                                             partial_check=True)
    check_all_tabs(request_row, provider)
    request_row.wait_for_request(method='ui')
    msg = f"Request failed with the message {request_row.row.last_message.text}"
    assert request_row.is_succeeded(method='ui'), msg
コード例 #4
0
def test_provision_cloud_init(appliance, request, setup_provider, provider,
                              provisioning, setup_ci_template, vm_name):
    """ Tests provisioning from a template with cloud_init

    Metadata:
        test_flag: cloud_init, provision

    Bugzilla:
        1619744
        1797706

    Polarion:
        assignee: jhenner
        initialEstimate: 1/4h
        casecomponent: Provisioning
    """
    image = provisioning.get('ci-image') or provisioning['image']['name']
    note = (
        'Testing provisioning from image {} to vm {} on provider {}'.format(
            image, vm_name, provider.key))
    logger.info(note)

    mgmt_system = provider.mgmt

    inst_args = {
        'request': {
            'notes': note
        },
        'customize': {
            'custom_template': {
                'name': provisioning['ci-template']
            }
        },
        'template_name': image  # for image selection in before_fill
    }

    # TODO Perhaps merge this with stuff in test_provisioning_dialog.prov_data
    if provider.one_of(AzureProvider):
        inst_args['environment'] = {'public_ip_address': "New"}
    if provider.one_of(OpenStackProvider):
        ip_pool = provider.data['public_network']
        floating_ip = mgmt_system.get_first_floating_ip(pool=ip_pool)
        provider.refresh_provider_relationships()
        inst_args['environment'] = {'public_ip_address': floating_ip}
        inst_arg_props = inst_args.setdefault('properties', {})
        inst_arg_props['instance_type'] = partial_match(
            provisioning['ci-flavor-name'])

    if provider.one_of(InfraProvider) and appliance.version > '5.9':
        inst_args['customize']['customize_type'] = 'Specification'

    logger.info(f'Instance args: {inst_args}')

    collection = appliance.provider_based_collection(provider)
    instance = collection.create(vm_name, provider, form_values=inst_args)

    request.addfinalizer(instance.cleanup_on_provider)
    provision_request = provider.appliance.collections.requests.instantiate(
        vm_name, partial_check=True)
    check_all_tabs(provision_request, provider)
    provision_request.wait_for_request()
    wait_for(lambda: instance.ip_address is not None, num_sec=600)
    connect_ip = instance.ip_address
    assert connect_ip, "VM has no IP"

    # Check that we can at least get the uptime via ssh this should only be possible
    # if the username and password have been set via the cloud-init script so
    # is a valid check
    with ssh.SSHClient(hostname=connect_ip,
                       username=provisioning['ci-username'],
                       password=provisioning['ci-pass']) as ssh_client:
        wait_for(ssh_client.uptime, num_sec=200, handle_exception=True)
コード例 #5
0
def test_provision_cloud_init_payload(appliance, request, setup_provider,
                                      provider, provisioning, vm_name):
    """
    Tests that options specified in VM provisioning dialog in UI are properly passed as a cloud-init
    payload to the newly provisioned VM.

    Metadata:
        test_flag: cloud_init, provision

    Polarion:
        assignee: jhenner
        initialEstimate: 1/4h
        casecomponent: Provisioning
    """
    image = provisioning.get('ci-image', None)
    if not image:
        pytest.skip('No ci-image found in provider specification.')
    note = (
        'Testing provisioning from image {image} to vm {vm} on provider {provider}'
        .format(image=image, vm=vm_name, provider=provider.key))
    logger.info(note)

    ci_payload = {
        'root_password': '******',
        'address_mode': 'Static',
        'hostname': 'cimachine',
        'ip_address': '169.254.0.1',
        'subnet_mask': '29',
        'gateway': '169.254.0.2',
        'dns_servers': '169.254.0.3',
        'dns_suffixes': 'virt.lab.example.com',
        'custom_template': {
            'name': 'oVirt cloud-init'
        }
    }

    inst_args = {
        'request': {
            'notes': note
        },
        'customize': {
            'customize_type': 'Specification'
        },
        'template_name': image
    }

    inst_args['customize'].update(ci_payload)
    logger.info(f'Instance args: {inst_args}')

    # Provision VM
    collection = appliance.provider_based_collection(provider)
    instance = collection.create(vm_name, provider, form_values=inst_args)
    request.addfinalizer(instance.cleanup_on_provider)
    provision_request = provider.appliance.collections.requests.instantiate(
        vm_name, partial_check=True)
    check_all_tabs(provision_request, provider)
    provision_request.wait_for_request()

    connect_ip = wait_for(find_global_ipv6,
                          func_args=[instance],
                          num_sec=600,
                          delay=20).out
    logger.info(f'Connect IP: {connect_ip}')

    # Connect to the newly provisioned VM
    with ssh.SSHClient(hostname=connect_ip,
                       username='******',
                       password=ci_payload['root_password']) as ssh_client:
        # Check that correct hostname has been set
        hostname_cmd = ssh_client.run_command('hostname')
        assert hostname_cmd.success
        assert hostname_cmd.output.strip() == ci_payload['hostname']

        # Obtain network configuration script for eth0 and store it in a list
        network_cfg_cmd = ssh_client.run_command(
            'cat /etc/sysconfig/network-scripts/ifcfg-eth0')
        assert network_cfg_cmd.success
        config_list = network_cfg_cmd.output.split('\n')

        # Compare contents of network script with cloud-init payload
        assert 'BOOTPROTO=none' in config_list, 'Address mode was not set to static'
        assert 'IPADDR={}'.format(ci_payload['ip_address']) in config_list
        assert 'PREFIX={}'.format(ci_payload['subnet_mask']) in config_list
        assert 'GATEWAY={}'.format(ci_payload['gateway']) in config_list
        assert 'DNS1={}'.format(ci_payload['dns_servers']) in config_list
        assert 'DOMAIN={}'.format(ci_payload['dns_suffixes']) in config_list