예제 #1
0
def _db_select_query(name=None, nativeid=None, server=None, provider=None):
    """Column order: `id`, `nativeid`, `name`, `properties`, `server_name`,
    `feed`, `provider_name`, `ems_ref`, `messaging_type`"""
    t_ms = cfmedb()["middleware_servers"]
    t_mm = cfmedb()["middleware_messagings"]
    t_ems = cfmedb()["ext_management_systems"]
    query = (
        cfmedb()
        .session.query(
            t_mm.id,
            t_mm.nativeid,
            t_mm.name,
            t_mm.properties,
            t_ms.name.label("server_name"),
            t_ms.feed,
            t_ems.name.label("provider_name"),
            t_mm.messaging_type,
            t_mm.ems_ref,
        )
        .join(t_ms, t_mm.server_id == t_ms.id)
        .join(t_ems, t_mm.ems_id == t_ems.id)
    )
    if name:
        query = query.filter(t_mm.name == name)
    if nativeid:
        query = query.filter(t_mm.nativeid == nativeid)
    if server:
        query = query.filter(t_ms.name == server.name)
        if server.feed:
            query = query.filter(t_ms.feed == server.feed)
    if provider:
        query = query.filter(t_ems.name == provider.name)
    return query
예제 #2
0
def test_metrics_collection(handle_provider, provider_key, provider_crud, enable_candu):
    """check the db is gathering collection data for the given provider

    Metadata:
        test_flag: metrics_collection
    """
    metrics_tbl = db.cfmedb()['metrics']
    mgmt_systems_tbl = db.cfmedb()['ext_management_systems']

    logger.info("Fetching provider ID for {}".format(provider_key))
    mgmt_system_id = db.cfmedb().session.query(mgmt_systems_tbl).filter(
        mgmt_systems_tbl.name == conf.cfme_data.get('management_systems', {})[provider_key]['name']
    ).first().id

    logger.info("ID fetched; testing metrics collection now")
    start_time = time.time()
    metric_count = 0
    timeout = 900.0  # 15 min
    while time.time() < start_time + timeout:
        last_metric_count = metric_count
        logger.info("name: {}, id: {}, metrics: {}".format(
            provider_key, mgmt_system_id, metric_count))
        # count all the metrics for the provider we're testing
        metric_count = db.cfmedb().session.query(metrics_tbl).filter(
            metrics_tbl.parent_ems_id == mgmt_system_id
        ).count()

        # collection is working if increasing
        if metric_count > last_metric_count and last_metric_count > 0:
            return
        else:
            time.sleep(15)

    if time.time() > start_time + timeout:
        raise Exception("Timed out waiting for metrics to be collected")
예제 #3
0
 def get_tags_db(self):
     """
     Gets tags detail from database
     Column order: `tag_id`, `db_id`, `category`, `tag_name`, `single_value`
     """
     # Some times object of db_id might changed in database, when we do CRUD operations,
     # do update now
     self.load_details(refresh=True)
     if not self.db_id or not self.taggable_type:
         raise KeyError("'db_id' and/or 'taggable_type' not set")
     t_cls1 = aliased(cfmedb()['classifications'])
     t_cls2 = aliased(cfmedb()['classifications'])
     t_tgg = aliased(cfmedb()['taggings'])
     query = cfmedb().session.query(t_cls1.tag_id, t_tgg.taggable_id.label('db_id'),
                                    t_cls2.description.label('category'),
                                    t_cls1.description.label('tag_name'), t_cls1.single_value)\
         .join(t_cls2, t_cls1.parent_id == t_cls2.id)\
         .join(t_tgg, t_tgg.tag_id == t_cls1.tag_id)\
         .filter(t_tgg.taggable_id == self.db_id)\
         .filter(t_tgg.taggable_type == self.taggable_type)
     tags = []
     for tag in query.all():
         tags.append(Tag(category=Category(display_name=tag.category,
                                           single_value=tag.single_value),
                         display_name=tag.tag_name))
     return tags
예제 #4
0
def get_vm_object(vm_name):
    """Looks up the CFME database for the VM.

    Args:
        vm_name: VM name
    Returns:
        If found, :py:class:`utils.miq_soap.MiqVM` for 5.4 and :py:class:`utils.api.Entity` for 5.5
        If not, `None`
    """
    if current_version() < "5.5":
        vm_table = cfmedb()['vms']
        for vm in cfmedb().session.query(vm_table.name, vm_table.guid)\
                .filter(vm_table.template == False):  # NOQA
            # Previous line is ok, if you change it to `is`, it won't work!
            if vm.name == vm_name:
                return MiqVM(vm.guid)
        else:
            return None
    else:
        rest_api = pytest.store.current_appliance.rest_api
        results = rest_api.collections.vms.find_by(name=vm_name)
        if len(results) > 0:
            return results[0]
        else:
            return None
예제 #5
0
 def exists(self):
     ems = cfmedb()['ext_management_systems']
     provs = (prov[0] for prov in cfmedb().session.query(ems.name))
     if self.name in provs:
         return True
     else:
         return False
