def valid_settings_values(): """Returns a list of valid settings values""" return [ gen_email(gen_string('alpha')), gen_email(gen_string('alphanumeric')), gen_email(gen_string('numeric')), ]
def test_tenant_quota_enforce_via_lifecycle_cloud(request, appliance, provider, set_roottenant_quota, extra_msg, custom_prov_data, approve, prov_data, vm_name, template_name): """Test Tenant Quota in UI Polarion: assignee: tpapaioa casecomponent: Cloud initialEstimate: 1/10h tags: quota """ prov_data.update(custom_prov_data) prov_data['catalog']['vm_name'] = vm_name prov_data.update({'request': {'email': fauxfactory.gen_email()}}) prov_data.update({'template_name': template_name}) request_description = f'Provision from [{template_name}] to [{vm_name}{extra_msg}]' appliance.collections.cloud_instances.create( vm_name, provider, prov_data, auto_approve=approve, override=True, request_description=request_description) # nav to requests page to check quota validation provision_request = appliance.collections.requests.instantiate( request_description) provision_request.wait_for_request(method='ui') request.addfinalizer(provision_request.remove_request) assert provision_request.row.reason.text == "Quota Exceeded"
def test_vm_migration_after_assigning_tenant_quota(appliance, create_vm_modscope, set_root_tenant_quota, custom_prov_data, migration_destination_host): """ Polarion: assignee: tpapaioa casecomponent: Infra caseimportance: high initialEstimate: 1/6h tags: quota testSteps: 1. Create VM 2. Assign tenant quota 3. Migrate VM 4. Check whether migration is successfully done """ vm = create_vm_modscope vm.migrate_vm(fauxfactory.gen_email(), fauxfactory.gen_alpha(), fauxfactory.gen_alpha(), host=migration_destination_host) request_description = vm.name cells = {'Description': request_description, 'Request Type': 'Migrate'} migrate_request = appliance.collections.requests.instantiate(request_description, cells=cells, partial_check=True) migrate_request.wait_for_request(method='ui') msg = f"Request failed with the message {migrate_request.row.last_message.text}" assert migrate_request.is_succeeded(method='ui'), msg
def new_instance(provider, zero_disk_flavor): flavor_name = zero_disk_flavor.name prov_data = provider.data['provisioning'] prov_form_data = { 'request': {'email': fauxfactory.gen_email(), 'first_name': fauxfactory.gen_alpha(), 'last_name': fauxfactory.gen_alpha()}, 'catalog': {'num_vms': '1', 'vm_name': random_vm_name("osp")}, 'environment': {'cloud_network': prov_data['cloud_network'], 'cloud_tenant': prov_data['cloud_tenant']}, 'properties': {'instance_type': partial_match(flavor_name)}, } instance_name = prov_form_data['catalog']['vm_name'] try: instance = provider.appliance.collections.cloud_instances.create( instance_name, provider, prov_form_data, find_in_cfme=True ) except KeyError: # some yaml value wasn't found pytest.skip('Unable to find an image map in provider "{}" provisioning data: {}' .format(provider, prov_data)) yield instance instance.cleanup_on_provider()
def test_alert_vm_turned_on_more_than_twice_in_past_15_minutes(request, provider, full_template_vm, smtp_test, alert_collection, setup_for_alerts): """ Tests alerts for vm turned on more than twice in 15 minutes Metadata: test_flag: alerts, provision """ vm = full_template_vm alert = alert_collection.instantiate("VM Power On > 2 in last 15 min") with update(alert): alert.active = True alert.emails = fauxfactory.gen_email() setup_for_alerts(request, [alert], "VM Power On", vm.name, provider) if not provider.mgmt.is_vm_stopped(vm.name): provider.mgmt.stop_vm(vm.name) provider.refresh_provider_relationships() vm.wait_for_vm_state_change(vm.STATE_OFF) for i in range(5): vm.power_control_from_cfme(option=vm.POWER_ON, cancel=False) wait_for(lambda: provider.mgmt.is_vm_running(vm.name), num_sec=300, message="Check if vm is running") vm.wait_for_vm_state_change(vm.STATE_ON) vm.power_control_from_cfme(option=vm.POWER_OFF, cancel=False) wait_for(lambda: provider.mgmt.is_vm_stopped(vm.name), num_sec=300, message="Check if vm is stopped") vm.wait_for_vm_state_change(vm.STATE_OFF) wait_for_alert(smtp_test, alert, delay=16 * 60)
def test_alert_rtp(request, full_template_vm, smtp_test, provider, setup_candu, wait_candu, setup_for_alerts, alert_collection): """ Tests a custom alert that uses C&U data to trigger an alert. Since the threshold is set to zero, it will start firing mails as soon as C&U data are available. Metadata: test_flag: alerts, provision, metrics_collection """ email = fauxfactory.gen_email() alert = alert_collection.create( "Trigger by CPU {}".format(fauxfactory.gen_alpha(length=4)), active=True, based_on="VM and Instance", evaluate=( "Real Time Performance", { "performance_field": "CPU - % Used", "performance_field_operator": ">", "performance_field_value": "0", "performance_trend": "Don't Care", "performance_time_threshold": "3 Minutes", }), notification_frequency="5 Minutes", emails=email, ) request.addfinalizer(alert.delete) setup_for_alerts(request, [alert]) wait_for_alert(smtp_test, alert, delay=30 * 60, additional_checks={ "text": full_template_vm.name, "from_address": email})
def make_user(session, org=None, loc=None, force_context=True, **kwargs): """Creates a user""" password = gen_string('alpha', 6) create_args = { u'admin': False, u'username': None, u'email': gen_email(), u'password1': password, u'password2': password, u'authorized_by': u'INTERNAL', u'locale': None, u'first_name': gen_string('alpha'), u'last_name': gen_string('alpha'), u'roles': None, u'locations': None, u'organizations': None, u'edit': False, u'select': True, u'default_org': None, u'default_loc': None, u'submit': True, } page = session.nav.go_to_users core_factory(create_args, kwargs, session, page, org=org, loc=loc, force_context=force_context) User(session.browser).create(**create_args)
def test_alert_vm_turned_on_more_than_twice_in_past_15_minutes( vm_name, vm_crud, provider, request, smtp_test, register_event): """ Tests alerts for vm turned on more than twice in 15 minutes Metadata: test_flag: alerts, provision """ alert = explorer.Alert("VM Power On > 2 in last 15 min") with update(alert): alert.emails = fauxfactory.gen_email() setup_for_alerts(request, [alert], "VM Power On", vm_name, provider) if not provider.mgmt.is_vm_stopped(vm_name): provider.mgmt.stop_vm(vm_name) provider.refresh_provider_relationships() register_event(provider.type, "vm", vm_name, ["vm_power_off"]) vm_crud.wait_for_vm_state_change(vm_crud.STATE_OFF) for i in range(5): vm_crud.power_control_from_cfme(option=vm_crud.POWER_ON, cancel=False) register_event(provider.type, "vm", vm_name, ["vm_power_on", "vm_power_on_req"]) wait_for(lambda: provider.mgmt.is_vm_running(vm_name), num_sec=300) vm_crud.wait_for_vm_state_change(vm_crud.STATE_ON) vm_crud.power_control_from_cfme(option=vm_crud.POWER_OFF, cancel=False) register_event(provider.type, "vm", vm_name, ["vm_power_off", "vm_power_off_req"]) wait_for(lambda: provider.mgmt.is_vm_stopped(vm_name), num_sec=300) vm_crud.wait_for_vm_state_change(vm_crud.STATE_OFF) wait_for_alert(smtp_test, alert, delay=16 * 60)
def test_action_cancel_clone(request, provider, vm_name, vm_big, policy_for_testing): """This test checks if 'Cancel vCenter task' action works. For this test we need big template otherwise CFME won't have enough time to cancel the task https://bugzilla.redhat.com/show_bug.cgi?id=1383372#c9 """ with update: policy_for_testing.scope = ( "fill_field(VM and Instance : Name, INCLUDES, {})".format(vm_big.name)) policy_for_testing.assign_events("VM Clone Start") policy_for_testing.assign_actions_to_event( "VM Clone Start", ["Cancel vCenter Task"]) clone_vm_name = "{}-clone".format(vm_big.name) @request.addfinalizer def finalize(): policy_for_testing.assign_events() with update: policy_for_testing.scope = ( "fill_field(VM and Instance : Name, INCLUDES, {})".format(vm_name)) cleanup_vm(clone_vm_name, provider) vm_big.crud.clone_vm(fauxfactory.gen_email(), "first", "last", clone_vm_name, "VMware") cells = {"Description": clone_vm_name} row, __ = wait_for(requests.wait_for_request, [cells, True], fail_func=requests.reload, num_sec=4000, delay=20) assert row.status.text == "Error"
def test_vm_migration_after_assigning_tenant_quota(appliance, small_vm, set_roottenant_quota, custom_prov_data, provider): """ Polarion: assignee: ghubale casecomponent: Infra caseimportance: high initialEstimate: 1/6h tags: quota testSteps: 1. Create VM 2. Assign tenant quota 3. Migrate VM 4. Check whether migration is successfully done """ migrate_to = check_hosts(small_vm, provider) small_vm.migrate_vm(fauxfactory.gen_email(), fauxfactory.gen_alpha(), fauxfactory.gen_alpha(), host=migrate_to) request_description = small_vm.name cells = {'Description': request_description, 'Request Type': 'Migrate'} migrate_request = appliance.collections.requests.instantiate(request_description, cells=cells, partial_check=True) migrate_request.wait_for_request(method='ui') msg = "Request failed with the message {}".format(migrate_request.row.last_message.text) assert migrate_request.is_succeeded(method='ui'), msg
def test_action_cancel_clone(request, provider, vm_name, vm_big, policy_for_testing): """This test checks if 'Cancel vCenter task' action works. For this test we need big template otherwise CFME won't have enough time to cancel the task https://bugzilla.redhat.com/show_bug.cgi?id=1383372#c9 """ with update: policy_for_testing.scope = ( "fill_field(VM and Instance : Name, INCLUDES, {})".format( vm_big.name)) policy_for_testing.assign_events("VM Clone Start") policy_for_testing.assign_actions_to_event("VM Clone Start", ["Cancel vCenter Task"]) clone_vm_name = "{}-clone".format(vm_big.name) @request.addfinalizer def finalize(): policy_for_testing.assign_events() with update: policy_for_testing.scope = ( "fill_field(VM and Instance : Name, INCLUDES, {})".format( vm_name)) cleanup_vm(clone_vm_name, provider) vm_big.crud.clone_vm(fauxfactory.gen_email(), "first", "last", clone_vm_name, "VMware") cells = {"Description": clone_vm_name} row, __ = wait_for(requests.wait_for_request, [cells, True], fail_func=requests.reload, num_sec=4000, delay=20) assert row.status.text == "Error"
def new_instance(provider): prov_data = provider.data['provisioning'] prov_form_data = { 'request': {'email': fauxfactory.gen_email(), 'first_name': fauxfactory.gen_alpha(), 'last_name': fauxfactory.gen_alpha()}, 'catalog': {'num_vms': '1', 'vm_name': fauxfactory.gen_alpha()}, 'environment': {'cloud_network': prov_data['cloud_network']}, 'properties': {'instance_type': partial_match(prov_data['instance_type'])}, } instance_name = prov_form_data['catalog']['vm_name'] try: instance = provider.appliance.collections.cloud_instances.create( instance_name, provider, prov_form_data, find_in_cfme=True ) except KeyError: # some yaml value wasn't found pytest.skip('Unable to find an image map in provider "{}" provisioning data: {}' .format(provider, prov_data)) yield instance try: instance.power_control_from_provider(instance.TERMINATE) except: pass
def user_self_service_role(appliance): """This is fixture with create user with user_self_service_role""" with appliance.context.use(ViaUI): # copy role with no restrictions role = appliance.collections.roles.instantiate(name="EvmRole-user_self_service") user_self_service_role = role.copy( name=fauxfactory.gen_alphanumeric(25, "self_service_role_"), vm_restriction="None" ) # Group with user self service role user_self_service_gp = appliance.collections.groups.create( description=fauxfactory.gen_alphanumeric(22, "self_service_gp_"), role=user_self_service_role.name ) # credentials for user creds = Credential( principal=fauxfactory.gen_alphanumeric(start="user_"), secret=fauxfactory.gen_alphanumeric(), ) # user with above group user = appliance.collections.users.create( name=fauxfactory.gen_alphanumeric(start="user_"), credential=creds, email=fauxfactory.gen_email(), groups=user_self_service_gp, ) yield user, user_self_service_role user.delete_if_exists() user_self_service_gp.delete_if_exists() user_self_service_role.delete_if_exists()
def test_alert_rtp(request, appliance, full_template_vm, smtp_test, provider, setup_candu, wait_candu, setup_for_alerts): """ Tests a custom alert that uses C&U data to trigger an alert. Since the threshold is set to zero, it will start firing mails as soon as C&U data are available. Metadata: test_flag: alerts, provision, metrics_collection Polarion: assignee: jdupuy casecomponent: Control initialEstimate: 1/6h """ email = fauxfactory.gen_email() alert = appliance.collections.alerts.create( "Trigger by CPU {}".format(fauxfactory.gen_alpha(length=4)), active=True, based_on="VM and Instance", evaluate=( "Real Time Performance", { "performance_field": "CPU - % Used", "performance_field_operator": ">", "performance_field_value": "0", "performance_trend": "Don't Care", "performance_time_threshold": "3 Minutes", }), notification_frequency="5 Minutes", emails=email, ) request.addfinalizer(alert.delete) setup_for_alerts(request, [alert]) wait_for_alert(smtp_test, alert, delay=30 * 60, additional_checks={ "text": full_template_vm.name, "from_address": email})
def test_alert_vm_turned_on_more_than_twice_in_past_15_minutes( request, appliance, provider, full_template_vm, smtp_test, setup_for_alerts ): """ Tests alerts for vm turned on more than twice in 15 minutes Metadata: test_flag: alerts, provision Polarion: assignee: jdupuy casecomponent: Control initialEstimate: 1/4h """ vm = full_template_vm alert = appliance.collections.alerts.instantiate("VM Power On > 2 in last 15 min") with update(alert): alert.active = True alert.emails = fauxfactory.gen_email() setup_for_alerts(request, [alert], "VM Power On", vm.name, provider) vm.mgmt.ensure_state(VmState.STOPPED) provider.refresh_provider_relationships() vm.wait_for_vm_state_change(vm.STATE_OFF) for i in range(5): vm.power_control_from_cfme(option=vm.POWER_ON, cancel=False) vm.mgmt.wait_for_state(VmState.RUNNING, timeout=300) vm.wait_for_vm_state_change(vm.STATE_ON) vm.power_control_from_cfme(option=vm.POWER_OFF, cancel=False) vm.mgmt.wait_for_state(VmState.STOPPED) vm.wait_for_vm_state_change(vm.STATE_OFF) wait_for_alert(smtp_test, alert, delay=16 * 60)
def make_user(session, org=None, loc=None, force_context=True, **kwargs): """Creates a user""" password = gen_string('alpha', 6) create_args = { u'admin': False, u'username': None, u'email': gen_email(), u'description': None, u'timezone': None, u'password1': password, u'password2': password, u'authorized_by': u'INTERNAL', u'locale': None, u'first_name': gen_string('alpha'), u'last_name': gen_string('alpha'), u'roles': None, u'locations': None, u'organizations': None, u'edit': False, u'select': True, u'default_org': None, u'default_loc': None, u'submit': True, } page = session.nav.go_to_users core_factory(create_args, kwargs, session, page, org=org, loc=loc, force_context=force_context) User(session.browser).create(**create_args)
def new_instance(provider): prov_data = provider.get_yaml_data()['provisioning'] instance = OpenStackInstance(fauxfactory.gen_alpha(), provider, template_name=prov_data['image']['name']) prov_form_data = { 'request': { 'email': fauxfactory.gen_email(), 'first_name': fauxfactory.gen_alpha(), 'last_name': fauxfactory.gen_alpha() }, 'catalog': { 'num_vms': '1', 'vm_name': instance.name }, 'environment': { 'cloud_network': prov_data['cloud_network'] }, 'properties': { 'instance_type': prov_data['instance_type'] }, } instance.create(False, **prov_form_data) instance.wait_to_appear() yield instance try: instance.power_control_from_provider(OpenStackInstance.TERMINATE) except: pass
def test_alert_rtp(request, vm_name, smtp_test, provider): """ Tests a custom alert that uses C&U data to trigger an alert. Since the threshold is set to zero, it will start firing mails as soon as C&U data are available. Metadata: test_flag: alerts, provision, metrics_collection """ email = fauxfactory.gen_email() alert = alerts.Alert( "Trigger by CPU {}".format(fauxfactory.gen_alpha(length=4)), active=True, based_on="VM and Instance", evaluate=( "Real Time Performance", { "performance_field": "CPU - % Used", "performance_field_operator": ">", "performance_field_value": "0", "performance_trend": "Don't Care", "performance_time_threshold": "3 Minutes", }), notification_frequency="5 Minutes", emails=email, ) alert.create() request.addfinalizer(alert.delete) setup_for_alerts(request, [alert]) wait_for_alert(smtp_test, alert, delay=30 * 60, additional_checks={ "text": vm_name, "from_address": email})
def test_alert_vm_turned_on_more_than_twice_in_past_15_minutes( vm_name, vm_crud, provider, request, smtp_test, register_event): """ Tests alerts for vm turned on more than twice in 15 minutes Metadata: test_flag: alerts, provision """ alert = explorer.Alert("VM Power On > 2 in last 15 min") with update(alert): alert.emails = fauxfactory.gen_email() setup_for_alerts(request, [alert], "VM Power On", vm_name, provider) if not provider.mgmt.is_vm_stopped(vm_name): provider.mgmt.stop_vm(vm_name) provider.refresh_provider_relationships() register_event('VmOrTemplate', vm_name, ['request_vm_poweroff', 'vm_poweoff']) vm_crud.wait_for_vm_state_change(vm_crud.STATE_OFF) for i in range(5): vm_crud.power_control_from_cfme(option=vm_crud.POWER_ON, cancel=False) register_event('VmOrTemplate', vm_name, ['request_vm_start', 'vm_start']) wait_for(lambda: provider.mgmt.is_vm_running(vm_name), num_sec=300) vm_crud.wait_for_vm_state_change(vm_crud.STATE_ON) vm_crud.power_control_from_cfme(option=vm_crud.POWER_OFF, cancel=False) register_event('VmOrTemplate', vm_name, ['request_vm_poweroff', 'vm_poweroff']) wait_for(lambda: provider.mgmt.is_vm_stopped(vm_name), num_sec=300) vm_crud.wait_for_vm_state_change(vm_crud.STATE_OFF) wait_for_alert(smtp_test, alert, delay=16 * 60)
def prov_data(provisioning, provider): data = { 'request': { 'email': fauxfactory.gen_email(), 'first_name': fauxfactory.gen_alphanumeric(), 'last_name': fauxfactory.gen_alphanumeric(), 'manager_name': fauxfactory.gen_alphanumeric(20, start="manager ") }, 'network': { 'vlan': partial_match(provisioning.get('vlan')) }, 'environment': { 'datastore_name': { 'name': provisioning['datastore'] }, 'host_name': { 'name': provisioning['host'] } }, 'catalog': {}, 'hardware': {}, 'schedule': {}, 'purpose': {}, } if provider.one_of(RHEVMProvider): data['catalog']['provision_type'] = 'Native Clone' elif provider.one_of(VMwareProvider): data['catalog']['provision_type'] = 'VMware' # Otherwise just leave it alone return data
def make_user(session, org=None, loc=None, force_context=True, **kwargs): """Creates a user""" password = gen_string("alpha", 6) create_args = { u"admin": False, u"username": None, u"email": gen_email(), u"password1": password, u"password2": password, u"authorized_by": u"INTERNAL", u"locale": None, u"first_name": gen_string("alpha"), u"last_name": gen_string("alpha"), u"roles": None, u"locations": None, u"organizations": None, u"edit": False, u"select": True, u"default_org": None, u"default_loc": None, u"submit": True, } page = session.nav.go_to_users core_factory(create_args, kwargs, session, page, org=org, loc=loc, force_context=force_context) User(session.browser).create(**create_args)
def test_action_cancel_clone(appliance, request, provider, vm_name, vm_big, policy_for_testing): """This test checks if 'Cancel vCenter task' action works. For this test we need big template otherwise CFME won't have enough time to cancel the task https://bugzilla.redhat.com/show_bug.cgi?id=1383372#c9 """ with update(policy_for_testing): policy_for_testing.scope = ( "fill_field(VM and Instance : Name, INCLUDES, {})".format(vm_big.name)) policy_for_testing.assign_events("VM Clone Start") policy_for_testing.assign_actions_to_event( "VM Clone Start", ["Cancel vCenter Task"]) clone_vm_name = "{}-clone".format(vm_big.name) @request.addfinalizer def finalize(): policy_for_testing.assign_events() with update(policy_for_testing): policy_for_testing.scope = ( "fill_field(VM and Instance : Name, INCLUDES, {})".format(vm_name)) cleanup_vm(clone_vm_name, provider) vm_big.crud.clone_vm(fauxfactory.gen_email(), "first", "last", clone_vm_name, "VMware") request_description = clone_vm_name clone_request = RequestCollection(appliance).instantiate(description=request_description, partial_check=True) clone_request.wait_for_request(method='ui') assert clone_request.status == "Error"
def test_quota_tagging_cloud_via_lifecycle(request, appliance, provider, prov_data, set_entity_quota_tag, template_name, vm_name): """Test Group and User Quota in UI using tagging Polarion: assignee: tpapaioa casecomponent: Cloud initialEstimate: 1/6h tags: quota """ recursive_update(prov_data, {'request': { 'email': fauxfactory.gen_email() }}) prov_data.update({'template_name': template_name}) appliance.collections.cloud_instances.create(vm_name, provider, prov_data, override=True) # nav to requests page to check quota validation request_description = 'Provision from [{template}] to [{vm}]'.format( template=template_name, vm=vm_name) provision_request = appliance.collections.requests.instantiate( request_description) provision_request.wait_for_request(method='ui') request.addfinalizer(provision_request.remove_request) assert provision_request.row.reason.text == "Quota Exceeded"
def test_action_cancel_clone(appliance, request, provider, vm_name, vm_big, policy_for_testing, compliance_policy): """This test checks if 'Cancel vCenter task' action works. For this test we need big template otherwise CFME won't have enough time to cancel the task https://bugzilla.redhat.com/show_bug.cgi?id=1383372#c9 """ with update(policy_for_testing): policy_for_testing.scope = ( "fill_field(VM and Instance : Name, INCLUDES, {})".format(vm_big.name)) with update(compliance_policy): compliance_policy.scope = ( "fill_field(VM and Instance : Name, INCLUDES, {})".format(vm_big.name)) policy_for_testing.assign_events("VM Clone Start") policy_for_testing.assign_actions_to_event( "VM Clone Start", ["Cancel vCenter Task"]) clone_vm_name = "{}-clone".format(vm_big.name) @request.addfinalizer def finalize(): policy_for_testing.assign_events() with update(policy_for_testing): policy_for_testing.scope = ( "fill_field(VM and Instance : Name, INCLUDES, {})".format(vm_name)) with update(compliance_policy): compliance_policy.scope = ( "fill_field(VM and Instance : Name, INCLUDES, {})".format(vm_name)) cleanup_vm(clone_vm_name, provider) vm_big.crud.clone_vm(fauxfactory.gen_email(), "first", "last", clone_vm_name, "VMware") request_description = clone_vm_name clone_request = appliance.collections.requests.instantiate(description=request_description, partial_check=True) clone_request.wait_for_request(method='ui') assert clone_request.status == "Error"
def test_alert_vm_turned_on_more_than_twice_in_past_15_minutes(request, provider, full_template_vm, smtp_test, alert_collection, setup_for_alerts): """ Tests alerts for vm turned on more than twice in 15 minutes Metadata: test_flag: alerts, provision Polarion: assignee: jdupuy casecomponent: Control initialEstimate: 1/4h """ vm = full_template_vm alert = alert_collection.instantiate("VM Power On > 2 in last 15 min") with update(alert): alert.active = True alert.emails = fauxfactory.gen_email() setup_for_alerts(request, [alert], "VM Power On", vm.name, provider) vm.mgmt.ensure_state(VmState.STOPPED) provider.refresh_provider_relationships() vm.wait_for_vm_state_change(vm.STATE_OFF) for i in range(5): vm.power_control_from_cfme(option=vm.POWER_ON, cancel=False) vm.mgmt.wait_for_state(VmState.RUNNING, timeout=300) vm.wait_for_vm_state_change(vm.STATE_ON) vm.power_control_from_cfme(option=vm.POWER_OFF, cancel=False) vm.mgmt.wait_for_state(VmState.STOPPED) vm.wait_for_vm_state_change(vm.STATE_OFF) wait_for_alert(smtp_test, alert, delay=16 * 60)
def test_alert_vm_turned_on_more_than_twice_in_past_15_minutes( request, provider, full_template_vm, smtp_test, alert_collection, setup_for_alerts): """ Tests alerts for vm turned on more than twice in 15 minutes Metadata: test_flag: alerts, provision """ vm = full_template_vm alert = alert_collection.instantiate("VM Power On > 2 in last 15 min") with update(alert): alert.active = True alert.emails = fauxfactory.gen_email() setup_for_alerts(request, [alert], "VM Power On", vm.name, provider) if not provider.mgmt.is_vm_stopped(vm.name): provider.mgmt.stop_vm(vm.name) provider.refresh_provider_relationships() vm.wait_for_vm_state_change(vm.STATE_OFF) for i in range(5): vm.power_control_from_cfme(option=vm.POWER_ON, cancel=False) wait_for(lambda: provider.mgmt.is_vm_running(vm.name), num_sec=300, message="Check if vm is running") vm.wait_for_vm_state_change(vm.STATE_ON) vm.power_control_from_cfme(option=vm.POWER_OFF, cancel=False) wait_for(lambda: provider.mgmt.is_vm_stopped(vm.name), num_sec=300, message="Check if vm is stopped") vm.wait_for_vm_state_change(vm.STATE_OFF) wait_for_alert(smtp_test, alert, delay=16 * 60)
def new_user(appliance, permission): # Tenant created collection = appliance.collections.tenants tenant = collection.create( name=fauxfactory.gen_alphanumeric(start="tenant_"), description=fauxfactory.gen_alphanumeric(), parent=collection.get_root_tenant(), ) # Role created role = appliance.collections.roles.create( name=fauxfactory.gen_alphanumeric(start="role_"), vm_restriction="Only User or Group Owned", product_features=permission) # Group creates group = appliance.collections.groups.create( description=fauxfactory.gen_alphanumeric(start="grp_"), role=role.name, tenant=f"My Company/{tenant.name}") creds = Credential(principal=fauxfactory.gen_alphanumeric(4), secret=fauxfactory.gen_alphanumeric(4)) # User created user = appliance.collections.users.create( name=fauxfactory.gen_alphanumeric(start="user_"), credential=creds, email=fauxfactory.gen_email(), groups=group, cost_center='Workload', value_assign='Database') yield user user.delete_if_exists() group.delete_if_exists() role.delete_if_exists() tenant.delete_if_exists()
def new_instance(provider, zero_disk_flavor): flavor_name = zero_disk_flavor.name prov_data = provider.data['provisioning'] prov_form_data = { 'request': {'email': fauxfactory.gen_email(), 'first_name': fauxfactory.gen_alpha(), 'last_name': fauxfactory.gen_alpha()}, 'catalog': {'num_vms': '1', 'vm_name': fauxfactory.gen_alpha()}, 'environment': {'cloud_network': prov_data['cloud_network'], 'cloud_tenant': prov_data['cloud_tenant']}, 'properties': {'instance_type': partial_match(flavor_name)}, } instance_name = prov_form_data['catalog']['vm_name'] try: instance = provider.appliance.collections.cloud_instances.create( instance_name, provider, prov_form_data, find_in_cfme=True ) except KeyError: # some yaml value wasn't found pytest.skip('Unable to find an image map in provider "{}" provisioning data: {}' .format(provider, prov_data)) yield instance instance.cleanup_on_provider()
def test_vm_migration_after_assigning_tenant_quota(appliance, setup_provider, small_vm, set_roottenant_quota, custom_prov_data, provider): """prerequisite: Provider should be added steps: 1. Create VM 2. Assign tenant quota 3. Migrate VM 4. Check whether migration is successfully done Polarion: assignee: ghubale casecomponent: infra initialEstimate: 1/6h """ migrate_to = check_hosts(small_vm, provider) small_vm.migrate_vm(fauxfactory.gen_email(), fauxfactory.gen_alpha(), fauxfactory.gen_alpha(), host=migrate_to) request_description = small_vm.name cells = {'Description': request_description, 'Request Type': 'Migrate'} migrate_request = appliance.collections.requests.instantiate( request_description, cells=cells, partial_check=True) migrate_request.wait_for_request(method='ui') msg = "Request failed with the message {}".format( migrate_request.row.last_message.text) assert migrate_request.is_succeeded(method='ui'), msg
def user(appliance): """Creates new user with role which does not have permission of modifying automate domains""" product_features = [([ 'Everything', 'Automation', 'Automate', 'Explorer', 'Automate Domains', 'Modify' ], False)] role = appliance.collections.roles.create( name=fauxfactory.gen_alphanumeric(), product_features=product_features) group = appliance.collections.groups.create( description=fauxfactory.gen_alphanumeric(), role=role.name, tenant=appliance.collections.tenants.get_root_tenant().name) user = appliance.collections.users.create( name=fauxfactory.gen_alphanumeric().lower(), credential=Credential( principal=fauxfactory.gen_alphanumeric(4), secret=fauxfactory.gen_alphanumeric(4), ), email=fauxfactory.gen_email(), groups=group, cost_center="Workload", value_assign="Database", ) yield user user.delete_if_exists() group.delete_if_exists() role.delete_if_exists()
def email_generator(name=None, domain="gmail", tlds="io"): """ Generates random email address of random length """ if not name: name = GeneralUtility.id_generator(utf8=False) result = fauxfactory.gen_email(name=name, domain=domain, tlds=tlds) return result.lower()
def test_quota_exceed_mail_with_more_info_link(configure_mail, appliance, provider, set_roottenant_quota, custom_prov_data, prov_data, extra_msg, vm_name, template_name): """ Bugzilla: 1579031 1759123 Polarion: assignee: ghubale initialEstimate: 1/12h caseimportance: high caseposneg: positive testtype: functional startsin: 5.9 casecomponent: Infra tags: quota setup: 1. Copy instance ManageIQ/Configuration/Email/Default to custom domain 2. Enter values for fields: approver, default_recipient, from and signature testSteps: 1. Provide valid mail address while provisioning Vm to exceed quota expectedResults: 1. Quota exceed mail should be sent """ approver, default_recipient, from_user = configure_mail mail_to = fauxfactory.gen_email() prov_data.update(custom_prov_data) prov_data['catalog']['vm_name'] = vm_name with LogValidator( "/var/www/miq/vmdb/log/automation.log", matched_patterns= [ f'"to"=>"{default_recipient}", "from"=>"{from_user}".*.Virtual Machine Request from ' f'{mail_to} was Denied."', f'"to"=>"{mail_to}", "from"=>"{from_user}".*.Your Virtual Machine Request was Approved,' f' pending Quota Validation.".*' ], ).waiting(timeout=120): do_vm_provisioning(appliance, template_name=template_name, provider=provider, vm_name=vm_name, provisioning_data=prov_data, wait=False, request=None, email=mail_to) # nav to requests page to check quota validation request_description = f'Provision from [{template_name}] to [{vm_name}{extra_msg}]' provision_request = appliance.collections.requests.instantiate( request_description) provision_request.wait_for_request(method='ui') assert provision_request.row.reason.text == "Quota Exceeded"
def test_project_quota_enforce_via_lifecycle_cloud( request, appliance, provider, new_user_project, set_project_quota, extra_msg, approve, custom_prov_data, prov_data, provisioning, ): """Test Project Quota in UI Polarion: assignee: ghubale casecomponent: Cloud caseimportance: high initialEstimate: 1/8h tags: quota testSteps: 1. Create a project 2. Assign quota to project 3. Provision instance over the assigned project's quota 4. Check whether quota is exceeded or not """ with new_user_project: recursive_update(prov_data, custom_prov_data) recursive_update( prov_data, { "request": { "email": fauxfactory.gen_email(), "first_name": fauxfactory.gen_alphanumeric(start="first_"), "last_name": fauxfactory.gen_alphanumeric(start="last_"), "manager_name": fauxfactory.gen_alphanumeric(start="manager_"), } }, ) prov_data.update({"template_name": provisioning["image"]["name"]}) request_description = "Provision from [{template}] to [{vm}{msg}]".format( template=provisioning["image"]["name"], vm=prov_data['catalog']['vm_name'], msg=extra_msg) appliance.collections.cloud_instances.create( prov_data['catalog']['vm_name'], provider, prov_data, auto_approve=approve, override=True, request_description=request_description, ) provision_request = appliance.collections.requests.instantiate( request_description) provision_request.wait_for_request(method="ui") request.addfinalizer(provision_request.remove_request) assert provision_request.row.reason.text == "Quota Exceeded"
def test_alert_hardware_reconfigured(request, appliance, configure_fleecing, smtp_test, full_template_vm, setup_for_alerts): """Tests alert based on "Hardware Reconfigured" evaluation. According https://bugzilla.redhat.com/show_bug.cgi?id=1396544 Hardware Reconfigured alerts require drift history. So here are the steps for triggering hardware reconfigured alerts based on CPU Count: 1. Run VM smart state analysis. 2. Change CPU count. 3. Run VM smart state analysis again. 4. Run VM reconfigure again. Then the alert for CPU count change should be triggered. It is either CPU increased or decreased depending on what has been done in your step 2, not the result of step 4. Step 4 is just to trigger the event. Metadata: test_flag: alerts, provision Polarion: assignee: jdupuy casecomponent: Control initialEstimate: 1/4h """ vm = full_template_vm email = fauxfactory.gen_email() service_request_desc = ("VM Reconfigure for: {0} - Processor Sockets: {1}, " "Processor Cores Per Socket: 1, Total Processors: {1}") alert = appliance.collections.alerts.create( "Trigger by hardware reconfigured {}".format(fauxfactory.gen_alpha(length=4)), active=True, based_on="VM and Instance", evaluate=( "Hardware Reconfigured", { "hardware_attribute": "Number of CPU Cores", "operator": "Increased", } ), notification_frequency="1 Minute", emails=email ) request.addfinalizer(alert.delete) setup_for_alerts(request, [alert], vm_name=vm.name) wait_for_ssa_enabled(vm) sockets_count = vm.configuration.hw.sockets for i in range(1, 3): do_scan(vm, rediscover=False) vm.reconfigure(changes={"cpu": True, "sockets": str(sockets_count + i), "disks": ()}) service_request = appliance.collections.requests.instantiate( description=service_request_desc.format(vm.name, sockets_count + i)) service_request.wait_for_request(method="ui", num_sec=300, delay=10) wait_for_alert( smtp_test, alert, delay=30 * 60, additional_checks={"text": vm.name, "from_address": email} )
def new_user(appliance, group_only_user_owned): user = appliance.collections.users.create( name=fauxfactory.gen_alphanumeric(start="user_"), credential=new_credential(), email=fauxfactory.gen_email(), groups=[group_only_user_owned], cost_center='Workload', value_assign='Database') return user
def admin_email(appliance): """Required for user quota tagging services to work, as it's mandatory for it's functioning.""" user = appliance.collections.users admin = user.instantiate(name='Administrator') with update(admin): admin.email = fauxfactory.gen_email() yield with update(admin): admin.email = ''
def configure_mail(domain): """This fixture copies email instance to custom domain""" approver = fauxfactory.gen_email() default_recipient = fauxfactory.gen_email() from_user = fauxfactory.gen_email() domain.parent.instantiate(name="ManageIQ").namespaces.instantiate( name="Configuration" ).classes.instantiate(name="Email").instances.instantiate(name="Default").copy_to(domain.name) instance = ( domain.namespaces.instantiate(name="Configuration").classes.instantiate(name="Email") ).instances.instantiate(name="Default") with update(instance): instance.fields = { "approver": {"value": approver}, "default_recipient": {"value": default_recipient}, "from": {"value": from_user}, } yield approver, default_recipient, from_user
def new_user(appliance, new_group, new_credential): collection = appliance.collections.users user = collection.create(name=fauxfactory.gen_alphanumeric(start="user_"), credential=new_credential, email=fauxfactory.gen_email(), groups=new_group, cost_center='Workload', value_assign='Database') yield user user.delete()
def test_project_quota_enforce_via_lifecycle_cloud( request, appliance, provider, new_user_project, set_project_quota, extra_msg, approve, custom_prov_data, prov_data, provisioning, ): """Test Project Quota in UI Polarion: assignee: ghubale casecomponent: Cloud caseimportance: high initialEstimate: 1/8h tags: quota testSteps: 1. Create a project 2. Assign quota to project 3. Provision instance over the assigned project's quota 4. Check whether quota is exceeded or not """ with new_user_project: recursive_update(prov_data, custom_prov_data) recursive_update( prov_data, { "request": { "email": fauxfactory.gen_email(), "first_name": fauxfactory.gen_alphanumeric(), "last_name": fauxfactory.gen_alphanumeric(), "manager_name": "{name}".format(name=fauxfactory.gen_alphanumeric()), } }, ) prov_data.update({"template_name": provisioning["image"]["name"]}) request_description = "Provision from [{template}] to [{vm}{msg}]".format( template=provisioning["image"]["name"], vm=prov_data['catalog']['vm_name'], msg=extra_msg) appliance.collections.cloud_instances.create( prov_data['catalog']['vm_name'], provider, prov_data, auto_approve=approve, override=True, request_description=request_description, ) provision_request = appliance.collections.requests.instantiate(request_description) provision_request.wait_for_request(method="ui") request.addfinalizer(provision_request.remove_request) assert provision_request.row.reason.text == "Quota Exceeded"
def test_alert_hardware_reconfigured(request, configure_fleecing, alert_collection, smtp_test, full_template_vm, requests_collection, setup_for_alerts): """Tests alert based on "Hardware Reconfigured" evaluation. According https://bugzilla.redhat.com/show_bug.cgi?id=1396544 Hardware Reconfigured alerts require drift history. So here are the steps for triggering hardware reconfigured alerts based on CPU Count: 1. Run VM smart state analysis. 2. Change CPU count. 3. Run VM smart state analysis again. 4. Run VM reconfigure again. Then the alert for CPU count change should be triggered. It is either CPU increased or decreased depending on what has been done in your step 2, not the result of step 4. Step 4 is just to trigger the event. Polarion: assignee: jdupuy casecomponent: Control initialEstimate: 1/4h """ vm = full_template_vm email = fauxfactory.gen_email() service_request_desc = ("VM Reconfigure for: {0} - Processor Sockets: {1}, " "Processor Cores Per Socket: 1, Total Processors: {1}") alert = alert_collection.create( "Trigger by hardware reconfigured {}".format(fauxfactory.gen_alpha(length=4)), active=True, based_on="VM and Instance", evaluate=( "Hardware Reconfigured", { "hardware_attribute": "Number of CPU Cores", "operator": "Increased", } ), notification_frequency="1 Minute", emails=email ) request.addfinalizer(alert.delete) setup_for_alerts(request, [alert], vm_name=vm.name) wait_for_ssa_enabled(vm) sockets_count = vm.configuration.hw.sockets for i in range(1, 3): do_scan(vm, rediscover=False) vm.reconfigure(changes={"cpu": True, "sockets": str(sockets_count + i), "disks": ()}) service_request = requests_collection.instantiate( description=service_request_desc.format(vm.name, sockets_count + i)) service_request.wait_for_request(method="ui", num_sec=300, delay=10) wait_for_alert( smtp_test, alert, delay=30 * 60, additional_checks={"text": vm.name, "from_address": email} )
def new_user(appliance, new_group, new_credential): collection = appliance.collections.users user = collection.create( name='user_{}'.format(fauxfactory.gen_alphanumeric()), credential=new_credential, email=fauxfactory.gen_email(), groups=new_group, cost_center='Workload', value_assign='Database') yield user user.delete()
def test_action_cancel_clone( appliance, request, provider, vm_big, policy_for_testing, compliance_policy ): """This test checks if 'Cancel vCenter task' action works. For this test we need big template otherwise CFME won't have enough time to cancel the task https://bugzilla.redhat.com/show_bug.cgi?id=1383372#c9 Metadata: test_flag: policy, actions Bugzilla: 1383372 1685201 Polarion: assignee: dgaikwad initialEstimate: 1/4h casecomponent: Control """ with update(policy_for_testing): policy_for_testing.scope = "fill_field(VM and Instance : Name, INCLUDES, {})".format( vm_big.name ) with update(compliance_policy): compliance_policy.scope = "fill_field(VM and Instance : Name, INCLUDES, {})".format( vm_big.name ) policy_for_testing.assign_events("VM Clone Start") policy_for_testing.assign_actions_to_event("VM Clone Start", ["Cancel vCenter Task"]) clone_vm_name = f"{vm_big.name}-clone" @request.addfinalizer def finalize(): policy_for_testing.unassign_events("VM Clone Start") collection = provider.appliance.provider_based_collection(provider) collection.instantiate(clone_vm_name, provider).cleanup_on_provider() # reset the policy scope to the original vm with update(policy_for_testing): policy_for_testing.scope = "fill_field(VM and Instance : Name, INCLUDES, {})".format( vm.name ) with update(compliance_policy): compliance_policy.scope = "fill_field(VM and Instance : Name, INCLUDES, {})".format( vm.name ) vm_big.clone_vm(fauxfactory.gen_email(), "first", "last", clone_vm_name, "VMware") request_description = clone_vm_name clone_request = appliance.collections.requests.instantiate( description=request_description, partial_check=True ) clone_request.wait_for_request(method="ui") assert clone_request.status == "Error"
def test_action_cancel_clone( appliance, request, provider, vm_big, policy_for_testing, compliance_policy ): """This test checks if 'Cancel vCenter task' action works. For this test we need big template otherwise CFME won't have enough time to cancel the task https://bugzilla.redhat.com/show_bug.cgi?id=1383372#c9 Metadata: test_flag: policy, actions Bugzilla: 1383372 1685201 Polarion: assignee: jdupuy initialEstimate: 1/4h casecomponent: Control """ with update(policy_for_testing): policy_for_testing.scope = "fill_field(VM and Instance : Name, INCLUDES, {})".format( vm_big.name ) with update(compliance_policy): compliance_policy.scope = "fill_field(VM and Instance : Name, INCLUDES, {})".format( vm_big.name ) policy_for_testing.assign_events("VM Clone Start") policy_for_testing.assign_actions_to_event("VM Clone Start", ["Cancel vCenter Task"]) clone_vm_name = "{}-clone".format(vm_big.name) @request.addfinalizer def finalize(): policy_for_testing.unassign_events("VM Clone Start") collection = provider.appliance.provider_based_collection(provider) collection.instantiate(clone_vm_name, provider).cleanup_on_provider() # reset the policy scope to the original vm with update(policy_for_testing): policy_for_testing.scope = "fill_field(VM and Instance : Name, INCLUDES, {})".format( vm.name ) with update(compliance_policy): compliance_policy.scope = "fill_field(VM and Instance : Name, INCLUDES, {})".format( vm.name ) vm_big.clone_vm(fauxfactory.gen_email(), "first", "last", clone_vm_name, "VMware") request_description = clone_vm_name clone_request = appliance.collections.requests.instantiate( description=request_description, partial_check=True ) clone_request.wait_for_request(method="ui") assert clone_request.status == "Error"
def new_user(appliance, new_group_list, new_credential): """Fixture is used to Create new user and User should be member of three groups. """ collection = appliance.collections.users user = collection.create(name=fauxfactory.gen_alphanumeric(start="user_"), credential=new_credential, email=fauxfactory.gen_email(), groups=new_group_list, cost_center='Workload', value_assign='Database') yield user if user.exists: user.delete()
def valid_settings_values(): """Returns a list of valid settings values""" return [ gen_email(gen_string('alpha')), gen_email(gen_string('alphanumeric')), gen_email(gen_string('latin1')), gen_email(gen_string('numeric')), gen_email(gen_string('utf8')), gen_email(gen_string('html')), gen_email(gen_string('alphanumeric', 40)), ]
def valid_settings_values(): """Returns a list of valid settings values""" return [ gen_email(gen_string("alpha")), gen_email(gen_string("alphanumeric")), gen_email(gen_string("latin1")), gen_email(gen_string("numeric")), gen_email(gen_string("utf8")), gen_email(gen_string("html")), gen_email(gen_string("alphanumeric", 40)), ]
def new_user_project(appliance, new_group_project): """This fixture creates new user which is assigned to new group and project""" user = appliance.collections.users.create( name=fauxfactory.gen_alphanumeric(start="user_").lower(), credential=Credential(principal=fauxfactory.gen_alphanumeric(start="uid"), secret=fauxfactory.gen_alphanumeric(start="pwd")), email=fauxfactory.gen_email(), groups=new_group_project, cost_center="Workload", value_assign="Database", ) yield user user.delete_if_exists()
def new_user(appliance, new_group_list, new_credential): """Fixture is used to Create new user and User should be member of three groups. """ collection = appliance.collections.users user = collection.create( name='user_{}'.format(fauxfactory.gen_alphanumeric()), credential=new_credential, email=fauxfactory.gen_email(), groups=new_group_list, cost_center='Workload', value_assign='Database') yield user if user.exists: user.delete()
def new_user_child(appliance, new_group_child): """This fixture creates new user which assigned to new child tenant""" user = appliance.collections.users.create( name="user_{}".format(fauxfactory.gen_alphanumeric().lower()), credential=Credential(principal='uid{}'.format(fauxfactory.gen_alphanumeric(4)), secret='{password}'.format(password=fauxfactory.gen_alphanumeric(4))), email=fauxfactory.gen_email(), groups=new_group_child, cost_center="Workload", value_assign="Database", ) yield user if user.exists: user.delete()
def test_gen_email_1(self): """ @Test: Create a random email value @Feature: Email Generator @Assert: A random email value is generated """ # Regex for email validation emailinator = re.compile(REGEX) for turn in range(100): result = gen_email() self.assertIsNotNone( emailinator.match(result), "A valid email value was not generated.")
def test_positive_update_email(self): """Update Email Address in My Account :id: 1c535b77-36d8-44d1-aaf0-07e0ca4eeb28 :Steps: Update current User with with Email :expectedresults: Current User is updated :CaseImportance: Critical """ with Session(self, self.account_user.login, self.account_password): email = gen_email() self.my_account.update(email=email) self.assertEqual(email, self.my_account.get_field_value('email'))
def create_user(username=None, password=None, email=None, default_organization=None, default_locale=None): """Creates an user""" if username is None: username = gen_string("alphanumeric", 10) if password is None: password = gen_string("alphanumeric", 10) if email is None: email = gen_email("alphanumeric", 10) cmd = 'user create --username {0} --password {1} --email {2}'.format( username, password, email) if default_organization is not None: cmd = cmd + ' --default_organization {0}'.format(default_organization) if default_locale is not None: cmd = cmd + ' --default_locale {0}'.format(default_locale) run_command(cmd) return username
def test_alert_vm_turned_on_more_than_twice_in_past_15_minutes(request, provider, vm, smtp_test, register_event, alert_collection, setup_for_alerts): """ Tests alerts for vm turned on more than twice in 15 minutes Metadata: test_flag: alerts, provision """ alert = alert_collection.create("VM Power On > 2 in last 15 min") with update(alert): alert.active = True alert.emails = fauxfactory.gen_email() setup_for_alerts(request, [alert], "VM Power On", vm.name, provider) if not provider.mgmt.is_vm_stopped(vm.name): provider.mgmt.stop_vm(vm.name) provider.refresh_provider_relationships() # preparing events to listen to register_event(target_type='VmOrTemplate', target_name=vm.name, event_type='request_vm_poweroff') register_event(target_type='VmOrTemplate', target_name=vm.name, event_type='vm_poweoff') vm.wait_for_vm_state_change(vm.STATE_OFF) for i in range(5): vm.power_control_from_cfme(option=vm.POWER_ON, cancel=False) register_event(target_type='VmOrTemplate', target_name=vm.name, event_type='request_vm_start') register_event(target_type='VmOrTemplate', target_name=vm.name, event_type='vm_start') wait_for(lambda: provider.mgmt.is_vm_running(vm.name), num_sec=300) vm.wait_for_vm_state_change(vm.STATE_ON) vm.power_control_from_cfme(option=vm.POWER_OFF, cancel=False) register_event(target_type='VmOrTemplate', target_name=vm.name, event_type='request_vm_poweroff') register_event(target_type='VmOrTemplate', target_name=vm.name, event_type='vm_poweroff') wait_for(lambda: provider.mgmt.is_vm_stopped(vm.name), num_sec=300) vm.wait_for_vm_state_change(vm.STATE_OFF) wait_for_alert(smtp_test, alert, delay=16 * 60)
def new_instance(provider): prov_data = provider.data['provisioning'] instance = OpenStackInstance(fauxfactory.gen_alpha(), provider, template_name=prov_data['image']['name']) prov_form_data = { 'request': {'email': fauxfactory.gen_email(), 'first_name': fauxfactory.gen_alpha(), 'last_name': fauxfactory.gen_alpha()}, 'catalog': {'num_vms': '1', 'vm_name': instance.name}, 'environment': {'cloud_network': prov_data['cloud_network']}, 'properties': {'instance_type': prov_data['instance_type']}, } instance.create(False, **prov_form_data) instance.wait_to_appear() yield instance try: instance.power_control_from_provider(OpenStackInstance.TERMINATE) except: pass
def test_vm_migration_after_assigning_tenant_quota(appliance, setup_provider, small_vm, set_roottenant_quota, custom_prov_data, provider): """prerequisite: Provider should be added steps: 1. Create VM 2. Assign tenant quota 3. Migrate VM 4. Check whether migration is successfully done """ migrate_to = check_hosts(small_vm, provider) small_vm.migrate_vm(fauxfactory.gen_email(), fauxfactory.gen_alpha(), fauxfactory.gen_alpha(), host=migrate_to) request_description = small_vm.name cells = {'Description': request_description, 'Request Type': 'Migrate'} migrate_request = appliance.collections.requests.instantiate(request_description, cells=cells, partial_check=True) migrate_request.wait_for_request(method='ui') msg = "Request failed with the message {}".format(migrate_request.row.last_message.text) assert migrate_request.is_succeeded(method='ui'), msg
def test_send_email_method(smtp_test, klass): """ Polarion: assignee: ghubale initialEstimate: 1/20h startsin: 5.10 casecomponent: Automate Bugzilla: 1688500 1702304 """ mail_to = fauxfactory.gen_email() mail_cc = fauxfactory.gen_email() mail_bcc = fauxfactory.gen_email() # Ruby code to send emails script = ( 'to = "{mail_to}"\n' 'subject = "Hello"\n' 'body = "Hi"\n' 'bcc = "{mail_bcc}"\n' 'cc = "{mail_cc}"\n' 'content_type = "message"\n' 'from = "*****@*****.**"\n' "$evm.execute(:send_email, to, from, subject, body, {{:bcc => bcc, :cc => cc," ":content_type => content_type}})" ) script = script.format(mail_cc=mail_cc, mail_bcc=mail_bcc, mail_to=mail_to) # Adding schema for executing method - send_email which helps to send emails klass.schema.add_fields({'name': 'execute', 'type': 'Method', 'data_type': 'String'}) # Adding method - send_email for sending mails method = klass.methods.create( name=fauxfactory.gen_alphanumeric(), display_name=fauxfactory.gen_alphanumeric(), location='inline', script=script) # Adding instance to call automate method - send_email instance = klass.instances.create( name=fauxfactory.gen_alphanumeric(), display_name=fauxfactory.gen_alphanumeric(), description=fauxfactory.gen_alphanumeric(), fields={'execute': {'value': method.name}} ) result = LogValidator( "/var/www/miq/vmdb/log/evm.log", matched_patterns=[ '.*:to=>"{mail_to}".*.*:cc=>"{mail_cc}".*.*:bcc=>"{mail_bcc}".*'.format( mail_to=mail_to, mail_cc=mail_cc, mail_bcc=mail_bcc ) ], ) result.fix_before_start() # Executing automate method - send_email using simulation simulate( appliance=klass.appliance, attributes_values={ "namespace": klass.namespace.name, "class": klass.name, "instance": instance.name, }, message="create", request="Call_Instance", execute_methods=True, ) result.validate_logs() # TODO(GH-8820): This issue should be fixed to check mails sent to person in 'cc' and 'bcc' # Check whether the mail sent via automate method really arrives wait_for(lambda: len(smtp_test.get_emails(to_address=mail_to)) > 0, num_sec=60, delay=10)
def test_dynamic_product_feature_for_tenant_quota(request, appliance, new_tenant, child_tenant): """ Polarion: assignee: ghubale initialEstimate: 1/12h caseimportance: high caseposneg: positive testtype: functional startsin: 5.10 casecomponent: Configuration tags: quota testSteps: 1. Add two users > alpha and omega 2. Create two tenants > alpha_tenant and it's child - omega_tenant 3. Create two custom roles (role_alpha and role_omega) from copying EvmRole-tenant-administrator role 4. Create groups alpha_group(for alpha_tenant) and omega_group(for omega_tenant) then assign role_alpha to alpha_group and role_omega to omega_group 5. Add alpha_group to alpha user and omega_group to omega user 6. Modify role_alpha for manage quota permissions of alpha user as it will manage only quota of omega_tenant 7. Modify role_omega for manage quota permissions of omega user as it will not even manage quota of itself or other tenants 8. CHECK IF YOU ARE ABLE TO MODIFY THE "MANAGE QUOTA" CHECKS IN ROLE AS YOU WANT 9. Then see if you are able to save these two new roles. 10.Login with alpha and SEE IF ALPHA USER CAN ABLE TO SET QUOTA OF omega_tenant 11.Login with omega and SEE QUOTA GETS CHANGED OR NOT. THEN TRY TO CHANGE QUOTA IMPOSED BY ALPHA USER. expectedResults: 1. 2. 3. 4. 5. 6. 7. 8. 9. Save roles successfully 10. 'Manage Quotas' option should be available for user alpha 11. Here as per role_omega permissions, omega must not able change its own quota or other tenants quota. Bugzilla: 1655012 1468795 """ user_ = [] role_ = [] # List of two tenants with their parents to assign to two different groups tenant_ = ["My Company/{parent}".format(parent=new_tenant.name), "My Company/{parent}/{child}".format(parent=new_tenant.name, child=child_tenant.name)] # Instantiating existing role - 'EvmRole-tenant_administrator' to copy it to new role role = appliance.collections.roles.instantiate(name='EvmRole-tenant_administrator') for i in range(2): # Creating two different RBAC roles for two different users new_role = role.copy(name="{name}_{role}".format(name=role.name, role=fauxfactory.gen_alphanumeric())) role_.append(new_role) request.addfinalizer(new_role.delete_if_exists) # Creating two different groups with assigned custom roles and tenants group = appliance.collections.groups.create( description="group_{}".format(fauxfactory.gen_alphanumeric()), role=new_role.name, tenant=tenant_[i] ) request.addfinalizer(group.delete_if_exists) # Creating two different users which are assigned with different groups user = appliance.collections.users.create( name="user_{}".format(fauxfactory.gen_alphanumeric().lower()), credential=Credential( principal="uid{}".format(fauxfactory.gen_alphanumeric(4)), secret="{password}".format(password=fauxfactory.gen_alphanumeric(4)), ), email=fauxfactory.gen_email(), groups=group, cost_center="Workload", value_assign="Database", ) user_.append(user) request.addfinalizer(user.delete_if_exists) # Updating roles for users with PRODUCT_FEATURES tree. It restrict user from the # tenants for which this role does not have access. # Here PRODUCT_FEATURES[0] is the tree path navigation for updating RBAC role for tenant1 # (parent tenant) from TENANTS list. # Here PRODUCT_FEATURES[1] is the tree path navigation for updating RBAC role for tenant2 # (child tenant) from TENANTS list. # role_[0] and role_[1] is the first and second role from the list of two role created # above; Providing 'False' while updating role means it restrict user from accessing that # particular tenant. role_[i].update({'product_features': [(PRODUCT_FEATURES[i], False)]}) # Logged in with user1 and then checking; this user should not have access of manage quota for # tenant1(parent tenant). with user_[0]: check_permissions(appliance=appliance, assigned_tenant=new_tenant.name) # Logged in with user2 and then checking; this user should not have access of manage quota for # tenant2(child tenant). with user_[1]: check_permissions(appliance=appliance, assigned_tenant=child_tenant.name)
def gen_value(self): """Return a value suitable for a :class:`EmailField`.""" # pylint:disable=no-self-use # See comment near top of module. return gen_email()
def get_value(self): """Return a value suitable for a :class:`EmailField`.""" return gen_email()