elif vim_type == "vmware":
log.info("This metric_request message is for the vROPs plugin.")
- self.vrops_rcvr.consume(message)
+ self.vrops_rcvr.consume(message,vim_uuid)
else:
log.debug("vim_type is misconfigured or unsupported; %s",
import json
from OpenSSL.crypto import load_certificate, FILETYPE_PEM
import os
+import sys
import datetime
from socket import getfqdn
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
+sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '..'))
+from osm_mon.core.database import DatabaseManager
+
OPERATION_MAPPING = {'GE':'GT_EQ', 'LE':'LT_EQ', 'GT':'GT', 'LT':'LT', 'EQ':'EQ'}
severity_mano2vrops = {'WARNING':'WARNING', 'MINOR':'WARNING', 'MAJOR':"IMMEDIATE",\
'CRITICAL':'CRITICAL', 'INDETERMINATE':'UNKNOWN'}
class MonPlugin():
"""MON Plugin class for vROPs telemetry plugin
"""
- def __init__(self):
+ def __init__(self, access_config=None):
"""Constructor of MON plugin
Params:
'access_config': dictionary with VIM access information based on VIM type.
Returns: Raise an exception if some needed parameter is missing, but it must not do any connectivity
check against the VIM
"""
+
self.logger = logging.getLogger('PluginReceiver.MonPlugin')
self.logger.setLevel(logging.DEBUG)
- access_config = self.get_default_Params('Access_Config')
+ if access_config is None:
+ self.logger.error("VIM Access Configuration not provided")
+ raise KeyError("VIM Access Configuration not provided")
+
+ self.database_manager = DatabaseManager()
+
self.access_config = access_config
if not bool(access_config):
- self.logger.error("Access configuration not provided in vROPs Config file")
- raise KeyError("Access configuration not provided in vROPs Config file")
+ self.logger.error("VIM Account details are not added. Please add a VIM account")
+ raise KeyError("VIM Account details are not added. Please add a VIM account")
try:
self.vrops_site = access_config['vrops_site']
self.vrops_user = access_config['vrops_user']
self.vrops_password = access_config['vrops_password']
- self.vcloud_site = access_config['vcloud-site']
+ self.vcloud_site = access_config['vim_url']
self.admin_username = access_config['admin_username']
self.admin_password = access_config['admin_password']
- self.tenant_id = access_config['tenant_id']
+ #self.tenant_id = access_config['tenant_id']
+ self.vim_uuid = access_config['vim_uuid']
+
except KeyError as exp:
- self.logger.error("Check Access configuration in vROPs Config file: {}".format(exp))
- raise KeyError("Check Access configuration in vROPs Config file: {}".format(exp))
+ self.logger.error("Required VIM account details not provided: {}".format(exp))
+ raise KeyError("Required VIM account details not provided: {}".format(exp))
+
def configure_alarm(self, config_dict = {}):
"operation": One of ('GE', 'LE', 'GT', 'LT', 'EQ')
"threshold_value": Defines the threshold (up to 2 fraction digits) that,
if crossed, will trigger the alarm.
- "unit": Unit of measurement in string format
"statistic": AVERAGE, MINIMUM, MAXIMUM, COUNT, SUM
Default parameters for each alarm are read from the plugin specific config file.
'resource_kind_key': def_a_params['resource_kind'],
'adapter_kind_key': def_a_params['adapter_kind'],
'symptom_name':vrops_alarm_name,
- 'severity': severity_mano2vrops[config_dict['severity']],
+ 'severity': severity_mano2vrops[config_dict['severity'].upper()],
'metric_key':metric_key_params['metric_key'],
'operation':OPERATION_MAPPING[config_dict['operation']],
'threshold_value':config_dict['threshold_value']}
+
symptom_uuid = self.create_symptom(symptom_params)
if symptom_uuid is not None:
self.logger.info("Symptom defined: {} with ID: {}".format(symptom_params['symptom_name'],symptom_uuid))
'resourceKindKey':def_a_params['resource_kind'],
'waitCycles':1, 'cancelCycles':1,
'type':def_a_params['alarm_type'], 'subType':def_a_params['alarm_subType'],
- 'severity':severity_mano2vrops[config_dict['severity']],
+ 'severity':severity_mano2vrops[config_dict['severity'].upper()],
'symptomDefinitionId':symptom_uuid,
'impact':def_a_params['impact']}
return None
else:
alarm_def_uuid = alarm_def.split('-', 1)[1]
- self.logger.info("Alarm defination created with notification: {} with ID: {}"\
+ self.logger.info("Alarm definition created with notification: {} with ID: {}"\
.format(alarm_params['name'],alarm_def_uuid))
- #Return alarm defination UUID by removing 'AlertDefinition' from UUID
+ ##self.database_manager.save_alarm(alarm_def_uuid, alarm_params['name'], self.vim_uuid)
+ self.database_manager.save_alarm(alarm_def_uuid,
+ self.vim_uuid,
+ ##alarm_params['name'],
+ config_dict['threshold_value'],
+ config_dict['operation'],
+ config_dict['metric_name'].lower(),
+ config_dict['vdu_name'].lower(),
+ config_dict['vnf_member_index'].lower(),
+ config_dict['ns_id'].lower()
+ )
+
+ #Return alarm definition UUID by removing 'AlertDefinition' from UUID
return (alarm_def_uuid)
def get_default_Params(self, metric_alarm_name):
tree = XmlElementTree.parse(source)
alarms = tree.getroot()
for alarm in alarms:
- if alarm.tag == metric_alarm_name:
+ if alarm.tag.lower() == metric_alarm_name.lower():
for param in alarm:
if param.tag in ("period", "evaluation", "cancel_period", "alarm_type",\
"cancel_cycles", "alarm_subType"):
vca = None
if vapp_uuid is None:
- return None
+ return parsed_respond
vca = self.connect_as_admin()
if not vca:
return_data = {}
return_data['schema_version'] = "1.0"
return_data['schema_type'] = 'read_metric_data_response'
+ return_data['vim_uuid'] = metric['vim_uuid']
return_data['metric_name'] = metric['metric_name']
#To do - No metric_uuid in vROPs, thus returning '0'
return_data['metric_uuid'] = '0'
return_data['resource_uuid'] = metric['resource_uuid']
return_data['metrics_data'] = {'time_series':[], 'metrics_series':[]}
#To do - Need confirmation about uuid & id
- if 'tenant_uuid' in metric and metric['tenant_uuid'] is not None:
- return_data['tenant_uuid'] = metric['tenant_uuid']
- else:
- return_data['tenant_uuid'] = None
+ ##if 'tenant_uuid' in metric and metric['tenant_uuid'] is not None:
+ ## return_data['tenant_uuid'] = metric['tenant_uuid']
+ ##else:
+ ## return_data['tenant_uuid'] = None
return_data['unit'] = None
#return_data['tenant_id'] = self.tenant_id
#self.logger.warning("return_data: {}".format(return_data))
verify = False, headers = headers)
if resp.status_code is not 200:
- self.logger.warning("Failed to retrive Metric data from vROPs for {}\nResponse code:{}\nResponse Content: {}"\
+ self.logger.warning("Failed to retrieve Metric data from vROPs for {}\nResponse code:{}\nResponse Content: {}"\
.format(metric['metric_name'], resp.status_code, resp.content))
return return_data
if new_alarm_config.get('alarm_uuid') is None:
self.logger.warning("alarm_uuid is required to update an Alarm")
return None
- #1) Get Alarm details from it's uuid & find the symptom defination
+ #1) Get Alarm details from it's uuid & find the symptom definition
alarm_details_json, alarm_details = self.get_alarm_defination_details(new_alarm_config['alarm_uuid'])
if alarm_details_json is None:
return None
try:
- #2) Update the symptom defination
+ #2) Update the symptom definition
if alarm_details['alarm_id'] is not None and alarm_details['symptom_definition_id'] is not None:
symptom_defination_id = alarm_details['symptom_definition_id']
else:
- self.logger.info("Symptom Defination ID not found for {}".format(new_alarm_config['alarm_uuid']))
+ self.logger.info("Symptom Definition ID not found for {}".format(new_alarm_config['alarm_uuid']))
return None
symptom_uuid = self.update_symptom_defination(symptom_defination_id, new_alarm_config)
- #3) Update the alarm defination & Return UUID if successful update
+ #3) Update the alarm definition & Return UUID if successful update
if symptom_uuid is None:
- self.logger.info("Symptom Defination details not found for {}"\
+ self.logger.info("Symptom Definition details not found for {}"\
.format(new_alarm_config['alarm_uuid']))
return None
else:
alarm_details['sub_type'] = json_data['subType']
alarm_details['symptom_definition_id'] = json_data['states'][0]['base-symptom-set']['symptomDefinitionIds'][0]
except Exception as exp:
- self.logger.warning("Exception while retriving alarm defination details: {}".format(exp))
+ self.logger.warning("Exception while retrieving alarm definition details: {}".format(exp))
return None, None
return json_data, alarm_details
return alert_match_list
except Exception as exp:
- self.logger.warning("Exception while searching alarm defination: {}".format(exp))
+ self.logger.warning("Exception while searching alarm definition: {}".format(exp))
return alert_match_list
def update_symptom_defination(self, symptom_uuid, new_alarm_config):
- """Update symptom defination based on new alarm input configuration
+ """Update symptom definition based on new alarm input configuration
"""
- #1) Get symptom defination details
+ #1) Get symptom definition details
symptom_details = self.get_symptom_defination_details(symptom_uuid)
#print "\n\nsymptom_details: {}".format(symptom_details)
if symptom_details is None:
if symptom_uuid is not None:
- self.logger.info("Symptom defination updated {} for alarm: {}"\
+ self.logger.info("Symptom definition updated {} for alarm: {}"\
.format(symptom_uuid, new_alarm_config['alarm_uuid']))
return symptom_uuid
else:
- self.logger.warning("Failed to update Symptom Defination {} for : {}"\
+ self.logger.warning("Failed to update Symptom Definition {} for : {}"\
.format(symptom_uuid, new_alarm_config['alarm_uuid']))
return None
def get_symptom_defination_details(self, symptom_uuid):
- """Get symptom defination details
+ """Get symptom definition details
"""
symptom_details = {}
if symptom_uuid is None:
verify = False, headers = headers)
if resp.status_code is not 200:
- self.logger.warning("Symptom defination not found {} \nResponse code:{}\nResponse Content: {}"\
+ self.logger.warning("Symptom definition not found {} \nResponse code:{}\nResponse Content: {}"\
.format(symptom_uuid, resp.status_code, resp.content))
return None
def reconfigure_alarm(self, alarm_details_json, new_alarm_config):
- """Reconfigure alarm defination as per input
+ """Reconfigure alarm definition as per input
"""
if 'severity' in new_alarm_config and new_alarm_config['severity'] is not None:
alarm_details_json['states'][0]['severity'] = new_alarm_config['severity']
return None
def delete_alarm_defination(self, alarm_id):
- """Delete created Alarm defination
+ """Delete created Alarm definition
"""
api_url = '/suite-api/api/alertdefinitions/'
headers = {'Accept':'application/json'}
return alarm_id
def delete_symptom_definition(self, symptom_id):
- """Delete symptom defination
+ """Delete symptom definition
"""
api_url = '/suite-api/api/symptomdefinitions/'
headers = {'Accept':'application/json'}
if 'metric_name' not in metric_info:
self.logger.debug("Metric name not provided: {}".format(metric_info))
return status
- metric_key_params = self.get_default_Params(metric_info['metric_name'])
+ metric_key_params = self.get_default_Params(metric_info['metric_name'].lower())
if not metric_key_params:
self.logger.warning("Metric not supported: {}".format(metric_info['metric_name']))
return status
date_time_formatted = complete_datetime.split('.',1)[0]
return date_time_formatted
-
##
"""
-Montoring plugin receiver that consumes the request messages &
+Monitoring plugin receiver that consumes the request messages &
responds using producer for vROPs
"""
import os
import sys
import traceback
-
-
#Core producer
import six
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '..'))
from osm_mon.core.message_bus.producer import KafkaProducer
+
+from osm_mon.core.auth import AuthManager
+
#from core.message_bus.producer import KafkaProducer
from xml.etree import ElementTree as XmlElementTree
+
schema_version = "1.0"
req_config_params = ('vrops_site', 'vrops_user', 'vrops_password',
'vcloud-site','admin_username','admin_password',
'vcenter_ip','vcenter_port','vcenter_user','vcenter_password',
- 'vim_tenant_name','orgname','tenant_id')
+ 'vim_tenant_name','orgname')
MODULE_DIR = os.path.dirname(__file__)
CONFIG_FILE_NAME = 'vrops_config.xml'
CONFIG_FILE_PATH = os.path.join(MODULE_DIR, CONFIG_FILE_NAME)
self.producer_access_credentials = KafkaProducer('vim_access_credentials_response')
- def consume(self, message):
+ def consume(self, message, vim_uuid):
"""Consume the message, act on it & respond
"""
try:
- self.logger.info("Message received:\nTopic={}:{}:{}:\nKey={}\nValue={}"\
- .format(message.topic, message.partition, message.offset, message.key, message.value))
+ self.logger.info("Message received for VIM: {} :\nMessage Topic={}:{}:{}:\n"\
+ "Message Key={}\nMessage Value={}"\
+ .format(vim_uuid, message.topic, message.partition, message.offset,\
+ message.key, message.value))
message_values = json.loads(message.value)
+ #Adding vim_uuid to message
+ message_values['vim_uuid'] = vim_uuid
self.logger.info("Action required for: {}".format(message.topic))
if message.topic == 'alarm_request':
if message.key == "create_alarm_request":
- config_alarm_info = json.loads(message.value)
- alarm_uuid = self.create_alarm(config_alarm_info['alarm_create_request'])
+ config_alarm_info = message_values
+ alarm_uuid = self.create_alarm(config_alarm_info)
self.logger.info("Alarm created with alarm uuid: {}".format(alarm_uuid))
#Publish message using producer
self.publish_create_alarm_status(alarm_uuid, config_alarm_info)
elif message.key == "update_alarm_request":
- update_alarm_info = json.loads(message.value)
- alarm_uuid = self.update_alarm(update_alarm_info['alarm_update_request'])
- self.logger.info("Alarm defination updated : alarm uuid: {}".format(alarm_uuid))
+ update_alarm_info = message_values
+ alarm_uuid = self.update_alarm(update_alarm_info)
+ self.logger.info("Alarm definition updated : alarm uuid: {}".format(alarm_uuid))
#Publish message using producer
self.publish_update_alarm_status(alarm_uuid, update_alarm_info)
elif message.key == "delete_alarm_request":
- delete_alarm_info = json.loads(message.value)
- alarm_uuid = self.delete_alarm(delete_alarm_info['alarm_delete_request'])
- self.logger.info("Alarm defination deleted : alarm uuid: {}".format(alarm_uuid))
+ delete_alarm_info = message_values
+ alarm_uuid = self.delete_alarm(delete_alarm_info)
+ self.logger.info("Alarm definition deleted : alarm uuid: {}".format(alarm_uuid))
#Publish message using producer
self.publish_delete_alarm_status(alarm_uuid, delete_alarm_info)
elif message.key == "list_alarm_request":
- request_input = json.loads(message.value)
- triggered_alarm_list = self.list_alarms(request_input['alarm_list_request'])
+ request_input = message_values
+ triggered_alarm_list = self.list_alarms(request_input)
#Publish message using producer
self.publish_list_alarm_response(triggered_alarm_list, request_input)
elif message.topic == 'metric_request':
if message.key == "read_metric_data_request":
- metric_request_info = json.loads(message.value)
- mon_plugin_obj = MonPlugin()
+ metric_request_info = message_values
+ access_config = None
+ access_config = self.get_vim_access_config(metric_request_info['vim_uuid'])
+ mon_plugin_obj = MonPlugin(access_config)
metrics_data = mon_plugin_obj.get_metrics_data(metric_request_info)
self.logger.info("Collected Metrics Data: {}".format(metrics_data))
#Publish message using producer
self.publish_metrics_data_status(metrics_data)
elif message.key == "create_metric_request":
- metric_info = json.loads(message.value)
- metric_status = self.verify_metric(metric_info['metric_create_request'])
+ metric_info = message_values
+ metric_status = self.verify_metric(metric_info)
#Publish message using producer
self.publish_create_metric_response(metric_info, metric_status)
elif message.key == "update_metric_request":
- metric_info = json.loads(message.value)
- metric_status = self.verify_metric(metric_info['metric_create_request'])
+ metric_info = message_values
+ metric_status = self.verify_metric(metric_info)
#Publish message using producer
self.publish_update_metric_response(metric_info, metric_status)
elif message.key == "delete_metric_request":
- metric_info = json.loads(message.value)
+ metric_info = message_values
#Deleting Metric Data is not allowed. Publish status as False
- self.logger.warning("Deleting Metric is not allowed: {}".format(metric_info['metric_name']))
+ self.logger.warning("Deleting Metric is not allowed by VMware vROPs plugin: {}"\
+ .format(metric_info['metric_name']))
#Publish message using producer
self.publish_delete_metric_response(metric_info)
elif message.topic == 'access_credentials':
if message.key == "vim_access_credentials":
- access_info = json.loads(message.value)
+ access_info = message_values
access_update_status = self.update_access_credentials(access_info['access_config'])
self.publish_access_update_response(access_update_status, access_info)
def create_alarm(self, config_alarm_info):
"""Create alarm using vROPs plugin
"""
- mon_plugin = MonPlugin()
+ access_config = None
+ access_config = self.get_vim_access_config(config_alarm_info['vim_uuid'])
+ mon_plugin = MonPlugin(access_config)
plugin_uuid = mon_plugin.configure_rest_plugin()
- alarm_uuid = mon_plugin.configure_alarm(config_alarm_info)
+ alarm_uuid = mon_plugin.configure_alarm(config_alarm_info['alarm_create_request'])
return alarm_uuid
def publish_create_alarm_status(self, alarm_uuid, config_alarm_info):
msg_key = 'create_alarm_response'
response_msg = {"schema_version":schema_version,
"schema_type":"create_alarm_response",
+ "vim_uuid":config_alarm_info["vim_uuid"],
"alarm_create_response":
{"correlation_id":config_alarm_info["alarm_create_request"]["correlation_id"],
"alarm_uuid":alarm_uuid,
self.producer_alarms.publish(key=msg_key, value=json.dumps(response_msg), topic=topic)
def update_alarm(self, update_alarm_info):
- """Updare already created alarm
+ """Update already created alarm
"""
- mon_plugin = MonPlugin()
- alarm_uuid = mon_plugin.update_alarm_configuration(update_alarm_info)
+ access_config = None
+ access_config = self.get_vim_access_config(update_alarm_info['vim_uuid'])
+ mon_plugin = MonPlugin(access_config)
+ alarm_uuid = mon_plugin.update_alarm_configuration(update_alarm_info['alarm_update_request'])
return alarm_uuid
def publish_update_alarm_status(self, alarm_uuid, update_alarm_info):
msg_key = 'update_alarm_response'
response_msg = {"schema_version":schema_version,
"schema_type":"update_alarm_response",
+ "vim_uuid":update_alarm_info["vim_uuid"],
"alarm_update_response":
{"correlation_id":update_alarm_info["alarm_update_request"]["correlation_id"],
"alarm_uuid":update_alarm_info["alarm_update_request"]["alarm_uuid"] \
def delete_alarm(self, delete_alarm_info):
"""Delete alarm configuration
"""
- mon_plugin = MonPlugin()
- alarm_uuid = mon_plugin.delete_alarm_configuration(delete_alarm_info)
+ access_config = None
+ access_config = self.get_vim_access_config(delete_alarm_info['vim_uuid'])
+ mon_plugin = MonPlugin(access_config)
+ alarm_uuid = mon_plugin.delete_alarm_configuration(delete_alarm_info['alarm_delete_request'])
return alarm_uuid
def publish_delete_alarm_status(self, alarm_uuid, delete_alarm_info):
msg_key = 'delete_alarm_response'
response_msg = {"schema_version":schema_version,
"schema_type":"delete_alarm_response",
+ "vim_uuid":delete_alarm_info['vim_uuid'],
"alarm_deletion_response":
{"correlation_id":delete_alarm_info["alarm_delete_request"]["correlation_id"],
"alarm_uuid":delete_alarm_info["alarm_delete_request"]["alarm_uuid"],
def verify_metric(self, metric_info):
"""Verify if metric is supported or not
"""
- mon_plugin = MonPlugin()
- metric_key_status = mon_plugin.verify_metric_support(metric_info)
+ access_config = None
+ access_config = self.get_vim_access_config(metric_info['vim_uuid'])
+ mon_plugin = MonPlugin(access_config)
+ if 'metric_create_request' in metric_info:
+ metric_key_status = mon_plugin.verify_metric_support(metric_info['metric_create_request'])
+ else:
+ metric_key_status = mon_plugin.verify_metric_support(metric_info['metric_update_request'])
return metric_key_status
def publish_create_metric_response(self, metric_info, metric_status):
msg_key = 'create_metric_response'
response_msg = {"schema_version":schema_version,
"schema_type":"create_metric_response",
- "correlation_id":metric_info['correlation_id'],
+ ##"vim_uuid":metric_info['vim_uuid'],
+ ##"correlation_id":metric_info['correlation_id'],
"metric_create_response":
{
- "metric_uuid":'0',
- "resource_uuid":metric_info['metric_create_request']['resource_uuid'],
+ ##"metric_uuid":'0',
+ ##"resource_uuid":metric_info['metric_create']['resource_uuid'],
+ ##"vim_uuid":metric_info['vim_uuid'], #May be required. TODO - Confirm
+ "correlation_id":metric_info['correlation_id'],
"status":metric_status
}
}
msg_key = 'update_metric_response'
response_msg = {"schema_version":schema_version,
"schema_type":"metric_update_response",
- "correlation_id":metric_info['correlation_id'],
+ "vim_uuid":metric_info['vim_uuid'],
"metric_update_response":
{
"metric_uuid":'0',
- "resource_uuid":metric_info['metric_create_request']['resource_uuid'],
+ "correlation_id":metric_info['correlation_id'],
+ "resource_uuid":metric_info['metric_create']['resource_uuid'],
"status":metric_status
}
}
self.producer_metrics.publish(key=msg_key, value=json.dumps(response_msg), topic=topic)
def publish_delete_metric_response(self, metric_info):
- """
+ """Publish delete metric response
"""
topic = 'metric_response'
msg_key = 'delete_metric_response'
response_msg = {"schema_version":schema_version,
"schema_type":"delete_metric_response",
+ "vim_uuid":metric_info['vim_uuid'],
"correlation_id":metric_info['correlation_id'],
"metric_name":metric_info['metric_name'],
"metric_uuid":'0',
def list_alarms(self, list_alarm_input):
"""Collect list of triggered alarms based on input
"""
- mon_plugin = MonPlugin()
- triggered_alarms = mon_plugin.get_triggered_alarms_list(list_alarm_input)
+ access_config = None
+ access_config = self.get_vim_access_config(list_alarm_input['vim_uuid'])
+ mon_plugin = MonPlugin(access_config)
+ triggered_alarms = mon_plugin.get_triggered_alarms_list(list_alarm_input['alarm_list_request'])
return triggered_alarms
msg_key = 'list_alarm_response'
response_msg = {"schema_version":schema_version,
"schema_type":"list_alarm_response",
+ "vim_type":"VMware",
+ "vim_uuid":list_alarm_input['vim_uuid'],
"correlation_id":list_alarm_input['alarm_list_request']['correlation_id'],
"list_alarm_response":triggered_alarm_list
}
#Core Add producer
self.producer_access_credentials.publish(key=msg_key, value=json.dumps(response_msg), topic=topic)
+
+ def get_vim_access_config(self, vim_uuid):
+ """Get VIM access configuration & account details from path: VIM_ACCOUNTS_FILE_PATH
+ """
+ vim_account_details = None
+ vim_account = {}
+ auth_manager = AuthManager()
+ vim_account_details = auth_manager.get_credentials(vim_uuid)
+
+ try:
+ if vim_account_details is not None:
+ vim_account['name'] = vim_account_details.name
+ vim_account['vim_tenant_name'] = vim_account_details.tenant_name
+ vim_account['vim_type'] = vim_account_details.type
+ vim_account['vim_url'] = vim_account_details.url
+ vim_account['org_user'] = vim_account_details.user
+ vim_account['org_password'] = vim_account_details.password
+ vim_account['vim_uuid'] = vim_account_details.uuid
+
+ vim_config = json.loads(vim_account_details.config)
+ vim_account['admin_username'] = vim_config['admin_username']
+ vim_account['admin_password'] = vim_config['admin_password']
+ vim_account['vrops_site'] = vim_config['vrops_site']
+ vim_account['vrops_user'] = vim_config['vrops_user']
+ vim_account['vrops_password'] = vim_config['vrops_password']
+ vim_account['vcenter_ip'] = vim_config['vcenter_ip']
+ vim_account['vcenter_port'] = vim_config['vcenter_port']
+ vim_account['vcenter_user'] = vim_config['vcenter_user']
+ vim_account['vcenter_password'] = vim_config['vcenter_password']
+
+ if vim_config['nsx_manager'] is not None:
+ vim_account['nsx_manager'] = vim_config['nsx_manager']
+ if vim_config['nsx_user'] is not None:
+ vim_account['nsx_user'] = vim_config['nsx_user']
+ if vim_config['nsx_password'] is not None:
+ vim_account['nsx_password'] = vim_config['nsx_password']
+ if vim_config['orgname'] is not None:
+ vim_account['orgname'] = vim_config['orgname']
+ except Exception as exp:
+ self.logger.error("VIM account details not sufficient: {}".format(exp))
+ return vim_account
+
"""
def main():
#log.basicConfig(filename='mon_vrops_log.log',level=log.DEBUG)
if __name__ == "__main__":
main()
"""
+
from osm_mon.core.message_bus.producer import KafkaProducer
#from core.message_bus.producer import KafkaProducer
+sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '..'))
+from osm_mon.core.database import DatabaseManager
+
try:
from cheroot.wsgi import Server as WSGIServer
from cheroot.ssl.pyopenssl import pyOpenSSLAdapter
return formated_datetime
-def get_alarm_config():
+def get_alarm_config(alarm_name):
"""
Method to get configuration parameters
Args:
Returns:
dictionary of config parameters
"""
- alarm_config = {}
+ vim_account = {}
+ database_manager = DatabaseManager()
+ vim_account_details = database_manager.get_credentials_for_alarm_name(alarm_name,'VMware')
+
try:
- xml_content = ET.parse(CONFIG_FILE)
- alarms = xml_content.getroot()
- for alarm in alarms:
- if alarm.tag == 'Access_Config':
- for param in alarm:
- alarm_config[param.tag] = param.text
+ if vim_account_details is not None:
+ vim_account['name'] = vim_account_details.name
+ vim_account['vim_tenant_name'] = vim_account_details.tenant_name
+ vim_account['vim_type'] = vim_account_details.type
+ vim_account['vim_uuid'] = vim_account_details._id
+ vim_account['vim_url'] = vim_account_details.url
+ vim_account['org_user'] = vim_account_details.user
+ vim_account['org_password'] = vim_account_details.password
+
+ vim_config = json.loads(vim_account_details.config)
+ vim_account['tenant_id'] = vim_config['tenant_id']
+ vim_account['admin_username'] = vim_config['admin_username']
+ vim_account['admin_password'] = vim_config['admin_password']
+ vim_account['vrops_site'] = vim_config['vrops_site']
+ vim_account['vrops_user'] = vim_config['vrops_user']
+ vim_account['vrops_password'] = vim_config['vrops_password']
+ vim_account['vcenter_ip'] = vim_config['vcenter_ip']
+ vim_account['vcenter_port'] = vim_config['vcenter_port']
+ vim_account['vcenter_user'] = vim_config['vcenter_user']
+ vim_account['vcenter_password'] = vim_config['vcenter_password']
+ if vim_config['nsx_manager'] is not None:
+ vim_account['nsx_manager'] = vim_config['nsx_manager']
+ if vim_config['nsx_user'] is not None:
+ vim_account['nsx_user'] = vim_config['nsx_user']
+ if vim_config['nsx_password'] is not None:
+ vim_account['nsx_password'] = vim_config['nsx_password']
+ if vim_config['orgname'] is not None:
+ vim_account['orgname'] = vim_config['orgname']
except Exception as exp:
- logger.error('Exception: {} occured while parsing config file.'.format(exp))
+ logger.error("VIM account details not sufficient: {}".format(exp))
+ return vim_account
- return alarm_config
-def get_alarm_definationID(alarm_uuid):
+def get_alarm_definationID(alarm_instance_uuid, access_config):
"""
Method to get alarm/alert defination ID
Args:
- alarm_uuid : UUID of alarm
+ alarm_instance_uuid : UUID of alarm
Returns:
alarm defination ID
"""
alarm_definationID = None
- if alarm_uuid :
+ if alarm_instance_uuid :
try:
- access_config = get_alarm_config()
+ #access_config = get_alarm_config()
headers = {'Accept': 'application/json'}
- api_url = '{}/suite-api/api/alerts/{}'.format(access_config.get('vrops_site'), alarm_uuid)
- api_response = requests.get(
- api_url,
- auth=(access_config.get('vrops_user'), access_config.get('vrops_password')),
- verify = False, headers = headers
- )
+ api_url = '{}/suite-api/api/alerts/{}'\
+ .format(access_config.get('vrops_site'), alarm_instance_uuid)
+ api_response = requests.get(api_url,
+ auth=(access_config.get('vrops_user'),\
+ access_config.get('vrops_password')),
+ verify = False,
+ headers = headers
+ )
if api_response.status_code == 200:
data = api_response.json()
if data.get("alertDefinitionId") is not None:
alarm_definationID = '-'.join(data.get("alertDefinitionId").split('-')[1:])
else:
- logger.error("Failed to get alert definition ID for alarm {}".format(alarm_uuid))
+ logger.error("Failed to get alert definition ID for alarm {}"\
+ .format(alarm_instance_uuid))
except Exception as exp:
- logger.error( "Exception occured while getting alert definition ID for alarm : {}".format(exp, alarm_uuid))
+ logger.error("Exception occured while getting alert definition ID for alarm : {}"\
+ .format(exp, alarm_instance_uuid))
return alarm_definationID
Returns:
response code
"""
- logger.info("Request:{} from:{} {} {} ".format(request, request.remote_addr, request.method, request.url))
+ logger.info("Request:{} from:{} {} {} "\
+ .format(request, request.remote_addr, request.method, request.url))
response.headers['Content-Type'] = 'application/json'
try:
postdata = json.loads(request.body.read())
notify_details = {}
- alaram_config = get_alarm_config()
+ vim_access_config = get_alarm_config(postdata.get('alertName'))
#Parse noditfy data
- notify_details['alarm_uuid'] = get_alarm_definationID(postdata.get('alertId'))
+ notify_details['vim_uuid'] = vim_access_config.get('vim_uuid')
+ notify_details['alarm_uuid'] = get_alarm_definationID(postdata.get('alertId'),\
+ vim_access_config)
notify_details['description'] = postdata.get('info')
notify_details['alarm_instance_uuid'] = alarmID
notify_details['resource_uuid'] = '-'.join(postdata.get('alertName').split('-')[1:])
- notify_details['tenant_uuid'] = alaram_config.get('tenant_id')
+ notify_details['tenant_uuid'] = vim_access_config.get('tenant_id')
notify_details['vim_type'] = "VMware"
- notify_details['severity'] = VROPS_SEVERITY_TO_OSM_MAPPING.get(postdata.get('criticality'), 'INDETERMINATE')
+ notify_details['severity'] = VROPS_SEVERITY_TO_OSM_MAPPING.get(postdata.get('criticality'),\
+ 'INDETERMINATE')
notify_details['status'] = postdata.get('status')
if postdata.get('startDate'):
notify_details['start_date_time'] = format_datetime(postdata.get('startDate'))
app = default_app()
server_names['sslwebserver'] = SSLWebServer
run(app=app,host=getfqdn(), port=8080, server='sslwebserver')
-
-
-
<impact>risk</impact>
<unit>msec</unit>
</CPU_Utilization_Above_Threshold>
- <AVERAGE_MEMORY_UTILIZATION>
+ <average_memory_utilization>
<metric_key>mem|usage_average</metric_key>
<unit>%</unit>
- </AVERAGE_MEMORY_UTILIZATION>
- <CPU_UTILIZATION>
+ </average_memory_utilization>
+ <cpu_utilization>
<metric_key>cpu|usage_average</metric_key>
<unit>%</unit>
- </CPU_UTILIZATION>
- <READ_LATENCY_0>
+ </cpu_utilization>
+ <read_latency_0>
<metric_key>virtualDisk:scsi0:0|totalReadLatency_average</metric_key>
<unit>msec</unit>
- </READ_LATENCY_0>
- <WRITE_LATENCY_0>
+ </read_latency_0>
+ <write_latency_0>
<metric_key>virtualDisk:scsi0:0|totalWriteLatency_average</metric_key>
<unit>msec</unit>
- </WRITE_LATENCY_0>
- <READ_LATENCY_1>
+ </write_latency_0>
+ <read_latency_1>
<metric_key>virtualDisk:scsi0:1|totalReadLatency_average</metric_key>
<unit>msec</unit>
- </READ_LATENCY_1>
- <WRITE_LATENCY_1>
+ </read_latency_1>
+ <write_latency_1>
<metric_key>virtualDisk:scsi0:1|totalWriteLatency_average</metric_key>
<unit>msec</unit>
- </WRITE_LATENCY_1>
- <PACKETS_DROPPED_0>
+ </write_latency_1>
+ <packets_dropped_0>
<metric_key>net:4000|dropped</metric_key>
<unit>nos</unit>
- </PACKETS_DROPPED_0>
- <PACKETS_DROPPED_1>
+ </packets_dropped_0>
+ <packets_dropped_1>
<metric_key>net:4001|dropped</metric_key>
<unit>nos</unit>
- </PACKETS_DROPPED_1>
- <PACKETS_DROPPED_2>
+ </packets_dropped_1>
+ <packets_dropped_2>
<metric_key>net:4002|dropped</metric_key>
<unit>nos</unit>
- </PACKETS_DROPPED_2>
- <PACKETS_RECEIVED>
+ </packets_dropped_2>
+ <packets_received>
<metric_key>net:Aggregate of all instances|packetsRxPerSec</metric_key>
<unit>nos</unit>
- </PACKETS_RECEIVED>
- <PACKETS_SENT>
+ </packets_received>
+ <packets_sent>
<metric_key>net:Aggregate of all instances|packetsTxPerSec</metric_key>
<unit>nos</unit>
- </PACKETS_SENT>
+ </packets_sent>
<Access_Config>
<vrops_site>https://192.169.241.123</vrops_site>
<vrops_user>admin</vrops_user>
<vcloud-site>https://192.169.241.15</vcloud-site>
<admin_username>admin</admin_username>
<admin_password>vmware</admin_password>
- <nsx_manager>https://192.169.241.104</nsx_manager>
+ <nsx_manager>https://192.169.241.181</nsx_manager>
<nsx_user>admin</nsx_user>
<nsx_password>VMware1!</nsx_password>
<vcenter_ip>192.169.241.13</vcenter_ip>
<orgname>Org2</orgname>
<tenant_id>Org2</tenant_id>
</Access_Config>
-</alarmsDefaultConfig>
\ No newline at end of file
+</alarmsDefaultConfig>
from osm_mon.plugins.vRealiseOps import mon_plugin_vrops as monPlugin
-from pyvcloud.vcd.client import Client
+from pyvcloud.vcd.client import Client,BasicLoginCredentials
class TestMonPlugin(unittest.TestCase):
def setUp(self):
"""Setup the tests for Mon Plugin class methods"""
super(TestMonPlugin, self).setUp()
- self.mon_plugin = monPlugin.MonPlugin()
+
+ self.m_vim_access_config = {'vrops_site':'abc',
+ 'vrops_user':'user',
+ 'vrops_password':'passwd',
+ 'vim_url':'vcd_url',
+ 'admin_username':'admin',
+ 'admin_password':'admin_passwd',
+ 'vim_uuid':'1',
+ 'tenant_id':'org_vdc_1'}
+ self.mon_plugin = monPlugin.MonPlugin(self.m_vim_access_config)
# create client object
self.vca = Client('test', verify_ssl_certs=False)
# create session
self.session = requests.Session()
+
def test_get_default_Params_valid_metric_alarm_name(self):
"""Test get default params method"""
# Mock valid symptom params and mock responses
symptom_param = {'threshold_value': 0, 'cancel_cycles': 1, 'adapter_kind_key': 'VMWARE',
'resource_kind_key': 'VirtualMachine', 'severity': 'CRITICAL',
- 'symptom_name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
+ 'symptom_name':\
+ 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
'operation': 'GT', 'wait_cycles': 1, 'metric_key': 'cpu|usage_average'}
m_post.return_value.status_code = 201
m_post.return_value.content = \
'{"id":"SymptomDefinition-351c23b4-bc3c-4c7b-b4af-1ad90a673c5d",\
"name":"CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
- "adapterKindKey":"VMWARE","resourceKindKey":"VirtualMachine","waitCycles":1,\
- "cancelCycles":1,"state":{"severity":"CRITICAL","condition":{"type":"CONDITION_HT",\
- "key":"cpu|usage_average","operator":"GT","value":"0.0","valueType":"NUMERIC",\
+ "adapterKindKey":"VMWARE","resourceKindKey":"VirtualMachine",\
+ "waitCycles":1,"cancelCycles":1,\
+ "state":{"severity":"CRITICAL","condition":{"type":"CONDITION_HT",\
+ "key":"cpu|usage_average","operator":"GT","value":"0.0",\
+ "valueType":"NUMERIC",\
"instanced":false,"thresholdType":"STATIC"}}}'
expected_return = "SymptomDefinition-351c23b4-bc3c-4c7b-b4af-1ad90a673c5d"
# Mock valid symptom params and invalid mock responses
symptom_param = {'threshold_value': 0, 'cancel_cycles': 1, 'adapter_kind_key': 'VMWARE',
'resource_kind_key': 'VirtualMachine', 'severity': 'CRITICAL',
- 'symptom_name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
+ 'symptom_name':\
+ 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
'operation': 'GT', 'wait_cycles': 1, 'metric_key': 'cpu|usage_average'}
m_post.return_value.status_code = 404
# Mock valid symptom params and invalid mock responses
symptom_param = {'threshold_value': 0, 'cancel_cycles': 1, 'adapter_kind_key': 'VMWARE',
'resource_kind_key': 'VirtualMachine', 'severity': 'CRITICAL',
- 'symptom_name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
+ 'symptom_name':\
+ 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
'operation': 'GT', 'metric_key': 'cpu|usage_average'}
expected_return = None
"""Test create alarm definition method-valid response"""
# Mock valid alarm params and mock responses
- alarm_param = {'description': 'CPU_Utilization_Above_Threshold', 'cancelCycles': 1, 'subType': 19,
- 'waitCycles': 1, 'severity': 'CRITICAL', 'impact': 'risk', 'adapterKindKey': 'VMWARE',
+ alarm_param = {'description': 'CPU_Utilization_Above_Threshold', 'cancelCycles': 1,
+ 'subType': 19, 'waitCycles': 1,
+ 'severity': 'CRITICAL', 'impact': 'risk', 'adapterKindKey': 'VMWARE',
'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
'resourceKindKey': 'VirtualMachine', 'type': 16,
- 'symptomDefinitionId': 'SymptomDefinition-25278b06-bff8-4409-a141-9b4e064235df'}
+ 'symptomDefinitionId':\
+ 'SymptomDefinition-25278b06-bff8-4409-a141-9b4e064235df'}
m_post.return_value.status_code = 201
m_post.return_value.content = \
'{"id":"AlertDefinition-d4f21e4b-770a-45d6-b298-022eaf489115",\
"name":"CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
"description":"CPU_Utilization_Above_Threshold","adapterKindKey":"VMWARE",\
- "resourceKindKey":"VirtualMachine","waitCycles":1,"cancelCycles":1,"type":16,\
- "subType":19,"states":[{"severity":"CRITICAL","base-symptom-set":{"type":"SYMPTOM_SET",\
+ "resourceKindKey":"VirtualMachine","waitCycles":1,"cancelCycles":1,\
+ "type":16,"subType":19,\
+ "states":[{"severity":"CRITICAL","base-symptom-set":{"type":"SYMPTOM_SET",\
"relation":"SELF","aggregation":"ALL","symptomSetOperator":"AND",\
- "symptomDefinitionIds":["SymptomDefinition-25278b06-bff8-4409-a141-9b4e064235df"]},\
+ "symptomDefinitionIds":\
+ ["SymptomDefinition-25278b06-bff8-4409-a141-9b4e064235df"]},\
"impact":{"impactType":"BADGE","detail":"risk"}}]}'
expected_return = "AlertDefinition-d4f21e4b-770a-45d6-b298-022eaf489115"
"""Test create alarm definition method-invalid response"""
# Mock valid alarm params and mock responses
- alarm_param = {'description': 'CPU_Utilization_Above_Threshold', 'cancelCycles': 1, 'subType': 19,
- 'waitCycles': 1, 'severity': 'CRITICAL', 'impact': 'risk', 'adapterKindKey': 'VMWARE',
+ alarm_param = {'description': 'CPU_Utilization_Above_Threshold', 'cancelCycles': 1,
+ 'subType': 19, 'waitCycles': 1,
+ 'severity': 'CRITICAL', 'impact': 'risk', 'adapterKindKey': 'VMWARE',
'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
'resourceKindKey': 'VirtualMachine', 'type': 16,
- 'symptomDefinitionId': 'SymptomDefinition-25278b06-bff8-4409-a141-9b4e064235df'}
+ 'symptomDefinitionId':\
+ 'SymptomDefinition-25278b06-bff8-4409-a141-9b4e064235df'}
m_post.return_value.status_code = 404
m_post.return_value.content = '404 Not Found'
"""Test create alarm definition method-incorrect data"""
# Mock incorrect alarm param
- alarm_param = {'description': 'CPU_Utilization_Above_Threshold', 'cancelCycles': 1, 'subType': 19,
- 'waitCycles': 1, 'severity': 'CRITICAL', 'impact': 'risk', 'adapterKindKey': 'VMWARE',
- 'symptomDefinitionId': 'SymptomDefinition-25278b06-bff8-4409-a141-9b4e064235df', 'type': 16}
+ alarm_param = {'description': 'CPU_Utilization_Above_Threshold', 'cancelCycles': 1,
+ 'subType': 19, 'waitCycles': 1, 'type': 16,
+ 'severity': 'CRITICAL', 'impact': 'risk', 'adapterKindKey': 'VMWARE',
+ 'symptomDefinitionId':\
+ 'SymptomDefinition-25278b06-bff8-4409-a141-9b4e064235df'}
expected_return = None
# call create symptom method under test
self.assertEqual(expected_return, actual_return)
+ @mock.patch.object(monPlugin.DatabaseManager, 'save_alarm')
@mock.patch.object(monPlugin.MonPlugin, 'create_alarm_notification_rule')
@mock.patch.object(monPlugin.MonPlugin, 'get_vm_resource_id')
@mock.patch.object(monPlugin.MonPlugin, 'get_vm_moref_id')
m_create_alarm_definition,\
m_get_vm_moref_id,\
m_get_vm_resource_id,\
- m_create_alarm_notification_rule):
+ m_create_alarm_notification_rule,\
+ m_save_alarm):
+
"""Test configure alarm valid request creating alarm"""
#Mock input configuration dictionary
'alarm_name': 'CPU_Utilization_Above_Threshold',
'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
- 'statistic': 'AVERAGE', 'metric_name': 'CPU_UTILIZATION',
+ 'statistic': 'AVERAGE', 'metric_name': 'cpu_utilization',
+ 'vdu_name':'vdu1','vnf_member_index':'index1','ns_id':'nsd1',
'operation': 'GT', 'unit': '%',
'description': 'CPU_Utilization_Above_Threshold'}
'adapter_kind_key': 'VMWARE',
'resource_kind_key': 'VirtualMachine',
'severity': 'CRITICAL',
- 'symptom_name':'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
+ 'symptom_name':\
+ 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
'operation': 'GT',
'wait_cycles': 1,
'metric_key': 'cpu|usage_average'}
'impact': 'risk', 'adapterKindKey': 'VMWARE',
'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
'resourceKindKey': 'VirtualMachine',
- 'symptomDefinitionId': 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804',
+ 'symptomDefinitionId':\
+ 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804',
'type': 16}
vm_moref_id = 'vm-6626'
#set mocked function return values
m_get_alarm_defination_by_name.return_value = []
m_create_symptom.return_value = 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804'
- m_create_alarm_definition.return_value = 'AlertDefinition-0f3cdcb3-4e1b-4a0b-86d0-66d4b3f65220'
+ m_create_alarm_definition.return_value =\
+ 'AlertDefinition-0f3cdcb3-4e1b-4a0b-86d0-66d4b3f65220'
m_get_vm_moref_id.return_value = vm_moref_id
m_get_vm_resource_id.return_value = 'ac87622f-b761-40a0-b151-00872a2a456e'
m_create_alarm_notification_rule.return_value = 'f37900e7-dd01-4383-b84c-08f519530d71'
m_create_alarm_definition.assert_called_with(alarm_params)
m_get_vm_moref_id.assert_called_with(config_dict['resource_uuid'])
m_get_vm_resource_id.assert_called_with(vm_moref_id)
- m_create_alarm_notification_rule.assert_called_with(vrops_alarm_name, alarm_def, resource_id)
+ m_create_alarm_notification_rule.assert_called_with(vrops_alarm_name,\
+ alarm_def,\
+ resource_id)
+ m_save_alarm.assert_called_with(alarm_def_uuid,'1',
+ config_dict['threshold_value'],
+ config_dict['operation'],
+ config_dict['metric_name'],
+ config_dict['vdu_name'],
+ config_dict['vnf_member_index'],
+ config_dict['ns_id'])
#Verify return value with expected value of alarm_def_uuid
self.assertEqual(return_value, alarm_def_uuid)
+ @mock.patch.object(monPlugin.DatabaseManager, 'save_alarm')
@mock.patch.object(monPlugin.MonPlugin, 'create_alarm_notification_rule')
@mock.patch.object(monPlugin.MonPlugin, 'get_vm_resource_id')
@mock.patch.object(monPlugin.MonPlugin, 'get_vm_moref_id')
m_create_alarm_definition,\
m_get_vm_moref_id,\
m_get_vm_resource_id,\
- m_create_alarm_notification_rule):
+ m_create_alarm_notification_rule,\
+ m_save_alarm):
"""Test configure alarm invalid test: for invalid alarm name"""
#Mock input configuration dictionary
return_value = self.mon_plugin.configure_alarm(config_dict)
#Verify that mocked methods are called with correct parameters
- m_get_default_Params.assert_called_once()
+ m_get_default_Params.assert_called_with(config_dict['alarm_name'])
m_get_alarm_defination_by_name.assert_not_called()
m_create_symptom.assert_not_called()
m_create_alarm_definition.assert_not_called()
m_get_vm_moref_id.assert_not_called()
m_get_vm_resource_id.assert_not_called()
m_create_alarm_notification_rule.assert_not_called()
+ m_save_alarm.assert_not_called()
#Verify return value with expected value i.e. None
self.assertEqual(return_value, alarm_def_uuid)
+ @mock.patch.object(monPlugin.DatabaseManager, 'save_alarm')
@mock.patch.object(monPlugin.MonPlugin, 'create_alarm_notification_rule')
@mock.patch.object(monPlugin.MonPlugin, 'get_vm_resource_id')
@mock.patch.object(monPlugin.MonPlugin, 'get_vm_moref_id')
m_create_alarm_definition,\
m_get_vm_moref_id,\
m_get_vm_resource_id,\
- m_create_alarm_notification_rule):
+ m_create_alarm_notification_rule,\
+ m_save_alarm):
"""Test configure alarm invalid test: for invalid metric name"""
#Mock input configuration dictionary
m_get_vm_moref_id.assert_not_called()
m_get_vm_resource_id.assert_not_called()
m_create_alarm_notification_rule.assert_not_called()
+ m_save_alarm.assert_not_called()
#Verify return value with expected value i.e. None
self.assertEqual(return_value, alarm_def_uuid)
+
+ @mock.patch.object(monPlugin.DatabaseManager, 'save_alarm')
@mock.patch.object(monPlugin.MonPlugin, 'create_alarm_notification_rule')
@mock.patch.object(monPlugin.MonPlugin, 'get_vm_resource_id')
@mock.patch.object(monPlugin.MonPlugin, 'get_vm_moref_id')
m_create_alarm_definition,\
m_get_vm_moref_id,\
m_get_vm_resource_id,\
- m_create_alarm_notification_rule):
+ m_create_alarm_notification_rule,\
+ m_save_alarm):
"""Test configure alarm invalid test: for alarm that already exists"""
#Mock input configuration dictionary
m_get_vm_moref_id.assert_not_called()
m_get_vm_resource_id.assert_not_called()
m_create_alarm_notification_rule.assert_not_called()
-
+ m_save_alarm.assert_not_called()
#Verify return value with expected value of alarm_def_uuid
self.assertEqual(return_value, alarm_def_uuid)
+ @mock.patch.object(monPlugin.DatabaseManager, 'save_alarm')
@mock.patch.object(monPlugin.MonPlugin, 'create_alarm_notification_rule')
@mock.patch.object(monPlugin.MonPlugin, 'get_vm_resource_id')
@mock.patch.object(monPlugin.MonPlugin, 'get_vm_moref_id')
m_create_alarm_definition,\
m_get_vm_moref_id,\
m_get_vm_resource_id,\
- m_create_alarm_notification_rule):
+ m_create_alarm_notification_rule,\
+ m_save_alarm):
"""Test configure alarm: failed to create symptom"""
#Mock input configuration dictionary
'adapter_kind_key': 'VMWARE',
'resource_kind_key': 'VirtualMachine',
'severity': 'CRITICAL',
- 'symptom_name':'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
+ 'symptom_name':\
+ 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
'operation': 'GT',
'wait_cycles': 1,
'metric_key': 'cpu|usage_average'}
m_get_vm_moref_id.assert_not_called()
m_get_vm_resource_id.assert_not_called()
m_create_alarm_notification_rule.assert_not_called()
+ m_save_alarm.assert_not_called()
#Verify return value with expected value of alarm_def_uuid
self.assertEqual(return_value, alarm_def_uuid)
+ @mock.patch.object(monPlugin.DatabaseManager, 'save_alarm')
@mock.patch.object(monPlugin.MonPlugin, 'create_alarm_notification_rule')
@mock.patch.object(monPlugin.MonPlugin, 'get_vm_resource_id')
@mock.patch.object(monPlugin.MonPlugin, 'get_vm_moref_id')
m_create_alarm_definition,\
m_get_vm_moref_id,\
m_get_vm_resource_id,\
- m_create_alarm_notification_rule):
+ m_create_alarm_notification_rule,\
+ m_save_alarm):
"""Test configure alarm: failed to create alert in vROPs"""
#Mock input configuration dictionary
'adapter_kind_key': 'VMWARE',
'resource_kind_key': 'VirtualMachine',
'severity': 'CRITICAL',
- 'symptom_name':'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
+ 'symptom_name':\
+ 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
'operation': 'GT',
'wait_cycles': 1,
'metric_key': 'cpu|usage_average'}
'impact': 'risk', 'adapterKindKey': 'VMWARE',
'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
'resourceKindKey': 'VirtualMachine',
- 'symptomDefinitionId': 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804',
+ 'symptomDefinitionId':\
+ 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804',
'type': 16}
vrops_alarm_name = 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
m_get_vm_moref_id.assert_not_called()
m_get_vm_resource_id.assert_not_called()
m_create_alarm_notification_rule.assert_not_called()
+ m_save_alarm.assert_not_called()
#Verify return value with expected value of alarm_def_uuid
self.assertEqual(return_value, alarm_def_uuid)
+ @mock.patch.object(monPlugin.DatabaseManager, 'save_alarm')
@mock.patch.object(monPlugin.MonPlugin, 'create_alarm_notification_rule')
@mock.patch.object(monPlugin.MonPlugin, 'get_vm_resource_id')
@mock.patch.object(monPlugin.MonPlugin, 'get_vm_moref_id')
m_create_alarm_definition,\
m_get_vm_moref_id,\
m_get_vm_resource_id,\
- m_create_alarm_notification_rule):
+ m_create_alarm_notification_rule,\
+ m_save_alarm):
"""Test configure alarm: failed to get vm_moref_id"""
#Mock input configuration dictionary
'adapter_kind_key': 'VMWARE',
'resource_kind_key': 'VirtualMachine',
'severity': 'CRITICAL',
- 'symptom_name':'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
+ 'symptom_name':\
+ 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
'operation': 'GT',
'wait_cycles': 1,
'metric_key': 'cpu|usage_average'}
'impact': 'risk', 'adapterKindKey': 'VMWARE',
'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
'resourceKindKey': 'VirtualMachine',
- 'symptomDefinitionId': 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804',
+ 'symptomDefinitionId':\
+ 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804',
'type': 16}
vrops_alarm_name = 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
#set mocked function return values
m_get_alarm_defination_by_name.return_value = []
m_create_symptom.return_value = 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804'
- m_create_alarm_definition.return_value = 'AlertDefinition-0f3cdcb3-4e1b-4a0b-86d0-66d4b3f65220'
+ m_create_alarm_definition.return_value =\
+ 'AlertDefinition-0f3cdcb3-4e1b-4a0b-86d0-66d4b3f65220'
m_get_vm_moref_id.return_value = None
#Call configure_alarm method under test
m_get_vm_moref_id.assert_called_with(config_dict['resource_uuid'])
m_get_vm_resource_id.assert_not_called()
m_create_alarm_notification_rule.assert_not_called()
+ m_save_alarm.assert_not_called()
#Verify return value with expected value of alarm_def_uuid
self.assertEqual(return_value, alarm_def_uuid)
+ @mock.patch.object(monPlugin.DatabaseManager, 'save_alarm')
@mock.patch.object(monPlugin.MonPlugin, 'create_alarm_notification_rule')
@mock.patch.object(monPlugin.MonPlugin, 'get_vm_resource_id')
@mock.patch.object(monPlugin.MonPlugin, 'get_vm_moref_id')
m_create_alarm_definition,\
m_get_vm_moref_id,\
m_get_vm_resource_id,\
- m_create_alarm_notification_rule):
+ m_create_alarm_notification_rule,\
+ m_save_alarm):
"""Test configure alarm: failed to get vm resource_id"""
#Mock input configuration dictionary
'adapter_kind_key': 'VMWARE',
'resource_kind_key': 'VirtualMachine',
'severity': 'CRITICAL',
- 'symptom_name':'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
+ 'symptom_name':\
+ 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
'operation': 'GT',
'wait_cycles': 1,
'metric_key': 'cpu|usage_average'}
'impact': 'risk', 'adapterKindKey': 'VMWARE',
'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
'resourceKindKey': 'VirtualMachine',
- 'symptomDefinitionId': 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804',
+ 'symptomDefinitionId':\
+ 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804',
'type': 16}
vrops_alarm_name = 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
#set mocked function return values
m_get_alarm_defination_by_name.return_value = []
m_create_symptom.return_value = 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804'
- m_create_alarm_definition.return_value = 'AlertDefinition-0f3cdcb3-4e1b-4a0b-86d0-66d4b3f65220'
+ m_create_alarm_definition.return_value =\
+ 'AlertDefinition-0f3cdcb3-4e1b-4a0b-86d0-66d4b3f65220'
m_get_vm_moref_id.return_value = vm_moref_id
m_get_vm_resource_id.return_value = None
+ m_save_alarm.assert_not_called()
#Call configure_alarm method under test
return_value = self.mon_plugin.configure_alarm(config_dict)
self.assertEqual(return_value, alarm_def_uuid)
+ @mock.patch.object(monPlugin.DatabaseManager, 'save_alarm')
@mock.patch.object(monPlugin.MonPlugin, 'create_alarm_notification_rule')
@mock.patch.object(monPlugin.MonPlugin, 'get_vm_resource_id')
@mock.patch.object(monPlugin.MonPlugin, 'get_vm_moref_id')
m_create_alarm_definition,\
m_get_vm_moref_id,\
m_get_vm_resource_id,\
- m_create_alarm_notification_rule):
+ m_create_alarm_notification_rule,\
+ m_save_alarm):
"""Test configure alarm: failed to create alarm notification rule"""
#Mock input configuration dictionary
'adapter_kind_key': 'VMWARE',
'resource_kind_key': 'VirtualMachine',
'severity': 'CRITICAL',
- 'symptom_name':'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
+ 'symptom_name':\
+ 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
'operation': 'GT',
'wait_cycles': 1,
'metric_key': 'cpu|usage_average'}
'impact': 'risk', 'adapterKindKey': 'VMWARE',
'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
'resourceKindKey': 'VirtualMachine',
- 'symptomDefinitionId': 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804',
+ 'symptomDefinitionId':\
+ 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804',
'type': 16}
vrops_alarm_name = 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
#set mocked function return values
m_get_alarm_defination_by_name.return_value = []
m_create_symptom.return_value = 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804'
- m_create_alarm_definition.return_value = 'AlertDefinition-0f3cdcb3-4e1b-4a0b-86d0-66d4b3f65220'
+ m_create_alarm_definition.return_value =\
+ 'AlertDefinition-0f3cdcb3-4e1b-4a0b-86d0-66d4b3f65220'
m_get_vm_moref_id.return_value = vm_moref_id
m_get_vm_resource_id.return_value = 'ac87622f-b761-40a0-b151-00872a2a456e'
m_create_alarm_notification_rule.return_value = None
m_get_vm_moref_id.assert_called_with(config_dict['resource_uuid'])
m_get_vm_resource_id.assert_called_with(vm_moref_id)
m_create_alarm_notification_rule.assert_called_with(vrops_alarm_name, alarm_def, resource_id)
+ m_save_alarm.assert_not_called()
#Verify return value with expected value of alarm_def_uuid
self.assertEqual(return_value, alarm_def_uuid)
"description":"CPU_Utilization_Above_Threshold",\
"adapterKindKey":"VMWARE","resourceKindKey":"VirtualMachine",\
"waitCycles":1,"cancelCycles":1,"type":16,"subType":19,\
- "states":[{"severity":"CRITICAL","base-symptom-set":{"type":"SYMPTOM_SET",\
- "relation":"SELF","aggregation":"ALL","symptomSetOperator":"AND",\
- "symptomDefinitionIds":["SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278"]},\
+ "states":[{"severity":"CRITICAL","base-symptom-set":\
+ {"type":"SYMPTOM_SET","relation":"SELF",\
+ "aggregation":"ALL","symptomSetOperator":"AND","symptomDefinitionIds":\
+ ["SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278"]},\
"impact":{"impactType":"BADGE","detail":"risk"}}]}'
- expected_alarm_details = {'adapter_kind': 'VMWARE',
- 'symptom_definition_id': 'SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278',
- 'alarm_name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
- 'alarm_id': 'AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444d',
- 'resource_kind': 'VirtualMachine', 'type': 16, 'sub_type': 19}
+ expected_alarm_details = {'adapter_kind': 'VMWARE','symptom_definition_id':\
+ 'SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278',
+ 'alarm_name':\
+ 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
+ 'alarm_id': 'AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444d',
+ 'resource_kind': 'VirtualMachine', 'type': 16, 'sub_type': 19}
expected_alarm_details_json = {'states':
[{'impact':
'aggregation':'ALL', 'symptomSetOperator': 'AND'}}],
'adapterKindKey': 'VMWARE',
'description': 'CPU_Utilization_Above_Threshold',
- 'type': 16, 'cancelCycles': 1, 'resourceKindKey': 'VirtualMachine',
+ 'type': 16, 'cancelCycles': 1,
+ 'resourceKindKey': 'VirtualMachine',
'subType': 19, 'waitCycles': 1,
'id': 'AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444d',
- 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'}
+ 'name':\
+ 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'}
#Call get_alarm_defination_details method under test
alarm_details_json, alarm_details = self.mon_plugin.get_alarm_defination_details(alarm_uuid)
@mock.patch.object(monPlugin.requests, 'get')
- # @unittest.skip("NEEDS FIX")
def test_get_alarm_defination_by_name_no_valid_alarm_found(self, m_get):
"""Test get_alarm_defination_by_name: With no valid alarm found in returned list"""
#Verify that mocked method is called with required parameters
m_get_symptom_defination_details.assert_called_with(symptom_defination_id)
- m_put.assert_called()
+ #m_put.assert_called_with(symptom_defination_id,new_alarm_config)
#Verify return value with expected value
self.assertEqual(symptom_defination_id, symptom_uuid)
'schema_version': 1.0, 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',\
'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef', \
'schema_type': 'read_metric_data_request', 'vim_type': 'VMware', \
- 'collection_unit': 'HR'}
+ 'collection_unit': 'HR', 'vim_uuid':'1'}
# mock return value
m_get_default_Params.return_value = {'metric_key': 'cpu|usage_average', 'unit': '%'}
'schema_version': 1.0, 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',\
'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef', \
'schema_type': 'read_metric_data_request', 'vim_type': 'VMware', \
- 'collection_unit': 'HR'}
+ 'collection_unit': 'HR', 'vim_uuid':'1'}
# mock return value
m_get_default_Params.return_value = {'metric_key': 'cpu|usage_average', 'unit': '%'}
expected_return = {'metric_name': 'CPU_UTILIZATION', 'metric_uuid': '0',
'schema_version': '1.0',
'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
- 'correlation_id': u'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
+ 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
'metrics_data': {'time_series': [], 'metrics_series': []},
- 'schema_type': 'read_metric_data_response', 'tenant_uuid': None,
- 'unit': '%'}
+ 'schema_type': 'read_metric_data_response',
+ 'unit': '%', 'vim_uuid':'1'}
- # call get matrics data method under test
+ # call get metrics data method under test
actual_return = self.mon_plugin.get_metrics_data(metrics)
# verify that mocked method is called
m_get):
"""Test get metrics data of resource method invalid metric name"""
- metrics = {'collection_period': 1, 'metric_name': 'INVALID_METRIC', 'metric_uuid': None, \
- 'schema_version': 1.0, 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',\
- 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef', \
- 'schema_type': 'read_metric_data_request', 'vim_type': 'VMware', \
- 'collection_unit': 'HR'}
+ metrics = {'collection_period': 1, 'metric_name': 'invalid_metric', 'metric_uuid': None,
+ 'schema_version': 1.0,
+ 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
+ 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
+ 'schema_type': 'read_metric_data_request', 'vim_type': 'VMware',
+ 'collection_unit': 'HR', 'vim_uuid':'1'}
# mock return value
m_get_default_Params.return_value = {} # returns empty dict
- expected_return = {'metric_name': 'INVALID_METRIC', 'metric_uuid': '0',
- 'schema_version': '1.0',
- 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
- 'correlation_id': u'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
+ expected_return = {'metric_name': 'invalid_metric', 'metric_uuid': '0','vim_uuid': '1',
+ 'schema_version': '1.0','resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
+ 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
'metrics_data': {'time_series': [], 'metrics_series': []},
- 'schema_type': 'read_metric_data_response', 'tenant_uuid': None,
- 'unit': None}
+ 'schema_type': 'read_metric_data_response','unit': None}
# call get matrics data method under test
actual_return = self.mon_plugin.get_metrics_data(metrics)
m_get):
"""Test get metrics data method negative scenario- invalid resource id"""
- metrics = {'collection_period': 1, 'metric_name': 'CPU_UTILIZATION', 'metric_uuid': None, \
+ metrics = {'collection_period': 1, 'metric_name': 'cpu_utilization', 'metric_uuid': None, \
'schema_version': 1.0, 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',\
'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef', \
'schema_type': 'read_metric_data_request', 'vim_type': 'VMware', \
- 'collection_unit': 'HR'}
+ 'collection_unit': 'HR', 'vim_uuid':'1'}
# mock return value
m_get_default_Params.return_value = {'metric_key': 'cpu|usage_average', 'unit': '%'}
m_get_vm_moref_id.return_value = None
- expected_return = {'metric_name': 'CPU_UTILIZATION', 'metric_uuid': '0',
+ expected_return = {'metric_name': 'cpu_utilization', 'metric_uuid': '0',
'schema_version': '1.0',
'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
- 'correlation_id': u'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
+ 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
'metrics_data': {'time_series': [], 'metrics_series': []},
- 'schema_type': 'read_metric_data_response', 'tenant_uuid': None,
- 'unit': '%'}
+ 'schema_type': 'read_metric_data_response',
+ 'unit': '%', 'vim_uuid':'1'}
# call get matrics data method under test
actual_return = self.mon_plugin.get_metrics_data(metrics)
'schema_version': 1.0, 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',\
'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef', \
'schema_type': 'read_metric_data_request', 'vim_type': 'VMware', \
- 'collection_unit': 'HR'}
+ 'collection_unit': 'HR', 'vim_uuid':'1'}
# mock return value
m_get_default_Params.return_value = {'metric_key': 'cpu|usage_average', 'unit': '%'}
expected_return = {'metric_name': 'CPU_UTILIZATION', 'metric_uuid': '0',
'schema_version': '1.0',
'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
- 'correlation_id': u'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
+ 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
'metrics_data': {'time_series': [], 'metrics_series': []},
- 'schema_type': 'read_metric_data_response', 'tenant_uuid': None,
- 'unit': '%'}
+ 'schema_type': 'read_metric_data_response',
+ 'unit': '%', 'vim_uuid':'1'}
# call get matrics data method under test
actual_return = self.mon_plugin.get_metrics_data(metrics)
m_get_default_Params.assert_called_with(metrics['metric_name'])
m_get_vm_moref_id.assert_called_with(metrics['resource_uuid'])
m_get_vm_resource_id.assert_called()
+ m_get_vm_resource_id.assert_called_with('Invalid-vm-6626')
m_get.assert_not_called()
# verify return value with expected value
alarm_details = {'symptom_definition_id': 'SymptomDefinition-47c88675-bea8-436a-bb41-\
8d2231428f44', 'alarm_name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-\
a91c-8c19d2', 'alarm_id': 'AlertDefinition-f1163767-6eac-438f-8e60-\
- a7a867257e14', 'resource_kind': u'VirtualMachine', 'type': 16}
+ a7a867257e14', 'resource_kind': 'VirtualMachine', 'type': 16}
m_get_alarm_defination_details.return_value = (alarm_details_json, alarm_details)
m_update_symptom_defination.return_value = 'SymptomDefinition-47c88675-bea8-436a-bb41-\
8d2231428f44'
alarm_details = {'symptom_definition_id': 'SymptomDefinition-47c88675-bea8-436a-bb41-\
8d2231428f44', 'alarm_name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-\
a91c-8c19d2', 'alarm_id': 'AlertDefinition-f1163767-6eac-438f-8e60-\
- a7a867257e14', 'resource_kind': u'VirtualMachine', 'type': 16}
+ a7a867257e14', 'resource_kind': 'VirtualMachine', 'type': 16}
m_get_alarm_defination_details.return_value = (alarm_details_json, alarm_details)
m_update_symptom_defination.return_value = 'SymptomDefinition-47c88675-bea8-436a-bb41-\
8d2231428f44'
alarm_details = {'symptom_definition_id': 'Invalid-47c88675-bea8-436a-bb41-\
8d2231428f44', 'alarm_name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-\
a91c-8c19d2', 'alarm_id': 'AlertDefinition-f1163767-6eac-438f-8e60-\
- a7a867257e14', 'resource_kind': u'VirtualMachine', 'type': 16}
+ a7a867257e14', 'resource_kind': 'VirtualMachine', 'type': 16}
m_get_alarm_defination_details.return_value = (alarm_details_json, alarm_details)
expected_return = m_update_symptom_defination.return_value = None
"""Test verify metric support method for supported metric"""
# mock return value
- metric_info = {'metric_unit': '%', 'metric_name': 'CPU_UTILIZATION',
+ metric_info = {'metric_unit': '%', 'metric_name': 'cpu_utilization',
'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4'}
m_get_default_Params.return_value = {'metric_key': 'cpu|usage_average', 'unit': '%'}
expected_return = True #supported metric returns True
# verify that mocked method is called
m_get_default_Params.assert_called_with(metric_info['metric_name'])
+ #m_get_default_Params.assert_called_with(metric_info)
# verify return value with expected value
self.assertEqual(expected_return, actual_return)
"""Test verify metric support method for un-supported metric"""
# mock return value
- metric_info = {'metric_unit': '%', 'metric_name': 'INVALID_METRIC',
+ metric_info = {'metric_unit': '%', 'metric_name': 'invalid_metric',
'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4'}
m_get_default_Params.return_value = {}
expected_return = False #supported metric returns True
"""Test verify metric support method for supported metric with mismatched unit"""
# mock return value
- metric_info = {'metric_unit': '', 'metric_name': 'INVALID_METRIC',
+ metric_info = {'metric_unit': '', 'metric_name': 'invalid_metric',
'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4'}
m_get_default_Params.return_value = {'metric_key': 'cpu|usage_average', 'unit': '%'}
expected_return = True #supported metric returns True
},\
"identifier": "ac87622f-b761-40a0-b151-00872a2a456e"\
}\
- ]\
}'
# call get_vm_resource_id method under test
actual_return = self.mon_plugin.get_vm_resource_id(vm_moref_id)
# verify that mocked method is called
- m_get.assert_called()
+ #m_get.assert_called
# verify return value with expected value
self.assertEqual(expected_return, actual_return)
# verify that mocked method is called
m_connect_as_admin.assert_called_with()
- m_get.assert_called()
# verify return value with expected value
self.assertEqual(expected_return, actual_return)
<vmext:VmVimInfo>\
<vmext:VmVimObjectRef>\
<vmext:VimServerRef type="application/vnd.vmware.admin.vmwvirtualcenter+xml"/>\
- <vmext:MoRef>vm-!!6626</vmext:MoRef>\
+ <vmext:MoRef>vm-6626</vmext:MoRef>\
<vmext:VimObjectType>VIRTUAL_MACHINE</vmext:VimObjectType>\
- </vmext:\
</vmext:VmVimInfo>\
</VCloudExtension>\
</Vm>\
actual_return = self.mon_plugin.connect_as_admin()
# verify that mocked method is called
- m_client.assert_called()
- m_set_credentials.assert_called()
+ m_client.assert_called_with(self.m_vim_access_config['vim_url'],
+ verify_ssl_certs=False)
# verify return value with expected value
self.assertEqual(expected_return, actual_return)
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)),"..","..",".."))
from osm_mon.plugins.vRealiseOps import plugin_receiver as monPluginRec
+from osm_mon.core.database import VimCredentials
class Message(object):
"""Setup the tests for plugin_receiver class methods"""
super(TestPluginReceiver, self).setUp()
self.plugin_receiver = monPluginRec.PluginReceiver()
- #self.mon_plugin = monPlugin.MonPlugin()
@mock.patch.object(monPluginRec.PluginReceiver, 'publish_create_alarm_status')
@mock.patch.object(monPluginRec.PluginReceiver, 'create_alarm')
- def test_consume_create_alarm_request_key(self, m_create_alarm, m_publish_create_alarm_status):
+ def test_consume_create_alarm_request_key(self, m_create_alarm,\
+ m_publish_create_alarm_status):
"""Test functionality of consume for create_alarm_request key"""
+ vim_uuid = "f85fc39e-723d-4172-979b-de28b36465bb"
# Mock a message
msg = Message()
msg.topic = "alarm_request"
msg.key = "create_alarm_request"
- msg.value = json.dumps({"alarm_create_request":"alarm_details"})
+ msg.value = json.dumps({"vim_uuid":vim_uuid,"alarm_create_request":"alarm_details"})
m_create_alarm.return_value = "test_alarm_id"
config_alarm_info = json.loads(msg.value)
# Call the consume method of plugin_receiver
- self.plugin_receiver.consume(msg)
+ self.plugin_receiver.consume(msg,vim_uuid)
# verify if create_alarm and publish methods called with correct params
- m_create_alarm.assert_called_with("alarm_details")
+ m_create_alarm.assert_called_with(config_alarm_info)
m_publish_create_alarm_status.assert_called_with("test_alarm_id", config_alarm_info)
@mock.patch.object(monPluginRec.PluginReceiver, 'publish_update_alarm_status')
@mock.patch.object(monPluginRec.PluginReceiver, 'update_alarm')
- def test_consume_update_alarm_request_key(self, m_update_alarm, m_publish_update_alarm_status):
+ def test_consume_update_alarm_request_key(self, m_update_alarm,\
+ m_publish_update_alarm_status):
"""Test functionality of consume for update_alarm_request key"""
+ vim_uuid = "f85fc39e-723d-4172-979b-de28b36465bb"
# Mock a message
msg = Message()
msg.topic = "alarm_request"
msg.key = "update_alarm_request"
- msg.value = json.dumps({"alarm_update_request":"alarm_details"})
+ msg.value = json.dumps({"vim_uuid":vim_uuid,"alarm_update_request":"alarm_details"})
# set return value to mocked method
m_update_alarm.return_value = "test_alarm_id"
update_alarm_info = json.loads(msg.value)
# Call the consume method of plugin_receiver
- self.plugin_receiver.consume(msg)
+ self.plugin_receiver.consume(msg,vim_uuid)
# verify update_alarm and publish method called with correct params
- m_update_alarm.assert_called_with("alarm_details")
+ m_update_alarm.assert_called_with(update_alarm_info)
m_publish_update_alarm_status.assert_called_with("test_alarm_id", update_alarm_info)
@mock.patch.object(monPluginRec.PluginReceiver, 'publish_delete_alarm_status')
@mock.patch.object(monPluginRec.PluginReceiver, 'delete_alarm')
- def test_consume_delete_alarm_request_key(self, m_delete_alarm, m_publish_delete_alarm_status):
+ def test_consume_delete_alarm_request_key(self, m_delete_alarm,\
+ m_publish_delete_alarm_status):
"""Test functionality of consume for delete_alarm_request key"""
+ vim_uuid = "f85fc39e-723d-4172-979b-de28b36465bb"
# Mock a message
msg = Message()
msg.topic = "alarm_request"
msg.key = "delete_alarm_request"
- msg.value = json.dumps({"alarm_delete_request":"alarm_details"})
+ msg.value = json.dumps({"vim_uuid":vim_uuid,"alarm_delete_request":"alarm_details"})
m_delete_alarm.return_value = "test_alarm_id"
delete_alarm_info = json.loads(msg.value)
# Call the consume method of plugin_receiver and check delete_alarm request
- self.plugin_receiver.consume(msg)
- m_delete_alarm.assert_called_with("alarm_details")
+ self.plugin_receiver.consume(msg,vim_uuid)
+ m_delete_alarm.assert_called_with(delete_alarm_info)
# Check if publish method called with correct parameters
m_publish_delete_alarm_status.assert_called_with("test_alarm_id", delete_alarm_info)
@mock.patch.object(monPluginRec.PluginReceiver, 'publish_list_alarm_response')
@mock.patch.object(monPluginRec.PluginReceiver, 'list_alarms')
- def test_consume_list_alarm_request_key(self, m_list_alarms, m_publish_list_alarm_response):
+ def test_consume_list_alarm_request_key(self, m_list_alarms,\
+ m_publish_list_alarm_response):
""" Test functionality of list alarm request key"""
+ vim_uuid = "f85fc39e-723d-4172-979b-de28b36465bb"
# Mock a message
msg = Message()
msg.topic = "alarm_request"
msg.key = "list_alarm_request"
test_alarm_list = [{"alarm_uuid":"alarm1_details"},{"alarm_uuid":"alarm2_details"}]
- msg.value = json.dumps({"alarm_list_request":"alarm_details"})
+ msg.value = json.dumps({"vim_uuid":vim_uuid,"alarm_list_request":"alarm_details"})
m_list_alarms.return_value = test_alarm_list
list_alarms_info = json.loads(msg.value)
# Call the consume method of plugin_receiver and check delete_alarm request
- self.plugin_receiver.consume(msg)
- m_list_alarms.assert_called_with("alarm_details")
+ self.plugin_receiver.consume(msg,vim_uuid)
+ m_list_alarms.assert_called_with(list_alarms_info)
# Check if publish method called with correct parameters
m_publish_list_alarm_response.assert_called_with(test_alarm_list, list_alarms_info)
@mock.patch.object(monPluginRec.PluginReceiver, 'publish_access_update_response')
@mock.patch.object(monPluginRec.PluginReceiver, 'update_access_credentials')
- def test_consume_vim_access_request_key(self, m_update_access_credentials, m_publish_access_update_response):
+ def test_consume_vim_access_request_key(self, m_update_access_credentials,\
+ m_publish_access_update_response):
"""Test functionality of consume for vim_access_credentials request key"""
+ vim_uuid = "f85fc39e-723d-4172-979b-de28b36465bb"
# Mock a message
msg = Message()
msg.topic = "access_credentials"
msg.key = "vim_access_credentials"
- msg.value = json.dumps({"access_config":"access_details"})
+ msg.value = json.dumps({"vim_uuid":vim_uuid,"access_config":"access_details"})
# set return value to mocked method
m_update_access_credentials.return_value = True
access_info = json.loads(msg.value)
# Call the consume method of plugin_receiver
- self.plugin_receiver.consume(msg)
+ self.plugin_receiver.consume(msg,vim_uuid)
# check if mocked method called with required parameters
m_update_access_credentials.assert_called_with("access_details")
@mock.patch.object(monPluginRec.PluginReceiver, 'publish_create_alarm_status')
@mock.patch.object(monPluginRec.PluginReceiver, 'create_alarm')
- def test_consume_invalid_alarm_request_key(self, m_create_alarm, m_publish_create_alarm_status):
+ def test_consume_invalid_alarm_request_key(self, m_create_alarm,\
+ m_publish_create_alarm_status):
"""Test functionality of consume for vim_access_credentials invalid request key"""
+ vim_uuid = "f85fc39e-723d-4172-979b-de28b36465bb"
# Mock a message with invalid alarm request key
msg = Message()
msg.topic = "alarm_request"
msg.key = "invalid_alarm_request" # invalid key
# Call the consume method of plugin_receiver
- self.plugin_receiver.consume(msg)
+ self.plugin_receiver.consume(msg,vim_uuid)
# verify that create_alarm and publish_create_alarm_status methods not called
m_create_alarm.assert_not_called()
@mock.patch.object(monPluginRec.PluginReceiver, 'publish_metrics_data_status')
@mock.patch.object(monPluginRec.MonPlugin, 'get_metrics_data')
- def test_consume_invalid_metric_request_key(self, m_get_metrics_data, m_publish_metric_data_status):
+ def test_consume_invalid_metric_request_key(self, m_get_metrics_data,\
+ m_publish_metric_data_status):
"""Test functionality of invalid metric key request"""
+ vim_uuid = "f85fc39e-723d-4172-979b-de28b36465bb"
# Mock a message with invalid metric request key
msg = Message()
msg.topic = "metric_request"
msg.key = "invalid_metric_data_request" #invalid key
# Call the consume method of plugin_receiver
- self.plugin_receiver.consume(msg)
+ self.plugin_receiver.consume(msg,vim_uuid)
# verify that get martics data and publish methods not called
m_get_metrics_data.assert_not_called()
@mock.patch.object(monPluginRec.PluginReceiver, 'publish_metrics_data_status')
@mock.patch.object(monPluginRec.MonPlugin, 'get_metrics_data')
- def test_consume_read_metric_data_request_key(self, m_get_metrics_data, m_publish_metric_data_status):
+ @mock.patch.object(monPluginRec.PluginReceiver,'get_vim_access_config')
+ def test_consume_read_metric_data_request_key(self, m_get_vim_access_config,\
+ m_get_metrics_data,\
+ m_publish_metric_data_status):
"""Test functionality of consume for read_metric_data_request key"""
+ vim_uuid = "f85fc39e-723d-4172-979b-de28b36465bb"
# Mock a message
msg = Message()
msg.topic = "metric_request"
msg.key = "read_metric_data_request"
- msg.value = json.dumps({"metric_name":"metric_details"})
+ msg.value = json.dumps({"vim_uuid":vim_uuid,"metric_name":"metric_details"})
m_get_metrics_data.return_value = {"metrics_data":"metrics_details"}
+ m_get_vim_access_config.return_value = {'vrops_site':'abc',
+ 'vrops_user':'user',
+ 'vrops_password':'passwd',
+ 'vim_url':'vcd_url',
+ 'admin_username':'admin',
+ 'admin_password':'admin_passwd',
+ 'vim_uuid':'1',
+ 'tenant_id':'org_vdc_1'}
+
metric_request_info = json.loads(msg.value)
# Call the consume method of plugin_receiver
- self.plugin_receiver.consume(msg)
+ self.plugin_receiver.consume(msg,vim_uuid)
m_get_metrics_data.assert_called_with(metric_request_info)
# Check if publish method called with correct parameters
@mock.patch.object(monPluginRec.PluginReceiver, 'publish_create_metric_response')
@mock.patch.object(monPluginRec.PluginReceiver, 'verify_metric')
- def test_consume_create_metric_request_key(self, m_verify_metric, m_publish_create_metric_response):
+ def test_consume_create_metric_request_key(self, m_verify_metric,\
+ m_publish_create_metric_response):
"""Test functionality of consume for create_metric_request key"""
+ vim_uuid = "f85fc39e-723d-4172-979b-de28b36465bb"
# Mock a message
msg = Message()
msg.topic = "metric_request"
msg.key = "create_metric_request"
- msg.value = json.dumps({"metric_create_request":"metric_details"})
+ msg.value = json.dumps({"vim_uuid":vim_uuid,"metric_create":"metric_details"})
# set the return value
m_verify_metric.return_value = True
metric_info = json.loads(msg.value)
# Call the consume method of plugin_receiver
- self.plugin_receiver.consume(msg)
- m_verify_metric.assert_called_with("metric_details")
+ self.plugin_receiver.consume(msg,vim_uuid)
+ m_verify_metric.assert_called_with(metric_info)
# Check if publish method called with correct parameters
m_publish_create_metric_response.assert_called_with(metric_info, True)
@mock.patch.object(monPluginRec.PluginReceiver, 'publish_update_metric_response')
@mock.patch.object(monPluginRec.PluginReceiver, 'verify_metric')
- def test_consume_update_metric_request_key(self, m_verify_metric, m_publish_update_metric_response):
+ def test_consume_update_metric_request_key(self, m_verify_metric,\
+ m_publish_update_metric_response):
"""Test functionality of update metric request key"""
+ vim_uuid = "f85fc39e-723d-4172-979b-de28b36465bb"
# Mock a message
msg = Message()
msg.topic = "metric_request"
msg.key = "update_metric_request"
- msg.value = json.dumps({"metric_create_request":"metric_details"})
+ msg.value = json.dumps({"vim_uuid":vim_uuid,"metric_create":"metric_details"})
# set the return value
m_verify_metric.return_value = True
metric_info = json.loads(msg.value)
# Call the consume method of plugin_receiver
- self.plugin_receiver.consume(msg)
+ self.plugin_receiver.consume(msg,vim_uuid)
# verify mocked methods called with correct parameters
- m_verify_metric.assert_called_with("metric_details")
+ m_verify_metric.assert_called_with(metric_info)
m_publish_update_metric_response.assert_called_with(metric_info, True)
"""Test functionality of consume for delete_metric_request key"""
# Note: vROPS doesn't support deleting metric data
+ vim_uuid = "f85fc39e-723d-4172-979b-de28b36465bb"
# Mock a message
msg = Message()
msg.topic = "metric_request"
msg.key = "delete_metric_request"
- msg.value = json.dumps({"metric_name":"metric_details"})
+ msg.value = json.dumps({"vim_uuid":vim_uuid,"metric_name":"metric_details"})
metric_info = json.loads(msg.value)
# Call the consume method of plugin_receiver
- self.plugin_receiver.consume(msg)
+ self.plugin_receiver.consume(msg,vim_uuid)
# Check if publish method called with correct parameters
m_publish_delete_metric_response.assert_called_with(metric_info)
@mock.patch.object(monPluginRec.MonPlugin, 'configure_alarm')
@mock.patch.object(monPluginRec.MonPlugin, 'configure_rest_plugin')
- def test_create_alarm_successful(self, m_configure_rest_plugin, m_configure_alarm):
+ @mock.patch.object(monPluginRec.PluginReceiver, 'get_vim_access_config')
+ def test_create_alarm_successful(self, m_get_vim_access_config,\
+ m_configure_rest_plugin,\
+ m_configure_alarm):
""" Test functionality of create alarm method-positive case"""
# Mock config_alarm_info
- config_alarm_info = {"correlation_id": 1,
+ config_alarm_info = {"schema_version":1.0,
+ "schema_type":"create_alarm_request",
+ "vim_type":"VMware",
+ "vim_uuid":"1",
+ "alarm_create_request":{"correlation_id": 1,
"alarm_name": "CPU_Utilize_Threshold",
"metric_name": "CPU_UTILIZATION",
"tenant_uuid": "tenant_uuid",
"operation": "GT",
"threshold_value": 10,
"unit": "%",
- "statistic": "AVERAGE"}
+ "statistic": "AVERAGE"}}
# set return value to plugin uuid
+ m_get_vim_access_config.return_value = {'vrops_site':'abc',
+ 'vrops_user':'user',
+ 'vrops_password':'passwd',
+ 'vim_url':'vcd_url',
+ 'admin_username':'admin',
+ 'admin_password':'admin_passwd',
+ 'vim_uuid':'1',
+ 'tenant_id':'org_vdc_1'}
+
m_configure_rest_plugin.retrun_value = "plugin_uuid"
m_configure_alarm.return_value = "alarm_uuid"
self.plugin_receiver.create_alarm(config_alarm_info)
# verify mocked methods get called with correct params
+ m_get_vim_access_config.assert_called_with(config_alarm_info['vim_uuid'])
m_configure_rest_plugin.assert_called_with()
- m_configure_alarm.assert_called_with(config_alarm_info)
+ m_configure_alarm.assert_called_with(config_alarm_info["alarm_create_request"])
@mock.patch.object(monPluginRec.MonPlugin, 'configure_alarm')
@mock.patch.object(monPluginRec.MonPlugin, 'configure_rest_plugin')
- def test_create_alarm_failed(self, m_configure_rest_plugin, m_configure_alarm):
+ @mock.patch.object(monPluginRec.PluginReceiver, 'get_vim_access_config')
+ def test_create_alarm_failed(self, m_get_vim_access_config,\
+ m_configure_rest_plugin,\
+ m_configure_alarm):
""" Test functionality of create alarm method negative case"""
# Mock config_alarm_info
- config_alarm_info = {"correlation_id": 1,
+ config_alarm_info = {"schema_version":1.0,
+ "schema_type":"create_alarm_request",
+ "vim_type":"VMware",
+ "vim_uuid":"1",
+ "alarm_create_request":{"correlation_id": 1,
"alarm_name": "CPU_Utilize_Threshold",
"metric_name": "CPU_UTILIZATION",
"tenant_uuid": "tenant_uuid",
"operation": "GT",
"threshold_value": 10,
"unit": "%",
- "statistic": "AVERAGE"}
+ "statistic": "AVERAGE"}}
# set return value to plugin uuid and alarm_uuid to None
+ m_get_vim_access_config.return_value = {'vrops_site':'abc',
+ 'vrops_user':'user',
+ 'vrops_password':'passwd',
+ 'vim_url':'vcd_url',
+ 'admin_username':'admin',
+ 'admin_password':'admin_passwd',
+ 'vim_uuid':'1',
+ 'tenant_id':'org_vdc_1'}
m_configure_rest_plugin.retrun_value = "plugin_uuid"
m_configure_alarm.return_value = None
alarm_uuid = self.plugin_receiver.create_alarm(config_alarm_info)
# verify mocked method called with correct params
+ m_get_vim_access_config.assert_called_with(config_alarm_info['vim_uuid'])
m_configure_rest_plugin.assert_called_with()
- m_configure_alarm.assert_called_with(config_alarm_info)
+ m_configure_alarm.assert_called_with(config_alarm_info["alarm_create_request"])
# verify create alarm method returns None when failed
self.assertEqual(alarm_uuid, None)
@mock.patch.object(monPluginRec.MonPlugin, 'update_alarm_configuration')
- def test_update_alarm_successful(self, m_update_alarm_configuration):
+ @mock.patch.object(monPluginRec.PluginReceiver, 'get_vim_access_config')
+ def test_update_alarm_successful(self, m_get_vim_access_config, m_update_alarm_configuration):
""" Test functionality of update alarm method-positive case"""
# Mock update_alarm_info
- update_alarm_info = {'alarm_uuid': 'abc', 'correlation_id': 14203}
+ update_alarm_info = {"schema_version":1.0,"schema_type":"update_alarm_request",
+ "vim_type":"VMware","vim_uuid":"1",
+ "alarm_update_request":{'alarm_uuid': 'abc', 'correlation_id': 14203}}
# set return value to mocked method
m_update_alarm_configuration.return_value = "alarm_uuid"
+ m_get_vim_access_config.return_value = {'vrops_site':'abc',
+ 'vrops_user':'user',
+ 'vrops_password':'passwd',
+ 'vim_url':'vcd_url',
+ 'admin_username':'admin',
+ 'admin_password':'admin_passwd',
+ 'vim_uuid':'1',
+ 'tenant_id':'org_vdc_1'}
# check update alarm gets called and returned correct value
ret_value = self.plugin_receiver.update_alarm(update_alarm_info)
# check mocked method get called with correct param
- m_update_alarm_configuration.assert_called_with(update_alarm_info)
+ m_get_vim_access_config.assert_called_with(update_alarm_info['vim_uuid'])
+ m_update_alarm_configuration.assert_called_with(update_alarm_info["alarm_update_request"])
# check return value and passed values are correct
self.assertEqual(ret_value, "alarm_uuid")
@mock.patch.object(monPluginRec.MonPlugin, 'update_alarm_configuration')
- def test_update_alarm_failed(self, m_update_alarm_configuration):
+ @mock.patch.object(monPluginRec.PluginReceiver, 'get_vim_access_config')
+ def test_update_alarm_failed(self, m_get_vim_access_config, m_update_alarm_configuration):
""" Test functionality of update alarm method negative case"""
# Mock update_alarm_info
- update_alarm_info = {'alarm_uuid': 'abc', 'correlation_id': 14203}
+ update_alarm_info = {"schema_version":1.0,"schema_type":"update_alarm_request",
+ "vim_type":"VMware","vim_uuid":"1",
+ "alarm_update_request":{'alarm_uuid': 'abc', 'correlation_id': 14203}}
# set return value to mocked method
m_update_alarm_configuration.return_value = None
+ m_get_vim_access_config.return_value = {'vrops_site':'abc',
+ 'vrops_user':'user',
+ 'vrops_password':'passwd',
+ 'vim_url':'vcd_url',
+ 'admin_username':'admin',
+ 'admin_password':'admin_passwd',
+ 'vim_uuid':'1',
+ 'tenant_id':'org_vdc_1'}
# check update alarm gets called and returned correct value
ret_value = self.plugin_receiver.update_alarm(update_alarm_info)
# check mocked method get called with correct param
- m_update_alarm_configuration.assert_called_with(update_alarm_info)
+ m_get_vim_access_config.assert_called_with(update_alarm_info['vim_uuid'])
+ m_update_alarm_configuration.assert_called_with(update_alarm_info["alarm_update_request"])
# check return value and passed values are correct
self.assertEqual(ret_value, None)
@mock.patch.object(monPluginRec.MonPlugin, 'delete_alarm_configuration')
- def test_delete_alarm_successful(self, m_delete_alarm_configuration):
+ @mock.patch.object(monPluginRec.PluginReceiver, 'get_vim_access_config')
+ def test_delete_alarm_successful(self, m_get_vim_access_config, m_delete_alarm_configuration):
""" Test functionality of delete alarm method-positive case"""
# Mock delete_alarm_info
- delete_alarm_info = {'alarm_uuid': 'abc', 'correlation_id': 14203}
+ delete_alarm_info = {"schema_version":1.0,"schema_type":"delete_alarm_request",
+ "vim_type":"VMware","vim_uuid":"1",
+ "alarm_delete_request":{'alarm_uuid': 'abc', 'correlation_id': 14203}}
# set return value to mocked method
m_delete_alarm_configuration.return_value = "alarm_uuid"
+ m_get_vim_access_config.return_value = {'vrops_site':'abc',
+ 'vrops_user':'user',
+ 'vrops_password':'passwd',
+ 'vim_url':'vcd_url',
+ 'admin_username':'admin',
+ 'admin_password':'admin_passwd',
+ 'vim_uuid':'1',
+ 'tenant_id':'org_vdc_1'}
# check delete alarm gets called and returned correct value
ret_value = self.plugin_receiver.delete_alarm(delete_alarm_info)
# check mocked method get called with correct param
- m_delete_alarm_configuration.assert_called_with(delete_alarm_info)
+ m_get_vim_access_config.assert_called_with(delete_alarm_info['vim_uuid'])
+ m_delete_alarm_configuration.assert_called_with(delete_alarm_info["alarm_delete_request"])
# check return value and passed values are correct
self.assertEqual(ret_value, "alarm_uuid")
@mock.patch.object(monPluginRec.MonPlugin, 'delete_alarm_configuration')
- def test_delete_alarm_failed(self, m_delete_alarm_configuration):
+ @mock.patch.object(monPluginRec.PluginReceiver, 'get_vim_access_config')
+ def test_delete_alarm_failed(self, m_get_vim_access_config, m_delete_alarm_configuration):
""" Test functionality of delete alarm method-negative case"""
# Mock update_alarm_info
- delete_alarm_info = {'alarm_uuid': 'abc', 'correlation_id': 14203}
+ delete_alarm_info = {"schema_version":1.0,"schema_type":"delete_alarm_request",
+ "vim_type":"VMware","vim_uuid":"1",
+ "alarm_delete_request":{'alarm_uuid': 'abc', 'correlation_id': 14203}}
# set return value to mocked method
m_delete_alarm_configuration.return_value = None
+ m_get_vim_access_config.return_value = {'vrops_site':'abc',
+ 'vrops_user':'user',
+ 'vrops_password':'passwd',
+ 'vim_url':'vcd_url',
+ 'admin_username':'admin',
+ 'admin_password':'admin_passwd',
+ 'vim_uuid':'1',
+ 'tenant_id':'org_vdc_1'}
# check delete alarm gets called and returned correct value
ret_value = self.plugin_receiver.delete_alarm(delete_alarm_info)
# check mocked method get called with correct param
- m_delete_alarm_configuration.assert_called_with(delete_alarm_info)
+ m_get_vim_access_config.assert_called_with(delete_alarm_info['vim_uuid'])
+ m_delete_alarm_configuration.assert_called_with(delete_alarm_info["alarm_delete_request"])
# check return value to check failed status
self.assertEqual(ret_value, None)
""" Test functionality of publish create alarm status method"""
# Mock config_alarm_info
- config_alarm_info = {'vim_type': 'VMware',
- 'alarm_create_request': {'threshold_value': 0,
- 'severity': 'CRITICAL',
- 'alarm_name': 'CPU_Utilization_Above_Threshold',
- 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
- 'correlation_id': 1234,
- 'statistic': 'AVERAGE',
- 'metric_name': 'CPU_UTILIZATION'}
+ config_alarm_info = {'vim_type': 'VMware', "vim_uuid":"1",
+ 'alarm_create_request': {
+ 'threshold_value': 0,
+ 'severity': 'CRITICAL',
+ 'alarm_name': 'CPU_Utilization_Above_Threshold',
+ 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
+ 'correlation_id': 1234,
+ 'statistic': 'AVERAGE',
+ 'metric_name': 'CPU_UTILIZATION'}
}
alarm_uuid = "xyz"
self.plugin_receiver.publish_create_alarm_status(alarm_uuid, config_alarm_info)
# verify mocked method called with correct params
- m_publish.assert_called_with(key='create_alarm_response', value=mock.ANY, topic='alarm_response')
+ m_publish.assert_called_with(key='create_alarm_response',\
+ value=mock.ANY,\
+ topic='alarm_response')
@mock.patch.object(monPluginRec.KafkaProducer, 'publish')
# Mock update_alarm_info
update_alarm_info = {'vim_type' : 'VMware',
+ 'vim_uuid':'1',
+ 'schema_type': 'update_alarm_request',
'alarm_update_request':{'alarm_uuid': '6486e69',
'correlation_id': 14203,
'operation': 'GT'
- },
- 'schema_type': 'update_alarm_request'
+ }
}
alarm_uuid = "xyz"
self.plugin_receiver.publish_update_alarm_status(alarm_uuid, update_alarm_info)
# verify mocked method called with correct params
- m_publish.assert_called_with(key='update_alarm_response', value=mock.ANY, topic='alarm_response')
+ m_publish.assert_called_with(key='update_alarm_response',\
+ value=mock.ANY,\
+ topic='alarm_response')
@mock.patch.object(monPluginRec.KafkaProducer, 'publish')
# Mock delete_alarm_info
delete_alarm_info = {'vim_type' : 'VMware',
+ "vim_uuid":"1",
+ 'schema_type': 'delete_alarm_request',
'alarm_delete_request':{'alarm_uuid': '6486e69',
'correlation_id': 14203,
'operation': 'GT'
- },
- 'schema_type': 'delete_alarm_request'
+ }
}
alarm_uuid = "xyz"
self.plugin_receiver.publish_delete_alarm_status(alarm_uuid, delete_alarm_info)
# verify mocked method called with correct params
- m_publish.assert_called_with(key='delete_alarm_response', value=mock.ANY, topic='alarm_response')
+ m_publish.assert_called_with(key='delete_alarm_response',\
+ value=mock.ANY,\
+ topic='alarm_response')
@mock.patch.object(monPluginRec.KafkaProducer, 'publish')
# Mock metrics data
metrics_data = {
+ 'vim_uuid':'1',
'metric_name': 'CPU_UTILIZATION', 'metric_uuid': '0',
- 'resource_uuid': 'e14b20', 'correlation_id': 'e14b2',
+ 'resource_uuid': 'e14b20', 'correlation_id': 14203,
'metrics_data': {'time_series': [15162011, 15162044],
'metrics_series': [0.1166666671, 0.1266666650]},
'tenant_uuid': 123, 'unit': '%'
self.plugin_receiver.publish_metrics_data_status(metrics_data)
# verify mocked method called with correct params
- m_publish.assert_called_with(key='read_metric_data_response', value=mock.ANY, topic='metric_response')
+ m_publish.assert_called_with(key='read_metric_data_response',\
+ value=mock.ANY,\
+ topic='metric_response')
@mock.patch.object(monPluginRec.MonPlugin, 'verify_metric_support')
- def test_verify_metric_supported_metric(self, m_verify_metric_support):
- """ Test functionality of verify matric method"""
+ @mock.patch.object(monPluginRec.PluginReceiver, 'get_vim_access_config')
+ def test_verify_metric_supported_metric(self, m_get_vim_access_config,\
+ m_verify_metric_support):
+ """ Test functionality of verify metric method"""
# mock metric_info
- metric_info = {'metric_unit': '%', 'metric_name': 'CPU_UTILIZATION', 'resource_uuid': 'e14b203'}
+ metric_info = {'vim_uuid':'1',\
+ 'metric_create_request':{'metric_unit': '%',\
+ 'metric_name': 'CPU_UTILIZATION',\
+ 'resource_uuid': 'e14b203'}}
- # set mocked function retrun value to true
+ # set mocked function return value to true
m_verify_metric_support.return_value = True
+ m_get_vim_access_config.return_value = {'vrops_site':'abc',
+ 'vrops_user':'user',
+ 'vrops_password':'passwd',
+ 'vim_url':'vcd_url',
+ 'admin_username':'admin',
+ 'admin_password':'admin_passwd',
+ 'vim_uuid':'1',
+ 'tenant_id':'org_vdc_1'}
# call verify_metric method under test
ret_value = self.plugin_receiver.verify_metric(metric_info)
# verify mocked method called with correct params
- m_verify_metric_support.assert_called_with(metric_info)
+ m_get_vim_access_config.assert_called_with(metric_info['vim_uuid'])
+ m_verify_metric_support.assert_called_with(metric_info['metric_create_request'])
# verify the return value
self.assertEqual(ret_value, True)
@mock.patch.object(monPluginRec.MonPlugin, 'verify_metric_support')
- def test_verify_metric_unsupported_metric(self, m_verify_metric_support):
- """ Test functionality of verify matric method-negative case"""
-
- # mock metric_info with unsupported matrics name
- metric_info = {'metric_unit': '%', 'metric_name': 'Invalid', 'resource_uuid': 'e14b203'}
-
- # set mocked function retrun value to true
+ @mock.patch.object(monPluginRec.PluginReceiver, 'get_vim_access_config')
+ def test_verify_metric_unsupported_metric(self, m_get_vim_access_config,\
+ m_verify_metric_support):
+ """ Test functionality of verify metric method-negative case"""
+
+ # mock metric_info with unsupported metrics name
+ metric_info = {'vim_uuid':'1',\
+ 'metric_create_request':{'metric_unit': '%',\
+ 'metric_name': 'Invalid',\
+ 'resource_uuid': 'e14b203'}}
+
+ # set mocked function return value to true
m_verify_metric_support.return_value = False
+ m_get_vim_access_config.return_value = {'vrops_site':'abc',
+ 'vrops_user':'user',
+ 'vrops_password':'passwd',
+ 'vim_url':'vcd_url',
+ 'admin_username':'admin',
+ 'admin_password':'admin_passwd',
+ 'vim_uuid':'1',
+ 'tenant_id':'org_vdc_1'}
# call verify_metric method under test
ret_value = self.plugin_receiver.verify_metric(metric_info)
# verify mocked method called with correct params
- m_verify_metric_support.assert_called_with(metric_info)
+ m_get_vim_access_config.assert_called_with(metric_info['vim_uuid'])
+ m_verify_metric_support.assert_called_with(metric_info['metric_create_request'])
# verify the return value
self.assertEqual(ret_value, False)
""" Test functionality of publish create metric response method"""
# Mock metric_info
- metric_info = {'vim_type' : 'VMware','correlation_id': 'e14b203c',
+ metric_info = {
+ 'vim_uuid':'1',
+ 'vim_type' : 'VMware',
+ 'correlation_id': 14203,
+ 'schema_type': 'create_metric_request',
'metric_create_request':{
'resource_uuid': '6486e69',
'metric_name': 'CPU_UTILIZATION',
'metric_unit': '%'
- },
- 'schema_type': 'create_metric_request'
+ }
}
metric_status = True
self.plugin_receiver.publish_create_metric_response(metric_info, metric_status)
# verify mocked method called with correct params
- m_publish.assert_called_with(key='create_metric_response', value=mock.ANY, topic='metric_response')
+ m_publish.assert_called_with(key='create_metric_response',\
+ value=mock.ANY,\
+ topic='metric_response')
@mock.patch.object(monPluginRec.KafkaProducer, 'publish')
""" Test functionality of publish update metric response method"""
# Mock metric_info
- metric_info = {'vim_type' : 'VMware','correlation_id': 'e14b203c',
- 'metric_create_request':{
+ metric_info = {
+ 'vim_uuid':'1',
+ 'vim_type' : 'VMware',
+ 'correlation_id': 14203,
+ 'schema_type': 'update_metric_request',
+ 'metric_create':{
'resource_uuid': '6486e69',
'metric_name': 'CPU_UTILIZATION',
'metric_unit': '%'
- },
- 'schema_type': 'update_metric_request'
+ }
}
metric_status = True
self.plugin_receiver.publish_update_metric_response(metric_info, metric_status)
# verify mocked method called with correct params
- m_publish.assert_called_with(key='update_metric_response', value=mock.ANY, topic='metric_response')
+ m_publish.assert_called_with(key='update_metric_response',\
+ value=mock.ANY,\
+ topic='metric_response')
@mock.patch.object(monPluginRec.KafkaProducer, 'publish')
""" Test functionality of publish delete metric response method"""
# Mock metric_info
- metric_info = {'vim_type' : 'VMware','correlation_id': 'e14b203c',
+ metric_info = {'vim_uuid':'1', 'vim_type' : 'VMware','correlation_id': 14203,
'metric_uuid': 'e14b203c', 'resource_uuid': '6486e69',
'metric_name': 'CPU_UTILIZATION',
'schema_type': 'delete_metric_request'}
metric_status = True
# call publish delete metric method under test-vROPS doesn't support
- # delete metric,just returns responce with success
+ # delete metric,just returns response with success
self.plugin_receiver.publish_delete_metric_response(metric_info)
# verify mocked method called with correct params
- m_publish.assert_called_with(key='delete_metric_response', value=mock.ANY, topic='metric_response')
+ m_publish.assert_called_with(key='delete_metric_response',\
+ value=mock.ANY,\
+ topic='metric_response')
@mock.patch.object(monPluginRec.MonPlugin, 'get_triggered_alarms_list')
- def test_list_alarms(self, m_get_triggered_alarms_list):
+ @mock.patch.object(monPluginRec.PluginReceiver, 'get_vim_access_config')
+ def test_list_alarms(self, m_get_vim_access_config, m_get_triggered_alarms_list):
""" Test functionality of list alarms method"""
# Mock list alarm input
- list_alarm_input = {'severity': 'CRITICAL',
- 'correlation_id': 'e14b203c',
- 'alarm_name': 'CPU_Utilization_Above_Threshold',
- 'resource_uuid': 'd14b203c'}
+ list_alarm_input = {
+ 'vim_uuid':'1',
+ 'vim_type' : 'VMware',
+ 'alarm_list_request':{
+ 'severity': 'CRITICAL',
+ 'correlation_id': 14203,
+ 'alarm_name': 'CPU_Utilization_Above_Threshold',
+ 'resource_uuid': 'd14b203c'}}
# set return value to mocked method
- m_return = m_get_triggered_alarms_list.return_value = [{'status': 'ACTIVE', 'update_date': '2018-01-12T08:34:05',
- 'severity': 'CRITICAL', 'resource_uuid': 'e14b203c',
- 'cancel_date': '0000-00-00T00:00:00','alarm_instance_uuid': 'd9e3bc84',
- 'alarm_uuid': '5714977d', 'vim_type': 'VMware',
- 'start_date': '2018-01-12T08:34:05'},
- {'status': 'CANCELED', 'update_date': '2017-12-20T09:37:57',
- 'severity': 'CRITICAL', 'resource_uuid': 'e14b203c',
- 'cancel_date': '2018-01-12T06:49:19', 'alarm_instance_uuid': 'd3bbeef6',
- 'alarm_uuid': '7ba1bf3e', 'vim_type': 'VMware',
- 'start_date': '2017-12-20T09:37:57'}]
+ m_return = [{'status': 'ACTIVE', 'update_date': '2018-01-12T08:34:05',
+ 'severity': 'CRITICAL', 'resource_uuid': 'e14b203c',
+ 'cancel_date': '0000-00-00T00:00:00','alarm_instance_uuid': 'd9e3bc84',
+ 'alarm_uuid': '5714977d', 'vim_type': 'VMware',
+ 'start_date': '2018-01-12T08:34:05'},
+ {'status': 'CANCELED', 'update_date': '2017-12-20T09:37:57',
+ 'severity': 'CRITICAL', 'resource_uuid': 'e14b203c',
+ 'cancel_date': '2018-01-12T06:49:19', 'alarm_instance_uuid': 'd3bbeef6',
+ 'alarm_uuid': '7ba1bf3e', 'vim_type': 'VMware',
+ 'start_date': '2017-12-20T09:37:57'}]
+ m_get_triggered_alarms_list.return_value = m_return
+
+ m_get_vim_access_config.return_value = {'vrops_site':'abc',
+ 'vrops_user':'user',
+ 'vrops_password':'passwd',
+ 'vim_url':'vcd_url',
+ 'admin_username':'admin',
+ 'admin_password':'admin_passwd',
+ 'vim_uuid':'1',
+ 'tenant_id':'org_vdc_1'}
+
# call list alarms method under test
return_value = self.plugin_receiver.list_alarms(list_alarm_input)
# verify mocked method called with correct params
- m_get_triggered_alarms_list.assert_called_with(list_alarm_input)
+ m_get_vim_access_config.assert_called_with(list_alarm_input['vim_uuid'])
+ m_get_triggered_alarms_list.assert_called_with(list_alarm_input['alarm_list_request'])
# verify list alarm method returns correct list
self.assertEqual(return_value, m_return)
# Mock list alarm input
msg_key = 'list_alarm_response'
topic = 'alarm_response'
- list_alarm_input = {'alarm_list_request': {'severity': 'CRITICAL',
- 'correlation_id': 'e14b203c',
- 'alarm_name': 'CPU_Utilization_Above_Threshold',
- 'resource_uuid': 'd14b203c'},'vim_type' : 'VMware'}
-
- triggered_alarm_list = [{'status': 'ACTIVE', 'update_date': '2018-01-12T08:34:05', 'severity': 'CRITICAL',
- 'resource_uuid': 'e14b203c', 'cancel_date': '0000-00-00T00:00:00','alarm_instance_uuid': 'd9e3bc84',
- 'alarm_uuid': '5714977d', 'vim_type': 'VMware', 'start_date': '2018-01-12T08:34:05'}]
+ list_alarm_input = {'vim_uuid':'1',
+ 'vim_type' : 'VMware',
+ 'alarm_list_request':{
+ 'severity': 'CRITICAL',
+ 'correlation_id': 14203,
+ 'alarm_name': 'CPU_Utilization_Above_Threshold',
+ 'resource_uuid': 'd14b203c'}}
+
+ triggered_alarm_list = [{'status': 'ACTIVE', 'update_date': '2018-01-12T08:34:05',
+ 'severity': 'CRITICAL','resource_uuid': 'e14b203c',
+ 'cancel_date': '0000-00-00T00:00:00',
+ 'start_date': '2018-01-12T08:34:05',
+ 'alarm_instance_uuid': 'd9e3bc84',
+ 'alarm_uuid': '5714977d',
+ 'vim_type': 'VMware'
+ }]
# call publish list alarm response method under test
self.plugin_receiver.publish_list_alarm_response(triggered_alarm_list, list_alarm_input)
access_update_status = True
msg_key = 'vim_access_credentials_response'
topic = 'access_credentials'
- access_info_req = {'access_config': {'vrops_password': 'vmware', 'vcloud-site': 'https://192.169.241.105',
- 'vrops_user': 'Admin', 'correlation_id': 'e14b203c', 'tenant_id': 'Org2'}, 'vim_type': u'VMware'}
+ access_info_req = {'vim_type': 'VMware',
+ 'vim_uuid':'1',
+ 'access_config': {'vrops_password': 'vmware',
+ 'vcloud-site': 'https://192.169.241.105',
+ 'vrops_user': 'Admin', 'correlation_id': 14203,
+ 'tenant_id': 'Org2'}
+ }
# call publish access update response method under test
self.plugin_receiver.publish_access_update_response(access_update_status, access_info_req)
""" Test functionality of update access credentials-positive case"""
# Mock access_info
- access_info = {'vrops_site':'https://192.169.241.13','vrops_user':'admin', 'vrops_password':'vmware',
- 'vcloud-site':'https://192.169.241.15','admin_username':'admin','admin_password':'vmware',
- 'vcenter_ip':'192.169.241.13','vcenter_port':'443','vcenter_user':'admin','vcenter_password':'vmware',
+ access_info = {'vrops_site':'https://192.169.241.13','vrops_user':'admin',
+ 'vrops_password':'vmware','vcloud-site':'https://192.169.241.15',
+ 'admin_username':'admin','admin_password':'vmware',
+ 'vcenter_ip':'192.169.241.13','vcenter_port':'443',
+ 'vcenter_user':'admin','vcenter_password':'vmware',
'vim_tenant_name':'Org2','orgname':'Org2','tenant_id':'Org2'}
# Mock return values
expected_status = m_write_access_config.return_value = True
- # call publish update acccess credentials method under test
+ # call publish update access credentials method under test
actual_status = self.plugin_receiver.update_access_credentials(access_info)
# check write_access_config called with correct params
""" Test functionality of update access credentials-negative case"""
# Mock access_info
- access_info = {'vrops_site':'https://192.169.241.13','vrops_user':'admin', 'vrops_password':'vmware',
- 'vcloud-site':'https://192.169.241.15','admin_username':'admin','admin_password':'vmware',
+ access_info = {'vrops_site':'https://192.169.241.13','vrops_user':'admin',
+ 'vrops_password':'vmware','vcloud-site':'https://192.169.241.15',
+ 'admin_username':'admin','admin_password':'vmware',
'vcenter_ip':'192.169.241.13','vcenter_port':'443','vcenter_user':'admin',
'vim_tenant_name':'Org2','orgname':'Org2','tenant_id':'Org2'}
# Mock return values
expected_status = m_write_access_config.return_value = False
- # call publish update acccess credentials method under test
+ # call publish update access credentials method under test
actual_status = self.plugin_receiver.update_access_credentials(access_info)
# check if mocked method not called
""" Test functionality of update access credentials-failed case """
# Mock access_info
- access_info = {'vrops_site':'https://192.169.241.13','vrops_user':'admin', 'vrops_password':'vmware',
- 'vcloud-site':'https://192.169.241.15','admin_username':'admin','admin_password':'vmware',
- 'vcenter_ip':'192.169.241.13','vcenter_port':'443','vcenter_user':'admin','vcenter_password':'vmware',
+ access_info = {'vrops_site':'https://192.169.241.13','vrops_user':'admin',
+ 'vrops_password':'vmware','vcloud-site':'https://192.169.241.15',
+ 'admin_username':'admin','admin_password':'vmware',
+ 'vcenter_ip':'192.169.241.13','vcenter_port':'443',
+ 'vcenter_user':'admin','vcenter_password':'vmware',
'vim_tenant_name':'Org2','orgname':'Org2','tenant_id':'Org2'}
# Mock return values
expected_status = m_write_access_config.return_value = False
- # call publish update acccess credentials method under test
+ # call publish update access credentials method under test
actual_status = self.plugin_receiver.update_access_credentials(access_info)
# check write_access_config called with correct params
""" Test functionality of write access config method-positive case"""
# Mock access_info
- access_info = {'vrops_sit':'https://192.169.241.13','vrops_user':'admin', 'vrops_password':'vmware',
- 'vcloud-site':'https://192.169.241.15','admin_username':'admin','admin_password':'vmware',
- 'vcenter_ip':'192.169.241.13','vcenter_port':'443','vcenter_user':'admin','vcenter_password':'vmware',
+ access_info = {'vrops_sit':'https://192.169.241.13','vrops_user':'admin',
+ 'vrops_password':'vmware','vcloud-site':'https://192.169.241.15',
+ 'admin_username':'admin','admin_password':'vmware',
+ 'vcenter_ip':'192.169.241.13','vcenter_port':'443',
+ 'vcenter_user':'admin','vcenter_password':'vmware',
'vim_tenant_name':'Org2','orgname':'Org2','tenant_id':'Org2'}
- # call write acccess config method under test
+ # call write access config method under test
actual_status = self.plugin_receiver.write_access_config(access_info)
# verify write access config returns correct status
# Mock access_info
access_info = [] # provided incorrect info to generate error
- # call write acccess config method under test
+ # call write access config method under test
actual_status = self.plugin_receiver.write_access_config(access_info)
# verify write access config returns correct status
self.assertEqual(False, actual_status)
+ @mock.patch.object(monPluginRec.AuthManager, 'get_credentials')
+ def test_get_vim_access_config(self, m_get_credentials):
+ """ Test functionality of get_vim_access_config method-positive case"""
+
+ # Mock vim_uuid & access_info
+ vim_uuid = '1'
+ vim_details = VimCredentials()
+ vim_details.name = "vrops_vcd82"
+ vim_details.password = "passwd"
+ vim_details.tenant_name = "MANO-VDC"
+ vim_details.type = "VMware"
+ vim_details.url = "https://10.10.1.1"
+ vim_details.user = "admin"
+ vim_details.uuid = "1"
+ vim_details.config = '{"orgname": "MANO-Org", "tenant_id": "MANO-VDC",\
+ "admin_username": "administrator","admin_password": "vcd_pwd",\
+ "vrops_user": "admin", "vrops_password": "vrops_pwd",\
+ "vrops_site": "https://10.10.1.2","nsx_user": "admin",\
+ "nsx_manager": "https://10.10.1.3", "nsx_password":"nsx_pwd",\
+ "sdn_controller": "None", "sdn_port_mapping": "None",\
+ "vcenter_ip": "10.10.1.4", "vcenter_user": "admin@vsphere.local",\
+ "vcenter_password": "vcenter_pwd", "vcenter_port": "443"}'
+ m_get_credentials.return_value = vim_details
+ expected_config = {'vrops_password': 'vrops_pwd', 'vcenter_password': 'vcenter_pwd',
+ 'name': 'vrops_vcd82', 'org_user': 'admin',
+ 'org_password': 'passwd', 'nsx_user': 'admin', 'vim_tenant_name': 'MANO-VDC',
+ 'admin_username': 'administrator', 'vcenter_port': '443',
+ 'vim_url': 'https://10.10.1.1', 'orgname': 'MANO-Org',
+ 'admin_password':'vcd_pwd', 'vrops_user':'admin', 'vcenter_ip':'10.10.1.4',
+ 'vrops_site': 'https://10.10.1.2', 'nsx_manager': 'https://10.10.1.3',
+ 'nsx_password': 'nsx_pwd', 'vim_type': 'VMware', 'vim_uuid': '1',
+ 'vcenter_user': 'admin@vsphere.local'}
+
+ # call get_vim_access_config method under test
+ actual_config = self.plugin_receiver.get_vim_access_config('1')
+
+ #verify that mocked method is called
+ m_get_credentials.assert_called_with(vim_uuid)
+
+ #Verify return value with expected value
+ self.assertEqual(expected_config, actual_config)
+
+
# For testing purpose
#if __name__ == '__main__':