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(get_project_root(), 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.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 RHEL6 contents product = entities.Product(organization=org).create() repo = entities.Repository(product=product, url=settings.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='organization_id={0}'.format(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': 'name={0}'.format(settings.server.hostname)}) proxy = proxy[0].read() proxy.location.append(loc) 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': '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={'search': '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.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 = '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.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': 'name="{0}"'.format(DEFAULT_PTABLE)})[0].read()) ptable.location.append(loc) 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="{0}" OR major="{1}")'.format( RHEL_6_MAJOR_VERSION, RHEL_7_MAJOR_VERSION) })[0].read()) else: os = (entities.OperatingSystem().search( query={ 'search': 'family="Redhat" ' 'AND major="{0}" ' 'AND minor="{1}")'.format( os.split(' ')[1].split('.')[0], os.split(' ')[1].split('.')[1]) })[0].read()) # Get the Provisioning template_ID and update with OS, Org, Location provisioning_template = entities.ProvisioningTemplate().search( query={'search': '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.ProvisioningTemplate().search( query={'search': '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={'search': 'name="{0}"'.format(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, }