def create_method(request, copy_domain): method = Method(name="InspectMe", data=METHOD_TORSO, cls=Class(name="Request", namespace=Namespace(name="System", parent=copy_domain))) method.create() return method
def create_method(request, copy_domain): method = Method( name="InspectMe", data=METHOD_TORSO, cls=Class( name="Request", namespace=Namespace( name="System", parent=copy_domain ) ) ) method.create() return method
def original_method(request, original_method_write_data): method = Method( name=generate_random_string(), data=METHOD_TORSO.format(original_method_write_data), cls=Class( name="Request", namespace=Namespace( name="System", parent=Domain.default ) ) ) method.create() request.addfinalizer(lambda: method.delete() if method.exists() else None) return method
def create_method(request, copy_domain): method = Method( name="InspectMe", data=METHOD_TORSO, cls=Class( name="Request", namespace=Namespace( name="System", parent=copy_domain ) ) ) method.create() request.addfinalizer(lambda: method.delete() if method.exists() else None) return method
def test_add_vm_to_service(myservice, request, copy_domain): """Tests adding vm to service Metadata: test_flag: provision """ method_torso = """ def add_to_service vm = $evm.root['vm'] service = $evm.vmdb('service').find_by_name('{}') user = $evm.root['user'] if service && vm $evm.log('info', "XXXXXXXX Attaching Service to VM: [#{{service.name}}][#{{vm.name}}]") vm.add_to_service(service) vm.owner = user if user vm.group = user.miq_group if user end end $evm.log("info", "Listing Root Object Attributes:") $evm.log("info", "===========================================") add_to_service """.format(myservice.service_name) method = Method( name="InspectMe", data=method_torso, cls=Class( name="Request", namespace=Namespace( name="System", parent=copy_domain ) ) ) method.create() request.addfinalizer(lambda: method.delete() if method.exists() else None) simulate( instance="Request", message="create", request=method.name, attribute=["VM and Instance", "auto_test_services"], # Random selection, does not matter execute_methods=True ) myservice.check_vm_add("auto_test_services") request.addfinalizer(lambda: myservice.delete(myservice.service_name))
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()
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()
def original_method(request, original_method_write_data, original_domain): method = Method( name=fauxfactory.gen_alphanumeric(), data=METHOD_TORSO.format(original_method_write_data), cls=Class( name="Request", namespace=Namespace( name="System", parent=original_domain ), setup_schema=[Class.SchemaField(name="meth5", type_="Method")] ) ) method.create() request.addfinalizer(lambda: method.delete() if method.exists() else None) return method
def original_method(request, original_method_write_data, original_domain, original_class): method = Method( name=fauxfactory.gen_alphanumeric(), data=METHOD_TORSO.format(original_method_write_data), cls=original_class, ) method.create() request.addfinalizer(lambda: method.delete() if method.exists() else None) return method
def original_method(request, original_method_write_data, original_domain): method = Method(name=fauxfactory.gen_alphanumeric(), data=METHOD_TORSO.format(original_method_write_data), cls=Class(name="Request", namespace=Namespace(name="System", parent=original_domain), setup_schema=[ Class.SchemaField(name="meth5", type_="Method") ])) method.create() request.addfinalizer(lambda: method.delete() if method.exists() else None) return method
def test_add_vm_to_service(myservice, request, copy_domain): """Tests adding vm to service Metadata: test_flag: provision """ method_torso = """ def add_to_service vm = $evm.root['vm'] service = $evm.vmdb('service').find_by_name('%s') user = $evm.root['user'] if service && vm $evm.log('info', "XXXXXXXX Attaching Service to VM: [#{service.name}][#{vm.name}]") vm.add_to_service(service) vm.owner = user if user vm.group = user.miq_group if user end end $evm.log("info", "Listing Root Object Attributes:") $evm.log("info", "===========================================") add_to_service """ % myservice.service_name method = Method( name="InspectMe", data=method_torso, cls=Class( name="Request", namespace=Namespace( name="System", parent=copy_domain ) ) ) method.create() request.addfinalizer(lambda: method.delete() if method.exists() else None) simulate( instance="Request", message="create", request=method.name, attribute=["VM and Instance", "auto_test_services"], # Random selection, does not matter execute_methods=True ) myservice.check_vm_add("auto_test_services") request.addfinalizer(lambda: myservice.delete(myservice.service_name))
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, 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: {}'.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 a_method(a_class): return Method(name=fauxfactory.gen_alphanumeric(8), data="foo.bar()", cls=a_class)
def a_method(a_class): return Method(name=generate_random_string(8), data="foo.bar()", cls=a_class)