Esempio n. 1
0
def copy_instance(request, copy_domain):
    miq_domain = Domain(name="ManageIQ (Locked)", enabled=True)
    instance = Instance(name="InspectMe",
                        cls=Class(name="Request",
                                  namespace=Namespace(name="System",
                                                      parent=miq_domain)))
    instance.copy_to(copy_domain)
def copy_instance(request, copy_domain):
    miq_domain = Domain(name="ManageIQ (Locked)", enabled=True)
    instance = Instance(
        name="InspectMe",
        cls=Class(
            name="Request",
            namespace=Namespace(
                name="System",
                parent=miq_domain
            )
        )
    )
    instance.copy_to(copy_domain)
Esempio n. 3
0
def test_create_snapshot_via_ae(request, domain, test_vm):
    """This test checks whether the vm.create_snapshot works in AE.

    Prerequisities:
        * A VMware provider
        * A VM that has been discovered by CFME

    Steps:
        * Clone the Request class inside the System namespace into a new domain
        * Add a method named ``snapshot`` and insert the provided code there.
        * Add an instance named ``snapshot`` and set the methd from previous step
            as ``meth5``
        * Run the simulation of the method against the VM, preferably setting
            ``snap_name`` to something that can be checked
        * Wait until snapshot with such name appears.
    """
    # PREPARE
    file = data_path.join("ui").join("automate").join(
        "test_create_snapshot_via_ae.rb")
    with file.open("r") as f:
        method_contents = f.read()
    miq_domain = Domain("ManageIQ (Locked)")
    miq_class = Class("Request",
                      namespace=Namespace("System", domain=miq_domain))
    request_cls = miq_class.copy_to(domain)
    request.addfinalizer(request_cls.delete)
    method = Method("snapshot", data=method_contents, cls=request_cls)
    method.create()
    request.addfinalizer(method.delete)
    instance = Instance("snapshot",
                        values={"meth5": "snapshot"},
                        cls=request_cls)
    instance.create()
    request.addfinalizer(instance.delete)

    # SIMULATE
    snap_name = fauxfactory.gen_alpha()
    snapshot = Vm.Snapshot(name=snap_name, parent_vm=test_vm)
    simulate(instance="Request",
             request="snapshot",
             attribute=["VM and Instance", test_vm.name],
             execute_methods=True,
             avp={"snap_name": snap_name})

    wait_for(snapshot.does_snapshot_exist, timeout="2m", delay=10)

    # Clean up if it appeared
    snapshot.delete()
Esempio n. 4
0
def test_create_snapshot_via_ae(request, domain, test_vm):
    """This test checks whether the vm.create_snapshot works in AE.

    Prerequisities:
        * A VMware provider
        * A VM that has been discovered by CFME

    Steps:
        * Clone the Request class inside the System namespace into a new domain
        * Add a method named ``snapshot`` and insert the provided code there.
        * Add an instance named ``snapshot`` and set the methd from previous step
            as ``meth5``
        * Run the simulation of the method against the VM, preferably setting
            ``snap_name`` to something that can be checked
        * Wait until snapshot with such name appears.
    """
    # PREPARE
    file = data_path.join("ui").join("automate").join("test_create_snapshot_via_ae.rb")
    with file.open("r") as f:
        method_contents = f.read()
    miq_domain = Domain("ManageIQ (Locked)")
    miq_class = Class("Request", namespace=Namespace("System", domain=miq_domain))
    request_cls = miq_class.copy_to(domain)
    request.addfinalizer(request_cls.delete)
    method = Method("snapshot", data=method_contents, cls=request_cls)
    method.create()
    request.addfinalizer(method.delete)
    instance = Instance("snapshot", values={"meth5": "snapshot"}, cls=request_cls)
    instance.create()
    request.addfinalizer(instance.delete)

    # SIMULATE
    snap_name = fauxfactory.gen_alpha()
    snapshot = Vm.Snapshot(name=snap_name, parent_vm=test_vm)
    simulate(
        instance="Request",
        request="snapshot",
        attribute=["VM and Instance", test_vm.name],
        execute_methods=True,
        avp={"snap_name": snap_name},
    )

    wait_for(snapshot.does_snapshot_exist, timeout="2m", delay=10)

    # Clean up if it appeared
    snapshot.delete()