예제 #6
0
def _db_select_query(name=None, feed=None, provider=None, server_group=None, product=None):
    """column order: `id`, `name`, `hostname`, `feed`, `product`,
    `provider_name`, `ems_ref`, `properties`, `server_group_name`"""
    t_ms = cfmedb()["middleware_servers"]
    t_msgr = cfmedb()["middleware_server_groups"]
    t_ems = cfmedb()["ext_management_systems"]
    query = (
        cfmedb()
        .session.query(
            t_ms.id,
            t_ms.name,
            t_ms.hostname,
            t_ms.feed,
            t_ms.product,
            t_ems.name.label("provider_name"),
            t_ms.ems_ref,
            t_ms.properties,
            t_msgr.name.label("server_group_name"),
        )
        .join(t_ems, t_ms.ems_id == t_ems.id)
        .outerjoin(t_msgr, t_ms.server_group_id == t_msgr.id)
    )
    if name:
        query = query.filter(t_ms.name == name)
    if feed:
        query = query.filter(t_ms.feed == feed)
    if provider:
        query = query.filter(t_ems.name == provider.name)
    if server_group:
        query = query.filter(t_msgr.name == server_group.name)
    if product:
        query = query.filter(t_ms.product == product)
    return query
예제 #7
0
def _db_select_query(name=None, nativeid=None, server=None, provider=None):
    """Column order: `id`, `nativeid`, `name`, `properties`, `server_name`,
    `feed`, `provider_name`, `ems_ref`, `hostname`"""
    t_ms = cfmedb()['middleware_servers']
    t_mds = cfmedb()['middleware_datasources']
    t_ems = cfmedb()['ext_management_systems']
    query = cfmedb().session.query(
        t_mds.id,
        t_mds.nativeid,
        t_mds.name,
        t_mds.properties,
        t_ms.name.label('server_name'),
        t_ms.feed,
        t_ems.name.label('provider_name'),
        t_ms.hostname,
        t_mds.ems_ref)\
        .join(t_ms, t_mds.server_id == t_ms.id).join(t_ems, t_mds.ems_id == t_ems.id)
    if name:
        query = query.filter(t_mds.name == name)
    if nativeid:
        query = query.filter(t_mds.nativeid == nativeid)
    if server:
        query = query.filter(t_ms.name == server.name)
        if server.feed:
            query = query.filter(t_ms.feed == server.feed)
    if provider:
        query = query.filter(t_ems.name == provider.name)
    return query
예제 #8
0
def get_vm_object(vm_name):
    """Looks up the CFME database for the VM.

    Args:
        vm_name: VM name
    Returns:
        If found, :py:class:`utils.miq_soap.MiqVM` for 5.4 and :py:class:`utils.api.Entity` for 5.5
        If not, `None`
    """
    if current_version() < "5.5":
        vm_table = cfmedb()['vms']
        for vm in cfmedb().session.query(vm_table.name, vm_table.guid)\
                .filter(vm_table.template == False):  # NOQA
            # Previous line is ok, if you change it to `is`, it won't work!
            if vm.name == vm_name:
                return MiqVM(vm.guid)
        else:
            return None
    else:
        rest_api = pytest.store.current_appliance.rest_api
        results = rest_api.collections.vms.find_by(name=vm_name)
        if len(results) > 0:
            return results[0]
        else:
            return None
예제 #9
0
 def get_tags_db(self):
     """
     Gets tags detail from database
     Column order: `tag_id`, `db_id`, `category`, `tag_name`, `single_value`
     """
     # Some times object of db_id might changed in database, when we do CRUD operations,
     # do update now
     self.load_details(refresh=True)
     if not self.db_id or not self.taggable_type:
         raise KeyError("'db_id' and/or 'taggable_type' not set")
     t_cls1 = aliased(cfmedb()['classifications'])
     t_cls2 = aliased(cfmedb()['classifications'])
     t_tgg = aliased(cfmedb()['taggings'])
     query = cfmedb().session.query(t_cls1.tag_id, t_tgg.taggable_id.label('db_id'),
                                    t_cls2.description.label('category'),
                                    t_cls1.description.label('tag_name'), t_cls1.single_value)\
         .join(t_cls2, t_cls1.parent_id == t_cls2.id)\
         .join(t_tgg, t_tgg.tag_id == t_cls1.tag_id)\
         .filter(t_tgg.taggable_id == self.db_id)\
         .filter(t_tgg.taggable_type == self.taggable_type)
     tags = []
     for tag in query.all():
         tags.append(Tag(category=Category(display_name=tag.category,
                                           single_value=tag.single_value),
                         display_name=tag.tag_name))
     return tags
예제 #10
0
 def exists(self):
     ems = cfmedb()['ext_management_systems']
     provs = (prov[0] for prov in cfmedb().session.query(ems.name))
     if self.name in provs:
         return True
     else:
         return False
