def setup_first_provider(): providers.setup_a_provider(prov_class="infra", validate=True, check_existing=True) providers.setup_a_provider(prov_class="cloud", validate=True, check_existing=True)
def test_db_restore(request, soft_assert): appl1, appl2 = get_appliances() def finalize(): appl1.destroy() appl2.destroy() request.addfinalizer(finalize) appl1.ipapp.browser_steal = True with appl1.ipapp: # Manage infra,cloud providers and set some roles before taking a DB backup config.set_server_roles(automate=True) roles = config.get_server_roles() provider_crud = setup_a_provider('infra', 'virtualcenter', validate=True) provider_mgmt = provider_crud.get_mgmt_system() wait_for_a_provider() setup_a_provider('cloud', 'ec2', validate=True) cloud_provider.wait_for_a_provider() providers_appl1 = appl1.ipapp.managed_providers appl1.ipapp.backup_database() # Fetch v2_key and DB backup from the first appliance with appl1.ipapp.ssh_client as ssh: rand_filename = "/tmp/v2_key_{}".format(fauxfactory.gen_alphanumeric()) ssh.get_file("/var/www/miq/vmdb/certs/v2_key", rand_filename) dump_filename = "/tmp/db_dump_{}".format(fauxfactory.gen_alphanumeric()) ssh.get_file("/tmp/evm_db.backup", dump_filename) with appl2.ipapp.ssh_client as ssh: ssh.put_file(rand_filename, "/var/www/miq/vmdb/certs/v2_key") ssh.put_file(dump_filename, "/tmp/evm_db.backup") appl2.ipapp.browser_steal = True with appl2.ipapp: # Restore DB on the second appliance appl2.ipapp.restore_database() appl2.ipapp.wait_for_web_ui() wait_for_a_provider() cloud_provider.wait_for_a_provider() # Assert providers on the second appliance providers_appl2 = appl2.ipapp.managed_providers assert set(providers_appl2).issubset(providers_appl1),\ 'Restored DB is missing some providers' # Verify that existing provider can detect new VMs on the second appliance vm = provision_vm(request, provider_crud, provider_mgmt) soft_assert(vm.find_quadicon().state == 'currentstate-on') soft_assert(vm.provider_crud.get_mgmt_system().is_vm_running(vm.name), "vm running") # Assert server roles on the second appliance for role, is_enabled in config.get_server_roles(db=False).iteritems(): if is_enabled: assert roles[role], "Role '%s' is selected but should not be" % role else: assert not roles[role], "Role '%s' is not selected but should be" % role
def providers(): """Ensure the infra providers are set up and get list of hosts""" try: setup_a_provider(prov_class="infra") except Exception: pytest.skip("It's not possible to set up any providers, therefore skipping") pytest.sel.force_navigate("infrastructure_providers") search.ensure_no_filter_applied()
def vms(): """Ensure the infra providers are set up and get list of vms""" try: setup_a_provider(prov_class="infra", required_keys=["large"]) except Exception: pytest.skip("It's not possible to set up any providers, therefore skipping") navigate_to(Vm, 'VMsOnly') search.ensure_no_filter_applied() return virtual_machines.get_all_vms()
def providers(): """Ensure the infra providers are set up and get list of hosts""" try: setup_a_provider(prov_type="infra") except Exception: pytest.skip( "It's not possible to set up any providers, therefore skipping") sel.force_navigate("infrastructure_providers") search.ensure_no_filter_applied()
def vms(): """Ensure the infra providers are set up and get list of vms""" try: setup_a_provider(prov_type="infra", required_keys="large") except Exception: pytest.skip("It's not possible to set up any providers, therefore skipping") sel.force_navigate("infra_vms") search.ensure_no_filter_applied() return virtual_machines.get_all_vms()
def hosts(): """Ensure the infra providers are set up and get list of hosts""" try: setup_a_provider(prov_class="infra") except Exception: pytest.skip("It's not possible to set up any providers, therefore skipping") navigate_to(Host, 'All') search.ensure_no_filter_applied() return host.get_all_hosts()
def vms(): """Ensure the infra providers are set up and get list of vms""" try: setup_a_provider(prov_type="infra", required_keys="large") except Exception: pytest.skip( "It's not possible to set up any providers, therefore skipping") pytest.sel.force_navigate("infra_vms") search.ensure_no_filter_applied() return virtual_machines.get_all_vms()
def existing_vm(request): """ Fixture will be using for set\unset retirement date for existing vm instead of creation a new one """ list_of_existing_providers = providers.existing_providers() if list_of_existing_providers: test_provider = providers.get_crud(list_of_existing_providers[0]) else: test_provider = providers.setup_a_provider() all_vms = test_provider.mgmt.list_vm() need_to_create_vm = True for virtual_machine in all_vms: if test_provider.mgmt.is_vm_running(virtual_machine): need_vm = VM.factory(virtual_machine, test_provider) need_to_create_vm = False break if need_to_create_vm: machine_name = 'test_retire_prov_{}'.format(fauxfactory.gen_alpha(length=8).lower()) need_vm = VM.factory(machine_name, test_provider) need_vm.create_on_provider(find_in_cfme=True, allow_skip="default") @request.addfinalizer def _delete_vm(): if need_to_create_vm: test_provider.mgmt.delete_vm(need_vm.name) return need_vm
def a_provider(): try: pf = ProviderFilter(classes=[InfraProvider], required_fields=[ ['provisioning', 'template'], ['provisioning', 'host'], ['provisioning', 'datastore'], ['provisioning', 'vlan'], ['provisioning', 'catalog_item_type']]) return setup_a_provider(filters=[pf]) except Exception: pytest.skip("It's not possible to set up any providers, therefore skipping")
def single_provider(): """Ensure the infra provider is setup""" try: return setup_a_provider(prov_class="infra") except Exception as ex: pytest.skip("Exception while setting up providers, therefore skipping: {}".format(ex))
def provider(): return setup_a_provider(prov_class="infra", prov_type="virtualcenter")
def setup_single_provider(): setup_a_provider()
def test_db_restore(request, soft_assert): appl1, appl2 = get_appliances() def finalize(): appl1.destroy() appl2.destroy() request.addfinalizer(finalize) appl1.ipapp.browser_steal = True with appl1.ipapp: # Manage infra,cloud providers and set some roles before taking a DB backup config.set_server_roles(automate=True) roles = config.get_server_roles() provider_crud = setup_a_provider('infra', 'virtualcenter', validate=True) wait_for_a_provider() setup_a_provider('cloud', 'ec2', validate=True) cloud_provider.wait_for_a_provider() providers_appl1 = appl1.ipapp.managed_providers appl1.ipapp.backup_database() # Fetch v2_key and DB backup from the first appliance with appl1.ipapp.ssh_client as ssh: rand_filename = "/tmp/v2_key_{}".format(fauxfactory.gen_alphanumeric()) ssh.get_file("/var/www/miq/vmdb/certs/v2_key", rand_filename) dump_filename = "/tmp/db_dump_{}".format( fauxfactory.gen_alphanumeric()) ssh.get_file("/tmp/evm_db.backup", dump_filename) with appl2.ipapp.ssh_client as ssh: ssh.put_file(rand_filename, "/var/www/miq/vmdb/certs/v2_key") ssh.put_file(dump_filename, "/tmp/evm_db.backup") appl2.ipapp.browser_steal = True with appl2.ipapp: # Restore DB on the second appliance appl2.ipapp.restore_database() appl2.ipapp.wait_for_web_ui() wait_for_a_provider() cloud_provider.wait_for_a_provider() # Assert providers on the second appliance providers_appl2 = appl2.ipapp.managed_providers assert set(providers_appl2).issubset(providers_appl1),\ 'Restored DB is missing some providers' # Verify that existing provider can detect new VMs on the second appliance vm = provision_vm(request, provider_crud) soft_assert(vm.find_quadicon().state == 'currentstate-on') soft_assert(vm.provider.mgmt.is_vm_running(vm.name), "vm running") # Assert server roles on the second appliance for role, is_enabled in config.get_server_roles(db=False).iteritems(): if is_enabled: assert roles[ role], "Role '{}' is selected but should not be".format( role) else: assert not roles[ role], "Role '{}' is not selected but should be".format( role)
def setup_first_provider(): setup_a_provider(validate=True, check_existing=True)
def setup_first_cloud_provider(): setup_a_provider(prov_class="cloud", validate=True, check_existing=True)
def any_provider_session(): providers.clear_providers() # To make it clean providers.setup_a_provider(validate=True, check_existing=True)
def a_provider(): try: pf = ProviderFilter(classes=[VMwareProvider, RHEVMProvider]) return setup_a_provider(filters=[pf]) except Exception: pytest.skip("It's not possible to set up any providers, therefore skipping")
def setup_infra_provider(): return setup_a_provider(prov_class="infra", validate=True, check_existing=True, required_keys=['ownership_vm'])
def provider(): return setup_a_provider("infra")
def test_ipappliance_managed_providers(): ip_a = IPAppliance() provider = setup_a_provider(prov_class='infra') assert provider.key in ip_a.managed_providers
def setup_a_provider(): return providers.setup_a_provider(prov_class="cloud", validate=True, check_existing=True)
def any_provider_session(): providers.setup_a_provider(validate=True, check_existing=True)