def configure(self, settings_path=None): """Read the settings file and parse the configuration. :param str settings_path: path to settings file to read. If None, looks in the project root for a file named 'robottelo.properties'. :raises: ImproperlyConfigured if any issue is found during the parsing or validation of the configuration. """ if not settings_path: # Expect the settings file to be on the robottelo project root. settings_path = os.path.join(robottelo_root_dir, SETTINGS_FILE_NAME) if not os.path.isfile(settings_path): raise ImproperlyConfigured( f'Not able to find settings file at {settings_path}') self.reader = INIReader(settings_path) attrs = map(lambda attr_name: (attr_name, getattr(self, attr_name)), dir(self)) feature_settings = filter( lambda tpl: isinstance(tpl[1], FeatureSettings), attrs) for name, settings in feature_settings: settings.read(self.reader) # Only has section will extend the error if self.reader.has_section(name): self._validation_errors.extend(settings.validate()) if self._validation_errors: raise ImproperlyConfigured( 'Failed to validate the configuration, check the message(s):\n' '{}'.format('\n'.join(self._validation_errors)))
def configure_provisioning(org=None, loc=None, compute=False, os=None): """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 str org: Default Organization that should be used in both host discovering and host provisioning procedures :param str loc: Default Location that should be used in both host discovering and host provisioning procedures :param bool compute: If False creates a default Libvirt compute resource :param str os: Specify the os to be used while provisioning and to associate related entities to the specified os. :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() if settings.repos.rhel7_os is None: raise ImproperlyConfigured( 'settings file is not configured for rhel os') # Create a new Life-Cycle environment lc_env = entities.LifecycleEnvironment(organization=org).create() # Create a Product, Repository for custom RHEL7 contents product = entities.Product(organization=org).create() repo = entities.Repository(product=product, url=settings.repos.rhel7_os, download_policy='immediate').create() # Increased timeout value for repo sync and CV publishing and promotion 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 existing organization puppet environment, otherwise create a # new one, associate organization and location where it is appropriate. environments = entities.Environment().search(query=dict( search=f'organization_id={org.id}')) if len(environments) > 0: environment = environments[0].read() environment.location.append(loc) environment = environment.update(['location']) else: environment = entities.Environment(organization=[org], location=[loc]).create() # Search for SmartProxy, and associate location proxy = entities.SmartProxy().search( query={'search': f'name={settings.server.hostname}'}) proxy = proxy[0].read() if loc.id not in [location.id for location in proxy.location]: proxy.location.append(loc) if org.id not in [organization.id for organization in proxy.organization]: proxy.organization.append(org) proxy = proxy.update(['location', '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={'search': f'name="{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={'search': f'network={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.ipam = 'DHCP' subnet = subnet.update([ 'domain', 'discovery', 'dhcp', 'dns', 'location', 'organization', 'tftp', 'ipam' ]) 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, ipam='DHCP', ).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 = f'qemu+ssh://root@{settings.libvirt.libvirt_hostname}/system' 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.update(['location', 'organization']) else: # Create Libvirt compute-resource entities.LibvirtComputeResource( provider='libvirt', url=resource_url, set_console_password=False, display_type='VNC', location=[loc.id], organization=[org.id], ).create() # Get the Partition table ID ptable = (entities.PartitionTable().search( query={'search': f'name="{DEFAULT_PTABLE}"'})[0].read()) if loc.id not in [location.id for location in ptable.location]: ptable.location.append(loc) if org.id not in [organization.id for organization in ptable.organization]: ptable.organization.append(org) ptable = ptable.update(['location', 'organization']) # Get the OS ID if os is None: os = (entities.OperatingSystem().search( query={ 'search': 'name="RedHat" AND (major="{}" OR major="{}")'.format( RHEL_6_MAJOR_VERSION, RHEL_7_MAJOR_VERSION) })[0].read()) else: os_ver = os.split(' ')[1].split('.') os = (entities.OperatingSystem().search( query={ 'search': f'family="Redhat" AND major="{os_ver[0]}" AND minor="{os_ver[1]}")' })[0].read()) # Get the Provisioning template_ID and update with OS, Org, Location provisioning_template = entities.ProvisioningTemplate().search( query={'search': f'name="{DEFAULT_TEMPLATE}"'}) provisioning_template = provisioning_template[0].read() provisioning_template.operatingsystem.append(os) if org.id not in [ organization.id for organization in provisioning_template.organization ]: provisioning_template.organization.append(org) if loc.id not in [ location.id for location in provisioning_template.location ]: 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.ProvisioningTemplate().search( query={'search': f'name="{DEFAULT_PXE_TEMPLATE}"'}) pxe_template = pxe_template[0].read() pxe_template.operatingsystem.append(os) if org.id not in [ organization.id for organization in pxe_template.organization ]: pxe_template.organization.append(org) if loc.id not in [location.id for location in pxe_template.location]: pxe_template.location.append(loc) pxe_template = pxe_template.update( ['location', 'operatingsystem', 'organization']) # Get the arch ID arch = (entities.Architecture().search( query={'search': f'name="{DEFAULT_ARCHITECTURE}"'})[0].read()) # Update the OS to associate arch, ptable, templates os.architecture.append(arch) os.ptable.append(ptable) os.provisioning_template.append(provisioning_template) os.provisioning_template.append(pxe_template) os = os.update(['architecture', 'provisioning_template', 'ptable']) # kickstart_repository is the content view and lce bind repo kickstart_repository = entities.Repository().search( query=dict(content_view_id=content_view.id, environment_id=lc_env.id, name=repo.name))[0] # 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, kickstart_repository=kickstart_repository, 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, 'subnet': subnet.name, 'os': os.title, }