예제 #11
0
def _db_select_query(name=None, server=None, provider=None):
    """Column order: `id`, `nativeid`, `name`, `server_name`,
    `feed`, `provider_name`, `host_name`, `status`"""
    t_ems = cfmedb()["ext_management_systems"]
    t_ms = cfmedb()["middleware_servers"]
    t_md = cfmedb()["middleware_deployments"]
    query = (
        cfmedb()
        .session.query(
            t_md.id,
            t_md.nativeid.label("nativeid"),
            t_md.name,
            t_ms.name.label("server_name"),
            t_ms.feed.label("feed"),
            t_ems.name.label("provider_name"),
            t_ms.hostname.label("host_name"),
            t_md.status.label("status"),
        )
        .join(t_ms, t_md.server_id == t_ms.id)
        .join(t_ems, t_md.ems_id == t_ems.id)
    )
    if name:
        query = query.filter(t_md.name == name)
    if server:
        query = query.filter(t_ms.name == server.name)
        if server.feed:
            query = query.filter(t_ms.feed == server.feed)
    if provider:
        query = query.filter(t_ems.name == provider.name)
    return query
예제 #12
0
 def num_host_db(self):
     ext_management_systems = cfmedb()["ext_management_systems"]
     hosts = cfmedb()["hosts"]
     hostlist = list(cfmedb().session.query(hosts.name)
                     .join(ext_management_systems, hosts.ems_id == ext_management_systems.id)
                     .filter(ext_management_systems.name == self.name))
     return len(hostlist)
예제 #13
0
def _db_select_query(name=None, server=None, provider=None):
    """Column order: `id`, `nativeid`, `name`, `server_name`,
    `feed`, `provider_name`, `host_name`, `status`"""
    t_ems = cfmedb()['ext_management_systems']
    t_ms = cfmedb()['middleware_servers']
    t_md = cfmedb()['middleware_deployments']
    query = cfmedb().session.query(
        t_md.id,
        t_md.nativeid.label('nativeid'),
        t_md.name,
        t_ms.name.label('server_name'),
        t_ms.feed.label('feed'),
        t_ems.name.label('provider_name'),
        t_ms.hostname.label('host_name'),
        t_md.status.label('status')) \
        .join(t_ms, t_md.server_id == t_ms.id).join(t_ems, t_md.ems_id == t_ems.id)
    if name:
        query = query.filter(t_md.name == name)
    if server:
        query = query.filter(t_ms.name == server.name)
        if server.feed:
            query = query.filter(t_ms.feed == server.feed)
    if provider:
        query = query.filter(t_ems.name == provider.name)
    return query
예제 #14
0
 def num_host_db(self):
     ext_management_systems = cfmedb()["ext_management_systems"]
     hosts = cfmedb()["hosts"]
     hostlist = list(cfmedb().session.query(hosts.name).join(
         ext_management_systems,
         hosts.ems_id == ext_management_systems.id).filter(
             ext_management_systems.name == self.name))
     return len(hostlist)
예제 #15
0
def _db_select_query(name=None, type=None):
    """column order: `id`, `name`, `type`"""
    t_ems = cfmedb()['ext_management_systems']
    query = cfmedb().session.query(t_ems.id, t_ems.name, t_ems.type)
    if name:
        query = query.filter(t_ems.name == name)
    if type:
        query = query.filter(t_ems.type == type)
    return query
예제 #16
0
 def num_vm(self):
     """ Returns the providers number of instances, as shown on the Details page."""
     ext_management_systems = cfmedb()["ext_management_systems"]
     vms = cfmedb()["vms"]
     vmlist = list(cfmedb().session.query(vms.name)
                   .join(ext_management_systems, vms.ems_id == ext_management_systems.id)
                   .filter(ext_management_systems.name == self.name)
                   .filter(vms.template == False))  # NOQA
     return len(vmlist)
예제 #17
0
 def num_cluster_db(self):
     """ Returns the providers number of templates, as shown on the Details page."""
     ext_management_systems = cfmedb()["ext_management_systems"]
     clusters = cfmedb()["ems_clusters"]
     clulist = list(cfmedb().session.query(clusters.name).join(
         ext_management_systems,
         clusters.ems_id == ext_management_systems.id).filter(
             ext_management_systems.name == self.name))
     return len(clulist)
예제 #18
0
def _db_select_query(name=None, type=None):
    """column order: `id`, `name`, `type`"""
    t_ems = cfmedb()['ext_management_systems']
    query = cfmedb().session.query(t_ems.id, t_ems.name, t_ems.type)
    if name:
        query = query.filter(t_ems.name == name)
    if type:
        query = query.filter(t_ems.type == type)
    return query
예제 #19
0
 def num_cluster_db(self):
     """ Returns the providers number of templates, as shown on the Details page."""
     ext_management_systems = cfmedb()["ext_management_systems"]
     clusters = cfmedb()["ems_clusters"]
     clulist = list(cfmedb().session.query(clusters.name)
                    .join(ext_management_systems,
                          clusters.ems_id == ext_management_systems.id)
                    .filter(ext_management_systems.name == self.name))
     return len(clulist)
예제 #20
0
 def num_vm(self):
     """ Returns the providers number of instances, as shown on the Details page."""
     ext_management_systems = cfmedb()["ext_management_systems"]
     vms = cfmedb()["vms"]
     vmlist = list(cfmedb().session.query(vms.name).join(
         ext_management_systems,
         vms.ems_id == ext_management_systems.id).filter(
             ext_management_systems.name == self.name).filter(
                 vms.template == False))  # NOQA
     return len(vmlist)
