def test_positive_remove_parameter_non_admin_user(test_name, module_org, module_loc): """Remove a host parameter as a non-admin user with enough permissions :id: 598111c1-fdb6-42e9-8c28-fae999b5d112 :expectedresults: user with sufficient permissions may remove host parameter :CaseLevel: System """ user_password = gen_string('alpha') parameter = {'name': gen_string('alpha'), 'value': gen_string('alpha')} role = entities.Role(organization=[module_org]).create() create_role_permissions( role, { 'Parameter': PERMISSIONS['Parameter'], 'Host': PERMISSIONS['Host'], 'Operatingsystem': ['view_operatingsystems'], }) user = entities.User( role=[role], admin=False, password=user_password, organization=[module_org], location=[module_loc], default_organization=module_org, default_location=module_loc, ).create() host = entities.Host( content_facet_attributes={ 'content_view_id': module_org.default_content_view.id, 'lifecycle_environment_id': module_org.library.id, }, location=module_loc, organization=module_org, host_parameters_attributes=[parameter], ).create() with Session(test_name, user=user.login, password=user_password) as session: values = session.host.read(host.name, 'parameters') assert values['parameters']['host_params'][0] == parameter session.host.update(host.name, {'parameters.host_params': []}) values = session.host.read(host.name, 'parameters') assert not values['parameters']['host_params']
def test_positive_generate_registered_hosts_report(session, module_org, module_loc): """Use provided Host - Registered Content Hosts report for testing :id: b44d4cd8-a78e-47cf-9993-0bb871ac2c96 :expectedresults: The Host - Registered Content Hosts report is generated (with host filter) and it contains created host with correct data :CaseLevel: Integration :CaseImportance: High """ # generate Host Status report os_name = 'comma,' + gen_string('alpha') os = entities.OperatingSystem(name=os_name).create() host_cnt = 3 host_templates = [ entities.Host(organization=module_org, location=module_loc, operatingsystem=os) for i in range(host_cnt) ] for host_template in host_templates: host_template.create_missing() with session: # create multiple hosts to test filtering host_names = [create_fake_host(session, host_template) for host_template in host_templates] host_name = host_names[1] # pick some that is not first and is not last file_path = session.reporttemplate.generate( 'Host - Registered Content Hosts', values={'hosts_filter': host_name} ) with open(file_path) as csvfile: dreader = csv.DictReader(csvfile) res = next(dreader) assert list(res.keys()) == [ 'Name', 'Ip', 'Operating System', 'Subscriptions', 'Applicable Errata', 'Owner', 'Kernel', 'Latest kernel available', ] assert res['Name'] == host_name # also tests comma in field contents assert res['Operating System'] == f'{os_name} {os.major}'
def test_positive_end_to_end(session, module_org, module_loc): """Perform end to end testing for host collection component :id: 1d40bc74-8e05-42fa-b6e3-2999dc3b730d :expectedresults: All expected CRUD actions finished successfully :CaseLevel: Integration :CaseImportance: High """ hc_name = gen_string('alpha') new_name = gen_string('alpha') description = gen_string('alpha') host = entities.Host(organization=module_org, location=module_loc).create() with session: # Create new host collection session.hostcollection.create({ 'name': hc_name, 'unlimited_hosts': False, 'max_hosts': 2, 'description': description }) assert session.hostcollection.search(hc_name)[0]['Name'] == hc_name session.hostcollection.associate_host(hc_name, host.name) hc_values = session.hostcollection.read( hc_name, widget_names=['details', 'hosts']) assert hc_values['details']['name'] == hc_name assert hc_values['details']['description'] == description assert hc_values['details']['content_hosts'] == '1' assert hc_values['details']['content_host_limit'] == '2' assert hc_values['hosts']['resources']['assigned'][0][ 'Name'] == host.name # View host collection on dashboard values = session.dashboard.read('HostCollections') assert [hc_name, '1'] in [[coll['Name'], coll['Content Hosts']] for coll in values['collections']] # Update host collection with new name session.hostcollection.update(hc_name, {'details.name': new_name}) assert session.hostcollection.search(new_name)[0]['Name'] == new_name # Delete host collection session.hostcollection.delete(new_name) assert not session.hostcollection.search(new_name)
def test_negative_run_capsule_upgrade_playbook_on_satellite(default_org): """Run Capsule Upgrade playbook against the Satellite itself :id: 99462a11-5133-415d-ba64-4354da539a34 :steps: 1. Add REX key to the Satellite server. 2. Run the Capsule Upgrade Playbook. 3. Check the job output for proper failure reason. :expectedresults: Should fail :CaseImportance: Medium """ sat = entities.Host().search( query={'search': f'name={settings.server.hostname}'})[0].read() template_id = (entities.JobTemplate().search( query={'search': 'name="Capsule Upgrade Playbook"'})[0].id) add_remote_execution_ssh_key(sat.name) with pytest.raises(TaskFailedError) as error: entities.JobInvocation().run( data={ 'job_template_id': template_id, 'inputs': { 'target_version': CAPSULE_TARGET_VERSION, 'whitelist_options': "repositories-validqqate,repositories-setup", }, 'targeting_type': "static_query", 'search_query': f"name = {sat.name}", }) assert 'A sub task failed' in error.value.args[0] job = entities.JobInvocation().search( query={ 'search': f'host={sat.name},status=failed,description="Capsule Upgrade Playbook"' })[0] response = client.get( f'https://{sat.name}/api/job_invocations/{job.id}/hosts/{sat.id}', auth=settings.server.get_credentials(), verify=False, ) assert 'This playbook cannot be executed on a Satellite server.' in response.text
def _install_package(self, clients, host_ids, package_name): """Workaround BZ1374669 and install package via CLI while the bug is open. """ if bz_bug_is_open(1374669): for client in clients: result = client.run('yum install -y {}'.format(package_name)) self.assertEqual(result.return_code, 0) result = client.run('rpm -q {}'.format(package_name)) self.assertEqual(result.return_code, 0) return entities.Host().install_content(data={ 'organization_id': self.org.id, 'included': {'ids': host_ids}, 'content_type': 'package', 'content': [package_name], }) self._validate_package_installed(clients, package_name)
def test_negative_update_name(self): """Attempt to update a host with invalid or empty name @id: 1c46b44c-a2ea-43a6-b4d9-244101b081e8 @assert: A host is not updated """ host = entities.Host().create() for new_name in invalid_values_list(): with self.subTest(new_name): host.name = new_name with self.assertRaises(HTTPError): host.update(['name']) self.assertNotEqual( host.read().name, u'{0}.{1}' .format(new_name, host.domain.read().name).lower() )
def test_negative_update_os(self): """Attempt to update a host with an operating system, which is not associated with host's medium @feature: Hosts @assert: A host is not updated """ host = entities.Host().create() new_os = entities.OperatingSystem( architecture=[host.architecture], ptable=[host.ptable], ).create() host.operatingsystem = new_os with self.assertRaises(HTTPError): host = host.update(['operatingsystem']) self.assertNotEqual( host.read().operatingsystem.read().name, new_os.name)
def test_negative_update_os(): """Attempt to update a host with an operating system, which is not associated with host's medium :id: 40e79f73-6356-4d61-9806-7ade2f4f8829 :expectedresults: A host is not updated :CaseLevel: Integration """ host = entities.Host().create() new_os = entities.OperatingSystem( architecture=[host.architecture], ptable=[host.ptable] ).create() host.operatingsystem = new_os with pytest.raises(HTTPError): host = host.update(['operatingsystem']) assert host.read().operatingsystem.read().name != new_os.name
def test_positive_get_search(): """GET ``api/v2/hosts`` and specify the ``search`` parameter. :id: d63f87e5-66e6-4886-8b44-4129259493a6 :expectedresults: HTTP 200 is returned, along with ``search`` term. :CaseImportance: Critical """ query = gen_string('utf8', gen_integer(1, 100)) response = client.get( entities.Host().path(), auth=settings.server.get_credentials(), data={'search': query}, verify=False, ) assert response.status_code == http.client.OK assert response.json()['search'] == query
def test_positive_read_puppet_ca_proxy_name(): """Read a hostgroup created with puppet ca proxy and inspect server's response :id: 8941395f-8040-4705-a981-5da21c47efd1 :expectedresults: Field 'puppet_ca_proxy_name' is returned :BZ: 1371900 :CaseImportance: Critical """ proxy = entities.SmartProxy().search( query={'search': f'url = https://{settings.server.hostname}:9090'} )[0] host = entities.Host(puppet_ca_proxy=proxy).create().read_json() assert 'puppet_ca_proxy_name' in host assert proxy.name == host['puppet_ca_proxy_name']
def module_host(module_org, module_loc, content_view, puppet_env, puppet_class): lce = entities.LifecycleEnvironment().search( query={ 'search': 'organization_id="{0}" and name="{1}"'.format( module_org.id, ENVIRONMENT) })[0] host = entities.Host(organization=module_org, location=module_loc, content_facet_attributes={ 'content_view_id': content_view.id, 'lifecycle_environment_id': lce.id, }).create() host.environment = puppet_env host.update(['environment']) host.add_puppetclass(data={'puppetclass_id': puppet_class.id}) return host
def test_positive_read_puppet_proxy_name(): """Read a hostgroup created with puppet proxy and inspect server's response :id: 8825462e-f1dc-4054-b7fb-69c2b10722a2 :expectedresults: Field 'puppet_proxy_name' is returned :BZ: 1371900 :CaseImportance: Critical """ proxy = entities.SmartProxy().search( query={'search': f'url = https://{settings.server.hostname}:9090'} )[0] host = entities.Host(puppet_proxy=proxy).create().read_json() assert 'puppet_proxy_name' in host assert proxy.name == host['puppet_proxy_name']
def test_positive_create_and_update_with_build_parameter(build): """Create and update a host with 'build' parameter specified. Build parameter determines whether to enable the host for provisioning :id: de30cf62-5036-4247-a5f0-37dd2b4aae23 :parametrized: yes :expectedresults: A host is created and updated with expected 'build' parameter value :CaseImportance: Critical """ host = entities.Host(build=build).create() assert host.build == build host.build = not build host = host.update(['build']) assert host.build == (not build)
def test_positive_update_os(self): """Update a host with a new operating system @feature: Hosts @assert: A host is updated with a new operating system """ host = entities.Host().create() new_os = entities.OperatingSystem( architecture=[host.architecture], ptable=[host.ptable], ).create() medium = entities.Media(id=host.medium.id).read() medium.operatingsystem.append(new_os) medium.update(['operatingsystem']) host.operatingsystem = new_os host = host.update(['operatingsystem']) self.assertEqual(host.operatingsystem.read().name, new_os.name)
def test_positive_create_and_update_domain(module_org, module_location, module_domain): """Create and update a host with a domain :id: 8ca9f67c-4c11-40f9-b434-4f200bad000f :expectedresults: A host is created and updated with expected domain :CaseLevel: Integration """ host = entities.Host( organization=module_org, location=module_location, domain=module_domain ).create() assert host.domain.read().name == module_domain.name new_domain = entities.Domain(organization=[module_org], location=[module_location]).create() host.domain = new_domain host = host.update(['domain']) assert host.domain.read().name == new_domain.name
def test_positive_provision_end_to_end(self): """Provision Host on libvirt compute resource :id: 2678f95f-0c0e-4b46-a3c1-3f9a954d3bde :expectedresults: Host is provisioned successfully :CaseLevel: System """ hostname = gen_string('numeric') with Session(self) as session: make_host( session, name=hostname, org=self.org_name, loc=self.loc_name, force_context=True, parameters_list=[ ['Host', 'Organization', self.org_name], ['Host', 'Location', self.loc_name], ['Host', 'Host group', self.host_group.name], ['Host', 'Deploy on', self.resource], ['Host', 'Puppet Environment', self.puppet_env.name], ['Virtual Machine', 'Memory', '1 GB'], ['Operating System', 'Root password', self.root_pwd], ], interface_parameters=[ ['Network type', 'Physical (Bridge)'], ['Network', settings.vlan_networking.bridge], ], ) name = u'{0}.{1}'.format(hostname, self.domain_name) self.assertIsNotNone(self.hosts.search(name)) self.addCleanup( host_cleanup, entities.Host().search( query={'search': 'name={}'.format(name)})[0].id) for _ in range(25): result = self.hosts.get_host_properties(name, ['Build']) if result['Build'] == 'Pending installation': sleep(30) else: break self.assertEqual(result['Build'], 'Installed')
def test_positive_create(self): """Create a new Host :id: 4821444d-3c86-4f93-849b-60460e025ba0 :expectedresults: Host is created :CaseLevel: System """ host = entities.Host() host.create_missing() os_name = u'{0} {1}'.format(host.operatingsystem.name, host.operatingsystem.major) with Session(self.browser) as session: make_host( session, name=host.name, org=host.organization.name, parameters_list=[ ['Host', 'Organization', host.organization.name], ['Host', 'Location', host.location.name], ['Host', 'Lifecycle Environment', ENVIRONMENT], ['Host', 'Content View', DEFAULT_CV], ['Host', 'Puppet Environment', host.environment.name], [ 'Operating System', 'Architecture', host.architecture.name ], ['Operating System', 'Operating system', os_name], ['Operating System', 'Media', host.medium.name], ['Operating System', 'Partition table', host.ptable.name], ['Operating System', 'Root password', host.root_pass], ], interface_parameters=[ ['Type', 'Interface'], ['MAC address', host.mac], ['Domain', host.domain.name], ['Primary', True], ], ) # confirm the Host appears in the UI search = self.hosts.search(u'{0}.{1}'.format( host.name, host.domain.name)) self.assertIsNotNone(search)
def test_positive_create_with_name(self): """A host can be created with a random name @id: 2e8dd25d-47ed-4131-bba6-1ff024808d05 @assert: A host is created and the name matches """ for name in valid_hosts_list(): with self.subTest(name): host = entities.Host() host.create_missing() result = Host.create({ u'architecture-id': host.architecture.id, u'domain-id': host.domain.id, u'environment-id': host.environment.id, # pylint:disable=no-member u'location-id': host.location.id, u'mac': host.mac, u'medium-id': host.medium.id, u'name': 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( '{0}.{1}'.format(name, host.domain.read().name), result['name'], )
def test_positive_content_host_previous_env(session, module_org, module_repos_col, vm): """Check if the applicable errata are available from the content host's previous environment :id: 78110ba8-3942-46dd-8c14-bffa1dbd5195 :Setup: 1. Make sure multiple environments are present. 2. Content host's previous environments have additional errata. :Steps: Go to Content Hosts -> Select content host -> Errata Tab -> Select Previous environments. :expectedresults: The errata from previous environments are displayed. :CaseLevel: System """ host_name = vm.hostname assert _install_client_package(vm, FAKE_1_CUSTOM_PACKAGE, errata_applicability=True) # Promote the latest content view version to a new lifecycle environment content_view = entities.ContentView( id=module_repos_col.setup_content_data['content_view']['id']).read() content_view_version = content_view.version[-1].read() lce = content_view_version.environment[-1].read() new_lce = entities.LifecycleEnvironment(organization=module_org, prior=lce).create() promote(content_view_version, new_lce.id) host = entities.Host().search( query={'search': 'name={0}'.format(host_name)})[0].read() host.content_facet_attributes = { 'content_view_id': content_view.id, 'lifecycle_environment_id': new_lce.id, } host.update(['content_facet_attributes']) with session: environment = 'Previous Lifecycle Environment ({0}/{1})'.format( lce.name, content_view.name) content_host_erratum = session.contenthost.search_errata( host_name, CUSTOM_REPO_ERRATA_ID, environment=environment) assert content_host_erratum[0]['Id'] == CUSTOM_REPO_ERRATA_ID
def test_positive_associate_scap_policy_with_single_server(self): """Assign an audit policy to a single server :id: 30566c27-f466-4b4d-beaf-0a5bfda98b89 :setup: 1. Oscap should be enabled. 2. Oscap-cli hammer plugin installed. 3. At least 1 policy and host. :steps: 1. Login to hammer shell. 2. Execute "policy" command with "update" as sub-command. 3. Pass host name as the parameter. :expectedresults: The scap policy is updated. """ host = entities.Host() host.create() name = gen_string('alpha') scap_policy = make_scap_policy({ 'name': name, 'deploy-by': 'puppet', 'scap-content-id': self.scap_id_rhel7, 'scap-content-profile-id': self.scap_profile_id_rhel7, 'period': OSCAP_PERIOD['weekly'].lower(), 'weekday': OSCAP_WEEKDAY['friday'].lower() }) host_name = host.name + "." + host.domain.name Scappolicy.update({ 'id': scap_policy['id'], 'hosts': host_name, }) hosts = Host.list( {'search': 'compliance_policy_id = {0}'.format(scap_policy['id'])}) assert host_name in [host['name'] for host in hosts]
def test_positive_read_from_edit_page(session): """Create new Host and read all its content through edit page :id: 758fcab3-b363-4bfc-8f5d-173098a7e72d :expectedresults: Host is created and has expected content :CaseLevel: System """ host = entities.Host() host.create_missing() os_name = u'{0} {1}'.format( host.operatingsystem.name, host.operatingsystem.major) interface_id = gen_string('alpha') host_name = u'{0}.{1}'.format(host.name, host.domain.name) with session: session.organization.select(org_name=host.organization.name) session.location.select(loc_name=host.location.name) create_fake_host(session, host, interface_id) assert session.host.search(host_name)[0]['Name'] == host_name values = session.host.read(host_name) assert values['host']['name'] == host.name assert values['host']['organization'] == host.organization.name assert values['host']['location'] == host.location.name assert values['host']['lce'] == ENVIRONMENT assert values['host']['content_view'] == DEFAULT_CV assert values['host']['puppet_environment'] == host.environment.name assert values[ 'operating_system']['architecture'] == host.architecture.name assert values['operating_system']['operating_system'] == os_name assert values['operating_system']['media_type'] == 'All Media' assert values['operating_system']['media'] == host.medium.name assert values['operating_system']['ptable'] == host.ptable.name assert values['interfaces']['interfaces_list'][0][ 'Identifier'] == interface_id assert values['interfaces']['interfaces_list'][0][ 'Type'] == 'Interface physical' assert values['interfaces']['interfaces_list'][0][ 'MAC Address'] == host.mac assert values['interfaces']['interfaces_list'][0][ 'FQDN'] == host_name assert values['additional_information'][ 'owned_by'] == values['current_user'] assert values['additional_information']['enabled'] is True
def test_positive_create_event(session, module_org, module_location): """When new host is created, corresponding audit entry appear in the application :id: d0595705-f4b2-4f06-888b-ee93edd4acf8 :expectedresults: Audit entry for created host contains valid data :CaseAutomation: Automated :CaseLevel: Integration :CaseImportance: Medium :BZ: 1730360 """ host = entities.Host(organization=module_org, location=module_location).create() with session: session.organization.select(org_name=module_org.name) session.location.select(loc_name=module_location.name) values = session.audit.search('type=host') assert values.get('action_type') == 'create' assert values.get('resource_type') == 'HOST' assert values.get('resource_name') == host.name assert values.get('created_at') assert values.get('affected_organization') == module_org.name assert values.get('affected_location') == module_location.name summary = { prop['column0']: prop['column1'] for prop in values.get('action_summary') if prop.get('column1') } assert summary.get('Name') == host.name assert summary.get('Architecture') == host.architecture.read().name os = host.operatingsystem.read() assert summary.get('Operatingsystem') == f'{os.name} {os.major}' assert summary.get('Environment') == host.environment.read().name assert summary.get('Ptable') == host.ptable.read().name assert summary.get('Medium') == host.medium.read().name assert summary.get('Build') == 'false' assert summary.get('Owner type') == 'User' assert summary.get('Managed') == 'true' assert summary.get('Enabled') == 'true' assert summary.get('Organization') == module_org.name assert summary.get('Location') == module_location.name
def test_positive_create_with_compresource(self): """Create a host with compute resource specified @feature: Hosts @assert: A host is created with expected compute resource assigned """ org = entities.Organization().create() loc = entities.Location(organization=[org]).create() compresource = entities.LibvirtComputeResource( location=[loc], organization=[org], ).create() host = entities.Host( compute_resource=compresource, location=loc, organization=org, ).create() self.assertEqual(host.compute_resource.read().name, compresource.name)
def test_positive_subscription_status_disabled(module_ak, rhel7_contenthost, module_org): """Verify that Content host Subscription status is set to 'Disabled' for a golden ticket manifest :id: d7d7e20a-e386-43d5-9619-da933aa06694 :expectedresults: subscription status is 'Disabled' :BZ: 1789924 :CaseImportance: Medium """ rhel7_contenthost.install_katello_ca() rhel7_contenthost.register_contenthost(module_org.label, module_ak.name) assert rhel7_contenthost.subscribed host_content = entities.Host( id=rhel7_contenthost.nailgun_host.id).read_raw().content assert 'Simple Content Access' in str(host_content)
def test_positive_update_medium(self): """Update a host with a new medium @feature: Hosts @assert: A host is updated with a new medium """ host = entities.Host().create() new_medium = entities.Media( operatingsystem=[host.operatingsystem], # pylint:disable=no-member location=[host.location], organization=[host.organization], ).create() new_medium.operatingsystem.append(host.operatingsystem) new_medium.update(['operatingsystem']) host.medium = new_medium host = host.update(['medium']) self.assertEqual(host.medium.read().name, new_medium.name)
def test_positive_get_per_page(): """GET ``api/v2/hosts`` and specify the ``per_page`` parameter. :id: 9086f41c-b3b9-4af2-b6c4-46b80b4d1cfd :expectedresults: HTTP 200 is returned, along with per ``per_page`` value. :CaseImportance: Critical """ per_page = gen_integer(1, 1000) response = client.get( entities.Host().path(), auth=settings.server.get_credentials(), data={'per_page': str(per_page)}, verify=False, ) assert response.status_code == http.client.OK assert response.json()['per_page'] == per_page
def test_positive_create_and_update_with_managed_parameter(managed): """Create and update a host with managed parameter specified. Managed flag shows whether the host is managed or unmanaged and determines whether some extra parameters are required :id: 00dcfaed-6f54-4b6a-a022-9c97fb992324 :parametrized: yes :expectedresults: A host is created and updated with expected managed parameter value :CaseImportance: Critical """ host = entities.Host(managed=managed).create() assert host.managed == managed host.managed = not managed host = host.update(['managed']) assert host.managed == (not managed)
def test_positive_create_and_update_with_enabled_parameter(enabled): """Create and update a host with 'enabled' parameter specified. Enabled parameter determines whether to include the host within Satellite 6 reporting :id: bd8d33f9-37de-4b8d-863e-9f73cd8dcec1 :parametrized: yes :expectedresults: A host is created and updated with expected 'enabled' parameter value :CaseImportance: Critical """ host = entities.Host(enabled=enabled).create() assert host.enabled == enabled host.enabled = not enabled host = host.update(['enabled']) assert host.enabled == (not enabled)
def test_positive_delete(session): """Delete a Host :id: 13735af1-f1c7-466e-a969-80618a1d854d :expectedresults: Host is delete :CaseLevel: System """ host = entities.Host() host.create_missing() host_name = u'{0}.{1}'.format(host.name, host.domain.name) with session: session.organization.select(org_name=host.organization.name) session.location.select(loc_name=host.location.name) create_fake_host(session, host) assert session.host.search(host_name)[0]['Name'] == host_name session.host.delete(host_name) assert not session.host.search(host_name)
def test_positive_create_and_update_with_subnet( module_location, module_org, module_default_subnet ): """Create and update a host with subnet specified :id: 9aa97aff-8439-4027-89ee-01c643fbf7d1 :expectedresults: A host is created and updated with expected subnet assigned :CaseLevel: Integration """ host = entities.Host( location=module_location, organization=module_org, subnet=module_default_subnet ).create() assert host.subnet.read().name == module_default_subnet.name new_subnet = entities.Subnet(location=[module_location], organization=[module_org]).create() host.subnet = new_subnet host = host.update(['subnet']) assert host.subnet.read().name == new_subnet.name