def test_negative_update_same_name(self): """Attempt to update a compute resource with already existing name :id: 4d7c5eb0-b8cb-414f-aa10-fe464a164ab4 :expectedresults: Compute resources is not updated :CaseImportance: Critical """ name = gen_string('alphanumeric') entities.LibvirtComputeResource( location=[self.loc], name=name, organization=[self.org], url=self.current_libvirt_url, ).create() new_compresource = entities.LibvirtComputeResource( location=[self.loc], organization=[self.org], url=self.current_libvirt_url, ).create() with self.assertRaises(HTTPError): new_compresource.name = name new_compresource.update(['name']) self.assertNotEqual(new_compresource.read().name, name)
def test_negative_create_with_same_name(self): """Attempt to create a compute resource with already existing name :id: 9376e25c-2aa8-4d99-83aa-2eec160c030e :expectedresults: Compute resources is not created :CaseImportance: High :CaseLevel: Component """ name = gen_string('alphanumeric') entities.LibvirtComputeResource( location=[self.loc], name=name, organization=[self.org], url=self.current_libvirt_url, ).create() with self.assertRaises(HTTPError): entities.LibvirtComputeResource( location=[self.loc], name=name, organization=[self.org], url=self.current_libvirt_url, ).create()
def test_positive_update_compresource(self): """Update a host with a new compute resource @feature: Hosts @assert: A host is updated with a new compute resource """ org = entities.Organization().create() loc = entities.Location(organization=[org]).create() compute_resource = entities.LibvirtComputeResource( location=[loc], organization=[org], ).create() host = entities.Host( compute_resource=compute_resource, location=loc, organization=org, ).create() new_compresource = entities.LibvirtComputeResource( location=[host.location], organization=[host.organization], ).create() host.compute_resource = new_compresource host = host.update(['compute_resource']) self.assertEqual( host.compute_resource.read().name, new_compresource.name)
def test_positive_end_to_end(session, module_loc, module_org): """Perform end to end testing for compute profile component :id: 5445fc7e-7b3f-472f-8a94-93f89aca6c22 :expectedresults: All expected CRUD actions finished successfully :CaseLevel: Integration :CaseImportance: High """ name = gen_string('alpha') new_name = gen_string('alpha') compute_resource = entities.LibvirtComputeResource( location=[module_loc], organization=[module_org], url='qemu+ssh://root@test/system').create() with session: session.computeprofile.create({'name': name}) assert session.computeprofile.search(name)[0]['Name'] == name compute_resource_list = session.computeprofile.list_resources(name) assert ('{} (Libvirt)'.format(compute_resource.name) in [ resource['Compute Resource'] for resource in compute_resource_list ]) session.computeprofile.rename(name, {'name': new_name}) assert session.computeprofile.search(new_name)[0]['Name'] == new_name session.computeprofile.delete(new_name) assert not session.computeprofile.search(new_name)
def test_positive_add_compresource(self): """Add compute resource using the organization name and compute resource name. @feature: Organizations associate compute resource. @assert: compute resource is added. """ strategy, value = common_locators['entity_deselect'] with Session(self.browser) as session: for resource_name in generate_strings_list(): with self.subTest(resource_name): org_name = gen_string('alpha') url = LIBVIRT_RESOURCE_URL % settings.server.hostname # Create compute resource using nailgun resource = entities.LibvirtComputeResource( name=resource_name, url=url, ).create() self.assertEqual(resource.name, resource_name) make_org(session, org_name=org_name) self.assertIsNotNone(self.org.search(org_name)) self.org.update(org_name, new_resources=[resource_name]) self.org.search(org_name).click() session.nav.click(tab_locators['context.tab_resources']) element = session.nav.wait_until_element( (strategy, value % resource_name)) self.assertIsNotNone(element)
def test_positive_remove_compresource(self): """Remove compute resource by using the location name and compute resource name @feature: Locations @assert: compute resource is added then removed """ strategy, value = common_locators['entity_select'] strategy1, value1 = common_locators['entity_deselect'] with Session(self.browser) as session: for resource_name in generate_strings_list(): with self.subTest(resource_name): loc_name = gen_string('alpha') url = LIBVIRT_RESOURCE_URL % settings.server.hostname resource = entities.LibvirtComputeResource( name=resource_name, url=url).create() self.assertEqual(resource.name, resource_name) set_context(session, org=ANY_CONTEXT['org']) make_loc(session, name=loc_name, resources=[resource_name]) self.location.search(loc_name).click() session.nav.click(tab_locators['context.tab_resources']) element = self.location.wait_until_element( (strategy1, value1 % resource_name)) # Item is listed in 'Selected Items' list and not # 'All Items' list. self.assertIsNotNone(element) self.location.update(loc_name, resources=[resource_name]) self.location.search(loc_name).click() session.nav.click(tab_locators['context.tab_resources']) element = session.nav.wait_until_element( (strategy, value % resource_name)) # Item is listed in 'All Items' list and not # 'Selected Items' list. self.assertIsNotNone(element)
def test_add_compresource(self): """Add compute resource using the location name and compute resource name @feature: Locations @assert: compute resource is added successfully """ strategy, value = common_locators['entity_deselect'] with Session(self.browser) as session: for resource_name in generate_strings_list(): with self.subTest(resource_name): loc_name = gen_string('alpha') url = LIBVIRT_RESOURCE_URL % settings.server.hostname resource = entities.LibvirtComputeResource( name=resource_name, url=url).create() self.assertEqual(resource.name, resource_name) make_loc(session, name=loc_name) self.assertIsNotNone(self.location.search(loc_name)) self.location.update(loc_name, new_resources=[resource_name]) self.location.search(loc_name).click() session.nav.click(tab_locators['context.tab_resources']) element = session.nav.wait_until_element( (strategy, value % resource_name)) self.assertIsNotNone(element)
def test_positive_update_orgs(self): """Update a compute resource with new multiple organizations :id: 2c759ad5-d115-46d9-8365-712c0bb39a1d :expectedresults: Compute resource is updated with expected organizations :CaseImportance: High :CaseLevel: Integration """ compresource = entities.LibvirtComputeResource( organization=[self.org], url=self.current_libvirt_url, ).create() new_orgs = [ entities.Organization().create() for _ in range(randint(3, 5)) ] compresource.organization = new_orgs compresource = compresource.update(['organization']) self.assertEqual( set(organization.id for organization in compresource.organization), set(organization.id for organization in new_orgs), )
def test_positive_update_locs(setup): """Update a compute resource with new multiple locations :id: cda9f501-2879-4cb0-a017-51ee795232f1 :expectedresults: Compute resource is updated with expected locations :CaseImportance: High :CaseLevel: Integration """ compresource = entities.LibvirtComputeResource( location=[setup.loc], organization=[setup.org], url=setup.current_libvirt_url).create() new_locs = [ entities.Location(organization=[setup.org]).create() for _ in range(randint(3, 5)) ] compresource.location = new_locs compresource = compresource.update(['location']) assert {location.id for location in compresource.location } == {location.id for location in new_locs}
def test_positive_update_compresource(session): """Add/Remove compute resource from/to location :id: 1d24414a-666d-490d-89b9-cd0704684cdd :expectedresults: compute resource is added and removed from the location :CaseLevel: Integration """ url = LIBVIRT_RESOURCE_URL % settings.compute_resources.libvirt_hostname resource = entities.LibvirtComputeResource(url=url).create() resource_name = resource.name + ' (Libvirt)' loc = entities.Location().create() with session: session.location.update( loc.name, {'compute_resources.resources.assigned': [resource_name]}) loc_values = session.location.read(loc.name) assert loc_values['compute_resources']['resources']['assigned'][ 0] == resource_name session.location.update( loc.name, {'compute_resources.resources.unassigned': [resource_name]}) loc_values = session.location.read(loc.name) assert len( loc_values['compute_resources']['resources']['assigned']) == 0 assert resource_name in loc_values['compute_resources']['resources'][ 'unassigned']
def test_positive_update_compresource(self): """Remove compute resource using the organization name and compute resource name. :id: db119bb1-8f79-415b-a056-70a19ffceeea :expectedresults: compute resource is added then removed. :CaseLevel: Integration """ with Session(self.browser) as session: org_name = gen_string('alpha') make_org(session, org_name=org_name) for resource_name in generate_strings_list(): with self.subTest(resource_name): url = (LIBVIRT_RESOURCE_URL % settings.compute_resources.libvirt_hostname) # Create compute resource using nailgun resource = entities.LibvirtComputeResource( name=resource_name, url=url).create() self.assertEqual(resource.name, resource_name) kwargs = { 'org_name': org_name, 'entity_type': 'resources', 'entity_name': resource_name } self.assertIsNotNone(self.org.add_entity(**kwargs)) self.assertIsNotNone(self.org.remove_entity(**kwargs))
def test_verify_bugzilla_1103157(self): """Create organization and add two compute resources one by one using different transactions and different users to see that they actually added, but not overwrite each other :id: 5f4fd2b7-d998-4980-b5e7-9822bd54156b :Steps: 1. Use the admin user to create an organization and two compute resources. Make one compute resource point at / belong to the organization. 2. Create a user and give them the ability to update compute resources and organizations. Have this user make the second compute resource point at / belong to the organization. 3. Use the admin user to read information about the organization. Verify that both compute resources are pointing at / belong to the organization. :expectedresults: Organization contains both compute resources :CaseLevel: Integration """ # setUpClass() creates an organization w/admin user. Here, we use admin # to make two compute resources and make first belong to organization. compute_resources = [ entities.LibvirtComputeResource( name=gen_string('alpha'), url='qemu://host.example.com/system').create() for _ in range(2) ] self.organization.compute_resource = compute_resources[:1] # list self.organization = self.organization.update(['compute_resource']) self.assertEqual(len(self.organization.compute_resource), 1) # Create a new user and give them minimal permissions. login = gen_alphanumeric() password = gen_alphanumeric() user = entities.User(login=login, password=password).create() role = entities.Role().create() for perm in ['edit_compute_resources', 'edit_organizations']: permissions = [ entities.Permission(id=permission['id']) for permission in entities.Permission(name=perm).search() ] entities.Filter(permission=permissions, role=role).create() user.role = [role] user = user.update(['role']) # Make new user assign second compute resource to org. cfg = get_nailgun_config() cfg.auth = (login, password) entities.Organization( cfg, id=self.organization.id, compute_resource=compute_resources[1:], # slice returns list ).update(['compute_resource']) # Use admin to verify both compute resources belong to organization. self.assertEqual(len(self.organization.read().compute_resource), 2)
def test_positive_add_compresource(self): """Add compute resource using the location name and compute resource name :id: 1d24414a-666d-490d-89b9-cd0704684cdd :expectedresults: compute resource is added successfully :CaseLevel: Integration """ strategy, value = common_locators['entity_deselect'] with Session(self.browser) as session: for resource_name in generate_strings_list(): with self.subTest(resource_name): loc_name = gen_string('alpha') url = (LIBVIRT_RESOURCE_URL % settings.compute_resources.libvirt_hostname) resource = entities.LibvirtComputeResource( name=resource_name, url=url).create() self.assertEqual(resource.name, resource_name) make_loc(session, name=loc_name) self.assertIsNotNone(self.location.search(loc_name)) self.location.update(loc_name, new_resources=[resource_name]) self.location.search_and_click(loc_name) session.nav.click(tab_locators['context.tab_resources']) element = session.nav.wait_until_element( (strategy, value % resource_name)) self.assertIsNotNone(element)
def test_positive_create_using_libvirt_without_mac(self): """Create a libvirt host and not specify a MAC address. @id: b003faa9-2810-4176-94d2-ea84bed248eb @Assert: Host is created """ compute_resource = entities.LibvirtComputeResource( url='qemu+ssh://root@{0}/system'.format( settings.compute_resources.libvirt_hostname)).create() host = entities.Host() host.create_missing() result = Host.create({ u'architecture-id': host.architecture.id, u'compute-resource-id': compute_resource.id, u'domain-id': host.domain.id, u'environment-id': host.environment.id, u'location-id': host.location.id, # pylint:disable=no-member u'medium-id': host.medium.id, u'name': host.name, u'operatingsystem-id': host.operatingsystem.id, # pylint:disable=no-member u'organization-id': host.organization.id, u'partition-table-id': host.ptable.id, u'puppet-proxy-id': self.puppet_proxy['id'], u'root-pass': host.root_pass, }) self.assertEqual(result['name'], host.name + '.' + host.domain.name) Host.delete({'id': result['id']})
def test_positive_update_libvirt_compresource(self): """Update location with new Libvirt compute resource @Assert: Location updated successfully and has correct Libvirt compute resource assigned @Feature: Location - Update """ location = entities.Location( compute_resource=[entities.LibvirtComputeResource().create()], ).create() test_cr = entities.LibvirtComputeResource().create() location.compute_resource = [test_cr] self.assertEqual( location.update(['compute_resource']).compute_resource[0].id, test_cr.id ) self.assertEqual( location.compute_resource[0].read().provider, 'Libvirt')
def test_positive_update_libvirt_compresource(self): """Update location with new Libvirt compute resource @id: 9d0aef06-25dd-4352-8045-00b24b79b514 @Assert: Location updated successfully and has correct Libvirt compute resource assigned @CaseLevel: Integration """ location = entities.Location(compute_resource=[ entities.LibvirtComputeResource().create() ], ).create() test_cr = entities.LibvirtComputeResource().create() location.compute_resource = [test_cr] self.assertEqual( location.update(['compute_resource']).compute_resource[0].id, test_cr.id) self.assertEqual(location.compute_resource[0].read().provider, 'Libvirt')
def setUpClass(cls): """Set up reusable entities for tests.""" super(LocationTestCase, cls).setUpClass() cls.org = entities.Organization().create() cls.org2 = entities.Organization().create() cls.domain = entities.Domain().create() cls.subnet = entities.Subnet().create() cls.env = entities.Environment().create() cls.host_group = entities.HostGroup().create() cls.template = entities.ProvisioningTemplate().create() cls.test_cr = entities.LibvirtComputeResource().create() cls.new_user = entities.User().create()
def test_negative_update_same_name(setup): """Attempt to update a compute resource with already existing name :id: 4d7c5eb0-b8cb-414f-aa10-fe464a164ab4 :expectedresults: Compute resources is not updated :CaseImportance: High :CaseLevel: Component """ name = gen_string('alphanumeric') entities.LibvirtComputeResource( location=[setup.loc], name=name, organization=[setup.org], url=setup.current_libvirt_url ).create() new_compresource = entities.LibvirtComputeResource( location=[setup.loc], organization=[setup.org], url=setup.current_libvirt_url ).create() with pytest.raises(HTTPError): new_compresource.name = name new_compresource.update(['name']) assert new_compresource.read().name != name
def test_positive_create_with_libvirt_compresource(self): """Create new location with Libvirt compute resource assigned to it @Assert: Location created successfully and has correct Libvirt compute resource assigned to it @Feature: Location """ test_cr = entities.LibvirtComputeResource().create() location = entities.Location(compute_resource=[test_cr]).create() self.assertEqual(location.compute_resource[0].id, test_cr.id) self.assertEqual( location.compute_resource[0].read().provider, 'Libvirt')
def test_positive_create_with_provider(self): """Create compute resources with different providers. Testing only Libvirt and Docker as other providers require valid credentials :id: f61c66c9-15f8-4b00-9e53-7ebfb09397cc :expectedresults: Compute resources are created with expected providers :CaseImportance: Critical """ entity = entities.LibvirtComputeResource() entity.location = [self.loc] entity.organization = [self.org] result = entity.create() self.assertEqual(result.provider, entity.provider)