예제 #21
0
 def num_host(self, db=True):
     """ Returns the providers number of instances, as shown on the Details page."""
     if db:
         ext_management_systems = cfmedb()["ext_management_systems"]
         hosts = cfmedb()["hosts"]
         hostlist = list(cfmedb().session.query(hosts.name)
                         .join(ext_management_systems, hosts.ems_id == ext_management_systems.id)
                         .filter(ext_management_systems.name == self.name))
         return len(hostlist)
     else:
         return int(self.get_detail("Relationships", "host.png", use_icon=True))
예제 #22
0
 def num_host(self, db=True):
     """ Returns the providers number of instances, as shown on the Details page."""
     if db:
         ext_management_systems = cfmedb()["ext_management_systems"]
         hosts = cfmedb()["hosts"]
         hostlist = list(cfmedb().session.query(hosts.name).join(
             ext_management_systems,
             hosts.ems_id == ext_management_systems.id).filter(
                 ext_management_systems.name == self.name))
         return len(hostlist)
     else:
         return int(self.get_detail("Relationships", "Hosts"))
예제 #23
0
 def num_cluster(self, db=True):
     """ Returns the providers number of templates, as shown on the Details page."""
     if db:
         ext_management_systems = cfmedb()["ext_management_systems"]
         clusters = cfmedb()["ems_clusters"]
         clulist = list(cfmedb().session.query(clusters.name)
                        .join(ext_management_systems,
                              clusters.ems_id == ext_management_systems.id)
                        .filter(ext_management_systems.name == self.name))
         return len(clulist)
     else:
         return int(self.get_detail("Relationships", "cluster.png", use_icon=True))
예제 #24
0
def _db_select_query(name=None, server=None, provider=None):
    t_ms = cfmedb()['middleware_servers']
    t_ems = cfmedb()['ext_management_systems']
    query = cfmedb().session.query(t_ms.name, t_ms.feed,
                                   t_ms.product, t_ems.name).join(t_ems, t_ms.ems_id == t_ems.id)
    if name:
        query = query.filter(t_ms.name == name)
    if server:
        query = query.filter(t_ms.nativeid.like('%{}%'.format(server)))
    if provider:
        query = query.filter(t_ems.name == provider)
    return query
예제 #25
0
 def num_vm(self, db=True):
     """ Returns the providers number of instances, as shown on the Details page."""
     if db:
         ext_management_systems = cfmedb()["ext_management_systems"]
         vms = cfmedb()["vms"]
         falsey = False  # This is to prevent a lint error with ==False
         vmlist = list(cfmedb().session.query(vms.name)
                       .join(ext_management_systems, vms.ems_id == ext_management_systems.id)
                       .filter(ext_management_systems.name == self.name)
                       .filter(vms.template == falsey))
         return len(vmlist)
     return int(self.get_detail("Relationships", "Instances"))
예제 #26
0
 def num_cluster(self, db=True):
     """ Returns the providers number of templates, as shown on the Details page."""
     if db:
         ext_management_systems = cfmedb()["ext_management_systems"]
         clusters = cfmedb()["ems_clusters"]
         clulist = list(cfmedb().session.query(clusters.name).join(
             ext_management_systems,
             clusters.ems_id == ext_management_systems.id).filter(
                 ext_management_systems.name == self.name))
         return len(clulist)
     else:
         return int(self.get_detail("Relationships", "Clusters"))
예제 #27
0
파일: pxe.py 프로젝트: vprusa/cfme_tests
 def get_pxe_image_type(self, image_name):
     pxe_i = cfmedb()["pxe_images"]
     pxe_s = cfmedb()["pxe_servers"]
     pxe_t = cfmedb()["pxe_image_types"]
     hosts = list(cfmedb().session.query(pxe_t.name).join(
         pxe_i, pxe_i.pxe_image_type_id == pxe_t.id).join(
             pxe_s, pxe_i.pxe_server_id == pxe_s.id).filter(
                 pxe_s.name == self.name).filter(pxe_i.name == image_name))
     if hosts:
         return hosts[0][0]
     else:
         return None