Esempio n. 5
0
def original_instance(request, original_method, original_domain):
    instance = Instance(
        name=fauxfactory.gen_alphanumeric(),
        values={
            "meth5": {
                "value": original_method.name
            }
        },
        cls=Class(
            name="Request",
            namespace=Namespace(
                name="System",
                parent=original_domain
            ),
            setup_schema=[Class.SchemaField(name="meth5",
                                            type_="Method")]
        )
    )
    instance.create()
    request.addfinalizer(lambda: instance.delete() if instance.exists() else None)
    return instance
def original_instance(request, original_method):
    if not Domain.default.is_enabled:
        with update(Domain.default):
            Domain.default.enabled = True
    instance = Instance(
        name=generate_random_string(),
        values={
            "meth5": {
                "value": original_method.name
            }
        },
        cls=Class(
            name="Request",
            namespace=Namespace(
                name="System",
                parent=Domain.default
            )
        )
    )
    instance.create()
    request.addfinalizer(lambda: instance.delete() if instance.exists() else None)
    return instance
Esempio n. 7
0
def original_instance(request, original_method, original_domain, original_class):
    instance = Instance(
        name=fauxfactory.gen_alphanumeric(),
        values={
            "meth5": {
                "value": original_method.name
            }
        },
        cls=original_class,
    )
    instance.create()
    request.addfinalizer(lambda: instance.delete() if instance.exists() else None)
    return instance
def original_instance(request, original_method, original_domain):
    instance = Instance(name=fauxfactory.gen_alphanumeric(),
                        values={"meth5": {
                            "value": original_method.name
                        }},
                        cls=Class(name="Request",
                                  namespace=Namespace(name="System",
                                                      parent=original_domain),
                                  setup_schema=[
                                      Class.SchemaField(name="meth5",
                                                        type_="Method")
                                  ]))
    instance.create()
    request.addfinalizer(lambda: instance.delete()
                         if instance.exists() else None)
    return instance
