def test_negative_delete_rule_with_non_admin_user(self, class_org, class_location, class_user_password, class_user_reader, class_hostgroup): """Delete rule with non-admin user by associating discovery_reader role :id: f7f9569b-916e-46f3-bd89-a05e33483741 :expectedresults: User should validation error and rule should not be deleted successfully. :CaseLevel: Integration """ rule = AttrDict( make_discoveryrule({ 'enabled': 'false', 'search': "last_report = Today", 'organizations': class_org.name, 'locations': class_location.name, 'hostgroup-id': class_hostgroup.id, })) rule = AttrDict( DiscoveryRule.with_user(class_user_reader.login, class_user_password).info({'id': rule.id})) with pytest.raises(CLIReturnCodeError): DiscoveryRule.with_user(class_user_reader.login, class_user_password).delete( {'id': rule.id})
def _create_discoveryrule(org, loc, hostgroup, options=None): """Makes a new discovery rule and asserts its success""" options = options or {} searches = [ 'cpu_count = 1', 'disk_count < 5', 'memory > 500', 'model = KVM', 'Organization = Default_Organization', 'last_report = Today', 'subnet = 192.168.100.0', 'facts.architecture != x86_64', ] if not any( options.get(key) for key in ['organizations', 'organization-ids']): options['organization-ids'] = org.id if not any( options.get(key) for key in ['locations', 'locations-ids']): options['location-ids'] = loc.id if not any( options.get(key) for key in ['hostgroup', 'hostgroup-ids']): options['hostgroup-id'] = hostgroup.id if options.get('search') is None: options['search'] = gen_choice(searches) # create a simple object from the dictionary that the CLI factory provides # This allows for consistent attributized access of all fixture entities in the tests return AttrDict(make_discoveryrule(options))
def test_positive_view_existing_rule_with_non_admin_user( self, class_org, class_location, class_user_password, class_user_reader, class_hostgroup): """Existing rule should be viewed to non-admin user by associating discovery_reader role. :id: 7b1d90b9-fc2d-4ccb-93d3-605c2da876f7 :Steps: 1. create a rule with admin user 2. create a non-admin user and assign 'Discovery Reader' role 3. Login with non-admin user :expectedresults: Rule should be visible to non-admin user. :CaseLevel: Integration """ rule_name = gen_string('alpha') rule = AttrDict( make_discoveryrule({ 'name': rule_name, 'enabled': 'false', 'search': "last_report = Today", 'organizations': class_org.name, 'locations': class_location.name, 'hostgroup-id': class_hostgroup.id, })) rule = AttrDict( DiscoveryRule.with_user(class_user_reader.login, class_user_password).info({'id': rule.id})) assert rule.name == rule_name
def test_positive_view_existing_rule_with_non_admin_user(self): """Existing rule should be viewed to non-admin user by associating discovery_reader role. :id: 7b1d90b9-fc2d-4ccb-93d3-605c2da876f7 :Steps: 1. create a rule with admin user 2. create a non-admin user and assign 'Discovery Reader' role 3. Login with non-admin user :expectedresults: Rule should be visible to non-admin user. :CaseLevel: Integration """ rule_name = gen_string('alpha') rule = make_discoveryrule({ u'name': rule_name, u'enabled': 'false', u'search': "last_report = Today", u'organization-ids': self.org['id'], u'location-ids': self.loc['id'], u'hostgroup-id': self.hostgroup['id'], }) rule = DiscoveryRule.with_user(self.user_reader['login'], self.user_reader['password']).info( {u'id': rule['id']}) self.assertEqual(rule['name'], rule_name)
def _make_discoveryrule(self, options=None): """Makes a new discovery rule and asserts its success""" if options is None: options = {} searches = [ 'cpu_count = 1', 'disk_count < 5', 'memory > 500', 'model = KVM', 'Organization = Default_Organization', 'last_report = Today', 'subnet = 192.168.100.0', 'facts.architecture != x86_64', ] if not any( options.get(key) for key in ['organizations', 'organization-ids']): options[u'organization-ids'] = self.org['id'] if not any(options.get(key) for key in ['locations', 'locations-ids']): options[u'location-ids'] = self.loc['id'] if not any(options.get(key) for key in ['hostgroup', 'hostgroup-ids']): options[u'hostgroup-id'] = self.hostgroup['id'] if options.get('search') is None: options[u'search'] = gen_choice(searches) return make_discoveryrule(options)
def test_negative_delete_rule_with_non_admin_user(self): """Delete rule with non-admin user by associating discovery_reader role :id: f7f9569b-916e-46f3-bd89-a05e33483741 :expectedresults: User should validation error and rule should not be deleted successfully. :CaseLevel: Integration """ rule = make_discoveryrule({ u'enabled': 'false', u'search': "last_report = Today", u'organization-ids': self.org['id'], u'location-ids': self.loc['id'], u'hostgroup-id': self.hostgroup['id'], }) rule = DiscoveryRule.with_user( self.user_reader['login'], self.user_reader['password'] ).info({u'id': rule['id']}) with self.assertRaises(CLIReturnCodeError): DiscoveryRule.with_user( self.user_reader['login'], self.user_reader['password'] ).delete({u'id': rule['id']})
def test_positive_view_existing_rule_with_non_admin_user(self): """Existing rule should be viewed to non-admin user by associating discovery_reader role. :id: 7b1d90b9-fc2d-4ccb-93d3-605c2da876f7 :Steps: 1. create a rule with admin user 2. create a non-admin user and assign 'Discovery Reader' role 3. Login with non-admin user :expectedresults: Rule should be visible to non-admin user. :CaseLevel: Integration """ rule_name = gen_string('alpha') rule = make_discoveryrule({ u'name': rule_name, u'enabled': 'false', u'search': "last_report = Today", u'organization-ids': self.org['id'], u'location-ids': self.loc['id'], u'hostgroup-id': self.hostgroup['id'], }) rule = DiscoveryRule.with_user( self.user_reader['login'], self.user_reader['password'] ).info({u'id': rule['id']}) self.assertEqual(rule['name'], rule_name)
def _make_discoveryrule(self, options=None): """Makes a new discovery rule and asserts its success""" if options is None: options = {} searches = [ 'cpu_count = 1', 'disk_count < 5', 'memory > 500', 'model = KVM', 'Organization = Default_Organization', 'last_report = Today', 'subnet = 192.168.100.0', 'facts.architecture != x86_64', ] if not any(options.get(key) for key in [ 'organizations', 'organization-ids' ]): options[u'organization-ids'] = self.org['id'] if not any(options.get(key) for key in ['locations', 'locations-ids']): options[u'location-ids'] = self.loc['id'] if not any(options.get(key) for key in ['hostgroup', 'hostgroup-ids']): options[u'hostgroup-id'] = self.hostgroup['id'] if options.get('search') is None: options[u'search'] = gen_choice(searches) return make_discoveryrule(options)