def tag(category): tag = Tag(name=fauxfactory.gen_alpha(8).lower(), display_name=fauxfactory.gen_alphanumeric(length=32), category=category) tag.create() yield tag tag.delete()
def tag(category): """ Returns random created tag object Object can be used in all test run session """ tag = Tag(name=fauxfactory.gen_alpha(8).lower(), display_name=fauxfactory.gen_alphanumeric(length=32), category=category) tag.create() yield tag tag.delete(False)
def test_retirement_now_ec2_instance_backed(retire_ec2_s3_vm, tagged): """Tests on-demand retirement of an instance/vm S3 (instance-backed) EC2 instances that aren't lifecycle tagged won't get shut down """ # Tag the VM with lifecycle for full retirement based on parameter if tagged: retire_ec2_s3_vm.add_tag( Tag(display_name='LifeCycle', category=Category( display_name='Fully retire VM and remove from Provider'))) expected_power_state = ['terminated'] else: # no tagging expected_power_state = ['on'] # For 5.7+ capture two times to assert the retire time is within a window. # Too finicky to get it down to minute precision, nor is it really needed here retire_times = dict() retire_times['start'] = generate_retirement_date_now() + timedelta(minutes=-5) retire_ec2_s3_vm.retire() view_cls = navigator.get_class(retire_ec2_s3_vm, 'Details').VIEW reload = retire_ec2_s3_vm.appliance.browser.create_view(view_cls).toolbar.reload assert wait_for(lambda: retire_ec2_s3_vm.is_retired, delay=5, num_sec=10 * 60, fail_func=reload.click, message="Wait for VM '{}' to enter retired state" .format(retire_ec2_s3_vm.name)) view = retire_ec2_s3_vm.load_details() assert view.entities.power_management.get_text_of('Power State') in expected_power_state retire_times['end'] = generate_retirement_date_now() + timedelta(minutes=5) verify_retirement_date(retire_ec2_s3_vm, expected_date=retire_times)
def get_tags(self, tenant="My Company Tags"): """Overridden get_tags method to deal with the fact that configured systems don't have a details view.""" view = navigate_to(self, 'EditTags') return [Tag(category=Category(display_name=r.category.text.replace('*', '').strip()), display_name=r.assigned_value.text.strip()) for r in view.form.tags]
def test_drift_analysis(request, ssa_vm, soft_assert, appliance): """ Tests drift analysis is correct Metadata: test_flag: vm_analysis """ ssa_vm.load_details() drift_num_orig = 0 view = navigate_to(ssa_vm, "Details") drift_orig = view.entities.summary("Relationships").get_text_of("Drift History") if drift_orig != 'None': drift_num_orig = int(drift_orig) ssa_vm.smartstate_scan(wait_for_task_result=True) view = navigate_to(ssa_vm, "Details") wait_for( lambda: view.entities.summary("Relationships").get_text_of( "Drift History") == str(drift_num_orig + 1), delay=20, num_sec=360, message="Waiting for Drift History count to increase", fail_func=view.toolbar.reload.click ) drift_new = int(view.entities.summary("Relationships").get_text_of("Drift History")) # add a tag and a finalizer to remove it added_tag = Tag(display_name='Accounting', category=Category(display_name='Department')) ssa_vm.add_tag(added_tag) request.addfinalizer(lambda: ssa_vm.remove_tag(added_tag)) ssa_vm.smartstate_scan(wait_for_task_result=True) view = navigate_to(ssa_vm, "Details") wait_for( lambda: view.entities.summary("Relationships").get_text_of( "Drift History") == str(drift_new + 1), delay=20, num_sec=360, message="Waiting for Drift History count to increase", fail_func=view.toolbar.reload.click ) # check drift difference soft_assert(ssa_vm.equal_drift_results( '{} (1)'.format(added_tag.category.display_name), 'My Company Tags', 0, 1), "Drift analysis results are equal when they shouldn't be") # Test UI features that modify the drift grid drift_analysis_view = appliance.browser.create_view(DriftAnalysis) # Accounting tag should not be displayed, because it was changed to True drift_analysis_view.toolbar.same_values_attributes.click() soft_assert( not drift_analysis_view.drift_analysis.check_section_attribute_availability( '{}'.format(added_tag.category.display_name)), "{} row should be hidden, but not".format(added_tag.display_name)) # Accounting tag should be displayed now drift_analysis_view.toolbar.different_values_attributes.click() soft_assert( drift_analysis_view.drift_analysis.check_section_attribute_availability( '{} (1)'.format(added_tag.category.display_name)), "{} row should be visible, but not".format(added_tag.display_name))
def get_tags_db(self): """ Gets tags detail from database Column order: `tag_id`, `db_id`, `category`, `tag_name`, `single_value` """ # Some times object of db_id might changed in database, when we do CRUD operations, # do update now self.load_details(refresh=True) if not self.db_id or not self.taggable_type: raise KeyError("'db_id' and/or 'taggable_type' not set") t_cls1 = aliased(self.appliance.db.client['classifications']) t_cls2 = aliased(self.appliance.db.client['classifications']) t_tgg = aliased(self.appliance.db.client['taggings']) query = self.appliance.db.client.session.query( t_cls1.tag_id, t_tgg.taggable_id.label('db_id'), t_cls2.description.label('category'), t_cls1.description.label('tag_name'), t_cls1.single_value)\ .join(t_cls2, t_cls1.parent_id == t_cls2.id)\ .join(t_tgg, t_tgg.tag_id == t_cls1.tag_id)\ .filter(t_tgg.taggable_id == self.db_id)\ .filter(t_tgg.taggable_type == self.taggable_type) tags = [] for tag in query.all(): tags.append(Tag(category=Category(display_name=tag.category, single_value=tag.single_value), display_name=tag.tag_name)) return tags
def get_tags(self, tenant="My Company Tags"): """ Get list of tags assigned to item. Details entities should have smart_management widget For vm, providers, and other like pages 'SummaryTable' widget should be used, for user, group like pages(no tables on details page) use 'SummaryForm' Args: tenant: string, tags tenant, default is "My Company Tags" Returns: :py:class:`list` List of Tag objects """ view = navigate_to(self, 'Details') tags = [] entities = view.entities if hasattr(entities, 'smart_management'): tag_table = entities.smart_management else: tag_table = entities.summary('Smart Management') tags_text = tag_table.get_text_of(tenant) if tags_text != 'No {} have been assigned'.format(tenant): # check for users/groups page in case one tag string is returned for tag in [tags_text] if isinstance( tags_text, six.string_types) else list(tags_text): tag_category, tag_name = tag.split(':') tags.append( Tag(category=Category(display_name=tag_category), display_name=tag_name.strip())) return tags
def set_entity_quota_tag(request, entities, appliance): tag, value = request.param tag = Tag(display_name=value, category=Category(display_name=tag)) entities.add_tag(tag) yield # will refresh page as navigation to configuration is blocked if alert are on requests page appliance.server.browser.refresh() entities.remove_tag(tag)
def get_tags(self, tag="My Company Tags"): self.load_details(refresh=True) tags = [] # Sample out put from UI, [u'Department: Accounting | Engineering', u'Location: London'] for _tag in mixins.get_tags(tag=tag): if _tag == 'No {} have been assigned'.format(tag): return tags _tag = _tag.split(':', 1) if len(_tag) != 2: raise RuntimeError('Unknown format of tagging in UI [{}]'.format(_tag)) if ' | ' in _tag[1]: for _sub_tag in _tag[1].split(' | '): tags.append(Tag(category=Category(display_name=tag[0], single_value=None), display_name=_sub_tag.strip())) else: tags.append(Tag(category=Category(display_name=_tag[0], single_value=None), display_name=_tag[1].strip())) return tags
def test_tag_crud(category): tag = Tag(name=fauxfactory.gen_alphanumeric(8).lower(), display_name=fauxfactory.gen_alphanumeric(32), category=category) tag.create() with update(tag): tag.display_name = fauxfactory.gen_alphanumeric(32) tag.delete(cancel=False)
def add_tag(self, tag=None, cancel=False, reset=False, details=True): # ToDo remove when taggable use random object if not tag: tag = Tag(display_name='Cost Center 001', category=Category(display_name='Cost Center')) Taggable.add_tag(self, tag=tag, cancel=cancel, reset=reset, details=details) return tag
def _set_random_tag(self, view): random_cat = random.choice(view.form.tag_category.all_options).text # '*' is added in UI almost to all categoly while tag selection, # but doesn't need for Category object creation random_cat_cut = random_cat[:-1].strip() if random_cat[-1] == '*' else random_cat view.form.tag_category.fill(random_cat) # In order to get the right tags list we need to select category first to get loaded tags random_tag = random.choice([tag_option for tag_option in view.form.tag_name.all_options if "select" not in tag_option.text.lower()]).text tag = Tag(display_name=random_tag, category=Category(display_name=random_cat_cut)) return tag
def tag(category): tag = Tag(name=fauxfactory.gen_alpha(8).lower(), display_name=fauxfactory.gen_alphanumeric(length=32), category=category) tag.create() yield tag tag.delete()
def set_random_tag(instance): view = navigate_to(instance, 'EditTags') logger.debug("Setting random tag") random_cat = random.choice(view.form.tag_category.all_options).text view.form.tag_category.select_by_visible_text(random_cat) # In order to get the right tags list logger.debug("Selected category {cat}".format(cat=random_cat)) random_tag = random.choice([op for op in view.form.tag_name.all_options if "select" not in op.text.lower()]).text logger.debug("Selected value {tag}".format(tag=random_tag)) tag = Tag(display_name=random_tag, category=random_cat) instance.add_tag(tag, details=False) logger.debug("Tag configuration was saved") return tag
def test_tag_crud(category): tag = Tag(name=fauxfactory.gen_alphanumeric(8).lower(), display_name=fauxfactory.gen_alphanumeric(32), category=category) tag.create() with update(tag): tag.display_name = fauxfactory.gen_alphanumeric(32) tag.delete(cancel=False)
def tag(category): """ Returns random created tag object Object can be used in all test run session """ tag = Tag(name=fauxfactory.gen_alpha(8).lower(), display_name=fauxfactory.gen_alphanumeric(length=32), category=category) tag.create() yield tag tag.delete(False)
def get_tags(self, tenant="My Company Tags"): """ Get list of tags assigned to item. Details entities should have smart_management widget For vm, providers, and other like pages 'SummaryTable' widget should be used, for user, group like pages(no tables on details page) use 'SummaryForm' Args: tenant: string, tags tenant, default is "My Company Tags" Returns: :py:class:`list' List of Tag objects """ view = navigate_to(self, 'Details') tags = [] tag_table = view.entities.smart_management tags_text = tag_table.get_text_of(tenant) if tags_text != 'No {} have been assigned'.format(tenant): for tag in list(tags_text): tag_category, tag_name = tag.split(':') tags.append(Tag(category=Category(display_name=tag_category), display_name=tag_name.strip())) return tags
def set_random_tag(instance): logger.debug("Setting random tag") navigate_to(instance, 'Details') toolbar.select('Policy', 'Edit Tags') # select random tag category cat_selector = AngularSelect("tag_cat") random_cat = random.choice(cat_selector.all_options) logger.debug("Selected category {cat}".format(cat=random_cat)) cat_selector.select_by_value(random_cat.value) # select random tag tag tag_selector = AngularSelect("tag_add") random_tag = random.choice( [op for op in tag_selector.all_options if op.value != "select"]) logger.debug("Selected value {tag}".format(tag=random_tag)) tag_selector.select_by_value(random_tag.value) # Save tag conig form_buttons.save() logger.debug("Tag configuration was saved") return Tag(display_name=random_tag.text, category=random_cat.text)
def location_tag(): """Existing tag object""" category = Category(name='location', display_name='Location') tag = Tag(name='paris', display_name='Paris', category=category) return tag
from cfme.middleware.deployment import MiddlewareDeployment from cfme.middleware.domain import MiddlewareDomain from cfme.middleware.server_group import MiddlewareServerGroup from cfme.middleware.messaging import MiddlewareMessaging from random_methods import get_random_object from cfme.utils.version import current_version pytestmark = [ pytest.mark.usefixtures('setup_provider'), pytest.mark.uncollectif(lambda: current_version() < '5.7'), pytest.mark.provider([HawkularProvider], scope="function"), ] tags = [ Tag(category=Category(display_name='Environment', single_value=True), display_name='Test'), Tag(category=Category(display_name='Workload', single_value=False), display_name='Application Servers'), ] @pytest.mark.parametrize("objecttype", [MiddlewareDatasource, MiddlewareDeployment, HawkularProvider, MiddlewareServer, MiddlewareDomain, MiddlewareMessaging, MiddlewareServerGroup]) def test_object_tags(provider, objecttype): """Tests tags in all taggable pages Steps: * Select a taggable object of provided objecttype randomly from database * Run `_validate_tags` with `tags` input
def service_level_tag(): """Existing tag object""" category = Category(name='service_level', display_name='Service Level') tag = Tag(name='silver', display_name='Silver', category=category) return tag
def test_host_drift_analysis(appliance, request, a_host, soft_assert, set_host_credentials): """Tests host drift analysis Metadata: test_flag: host_drift_analysis """ # tabs changed, hack until configure.tasks is refactored for collections and versioned widgets destination = 'AllTasks' if appliance.version >= '5.9' else 'AllOtherTasks' # get drift history num view = navigate_to(a_host, 'Details') drift_num_orig = int(view.entities.summary('Relationships').get_text_of('Drift History')) # clear table delete_all_tasks(destination) # initiate 1st analysis a_host.run_smartstate_analysis(wait_for_task_result=True) # wait for for drift history num+1 navigate_to(a_host, 'Details') wait_for( lambda: (view.entities.summary('Relationships').get_text_of('Drift History') == str(drift_num_orig + 1)), delay=20, num_sec=360, message="Waiting for Drift History count to increase", fail_func=appliance.server.browser.refresh ) # add a tag and a finalizer to remove it added_tag = Tag(display_name='Accounting', category=Category(display_name='Department')) a_host.add_tag(added_tag) request.addfinalizer(lambda: a_host.remove_tag(added_tag)) # initiate 2nd analysis a_host.run_smartstate_analysis(wait_for_task_result=True) # wait for for drift history num+2 navigate_to(a_host, 'Details') wait_for( lambda: (view.entities.summary('Relationships').get_text_of('Drift History') == str(drift_num_orig + 2)), delay=20, num_sec=360, message="Waiting for Drift History count to increase", fail_func=appliance.server.browser.refresh ) # check drift difference soft_assert(a_host.equal_drift_results( '{} (1)'.format(added_tag.category.display_name), 'My Company Tags', 0, 1), "Drift analysis results are equal when they shouldn't be") # Test UI features that modify the drift grid drift_analysis_view = appliance.browser.create_view(HostDriftAnalysis) # Accounting tag should not be displayed, because it was changed to True drift_analysis_view.toolbar.same_values_attributes.click() soft_assert( not drift_analysis_view.drift_analysis.check_section_attribute_availability( '{}'.format(added_tag.category.display_name)), "{} row should be hidden, but not".format(added_tag.display_name)) # Accounting tag should be displayed now drift_analysis_view.toolbar.different_values_attributes.click() soft_assert( drift_analysis_view.drift_analysis.check_section_attribute_availability( '{} (1)'.format(added_tag.category.display_name)), "{} row should be visible, but not".format(added_tag.display_name))