Esempio n. 9
0
def setup_for_event_testing(ssh_client, db, listener_info, providers):
    domain_name = "EventTesting"
    domain = Domain(name=domain_name, enabled=True)
    if not domain.exists():
        domain.create()

    # FIX THE ENV ERROR IF PRESENT
    if ssh_client.run_command("ruby -v")[0] != 0:
        logger.info("Pathing env to correctly source EVM environment")
        success = ssh_client.run_command("echo 'source /etc/default/evm' >> .bashrc")[0] == 0
        assert success, "Issuing the patch command was unsuccessful"
        # Verify it works
        assert ssh_client.run_command("ruby -v")[0] == 0, "Patch failed"

    # INSTALL REST-CLIENT - REQUIRED FOR THE EVENT DISPATCHER SCRIPT
    if ssh_client.run_rails_command("\"require 'rest-client'\"")[0] != 0:
        # We have to install the gem
        logger.info("Installing rest-client ruby gem that is required by the event dispatcher.")
        success = ssh_client.run_command("gem install rest-client")[0] == 0
        assert success, "Could not install 'rest-client' gem"
        # Verify it works
        assert ssh_client.run_rails_command("\"require 'rest-client'\"")[0] == 0

    # IMPORT AUTOMATE NAMESPACE
    qe_automate_namespace_xml = "qe_event_handler.xml"
    qe_automate_namespace_script = "qe_event_handler.rb"
    local_automate_script = local(__file__)\
        .new(basename="../data/{}".format(qe_automate_namespace_script))\
        .strpath
    local_automate_file = local(__file__)\
        .new(basename="../data/{}".format(qe_automate_namespace_xml))\
        .strpath
    tmp_automate_file = "/tmp/{}".format(qe_automate_namespace_xml)

    # Change the information
    with open(local_automate_file, "r") as input_xml, \
            open(tmp_automate_file, "w") as output_xml:
        tree = etree.parse(input_xml)
        root = tree.getroot()

        def set_text(xpath, text):
            field = root.xpath(xpath)
            assert len(field) == 1
            field[0].text = text
        set_text("//MiqAeSchema/MiqAeField[@name='url']",
                 re.sub(r"^http://([^/]+)/?$", "\\1", listener_info.host))
        set_text("//MiqAeSchema/MiqAeField[@name='port']", str(listener_info.port))

        # Put the custom script from an external file
        with open(local_automate_script, "r") as script:
            set_text("//MiqAeMethod[@name='relay_events']",
                     etree.CDATA(script.read()))

        et = etree.ElementTree(root)
        et.write(output_xml)

    # copy xml file to appliance
    # but before that, let's check whether it's there because we may have already applied this file
    if ssh_client.run_command("ls /root/{}".format(qe_automate_namespace_xml))[0] != 0:
        ssh_client.put_file(tmp_automate_file, '/root/')

        # We have to convert it first for new version
        convert_cmd = version.pick({
            version.LOWEST: None,

            "5.3.0.0":
            "evm:automate:convert DOMAIN={} FILE=/root/{} ZIP_FILE=/root/{}.zip".format(
                domain_name, qe_automate_namespace_xml, qe_automate_namespace_xml),
        })
        if convert_cmd is not None:
            logger.info("Converting namespace for use on newer appliance...")
            return_code, stdout = ssh_client.run_rake_command(convert_cmd)
            if return_code != 0:
                logger.error("Namespace conversion was unsuccessful")
                logger.error(stdout)
                # We didn't successfully do that so remove the file to know
                # that it's needed to do it again when run again
                ssh_client.run_command("rm -f /root/{}*".format(qe_automate_namespace_xml))
                raise AutomateImportError(stdout)

        # run rake cmd on appliance to import automate namespace
        rake_cmd = version.pick({
            version.LOWEST: "evm:automate:import FILE=/root/{}".format(qe_automate_namespace_xml),

            "5.3.0.0":
            "evm:automate:import ZIP_FILE=/root/{}.zip DOMAIN={} OVERWRITE=true "
            "PREVIEW=false".format(qe_automate_namespace_xml, domain_name),
        })
        logger.info("Importing the QE Automation namespace ...")
        return_code, stdout = ssh_client.run_rake_command(rake_cmd)
        if return_code != 0:
            logger.error("Namespace import was unsuccessful")
            logger.error(stdout)
            # We didn't successfully do that so remove the file to know
            # that it's needed to do it again when run again
            ssh_client.run_command("rm -f /root/{}*".format(qe_automate_namespace_xml))
            raise AutomateImportError(stdout)

    # CREATE AUTOMATE INSTANCE HOOK
    if db is None or db.session.query(db['miq_ae_instances'].name)\
            .filter(db['miq_ae_instances'].name == "RelayEvents").count() == 0:
        original_class = Class(
            name=version.pick({
                version.LOWEST: "Automation Requests (Request)",
                "5.3": "Request"
            }),
            namespace=Namespace("System", domain=Domain("ManageIQ (Locked)")))
        copied_class = original_class.copy_to(domain)
        instance = Instance(
            name="RelayEvents",
            display_name="RelayEvents",
            description="relationship hook to link to custom QE events relay namespace",
            values={
                "rel2": {
                    "value": "/QE/Automation/APIMethods/relay_events?event=$evm.object['event']"
                }
            },
            cls=copied_class,
        )
        instance.create()

    # IMPORT POLICIES
    policy_yaml = "profile_relay_events.yaml"
    policy_path = local(__file__).new(basename="../data/{}".format(policy_yaml))
    if not is_imported("Automate event policies"):
        import_file(policy_path.strpath)

    # ASSIGN POLICY PROFILES
    for provider in providers:
        prov_obj = get_crud(provider)
        if not prov_obj.exists:
            prov_obj.create()
        prov_obj.assign_policy_profiles("Automate event policies")
        flash.assert_no_errors()