예제 #28
0
def test_metrics_collection(handle_provider, provider, enable_candu):
    """check the db is gathering collection data for the given provider

    Metadata:
        test_flag: metrics_collection
    """
    metrics_tbl = db.cfmedb()['metrics']
    mgmt_systems_tbl = db.cfmedb()['ext_management_systems']

    logger.info("Fetching provider ID for %s", provider.key)
    mgmt_system_id = db.cfmedb().session.query(mgmt_systems_tbl).filter(
        mgmt_systems_tbl.name == conf.cfme_data.get('management_systems', {})[provider.key]['name']
    ).first().id

    logger.info("ID fetched; testing metrics collection now")
    start_time = time.time()
    host_count = 0
    vm_count = 0
    host_rising = False
    vm_rising = False
    timeout = 900.0  # 15 min
    while time.time() < start_time + timeout:
        last_host_count = host_count
        last_vm_count = vm_count
        logger.info("name: %s, id: %s, vms: %s, hosts: %s",
            provider.key, mgmt_system_id, vm_count, host_count)
        # count host and vm metrics for the provider we're testing
        host_count = db.cfmedb().session.query(metrics_tbl).filter(
            metrics_tbl.parent_ems_id == mgmt_system_id).filter(
            metrics_tbl.resource_type == "Host"
        ).count()
        vm_count = db.cfmedb().session.query(metrics_tbl).filter(
            metrics_tbl.parent_ems_id == mgmt_system_id).filter(
            metrics_tbl.resource_type == "VmOrTemplate"
        ).count()

        if (host_count > last_host_count) and (last_host_count > 0):
            host_rising = True
        if (vm_count > last_vm_count) and (last_vm_count > 0):
            vm_rising = True

        # only vms are collected for cloud
        if provider.category == "cloud" and vm_rising:
            return
        # both vms and hosts must be collected for infra
        elif provider.category == "infra" and vm_rising and host_rising:
            return
        else:
            time.sleep(15)

    if time.time() > start_time + timeout:
        raise Exception("Timed out waiting for metrics to be collected")
예제 #29
0
 def num_template(self, db=True):
     """ Returns the providers number of templates, as shown on the Details page."""
     if db:
         ext_management_systems = cfmedb()["ext_management_systems"]
         vms = cfmedb()["vms"]
         truthy = True  # This is to prevent a lint error with ==True
         temlist = list(cfmedb().session.query(vms.name)
                        .join(ext_management_systems, vms.ems_id == ext_management_systems.id)
                        .filter(ext_management_systems.name == self.name)
                        .filter(vms.template == truthy))
         return len(temlist)
     else:
         return int(self.get_detail("Relationships", "Images"))
예제 #30
0
파일: pxe.py 프로젝트: vprusa/cfme_tests
 def exists(self):
     """
     Checks if the ISO Datastore already exists via db
     """
     iso = cfmedb()['iso_datastores']
     ems = cfmedb()['ext_management_systems']
     name = self.provider
     iso_ds = list(cfmedb().session.query(iso.id).join(
         ems, iso.ems_id == ems.id).filter(ems.name == name))
     if iso_ds:
         return True
     else:
         return False
예제 #31
0
파일: pxe.py 프로젝트: rrasouli/cfme_tests
 def get_pxe_image_type(self, image_name):
     pxe_i = cfmedb()["pxe_images"]
     pxe_s = cfmedb()["pxe_servers"]
     pxe_t = cfmedb()["pxe_image_types"]
     hosts = list(cfmedb().session.query(pxe_t.name)
                  .join(pxe_i, pxe_i.pxe_image_type_id == pxe_t.id)
                  .join(pxe_s, pxe_i.pxe_server_id == pxe_s.id)
                  .filter(pxe_s.name == self.name)
                  .filter(pxe_i.name == image_name))
     if hosts:
         return hosts[0][0]
     else:
         return None
예제 #32
0
 def num_vm(self, db=True):
     """ Returns the providers number of instances, as shown on the Details page."""
     if db:
         ext_management_systems = cfmedb()["ext_management_systems"]
         vms = cfmedb()["vms"]
         falsey = False  # This is to prevent a lint error with ==False
         vmlist = list(cfmedb().session.query(vms.name).join(
             ext_management_systems,
             vms.ems_id == ext_management_systems.id).filter(
                 ext_management_systems.name == self.name).filter(
                     vms.template == falsey))
         return len(vmlist)
     return int(self.get_detail("Relationships", self.vm_name))
예제 #33
0
 def num_template(self, db=True):
     """ Returns the providers number of templates, as shown on the Details page."""
     if db:
         ext_management_systems = cfmedb()["ext_management_systems"]
         vms = cfmedb()["vms"]
         truthy = True  # This is to prevent a lint error with ==True
         temlist = list(cfmedb().session.query(vms.name).join(
             ext_management_systems,
             vms.ems_id == ext_management_systems.id).filter(
                 ext_management_systems.name == self.name).filter(
                     vms.template == truthy))
         return len(temlist)
     else:
         return int(self.get_detail("Relationships", self.template_name))
