def error_cleanup(): global endpoint_uuid, sns_topic_uuid, alarm_uuid, test_dict test_lib.lib_error_cleanup(test_dict) if alarm_uuid: zwt_ops.delete_alarm(alarm_uuid) if sns_topic_uuid: zwt_ops.delete_sns_topic(sns_topic_uuid) if endpoint_uuid: zwt_ops.delete_sns_application_endpoint(endpoint_uuid)
def error_cleanup(): global vm, my_sns_topic_uuid, email_endpoint_uuid, email_platform_uuid, disk_all_write_bytes_alarm_uuid if vm: vm.clean() if disk_all_write_bytes_alarm_uuid: zwt_ops.delete_alarm(disk_all_write_bytes_alarm_uuid) if my_sns_topic_uuid: zwt_ops.delete_sns_topic(my_sns_topic_uuid) if email_endpoint_uuid: zwt_ops.delete_sns_application_endpoint(email_endpoint_uuid) if email_platform_uuid: zwt_ops.delete_sns_application_platform(email_platform_uuid)
def error_cleanup(): global endpoint_uuid_01, endpoint_uuid_02, sns_topic_uuid_01, sns_topic_uuid_02, alarm_uuid if alarm_uuid: zwt_ops.delete_alarm(alarm_uuid) if sns_topic_uuid_01: zwt_ops.delete_sns_topic(sns_topic_uuid_01) if sns_topic_uuid_02: zwt_ops.delete_sns_topic(sns_topic_uuid_02) if endpoint_uuid_02: zwt_ops.delete_sns_application_endpoint(endpoint_uuid_02) if endpoint_uuid_01: zwt_ops.delete_sns_application_endpoint(endpoint_uuid_01)
def error_cleanup(): global vm, my_sns_topic_uuid, email_endpoint_uuid, email_platform_uuid, disk_all_write_bytes_alarm_uuid if vm: vm.clean() if disk_all_write_bytes_alarm_uuid: zwt_ops.delete_alarm(disk_all_write_bytes_alarm_uuid) if my_sns_topic_uuid: zwt_ops.delete_sns_topic(my_sns_topic_uuid) if email_endpoint_uuid: zwt_ops.delete_sns_application_endpoint(email_endpoint_uuid) if email_platform_uuid: zwt_ops.delete_sns_application_platform(email_platform_uuid)
def error_cleanup(): global test_dict, my_sns_topic_uuid, email_endpoint_uuid, email_platform_uuid, event_template_uuid, \ alarm_template_uuid, alarm_uuid_list test_lib.lib_error_cleanup(test_dict) if alarm_uuid_list: for alarm_uuid in alarm_uuid_list: zwt_ops.delete_alarm(alarm_uuid) if event_template_uuid: zwt_ops.delete_sns_text_template(event_template_uuid) if alarm_template_uuid: zwt_ops.delete_sns_text_template(alarm_template_uuid) if my_sns_topic_uuid: zwt_ops.delete_sns_topic(my_sns_topic_uuid) if email_endpoint_uuid: zwt_ops.delete_sns_application_endpoint(email_endpoint_uuid) if email_platform_uuid: zwt_ops.delete_sns_application_platform(email_platform_uuid) if event_template_uuid: zwt_ops.delete_sns_text_template(event_template_uuid)
def error_cleanup(): global email_platform_uuid, email_endpoint_uuid, dingtalk_endpoint_uuid, http_endpoint_uuid, alarm_uuid, ps_event_sub_uuid, sns_topic_uuid, alarm_template_uuid iam2_ops.clean_iam2_enviroment() if email_platform_uuid: zwt_ops.delete_sns_application_platform(email_platform_uuid) if email_endpoint_uuid: zwt_ops.delete_sns_application_endpoint(email_endpoint_uuid) if dingtalk_endpoint_uuid: zwt_ops.delete_sns_application_endpoint(dingtalk_endpoint_uuid) if http_endpoint_uuid: zwt_ops.delete_sns_application_endpoint(http_endpoint_uuid) if alarm_uuid: zwt_ops.delete_alarm(alarm_uuid) if ps_event_sub_uuid: zwt_ops.unsubscribe_event(ps_event_sub_uuid) if sns_topic_uuid: zwt_ops.delete_sns_topic(sns_topic_uuid) if alarm_template_uuid: zwt_ops.delete_sns_text_template(alarm_template_uuid)
def error_cleanup(): global test_dict, my_sns_topic_uuid, email_endpoint_uuid, email_platform_uuid, event_template_uuid, \ alarm_template_uuid, alarm_uuid_list test_lib.lib_error_cleanup(test_dict) if alarm_uuid_list: for alarm_uuid in alarm_uuid_list: zwt_ops.delete_alarm(alarm_uuid) if event_template_uuid: zwt_ops.delete_sns_text_template(event_template_uuid) if alarm_template_uuid: zwt_ops.delete_sns_text_template(alarm_template_uuid) if my_sns_topic_uuid: zwt_ops.delete_sns_topic(my_sns_topic_uuid) if email_endpoint_uuid: zwt_ops.delete_sns_application_endpoint(email_endpoint_uuid) if email_platform_uuid: zwt_ops.delete_sns_application_platform(email_platform_uuid) if event_template_uuid: zwt_ops.delete_sns_text_template(event_template_uuid)
def error_cleanup(): global email_platform_uuid,email_endpoint_uuid,dingtalk_endpoint_uuid,http_endpoint_uuid,alarm_uuid,ps_event_sub_uuid,sns_topic_uuid,alarm_template_uuid iam2_ops.clean_iam2_enviroment() if email_platform_uuid: zwt_ops.delete_sns_application_platform(email_platform_uuid) if email_endpoint_uuid: zwt_ops.delete_sns_application_endpoint(email_endpoint_uuid) if dingtalk_endpoint_uuid: zwt_ops.delete_sns_application_endpoint(dingtalk_endpoint_uuid) if http_endpoint_uuid: zwt_ops.delete_sns_application_endpoint(http_endpoint_uuid) if alarm_uuid: zwt_ops.delete_alarm(alarm_uuid) if ps_event_sub_uuid: zwt_ops.unsubscribe_event(ps_event_sub_uuid) if sns_topic_uuid: zwt_ops.delete_sns_topic(sns_topic_uuid) if alarm_template_uuid: zwt_ops.delete_sns_text_template(alarm_template_uuid)
def test(): global endpoint_uuid, sns_topic_uuid, alarm_uuid, test_dict, test_stub url = 'https://oapi.dingtalk.com/robot/send?access_token' \ '=0be899d4bd0a7629961a5ccd3035dfba30d084b57944897838f1b60100dddddd' name = 'dingtalkendpointTest' endpoint_uuid = zwt_ops.create_sns_dingtalk_endpoint(url, name, at_all=True).uuid # create sns topic sns_topic_uuid = zwt_ops.create_sns_topic('sns_topic_01').uuid zwt_ops.subscribe_sns_topic(sns_topic_uuid, endpoint_uuid) # create alarm namespace = 'ZStack/Volume' actions = [{"actionUuid": sns_topic_uuid, "actionType": "sns"}] comparisonOperator = 'GreaterThanOrEqualTo' repeat_interval = 20 period = 10 threshold = 5 metric_name = 'TotalVolumeCount' alarm_uuid = zwt_ops.create_alarm(comparisonOperator, period, threshold, namespace, metric_name, actions=actions, repeat_interval=repeat_interval).uuid # Create volume for i in range(threshold+1): volume = test_stub.create_volume() test_dict.add_volume(volume) time.sleep(20) cond = res_ops.gen_query_conditions('uuid','=',alarm_uuid) alarm_inv = res_ops.query_resource(res_ops.ALARM,cond)[0] if alarm_inv.status != 'Alarm': test_util.test_fail("Alarm did't change status to alarm.Test fail") test_lib.lib_robot_cleanup(test_dict) zwt_ops.delete_alarm(alarm_uuid) zwt_ops.delete_sns_topic(sns_topic_uuid) zwt_ops.delete_sns_application_endpoint(endpoint_uuid) test_util.test_pass('success test alarm image account with dingtalk!')
def test(): global my_sns_topic_uuid, email_endpoint_uuid, email_platform_uuid, event_template_uuid, \ alarm_template_uuid, alarm_uuid_list, test_dict smtp_server = 'smtp.zstack.io' pop_server = 'pop3.zstack.io' smtp_port = 25 username = '******' password = '******' email_platform_name = 'Alarm_email' email_platform = zwt_ops.create_sns_email_platform(smtp_server, smtp_port, email_platform_name, username, password) email_platform_uuid = email_platform.uuid try: zwt_ops.validate_sns_email_platform(email_platform_uuid) except: test_util.test_fail( 'Validate SNS Email Platform Failed, Email Plarform: %s' % email_platform_uuid) email_endpoint_uuid = zwt_ops.create_sns_email_endpoint( username, 'test_qa', email_platform_uuid).uuid my_sns_topic = zwt_ops.create_sns_topic('my_sns_topic') my_sns_topic_uuid = my_sns_topic.uuid zwt_ops.subscribe_sns_topic(my_sns_topic_uuid, email_endpoint_uuid) # create alarm namespace = 'ZStack/Image' greater_than_or_equal_to = 'GreaterThanOrEqualTo' greater_than = 'GreaterThan' actions = [{"actionUuid": my_sns_topic_uuid, "actionType": "sns"}] period = 10 threshold_1 = 1 threshold_3 = 3 threshold_10 = 10 threshold_50 = 50 total_image_count = 'TotalImageCount' total_image_count_alarm_uuid = zwt_ops.create_alarm( greater_than_or_equal_to, period, threshold_3, namespace, total_image_count, name='total-count-image', repeat_interval=600, actions=actions).uuid alarm_uuid_list.append(total_image_count_alarm_uuid) ready_image_count = 'ReadyImageCount' ready_image_count_alarm_uuid = zwt_ops.create_alarm( greater_than_or_equal_to, period, threshold_3, namespace, ready_image_count, name='ready_image_count', repeat_interval=600, actions=actions).uuid alarm_uuid_list.append(ready_image_count_alarm_uuid) ready_image_in_percent = 'ReadyImageInPercent' ready_image_in_percent_alarm_uuid = zwt_ops.create_alarm( greater_than_or_equal_to, period, threshold_1, namespace, ready_image_in_percent, name='ready_image_in_percent', repeat_interval=600, actions=actions).uuid alarm_uuid_list.append(ready_image_in_percent_alarm_uuid) root_volume_template_count = 'RootVolumeTemplateCount' root_volume_template_count_alarm_uuid = zwt_ops.create_alarm( greater_than_or_equal_to, period, threshold_3, namespace, root_volume_template_count, name='root_volume_template_count', repeat_interval=600, actions=actions, ).uuid alarm_uuid_list.append(root_volume_template_count_alarm_uuid) root_volume_template_in_percent = 'RootVolumeTemplateInPercent' root_volume_template_in_percent_alarm_uuid = zwt_ops.create_alarm( greater_than, period, threshold_1, namespace, root_volume_template_in_percent, name='root_volume_template_in_percent', repeat_interval=600, actions=actions).uuid alarm_uuid_list.append(root_volume_template_in_percent_alarm_uuid) data_volume_template_count = 'DataVolumeTemplateCount' data_volume_template_count_alarm_uuid = zwt_ops.create_alarm( greater_than_or_equal_to, period, threshold_3, namespace, data_volume_template_count, name='data_volume_template_count', repeat_interval=600, actions=actions).uuid alarm_uuid_list.append(data_volume_template_count_alarm_uuid) data_volume_template_in_percent = 'DataVolumeTemplateInPercent' data_volume_template_in_percent_alarm_uuid = zwt_ops.create_alarm( greater_than, period, threshold_1, namespace, data_volume_template_in_percent, name='data_volume_template_in_percent', repeat_interval=600, actions=actions).uuid alarm_uuid_list.append(data_volume_template_in_percent_alarm_uuid) iso_count = 'ISOCount' iso_count_alarm_uuid = zwt_ops.create_alarm(greater_than_or_equal_to, period, threshold_3, namespace, iso_count, name='iso_count', repeat_interval=600, actions=actions).uuid alarm_uuid_list.append(iso_count_alarm_uuid) iso_in_percent = 'ISOInPercent' iso_in_percent_alarm_uuid = zwt_ops.create_alarm(greater_than, period, threshold_1, namespace, iso_in_percent, name='iso_in_percent', repeat_interval=600, actions=actions).uuid alarm_uuid_list.append(iso_in_percent_alarm_uuid) # create Image image_name = os.environ.get('imageName_s') l3_name = os.environ.get('l3VlanNetworkName1') vm_name = 'multihost_basic_vm' vm = test_stub.create_vm(vm_name, image_name, l3_name) test_dict.add_vm(vm) volume = test_stub.create_volume() test_dict.add_volume(volume) volume.attach(vm) zone_uuid = vm.get_vm().zoneUuid root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) bs_uuid_list = test_lib.lib_get_backup_storage_uuid_list_by_zone(zone_uuid) image_option = test_util.ImageOption() image_option.set_root_volume_uuid(root_volume_uuid) image_option.set_format('qcow2') image_option.set_backup_storage_uuid_list(bs_uuid_list) # image_option.set_mediaType('ISO') for i in range(threshold_3): image_option.set_name('root_volume_template_for_test_' + str(i)) root_volume_template = zstack_image_header.ZstackTestImage() root_volume_template.set_creation_option(image_option) root_volume_template.create() test_dict.add_image(root_volume_template) iso = test_stub.add_test_minimal_iso("iso_for_test_" + str(i)) test_dict.add_image(iso) time.sleep(30) # before change template flag = zwt_ops.check_sns_email(pop_server, username, password, total_image_count, total_image_count_alarm_uuid) if flag != 1: test_util.test_fail('No send event email') flag = zwt_ops.check_sns_email(pop_server, username, password, ready_image_count, ready_image_count_alarm_uuid) if flag != 1: test_util.test_fail('No send event email') flag = zwt_ops.check_sns_email(pop_server, username, password, ready_image_in_percent, ready_image_in_percent_alarm_uuid) if flag != 1: test_util.test_fail('No send event email') flag = zwt_ops.check_sns_email(pop_server, username, password, root_volume_template_count, root_volume_template_count_alarm_uuid) if flag != 1: test_util.test_fail('No send event email') flag = zwt_ops.check_sns_email(pop_server, username, password, root_volume_template_in_percent, root_volume_template_in_percent_alarm_uuid) if flag != 1: test_util.test_fail('No send event email') flag = zwt_ops.check_sns_email(pop_server, username, password, iso_count, iso_count_alarm_uuid) if flag != 1: test_util.test_fail('No send event email') flag = zwt_ops.check_sns_email(pop_server, username, password, iso_in_percent, iso_in_percent_alarm_uuid) if flag != 1: test_util.test_fail('No send event email') alarm_keywords = 'TemplateForAlarmOn' if zwt_ops.check_keywords_in_email(pop_server, username, password, alarm_keywords, total_image_count_alarm_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_keywords_in_email(pop_server, username, password, alarm_keywords, ready_image_count_alarm_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_keywords_in_email(pop_server, username, password, alarm_keywords, ready_image_in_percent_alarm_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_keywords_in_email(pop_server, username, password, alarm_keywords, root_volume_template_count_alarm_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_keywords_in_email( pop_server, username, password, alarm_keywords, root_volume_template_in_percent_alarm_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_keywords_in_email(pop_server, username, password, alarm_keywords, data_volume_template_count_alarm_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_keywords_in_email( pop_server, username, password, alarm_keywords, data_volume_template_in_percent_alarm_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_keywords_in_email(pop_server, username, password, alarm_keywords, iso_count_alarm_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_keywords_in_email(pop_server, username, password, alarm_keywords, iso_in_percent_alarm_uuid): test_util.test_fail('email already exsist before test') application_platform_type = 'Email' alarm_template_name = 'my-alarm-template' alarm_template = '${ALARM_NAME} Change status to ${ALARM_CURRENT_STATUS}' \ 'ALARM_UUID:${ALARM_UUID}' \ 'keyword1:ThisWordIsKeyWord' \ 'keyword2:TemplateForAlarmOn' \ '(Using for template changes email check)' alarm_template_uuid = zwt_ops.create_sns_text_template( alarm_template_name, application_platform_type, alarm_template, default_template=False).uuid event_template_name = 'my-event-template' event_keywords = 'TemplateForEventHappened' event_template = '${EVENT_NAME} IN ${EVENT_NAMESPACE}' \ 'keyword1:ThisWordIsKeyWord' \ 'keyword2:TemplateForEventHappened' \ 'keyword3{PARAM_EVENT_SUBSCRIPTION_UUID}' \ '(Using for template changes email check)' event_template_uuid = zwt_ops.create_sns_text_template( event_template_name, application_platform_type, event_template, default_template=True).uuid # test update text template zwt_ops.update_sns_text_template(alarm_template_uuid, description='this is a new description', default_template=True) cond = res_ops.gen_query_conditions('uuid', '=', alarm_template_uuid) inv = res_ops.query_resource(res_ops.SNS_TEXT_TEMPLATE, cond)[0] if inv.defaultTemplate == False or inv.description != 'this is a new description': test_util.test_fail('change template fail') for i in range(threshold_3): data_volume_template = volume.create_template( bs_uuid_list, name="vol_temp_for_volume_test_" + str(i)) test_dict.add_image(data_volume_template) # wait for reboot and send email time.sleep(30) test_lib.lib_robot_cleanup(test_dict) zwt_ops.delete_sns_text_template(alarm_template_uuid) zwt_ops.delete_sns_text_template(event_template_uuid) for alarm_uuid in alarm_uuid_list: zwt_ops.delete_alarm(alarm_uuid) zwt_ops.delete_sns_topic(my_sns_topic_uuid) zwt_ops.delete_sns_application_endpoint(email_endpoint_uuid) zwt_ops.delete_sns_application_platform(email_platform_uuid) if zwt_ops.check_keywords_in_email( pop_server, username, password, alarm_keywords, data_volume_template_count_alarm_uuid ) and zwt_ops.check_keywords_in_email( pop_server, username, password, alarm_keywords, data_volume_template_in_percent_alarm_uuid): test_util.test_pass('success check all keywords in the email') else: test_util.test_fail('cannt check all mail')
def test(): global email_endpoint_uuid, email_platform_uuid, vm, disk_all_write_bytes_alarm_uuid, my_sns_topic_uuid smtp_server = 'smtp.zstack.io' pop_server = 'pop3.zstack.io' smtp_port = 25 username = '******' password = '******' email_platform_name = 'Alarm_email' email_platform_uuid = zwt_ops.create_sns_email_platform( smtp_server, smtp_port, email_platform_name, username, password).uuid zwt_ops.validate_sns_email_platform(email_platform_uuid) email_endpoint_uuid = zwt_ops.create_sns_email_endpoint( username, 'test_qa', email_platform_uuid).uuid my_sns_topic = zwt_ops.create_sns_topic('my_sns_topic') my_sns_topic_uuid = my_sns_topic.uuid zwt_ops.subscribe_sns_topic(my_sns_topic_uuid, email_endpoint_uuid) namespace = 'ZStack/VM' less_than = 'LessThan' actions = [{"actionUuid": my_sns_topic_uuid, "actionType": "sns"}] period = 10 threshold_3 = 1024 * 1024 * 1024 disk_all_write_bytes = 'DiskAllWriteBytes' disk_all_write_bytes_alarm_uuid = zwt_ops.create_alarm( less_than, period, threshold_3, namespace, disk_all_write_bytes, name='disk_all_write_bytes', repeat_interval=20, actions=actions).uuid image_name = os.environ.get('imageName_s') l3_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vm('test_vm', image_name, l3_name) # wait for send email time.sleep(30) flag = zwt_ops.check_keywords_in_email(pop_server, username, password, disk_all_write_bytes, disk_all_write_bytes_alarm_uuid) if not flag: test_util.test_fail('cant receive alarm email ') zwt_ops.change_alarm_state(disk_all_write_bytes_alarm_uuid, 'disable') time.sleep(10) time_stamp = zwt_ops.get_boundary_words() zwt_ops.send_boundary_email(time_stamp) time.sleep(30) flag = zwt_ops.check_keywords_in_email(pop_server, username, password, disk_all_write_bytes, disk_all_write_bytes_alarm_uuid, time_stamp) if flag: test_util.test_fail( 'the alarm had been changed state to Disabled,we should not receive the email,but we found flag is %s' % flag) time.sleep(10) zwt_ops.change_alarm_state(disk_all_write_bytes_alarm_uuid, 'enable') time.sleep(30) flag = zwt_ops.check_keywords_in_email(pop_server, username, password, disk_all_write_bytes, disk_all_write_bytes_alarm_uuid, time_stamp) if not flag: test_util.test_fail( 'cant receive email when it change state to Enable.') vm.clean() zwt_ops.delete_alarm(disk_all_write_bytes_alarm_uuid) zwt_ops.delete_sns_topic(my_sns_topic_uuid) zwt_ops.delete_sns_application_endpoint(email_endpoint_uuid) zwt_ops.delete_sns_application_platform(email_platform_uuid) test_util.test_pass('success')
def test(): global endpoint_uuid_01, endpoint_uuid_02, sns_topic_uuid_01, sns_topic_uuid_02, alarm_uuid # create endpoint url_01 = 'https://oapi.dingtalk.com/robot/send?access_token=0be899d4bd0a7629961a5ccd3035dfba30d084b57944897838f1b601006dd151' url_02 = 'https://oapi.dingtalk.com/robot/send?access_token=0be899d4bd0a7629961a5ccd3035dfba30d084b57944897838f1b601006dd151' name_01 = 'dingtalkAtPerson' name_02 = 'dingtalkAtAll' phone_number = '+86-13999999999' endpoint_uuid_01 = zwt_ops.create_sns_dingtalk_endpoint(url_01, name_01, at_all=False).uuid cond = res_ops.gen_query_conditions('uuid', '=', endpoint_uuid_01) if not res_ops.query_resource(res_ops.SNS_DING_TALK_ENDPOINT, cond): test_util.test_fail('create sns dingtalk endpoint failed') zwt_ops.add_sns_dingtalk_at_person(phone_number, endpoint_uuid_01) cond = res_ops.gen_query_conditions('uuid', '=', endpoint_uuid_01) inv = res_ops.query_resource(res_ops.SNS_DING_TALK_ENDPOINT, cond)[0] if phone_number not in inv.atPersonPhoneNumbers: test_util.test_fail('add sns dingtalk at person failed') zwt_ops.remove_sns_dingtalk_at_person(phone_number, endpoint_uuid_01) cond = res_ops.gen_query_conditions('uuid', '=', endpoint_uuid_01) inv = res_ops.query_resource(res_ops.SNS_DING_TALK_ENDPOINT, cond)[0] if phone_number in inv.atPersonPhoneNumbers: test_util.test_fail('remove sns dingtalk at person failed') endpoint_uuid_02 = zwt_ops.create_sns_dingtalk_endpoint(url_02, name_02, at_all=True).uuid cond = res_ops.gen_query_conditions('uuid', '=', endpoint_uuid_02) if not res_ops.query_resource(res_ops.SNS_DING_TALK_ENDPOINT, cond): test_util.test_fail('create sns dingtalk endpoint failed') # update endpoint endpoint_new_name = 'dingtalkAtpersonNew' endpoint_description = 'this is a description for atperson' zwt_ops.update_sns_application_endpoint(endpoint_uuid_01, endpoint_new_name, endpoint_description) cond = res_ops.gen_query_conditions('name', '=', endpoint_new_name) endpoint = res_ops.query_resource(res_ops.SNS_DING_TALK_ENDPOINT, cond)[0] if endpoint.description != endpoint_description: test_util.test_fail('update sns application endpoint failed') # create sns topic sns_topic_uuid_01 = zwt_ops.create_sns_topic('sns_topic_01').uuid cond = res_ops.gen_query_conditions('uuid', '=', sns_topic_uuid_01) if not res_ops.query_resource(res_ops.SNS_TOPIC, cond): test_util.test_fail('create sns topic failed') sns_topic_uuid_02 = zwt_ops.create_sns_topic('sns_topic_02').uuid cond = res_ops.gen_query_conditions('uuid', '=', sns_topic_uuid_02) if not res_ops.query_resource(res_ops.SNS_TOPIC, cond): test_util.test_fail('create sns topic failed') # update sns topic topic_new_name = 'sns_topic_01_new' topic_description = 'this is a description for topic' zwt_ops.update_sns_topic(sns_topic_uuid_01, topic_new_name, topic_description) cond = res_ops.gen_query_conditions('uuid', '=', sns_topic_uuid_01) inv = res_ops.query_resource(res_ops.SNS_TOPIC, cond)[0] if inv.name != topic_new_name or inv.description != topic_description: test_util.test_fail('update sns topic failed') # subscribe sns topic zwt_ops.subscribe_sns_topic(sns_topic_uuid_01, endpoint_uuid_01) cond = res_ops.gen_query_conditions('endpoints.uuid', '=', endpoint_uuid_01) if not res_ops.query_resource(res_ops.SNS_TOPIC, cond): test_util.test_fail('subscribe sns topic failed') zwt_ops.subscribe_sns_topic(sns_topic_uuid_01, endpoint_uuid_02) cond = res_ops.gen_query_conditions('endpoints.uuid', '=', endpoint_uuid_02) if not res_ops.query_resource(res_ops.SNS_TOPIC, cond): test_util.test_fail('subscribe sns topic failed') zwt_ops.subscribe_sns_topic(sns_topic_uuid_02, endpoint_uuid_02) cond = res_ops.gen_query_conditions('endpoints.uuid', '=', endpoint_uuid_02) if len(res_ops.query_resource(res_ops.SNS_TOPIC, cond)) != 2: test_util.test_fail('subscribe sns topic failed') # create alarm namespace = 'ZStack/VM' actions = [{"actionUuid": sns_topic_uuid_01, "actionType": "sns"}] period = 60 comparisonOperator = 'GreaterThanOrEqualTo' threshold = 10 metric_name = 'CPUUsedUtilization' alarm = zwt_ops.create_alarm(comparisonOperator, period, threshold, namespace, metric_name, actions=actions) alarm_uuid = alarm.uuid cond = res_ops.gen_query_conditions('uuid', '=', alarm_uuid) inv = res_ops.query_resource(res_ops.ALARM, cond) if not inv: test_util.test_fail('create alarm Failed') # test update alarm new_name = 'total_image_count_alarm' zwt_ops.update_alarm(alarm_uuid, name=new_name, period=10) cond = res_ops.gen_query_conditions('uuid', '=', alarm_uuid) inv = res_ops.query_resource(res_ops.ALARM, cond)[0] if inv.period != 10 or inv.name != new_name: test_util.test_fail('update alarm Failed') # test add action to alarm action_type = 'sns' zwt_ops.add_action_to_alarm(alarm_uuid, sns_topic_uuid_02, action_type) cond = res_ops.gen_query_conditions('uuid', '=', alarm_uuid) inv = res_ops.query_resource(res_ops.ALARM, cond)[0] flag = False for action in inv.actions: if action.actionUuid == sns_topic_uuid_02: flag = True if not flag: test_util.test_fail('add action to alarm failed') # test remove action from alarm zwt_ops.remove_action_from_alarm(alarm_uuid, sns_topic_uuid_02) cond = res_ops.gen_query_conditions('uuid', '=', alarm_uuid) inv = res_ops.query_resource(res_ops.ALARM, cond)[0] flag = False for action in inv.actions: if action.actionUuid == sns_topic_uuid_02: flag = True if flag: test_util.test_fail('remove action from alarm failed') # test add label to alarm key = 'VMUuid' operator = 'Equal' value = '1a1d7395cf74474ca52deb80c41214a1' zwt_ops.add_label_to_alarm(alarm_uuid, key, value, operator) cond = res_ops.gen_query_conditions('uuid', '=', alarm_uuid) inv = res_ops.query_resource(res_ops.ALARM, cond)[0] if not inv.labels: test_util.test_fail('add label to alarm failed') label_uuid = inv.labels[0].uuid # test remove label from alarm zwt_ops.remove_label_from_alarm(label_uuid) cond = res_ops.gen_query_conditions('uuid', '=', alarm_uuid) inv = res_ops.query_resource(res_ops.ALARM, cond)[0] if inv.labels: test_util.test_fail('remove label from alarm failed') # test change state state_event = 'disable' state_result = 'Disabled' zwt_ops.change_alarm_state(alarm_uuid, state_event) cond = res_ops.gen_query_conditions('uuid', '=', alarm_uuid) inv = res_ops.query_resource(res_ops.ALARM, cond)[0] if inv.state != state_result: test_util.test_fail('change alarm state failed') zwt_ops.change_sns_application_endpoint_state(endpoint_uuid_02, state_event) cond = res_ops.gen_query_conditions('uuid', '=', endpoint_uuid_02) inv = res_ops.query_resource(res_ops.SNS_APPLICATION_ENDPOINT, cond)[0] if inv.state != state_result: test_util.test_fail('change sns application endpoint failed') zwt_ops.change_sns_topic_state(sns_topic_uuid_02, state_event) cond = res_ops.gen_query_conditions('uuid', '=', sns_topic_uuid_02) inv = res_ops.query_resource(res_ops.SNS_TOPIC, cond)[0] if inv.state != state_result: test_util.test_fail('change sns topic state failed') # test recover and delete state_event = 'enable' state_result = 'Enabled' zwt_ops.change_alarm_state(alarm_uuid, state_event) cond = res_ops.gen_query_conditions('uuid', '=', alarm_uuid) inv = res_ops.query_resource(res_ops.ALARM, cond)[0] if inv.state != state_result: test_util.test_fail('change alarm state failed') zwt_ops.change_sns_application_endpoint_state(endpoint_uuid_02, state_event) cond = res_ops.gen_query_conditions('uuid', '=', endpoint_uuid_02) inv = res_ops.query_resource(res_ops.SNS_APPLICATION_ENDPOINT, cond)[0] if inv.state != state_result: test_util.test_fail('change sns application endpoint failed') zwt_ops.change_sns_topic_state(sns_topic_uuid_02, state_event) cond = res_ops.gen_query_conditions('uuid', '=', sns_topic_uuid_02) inv = res_ops.query_resource(res_ops.SNS_TOPIC, cond)[0] if inv.state != state_result: test_util.test_fail('change sns topic state failed') zwt_ops.unsubscribe_sns_topic(sns_topic_uuid_01, endpoint_uuid_01) cond = res_ops.gen_query_conditions('endpoints.uuid', '=', endpoint_uuid_01) if res_ops.query_resource(res_ops.SNS_TOPIC, cond): test_util.test_fail('unsubscribe sns topic failed') zwt_ops.unsubscribe_sns_topic(sns_topic_uuid_01, endpoint_uuid_02) zwt_ops.unsubscribe_sns_topic(sns_topic_uuid_02, endpoint_uuid_02) cond = res_ops.gen_query_conditions('endpoints.uuid', '=', endpoint_uuid_02) if res_ops.query_resource(res_ops.SNS_TOPIC, cond): test_util.test_fail('unsubscribe sns topic failed') zwt_ops.delete_alarm(alarm_uuid) cond = res_ops.gen_query_conditions('uuid', '=', alarm_uuid) inv = res_ops.query_resource(res_ops.ALARM, cond) if inv: test_util.test_fail('delete alarm failed') zwt_ops.delete_sns_topic(sns_topic_uuid_01) cond = res_ops.gen_query_conditions('uuid', '=', sns_topic_uuid_01) inv = res_ops.query_resource(res_ops.SNS_TOPIC, cond) if inv: test_util.test_fail('delete sns topic failed') zwt_ops.delete_sns_topic(sns_topic_uuid_02) cond = res_ops.gen_query_conditions('uuid', '=', sns_topic_uuid_02) inv = res_ops.query_resource(res_ops.SNS_TOPIC, cond) if inv: test_util.test_fail('delete sns topic failed') zwt_ops.delete_sns_application_endpoint(endpoint_uuid_01) cond = res_ops.gen_query_conditions('uuid', '=', endpoint_uuid_01) inv = res_ops.query_resource(res_ops.SNS_APPLICATION_ENDPOINT, cond) if inv: test_util.test_fail('delete sns application endpoint failed') zwt_ops.delete_sns_application_endpoint(endpoint_uuid_02) cond = res_ops.gen_query_conditions('uuid', '=', endpoint_uuid_02) inv = res_ops.query_resource(res_ops.SNS_APPLICATION_ENDPOINT, cond) if inv: test_util.test_fail('delete sns application endpoint failed') test_util.test_pass( 'success test alarm with dingtalk endpoint basic option!')
def test(): global email_endpoint_uuid, email_platform_uuid, vm, disk_all_write_bytes_alarm_uuid, my_sns_topic_uuid smtp_server = os.environ.get('smtpServer') pop_server = os.environ.get('popServer') smtp_port = os.environ.get('smtpPort') username = os.environ.get('mailUsername') password = os.environ.get('mailPassword') email_platform_name = 'Alarm_email' email_platform_uuid = zwt_ops.create_sns_email_platform(smtp_server, smtp_port, email_platform_name, username, password).uuid zwt_ops.validate_sns_email_platform(email_platform_uuid) email_endpoint_uuid = zwt_ops.create_sns_email_endpoint(username, 'test_qa', email_platform_uuid).uuid my_sns_topic = zwt_ops.create_sns_topic('my_sns_topic') my_sns_topic_uuid = my_sns_topic.uuid zwt_ops.subscribe_sns_topic(my_sns_topic_uuid, email_endpoint_uuid) namespace = 'ZStack/VM' less_than = 'LessThan' actions = [{"actionUuid": my_sns_topic_uuid, "actionType": "sns"}] period = 10 threshold_3 = 1024 * 1024 * 1024 disk_all_write_bytes = 'DiskAllWriteBytes' disk_all_write_bytes_alarm_uuid = zwt_ops.create_alarm(less_than, period, threshold_3, namespace, disk_all_write_bytes, name='disk_all_write_bytes', repeat_interval=15, actions=actions).uuid image_name = os.environ.get('imageName_s') l3_name = os.environ.get('l3PublicNetworkName') vm = test_stub.create_vm('test_vm', image_name, l3_name) # wait for send email time.sleep(60) flag = zwt_ops.check_keywords_in_email(pop_server, username, password, disk_all_write_bytes, disk_all_write_bytes_alarm_uuid) if not flag: test_util.test_fail('cant receive alarm email ') zwt_ops.change_alarm_state(disk_all_write_bytes_alarm_uuid, 'disable') time.sleep(10) time_stamp = zwt_ops.get_boundary_words() zwt_ops.send_boundary_email(time_stamp,smtp_server,username,password,username) time.sleep(30) flag = zwt_ops.check_keywords_in_email(pop_server, username, password, disk_all_write_bytes, disk_all_write_bytes_alarm_uuid, time_stamp) if flag: test_util.test_fail( 'the alarm had been changed state to Disabled,we should not receive the email,but we found flag is %s' % flag) time.sleep(10) zwt_ops.change_alarm_state(disk_all_write_bytes_alarm_uuid, 'enable') time.sleep(30) flag = zwt_ops.check_keywords_in_email(pop_server, username, password, disk_all_write_bytes, disk_all_write_bytes_alarm_uuid, time_stamp) if not flag: test_util.test_fail('cant receive email when it change state to Enable.') vm.clean() zwt_ops.delete_alarm(disk_all_write_bytes_alarm_uuid) zwt_ops.delete_sns_topic(my_sns_topic_uuid) zwt_ops.delete_sns_application_endpoint(email_endpoint_uuid) zwt_ops.delete_sns_application_platform(email_platform_uuid) test_util.test_pass('success')
def test(): global my_sns_topic_uuid, email_endpoint_uuid, email_platform_uuid, event_template_uuid, \ alarm_template_uuid, alarm_uuid_list, test_dict smtp_server = os.environ.get('smtpServer') pop_server = os.environ.get('popServer') smtp_port = os.environ.get('smtpPort') username = os.environ.get('mailUsername') password = os.environ.get('mailPassword') email_platform_name = 'Alarm_email' email_platform = zwt_ops.create_sns_email_platform(smtp_server, smtp_port, email_platform_name, username, password) email_platform_uuid = email_platform.uuid try: zwt_ops.validate_sns_email_platform(email_platform_uuid) except: test_util.test_fail( 'Validate SNS Email Platform Failed, Email Plarform: %s' % email_platform_uuid) email_endpoint_uuid = zwt_ops.create_sns_email_endpoint(username, 'test_qa', email_platform_uuid).uuid my_sns_topic = zwt_ops.create_sns_topic('my_sns_topic') my_sns_topic_uuid = my_sns_topic.uuid zwt_ops.subscribe_sns_topic(my_sns_topic_uuid, email_endpoint_uuid) # create alarm namespace = 'ZStack/Image' greater_than_or_equal_to = 'GreaterThanOrEqualTo' greater_than = 'GreaterThan' actions = [{"actionUuid": my_sns_topic_uuid, "actionType": "sns"}] period = 10 threshold_1 = 1 threshold_3 = 3 threshold_10 = 10 threshold_50 = 50 total_image_count = 'TotalImageCount' total_image_count_alarm_uuid = zwt_ops.create_alarm(greater_than_or_equal_to, period, threshold_3, namespace, total_image_count, name='total-count-image', repeat_interval=600, actions=actions).uuid alarm_uuid_list.append(total_image_count_alarm_uuid) ready_image_count = 'ReadyImageCount' ready_image_count_alarm_uuid = zwt_ops.create_alarm(greater_than_or_equal_to, period, threshold_3, namespace, ready_image_count, name='ready_image_count', repeat_interval=600, actions=actions).uuid alarm_uuid_list.append(ready_image_count_alarm_uuid) ready_image_in_percent = 'ReadyImageInPercent' ready_image_in_percent_alarm_uuid = zwt_ops.create_alarm(greater_than_or_equal_to, period, threshold_1, namespace, ready_image_in_percent, name='ready_image_in_percent', repeat_interval=600, actions=actions).uuid alarm_uuid_list.append(ready_image_in_percent_alarm_uuid) root_volume_template_count = 'RootVolumeTemplateCount' root_volume_template_count_alarm_uuid = zwt_ops.create_alarm(greater_than_or_equal_to, period, threshold_3, namespace, root_volume_template_count, name='root_volume_template_count', repeat_interval=600, actions=actions, ).uuid alarm_uuid_list.append(root_volume_template_count_alarm_uuid) root_volume_template_in_percent = 'RootVolumeTemplateInPercent' root_volume_template_in_percent_alarm_uuid = zwt_ops.create_alarm(greater_than, period, threshold_1, namespace, root_volume_template_in_percent, name='root_volume_template_in_percent', repeat_interval=600, actions=actions).uuid alarm_uuid_list.append(root_volume_template_in_percent_alarm_uuid) data_volume_template_count = 'DataVolumeTemplateCount' data_volume_template_count_alarm_uuid = zwt_ops.create_alarm(greater_than_or_equal_to, period, threshold_3, namespace, data_volume_template_count, name='data_volume_template_count', repeat_interval=600, actions=actions).uuid alarm_uuid_list.append(data_volume_template_count_alarm_uuid) data_volume_template_in_percent = 'DataVolumeTemplateInPercent' data_volume_template_in_percent_alarm_uuid = zwt_ops.create_alarm(greater_than, period, threshold_1, namespace, data_volume_template_in_percent, name='data_volume_template_in_percent', repeat_interval=600, actions=actions).uuid alarm_uuid_list.append(data_volume_template_in_percent_alarm_uuid) iso_count = 'ISOCount' iso_count_alarm_uuid = zwt_ops.create_alarm(greater_than_or_equal_to, period, threshold_3, namespace, iso_count, name='iso_count', repeat_interval=600, actions=actions).uuid alarm_uuid_list.append(iso_count_alarm_uuid) iso_in_percent = 'ISOInPercent' iso_in_percent_alarm_uuid = zwt_ops.create_alarm(greater_than, period, threshold_1, namespace, iso_in_percent, name='iso_in_percent', repeat_interval=600, actions=actions).uuid alarm_uuid_list.append(iso_in_percent_alarm_uuid) # create Image image_name = os.environ.get('imageName_s') l3_name = os.environ.get('l3VlanNetworkName1') vm_name='multihost_basic_vm' vm = test_stub.create_vm(vm_name,image_name,l3_name) test_dict.add_vm(vm) volume = test_stub.create_volume() test_dict.add_volume(volume) volume.attach(vm) zone_uuid = vm.get_vm().zoneUuid root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) bs_uuid_list = test_lib.lib_get_backup_storage_uuid_list_by_zone(zone_uuid) image_option = test_util.ImageOption() image_option.set_root_volume_uuid(root_volume_uuid) image_option.set_format('qcow2') image_option.set_backup_storage_uuid_list(bs_uuid_list) # image_option.set_mediaType('ISO') for i in range(threshold_3): image_option.set_name('root_volume_template_for_test_' + str(i)) root_volume_template = zstack_image_header.ZstackTestImage() root_volume_template.set_creation_option(image_option) root_volume_template.create() test_dict.add_image(root_volume_template) iso=test_stub.add_test_minimal_iso("iso_for_test_"+str(i)) test_dict.add_image(iso) time.sleep(30) # before change template flag = zwt_ops.check_sns_email(pop_server, username, password, total_image_count, total_image_count_alarm_uuid) if flag != 1: test_util.test_fail('No send event email') flag = zwt_ops.check_sns_email(pop_server, username, password, ready_image_count, ready_image_count_alarm_uuid) if flag != 1: test_util.test_fail('No send event email') flag = zwt_ops.check_sns_email(pop_server, username, password, ready_image_in_percent, ready_image_in_percent_alarm_uuid) if flag != 1: test_util.test_fail('No send event email') flag = zwt_ops.check_sns_email(pop_server, username, password, root_volume_template_count, root_volume_template_count_alarm_uuid) if flag != 1: test_util.test_fail('No send event email') flag = zwt_ops.check_sns_email(pop_server, username, password, root_volume_template_in_percent, root_volume_template_in_percent_alarm_uuid) if flag != 1: test_util.test_fail('No send event email') flag = zwt_ops.check_sns_email(pop_server, username, password, iso_count, iso_count_alarm_uuid) if flag != 1: test_util.test_fail('No send event email') flag = zwt_ops.check_sns_email(pop_server, username, password, iso_in_percent, iso_in_percent_alarm_uuid) if flag != 1: test_util.test_fail('No send event email') alarm_keywords = 'TemplateForAlarmOn' if zwt_ops.check_keywords_in_email(pop_server, username, password, alarm_keywords, total_image_count_alarm_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_keywords_in_email(pop_server, username, password, alarm_keywords, ready_image_count_alarm_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_keywords_in_email(pop_server, username, password, alarm_keywords, ready_image_in_percent_alarm_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_keywords_in_email(pop_server, username, password, alarm_keywords, root_volume_template_count_alarm_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_keywords_in_email(pop_server, username, password, alarm_keywords, root_volume_template_in_percent_alarm_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_keywords_in_email(pop_server, username, password, alarm_keywords, data_volume_template_count_alarm_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_keywords_in_email(pop_server, username, password, alarm_keywords, data_volume_template_in_percent_alarm_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_keywords_in_email(pop_server, username, password, alarm_keywords, iso_count_alarm_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_keywords_in_email(pop_server, username, password, alarm_keywords, iso_in_percent_alarm_uuid): test_util.test_fail('email already exsist before test') application_platform_type = 'Email' alarm_template_name = 'my-alarm-template' alarm_template = '${ALARM_NAME} Change status to ${ALARM_CURRENT_STATUS}' \ 'ALARM_UUID:${ALARM_UUID}' \ 'keyword1:ThisWordIsKeyWord' \ 'keyword2:TemplateForAlarmOn' \ '(Using for template changes email check)' alarm_template_uuid = zwt_ops.create_sns_text_template(alarm_template_name, application_platform_type, alarm_template, default_template=False).uuid event_template_name = 'my-event-template' event_keywords = 'TemplateForEventHappened' event_template = '${EVENT_NAME} IN ${EVENT_NAMESPACE}' \ 'keyword1:ThisWordIsKeyWord' \ 'keyword2:TemplateForEventHappened' \ 'keyword3{PARAM_EVENT_SUBSCRIPTION_UUID}' \ '(Using for template changes email check)' event_template_uuid = zwt_ops.create_sns_text_template(event_template_name, application_platform_type, event_template, default_template=True).uuid # test update text template zwt_ops.update_sns_text_template(alarm_template_uuid, description='this is a new description', default_template=True) cond = res_ops.gen_query_conditions('uuid', '=', alarm_template_uuid) inv = res_ops.query_resource(res_ops.SNS_TEXT_TEMPLATE, cond)[0] if inv.defaultTemplate == False or inv.description != 'this is a new description': test_util.test_fail('change template fail') for i in range(threshold_3): data_volume_template = volume.create_template(bs_uuid_list, name="vol_temp_for_volume_test_" + str(i)) test_dict.add_image(data_volume_template) # wait for reboot and send email time.sleep(30) test_lib.lib_robot_cleanup(test_dict) zwt_ops.delete_sns_text_template(alarm_template_uuid) zwt_ops.delete_sns_text_template(event_template_uuid) for alarm_uuid in alarm_uuid_list: zwt_ops.delete_alarm(alarm_uuid) zwt_ops.delete_sns_topic(my_sns_topic_uuid) zwt_ops.delete_sns_application_endpoint(email_endpoint_uuid) zwt_ops.delete_sns_application_platform(email_platform_uuid) if zwt_ops.check_keywords_in_email(pop_server, username, password, alarm_keywords, data_volume_template_count_alarm_uuid) and zwt_ops.check_keywords_in_email( pop_server, username, password, alarm_keywords, data_volume_template_in_percent_alarm_uuid): test_util.test_pass('success check all keywords in the email') else: test_util.test_fail('cannt check all mail')