Esempio n. 10
0
def setup_for_event_testing(ssh_client, db, listener_info, providers):
    # FIX THE ENV ERROR IF PRESENT
    if ssh_client.run_command("ruby -v")[0] != 0:
        success = ssh_client.run_command("echo 'source /etc/default/evm' >> .bashrc")[0] == 0
        assert success, "Issuing the patch command was unsuccessful"
        # Verify it works
        assert ssh_client.run_command("ruby -v")[0] == 0, "Patch failed"

    # IMPORT AUTOMATE NAMESPACE
    qe_automate_namespace_xml = "qe_event_handler.xml"
    qe_automate_namespace_script = "qe_event_handler.rb"
    local_automate_script = local(__file__)\
        .new(basename="../data/%s" % qe_automate_namespace_script)\
        .strpath
    local_automate_file = local(__file__)\
        .new(basename="../data/%s" % qe_automate_namespace_xml)\
        .strpath
    tmp_automate_file = "/tmp/%s" % qe_automate_namespace_xml

    # Change the information
    with open(local_automate_file, "r") as input_xml, \
            open(tmp_automate_file, "w") as output_xml:
        tree = etree.parse(input_xml)
        root = tree.getroot()

        def set_text(xpath, text):
            field = root.xpath(xpath)
            assert len(field) == 1
            field[0].text = text
        set_text("//MiqAeSchema/MiqAeField[@name='url']",
                 re.sub(r"^http://([^/]+)/?$", "\\1", listener_info.host))
        set_text("//MiqAeSchema/MiqAeField[@name='port']", str(listener_info.port))

        # Put the custom script from an external file
        with open(local_automate_script, "r") as script:
            set_text("//MiqAeMethod[@name='relay_events']",
                     etree.CDATA(script.read()))

        et = etree.ElementTree(root)
        et.write(output_xml)

    # copy xml file to appliance
    # but before that, let's check whether it's there because we may have already applied this file
    if ssh_client.run_command("ls /root/%s" % qe_automate_namespace_xml)[0] != 0:
        ssh_client.put_file(tmp_automate_file, '/root/')

        # We have to convert it first for new version
        convert_cmd = version.pick({
            "default": None,

            "5.3.0.0":
            "evm:automate:convert DOMAIN=Default FILE=/root/{} ZIP_FILE=/root/{}.zip".format(
                qe_automate_namespace_xml, qe_automate_namespace_xml),
        })
        if convert_cmd is not None:
            logger.info("Converting namespace for use on newer appliance...")
            return_code, stdout = ssh_client.run_rake_command(convert_cmd)
            if return_code != 0:
                logger.error("Namespace conversion was unsuccessful")
                logger.error(stdout)
                # We didn't successfully do that so remove the file to know
                # that it's needed to do it again when run again
                ssh_client.run_command("rm -f /root/%s*" % qe_automate_namespace_xml)
                raise AutomateImportError(stdout)

        # run rake cmd on appliance to import automate namespace
        rake_cmd = version.pick({
            "default": "evm:automate:import FILE=/root/{}".format(qe_automate_namespace_xml),

            "5.3.0.0":
            "evm:automate:import ZIP_FILE=/root/{}.zip DOMAIN=Default OVERWRITE=true "
            "PREVIEW=false".format(qe_automate_namespace_xml),
        })
        logger.info("Importing the QE Automation namespace ...")
        return_code, stdout = ssh_client.run_rake_command(rake_cmd)
        if return_code != 0:
            logger.error("Namespace import was unsuccessful")
            logger.error(stdout)
            # We didn't successfully do that so remove the file to know
            # that it's needed to do it again when run again
            ssh_client.run_command("rm -f /root/%s*" % qe_automate_namespace_xml)
            raise AutomateImportError(stdout)

    # CREATE AUTOMATE INSTANCE HOOK
    if db is None or db.session.query(db['miq_ae_instances'].name)\
            .filter(db['miq_ae_instances'].name == "RelayEvents").count() == 0:
        # Check presence
        instance = Instance(
            name="RelayEvents",
            display_name="RelayEvents",
            description="relationship hook to link to custom QE events relay namespace",
            values={
                "rel2": {
                    "value": "/QE/Automation/APIMethods/relay_events?event=$evm.object['event']"
                }
            },
            cls=Class(name="Automation Requests (Request)", namespace=Namespace("System"))
        )
        instance.create()

    # IMPORT POLICIES
    policy_yaml = "profile_relay_events.yaml"
    policy_path = local(__file__).new(basename="../data/%s" % policy_yaml)
    if not is_imported("Automate event policies"):
        import_file(policy_path.strpath)

    # ASSIGN POLICY PROFILES
    for provider in providers:
        prov_obj = get_from_config(provider)
        prov_obj.assign_policy_profiles("Automate event policies")
        flash.assert_no_errors()
