def test_positive_update_realm(self): """Update a hostgroup with a new realm @feature: HostGroup @assert: A hostgroup is updated with expected realm """ realm = entities.Realm( location=[self.loc], organization=[self.org], realm_proxy=entities.SmartProxy().search()[0], ).create() hostgroup = entities.HostGroup( location=[self.loc], organization=[self.org], realm=realm, ).create() new_realm = entities.Realm( location=[self.loc], organization=[self.org], realm_proxy=entities.SmartProxy().search()[0], ).create() hostgroup.realm = new_realm hostgroup = hostgroup.update(['realm']) self.assertEqual(hostgroup.realm.read().name, new_realm.name)
def test_positive_create_update_and_remove_capsule(self): """Update location with new capsule :id: 2786146f-f466-4ed8-918a-5f46806558e2 :expectedresults: Location updated successfully and has correct capsule assigned :BZ: 1398695 :CaseLevel: Integration :CaseImportance: Critical """ proxy_id_1 = self._make_proxy()['id'] proxy_id_2 = self._make_proxy()['id'] proxy = entities.SmartProxy(id=proxy_id_1).read() location = entities.Location(smart_proxy=[proxy]).create() # Add location to cleanup list self.addCleanup(location_cleanup, location.id) new_proxy = entities.SmartProxy(id=proxy_id_2).read() location.smart_proxy = [new_proxy] location = location.update(['smart_proxy']) self.assertEqual(location.smart_proxy[0].id, new_proxy.id) self.assertEqual(location.smart_proxy[0].read().name, new_proxy.name) location.smart_proxy = [] location = location.update(['smart_proxy']) self.assertEqual(len(location.smart_proxy), 0)
def test_positive_create_update_and_remove_capsule(self, make_proxies): """Update location with new capsule :id: 2786146f-f466-4ed8-918a-5f46806558e2 :expectedresults: Location updated successfully and has correct capsule assigned :BZ: 1398695 :CaseLevel: Integration :CaseImportance: Critical """ proxy_id_1 = make_proxies['proxy1']['id'] proxy_id_2 = make_proxies['proxy2']['id'] proxy = entities.SmartProxy(id=proxy_id_1).read() location = entities.Location(smart_proxy=[proxy]).create() new_proxy = entities.SmartProxy(id=proxy_id_2).read() location.smart_proxy = [new_proxy] location = location.update(['smart_proxy']) assert location.smart_proxy[0].id == new_proxy.id assert location.smart_proxy[0].read().name == new_proxy.name location.smart_proxy = [] location = location.update(['smart_proxy']) assert len(location.smart_proxy) == 0
def test_positive_update_realm(self): """Update a hostgroup with a new realm :id: fd9d141f-7a71-4439-92c7-1dbc1eea4772 :expectedresults: A hostgroup is updated with expected realm :CaseLevel: Integration """ realm = entities.Realm( location=[self.loc], organization=[self.org], realm_proxy=entities.SmartProxy().search( query={ 'search': 'url = https://{0}:9090'.format(settings.server.hostname) })[0]).create() hostgroup = entities.HostGroup( location=[self.loc], organization=[self.org], realm=realm, ).create() new_realm = entities.Realm( location=[self.loc], organization=[self.org], realm_proxy=entities.SmartProxy().search( query={ 'search': 'url = https://{0}:9090'.format(settings.server.hostname) })[0]).create() hostgroup.realm = new_realm hostgroup = hostgroup.update(['realm']) self.assertEqual(hostgroup.realm.read().name, new_realm.name)
def test_positive_update_realm(self): """Update a hostgroup with a new realm @id: fd9d141f-7a71-4439-92c7-1dbc1eea4772 @assert: A hostgroup is updated with expected realm @CaseLevel: Integration """ realm = entities.Realm( location=[self.loc], organization=[self.org], realm_proxy=entities.SmartProxy().search()[0], ).create() hostgroup = entities.HostGroup( location=[self.loc], organization=[self.org], realm=realm, ).create() new_realm = entities.Realm( location=[self.loc], organization=[self.org], realm_proxy=entities.SmartProxy().search()[0], ).create() hostgroup.realm = new_realm hostgroup = hostgroup.update(['realm']) self.assertEqual(hostgroup.realm.read().name, new_realm.name)
def test_positive_update_realm(self, module_org, module_location): """Update a hostgroup with a new realm :id: fd9d141f-7a71-4439-92c7-1dbc1eea4772 :expectedresults: A hostgroup is updated with expected realm :CaseLevel: Integration """ realm = entities.Realm( location=[module_location], organization=[module_org], realm_proxy=entities.SmartProxy().search( query={ 'search': f'url = https://{settings.server.hostname}:9090' })[0], ).create() hostgroup = entities.HostGroup(location=[module_location], organization=[module_org], realm=realm).create() new_realm = entities.Realm( location=[module_location], organization=[module_org], realm_proxy=entities.SmartProxy().search( query={ 'search': f'url = https://{settings.server.hostname}:9090' })[0], ).create() hostgroup.realm = new_realm hostgroup = hostgroup.update(['realm']) assert hostgroup.realm.read().name == new_realm.name
def test_positive_update_capsule(self): """Update location with new capsule @id: 2786146f-f466-4ed8-918a-5f46806558e2 @Assert: Location updated successfully and has correct capsule assigned @CaseLevel: Integration """ proxy_id_1 = make_proxy()['id'] proxy_id_2 = make_proxy()['id'] # Add capsules to cleanup list self.addCleanup(capsule_cleanup, proxy_id_1) self.addCleanup(capsule_cleanup, proxy_id_2) proxy = entities.SmartProxy(id=proxy_id_1).search()[0] location = entities.Location(smart_proxy=[proxy]).create() # Add location to cleanup list self.addCleanup(location_cleanup, location.id) new_proxy = entities.SmartProxy(id=proxy_id_2).search()[0] location.smart_proxy = [new_proxy] location = location.update(['smart_proxy']) self.assertEqual(location.smart_proxy[0].id, new_proxy.id) self.assertEqual(location.smart_proxy[0].read().name, new_proxy.name)
def module_smart_proxy(module_location): smart_proxy = (entities.SmartProxy().search( query={'search': 'name={0}'.format(settings.server.hostname)}) [0].read()) smart_proxy.location.append(entities.Location(id=module_location.id)) smart_proxy.update(['location']) return entities.SmartProxy(id=smart_proxy.id).read()
def test_positive_update_capsule(self): """Update location with new capsule @Assert: Location updated successfully and has correct capsule assigned @Feature: Location - Update """ proxy = entities.SmartProxy(id=make_proxy()['id']).search()[0] location = entities.Location(smart_proxy=[proxy]).create() new_proxy = entities.SmartProxy(id=make_proxy()['id']).search()[0] location.smart_proxy = [new_proxy] location = location.update(['smart_proxy']) self.assertEqual(location.smart_proxy[0].id, new_proxy.id) self.assertEqual(location.smart_proxy[0].read().name, new_proxy.name)
def module_loc(module_org): location = entities.Location(organization=[module_org]).create() smart_proxy = (entities.SmartProxy().search( query={'search': f'name={settings.server.hostname}'})[0].read()) smart_proxy.location.append(entities.Location(id=location.id)) smart_proxy.update(['location']) return location
def test_positive_add_smart_proxy(self): """Add a smart proxy to an organization :id: e21de720-3fa2-429b-bd8e-b6a48a13146d :expectedresults: Smart proxy is successfully added to organization :CaseLevel: Integration """ # Every Satellite has a built-in smart proxy, so let's find it smart_proxy = entities.SmartProxy().search(query={ 'search': 'url = https://{0}:9090'.format(settings.server.hostname) }) # Check that proxy is found and unpack it from the list self.assertGreater(len(smart_proxy), 0) smart_proxy = smart_proxy[0] # By default, newly created organization uses built-in smart proxy, # so we need to remove it first org = entities.Organization().create() org.smart_proxy = [] org = org.update(['smart_proxy']) # Verify smart proxy was actually removed self.assertEqual(len(org.smart_proxy), 0) # Add smart proxy to organization org.smart_proxy = [smart_proxy] org = org.update(['smart_proxy']) # Verify smart proxy was actually added self.assertEqual(len(org.smart_proxy), 1) self.assertEqual(org.smart_proxy[0].id, smart_proxy.id)
def smart_proxy_location(module_org, default_sat): location = entities.Location(organization=[module_org]).create() smart_proxy = (entities.SmartProxy().search( query={'search': f'name={default_sat.hostname}'})[0].read()) smart_proxy.location.append(entities.Location(id=location.id)) smart_proxy.update(['location']) return location
def test_positive_read_content_source_id(module_org, module_location, module_lce, module_published_cv): """Read the host content_source_id attribute from the read request response :id: 0a7fd8d4-1ea8-4b21-8c46-10579644fd11 :customerscenario: true :expectedresults: content_source_id is present in GET host request response :BZ: 1339613, 1488130 :CaseLevel: System """ proxy = (entities.SmartProxy().search( query={'url': f'https://{settings.server.hostname}:9090'})[0].read()) promote(module_published_cv.version[0], environment_id=module_lce.id) host = entities.Host( organization=module_org, location=module_location, content_facet_attributes={ 'content_source_id': proxy.id, 'content_view_id': module_published_cv.id, 'lifecycle_environment_id': module_lce.id, }, ).create() content_facet_attributes = getattr(host, 'content_facet_attributes') assert content_facet_attributes is not None content_source_id = content_facet_attributes.get('content_source_id') assert content_source_id is not None assert content_source_id == proxy.id
def module_loc(module_org): location = entities.Location(organization=[module_org]).create() smart_proxy = entities.SmartProxy().search( query={'search': 'name={0}'.format(settings.server.hostname)})[0] smart_proxy.location = [entities.Location(id=location.id)] smart_proxy.update(['location']) return location
def test_pre_scenario_remoteexecution_satellite(self): """Run REX job on client registered with Satellite :id: preupgrade-3f338475-fa69-43ef-ac86-f00f4d324b33 :steps: 1. Create Subnet. 2. Create Content host. 3. Install katello-ca package and register to Satellite host. 4. Add rex ssh_key of Satellite on content host. 5. Run the REX job on client vm. :expectedresults: 1. It should create with pre-required details. 2. REX job should run on it. """ try: default_loc_id = entities.Location().search( query={'search': 'name="{}"'.format(DEFAULT_LOC)})[0].id sn = entities.Subnet( domain=self.vm_domain, gateway=self.gateway, ipam='DHCP', location=[default_loc_id], mask=self.netmask, network=self.subnet, organization=[self.org.id], remote_execution_proxy=[entities.SmartProxy(id=1)], ).create() client = VirtualMachine(distro=DISTRO_RHEL7, provisioning_server=self.libvirt_vm, bridge=self.bridge) client.create() client.install_katello_ca() client.register_contenthost(org=self.org.label, lce='Library') add_remote_execution_ssh_key(hostname=client.ip_addr) host = entities.Host().search( query={'search': 'name="{}"'.format(client.hostname)}) host[0].subnet = sn host[0].update(['subnet']) job = entities.JobInvocation().run( data={ 'job_template_id': 89, 'inputs': { 'command': "ls" }, 'targeting_type': 'static_query', 'search_query': "name = {0}".format(client.hostname) }) self.assertEqual(job['output']['success_count'], 1) global_dict = { self.__class__.__name__: { 'client_name': client.hostname } } create_dict(global_dict) except Exception as exp: if client._created: self._vm_cleanup(hostname=client.hostname) raise Exception(exp)
def test_positive_add_smart_proxy(self): """Add a smart proxy to an organization @id: e21de720-3fa2-429b-bd8e-b6a48a13146d @Assert: Smart proxy is successfully added to organization @CaseLevel: Integration """ # Every Satellite has a built-in smart proxy, so let's find it smart_proxies = entities.SmartProxy().search() self.assertGreater(len(smart_proxies), 0) smart_proxy = smart_proxies[0] # By default, newly created organization uses built-in smart proxy, # so we need to remove it first org = entities.Organization().create() org.smart_proxy = [] org = org.update(['smart_proxy']) # Verify smart proxy was actually removed self.assertEqual(len(org.smart_proxy), 0) # Add smart proxy to organization org.smart_proxy = [smart_proxy] org = org.update(['smart_proxy']) # Verify smart proxy was actually added self.assertEqual(len(org.smart_proxy), 1) self.assertEqual(org.smart_proxy[0].id, smart_proxy.id)
def test_post_user_scenario_capsule_sync(self): """Post-upgrade scenario that sync capsule from satellite and then verifies if the repo/rpm of pre-upgrade scenario is synced to capsule :id: postupgrade-eb8970fa-98cc-4a99-99fb-1c12c4e319c9 :steps: 1. Run capsule sync post upgrade. 2. Check if the repo/rpm is been synced to capsule. :expectedresults: 1. The capsule sync should be successful 2. The repos/rpms from satellite should be synced to satellite """ env_name = get_entity_data(self.__class__.__name__)['env_name'] org_name = (entities.Organization().search( query={'search': 'id={}'.format(self.org_id)})[0].label) capsule = entities.SmartProxy().search( query={'search': 'name={}'.format(self.cap_host)})[0] call_entity_method_with_timeout( entities.Capsule(id=capsule.id).content_sync, timeout=3600) result = execute( lambda: run('[ -f /var/lib/pulp/published/yum/http/repos/' '{0}/{1}/{2}/custom/{3}/{4}/Packages/b/{5} ]; echo $?'. format(org_name, env_name, self.cv_name, self. prod_name, self.repo_name, self.rpm_name)), host=self.cap_host, )[self.cap_host] self.assertEqual('0', result)
def setUpClass(cls): super(AnsibleREXTestCase, cls).setUpClass() cls.sat6_hostname = settings.server.hostname # register and setup a host here and tests will share the host, step 0. cls.org = entities.Organization().create() # create subnet for current org, default loc and domain # add rex proxy to subnet, default is internal proxy (id 1) # using API due BZ#1370460 cls.sn = entities.Subnet( domain=[1], gateway=settings.vlan_networking.gateway, ipam='DHCP', location=[DEFAULT_LOC_ID], mask=settings.vlan_networking.netmask, network=settings.vlan_networking.subnet, organization=[cls.org.id], remote_execution_proxy=[entities.SmartProxy(id=1)], ).create() # Create VM and register content host cls.client = VirtualMachine( distro=DISTRO_RHEL7, provisioning_server=settings.compute_resources.libvirt_hostname, bridge=settings.vlan_networking.bridge) cls.addCleanup(vm_cleanup, cls.client) cls.client.create() cls.client.install_katello_ca() cls.client.register_contenthost(org=cls.org['label'], lce='Library') cls.assertTrue(cls.client.subscribed) Host.set_parameter({ 'host': cls.client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', }) add_remote_execution_ssh_key(cls.client.ip_addr)
def update_capsule_download_policy(self, capsule_configured, download_policy): """Updates capsule's download policy to desired value""" proxy = entities.SmartProxy( id=capsule_configured.nailgun_capsule.id).read() proxy.download_policy = download_policy proxy.update(['download_policy'])
def test_positive_run_capsule_upgrade_playbook(): """Run Capsule Upgrade playbook against an External Capsule :id: 9ec6903d-2bb7-46a5-8002-afc74f06d83b :steps: 1. Create a Capsule VM, add REX key. 2. Run the Capsule Upgrade Playbook. :expectedresults: Capsule is upgraded successfully :CaseImportance: Medium """ with CapsuleVirtualMachine() as capsule_vm: template_id = (entities.JobTemplate().search( query={'search': 'name="Capsule Upgrade Playbook"'})[0].id) add_remote_execution_ssh_key(capsule_vm.ip_addr) job = entities.JobInvocation().run( synchronous=False, data={ 'job_template_id': template_id, 'inputs': { 'target_version': CAPSULE_TARGET_VERSION, 'whitelist_options': "repositories-validate,repositories-setup", }, 'targeting_type': "static_query", 'search_query': f"name = {capsule_vm.hostname}", }, ) wait_for_tasks( f"resource_type = JobInvocation and resource_id = {job['id']}") result = entities.JobInvocation(id=job['id']).read() assert result.succeeded == 1 result = capsule_vm.run('foreman-maintain health check') assert result.return_code == 0 for line in result.stdout: assert 'FAIL' not in line result = entities.SmartProxy(id=entities.SmartProxy( name=capsule_vm.hostname).search()[0].id).refresh() feature_list = [feat['name'] for feat in result['features']] assert {'Discovery', 'Dynflow', 'Ansible', 'SSH', 'Logs', 'Pulp'}.issubset(feature_list)
def lifecycle_env(module_org, puppet_env): """ Create lifecycle environment""" smart_proxy = entities.SmartProxy().search(query={'search': f'name={sat6_hostname}'})[0].read() smart_proxy.import_puppetclasses(environment=puppet_env.name) lce_env = entities.LifecycleEnvironment( organization=module_org, name=gen_string('alpha') ).create() return lce_env
def setUpClass(cls): super(OpenScapContentTestCase, cls).setUpClass() path = settings.oscap.content_path cls.content_path = get_data_file(path) org = entities.Organization(name=gen_string('alpha')).create() cls.org_name = org.name proxy = entities.SmartProxy().search( query={u'search': u'name={0}'.format(settings.server.hostname)})[0] proxy.organization = [org]
def setUpClass(cls): cls.hostgroup_name = 'preupgrade_hostgroup' cls.parent_name = 'pre_upgrade_parent_hostgrp' cls.subnet_name = 'pre_upgrade_hostgrp_subnet' cls.os_name = 'pre_upgrade_hostgrp_os' cls.domain_name = 'pre_upgrade_hostgrp_domain' cls.proxy = entities.SmartProxy().search( query={'search': f'url = https://{settings.server.hostname}:9090' })[0]
def _create_smart_proxy(request, **kwargs): """Create a Smart Proxy and add the finalizer""" proxy = entities.SmartProxy(**kwargs).create() @request.addfinalizer def _cleanup(): capsule_cleanup(proxy.id) return proxy
def test_positive_create_with_puppet_ca_proxy(self): """Create a host with puppet CA proxy specified @feature: Hosts @assert: A host is created with expected puppet CA proxy assigned """ proxy = entities.SmartProxy().search()[0] host = entities.Host(puppet_ca_proxy=proxy).create() self.assertEqual(host.puppet_ca_proxy.read().name, proxy.name)
def test_positive_create_with_puppet_ca_proxy(self): """Create a host with puppet CA proxy specified @id: 1b73dd35-c2e8-44bd-b8f8-9e51428a6239 @assert: A host is created with expected puppet CA proxy assigned """ proxy = entities.SmartProxy().search()[0] host = entities.Host(puppet_ca_proxy=proxy).create() self.assertEqual(host.puppet_ca_proxy.read().name, proxy.name)
def test_positive_create_with_puppet_proxy(self): """Create a host with puppet proxy specified @id: 9269d87b-abb9-48e0-b0d1-9b8e258e1ae3 @assert: A host is created with expected puppet proxy assigned """ proxy = entities.SmartProxy().search()[0] host = entities.Host(puppet_proxy=proxy).create() self.assertEqual(host.puppet_proxy.read().name, proxy.name)
def setUpClass(cls): """Find a ``SmartProxy``. Every Satellite has a built-in smart proxy, so searching for an existing smart proxy should always succeed. """ super(SmartProxyMissingAttrTestCase, cls).setUpClass() smart_proxies = entities.SmartProxy().search() assert len(smart_proxies) > 0 cls.smart_proxy_attrs = set(smart_proxies[0].update_json([]).keys())
def test_pre_create_hostgroup(self, request): """Hostgroup with different data type are created :id: preupgrade-79958754-94b6-4bfe-af12-7d4031cd2dd2 :steps: In Preupgrade Satellite, Create hostgroup with different entities. :expectedresults: Hostgroup should be create successfully. """ proxy = entities.SmartProxy().search( query={'search': f'url = https://{settings.server.hostname}:9090' })[0] test_name = request.node.name org = entities.Organization(name=f"{test_name}_org").create() loc = entities.Location(organization=[org], name=f"{test_name}_loc").create() parent_hostgroup = entities.HostGroup( location=[loc.id], organization=[org.id], name=f'{test_name}_parent_host_grp').create() lc_env = entities.LifecycleEnvironment(name=f"{test_name}_lce", organization=org).create() domain = entities.Domain(name=f"{test_name}_domain").create() architecture = entities.Architecture().create() ptable = entities.PartitionTable().create() operatingsystem = entities.OperatingSystem( architecture=[architecture], ptable=[ptable], name=f"{test_name}_os").create() medium = entities.Media(operatingsystem=[operatingsystem]).create() subnet = entities.Subnet(location=[loc], organization=[org], name=f"{test_name}_subnet").create() host_group = entities.HostGroup( architecture=architecture, domain=domain, location=[loc.id], medium=medium, name=f"{test_name}_host_grp", operatingsystem=operatingsystem, organization=[org.id], ptable=ptable, puppet_proxy=proxy, puppet_ca_proxy=proxy, subnet=subnet, parent=parent_hostgroup, lifecycle_environment=lc_env, content_source=proxy, root_pass='******', ).create() assert host_group.name == f"{test_name}_host_grp"
def test_pre_scenario_remoteexecution_external_capsule( self, request, default_location, rhel7_contenthost): """Run REX job on client registered with external capsule :id: preupgrade-261dd2aa-be01-4c34-b877-54b8ee346561 :steps: 1. Create Subnet. 2. Create Content host. 3. Install katello-ca package and register to Satellite host. 4. add rex ssh_key of external capsule on content host. 5. run the REX job on client vm. :expectedresults: 1. Content host should create with pre-required details. 2. REX job should run on it. :parametrized: yes """ sn = entities.Subnet( domain=self.vm_domain, gateway=self.gateway, ipam='DHCP', location=[default_location.id], mask=self.netmask, network=self.subnet, organization=[self.org.id], remote_execution_proxy=[entities.SmartProxy(id=2)], ).create() rhel7_contenthost.install_capsule_katello_ca(capsule=self.proxy_name) rhel7_contenthost.register_contenthost(org=self.org.label, lce='Library') capsule = Capsule(self.proxy_name) rhel7_contenthost.add_rex_key(satellite=capsule) host = entities.Host().search( query={'search': f'name="{rhel7_contenthost.hostname}"'}) host[0].subnet = sn host[0].update(['subnet']) job = entities.JobInvocation().run( data={ 'job_template_id': 89, 'inputs': { 'command': 'ls' }, 'targeting_type': 'static_query', 'search_query': f'name = {rhel7_contenthost.hostname}', }) assert job['output']['success_count'] == 1 global_dict = { self.__class__.__name__: { 'client_name': rhel7_contenthost.hostname } } create_dict(global_dict)