예제 #34
0
def test_metrics_collection(handle_provider, provider, enable_candu):
    """check the db is gathering collection data for the given provider

    Metadata:
        test_flag: metrics_collection
    """
    metrics_tbl = db.cfmedb()['metrics']
    mgmt_systems_tbl = db.cfmedb()['ext_management_systems']

    logger.info("Fetching provider ID for {}".format(provider.key))
    mgmt_system_id = db.cfmedb().session.query(mgmt_systems_tbl).filter(
        mgmt_systems_tbl.name == conf.cfme_data.get('management_systems', {})[
            provider.key]['name']).first().id

    logger.info("ID fetched; testing metrics collection now")
    start_time = time.time()
    host_count = 0
    vm_count = 0
    host_rising = False
    vm_rising = False
    timeout = 900.0  # 15 min
    while time.time() < start_time + timeout:
        last_host_count = host_count
        last_vm_count = vm_count
        logger.info("name: {}, id: {}, vms: {}, hosts: {}".format(
            provider.key, mgmt_system_id, vm_count, host_count))
        # count host and vm metrics for the provider we're testing
        host_count = db.cfmedb().session.query(metrics_tbl).filter(
            metrics_tbl.parent_ems_id == mgmt_system_id).filter(
                metrics_tbl.resource_type == "Host").count()
        vm_count = db.cfmedb().session.query(metrics_tbl).filter(
            metrics_tbl.parent_ems_id == mgmt_system_id).filter(
                metrics_tbl.resource_type == "VmOrTemplate").count()

        if (host_count > last_host_count) and (last_host_count > 0):
            host_rising = True
        if (vm_count > last_vm_count) and (last_vm_count > 0):
            vm_rising = True

        # only vms are collected for cloud
        if provider.type in cloud_provider_type_map and vm_rising:
            return
        # both vms and hosts must be collected for infra
        elif provider.type in infra_provider_type_map and vm_rising and host_rising:
            return
        else:
            time.sleep(15)

    if time.time() > start_time + timeout:
        raise Exception("Timed out waiting for metrics to be collected")
예제 #35
0
파일: pxe.py 프로젝트: rrasouli/cfme_tests
 def exists(self):
     """
     Checks if the ISO Datastore already exists via db
     """
     iso = cfmedb()['iso_datastores']
     ems = cfmedb()['ext_management_systems']
     name = self.provider
     iso_ds = list(cfmedb().session.query(iso.id)
                   .join(ems, iso.ems_id == ems.id)
                   .filter(ems.name == name))
     if iso_ds:
         return True
     else:
         return False
예제 #36
0
def _db_select_query(domain, name=None, feed=None):
    """column order: `id`, `name`, `feed`, `profile`,
    `domain_name`, `ems_ref`, `properties`"""
    t_msgr = cfmedb()['middleware_server_groups']
    t_md = cfmedb()['middleware_domains']
    query = cfmedb().session.query(t_msgr.id, t_msgr.name, t_msgr.feed, t_msgr.profile,
                                   t_md.name.label('domain_name'),
                                   t_msgr.ems_ref, t_msgr.properties)\
        .join(t_md, t_msgr.domain_id == t_md.id)
    if name:
        query = query.filter(t_msgr.name == name)
    if feed:
        query = query.filter(t_msgr.feed == feed)
    query = query.filter(t_md.name == domain.name)
    return query
예제 #37
0
def get_vm_object(vm_name):
    """Looks up the CFME database for the VM.

    Args:
        vm_name: VM name
    Returns:
        If found, :py:class:`utils.miq_soap.MiqVM`. If not, `None`
    """
    vm_table = cfmedb()['vms']
    for vm in cfmedb().session.query(vm_table.name, vm_table.guid)\
            .filter(vm_table.template == False):  # NOQA
        # Previous line is ok, if you change it to `is`, it won't work!
        if vm.name == vm_name:
            return MiqVM(vm.guid)
    else:
        return None
예제 #38
0
파일: pxe.py 프로젝트: vprusa/cfme_tests
 def exists(self):
     """
     Checks if the Customization template already exists
     """
     dbs = cfmedb()
     candidates = list(dbs.session.query(dbs["customization_templates"]))
     return self.name in [s.name for s in candidates]
예제 #39
0
파일: pxe.py 프로젝트: vprusa/cfme_tests
 def exists(self):
     """
     Checks if the PXE server already exists
     """
     dbs = cfmedb()
     candidates = list(dbs.session.query(dbs["pxe_servers"]))
     return self.name in [s.name for s in candidates]
예제 #40
0
def _db_select_query(name=None, feed=None, provider=None):
    """column order: `name`, `hostname`, `feed`, `product`,
    `provider_name`, `ems_ref`, `properties`"""
    t_ms = cfmedb()['middleware_servers']
    t_ems = cfmedb()['ext_management_systems']
    query = cfmedb().session.query(t_ms.name, t_ms.hostname, t_ms.feed, t_ms.product,
                                   t_ems.name.label('provider_name'),
                                   t_ms.ems_ref, t_ms.properties)\
        .join(t_ems, t_ms.ems_id == t_ems.id)
    if name:
        query = query.filter(t_ms.name == name)
    if feed:
        query = query.filter(t_ms.feed == feed)
    if provider:
        query = query.filter(t_ems.name == provider.name)
    return query
예제 #41
0
def _db_select_query(name=None, feed=None, provider=None):
    """column order: `id`, `name`, `feed`,
    `provider_name`, `ems_ref`, `properties`"""
    t_md = cfmedb()['middleware_domains']
    t_ems = cfmedb()['ext_management_systems']
    query = cfmedb().session.query(t_md.id, t_md.name, t_md.feed,
                                   t_ems.name.label('provider_name'),
                                   t_md.ems_ref, t_md.properties)\
        .join(t_ems, t_md.ems_id == t_ems.id)
    if name:
        query = query.filter(t_md.name == name)
    if feed:
        query = query.filter(t_md.feed == feed)
    if provider:
        query = query.filter(t_ems.name == provider.name)
    return query