Esempio n. 11
0
def test_vmware_vimapi_hotadd_disk(request, testing_group, provider,
                                   testing_vm, domain, cls):
    """ Tests hot adding a disk to vmware vm.

    This test exercises the ``VMware_HotAdd_Disk`` method, located in ``/Integration/VMware/VimApi``

    Steps:
        * It creates an instance in ``System/Request`` that can be accessible from eg. a button.
        * Then it creates a service dialog that contains a field with the desired disk size, the
            text field name should be ``size``
        * Then it creates a button, that refers to the ``VMware_HotAdd_Disk`` in ``Request``. The
            button shall belong in the VM and instance button group.
        * After the button is created, it goes to a VM's summary page, clicks the button, enters
            the size of the disk and submits the dialog.
        * The test waits until the number of disks is raised.

    Metadata:
        test_flag: hotdisk, provision
    """
    meth = Method(name='parse_dialog_value_{}'.format(fauxfactory.gen_alpha()),
                  data=dedent('''\
            # Transfers the dialog value to the root so the VMware method can use it.

            $evm.root['size'] = $evm.object['dialog_size']
            exit MIQ_OK
            '''),
                  cls=cls)

    @request.addfinalizer
    def _remove_method():
        if meth.exists():
            meth.delete()

    meth.create()

    # Instance that calls the method and is accessible from the button
    instance = Instance(
        name="VMware_HotAdd_Disk_{}".format(fauxfactory.gen_alpha()),
        values={
            "meth4": {
                'on_entry': meth.name
            },  # To preparse the value
            "rel5": "/Integration/VMware/VimApi/VMware_HotAdd_Disk",
        },
        cls=cls)

    @request.addfinalizer
    def _remove_instance():
        if instance.exists():
            instance.delete()

    instance.create()
    # Dialog to put the disk capacity
    element_data = {
        'ele_label': "Disk size",
        'ele_name': "size",
        'ele_desc': "Disk size",
        'choose_type': "Text Box",
        'default_text_box': "Default text"
    }
    dialog = ServiceDialog(
        label=fauxfactory.gen_alphanumeric(),
        description=fauxfactory.gen_alphanumeric(),
        submit=True,
        tab_label=fauxfactory.gen_alphanumeric(),
        tab_desc=fauxfactory.gen_alphanumeric(),
        box_label=fauxfactory.gen_alphanumeric(),
        box_desc=fauxfactory.gen_alphanumeric(),
    )
    dialog.create(element_data)
    request.addfinalizer(dialog.delete)
    # Button that will invoke the dialog and action
    button_name = fauxfactory.gen_alphanumeric()
    button = Button(group=testing_group,
                    text=button_name,
                    hover=button_name,
                    dialog=dialog,
                    system="Request",
                    request=instance.name)
    request.addfinalizer(button.delete_if_exists)
    button.create()

    def _get_disk_count():
        return int(
            testing_vm.get_detail(properties=("Datastore Allocation Summary",
                                              "Number of Disks")).strip())

    original_disk_count = _get_disk_count()
    logger.info('Initial disk count: {}'.format(original_disk_count))
    toolbar.select(testing_group.text, button.text)
    fill(Input("size"), '1')
    pytest.sel.click(submit)
    flash.assert_no_errors()
    try:
        wait_for(lambda: original_disk_count + 1 == _get_disk_count(),
                 num_sec=180,
                 delay=5)
    finally:
        logger.info('End disk count: {}'.format(_get_disk_count()))
