Beispiel #1
0
 def test_get_version_info(self):
     self.assertIsNone(utils.get_version_info(None))
     self.env.create()
     cluster = self.env.clusters[0]
     version_info = utils.get_version_info(cluster)
     self.assertItemsEqual(('release_os', 'release_name', 'release_version',
                            'environment_version', 'fuel_version'),
                           version_info.keys())
 def test_get_version_info(self):
     self.assertIsNone(utils.get_version_info(None))
     cluster = self.env.create()
     version_info = utils.get_version_info(cluster)
     self.assertItemsEqual(
         ('release_os', 'release_name', 'release_version',
          'environment_version', 'fuel_version'),
         version_info.keys()
     )
Beispiel #3
0
def collect(resource_type):
    try:
        operational_clusters = ClusterCollection.filter_by(
            iterable=None, status=consts.CLUSTER_STATUSES.operational).all()
        error_clusters = ClusterCollection.filter_by(
            iterable=None, status=consts.CLUSTER_STATUSES.error).all()

        all_envs_last_recs = \
            OpenStackWorkloadStatsCollection.get_last_by_resource_type(
                resource_type)
        ready_or_error_ids = set([c.id for c in operational_clusters] +
                                 [c.id for c in error_clusters])
        envs_ids_to_clear = set(r.cluster_id for r in all_envs_last_recs) - \
            ready_or_error_ids
        # Clear current resource data for unavailable clusters.
        # Current OSWL data is cleared for those clusters which status is not
        # 'operational' nor 'error' or when cluster was removed. Data is
        # cleared for cluster only if it was updated recently (today or
        # yesterday). While this collector is running with interval much
        # smaller than one day it should not miss any unavailable cluster.
        for id in envs_ids_to_clear:
            oswl_statistics_save(id, resource_type, [])

        # Collect current OSWL data and update data in DB
        for cluster in operational_clusters:
            try:
                client_provider = helpers.ClientProvider(cluster)
                proxy_for_os_api = utils.get_proxy_for_cluster(cluster)
                version_info = utils.get_version_info(cluster)

                with utils.set_proxy(proxy_for_os_api):
                    data = helpers.get_info_from_os_resource_manager(
                        client_provider, resource_type)
                    oswl_statistics_save(cluster.id, resource_type, data,
                                         version_info=version_info)

            except errors.StatsException as e:
                logger.error("Cannot collect OSWL resource {0} for cluster "
                             "with id {1}. Details: {2}."
                             .format(resource_type,
                                     cluster.id,
                                     six.text_type(e))
                             )
            except Exception as e:
                logger.exception("Error while collecting OSWL resource {0} "
                                 "for cluster with id {1}. Details: {2}."
                                 .format(resource_type,
                                         cluster.id,
                                         six.text_type(e))
                                 )

        db.commit()

    except Exception as e:
        logger.exception("Exception while collecting OS workloads "
                         "for resource name {0}. Details: {1}"
                         .format(resource_type, six.text_type(e)))
    finally:
        db.remove()
Beispiel #4
0
    def test_oswl_statistics_save_version_info(self):
        cluster = self.env.create()

        # Without version info
        oswl_statistics_save(cluster.id, consts.OSWL_RESOURCE_TYPES.vm, [])
        oswl = OpenStackWorkloadStats.get_last_by(
            cluster.id, consts.OSWL_RESOURCE_TYPES.vm)
        self.assertEqual({}, oswl.version_info)

        # With version info
        oswl_statistics_save(
            cluster.id, consts.OSWL_RESOURCE_TYPES.vm, [{'id': 1}],
            version_info=utils.get_version_info(cluster)
        )
        oswl = OpenStackWorkloadStats.get_last_by(
            cluster.id, consts.OSWL_RESOURCE_TYPES.vm)
        self.assertEqual(utils.get_version_info(cluster), oswl.version_info)
Beispiel #5
0
    def test_oswl_statistics_save_version_info(self):
        cluster = self.env.create()

        # Without version info
        oswl_statistics_save(cluster.id, consts.OSWL_RESOURCE_TYPES.vm, [])
        oswl = OpenStackWorkloadStats.get_last_by(
            cluster.id, consts.OSWL_RESOURCE_TYPES.vm)
        self.assertEqual({}, oswl.version_info)

        # With version info
        oswl_statistics_save(cluster.id,
                             consts.OSWL_RESOURCE_TYPES.vm, [{
                                 'id': 1
                             }],
                             version_info=utils.get_version_info(cluster))
        oswl = OpenStackWorkloadStats.get_last_by(
            cluster.id, consts.OSWL_RESOURCE_TYPES.vm)
        self.assertEqual(utils.get_version_info(cluster), oswl.version_info)