예제 #42
0
파일: pxe.py 프로젝트: rrasouli/cfme_tests
 def exists(self):
     """
     Checks if the Customization template already exists
     """
     dbs = cfmedb()
     candidates = list(dbs.session.query(dbs["customization_templates"]))
     return self.name in [s.name for s in candidates]
예제 #43
0
def get_vm_object(vm_name):
    """Looks up the CFME database for the VM.

    Args:
        vm_name: VM name
    Returns:
        If found, :py:class:`utils.miq_soap.MiqVM`. If not, `None`
    """
    vm_table = cfmedb()['vms']
    for vm in cfmedb().session.query(vm_table.name, vm_table.guid)\
            .filter(vm_table.template == False):  # NOQA
        # Previous line is ok, if you change it to `is`, it won't work!
        if vm.name == vm_name:
            return MiqVM(vm.guid)
    else:
        return None
예제 #44
0
파일: pxe.py 프로젝트: rrasouli/cfme_tests
 def exists(self):
     """
     Checks if the PXE server already exists
     """
     dbs = cfmedb()
     candidates = list(dbs.session.query(dbs["pxe_servers"]))
     return self.name in [s.name for s in candidates]
예제 #45
0
 def _num_db_generic(self, table_str):
     res = cfmedb().engine.execute(
         "SELECT count(*) "
         "FROM ext_management_systems, {0} "
         "WHERE {0}.ems_id=ext_management_systems.id "
         "AND ext_management_systems.name='{1}'".format(table_str, self.name))
     return int(res.first()[0])
예제 #46
0
 def _num_db_generic(self, table_str):
     res = cfmedb().engine.execute(
         "SELECT count(*) "
         "FROM ext_management_systems, {0} "
         "WHERE {0}.ems_id=ext_management_systems.id "
         "AND ext_management_systems.name='{1}'".format(
             table_str, self.name))
     return int(res.first()[0])
예제 #47
0
 def num_server_group(self):
     res = cfmedb().engine.execute(
         "SELECT count(*) "
         "FROM ext_management_systems, middleware_domains, middleware_server_groups "
         "WHERE middleware_domains.ems_id=ext_management_systems.id "
         "AND middleware_domains.id=middleware_server_groups.domain_id "
         "AND ext_management_systems.name='{0}'".format(self.name))
     return int(res.first()[0])
예제 #48
0
def _db_select_query(name=None, server=None, provider=None):
    """Column order: `id`, `nativeid`, `name`, `server_name`, `feed`, `provider_name`"""
    t_ems = cfmedb()['ext_management_systems']
    t_ms = cfmedb()['middleware_servers']
    t_md = cfmedb()['middleware_deployments']
    query = cfmedb().session.query(t_md.id, t_md.nativeid.label('nativeid'), t_md.name,
                                   t_ms.name.label('server_name'), t_ms.feed.label('feed'),
                                   t_ems.name.label('provider_name')) \
        .join(t_ms, t_md.server_id == t_ms.id).join(t_ems, t_md.ems_id == t_ems.id)
    if name:
        query = query.filter(t_md.name == name)
    if server:
        query = query.filter(t_ms.name == server.name)
        if server.feed:
            query = query.filter(t_ms.feed == server.feed)
    if provider:
        query = query.filter(t_ems.name == provider.name)
    return query
예제 #49
0
 def get_pxe_image_type(self, image_name, db=True):
     if db:
         pxe_i = cfmedb()["pxe_images"]
         pxe_s = cfmedb()["pxe_servers"]
         pxe_t = cfmedb()["pxe_image_types"]
         hosts = list(cfmedb().session.query(pxe_t.name)
                      .join(pxe_i, pxe_i.pxe_image_type_id == pxe_t.id)
                      .join(pxe_s, pxe_i.pxe_server_id == pxe_s.id)
                      .filter(pxe_s.name == self.name)
                      .filter(pxe_i.name == image_name))
         if hosts:
             return hosts[0][0]
         else:
             return None
     else:
         sel.force_navigate('infrastructure_pxe_servers')
         pxe_tree(self.name, 'PXE Images', image_name)
         return pxe_details_page.pxe_image_type.text
예제 #50
0
def configure_appliance_for_event_testing(request, listener_info):
    """ This fixture ensures that the appliance is configured for event testing.
    """
    event_testing = request.config.pluginmanager.getplugin("event_testing")
    # If we did not enable the event testing, do not setup
    if event_testing.listener is None:
        return
    return setup_for_event_testing(SSHClient(), cfmedb(), listener_info,
                                   providers.list_infra_providers())
예제 #51
0
 def num_container(self):
     # Containers are linked to providers through container definitions and then through pods
     res = cfmedb().engine.execute(
         "SELECT count(*) "
         "FROM ext_management_systems, container_groups, container_definitions, containers "
         "WHERE containers.container_definition_id=container_definitions.id "
         "AND container_definitions.container_group_id=container_groups.id "
         "AND container_groups.ems_id=ext_management_systems.id "
         "AND ext_management_systems.name='{}'".format(self.name))
     return int(res.first()[0])