def test_vmware_vimapi_hotadd_disk(
        request, testing_group, provider, testing_vm, domain, namespace, cls):
    """ Tests hot adding a disk to vmware vm.

    This test exercises the ``VMware_HotAdd_Disk`` method, located either in
    ``/Integration/VimApi/`` (<5.3) or ``/Integration/VMware/VimApi`` (5.3 and up).

    Steps:
        * It creates an instance in ``System/Request`` that can be accessible from eg. a button.
        * Then it creates a service dialog that contains a field with the desired disk size, the
            text field name should be ``size``
        * Then it creates a button, that refers to the ``VMware_HotAdd_Disk`` in ``Request``. The
            button shall belong in the VM and instance button group.
        * After the button is created, it goes to a VM's summary page, clicks the button, enters
            the size of the disk and submits the dialog.
        * The test waits until the number of disks is raised.

    Metadata:
        test_flag: hotdisk, provision
    """
    # Instance that calls the method and is accessible from the button
    if current_version() < "5.3":
        rel = "/Integration/VimApi/VMware_HotAdd_Disk"
    else:
        rel = "/Integration/VMware/VimApi/VMware_HotAdd_Disk"
    instance = Instance(
        name="VMware_HotAdd_Disk",
        values={
            "rel5": rel,
        },
        cls=cls
    )
    if not instance.exists():
        request.addfinalizer(lambda: instance.delete() if instance.exists() else None)
        instance.create()
    # Dialog to put the disk capacity
    return
    element_data = {
        'ele_label': "Disk size",
        'ele_name': "size",
        'ele_desc': "Disk size",
        'choose_type': "Text Box",
        'default_text_box': "Default text"
    }
    dialog = ServiceDialog(
        label=fauxfactory.gen_alphanumeric(),
        description=fauxfactory.gen_alphanumeric(),
        submit=True,
        tab_label=fauxfactory.gen_alphanumeric(),
        tab_desc=fauxfactory.gen_alphanumeric(),
        box_label=fauxfactory.gen_alphanumeric(),
        box_desc=fauxfactory.gen_alphanumeric(),
    )
    dialog.create(element_data)
    request.addfinalizer(lambda: dialog.delete())
    # Button that will invoke the dialog and action
    button_name = fauxfactory.gen_alphanumeric()
    button = Button(group=testing_group,
                    text=button_name,
                    hover=button_name,
                    dialog=dialog, system="Request", request="VMware_HotAdd_Disk")
    request.addfinalizer(button.delete_if_exists)
    button.create()
    # Now do the funny stuff

    def _get_disk_count():
        return int(testing_vm.get_detail(
            properties=("Datastore Allocation Summary", "Number of Disks")).strip())
    original_disk_count = _get_disk_count()
    toolbar.select(testing_group.text, button.text)
    fill(Input("size"), "1")
    pytest.sel.click(submit)
    flash.assert_no_errors()
    wait_for(lambda: original_disk_count + 1 == _get_disk_count(), num_sec=180, delay=5)
Esempio n. 13
0
def an_instance(a_class):
    return Instance(name=generate_random_string(8),
                    description=generate_random_string(32),
                    cls=a_class)
Esempio n. 14
0
def an_instance(cls=None, request=None):
    if not cls:
        cls = make_class(request=request)
    return Instance(name=fauxfactory.gen_alphanumeric(8),
                    description=fauxfactory.gen_alphanumeric(32),
                    cls=cls)
Esempio n. 15
0
def test_vmware_vimapi_hotadd_disk(
        request, testing_group, provider_crud, provider_mgmt, testing_vm, domain, namespace, cls):
    """ Tests hot adding a disk to vmware vm

    Metadata:
        test_flag: hotdisk, provision
    """
    # Instance that calls the method and is accessible from the button
    if current_version() < "5.3":
        rel = "/Integration/VimApi/VMware_HotAdd_Disk"
    else:
        rel = "/Integration/VMware/VimApi/VMware_HotAdd_Disk"
    instance = Instance(
        name="VMware_HotAdd_Disk",
        values={
            "rel5": rel,
        },
        cls=cls
    )
    if not instance.exists():
        request.addfinalizer(lambda: instance.delete() if instance.exists() else None)
        instance.create()
    # Dialog to put the disk capacity
    return
    element_data = {
        'ele_label': "Disk size",
        'ele_name': "size",
        'ele_desc': "Disk size",
        'choose_type': "Text Box",
        'default_text_box': "Default text"
    }
    dialog = ServiceDialog(
        label=fauxfactory.gen_alphanumeric(),
        description=fauxfactory.gen_alphanumeric(),
        submit=True,
        tab_label=fauxfactory.gen_alphanumeric(),
        tab_desc=fauxfactory.gen_alphanumeric(),
        box_label=fauxfactory.gen_alphanumeric(),
        box_desc=fauxfactory.gen_alphanumeric(),
    )
    dialog.create(element_data)
    request.addfinalizer(lambda: dialog.delete())
    # Button that will invoke the dialog and action
    button_name = fauxfactory.gen_alphanumeric()
    button = Button(group=testing_group,
                    text=button_name,
                    hover=button_name,
                    dialog=dialog, system="Request", request="VMware_HotAdd_Disk")
    request.addfinalizer(button.delete_if_exists)
    button.create()
    # Now do the funny stuff

    def _get_disk_count():
        return int(testing_vm.get_detail(
            properties=("Datastore Allocation Summary", "Number of Disks")).strip())
    original_disk_count = _get_disk_count()
    toolbar.select(testing_group.text, button.text)
    fill(Input("size"), "1")
    pytest.sel.click(submit)
    flash.assert_no_errors()
    wait_for(lambda: original_disk_count + 1 == _get_disk_count(), num_sec=180, delay=5)
