def system_fact_compliance_list(account): list_of_instances = [] rules = Rules() report_biz_rules = rules.get_rules() list_of_rhics = list(RHIC.objects.filter(account_id=account)) for rhic in list_of_rhics: instances = ReportData.objects.filter(consumer=rhic.name) #instances = ReportData.objects.distinct(consumer=rhic.name) for i in instances: list_of_instances.append(i.instance_identifier) unique_list = set(list_of_instances) results = [] for i in unique_list: # we need to find if this instance_identifier has any other products # associated w/ it products = ReportData.objects.filter( instance_identifier=i).distinct('product_name') for p in products: inst = ReportData.objects.filter( instance_identifier=i, product_name=p).first() product_rules = report_biz_rules[inst.product_name] if product_rules['cpu']: if product_rules['cpu']['high_lt'] != -1: if inst.cpu > product_rules['cpu']['high_lt']: results.append([inst, product_rules, 'violates cpu']) if product_rules['cpu_sockets']: if product_rules['cpu_sockets']['high_lt'] != -1: if inst.cpu_sockets > product_rules['cpu_sockets']['high_lt']: results.append([inst, product_rules, 'violates cpu_sockets']) if product_rules['memtotal']: if product_rules['memtotal']['high_lt'] != -1: if inst.memtotal > product_rules['memtotal']['high_lt']: results.append([inst, product_rules, 'violates memory']) return results
def test_rules_rhel(self): r = Rules() rules = r.get_rules() this_test = rules[RHEL]['memtotal'] this_expected_results = {'low_gt': 0, 'low_lt': 8388608, 'low_desc': '< 8GB', 'high_gt': 8388608, 'high_lt': 83886080, 'high_desc': '> 8GB', 'rule': '0 > 8388608; 8388608 > 83886080'} self.assertEqual(this_test, this_expected_results, 'results match')
def create_entry(product, mem_high=True, date=None, socket=4, cpu=4, instance_identifier="12:31:3D:08:49:00"): rules = Rules() report_biz_rules = rules.get_rules() if not date: date = datetime.now() this_hour = date.strftime(constants.hr_fmt) this_day = date.strftime(constants.day_fmt) interval = report_biz_rules[product]['calculation'] if interval == 'hourly': row = ReportData( instance_identifier=instance_identifier, date=date, hour=this_hour, day=this_day, environment="us-east-1", splice_server="splice-server-1.spliceproject.org" ) elif interval == 'daily': row = ReportDataDaily( instance_identifier=instance_identifier, date=date, day=this_day, environment="us-east-1", splice_server="splice-server-1.spliceproject.org" ) for key, value in PRODUCTS_DICT.items(): if product == key: rhic = RHIC.objects.filter(uuid=value[1])[0] row['product_name'] = key row['product'] = value[0] row['consumer_uuid'] = value[1] row['consumer'] = value[2] row['contract_id'] = rhic.contract row['sla'] = rhic.sla row['support'] = rhic.support_level row['contract_use'] = "20" row['cpu_sockets'] = socket row['cpu'] = cpu row['record_identifier'] = str(value[2]) + instance_identifier\ + str(date) + str(value[0]) if mem_high: row['memtotal'] = 16048360 return row else: row['memtotal'] = 640 return row
def hours_per_consumer(start, end, list_of_rhics=None, contract_number=None, environment="All", return_failed_only=False): results = [] rules = Rules() report_biz_rules = rules.get_rules() if contract_number: list_of_rhics = list(RHIC.objects.filter(contract=contract_number)) if list_of_rhics: account_num = RHIC.objects.get(uuid=list_of_rhics[0].uuid).account_id for rhic in list_of_rhics: rhic_list = [] account_num = str(RHIC.objects.filter(uuid=str(rhic.uuid))[0].account_id) contract_num = str(RHIC.objects.filter(uuid=str(rhic.uuid))[0].contract) ''' There can be multiple contracts under an account. The contract is an embedded document under account and can not be filtered directly. Iterating through the list of contracts under an account is the only way I can think of to get the correct contract ''' list_of_products = get_list_of_products(account_num, contract_num) products_contract = [(prod.name) for prod in list_of_products] intersect = set(products_contract).intersection(set(rhic.products)) for p in (p for p in list_of_products if p.name in intersect): # _LOG.info(p.name, p.sla, p.support_level) results_dicts = [] results_dicts = Product_Def.get_count(p, rhic, start, end, contract_num, environment, report_biz_rules) if results_dicts: for result in results_dicts: if not return_failed_only: rhic_list.append(result) else: if not result['compliant']: rhic_list.append(result) if rhic_list: results.append(rhic_list) return results
def create_entry(product, mem_high=True, date=None, socket=4, cpu=4, instance_identifier="12:31:3D:08:49:00"): rules = Rules() report_biz_rules = rules.get_rules() if not date: date = datetime.now() this_hour = date.strftime(constants.hr_fmt) this_day = date.strftime(constants.day_fmt) interval = report_biz_rules[product]["calculation"] if interval == "hourly": row = ReportData( instance_identifier=instance_identifier, date=date, hour=this_hour, day=this_day, environment="us-east-1", splice_server="test01", ) for key, value in PRODUCTS_DICT.items(): if product == key: rhic = RHIC.objects.filter(uuid=value[1])[0] row["product_name"] = key row["product"] = value[0] row["consumer_uuid"] = value[1] row["consumer"] = value[2] row["contract_id"] = rhic.contract row["sla"] = rhic.sla row["support"] = rhic.support_level row["contract_use"] = "20" row["cpu_sockets"] = socket row["cpu"] = cpu row["record_identifier"] = str(value[2]) + instance_identifier + str(date) + str(value[0]) if mem_high: row["memtotal"] = 16048360 return row else: row["memtotal"] = 640 return row
# Connect to the mongo databases. connect(MONGO_DATABASE_NAME_CHECKIN, alias='checkin', tz_aware=True, host=MONGO_DATABASE_HOST_CHECKIN) connect(MONGO_DATABASE_NAME_RHICSERVE, alias='rhic_serve', tz_aware=True, host=MONGO_DATABASE_HOST_RHICSERVE) connect(MONGO_DATABASE_NAME, alias='results', tz_aware=True, host=MONGO_DATABASE_HOST) register_connection('default', MONGO_DATABASE_NAME_RHICSERVE, host=MONGO_DATABASE_HOST_RHICSERVE) # Custom test runner to work with Mongo TEST_RUNNER = 'rhic_serve.common.tests.MongoTestRunner' # Business Rules initialization r = Rules() r.init() r.list_rules() LOGIN_URL = '/ui/' ROOT_URLCONF = 'report_server.splice_reports.urls' # Python dotted path to the WSGI application used by Django's runserver. WSGI_APPLICATION = 'splice_reports.wsgi.application' TEMPLATE_DIRS = ( # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. #os.path.join(os.path.abspath(os.path.dirname(__name__)), "templates"),
''' RHEL = TestData.RHEL HA = TestData.HA EUS = TestData.EUS LB = TestData.LB JBoss = TestData.JBoss EDU = TestData.EDU UNLIMITED = TestData.UNLIMITED GEAR = TestData.GEAR products_dict = TestData.PRODUCTS_DICT rules = Rules() report_biz_rules = rules.get_rules() class UITestCase(BaseMongoTestCase): def test_import_three(self): SpliceServer.drop_collection() ProductUsage.drop_collection() ReportData.drop_collection() ss1 = TestData.create_splice_server("test01", "east") uuid_rhel_jboss = products_dict[RHEL][1] prod_rhel = products_dict[RHEL][0] prod_jboss = products_dict[JBoss][0]
def drop_rules(self): #Note: name conflict with 'report_server.common.biz_rules.Rules' from report_server.sreport.models import Rules Rules.drop_collection()
MONGO_DATABASE_HOST_CHECKIN = config.CONFIG.get('server', 'db_host') MONGO_DATABASE_NAME_RHICSERVE = config.CONFIG.get('rhic_serve', 'db_name') MONGO_DATABASE_HOST_RHICSERVE = config.CONFIG.get('rhic_serve', 'db_host') # Connect to the mongo databases. connect(MONGO_DATABASE_NAME_CHECKIN, alias='checkin_service', tz_aware=True, host=MONGO_DATABASE_HOST_CHECKIN) connect(MONGO_DATABASE_NAME_RHICSERVE, alias='rhic_serve', tz_aware=True, host=MONGO_DATABASE_HOST_RHICSERVE) connect(MONGO_DATABASE_NAME, alias='results', tz_aware=True, host=MONGO_DATABASE_HOST) register_connection('default', MONGO_DATABASE_NAME_RHICSERVE, host=MONGO_DATABASE_HOST_RHICSERVE, tz_aware=True) # Business Rules initialization r = Rules() r.init() #r.list_rules() ROOT_URLCONF = 'report_server.splice_reports.urls' # Python dotted path to the WSGI application used by Django's runserver. WSGI_APPLICATION = 'splice_reports.wsgi.application' TEMPLATE_DIRS = ( '/usr/lib/report_server/templates', ) INSTALLED_APPS = ( 'django.contrib.auth',