예제 #52
0
def configure_appliance_for_event_testing(request, listener_info):
    """ This fixture ensures that the appliance is configured for event testing.
    """
    event_testing = request.config.pluginmanager.getplugin("event_testing")
    # If we did not enable the event testing, do not setup
    if event_testing.listener is None:
        return
    return setup_for_event_testing(
        SSHClient(), cfmedb(), listener_info, providers.list_infra_providers()
    )
예제 #53
0
def _db_select_query(name=None, nativeid=None, server=None, provider=None):
    """Column order: `id`, `nativeid`, `name`, `properties`, `server_name`,
    `feed`, `provider_name`, `ems_ref`"""
    t_ms = cfmedb()['middleware_servers']
    t_mds = cfmedb()['middleware_datasources']
    t_ems = cfmedb()['ext_management_systems']
    query = cfmedb().session.query(t_mds.id, t_mds.nativeid, t_mds.name, t_mds.properties,
                                   t_ms.name.label('server_name'), t_ms.feed,
                                   t_ems.name.label('provider_name'), t_mds.ems_ref)\
        .join(t_ms, t_mds.server_id == t_ms.id).join(t_ems, t_mds.ems_id == t_ems.id)
    if name:
        query = query.filter(t_mds.name == name)
    if nativeid:
        query = query.filter(t_mds.nativeid == nativeid)
    if server:
        query = query.filter(t_ms.name == server.name)
        if server.feed:
            query = query.filter(t_ms.feed == server.feed)
    if provider:
        query = query.filter(t_ems.name == provider.name)
    return query
예제 #54
0
 def num_datastore(self, db=True):
     """ Returns the providers number of templates, as shown on the Details page."""
     if db:
         results = list(cfmedb().engine.execute(
             'SELECT DISTINCT storages.name, hosts.ems_id '
             'FROM ext_management_systems, hosts, storages, hosts_storages '
             'WHERE hosts.id=hosts_storages.host_id AND '
             'storages.id=hosts_storages.storage_id AND '
             'hosts.ems_id=ext_management_systems.id AND '
             'ext_management_systems.name=\'{}\''.format(self.name)))
         return len(results)
     else:
         return int(self.get_detail("Relationships", "Datastores"))
예제 #55
0
 def exists(self, db=True):
     """
     Checks if the ISO Datastore already exists
     """
     if db:
         iso = cfmedb()['iso_datastores']
         ems = cfmedb()['ext_management_systems']
         name = self.provider
         iso_ds = list(cfmedb().session.query(iso.id)
                       .join(ems, iso.ems_id == ems.id)
                       .filter(ems.name == name))
         if iso_ds:
             return True
         else:
             return False
     else:
         sel.force_navigate('infrastructure_iso_datastores')
         try:
             iso_tree(self.provider)
             return True
         except CandidateNotFound:
             return False
예제 #56
0
    def _num_db_generic(self, table_str):
        """ Fetch number of rows related to this provider in a given table

        Args:
            table_str: Name of the table; e.g. 'vms' or 'hosts'
        """
        res = cfmedb().engine.execute(
            "SELECT count(*) "
            "FROM ext_management_systems, {0} "
            "WHERE {0}.ems_id=ext_management_systems.id "
            "AND ext_management_systems.name='{1}'".format(
                table_str, self.name))
        return int(res.first()[0])
예제 #57
0
    def num_datastore(self):
        storage_table_name = version.pick({
            version.LOWEST: 'hosts_storages',
            '5.5.0.8': 'host_storages'
        })
        """ Returns the providers number of templates, as shown on the Details page."""

        results = list(cfmedb().engine.execute(
            'SELECT DISTINCT storages.name, hosts.ems_id '
            'FROM ext_management_systems, hosts, storages, {} '
            'WHERE hosts.id={}.host_id AND '
            'storages.id={}.storage_id AND '
            'hosts.ems_id=ext_management_systems.id AND '
            'ext_management_systems.name=\'{}\''.format(
                storage_table_name, storage_table_name, storage_table_name,
                self.name)))
        return len(results)
예제 #58
0
 def exists(self, db=True):
     """
     Checks if the PXE server already exists
     """
     if db:
         dbs = cfmedb()
         candidates = list(dbs.session.query(dbs["pxe_servers"]))
         return self.name in [s.name for s in candidates]
     else:
         sel.force_navigate('infrastructure_pxe_servers')
         try:
             pxe_tree(self.name)
             return True
         except CandidateNotFound:
             return False
         except NoSuchElementException:
             return False
예제 #59
0
 def exists(self, db=True):
     """
     Checks if the Customization template already exists
     """
     if db:
         dbs = cfmedb()
         candidates = list(dbs.session.query(dbs["customization_templates"]))
         return self.name in [s.name for s in candidates]
     else:
         sel.force_navigate('infrastructure_pxe_templates')
         try:
             template_tree(self.image_type, self.name)
             return True
         except CandidateNotFound:
             return False
         except NoSuchElementException:
             return False