Esempio n. 16
0
def test_vmware_vimapi_hotadd_disk(
        request, testing_group, provider, testing_vm, domain, cls):
    """ Tests hot adding a disk to vmware vm.

    This test exercises the ``VMware_HotAdd_Disk`` method, located in ``/Integration/VMware/VimApi``

    Steps:
        * It creates an instance in ``System/Request`` that can be accessible from eg. a button.
        * Then it creates a button, that refers to the ``VMware_HotAdd_Disk`` in ``Request``. The
            button shall belong in the VM and instance button group.
        * After the button is created, it goes to a VM's summary page, clicks the button.
        * The test waits until the capacity of disks is raised.

    Metadata:
        test_flag: hotdisk, provision
    """
    meth = Method(
        name='load_value_{}'.format(fauxfactory.gen_alpha()),
        data=dedent('''\
            # Sets the capacity of the new disk.

            $evm.root['size'] = 1  # GB
            exit MIQ_OK
            '''),
        cls=cls)

    @request.addfinalizer
    def _remove_method():
        if meth.exists():
            meth.delete()

    meth.create()

    # Instance that calls the method and is accessible from the button
    instance = Instance(
        name="VMware_HotAdd_Disk_{}".format(fauxfactory.gen_alpha()),
        values={
            "meth4": meth.name,  # To get the value
            "rel5": "/Integration/VMware/VimApi/VMware_HotAdd_Disk",
        },
        cls=cls
    )

    @request.addfinalizer
    def _remove_instance():
        if instance.exists():
            instance.delete()
    instance.create()

    # Button that will invoke the dialog and action
    button_name = fauxfactory.gen_alphanumeric()
    button = Button(group=testing_group,
                    text=button_name,
                    hover=button_name, system="Request", request=instance.name)
    request.addfinalizer(button.delete_if_exists)
    button.create()

    def _get_disk_capacity():
        testing_vm.summary.reload()
        return testing_vm.summary.datastore_allocation_summary.total_allocation.value

    original_disk_capacity = _get_disk_capacity()
    logger.info('Initial disk allocation: %s', original_disk_capacity)
    toolbar.select(testing_group.text, button.text)
    flash.assert_no_errors()
    try:
        wait_for(
            lambda: _get_disk_capacity() > original_disk_capacity, num_sec=180, delay=5)
    finally:
        logger.info('End disk capacity: %s', _get_disk_capacity())
def test_vmware_vimapi_hotadd_disk(
        request, testing_group, provider, testing_vm, domain, cls):
    """ Tests hot adding a disk to vmware vm.

    This test exercises the ``VMware_HotAdd_Disk`` method, located in ``/Integration/VMware/VimApi``

    Steps:
        * It creates an instance in ``System/Request`` that can be accessible from eg. a button.
        * Then it creates a service dialog that contains a field with the desired disk size, the
            text field name should be ``size``
        * Then it creates a button, that refers to the ``VMware_HotAdd_Disk`` in ``Request``. The
            button shall belong in the VM and instance button group.
        * After the button is created, it goes to a VM's summary page, clicks the button, enters
            the size of the disk and submits the dialog.
        * The test waits until the number of disks is raised.

    Metadata:
        test_flag: hotdisk, provision
    """
    meth = Method(
        name='parse_dialog_value_{}'.format(fauxfactory.gen_alpha()),
        data=dedent('''\
            # Transfers the dialog value to the root so the VMware method can use it.

            $evm.root['size'] = $evm.object['dialog_size']
            exit MIQ_OK
            '''),
        cls=cls)

    @request.addfinalizer
    def _remove_method():
        if meth.exists():
            meth.delete()

    meth.create()

    # Instance that calls the method and is accessible from the button
    instance = Instance(
        name="VMware_HotAdd_Disk_{}".format(fauxfactory.gen_alpha()),
        values={
            "meth4": {'on_entry': meth.name},  # To preparse the value
            "rel5": "/Integration/VMware/VimApi/VMware_HotAdd_Disk",
        },
        cls=cls
    )

    @request.addfinalizer
    def _remove_instance():
        if instance.exists():
            instance.delete()
    instance.create()
    # Dialog to put the disk capacity
    element_data = {
        'ele_label': "Disk size",
        'ele_name': "size",
        'ele_desc': "Disk size",
        'choose_type': "Text Box",
        'default_text_box': "Default text"
    }
    dialog = ServiceDialog(
        label=fauxfactory.gen_alphanumeric(),
        description=fauxfactory.gen_alphanumeric(),
        submit=True,
        tab_label=fauxfactory.gen_alphanumeric(),
        tab_desc=fauxfactory.gen_alphanumeric(),
        box_label=fauxfactory.gen_alphanumeric(),
        box_desc=fauxfactory.gen_alphanumeric(),
    )
    dialog.create(element_data)
    request.addfinalizer(dialog.delete)
    # Button that will invoke the dialog and action
    button_name = fauxfactory.gen_alphanumeric()
    button = Button(group=testing_group,
                    text=button_name,
                    hover=button_name,
                    dialog=dialog, system="Request", request=instance.name)
    request.addfinalizer(button.delete_if_exists)
    button.create()

    def _get_disk_count():
        return int(testing_vm.get_detail(
            properties=("Datastore Allocation Summary", "Number of Disks")).strip())
    original_disk_count = _get_disk_count()
    logger.info('Initial disk count: %s', original_disk_count)
    toolbar.select(testing_group.text, button.text)
    fill(Input("size"), '1')
    pytest.sel.click(submit)
    flash.assert_no_errors()
    try:
        wait_for(
            lambda: original_disk_count + 1 == _get_disk_count(), num_sec=180, delay=5)
    finally:
        logger.info('End disk count: %s', _get_disk_count())
