def test_negative_list_with_parameters(self): """Test Environment List filtering parameters validation. :id: 97872953-e1aa-44bd-9ce0-a04bccbc9e94 :expectedresults: Server returns empty result as there is no environment associated with location :CaseLevel: Integration :BZ: 1337947 """ make_environment({ 'organization-ids': self.org.id, 'location-ids': self.loc.id, }) # Filter by non-existing location and existing organization with self.assertRaises(CLIReturnCodeError): Environment.list({ 'organization-id': self.org.id, 'location-id': gen_string('numeric') }) # Filter by non-existing organization and existing location with self.assertRaises(CLIReturnCodeError): Environment.list({ 'organization-id': gen_string('numeric'), 'location-id': self.loc.id }) # Filter by another location results = Environment.list({ 'organization': self.org.name, 'location': self.loc2.name }) self.assertEqual(len(results), 0)
def test_positive_list_with_org_and_loc_by_name(self): """Test Environment List filtering. :id: 962c6750-f203-4478-8827-651db208ff92 :expectedresults: Results that match both organization and location are returned :CaseLevel: Integration :BZ: 1337947 """ # Create 2 envs with the same organization but different locations org = make_org() locs = [make_location() for _ in range(2)] envs = [ make_environment({ 'organizations': org['name'], 'locations': loc['name'], }) for loc in locs ] results = Environment.list({'organization': org['name']}) # List environments for the whole organization self.assertEqual(len(results), 2) self.assertEqual({env['name'] for env in envs}, {result['name'] for result in results}) # List environments with additional location filtering results = Environment.list({ 'organization': org['name'], 'location': locs[0]['name'], }) self.assertEqual(len(results), 1) self.assertEqual(results[0]['name'], envs[0]['name'])
def test_positive_list_with_org_and_loc_by_name(self): """Test Environment List filtering. :id: 962c6750-f203-4478-8827-651db208ff92 :expectedresults: Results that match both organization and location are returned :CaseLevel: Integration :BZ: 1337947 """ # Create 2 envs with the same organization but different locations org = make_org() locs = [make_location() for _ in range(2)] envs = [make_environment({ 'organizations': org['name'], 'locations': loc['name'], }) for loc in locs] results = Environment.list({'organization': org['name']}) # List environments for the whole organization self.assertEqual(len(results), 2) self.assertEqual( {env['name'] for env in envs}, {result['name'] for result in results} ) # List environments with additional location filtering results = Environment.list({ 'organization': org['name'], 'location': locs[0]['name'], }) self.assertEqual(len(results), 1) self.assertEqual(results[0]['name'], envs[0]['name'])
def test_positive_list_with_org_and_loc_by_id(self): """Test Environment List filtering. :id: 643f7cb5-0817-4b0a-ba5e-434df2033a40 :expectedresults: Results that match both organization and location are returned :CaseLevel: Integration :BZ: 1337947 """ # Create 2 envs with the same organization but different locations org = make_org() locs = [make_location() for _ in range(2)] envs = [ make_environment({ 'organization-ids': org['id'], 'location-ids': loc['id'], }) for loc in locs ] results = Environment.list({'organization-id': org['id']}) # List environments for the whole organization self.assertEqual(len(results), 2) self.assertEqual({env['id'] for env in envs}, {result['id'] for result in results}) # List environments with additional location filtering results = Environment.list({ 'organization-id': org['id'], 'location-id': locs[0]['id'], }) self.assertEqual(len(results), 1) self.assertEqual(results[0]['id'], envs[0]['id'])
def test_negative_list_with_non_existing_org_and_loc_by_name(self): """Test Environment List filtering parameters validation. :id: 38cb48e3-a836-47d0-b8a8-9acd33a30546 :expectedresults: Server returns empty result as there is no environment associated with location :CaseLevel: Integration :BZ: 1337947 """ # Create env with specified organization and location org = make_org() loc = make_location() make_environment({ 'organizations': org['name'], 'locations': loc['name'], }) # Filter by non-existing location and existing organization with self.assertRaises(CLIReturnCodeError): Environment.list({ 'organization': org['name'], 'location': gen_string('alpha') }) # Filter by non-existing organization and existing location with self.assertRaises(CLIReturnCodeError): Environment.list({ 'organization': gen_string('alpha'), 'location': loc['name'] })
def test_negative_list_with_non_existing_org_and_loc_by_id(self): """Test Environment List filtering parameters validation. :id: 97872953-e1aa-44bd-9ce0-a04bccbc9e94 :expectedresults: Server returns empty result as there is no environment associated with location :CaseLevel: Integration :BZ: 1337947 """ # Create env with specified organization and location org = make_org() loc = make_location() make_environment({ 'organization-ids': org['id'], 'location-ids': loc['id'], }) # Filter by non-existing location and existing organization with self.assertRaises(CLIReturnCodeError): Environment.list({ 'organization-id': org['id'], 'location-id': gen_string('numeric') }) # Filter by non-existing organization and existing location with self.assertRaises(CLIReturnCodeError): Environment.list({ 'organization-id': gen_string('numeric'), 'location-id': loc['id'] })
def test_positive_list_with_org_and_loc_by_id(self): """Test Environment List filtering. :id: 643f7cb5-0817-4b0a-ba5e-434df2033a40 :expectedresults: Results that match both organization and location are returned :CaseLevel: Integration :BZ: 1337947 """ # Create 2 envs with the same organization but different locations org = make_org() locs = [make_location() for _ in range(2)] envs = [make_environment({ 'organization-ids': org['id'], 'location-ids': loc['id'], }) for loc in locs] results = Environment.list({'organization-id': org['id']}) # List environments for the whole organization self.assertEqual(len(results), 2) self.assertEqual( {env['id'] for env in envs}, {result['id'] for result in results} ) # List environments with additional location filtering results = Environment.list({ 'organization-id': org['id'], 'location-id': locs[0]['id'], }) self.assertEqual(len(results), 1) self.assertEqual(results[0]['id'], envs[0]['id'])
def test_positive_CRUD_with_attributes(module_org, module_locs): """Check if Environment with attributes can be created, updated and removed :id: d2187971-86b2-40c9-a93c-66f37691ae2b :BZ: 1337947 :expectedresults: 1. Environment is created and has parameters assigned 2. Environment can be listed by parameters 3. Environment can be updated 4. Environment can be removed :CaseImportance: Critical """ # Create with attributes env_name = gen_string('alpha') environment = make_environment( {'location-ids': module_locs[0].id, 'organization-ids': module_org.id, 'name': env_name} ) assert module_locs[0].name in environment['locations'] assert module_org.name in environment['organizations'] assert env_name == environment['name'] # List by name result = Environment.list({'search': f'name={env_name}'}) assert len(result) == 1 assert result[0]['name'] == env_name # List by org loc id results = Environment.list({'organization-id': module_org.id, 'location-id': module_locs[0].id}) assert env_name in [res['name'] for res in results] # List by org loc name results = Environment.list({'organization': module_org.name, 'location': module_locs[0].name}) assert env_name in [res['name'] for res in results] # Update org and loc new_org = entities.Organization().create() Environment.update( { 'location-ids': module_locs[1].id, 'organization-ids': new_org.id, 'name': environment['name'], } ) env_info = Environment.info({'name': environment['name']}) assert module_locs[1].name in env_info['locations'] assert module_locs[0].name not in env_info['locations'] assert new_org.name in env_info['organizations'] assert module_org.name not in env_info['organizations'] # Update name new_env_name = gen_string('alpha') Environment.update({'id': environment['id'], 'new-name': new_env_name}) env_info = Environment.info({'id': environment['id']}) assert env_info['name'] == new_env_name # Delete Environment.delete({'id': environment['id']}) with pytest.raises(CLIReturnCodeError): Environment.info({'id': environment['id']})
def test_negative_list_with_org_and_loc_by_name(self): """Test Environment List filtering. :id: b8382ebb-ffa3-4637-b3b4-444af6c2fe9b :expectedresults: Server returns empty result as there is no environment associated with location or organization :CaseLevel: Integration :BZ: 1337947 """ # Create env with specified organization and location org = make_org() locs = [make_location() for _ in range(2)] make_environment({ 'organizations': org['name'], 'locations': locs[0]['name'], }) # But filter by another location results = Environment.list({ 'organization': org['name'], 'location': locs[1]['name'], }) self.assertEqual(len(results), 0)
def test_negative_list_with_org_and_loc_by_id(self): """Test Environment List filtering. :id: b1659c48-302b-4fe3-a38b-cd34c0fd4878 :expectedresults: Server returns empty result as there is no environment associated with location or organization :CaseLevel: Integration :BZ: 1337947 """ # Create env with specified organization and location org = make_org() locs = [make_location() for _ in range(2)] make_environment({ 'organization-ids': org['id'], 'location-ids': locs[0]['id'], }) # But filter by another location results = Environment.list({ 'organization-id': org['id'], 'location-id': locs[1]['id'], }) self.assertEqual(len(results), 0)
def test_positive_import_twice_list_by_puppetclass_id(self): """Import same puppet class twice (e.g. into different Content Views) but list class parameters only for specific puppet class. :id: 79a33641-54af-4e04-89ff-3b7f9a4e3ec2 :expectedresults: Parameters listed for specific Puppet class. BZ: 1385351 :CaseImportance: Low """ cv = publish_puppet_module(self.puppet_modules, CUSTOM_PUPPET_REPO, self.org['id']) env = Environment.list( {'search': u'content_view="{0}"'.format(cv['name'])})[0] puppet_class = Puppet.info({ 'name': self.puppet_modules[0]['name'], 'environment': env['name'], }) sc_params = SmartClassParameter.list({ 'environment': env['name'], 'puppet-class-id': puppet_class['id'], 'per-page': 1000, }) self.assertGreater(len(sc_params), 0) # Check that only unique results are returned self.assertEqual(len(sc_params), len({scp['id'] for scp in sc_params}))
def setUpClass(cls): """Import some parametrized puppet classes. This is required to make sure that we have data to be able to perform interactions with smart class variables. """ super(SmartVariablesTestCase, cls).setUpClass() cls.puppet_modules = [ {'author': 'robottelo', 'name': 'cli_test_variables'}, ] cls.org = make_org() cv = publish_puppet_module( cls.puppet_modules, CUSTOM_PUPPET_REPO, cls.org['id']) cls.env = Environment.list({ 'search': u'content_view="{0}"'.format(cv['name']) })[0] # Find imported puppet class cls.puppet_class = Puppet.info({ 'name': cls.puppet_modules[0]['name'], 'environment': cls.env['name'], }) # And all its subclasses cls.puppet_subclasses = Puppet.list({ 'search': "name ~ {0}:: and environment = {1}".format( cls.puppet_class['name'], cls.env['name']) })
def setUpClass(cls): super(HostGroupTestCase, cls).setUpClass() cls.org = make_org() # Setup for puppet class related tests puppet_modules = [ { 'author': 'robottelo', 'name': 'generic_1' }, { 'author': 'robottelo', 'name': 'generic_2' }, ] cls.cv = publish_puppet_module(puppet_modules, CUSTOM_PUPPET_REPO, cls.org['id']) cls.env = Environment.list( {'search': 'content_view="{0}"'.format(cls.cv['name'])})[0] cls.puppet_classes = [ Puppet.info({ 'name': mod['name'], 'puppet-environment': cls.env['name'] }) for mod in puppet_modules ] cls.content_source = Proxy.list({ 'search': 'url = https://{0}:9090'.format(settings.server.hostname) })[0] cls.hostgroup = make_hostgroup({ 'content-source-id': cls.content_source['id'], 'organization-ids': cls.org['id'] })
def setUpClass(cls): """Import some parametrized puppet classes. This is required to make sure that we have smart class variable available. Read all available smart class parameters for imported puppet class to be able to work with unique entity for each specific test. """ super(SmartClassParametersTestCase, cls).setUpClass() cls.puppet_modules = [ {'author': 'robottelo', 'name': 'cli_test_classparameters'}, ] cls.org = make_org() cv = publish_puppet_module( cls.puppet_modules, CUSTOM_PUPPET_REPO, cls.org['id']) cls.env = Environment.list({ 'search': u'content_view="{0}"'.format(cv['name']) })[0] cls.puppet_class = Puppet.info({ 'name': cls.puppet_modules[0]['name'], 'environment': cls.env['name'], }) cls.sc_params_list = SmartClassParameter.list({ 'environment': cls.env['name'], 'search': u'puppetclass="{0}"'.format(cls.puppet_class['name']) }) cls.sc_params_ids_list = [ sc_param['id'] for sc_param in cls.sc_params_list]
def setUpClass(cls): """Import some parametrized puppet classes. This is required to make sure that we have data to be able to perform interactions with smart class variables. """ super(SmartVariablesTestCase, cls).setUpClass() cls.puppet_modules = [ { 'author': 'robottelo', 'name': 'cli_test_variables' }, ] cls.org = make_org() cls.loc = make_location() cv = publish_puppet_module(cls.puppet_modules, CUSTOM_PUPPET_REPO, cls.org['id']) cls.env = Environment.list( {'search': u'content_view="{0}"'.format(cv['name'])})[0] Environment.update({ 'name': cls.env['name'], 'organization-ids': cls.org['id'], 'location-ids': cls.loc['id'], }) # Find imported puppet class cls.puppet_class = Puppet.info({ 'name': cls.puppet_modules[0]['name'], 'environment': cls.env['name'], }) # And all its subclasses cls.puppet_subclasses = Puppet.list({ 'search': "name ~ {0}:: and environment = {1}".format( cls.puppet_class['name'], cls.env['name']) })
def test_positive_import_twice_list_by_puppetclass_id( self, module_org, module_puppet): """Import same puppet class twice (e.g. into different Content Views) but list class parameters only for specific puppet class. :id: 79a33641-54af-4e04-89ff-3b7f9a4e3ec2 :expectedresults: Parameters listed for specific Puppet class. BZ: 1385351 :CaseImportance: Low """ cv = publish_puppet_module(module_puppet['modules'], CUSTOM_PUPPET_REPO, module_org.id) env = Environment.list({'search': f'content_view="{cv["name"]}"'})[0] puppet_class = Puppet.info({ 'name': module_puppet['modules'][0]['name'], 'environment': env['name'] }) sc_params = SmartClassParameter.list({ 'environment': env['name'], 'puppet-class-id': puppet_class['id'], 'per-page': 1000 }) assert len(sc_params) > 0 # Check that only unique results are returned assert len(sc_params) == len({scp['id'] for scp in sc_params})
def module_puppet(module_org, module_locs): puppet_modules = [{'author': 'robottelo', 'name': 'generic_1'}] cv = publish_puppet_module(puppet_modules, CUSTOM_PUPPET_REPO, module_org.id) env = Environment.list({'search': f'content_view="{cv["name"]}"'})[0] puppet_class = Puppet.info({ 'name': puppet_modules[0]['name'], 'environment': env['name'] }) return {'env': env, 'puppet_class': puppet_class}
def make_puppet(): """Import a parametrized puppet class.""" puppet_modules = [{'author': 'robottelo', 'name': 'generic_1'}] org = make_org() cv = publish_puppet_module(puppet_modules, CUSTOM_PUPPET_REPO, org['id']) env = Environment.list({'search': f'content_view="{cv["name"]}"'})[0] puppet = Puppet.info({ 'name': puppet_modules[0]['name'], 'environment': env['name'] }) return puppet
def test_positive_list_with_name(self): """Test Environment List @Feature: Environment @Assert: Environment list is displayed """ for name in valid_environments_list(): with self.subTest(name): Environment.create({'name': name}) result = Environment.list({'search': 'name={0}'.format(name)}) self.assertEqual(len(result), 1) self.assertEqual(result[0]['name'], name)
def setUpClass(cls): """Import some parametrized puppet classes. This is required to make sure that we have smart class variable available. Read all available smart class parameters for imported puppet class to be able to work with unique entity for each specific test. """ super(SmartClassParametersTestCase, cls).setUpClass() cls.puppet_modules = [ { 'author': 'robottelo', 'name': 'cli_test_classparameters' }, ] cls.org = make_org() cls.loc = make_location() cv = publish_puppet_module(cls.puppet_modules, CUSTOM_PUPPET_REPO, cls.org['id']) cls.env = Environment.list( {'search': u'content_view="{0}"'.format(cv['name'])})[0] Environment.update({ 'name': cls.env['name'], 'organization-ids': cls.org['id'], 'location-ids': cls.loc['id'], }) cls.puppet_class = Puppet.info({ 'name': cls.puppet_modules[0]['name'], 'environment': cls.env['name'], }) cls.sc_params_list = SmartClassParameter.list({ 'environment': cls.env['name'], 'search': u'puppetclass="{0}"'.format(cls.puppet_class['name']) }) cls.sc_params_ids_list = [ sc_param['id'] for sc_param in cls.sc_params_list ] cls.host = entities.Host( organization=cls.org['id'], location=cls.loc['id'], environment=cls.env['name'], ).create() cls.host.add_puppetclass( data={'puppetclass_id': cls.puppet_class['id']}) cls.hostgroup = make_hostgroup({ 'environment-id': cls.env['id'], 'puppet-class-ids': cls.puppet_class['id'] })
def setUpClass(cls): """Import a parametrized puppet class. """ super(PuppetClassTestCase, cls).setUpClass() cls.puppet_modules = [{'author': 'robottelo', 'name': 'generic_1'}] cls.org = make_org() cv = publish_puppet_module(cls.puppet_modules, CUSTOM_PUPPET_REPO, cls.org['id']) cls.env = Environment.list( {'search': 'content_view="{0}"'.format(cv['name'])})[0] cls.puppet = Puppet.info({ 'name': cls.puppet_modules[0]['name'], 'environment': cls.env['name'] })
def module_puppet(module_org, module_location): puppet_modules = [{'author': 'robottelo', 'name': 'cli_test_classparameters'}] cv = publish_puppet_module(puppet_modules, CUSTOM_PUPPET_REPO, module_org.id) env = Environment.list({'search': f'content_view="{cv["name"]}"'})[0] Environment.update( { 'name': env['name'], 'organization-ids': module_org.id, 'location-ids': module_location.id, } ) puppet_class = Puppet.info({'name': puppet_modules[0]['name'], 'environment': env['name']}) yield {'modules': puppet_modules, 'env': env, 'class': puppet_class} delete_puppet_class(puppet_class['name'])
def test_positive_list_with_name(self): """Test Environment List @Feature: Environment @Assert: Environment list is displayed """ for name in valid_environments_list(): with self.subTest(name): Environment.create({'name': name}) result = Environment.list({ 'search': 'name={0}'.format(name) }) self.assertEqual(len(result), 1) self.assertEqual(result[0]['name'], name)
def test_positive_list_with_name(self): """Test Environment List :id: 8a81f853-929c-4eaa-8ae0-4c92ebf1f250 :expectedresults: Environment list is displayed :CaseLevel: Integration """ for name in valid_environments_list(): with self.subTest(name): Environment.create({'name': name}) result = Environment.list({'search': 'name={0}'.format(name)}) self.assertEqual(len(result), 1) self.assertEqual(result[0]['name'], name)
def setUpClass(cls): super(EnvironmentTestCase, cls).setUpClass() cls.org = make_org() # Setup for puppet class related tests puppet_modules = [ {'author': 'robottelo', 'name': 'generic_1'}, ] cls.cv = publish_puppet_module( puppet_modules, CUSTOM_PUPPET_REPO, cls.org['id']) cls.env = Environment.list({ 'search': u'content_view="{0}"'.format(cls.cv['name'])})[0] cls.puppet_class = Puppet.info({ 'name': puppet_modules[0]['name'], 'environment': cls.env['name'], })
def setUpClass(cls): super(HostGroupTestCase, cls).setUpClass() cls.org = make_org() # Setup for puppet class related tests puppet_modules = [ {'author': 'robottelo', 'name': 'generic_1'}, {'author': 'robottelo', 'name': 'generic_2'}, ] cls.cv = publish_puppet_module( puppet_modules, CUSTOM_PUPPET_REPO, cls.org['id']) cls.env = Environment.list({ 'search': u'content_view="{0}"'.format(cls.cv['name'])})[0] cls.puppet_classes = [ Puppet.info({'name': mod['name'], 'environment': cls.env['name']}) for mod in puppet_modules ]
def setUpClass(cls): super(EnvironmentTestCase, cls).setUpClass() cls.org = entities.Organization().create() cls.loc = entities.Location().create() cls.loc2 = entities.Location().create() # Setup for puppet class related tests puppet_modules = [{'author': 'robottelo', 'name': 'generic_1'}] cls.cv = publish_puppet_module(puppet_modules, CUSTOM_PUPPET_REPO, cls.org.id) cls.env = Environment.list( {'search': 'content_view="{0}"'.format(cls.cv['name'])})[0] cls.puppet_class = Puppet.info({ 'name': puppet_modules[0]['name'], 'environment': cls.env['name'] })
def test_positive_list_with_name(self): """Test Environment List :id: 8a81f853-929c-4eaa-8ae0-4c92ebf1f250 :expectedresults: Environment list is displayed :CaseLevel: Integration """ for name in valid_environments_list(): with self.subTest(name): Environment.create({'name': name}) result = Environment.list({ 'search': 'name={0}'.format(name) }) self.assertEqual(len(result), 1) self.assertEqual(result[0]['name'], name)
def setUpClass(cls): """Import a parametrized puppet class. """ super(PuppetClassTestCase, cls).setUpClass() cls.puppet_modules = [ {'author': 'robottelo', 'name': 'generic_1'}, ] cls.org = make_org() cv = publish_puppet_module( cls.puppet_modules, CUSTOM_PUPPET_REPO, cls.org['id']) cls.env = Environment.list({ 'search': u'content_view="{0}"'.format(cv['name']) })[0] cls.puppet = Puppet.info({ 'name': cls.puppet_modules[0]['name'], 'environment': cls.env['name'], })
def test_positive_CRUD_with_attributes(self): """Check if Environment with attributes can be created, updated and removed :id: d2187971-86b2-40c9-a93c-66f37691ae2b :bz: 1337947 :expectedresults: 1. Environment is created and has parameters assigned 2. Environment can be listed by parameters 3. Environment can be updated 4. Environment can be removed :CaseImportance: Critical """ # Create with attributes env_name = gen_string('alpha') environment = make_environment({ 'location-ids': self.loc.id, 'organization-ids': self.org.id, 'name': env_name, }) self.assertIn(self.loc.name, environment['locations']) self.assertIn(self.org.name, environment['organizations']) self.assertEqual(env_name, environment['name']) # List by name result = Environment.list({'search': 'name={0}'.format(env_name)}) self.assertEqual(len(result), 1) self.assertEqual(result[0]['name'], env_name) # List by org loc id results = Environment.list({ 'organization-id': self.org.id, 'location-id': self.loc.id, }) self.assertIn(env_name, [res['name'] for res in results]) # List by org loc name results = Environment.list({ 'organization': self.org.name, 'location': self.loc.name, }) self.assertIn(env_name, [res['name'] for res in results]) # Update org and loc new_org = entities.Organization().create() Environment.update({ 'location-ids': self.loc2.id, 'organization-ids': new_org.id, 'name': environment['name'], }) env_info = Environment.info({'name': environment['name']}) self.assertIn(self.loc2.name, env_info['locations']) self.assertNotIn(self.loc.name, env_info['locations']) self.assertIn(new_org.name, env_info['organizations']) self.assertNotIn(self.org.name, env_info['organizations']) # Update name new_env_name = gen_string('alpha') Environment.update({ 'id': environment['id'], 'new-name': new_env_name, }) env_info = Environment.info({'id': environment['id']}) self.assertEqual(env_info['name'], new_env_name) # Delete Environment.delete({'id': environment['id']}) with self.assertRaises(CLIReturnCodeError): Environment.info({'id': environment['id']})
def env(cv): """Return the puppet environment.""" return Environment.list({'search': 'content_view="{}"'.format(cv['name'])})[0]