def test_positive_host_configuration_chart(session): """Check if the Host Configuration Chart is working in the Dashboard UI :id: b03314aa-4394-44e5-86da-c341c783003d :Steps: 1. Navigate to Monitor -> Dashboard 2. Review the Host Configuration Chart widget 3. Check that chart contains correct percentage value :expectedresults: Chart showing correct data :CaseLevel: Integration """ org = entities.Organization().create() loc = entities.Location().create() entities.Host(organization=org, location=loc).create() with session: session.organization.select(org_name=org.name) session.location.select(loc_name=loc.name) dashboard_values = session.dashboard.read('HostConfigurationChart') assert dashboard_values['chart'][''] == '100%'
def test_update_environment(session): """Add/Remove environment from/to location :id: bbca1af0-a31f-4096-bc6e-bb341ffed575 :expectedresults: environment is added and removed from the location :CaseLevel: Integration """ env = entities.Environment().create() loc = entities.Location().create() with session: session.location.update( loc.name, {'environments.resources.assigned': [env.name]}) loc_values = session.location.read(loc.name) assert loc_values[ 'environments']['resources']['assigned'][0] == env.name session.location.update( loc.name, {'environments.resources.unassigned': [env.name]}) loc_values = session.location.read(loc.name) assert len(loc_values['environments']['resources']['assigned']) == 0 assert env.name in loc_values[ 'environments']['resources']['unassigned']
def test_positive_update_location(session): """Add/Remove location from/to organization. :id: 086efafa-0d7f-11e7-81e9-68f72889dc7f :expectedresults: Location is added/removed to/from organization. :CaseLevel: Integration """ location = entities.Location().create() org = entities.Organization().create() with session: session.organization.update( org.name, {'locations.resources.assigned': [location.name]}) org_values = session.organization.read(org.name) assert org_values[ 'locations']['resources']['assigned'][0] == location.name session.organization.update( org.name, {'locations.resources.unassigned': [location.name]}) org_values = session.organization.read(org.name) assert len(org_values['locations']['resources']['assigned']) == 0 assert location.name in org_values[ 'locations']['resources']['unassigned']
def test_positive_delete_by_type(self): """Delete some entities of different types and check audit logs for these events using entity type as search criteria :id: de9b056f-10da-485a-87ce-b02a9efff15c :expectedresults: Audit logs contain corresponding entries per each delete event :CaseImportance: Medium :CaseComponent: AuditLog """ for entity in [ entities.Architecture(), entities.Domain(), entities.Host(), entities.HostGroup(), entities.Location(), entities.Organization(), entities.Role(), entities.UserGroup(), ]: created_entity = entity.create() created_entity.delete() audits = entities.Audit().search( query={'search': 'type={0}'.format(created_entity.__class__.__name__.lower())} ) entity_audits = [ entry for entry in audits if entry.auditable_name == created_entity.name ] if not entity_audits: self.fail('audit not found by name "{}"'.format(created_entity.name)) audit = entity_audits[0] self.assertEqual(audit.auditable_id, created_entity.id) self.assertEqual(audit.action, 'destroy') self.assertEqual(audit.version, 2)
def test_positive_add_org_hostgroup_template(session): """Add a organization, hostgroup, provisioning template by using the location name :id: 27d56d64-6866-46b6-962d-1ac2a11ae136 :expectedresults: organization, hostgroup, provisioning template are added to location :CaseLevel: Integration """ org = entities.Organization().create() loc = entities.Location().create() hostgroup = entities.HostGroup().create() template = entities.ProvisioningTemplate().create() with session: session.location.update(loc.name, { 'organizations.resources.assigned': [org.name], 'host_groups.all_hostgroups': False, 'host_groups.resources.unassigned': [hostgroup.name], 'provisioning_templates.all_templates': False, 'provisioning_templates.resources.unassigned': [template.name] }) loc_values = session.location.read(loc.name) assert loc_values[ 'organizations']['resources']['assigned'][0] == org.name assert hostgroup.name in loc_values['host_groups']['resources']['unassigned'] assert template.name in loc_values[ 'provisioning_templates']['resources']['unassigned'] session.location.update(loc.name, { 'host_groups.resources.assigned': [hostgroup.name], 'provisioning_templates.resources.assigned': [template.name] }) loc_values = session.location.read(loc.name) assert hostgroup.name in loc_values['host_groups']['resources']['assigned'] assert template.name in loc_values[ 'provisioning_templates']['resources']['assigned']
def test_positive_update_with_all_users(session): """Create location and do not add user to it. Check and uncheck 'all users' setting. Verify that for both operation expected location is assigned to user. Then add user to location and retry. :id: 6596962b-8fd0-4a82-bf54-fa6a31147311 :expectedresults: Location entity is assigned to user after checkbox was enabled and then disabled afterwards :BZ: 1321543, 1479736, 1479736 :CaseLevel: Integration """ user = entities.User().create() loc = entities.Location().create() with session: session.organization.select(org_name=ANY_CONTEXT['org']) session.location.select(loc_name=loc.name) session.location.update(loc.name, {'users.all_users': True}) user_values = session.user.read(user.login) assert loc.name in user_values['locations']['resources']['assigned'] session.location.update(loc.name, {'users.all_users': False}) user_values = session.user.read(user.login) assert loc.name in user_values['locations']['resources']['unassigned'] session.location.update(loc.name, {'users.resources.assigned': [user.login]}) loc_values = session.location.read(loc.name) user_values = session.user.read(user.login) assert loc_values['users']['resources']['assigned'][0] == user.login assert user_values['locations']['resources']['assigned'][0] == loc.name session.location.update(loc.name, {'users.all_users': True}) user_values = session.user.read(user.login) assert loc.name in user_values['locations']['resources']['assigned'] session.location.update(loc.name, {'users.all_users': False}) user_values = session.user.read(user.login) assert loc.name in user_values['locations']['resources']['unassigned']
def test_positive_redirection_for_multiple_hosts(self): """Create new hostgroup with whitespaces in its name for specific organization and location. After that create some hosts using already created hostgroup :id: f301ec2f-1e9b-4e34-8c87-4d0b3381d9e1 :expectedresults: Hostgroup hosts count can be successfully observed in a table and redirection to these hosts works properly :BZ: 1402390 :CaseImportance: Critical """ name = '{0} {1}'.format(gen_string('alpha'), gen_string('numeric')) org = entities.Organization().create() loc = entities.Location(organization=[org]).create() hostgroup = entities.HostGroup( location=[loc], organization=[org], name=name, ).create() host_names = [ entities.Host( hostgroup=hostgroup, location=loc, organization=org, ).create().name for _ in range(3) ] with Session(self) as session: set_context(session, org=org.name, loc=loc.name) self.assertIsNotNone(self.hostgroup.search(name)) self.hostgroup.click(common_locators['table_cell_link'] % (name, 'Hosts')) for host_name in host_names: self.hosts.wait_until_element(locators['host.select_name'] % host_name)
def test_positive_list_parameters(self): """Satellite lists all the subnet parameters :id: ce86d531-bf6b-45a9-81e3-67e1b3398f76 :steps: 1. Create subnet with all the details 2. Add two parameters in subnet 3. List parameters of subnet :expectedresults: The satellite should display all the subnet parameters """ parameter = {'name': gen_string('alpha'), 'value': gen_string('alpha')} org = entities.Organization().create() loc = entities.Location(organization=[org]).create() org_subnet = entities.Subnet(location=[loc], organization=[org], ipam=u'DHCP', vlanid=gen_string('numeric', 3), subnet_parameters_attributes=[parameter ]).create() self.assertEqual(org_subnet.subnet_parameters_attributes[0]['name'], parameter['name']) self.assertEqual(org_subnet.subnet_parameters_attributes[0]['value'], parameter['value']) sub_param = entities.Parameter(name=gen_string('alpha'), subnet=org_subnet.id, value=gen_string('alpha')).create() org_subnet = entities.Subnet(id=org_subnet.id).read() params_list = { param['name']: param['value'] for param in org_subnet.subnet_parameters_attributes if param['name'] == sub_param.name } self.assertEqual(params_list[sub_param.name], sub_param.value)
def test_positive_update_by_type(): """Update some entities of different types and check audit logs for these events using entity type as search criteria :id: 43e73a11-b241-4b91-bdf6-e966366014e8 :expectedresults: Audit logs contain corresponding entries per each update event :CaseImportance: Medium """ for entity in [ entities.Architecture(), entities.Domain(), entities.HostGroup(), entities.Location(), entities.Role(), entities.UserGroup(), ]: created_entity = entity.create() name = created_entity.name new_name = gen_string('alpha') created_entity.name = new_name created_entity = created_entity.update(['name']) audits = entities.Audit().search( query={ 'search': f'type={created_entity.__class__.__name__.lower()}' }) entity_audits = [ entry for entry in audits if entry.auditable_name == name ] assert entity_audits, f'audit not found by name "{name}"' audit = entity_audits[0] assert audit.auditable_id == created_entity.id assert audit.audited_changes['name'] == [name, new_name] assert audit.action == 'update' assert audit.version == 2
def test_positive_update_with_manager_role(self): """Create template providing the initial name, then update its name with manager user role. :id: 0aed79f0-7c9a-4789-99ba-56f2db82f097 :expectedresults: Provisioning Template is created, and its name can be updated. :CaseImportance: Critical :BZ: 1277308 """ user_login = gen_string('alpha') user_password = gen_string('alpha') new_name = gen_string('alpha') org = entities.Organization().create() loc = entities.Location().create() template = entities.ProvisioningTemplate(organization=[org], location=[loc]).create() # Create user with Manager role role = entities.Role().search(query={'search': 'name="Manager"'})[0] entities.User( role=[role], admin=False, login=user_login, password=user_password, organization=[org], location=[loc], ).create() # Update template name with that user cfg = get_nailgun_config() cfg.auth = (user_login, user_password) updated = entities.ProvisioningTemplate(cfg, id=template.id, name=new_name).update(['name']) self.assertEqual(updated.name, new_name)
def test_positive_end_to_end(session, oscap_tailoring_path): """Perform end to end testing for tailoring file component :id: 9aebccb8-6837-4583-8a8a-8883480ab688 :expectedresults: All expected CRUD actions finished successfully :CaseLevel: Integration :CaseImportance: High """ name = gen_string('alpha') new_name = gen_string('alpha') org = entities.Organization().create() loc = entities.Location().create() with session: session.oscaptailoringfile.create({ 'file_upload.name': name, 'file_upload.scap_file': oscap_tailoring_path, 'organizations.resources.assigned': [org.name], 'locations.resources.assigned': [loc.name], }) assert session.oscaptailoringfile.search(name)[0]['Name'] == name tailroingfile_values = session.oscaptailoringfile.read(name) assert tailroingfile_values['file_upload']['name'] == name assert (tailroingfile_values['file_upload']['uploaded_scap_file'] == oscap_tailoring_path.rsplit('/', 1)[-1]) assert org.name in tailroingfile_values['organizations']['resources'][ 'assigned'] assert loc.name in tailroingfile_values['locations']['resources'][ 'assigned'] session.oscaptailoringfile.update(name, {'file_upload.name': new_name}) assert session.oscaptailoringfile.search( new_name)[0]['Name'] == new_name assert not session.oscaptailoringfile.search(name)
def create_ldap(self): """Fetch necessary properties from settings and Create ldap auth source""" org = entities.Organization().create() loc = entities.Location(organization=[org]).create() ldap_user_name = settings.ipa.username_ipa ldap_user_passwd = settings.ipa.password_ipa username = settings.ipa.user_ipa yield dict( org=org, loc=loc, ldap_user_name=ldap_user_name, ldap_user_passwd=ldap_user_passwd, sat_url=f'https://{settings.server.hostname}', username=username, authsource=entities.AuthSourceLDAP( onthefly_register=True, account=ldap_user_name, account_password=ldap_user_passwd, base_dn=settings.ipa.basedn_ipa, groups_base=settings.ipa.grpbasedn_ipa, attr_firstname=LDAP_ATTR['firstname'], attr_lastname=LDAP_ATTR['surname'], attr_login=LDAP_ATTR['login'], server_type=LDAP_SERVER_TYPE['API']['ipa'], attr_mail=LDAP_ATTR['mail'], name=gen_string('alpha'), host=settings.ipa.hostname_ipa, tls=False, port='389', location=[loc], organization=[org], ).create(), ) for user in entities.User().search( query={'search': f'login={username}'}): user.delete()
def test_positive_create_filter_admin_user_with_orgs(test_name): """Attempt to create a role filter by admin user, who has 10 organizations assigned. :id: 04208e17-34b5-46b1-84dd-b8a973521d30 :customerscenario: true :expectedresults: filter was successfully created. :BZ: 1389795 :CaseImportance: Critical """ role_name = gen_string('alpha') resource_type = 'Architecture' permissions = ['view_architectures', 'edit_architectures'] password = gen_string('alphanumeric') organizations = [entities.Organization().create() for _ in range(10)] loc = entities.Location(organization=[organizations[0]]).create() user = entities.User( admin=True, organization=organizations, location=[loc], default_organization=organizations[0], default_location=loc, password=password, ).create() with Session(test_name, user=user.login, password=password) as session: session.role.create({'name': role_name}) assert session.role.search(role_name)[0]['Name'] == role_name session.filter.create(role_name, { 'resource_type': resource_type, 'permission.assigned': permissions }) assigned_permissions = session.filter.read_permissions(role_name) assert set(assigned_permissions[resource_type]) == set(permissions)
def test_positive_update_entities(self, make_entities): """Update location with new domain :id: 1016dfb9-8103-45f1-8738-0579fa9754c1 :expectedresults: Location updated successfully and has correct domain assigned :CaseLevel: Integration """ location = entities.Location().create() location.domain = [make_entities["domain"]] location.subnet = [make_entities["subnet"]] location.environment = [make_entities["env"]] location.hostgroup = [make_entities["host_group"]] location.provisioning_template = [make_entities["template"]] location.compute_resource = [make_entities["test_cr"]] location.user = [make_entities["new_user"]] assert location.update(['domain']).domain[0].id == make_entities["domain"].id assert location.update(['subnet']).subnet[0].id == make_entities["subnet"].id assert location.update(['environment']).environment[0].id == make_entities["env"].id assert location.update(['hostgroup']).hostgroup[0].id == make_entities["host_group"].id ct_list = [ ct for ct in location.update(['provisioning_template']).provisioning_template if ct.id == make_entities["template"].id ] assert len(ct_list) == 1 assert ( location.update(['compute_resource']).compute_resource[0].id == make_entities["test_cr"].id ) assert location.compute_resource[0].read().provider == 'Libvirt' assert location.update(['user']).user[0].id == make_entities["new_user"].id
def test_pre_subscription_scenario_autoattach(self): """Create content host and register with Satellite :id: preupgrade-940fc78c-ffa6-4d9a-9c4b-efa1b9480a22 :steps: 1. Before Satellite upgrade. 2. Create new Organization and Location 3. Upload a manifest in it. 4. Create a AK with 'auto-attach False' and without Subscription add in it. 5. Create a content host. 6. Update content host location. :expectedresults: 1. Content host should be created. 2. Content host location should be updated. """ org = entities.Organization().create() loc = entities.Location(organization=[org]).create() manifests.upload_manifest_locked(org.id, interface=manifests.INTERFACE_API) act_key = entities.ActivationKey(auto_attach=False, organization=org.id, environment=org.library.id).create() rhel7_client = dockerize( ak_name=act_key.name, distro='rhel7', org_label=org.label) client_container_id = [value for value in rhel7_client.values()][0] client_container_name = [key for key in rhel7_client.keys()][0] self._host_location_update(client_container_name=client_container_name, loc=loc) status = execute(docker_execute_command, client_container_id, 'subscription-manager identity', host=self.docker_vm)[self.docker_vm] self.assertIn(org.name, status) global_dict = { self.__class__.__name__: {'client_container_id': client_container_id} } create_dict(global_dict)
def test_positive_update_medium(session): """Add/Remove medium from/to location :id: 738c5ff1-ef09-466f-aaac-64f194cac78d :expectedresults: medium is added and removed from the location :CaseLevel: Integration """ media = entities.Media( path_=INSTALL_MEDIUM_URL % gen_string('alpha', 6), os_family='Redhat', ).create() loc = entities.Location().create() with session: session.location.update(loc.name, {'media.resources.assigned': [media.name]}) loc_values = session.location.read(loc.name) assert loc_values['media']['resources']['assigned'][0] == media.name session.location.update(loc.name, {'media.resources.unassigned': [media.name]}) loc_values = session.location.read(loc.name) assert len(loc_values['media']['resources']['assigned']) == 0 assert media.name in loc_values['media']['resources']['unassigned']
def test_positive_ssh_key_in_host_enc(self): """SSH key appears in host ENC output :id: 4b70a950-e777-4b2d-a83d-29279715fe6d :steps: 1. Create user with all the details 2. Add ssh key in above user 3. Provision a new host from the above user 4. Check new hosts ENC output :expectedresults: SSH key should be added to host ENC output :CaseLevel: Integration """ org = entities.Organization().create() loc = entities.Location(organization=[org]).create() user = entities.User( organization=[org], location=[loc]).create() ssh_key = self.gen_ssh_rsakey() entities.SSHKey( user=user, name=gen_string('alpha'), key=ssh_key).create() host = entities.Host( owner=user, owner_type='User', organization=org, location=loc, ).create() sshkey_updated_for_host = '{0} {1}@{2}'.format( ssh_key, user.login, settings.server.hostname ) host_enc_key = host.enc()['data']['parameters']['ssh_authorized_keys'] self.assertEqual(sshkey_updated_for_host, host_enc_key[0])
def test_positive_update_locs(self): """Update a compute resource with new multiple locations @id: cda9f501-2879-4cb0-a017-51ee795232f1 @Assert: Compute resource is updated with expected locations @CaseLevel: Integration """ compresource = entities.LibvirtComputeResource( location=[self.loc], organization=[self.org], url=self.current_libvirt_url, ).create() new_locs = [ entities.Location(organization=[self.org]).create() for _ in range(randint(3, 5)) ] compresource.location = new_locs compresource = compresource.update(['location']) self.assertEqual( set(location.id for location in compresource.location), set(location.id for location in new_locs), )
def test_negative_create_taxonomies_by_org_admin(self): """Org Admin cannot define/create organizations but can create locations :id: 56d9e204-395c-4d6a-b821-43c2f4fe8822 :steps: 1. Create Org Admin role and assign any taxonomies to it 2. Create user and assign above Org Admin role to it 3. Login with above Org Admin user 4. Attempt to create Organizations and locations :expectedresults: 1. Org Admin should not have access to create organizations 2. Org Admin should have access to create locations """ org_admin = self.create_org_admin_role(orgs=[self.role_org.id]) user_login = gen_string('alpha') user_pass = gen_string('alphanumeric') user = entities.User(login=user_login, password=user_pass, role=[org_admin.id], organization=[self.role_org], location=[self.role_loc]).create() self.assertEqual(user_login, user.login) sc = ServerConfig(auth=(user_login, user_pass), url=self.sat_url, verify=False) with self.assertRaises(HTTPError): entities.Organization(sc, name=gen_string('alpha')).create() with self.assertNotRaises(HTTPError): loc_name = gen_string('alpha') loc = entities.Location(sc, name=loc_name).create() self.assertEqual(loc_name, loc.name)
def test_positive_create_with_inherited_params(session): """Create a new Host in organization and location with parameters :BZ: 1287223 :id: 628122f2-bda9-4aa1-8833-55debbd99072 :expectedresults: Host has inherited parameters from organization and location :CaseImportance: High """ org = entities.Organization().create() loc = entities.Location(organization=[org]).create() org_param = dict(name=gen_string('alphanumeric'), value=gen_string('alphanumeric')) loc_param = dict(name=gen_string('alphanumeric'), value=gen_string('alphanumeric')) host_template = entities.Host(organization=org, location=loc) host_template.create_missing() host_name = u'{0}.{1}'.format(host_template.name, host_template.domain.name) with session: session.organization.update(org.name, {'parameters.resources': org_param}) session.location.update(loc.name, {'parameters.resources': loc_param}) session.organization.select(org_name=org.name) session.location.select(loc_name=loc.name) create_fake_host(session, host_template) values = session.host.read(host_name, 'parameters') expected_params = {(org_param['name'], org_param['value']), (loc_param['name'], loc_param['value'])} assert expected_params.issubset({ (param['name'], param['value']) for param in values['parameters']['global_params'] })
def test_positive_assign_taxonomies(session, module_org, module_loc): """Ensure Host organization and Location can be assigned. :id: 52466df5-6f56-4faa-b0f8-42b63731f494 :expectedresults: Host Assign Organization and Location actions are working as expected. :CaseLevel: Integration """ host = entities.Host(organization=module_org, location=module_loc).create() new_host_org = entities.Organization().create() new_host_location = entities.Location(organization=[new_host_org]).create() with session: assert session.host.search(host.name)[0]['Name'] == host.name session.host.apply_action( 'Assign Organization', [host.name], { 'organization': new_host_org.name, 'on_mismatch': 'Fix Organization on Mismatch' }) assert not session.host.search(host.name) session.organization.select(org_name=new_host_org.name) assert session.host.search(host.name)[0]['Name'] == host.name session.host.apply_action( 'Assign Location', [host.name], { 'location': new_host_location.name, 'on_mismatch': 'Fix Location on Mismatch' }) assert not session.host.search(host.name) session.location.select(loc_name=new_host_location.name) assert session.host.search(host.name)[0]['Name'] == host.name values = session.host.get_details(host.name) assert (values['properties']['properties_table']['Organization'] == new_host_org.name) assert (values['properties']['properties_table']['Location'] == new_host_location.name)
def test_positive_search_with_org_and_loc_context(session): """Perform usual search for host, but organization and location used for host create procedure should have 'All capsules' checkbox selected :id: 2ce50df0-2b30-42cc-a40b-0e1f4fde3c6f :expectedresults: Search functionality works as expected and correct result is returned :BZ: 1405496 :CaseLevel: Integration """ org = entities.Organization().create() loc = entities.Location().create() host = entities.Host(organization=org, location=loc).create() with session: session.organization.update(org.name, {'capsules.all_capsules': True}) session.location.update(loc.name, {'capsules.all_capsules': True}) session.organization.select(org_name=org.name) session.location.select(loc_name=loc.name) assert session.host.search('name = "{0}"'.format( host.name))[0]['Name'] == host.name assert session.host.search(host.name)[0]['Name'] == host.name
def test_positive_delete_by_type(): """Delete some entities of different types and check audit logs for these events using entity type as search criteria :id: de9b056f-10da-485a-87ce-b02a9efff15c :expectedresults: Audit logs contain corresponding entries per each delete event :CaseImportance: Medium """ for entity in [ entities.Architecture(), entities.Domain(), entities.Host(), entities.HostGroup(), entities.Location(), entities.Organization(), entities.Role(), entities.UserGroup(), ]: created_entity = entity.create() created_entity.delete() audits = entities.Audit().search( query={ 'search': f'type={created_entity.__class__.__name__.lower()}' }) entity_audits = [ entry for entry in audits if entry.auditable_name == created_entity.name ] assert entity_audits, f'audit not found by name "{created_entity.name}"' audit = entity_audits[0] assert audit.auditable_id == created_entity.id assert audit.action == 'destroy' assert audit.version == 2
def test_positive_advanced_search(self): """Create new provisioning template and associate it with specific organization and location. Also associate it with new hostgroup. Afterwards search for that template by hostgroup :id: 5bcecd40-28af-4913-92a4-863c8dc05ecc :BZ: 1386334 :expectedresults: Template can be found successfully and no error is raised :CaseImportance: Critical """ org = entities.Organization().create() loc = entities.Location().create() hostgroup = entities.HostGroup( organization=[org], location=[loc]).create() template_name = gen_string('alpha') with Session(self) as session: set_context(session, org=org.name, loc=loc.name) make_templates( session, name=template_name, template_path=OS_TEMPLATE_DATA_FILE, custom_really=True, template_type='Provisioning template', hostgroup=hostgroup.name, ) self.assertIsNotNone(self.template.search(template_name)) self.assertIsNotNone( self.template.search( template_name, _raw_query='hostgroup = {}'.format(hostgroup.name) ) )
def setUpClass(cls): super(RhevComputeResourceHostTestCase, cls).setUpClass() cls.rhev_url = settings.rhev.hostname cls.rhev_password = settings.rhev.password cls.rhev_username = settings.rhev.username cls.rhev_datacenter = settings.rhev.datacenter cls.rhev_img_name = settings.rhev.image_name cls.rhev_img_arch = settings.rhev.image_arch cls.rhev_img_os = settings.rhev.image_os cls.rhev_img_user = settings.rhev.image_username cls.rhev_img_pass = settings.rhev.image_password cls.rhev_vm_name = settings.rhev.vm_name cls.rhev_storage_domain = settings.rhev.storage_domain cls.org = entities.Organization(name=gen_string('alpha')).create() cls.org_name = cls.org.name cls.loc = entities.Location( name=gen_string('alpha'), organization=[cls.org], ).create() cls.loc_name = cls.loc.name cls.config_env = configure_provisioning(compute=True, org=cls.org, loc=cls.loc)
def test_positive_end_to_end(session): """Create all possible entities that required for operating system and then test all scenarios like create/read/update/delete for it :id: 280afff3-ebf4-4a54-af11-200327b8957b :expectedresults: All scenarios flows work properly :CaseLevel: Integration """ name = gen_string('alpha') major_version = gen_string('numeric', 2) minor_version = gen_string('numeric', 2) description = gen_string('alpha') family = 'Red Hat' hash = HASH_TYPE['md5'] architecture = entities.Architecture().create() org = entities.Organization().create() loc = entities.Location().create() ptable = entities.PartitionTable( organization=[org], location=[loc], os_family='Redhat', ).create() medium = entities.Media( organization=[org], location=[loc], ).create() param_name = gen_string('alpha') param_value = gen_string('alpha') with session: session.organization.select(org_name=org.name) session.location.select(loc_name=loc.name) session.operatingsystem.create({ 'operating_system.name': name, 'operating_system.major': major_version, 'operating_system.minor': minor_version, 'operating_system.description': description, 'operating_system.family': family, 'operating_system.password_hash': hash, 'operating_system.architectures.assigned': [architecture.name], 'partition_table.resources.assigned': [ptable.name], 'installation_media.resources.assigned': [medium.name], 'parameters.os_params': { 'name': param_name, 'value': param_value }, }) assert session.operatingsystem.search( description)[0]['Title'] == description os = session.operatingsystem.read(description) assert os['operating_system']['name'] == name assert os['operating_system']['major'] == major_version assert os['operating_system']['minor'] == minor_version assert os['operating_system']['description'] == description assert os['operating_system']['family'] == family assert os['operating_system']['password_hash'] == hash assert len(os['operating_system']['architectures']['assigned']) == 1 assert os['operating_system']['architectures']['assigned'][ 0] == architecture.name assert ptable.name in os['partition_table']['resources']['assigned'] assert os['installation_media']['resources']['assigned'][ 0] == medium.name assert len(os['parameters']['os_params']) == 1 assert os['parameters']['os_params'][0]['name'] == param_name assert os['parameters']['os_params'][0]['value'] == param_value new_description = gen_string('alpha') session.operatingsystem.update( description, {'operating_system.description': new_description}) assert not session.operatingsystem.search(description) assert session.operatingsystem.search( new_description)[0]['Title'] == new_description assert session.partitiontable.search( ptable.name)[0]['Operating Systems'] == new_description session.operatingsystem.delete(new_description) assert not session.operatingsystem.search(new_description)
def setUpClass(cls): super(TemplateTestCase, cls).setUpClass() cls.organization = entities.Organization().create() cls.loc = entities.Location().create()
def configure_puppet_test(): sat6_hostname = settings.server.hostname repo_values = [ { 'repo': REPOS['rhst6']['name'], 'reposet': REPOSET['rhst6'] }, { 'repo': REPOS['rhst7']['name'], 'reposet': REPOSET['rhst7'] }, ] # step 1: Create new organization and environment. org = entities.Organization(name=gen_string('alpha')).create() loc = entities.Location(name=DEFAULT_LOC).search()[0].read() puppet_env = entities.Environment(name='production').search()[0].read() puppet_env.location.append(loc) puppet_env.organization.append(org) puppet_env = puppet_env.update(['location', 'organization']) Proxy.import_classes({ u'environment': puppet_env.name, u'name': sat6_hostname, }) env = entities.LifecycleEnvironment(organization=org, name=gen_string('alpha')).create() # step 2: Clone and Upload manifest with manifests.clone() as manifest: upload_manifest(org.id, manifest.content) # step 3: Sync RedHat Sattools RHEL6 and RHEL7 repository repos = [ entities.Repository(id=enable_rhrepo_and_fetchid( basearch='x86_64', org_id=org.id, product=PRDS['rhel'], repo=value['repo'], reposet=value['reposet'], releasever=None, )) for value in repo_values ] for repo in repos: repo.sync() # step 4: Create content view content_view = entities.ContentView(organization=org, name=gen_string('alpha')).create() # step 5: Associate repository to new content view content_view.repository = repos content_view = content_view.update(['repository']) # step 6: Publish content view and promote to lifecycle env. content_view.publish() content_view = content_view.read() promote(content_view.version[0], env.id) # step 7: Create activation key ak_name = gen_string('alpha') activation_key = entities.ActivationKey( name=ak_name, environment=env, organization=org, content_view=content_view, ).create() # step 7.1: Walk through the list of subscriptions. # Find the "Employee SKU" and attach it to the # recently-created activation key. for sub in entities.Subscription(organization=org).search(): if sub.read_json()['product_name'] == DEFAULT_SUBSCRIPTION_NAME: # 'quantity' must be 1, not subscription['quantity']. Greater # values produce this error: "RuntimeError: Error: Only pools # with multi-entitlement product subscriptions can be added to # the activation key with a quantity greater than one." activation_key.add_subscriptions(data={ 'quantity': 1, 'subscription_id': sub.id, }) break for content_label in [REPOS['rhst6']['id'], REPOS['rhst7']['id']]: # step 7.2: Enable product content activation_key.content_override( data={ 'content_override': { u'content_label': content_label, u'value': u'1', } }) return { 'org_name': org.name, 'cv_name': content_view.name, 'sat6_hostname': settings.server.hostname, 'ak_name': ak_name, 'env_name': env.name, }
def module_loc(): return entities.Location().create()
def configure_provisioning(org=None, loc=None, compute=False): """Create and configure org, loc, product, repo, cv, env. Update proxy, domain, subnet, compute resource, provision templates and medium with previously created entities and create a hostgroup using all mentioned entities. :param org: Default Organization that should be used in both host discovering and host provisioning procedures :param loc: Default Location that should be used in both host discovering and host provisioning procedures :return: List of created entities that can be re-used further in provisioning or validation procedure (e.g. hostgroup or domain) """ # Create new organization and location in case they were not passed if org is None: org = entities.Organization().create() if loc is None: loc = entities.Location(organization=[org]).create() # Create a new Life-Cycle environment lc_env = entities.LifecycleEnvironment(organization=org).create() # Create a Product, Repository for custom RHEL6 contents product = entities.Product(organization=org).create() repo = entities.Repository(product=product, url=settings.rhel7_os).create() # Increased timeout value for repo sync try: old_task_timeout = entity_mixins.TASK_TIMEOUT entity_mixins.TASK_TIMEOUT = 3600 repo.sync() # Create, Publish and promote CV content_view = entities.ContentView(organization=org).create() content_view.repository = [repo] content_view = content_view.update(['repository']) content_view.publish() content_view = content_view.read() promote(content_view.version[0], lc_env.id) finally: entity_mixins.TASK_TIMEOUT = old_task_timeout # Search for puppet environment and associate location environment = entities.Environment( organization=[org.id]).search()[0].read() environment.location.append(loc) environment = environment.update(['location']) # Search for SmartProxy, and associate location proxy = entities.SmartProxy().search( query={u'search': u'name={0}'.format(settings.server.hostname)}) proxy = proxy[0].read() proxy.location.append(loc) proxy = proxy.update(['location']) proxy.organization.append(org) proxy = proxy.update(['organization']) # Search for existing domain or create new otherwise. Associate org, # location and dns to it _, _, domain = settings.server.hostname.partition('.') domain = entities.Domain().search( query={u'search': u'name="{0}"'.format(domain)}) if len(domain) == 1: domain = domain[0].read() domain.location.append(loc) domain.organization.append(org) domain.dns = proxy domain = domain.update(['dns', 'location', 'organization']) else: domain = entities.Domain( dns=proxy, location=[loc], organization=[org], ).create() # Search if subnet is defined with given network. # If so, just update its relevant fields otherwise, # Create new subnet network = settings.vlan_networking.subnet subnet = entities.Subnet().search( query={u'search': u'network={0}'.format(network)}) if len(subnet) == 1: subnet = subnet[0].read() subnet.domain = [domain] subnet.location.append(loc) subnet.organization.append(org) subnet.dns = proxy subnet.dhcp = proxy subnet.tftp = proxy subnet.discovery = proxy subnet = subnet.update([ 'domain', 'dhcp', 'tftp', 'dns', 'discovery', 'location', 'organization', ]) else: # Create new subnet subnet = entities.Subnet(network=network, mask=settings.vlan_networking.netmask, domain=[domain], location=[loc], organization=[org], dns=proxy, dhcp=proxy, tftp=proxy, discovery=proxy).create() # Search if Libvirt compute-resource already exists # If so, just update its relevant fields otherwise, # Create new compute-resource with 'libvirt' provider. # compute boolean is added to not block existing test's that depend on # Libvirt resource and use this same functionality to all CR's. if compute is False: resource_url = u'qemu+ssh://root@{0}/system'.format( settings.compute_resources.libvirt_hostname) comp_res = [ res for res in entities.LibvirtComputeResource().search() if res.provider == 'Libvirt' and res.url == resource_url ] if len(comp_res) > 0: computeresource = entities.LibvirtComputeResource( id=comp_res[0].id).read() computeresource.location.append(loc) computeresource.organization.append(org) computeresource = computeresource.update( ['location', 'organization']) else: # Create Libvirt compute-resource computeresource = entities.LibvirtComputeResource( provider=u'libvirt', url=resource_url, set_console_password=False, display_type=u'VNC', location=[loc.id], organization=[org.id], ).create() # Get the Partition table ID ptable = entities.PartitionTable().search( query={u'search': u'name="{0}"'.format(DEFAULT_PTABLE)})[0].read() # Get the OS ID os = entities.OperatingSystem().search( query={ u'search': u'name="RedHat" AND (major="{0}" OR major="{1}")'.format( RHEL_6_MAJOR_VERSION, RHEL_7_MAJOR_VERSION) })[0].read() # Get the Provisioning template_ID and update with OS, Org, Location provisioning_template = entities.ConfigTemplate().search( query={u'search': u'name="{0}"'.format(DEFAULT_TEMPLATE)}) provisioning_template = provisioning_template[0].read() provisioning_template.operatingsystem.append(os) provisioning_template.organization.append(org) provisioning_template.location.append(loc) provisioning_template = provisioning_template.update( ['location', 'operatingsystem', 'organization']) # Get the PXE template ID and update with OS, Org, location pxe_template = entities.ConfigTemplate().search( query={u'search': u'name="{0}"'.format(DEFAULT_PXE_TEMPLATE)}) pxe_template = pxe_template[0].read() pxe_template.operatingsystem.append(os) pxe_template.organization.append(org) pxe_template.location.append(loc) pxe_template = pxe_template.update( ['location', 'operatingsystem', 'organization']) # Get the arch ID arch = entities.Architecture().search( query={u'search': u'name="x86_64"'})[0].read() # Update the OS to associate arch, ptable, templates os.architecture.append(arch) os.ptable.append(ptable) os.config_template.append(provisioning_template) os.config_template.append(pxe_template) os = os.update([ 'architecture', 'config_template', 'ptable', ]) # Create Hostgroup host_group = entities.HostGroup( architecture=arch, domain=domain.id, subnet=subnet.id, lifecycle_environment=lc_env.id, content_view=content_view.id, location=[loc.id], environment=environment.id, puppet_proxy=proxy, puppet_ca_proxy=proxy, content_source=proxy, root_pass=gen_string('alphanumeric'), operatingsystem=os.id, organization=[org.id], ptable=ptable.id, ).create() return { 'host_group': host_group.name, 'domain': domain.name, 'environment': environment.name, 'ptable': ptable.name, }