def test_vmware_vimapi_hotadd_disk(request, testing_group, provider,
                                   testing_vm, domain, namespace, cls):
    """ Tests hot adding a disk to vmware vm.

    This test exercises the ``VMware_HotAdd_Disk`` method, located either in
    ``/Integration/VimApi/`` (<5.3) or ``/Integration/VMware/VimApi`` (5.3 and up).

    Steps:
        * It creates an instance in ``System/Request`` that can be accessible from eg. a button.
        * Then it creates a service dialog that contains a field with the desired disk size, the
            text field name should be ``size``
        * Then it creates a button, that refers to the ``VMware_HotAdd_Disk`` in ``Request``. The
            button shall belong in the VM and instance button group.
        * After the button is created, it goes to a VM's summary page, clicks the button, enters
            the size of the disk and submits the dialog.
        * The test waits until the number of disks is raised.

    Metadata:
        test_flag: hotdisk, provision
    """
    # Instance that calls the method and is accessible from the button
    if current_version() < "5.3":
        rel = "/Integration/VimApi/VMware_HotAdd_Disk"
    else:
        rel = "/Integration/VMware/VimApi/VMware_HotAdd_Disk"
    instance = Instance(name="VMware_HotAdd_Disk",
                        values={
                            "rel5": rel,
                        },
                        cls=cls)
    if not instance.exists():
        request.addfinalizer(lambda: instance.delete()
                             if instance.exists() else None)
        instance.create()
    # Dialog to put the disk capacity
    return
    element_data = {
        'ele_label': "Disk size",
        'ele_name': "size",
        'ele_desc': "Disk size",
        'choose_type': "Text Box",
        'default_text_box': "Default text"
    }
    dialog = ServiceDialog(
        label=fauxfactory.gen_alphanumeric(),
        description=fauxfactory.gen_alphanumeric(),
        submit=True,
        tab_label=fauxfactory.gen_alphanumeric(),
        tab_desc=fauxfactory.gen_alphanumeric(),
        box_label=fauxfactory.gen_alphanumeric(),
        box_desc=fauxfactory.gen_alphanumeric(),
    )
    dialog.create(element_data)
    request.addfinalizer(lambda: dialog.delete())
    # Button that will invoke the dialog and action
    button_name = fauxfactory.gen_alphanumeric()
    button = Button(group=testing_group,
                    text=button_name,
                    hover=button_name,
                    dialog=dialog,
                    system="Request",
                    request="VMware_HotAdd_Disk")
    request.addfinalizer(button.delete_if_exists)
    button.create()

    # Now do the funny stuff

    def _get_disk_count():
        return int(
            testing_vm.get_detail(properties=("Datastore Allocation Summary",
                                              "Number of Disks")).strip())

    original_disk_count = _get_disk_count()
    toolbar.select(testing_group.text, button.text)
    fill(Input("size"), "1")
    pytest.sel.click(submit)
    flash.assert_no_errors()
    wait_for(lambda: original_disk_count + 1 == _get_disk_count(),
             num_sec=180,
             delay=5)