def fixture_vmsetup(request, module_org): """ Create VM and register content host """ if '_count' in request.param.keys(): with VMBroker( nick=request.param['nick'], host_classes={'host': ContentHost}, _count=request.param['_count'], ) as clients: for client in clients: _setup_host(client, module_org.label) yield clients else: with VMBroker(nick=request.param['nick'], host_classes={'host': ContentHost}) as client: _setup_host(client, module_org.label) yield client
def client_provisioning(self, activation_key_name, organization_label, package_name='python-kitchen'): """Provision a Satellite's client. Do the following: 1. Install Katello CA cert on the client 2. Register the client using Activation Key 3. Install a package on the client served by the Satellite server. :param activation_key_name: Name of the Activation Key to register. :param organization_label: Organization label where the Activation Key is available. :param package_name: Name of the package to be installed on the client. """ if not setting_is_set('clients'): return with VMBroker(nick='rhel6', host_classes={'host': ContentHost}) as host: # Pull rpm from Foreman server and install on client host.install_katello_ca() # Register client with foreman server using act keys host.register_contenthost(organization_label, activation_key_name) assert host.subscribed # Install rpm on client result = host.run(f'yum install -y {package_name}') assert result.status == 0 # Verify that the package is installed by querying it result = host.run(f'rpm -q {package_name}') assert result.status == 0
def sat_maintain(satellite_factory): if settings.remotedb.server: yield Satellite(settings.remotedb.server) else: sat = satellite_factory() yield sat VMBroker(hosts=[sat]).checkin()
def test_vm_install_package(org, lce, distro, cdn): """Install a package with all supported distros and cdn / non-cdn variants :id: b2a6065a-69f6-4805-a28b-eaaa812e0f4b :parametrized: yes :expectedresults: Package is install is installed """ if distro == DISTRO_RHEL6: pytest.skip(f'{DISTRO_RHEL6!s} skipped until ELS subscriptions are in manifest.') repos_collection = RepositoryCollection( distro=distro, repositories=[ SatelliteToolsRepository(cdn=cdn, distro=distro), YumRepository(url=FAKE_0_YUM_REPO), DockerRepository(url=CONTAINER_REGISTRY_HUB, upstream_name=CONTAINER_UPSTREAM_NAME), PuppetRepository( url=CUSTOM_PUPPET_REPO, modules=[dict(name='generic_1', author='robottelo')] ), ], ) # Create repos, content view, and activation key. repos_collection.setup_content(org['id'], lce['id'], upload_manifest=True) with VMBroker(nick=distro, host_classes={'host': ContentHost}) as host: # install katello-agent repos_collection.setup_virtual_machine( host, enable_custom_repos=True, install_katello_agent=False ) # install a package from custom repo result = host.execute(f'yum -y install {FAKE_0_CUSTOM_PACKAGE}') assert result.status == 0
def erratatype_vm(module_erratatype_repos_col): """Virtual machine client using module_erratatype_repos_col for subscription""" with VMBroker( nick=module_erratatype_repos_col.distro, host_classes={'host': ContentHost} ) as client: module_erratatype_repos_col.setup_virtual_machine(client) yield client
def fixture_vmsetup(request, module_org, default_sat): """Create VM and register content host""" if '_count' in request.param.keys(): with VMBroker( nick=request.param['nick'], host_classes={'host': ContentHost}, _count=request.param['_count'], ) as clients: for client in clients: client.configure_rex(satellite=default_sat, org=module_org) yield clients else: with VMBroker(nick=request.param['nick'], host_classes={'host': ContentHost}) as client: client.configure_rex(satellite=default_sat, org=module_org) yield client
def test_positive_apply_for_all_hosts(session, module_org, module_repos_col): """Apply an erratum for all content hosts :id: d70a1bee-67f4-4883-a0b9-2ccc08a91738 :Setup: Errata synced on satellite server. :customerscenario: true :Steps: 1. Go to Content -> Errata. Select an erratum -> Content Hosts tab. 2. Select all Content Hosts and apply the erratum. :expectedresults: Check that the erratum is applied in all the content hosts. :CaseLevel: System """ with VMBroker(nick=module_repos_col.distro, host_classes={'host': ContentHost}, _count=2) as clients: for client in clients: module_repos_col.setup_virtual_machine(client) assert _install_client_package(client, FAKE_1_CUSTOM_PACKAGE) with session: for client in clients: task_values = session.errata.install(CUSTOM_REPO_ERRATA_ID, client.hostname) assert task_values['result'] == 'success' packages_rows = session.contenthost.search_package( client.hostname, FAKE_2_CUSTOM_PACKAGE) assert packages_rows[0][ 'Installed Package'] == FAKE_2_CUSTOM_PACKAGE
def test_positive_install_in_hc(module_org, activation_key, custom_repo, target_sat): """Install errata in a host-collection :id: 6f0242df-6511-4c0f-95fc-3fa32c63a064 :Setup: Errata synced on satellite server. :Steps: PUT /api/v2/hosts/bulk/update_content :expectedresults: errata is installed in the host-collection. :CaseLevel: System :BZ: 1983043 """ with VMBroker(nick=constants.DISTRO_RHEL7, host_classes={'host': ContentHost}, _count=2) as clients: for client in clients: client.install_katello_ca(target_sat) client.register_contenthost(module_org.label, activation_key.name) assert client.subscribed client.add_rex_key(satellite=target_sat) host_ids = [client.nailgun_host.id for client in clients] _install_package( module_org, clients=clients, host_ids=host_ids, package_name=constants.FAKE_1_CUSTOM_PACKAGE, ) host_collection = target_sat.api.HostCollection( organization=module_org).create() host_ids = [client.nailgun_host.id for client in clients] host_collection.host_ids = host_ids host_collection = host_collection.update(['host_ids']) task_id = target_sat.api.JobInvocation().run(data={ 'feature': 'katello_errata_install', 'inputs': { 'errata': str(CUSTOM_REPO_ERRATA_ID) }, 'targeting_type': 'static_query', 'search_query': f'host_collection_id = {host_collection.id}', 'organization_id': module_org.id, }, )['id'] wait_for_tasks( search_query= (f'label = Actions::RemoteExecution::RunHostsJob and id = {task_id}' ), search_rate=15, max_tries=10, ) for client in clients: result = client.run(f'rpm -q {constants.FAKE_2_CUSTOM_PACKAGE}') assert result.status == 0
def align_to_satellite(worker_id, satellite_factory): """Attempt to align a Satellite to the current xdist worker""" cache_proxy = robottelo.config.settings_proxy._cache # clear any hostname that may have been previously set cache_proxy['server.hostname'] = on_demand_sat = None if worker_id in ['master', 'local']: worker_pos = 0 else: worker_pos = int(worker_id.replace('gw', '')) # attempt to add potential satellites from the broker inventory file if settings.server.inventory_filter: settings.server.hostnames # need to prime the cache hosts = VMBroker().from_inventory( filter=settings.server.inventory_filter) # update the cache_proxy for server.hostnames in case its empty cache_proxy['server.hostnames'] = cache_proxy['server.hostnames'] or [] cache_proxy['server.hostnames'].extend( [host.hostname for host in hosts]) # attempt to align a worker to a satellite if settings.server.xdist_behavior == 'run-on-one' and settings.server.hostnames: cache_proxy['server.hostname'] = settings.server.hostnames[0] elif settings.server.hostnames and worker_pos < len( settings.server.hostnames): cache_proxy['server.hostname'] = settings.server.hostnames[worker_pos] elif settings.server.xdist_behavior == 'balance' and settings.server.hostnames: cache_proxy['server.hostname'] = random.choice( settings.server.hostnames) # get current satellite information elif settings.server.xdist_behavior == "on-demand": on_demand_sat = satellite_factory() if on_demand_sat.hostname: cache_proxy['server.hostname'] = on_demand_sat.hostname # if no satellite was received, fallback to balance if not settings.server.hostname: cache_proxy['server.hostname'] = random.choice( settings.server.hostnames) logger.info(f"xdist worker {worker_id} " f"was assigned hostname {settings.server.hostname}") settings.configure_airgun() settings.configure_nailgun() yield if on_demand_sat and settings.server.auto_checkin: VMBroker(hosts=[on_demand_sat]).checkin()
def vm_content_hosts(request, module_loc, module_repos_collection): distro = module_repos_collection.distro with VMBroker(nick=distro, host_classes={'host': ContentHost}, _count=2) as clients: for client in clients: module_repos_collection.setup_virtual_machine(client) update_vm_host_location(client, module_loc.id) yield clients
def _target_sat_imp(request, _default_sat, satellite_factory): """This is the actual working part of the following target_sat fixtures""" if request.node.get_closest_marker(name='destructive'): new_sat = satellite_factory() yield new_sat VMBroker(hosts=[new_sat]).checkin() else: yield _default_sat
def fixture_sca_vmsetup(request, module_gt_manifest_org, target_sat): """Create VM and register content host to Simple Content Access organization""" if '_count' in request.param.keys(): with VMBroker( nick=request.param['nick'], host_classes={'host': ContentHost}, _count=request.param['_count'], ) as clients: for client in clients: client.configure_rex(satellite=target_sat, org=module_gt_manifest_org) yield clients else: with VMBroker(nick=request.param['nick'], host_classes={'host': ContentHost}) as client: client.configure_rex(satellite=target_sat, org=module_gt_manifest_org) yield client
def test_positive_filter_by_environment(session, module_org, module_repos_col, target_sat): """Filter Content hosts by environment :id: 578c3a92-c4d8-4933-b122-7ff511c276ec :customerscenario: true :BZ: 1383729 :Setup: Errata synced on satellite server. :Steps: Go to Content -> Errata. Select an Errata -> Content Hosts tab -> Filter content hosts by Environment. :expectedresults: Content hosts can be filtered by Environment. :CaseLevel: System """ with VMBroker( nick=module_repos_col.distro, host_classes={'host': ContentHost}, _count=2 ) as clients: for client in clients: module_repos_col.setup_virtual_machine(client, target_sat, install_katello_agent=False) assert _install_client_package(client, 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': f'name={clients[0].hostname}'})[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: session.location.select(loc_name=DEFAULT_LOC) # search in new_lce values = session.errata.search_content_hosts( CUSTOM_REPO_ERRATA_ID, clients[0].hostname, environment=new_lce.name ) assert values[0]['Name'] == clients[0].hostname assert not session.errata.search_content_hosts( CUSTOM_REPO_ERRATA_ID, clients[1].hostname, environment=new_lce.name ) # search in lce values = session.errata.search_content_hosts( CUSTOM_REPO_ERRATA_ID, clients[1].hostname, environment=lce.name ) assert values[0]['Name'] == clients[1].hostname assert not session.errata.search_content_hosts( CUSTOM_REPO_ERRATA_ID, clients[0].hostname, environment=lce.name )
def vm_content_hosts(module_loc, module_repos_collection, default_sat): distro = module_repos_collection.distro with VMBroker(nick=distro, host_classes={'host': ContentHost}, _count=2) as clients: for client in clients: module_repos_collection.setup_virtual_machine( client, default_sat, install_katello_agent=False) add_remote_execution_ssh_key(client.ip_addr) update_vm_host_location(client, module_loc.id) yield clients
def test_positive_register_host_ak_with_host_collection( katello_agent_client, module_cv, module_lce, module_org, rhel7_contenthost, default_sat): """Attempt to register a host using activation key with host collection :id: 7daf4e40-3fa6-42af-b3f7-1ca1a5c9bfeb :BZ: 1385814 :expectedresults: Host successfully registered and listed in host collection :CaseLevel: System """ # client = katello_agent_client['client'] host_info = katello_agent_client['host_info'] # create a new activation key activation_key = make_activation_key({ 'lifecycle-environment-id': module_lce.id, 'organization-id': module_org.id, 'content-view-id': module_cv.id, }) hc = make_host_collection({'organization-id': module_org.id}) ActivationKey.add_host_collection({ 'id': activation_key['id'], 'organization-id': module_org.id, 'host-collection-id': hc['id'], }) # add the registered instance host to collection HostCollection.add_host({ 'id': hc['id'], 'organization-id': module_org.id, 'host-ids': host_info['id'] }) with VMBroker(nick='rhel7', host_classes={'host': ContentHost}) as vm: vm.install_katello_ca(default_sat) # register the client host with the current activation key vm.register_contenthost(module_org.name, activation_key=activation_key['name']) assert vm.subscribed # note: when registering the host, it should be automatically added to the host-collection client_host = Host.info({'name': vm.hostname}) hosts = HostCollection.hosts({ 'id': hc['id'], 'organization-id': module_org.id }) assert len(hosts) == 2 expected_hosts_ids = {host_info['id'], client_host['id']} hosts_ids = {host['id'] for host in hosts} assert hosts_ids == expected_hosts_ids
def vm_content_hosts(smart_proxy_location, module_repos_collection, default_sat): distro = module_repos_collection.distro with VMBroker(nick=distro, host_classes={'host': ContentHost}, _count=2) as clients: for client in clients: module_repos_collection.setup_virtual_machine( client, default_sat, install_katello_agent=False) client.add_rex_key(satellite=default_sat) update_vm_host_location(client, smart_proxy_location.id) yield clients
def align_to_satellite(worker_id, satellite_factory): """Attempt to align a Satellite to the current xdist worker""" # clear any hostname that may have been previously set settings.server.hostname = on_demand_sat = None if worker_id in ['master', 'local']: worker_pos = 0 else: worker_pos = int(worker_id.replace('gw', '')) # attempt to add potential satellites from the broker inventory file if settings.server.inventory_filter: hosts = VMBroker().from_inventory( filter=settings.server.inventory_filter) settings.server.hostnames += [host.hostname for host in hosts] # attempt to align a worker to a satellite if settings.server.xdist_behavior == 'run-on-one' and settings.server.hostnames: settings.server.hostname = settings.server.hostnames[0] elif settings.server.hostnames and worker_pos < len( settings.server.hostnames): settings.server.hostname = settings.server.hostnames[worker_pos] elif settings.server.xdist_behavior == 'balance' and settings.server.hostnames: settings.server.hostname = random.choice(settings.server.hostnames) # get current satellite information elif settings.server.xdist_behavior == 'on-demand': on_demand_sat = satellite_factory() if on_demand_sat.hostname: settings.server.hostname = on_demand_sat.hostname # if no satellite was received, fallback to balance if not settings.server.hostname: settings.server.hostname = random.choice(settings.server.hostnames) logger.info( f'xdist worker {worker_id} was assigned hostname {settings.server.hostname}' ) configure_airgun() configure_nailgun() yield if on_demand_sat and settings.server.auto_checkin: VMBroker(hosts=[on_demand_sat]).checkin()
def factory(retry_limit=3, delay=300, workflow=None, **broker_args): if settings.capsule.deploy_arguments: broker_args.update(settings.capsule.deploy_arguments) vmb = VMBroker( host_classes={'host': Capsule}, workflow=workflow or settings.capsule.deploy_workflow, **broker_args, ) timeout = (1200 + delay) * retry_limit cap = wait_for(vmb.checkout, timeout=timeout, delay=delay, fail_condition=[]) return cap.out
def test_positive_run_job_template_multiple_hosts_by_ip( session, module_org, smart_proxy_location, target_sat ): """Run a job template against multiple hosts by ip :id: c4439ec0-bb80-47f6-bc31-fa7193bfbeeb :Setup: Create a working job template. :Steps: 1. Set remote_execution_connect_by_ip on hosts to true 2. Navigate to the hosts page and select at least two hosts 3. Click the "Select Action" 4. Select the job and appropriate template 5. Run the job :expectedresults: Verify the job was successfully ran against the hosts :CaseLevel: System """ with VMBroker(nick='rhel7', host_classes={'host': ContentHost}, _count=2) as hosts: host_names = [] for host in hosts: host_names.append(host.hostname) host.configure_rex(satellite=target_sat, org=module_org) update_vm_host_location(host, location_id=smart_proxy_location.id) with session: session.location.select(smart_proxy_location.name) hosts = session.host.search( ' or '.join([f'name="{hostname}"' for hostname in host_names]) ) assert {host['Name'] for host in hosts} == set(host_names) job_status = session.host.schedule_remote_job( host_names, { 'job_category': 'Commands', 'job_template': 'Run Command - SSH Default', 'template_content.command': 'ls', 'schedule': 'Execute now', }, ) assert job_status['overview']['job_status'] == 'Success' assert {host_job['Host'] for host_job in job_status['overview']['hosts_table']} == set( host_names ) assert all( host_job['Status'] == 'success' for host_job in job_status['overview']['hosts_table'] )
def vm_content_hosts_module_stream(module_loc, module_repos_collection_module_stream): distro = module_repos_collection_module_stream.distro with VMBroker(nick=distro, host_classes={'host': ContentHost}, _count=2) as clients: for client in clients: module_repos_collection_module_stream.setup_virtual_machine( client, install_katello_agent=False) add_remote_execution_ssh_key(client.ip_addr) update_vm_host_location(client, module_loc.id) smart_proxy = (entities.SmartProxy().search( query={'search': f'name={settings.server.hostname}'})[0].read()) smart_proxy.location.append(entities.Location(id=module_loc.id)) smart_proxy.update(['location']) yield clients
def test_positive_install_in_hc(module_org, activation_key, custom_repo, rh_repo, default_sat): """Install errata in a host-collection :id: 6f0242df-6511-4c0f-95fc-3fa32c63a064 :Setup: Errata synced on satellite server. :Steps: PUT /api/v2/hosts/bulk/update_content :expectedresults: errata is installed in the host-collection. :CaseLevel: System :BZ: 1983043 """ with VMBroker(nick=constants.DISTRO_RHEL7, host_classes={'host': ContentHost}, _count=2) as clients: for client in clients: client.install_katello_ca(default_sat) client.register_contenthost(module_org.label, activation_key.name) assert client.subscribed client.enable_repo(constants.REPOS['rhst7']['id']) client.add_rex_key(satellite=default_sat) host_ids = [client.nailgun_host.id for client in clients] _install_package( module_org, clients=clients, host_ids=host_ids, package_name=constants.FAKE_1_CUSTOM_PACKAGE, ) host_collection = default_sat.api.HostCollection( organization=module_org).create() host_ids = [client.nailgun_host.id for client in clients] host_collection.host_ids = host_ids host_collection = host_collection.update(['host_ids']) default_sat.api.JobInvocation().run( data={ 'feature': 'katello_errata_install', 'inputs': { 'errata': f'{CUSTOM_REPO_ERRATA_ID}' }, 'targeting_type': 'static_query', 'search_query': f'host_collection_id = {host_collection.id}', 'organization_id': module_org.id, }) _validate_package_installed(clients, constants.FAKE_2_CUSTOM_PACKAGE)
def factory(retry_limit=3, delay=300, workflow=None, **broker_args): if settings.server.deploy_arguments: broker_args.update(settings.server.deploy_arguments) logger.debug(f'Updated broker args for sat: {broker_args}') vmb = VMBroker( host_classes={'host': Satellite}, workflow=workflow or settings.server.deploy_workflow, **broker_args, ) timeout = (1200 + delay) * retry_limit sat = wait_for(vmb.checkout, timeout=timeout, delay=delay, fail_condition=[]) return sat.out
def test_positive_host_associations(session, default_sat): """Register few hosts with different activation keys and ensure proper data is reflected under Associations > Content Hosts tab :id: 111aa2af-caf4-4940-8e4b-5b071d488876 :expectedresults: Only hosts, registered by specific AK are shown under Associations > Content Hosts tab :customerscenario: true :BZ: 1344033, 1372826, 1394388 :CaseLevel: System """ org = entities.Organization().create() org_entities = setup_org_for_a_custom_repo({ 'url': settings.repos.yum_1.url, 'organization-id': org.id }) ak1 = entities.ActivationKey(id=org_entities['activationkey-id']).read() ak2 = entities.ActivationKey( content_view=org_entities['content-view-id'], environment=org_entities['lifecycle-environment-id'], organization=org.id, ).create() with VMBroker(nick='rhel7', host_classes={'host': ContentHost}, _count=2) as hosts: vm1, vm2 = hosts vm1.install_katello_ca(default_sat) vm1.register_contenthost(org.label, ak1.name) assert vm1.subscribed vm2.install_katello_ca(default_sat) vm2.register_contenthost(org.label, ak2.name) assert vm2.subscribed with session: session.organization.select(org.name) ak1 = session.activationkey.read(ak1.name, widget_names='content_hosts') assert len(ak1['content_hosts']['table']) == 1 assert ak1['content_hosts']['table'][0]['Name'] == vm1.hostname ak2 = session.activationkey.read(ak2.name, widget_names='content_hosts') assert len(ak2['content_hosts']['table']) == 1 assert ak2['content_hosts']['table'][0]['Name'] == vm2.hostname
def fixture_vmsetup(request, module_org): """Create Org, Lifecycle Environment, Content View, Activation key, VM, install katello-ca, register it, add remote execution key """ # Create VM and register content host with VMBroker(nick=request.param, host_classes={'host': ContentHost}) as client: client.install_katello_ca() client.register_contenthost(org=module_org.label, lce='Library') assert client.subscribed add_remote_execution_ssh_key(client.ip_addr) Host.set_parameter( { 'host': client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', } ) yield client
def test_positive_register_host_ak_with_host_collection( module_org, module_ak_with_cv, default_sat): """Attempt to register a host using activation key with host collection :id: 62459e8a-0cfa-44ff-b70c-7f55b4757d66 :expectedresults: Host successfully registered and listed in host collection :BZ: 1385814 :CaseLevel: System """ host_info = _make_fake_host_helper(module_org) hc = make_host_collection({'organization-id': module_org.id}) ActivationKey.add_host_collection({ 'id': module_ak_with_cv.id, 'organization-id': module_org.id, 'host-collection-id': hc['id'], }) # add the registered instance host to collection HostCollection.add_host({ 'id': hc['id'], 'organization-id': module_org.id, 'host-ids': host_info['id'] }) with VMBroker(nick='rhel7', host_classes={'host': ContentHost}) as client: client.install_katello_ca(default_sat) # register the client host with the current activation key client.register_contenthost(module_org.name, activation_key=module_ak_with_cv.name) assert client.subscribed # note: when registering the host, it should be automatically added to the host-collection client_host = Host.info({'name': client.hostname}) hosts = HostCollection.hosts({ 'id': hc['id'], 'organization-id': module_org.id }) assert len(hosts) == 2 expected_hosts_ids = {host_info['id'], client_host['id']} hosts_ids = {host['id'] for host in hosts} assert hosts_ids == expected_hosts_ids
def test_negative_usage_limit(session, module_org, default_sat): """Test that Usage limit actually limits usage :id: 9fe2d661-66f8-46a4-ae3f-0a9329494bdd :Steps: 1. Create Activation key 2. Update Usage Limit to a finite number 3. Register Systems to match the Usage Limit 4. Attempt to register an other system after reaching the Usage Limit :expectedresults: System Registration fails. Appropriate error shown :CaseLevel: System """ name = gen_string('alpha') hosts_limit = '1' with session: session.activationkey.create({ 'name': name, 'lce': { constants.ENVIRONMENT: True } }) assert session.activationkey.search(name)[0]['Name'] == name session.activationkey.update(name, {'details.hosts_limit': hosts_limit}) ak = session.activationkey.read(name, widget_names='details') assert ak['details']['hosts_limit'] == hosts_limit with VMBroker(nick='rhel6', host_classes={'host': ContentHost}, _count=2) as hosts: vm1, vm2 = hosts vm1.install_katello_ca(default_sat) vm1.register_contenthost(module_org.label, name) assert vm1.subscribed vm2.install_katello_ca(default_sat) result = vm2.register_contenthost(module_org.label, name) assert not vm2.subscribed assert len(result.stderr) assert f'Max Hosts ({hosts_limit}) reached for activation key' in result.stderr
def test_positive_apply_for_all_hosts(session, module_org, module_repos_col, default_sat): """Apply an erratum for all content hosts :id: d70a1bee-67f4-4883-a0b9-2ccc08a91738 :Setup: Errata synced on satellite server. :customerscenario: true :Steps: 1. Go to Content -> Errata. Select an erratum -> Content Hosts tab. 2. Select all Content Hosts and apply the erratum. :expectedresults: Check that the erratum is applied in all the content hosts. :CaseLevel: System """ with VMBroker(nick=module_repos_col.distro, host_classes={'host': ContentHost}, _count=2) as clients: for client in clients: module_repos_col.setup_virtual_machine(client, default_sat, install_katello_agent=False) client.add_rex_key(satellite=default_sat) assert _install_client_package(client, FAKE_1_CUSTOM_PACKAGE) with session: session.location.select(loc_name=DEFAULT_LOC) for client in clients: client.add_rex_key(satellite=default_sat) status = session.contenthost.install_errata( client.hostname, CUSTOM_REPO_ERRATA_ID, install_via='rex') assert status['overview']['job_status'] == 'Success' assert status['overview']['job_status_progress'] == '100%' packages_rows = session.contenthost.search_package( client.hostname, FAKE_2_CUSTOM_PACKAGE) assert packages_rows[0][ 'Installed Package'] == FAKE_2_CUSTOM_PACKAGE
def power_control(self, state=VmState.RUNNING, ensure=True): """Lookup the host workflow for power on and execute Args: state: A VmState from wrapanapi.entities.vm or 'reboot' ensure: boolean indicating whether to try and connect to ensure power state Raises: NotImplementedError: if the workflow name isn't found in settings BrokerError: various error types to do with broker execution ContentHostError: if the workflow status isn't successful and broker didn't raise """ try: vm_operation = POWER_OPERATIONS.get(state) workflow_name = settings.broker.host_workflows.power_control except (AttributeError, KeyError): raise NotImplementedError( 'No workflow in broker.host_workflows for power control, ' 'or VM operation not supported' ) assert ( # TODO read the kwarg name from settings too? VMBroker() .execute( workflow=workflow_name, vm_operation=vm_operation, source_vm=self.name, )['status'] .lower() == 'successful' ) if ensure and state in [VmState.RUNNING, 'reboot']: try: wait_for( self.connect, fail_condition=lambda res: res is not None, handle_exception=True ) # really broad diaper here, but connection exceptions could be a ton of types except TimedOutError: raise ContentHostError('Unable to connect to host that should be running')
def test_positive_install_in_hc(module_org, activation_key, custom_repo, rh_repo): """Install errata in a host-collection :id: 6f0242df-6511-4c0f-95fc-3fa32c63a064 :Setup: Errata synced on satellite server. :Steps: PUT /api/v2/hosts/bulk/update_content :expectedresults: errata is installed in the host-collection. :CaseLevel: System """ with VMBroker(nick=DISTRO_RHEL7, host_classes={'host': ContentHost}, _count=2) as clients: for client in clients: client.install_katello_ca() client.register_contenthost(module_org.label, activation_key.name) assert client.subscribed client.enable_repo(constants.REPOS['rhst7']['id']) client.install_katello_agent() host_ids = [client.nailgun_host.id for client in clients] _install_package( module_org, clients=clients, host_ids=host_ids, package_name=constants.FAKE_1_CUSTOM_PACKAGE_NAME, ) entities.Host().install_content( data={ 'organization_id': module_org.id, 'included': { 'ids': host_ids }, 'content_type': 'errata', 'content': [CUSTOM_REPO_ERRATA_ID], }) _validate_package_installed(clients, constants.FAKE_2_CUSTOM_PACKAGE)
def power_control(self, state=VmState.RUNNING, ensure=True): """Lookup the host workflow for power on and execute Args: state: A VmState mapped in POWER_WORKFLOW_KEYS or settings.broker.host_workflows key ensure: boolean indicating whether to try and connect to ensure power state Raises: NotImplementedError: if the workflow name isn't found in settings BrokerError: various error types to do with broker execution AssertionError: if the workflow status isn't successful and broker didn't raise """ try: workflow_key = POWER_WORKFLOW_KEYS.get(state, state) workflow_name = getattr(settings.broker.host_workflows, workflow_key) except (AttributeError, KeyError): raise NotImplementedError( f'No workflow specified in broker.host_workflows for {state}') assert (VMBroker().execute( workflow=workflow_name, target_vm=self.name)['status'].lower() == 'successful') if ensure: try: self.connect() # really broad diaper here, but connection exceptions could be a ton of types except Exception: if state == VmState.RUNNING: raise AssertionError( 'Unable to connect to host that should be running') if state == VmState.STOPPED: # Other than running/stopped, no telling what state the host is in pass else: pass