def error_cleanup(): global vm,bss,host,ENABLE,infoType if vm: vm.clean() bs_ops.change_backup_storage_state(bss[0].uuid, ENABLE) bs_ops.update_image_store_backup_storage_info(bss[0].uuid, infoType, host) bs_ops.reconnect_backup_storage(bss[0].uuid)
def error_cleanup(): global email_endpoint_uuid, email_platform_uuid, my_sns_topic_uuid, host_sns_topic_uuid, ps_uuid, hostname, host_management_ip, host_status, bs_type, bs_status, event_list if host_status == 'Disconnected': host_ops.update_host(host_uuid, 'managementIp', host_management_ip) host_ops.reconnect_host(host_uuid) if bs_status == 'Disconnected': if bs_type == res_ops.IMAGE_STORE_BACKUP_STORAGE: bs_ops.update_image_store_backup_storage_info( bs_uuid, 'hostname', hostname) bs_ops.reconnect_backup_storage(bs_uuid) elif bs_type == res_ops.SFTP_BACKUP_STORAGE: bs_ops.update_sftp_backup_storage_info(bs_uuid, 'hostname', hostname) bs_ops.reconnect_backup_storage(bs_uuid) if ps_uuid: ps_ops.delete_primary_storage(ps_uuid) if host_sns_topic_uuid: zwt_ops.delete_sns_topic(host_sns_topic_uuid) if my_sns_topic_uuid: zwt_ops.delete_sns_topic(my_sns_topic_uuid) if event_list: for event_uuid in event_list: zwt_ops.unsubscribe_event(event_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 vm, bss, host, ENABLE, infoType if vm: vm.clean() bs_ops.change_backup_storage_state(bss[0].uuid, ENABLE) bs_ops.update_image_store_backup_storage_info(bss[0].uuid, infoType, host) bs_ops.reconnect_backup_storage(bss[0].uuid)
def error_cleanup(): global email_endpoint_uuid,email_platform_uuid,my_sns_topic_uuid,host_sns_topic_uuid,ps_uuid,hostname,host_management_ip,host_status,bs_type,bs_status,event_list if host_status == 'Disconnected': host_ops.update_host(host_uuid, 'managementIp', host_management_ip) host_ops.reconnect_host(host_uuid) if bs_status == 'Disconnected': if bs_type == res_ops.IMAGE_STORE_BACKUP_STORAGE: bs_ops.update_image_store_backup_storage_info(bs_uuid, 'hostname', hostname) bs_ops.reconnect_backup_storage(bs_uuid) elif bs_type == res_ops.SFTP_BACKUP_STORAGE: bs_ops.update_sftp_backup_storage_info(bs_uuid, 'hostname', hostname) bs_ops.reconnect_backup_storage(bs_uuid) if ps_uuid: ps_ops.delete_primary_storage(ps_uuid) if host_sns_topic_uuid: zwt_ops.delete_sns_topic(host_sns_topic_uuid) if my_sns_topic_uuid: zwt_ops.delete_sns_topic(my_sns_topic_uuid) if event_list: for event_uuid in event_list: zwt_ops.unsubscribe_event(event_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 test(): global vm_inv,host_name, host_uuid, host_management_ip, vm_ip, bs_name, bs_uuid test_util.test_dsc('Create test vm to test zstack upgrade by -u.') image_name = os.environ.get('imageTestAlarm_230_mn') iso_path = os.environ.get('iso_path') zstack_latest_version = os.environ.get('zstackLatestVersion') zstack_latest_path = os.environ.get('zstackLatestInstaller') vm_name = os.environ.get('vmName') + image_name upgrade_script_path = os.environ.get('upgradeScript') vm_inv = test_stub.create_vm_scenario(image_name, vm_name) vm_ip = vm_inv.vmNics[0].ip test_lib.lib_wait_target_up(vm_ip, 22) #vm_ip = '172.20.197.159' os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = vm_ip test_stub.make_ssh_no_password(vm_ip, tmp_file) test_util.test_logger('Update MN IP') test_stub.update_mn_hostname(vm_ip, tmp_file) test_stub.update_mn_ip(vm_ip, tmp_file) test_stub.start_mn(vm_ip, tmp_file) test_util.test_logger('Update host management IP and reconnect host') host_name = 'Host-1' cond1 = res_ops.gen_query_conditions('name', '=', host_name) test2 = res_ops.query_resource(res_ops.HOST, cond1) test_util.test_logger('aaaaa %s' % test2) #host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].inventories[0] management_ip = vm_ip host_uuid = scen_ops.query_resource(management_ip, res_ops.HOST, cond1).inventories[0].uuid print 'test = ' print host_uuid host_management_ip = vm_ip host_ops.update_host(host_uuid, 'managementIp', host_management_ip) host_ops.reconnect_host(host_uuid) test_util.test_logger('Update bs IP and reconnect bs') bs_name = 'BS-1' cond2 = res_ops.gen_query_conditions('name', '=', bs_name) #bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, conditions)[0].inventories[0].uuid bs_uuid = scen_ops.query_resource(management_ip, res_ops.BACKUP_STORAGE, cond2).inventories[0].uuid bs_ip = vm_ip bs_ops.update_image_store_backup_storage_info(bs_uuid, 'hostname', bs_ip) bs_ops.reconnect_backup_storage(bs_uuid) #test_stub.check_installation(vm_ip, tmp_file) test_util.test_logger('Upgrade zstack to latest') test_stub.update_iso(vm_ip, tmp_file, iso_path, upgrade_script_path) test_stub.upgrade_zstack(vm_ip, zstack_latest_path, tmp_file) test_stub.check_zstack_version(vm_ip, tmp_file, zstack_latest_version) test_stub.start_mn(vm_ip, tmp_file) test_stub.check_installation(vm_ip, tmp_file) os.system('rm -f %s' % tmp_file) test_stub.destroy_vm_scenario(vm_inv.uuid) test_util.test_pass('ZStack upgrade Test Success')
def test(): global email_endpoint_uuid, email_platform_uuid, my_sns_topic_uuid, host_sns_topic_uuid, ps_uuid, hostname, host_management_ip, host_uuid, host_status, bs_uuid, bs_type, bs_status bs_cond = res_ops.gen_query_conditions('status', '=', 'Connected') bs_list = res_ops.query_resource(res_ops.BACKUP_STORAGE, bs_cond) for bss in bs_list: if bss.type == res_ops.SFTP_BACKUP_STORAGE: bs_uuid = bss.uuid bs_type = bss.type hostname = bss.hostname break elif bss.type == res_ops.IMAGE_STORE_BACKUP_STORAGE: bs_uuid = bss.uuid bs_type = bss.type hostname = bss.hostname break else: test_util.test_skip('No match backupStorage,test skip') 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) host_sns_topic = zwt_ops.create_sns_topic('host_topic') host_sns_topic_uuid = host_sns_topic.uuid zwt_ops.subscribe_sns_topic(host_sns_topic_uuid, email_endpoint_uuid) ps_actions = [{"actionUuid": my_sns_topic_uuid, "actionType": "sns"}] ps_namespace = 'ZStack/PrimaryStorage' ps_disconnected = 'PrimaryStorageDisconnected' ps_event_sub_uuid = zwt_ops.subscribe_event(ps_namespace, ps_disconnected, ps_actions).uuid event_list.append(ps_event_sub_uuid) bs_actions = [{"actionUuid": my_sns_topic_uuid, "actionType": "sns"}] bs_namespace = 'ZStack/BackupStorage' bs_disconnected = 'BackupStorageDisconnected' bs_event_sub_uuid = zwt_ops.subscribe_event(bs_namespace, bs_disconnected, bs_actions).uuid event_list.append(bs_event_sub_uuid) host_actions = [{"actionUuid": host_sns_topic_uuid, "actionType": "sns"}] host_namespace = 'ZStack/Host' host_status_changed = 'HostStatusChanged' host_status_labels = [{ "key": "NewStatus", "op": "Equal", "value": "Disconnected" }] host_status_event_sub_uuid = zwt_ops.subscribe_event( host_namespace, host_status_changed, host_actions, host_status_labels).uuid event_list.append(host_status_event_sub_uuid) host_disconnected = 'HostDisconnected' host_disconnected_event_sub_uuid = zwt_ops.subscribe_event( host_namespace, host_disconnected, host_actions).uuid event_list.append(host_disconnected_event_sub_uuid) if zwt_ops.check_sns_email(pop_server, username, password, ps_disconnected, ps_event_sub_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_sns_email(pop_server, username, password, bs_disconnected, bs_event_sub_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_sns_email(pop_server, username, password, host_status_changed, host_status_event_sub_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_sns_email(pop_server, username, password, host_disconnected, host_disconnected_event_sub_uuid): test_util.test_fail('email already exsist before test') # Disconnected ps ,bs and host zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid primary_storage_option = test_util.PrimaryStorageOption() primary_storage_option.set_type('nfs') primary_storage_option.set_zone_uuid(zone_uuid) primary_storage_option.set_name('test_nfs_ps') primary_storage_option.set_url('222.222.222.222/nfs/') try: ps_uuid = ps_ops.create_nfs_primary_storage( primary_storage_option).uuid ps_ops.reconnect_primary_storage(ps_uuid) except: pass if bs_type == res_ops.IMAGE_STORE_BACKUP_STORAGE: bs_ops.update_image_store_backup_storage_info(bs_uuid, 'hostname', '222.222.222.222') try: bs_ops.reconnect_backup_storage(bs_uuid) except: cond = res_ops.gen_query_conditions('uuid', '=', bs_uuid) bs_status = res_ops.query_resource( res_ops.IMAGE_STORE_BACKUP_STORAGE, cond)[0].status elif bs_type == res_ops.SFTP_BACKUP_STORAGE: bs_ops.update_sftp_backup_storage_info(bs_uuid, 'hostname', '222.222.222.222') try: bs_ops.reconnect_backup_storage(bs_uuid) except: cond = res_ops.gen_query_conditions('uuid', '=', bs_uuid) bs_status = res_ops.query_resource(res_ops.SFTP_BACKUP_STORAGE, cond)[0].status host_cond = res_ops.gen_query_conditions('status', '=', 'Connected') host = res_ops.query_resource_with_num(res_ops.HOST, host_cond, start=0, limit=1)[0] host_uuid = host.uuid host_management_ip = host.managementIp host_ops.update_host(host_uuid, 'managementIp', '222.222.222.222') try: host_ops.reconnect_host(host_uuid) except: cond = res_ops.gen_query_conditions('uuid', '=', host_uuid) bs_status = res_ops.query_resource(res_ops.HOST, cond)[0].status # wait for send email time.sleep(60) ps_ops.delete_primary_storage(ps_uuid) if hostname: if bs_type == res_ops.IMAGE_STORE_BACKUP_STORAGE: bs_ops.update_image_store_backup_storage_info( bs_uuid, 'hostname', hostname) bs_ops.reconnect_backup_storage(bs_uuid) elif bs_type == res_ops.SFTP_BACKUP_STORAGE: bs_ops.update_sftp_backup_storage_info(bs_uuid, 'hostname', hostname) bs_ops.reconnect_backup_storage(bs_uuid) host_ops.update_host(host_uuid, 'managementIp', host_management_ip) host_ops.reconnect_host(host_uuid) zwt_ops.delete_sns_topic(host_sns_topic_uuid) zwt_ops.delete_sns_topic(my_sns_topic_uuid) for event_uuid in event_list: zwt_ops.unsubscribe_event(event_uuid) zwt_ops.delete_sns_application_endpoint(email_endpoint_uuid) zwt_ops.delete_sns_application_platform(email_platform_uuid) check_1 = zwt_ops.check_sns_email(pop_server, username, password, ps_disconnected, ps_event_sub_uuid) check_2 = zwt_ops.check_sns_email(pop_server, username, password, bs_disconnected, bs_event_sub_uuid) check_3 = zwt_ops.check_sns_email(pop_server, username, password, host_status_changed, host_status_event_sub_uuid) check_4 = zwt_ops.check_sns_email(pop_server, username, password, host_disconnected, host_disconnected_event_sub_uuid) if check_1 and check_2 and check_3 and check_4: test_util.test_pass( 'test host ,bs, ps disconnected event with email success!') else: test_util.test_fail('cannt receive all event mail')
def test(): """ """ image_uuid = None flag1 = False flag2 = False global bss, vm, host test_util.test_dsc( 'test for creating root volume template with bss disconnected and disable' ) #create a new vm image_uuid = test_lib.lib_get_image_by_name("centos").uuid vm = test_stub.create_vm(image_uuid=image_uuid) # firstly,test for bss state disable # change backup storage state cond = res_ops.gen_query_conditions('state', '=', 'Enabled') bss = res_ops.query_resource_with_num(res_ops.BACKUP_STORAGE, cond, limit=1) bs_ops.change_backup_storage_state(bss[0].uuid, DISABLE) #prepare to create root volume template after buckup_storage change state to disable root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) image_option1 = test_util.ImageOption() image_option1.set_root_volume_uuid(root_volume_uuid) image_option1.set_name('image_for_bss_disconnected_test') image_option1.set_format('qcow2') image_option1.set_backup_storage_uuid_list([bss[0].uuid]) # image_option1.set_platform('Linux') # bs_type = bss[0].type vm.stop() # this API can only be invoke when vm is stopped try: img_ops.create_root_volume_template(image_option1) except: bs_ops.change_backup_storage_state(bss[0].uuid, ENABLE) flag1 = True # secondly,test for bss disconnected # change bss.host(IP address) to let bss disconnected. host = bss[0].hostname bs_ops.update_image_store_backup_storage_info(bss[0].uuid, infoType, infoValue) try: bs_ops.reconnect_backup_storage(bss[0].uuid) except: #can't reconnect the bs,so the bs'status is disconnected pass #create root volume template after buckup_storage change state to disable try: img_ops.create_root_volume_template(image_option1) except: bs_ops.update_image_store_backup_storage_info(bss[0].uuid, infoType, host) bs_ops.reconnect_backup_storage(bss[0].uuid) flag2 = True if flag1 and flag2: vm.clean() test_util.test_pass( "can't create root volume template,The test that create root volume template from root volume with ImageStoreBackupStorage server disconnected or disable is " "success! ") else: vm.clean() test_util.test_fail( "success create root image,The test that create root volume template from root volume with ImageStoreBackupStorage server disconnected or dieable is " "fail! ")
def test(): """ """ image_uuid = None flag1 = False flag2 = False global bss,vm,host test_util.test_dsc('test for creating root volume template with bss disconnected and disable') #create a new vm image_uuid = test_lib.lib_get_image_by_name("centos").uuid vm = test_stub.create_vm(image_uuid=image_uuid) # firstly,test for bss state disable # change backup storage state cond = res_ops.gen_query_conditions('state', '=', 'Enabled') bss = res_ops.query_resource_with_num(res_ops.BACKUP_STORAGE, cond, limit=1) bs_ops.change_backup_storage_state(bss[0].uuid,DISABLE) #prepare to create root volume template after buckup_storage change state to disable root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) image_option1 = test_util.ImageOption() image_option1.set_root_volume_uuid(root_volume_uuid) image_option1.set_name('image_for_bss_disconnected_test') image_option1.set_format('qcow2') image_option1.set_backup_storage_uuid_list([bss[0].uuid]) # image_option1.set_platform('Linux') # bs_type = bss[0].type vm.stop() # this API can only be invoke when vm is stopped try: img_ops.create_root_volume_template(image_option1) except: bs_ops.change_backup_storage_state(bss[0].uuid, ENABLE) flag1=True # secondly,test for bss disconnected # change bss.host(IP address) to let bss disconnected. host = bss[0].hostname bs_ops.update_image_store_backup_storage_info(bss[0].uuid, infoType, infoValue) try: bs_ops.reconnect_backup_storage(bss[0].uuid) except: #can't reconnect the bs,so the bs'status is disconnected pass #create root volume template after buckup_storage change state to disable try: img_ops.create_root_volume_template(image_option1) except: bs_ops.update_image_store_backup_storage_info(bss[0].uuid, infoType, host) bs_ops.reconnect_backup_storage(bss[0].uuid) flag2=True if flag1 and flag2: vm.clean() test_util.test_pass( "can't create root volume template,The test that create root volume template from root volume with ImageStoreBackupStorage server disconnected or disable is " "success! ") else: vm.clean() test_util.test_fail( "success create root image,The test that create root volume template from root volume with ImageStoreBackupStorage server disconnected or dieable is " "fail! ")
def test(): global vm_inv, host_name, host_uuid, host_management_ip, vm_ip, bs_name, bs_uuid, management_ip test_util.test_dsc('Create test vm to test zstack upgrade by -u.') image_name = os.environ.get('imageTestAlarm_230_mn') iso_path = os.environ.get('iso_path') #iso_21_path = os.environ.get('iso_21_path') zstack_latest_version = os.environ.get('zstackLatestVersion') zstack_latest_path = os.environ.get('zstackLatestInstaller') vm_name = os.environ.get('vmName') upgrade_script_path = os.environ.get('upgradeScript') vm_inv = test_stub.create_vm_scenario(image_name, vm_name) vm_ip = vm_inv.vmNics[0].ip test_lib.lib_wait_target_up(vm_ip, 22) test_util.test_dsc('vm_ip change to environ management_node_ip') os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = vm_ip test_stub.make_ssh_no_password(vm_ip, tmp_file) test_util.test_logger('Update MN IP') test_stub.update_mn_hostname(vm_ip, tmp_file) test_stub.update_mn_ip(vm_ip, tmp_file) test_stub.start_mn(vm_ip, tmp_file) time.sleep(400) test_util.test_logger('Update host management IP and reconnect host') host_name = 'Host-1' management_ip = vm_ip cond1 = res_ops.gen_query_conditions('name', '=', host_name) #host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].inventories[0].uuid host_uuid = scen_ops.query_resource(management_ip, res_ops.HOST, cond1).inventories[0].uuid host_management_ip = vm_ip host_ops.update_host(host_uuid, 'managementIp', host_management_ip) host_ops.reconnect_host(host_uuid) test_util.test_logger('Update bs IP and reconnect bs') bs_name = 'BS-1' cond2 = res_ops.gen_query_conditions('name', '=', bs_name) #bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, conditions)[0].inventories[0].uuid bs_uuid = scen_ops.query_resource(management_ip, res_ops.BACKUP_STORAGE, cond2).inventories[0].uuid bs_ip = vm_ip bs_ops.update_image_store_backup_storage_info(bs_uuid, 'hostname', bs_ip) bs_ops.reconnect_backup_storage(bs_uuid) #test_stub.check_installation(vm_ip, tmp_file) test_util.test_logger('Upgrade zstack to latest') test_stub.update_iso(vm_ip, tmp_file, iso_path, upgrade_script_path) #test_stub.updatei_21_iso(vm_ip, tmp_file, iso_21_path, upgrade_script_path) test_stub.upgrade_zstack(vm_ip, zstack_latest_path, tmp_file) test_stub.check_zstack_version(vm_ip, tmp_file, zstack_latest_version) test_stub.start_mn(vm_ip, tmp_file) test_stub.check_mn_running(vm_ip, tmp_file) #test_stub.check_installation(vm_ip, tmp_file) #check alarm update: test_util.test_dsc('check if alarm is update') all_alarm_list = scen_ops.query_resource(vm_ip, res_ops.ALARM) if len(all_alarm_list.inventories) <= 1: test_util.test_fail('update alarm failed.') all_endpoint_list = scen_ops.query_resource(vm_ip, res_ops.SNS_EMAIL_ENDPOINT) if len(all_endpoint_list.inventories) <= 1: test_util.test_fail('update endpoints failed') #check alarm email send test_util.test_dsc('check if alarm email is send') flag = False times = 5 while times > 0: cond3 = res_ops.gen_query_conditions('status', '=', 'Alarm') alarm_list = scen_ops.query_resource(vm_ip, res_ops.ALARM, cond3).inventories #server = 'pop3.zstack.io' #email = '*****@*****.**' #password = '******' server = os.environ.get('receive_pop3server') email = os.environ.get('receive_email') password = os.environ.get('receive_password') for alarm in alarm_list: if True == flag: break flag = zwt_ops.check_sns_email(server, email, password, alarm.metricName, alarm.uuid) if True == flag: break time.sleep(60) times = times - 1 os.system('rm -f %s' % tmp_file) test_stub.destroy_vm_scenario(vm_inv.uuid) if True == flag: test_util.test_pass('ZStack upgrade Test Success') else: test_util.test_fail('did\'n find alarm email.')
def test(): global email_endpoint_uuid,email_platform_uuid,my_sns_topic_uuid,host_sns_topic_uuid,ps_uuid,hostname,host_management_ip,host_uuid,host_status,bs_uuid,bs_type,bs_status bs_cond = res_ops.gen_query_conditions('status', '=', 'Connected') bs_list = res_ops.query_resource(res_ops.BACKUP_STORAGE, bs_cond) for bss in bs_list: if bss.type ==res_ops.SFTP_BACKUP_STORAGE: bs_uuid =bss.uuid bs_type =bss.type hostname = bss.hostname break elif bss.type == res_ops.IMAGE_STORE_BACKUP_STORAGE: bs_uuid=bss.uuid bs_type=bss.type hostname = bss.hostname break else: test_util.test_skip('No match backupStorage,test skip') 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) host_sns_topic = zwt_ops.create_sns_topic('host_topic') host_sns_topic_uuid = host_sns_topic.uuid zwt_ops.subscribe_sns_topic(host_sns_topic_uuid, email_endpoint_uuid) ps_actions = [{"actionUuid": my_sns_topic_uuid, "actionType": "sns"}] ps_namespace = 'ZStack/PrimaryStorage' ps_disconnected = 'PrimaryStorageDisconnected' ps_event_sub_uuid = zwt_ops.subscribe_event(ps_namespace, ps_disconnected, ps_actions).uuid event_list.append(ps_event_sub_uuid) bs_actions = [{"actionUuid": my_sns_topic_uuid, "actionType": "sns"}] bs_namespace = 'ZStack/BackupStorage' bs_disconnected = 'BackupStorageDisconnected' bs_event_sub_uuid = zwt_ops.subscribe_event(bs_namespace, bs_disconnected, bs_actions).uuid event_list.append(bs_event_sub_uuid) host_actions = [{"actionUuid": host_sns_topic_uuid, "actionType": "sns"}] host_namespace = 'ZStack/Host' host_status_changed = 'HostStatusChanged' host_status_labels = [{"key": "NewStatus", "op": "Equal", "value": "Disconnected"}] host_status_event_sub_uuid = zwt_ops.subscribe_event(host_namespace, host_status_changed, host_actions, host_status_labels).uuid event_list.append(host_status_event_sub_uuid) host_disconnected = 'HostDisconnected' host_disconnected_event_sub_uuid = zwt_ops.subscribe_event(host_namespace, host_disconnected, host_actions).uuid event_list.append(host_disconnected_event_sub_uuid) if zwt_ops.check_sns_email(pop_server, username, password, ps_disconnected, ps_event_sub_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_sns_email(pop_server, username, password, bs_disconnected, bs_event_sub_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_sns_email(pop_server, username, password, host_status_changed, host_status_event_sub_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_sns_email(pop_server, username, password, host_disconnected, host_disconnected_event_sub_uuid): test_util.test_fail('email already exsist before test') # Disconnected ps ,bs and host zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid primary_storage_option = test_util.PrimaryStorageOption() primary_storage_option.set_type('nfs') primary_storage_option.set_zone_uuid(zone_uuid) primary_storage_option.set_name('test_nfs_ps') primary_storage_option.set_url('222.222.222.222/nfs/') try: ps_uuid = ps_ops.create_nfs_primary_storage(primary_storage_option).uuid ps_ops.reconnect_primary_storage(ps_uuid) except: pass if bs_type == res_ops.IMAGE_STORE_BACKUP_STORAGE: bs_ops.update_image_store_backup_storage_info(bs_uuid, 'hostname', '222.222.222.222') try: bs_ops.reconnect_backup_storage(bs_uuid) except: cond = res_ops.gen_query_conditions('uuid', '=', bs_uuid) bs_status = res_ops.query_resource(res_ops.IMAGE_STORE_BACKUP_STORAGE, cond)[0].status elif bs_type == res_ops.SFTP_BACKUP_STORAGE: bs_ops.update_sftp_backup_storage_info(bs_uuid,'hostname','222.222.222.222') try: bs_ops.reconnect_backup_storage(bs_uuid) except: cond=res_ops.gen_query_conditions('uuid','=',bs_uuid) bs_status=res_ops.query_resource(res_ops.SFTP_BACKUP_STORAGE,cond)[0].status host_cond = res_ops.gen_query_conditions('status', '=', 'Connected') host = res_ops.query_resource_with_num(res_ops.HOST, host_cond, start=0, limit=1)[0] host_uuid = host.uuid host_management_ip = host.managementIp host_ops.update_host(host_uuid, 'managementIp', '222.222.222.222') try: host_ops.reconnect_host(host_uuid) except: cond = res_ops.gen_query_conditions('uuid', '=', host_uuid) bs_status = res_ops.query_resource(res_ops.HOST, cond)[0].status # wait for send email time.sleep(120) ps_ops.delete_primary_storage(ps_uuid) if hostname: if bs_type == res_ops.IMAGE_STORE_BACKUP_STORAGE: bs_ops.update_image_store_backup_storage_info(bs_uuid, 'hostname', hostname) bs_ops.reconnect_backup_storage(bs_uuid) elif bs_type == res_ops.SFTP_BACKUP_STORAGE: bs_ops.update_sftp_backup_storage_info(bs_uuid, 'hostname', hostname) bs_ops.reconnect_backup_storage(bs_uuid) host_ops.update_host(host_uuid, 'managementIp', host_management_ip) host_ops.reconnect_host(host_uuid) zwt_ops.delete_sns_topic(host_sns_topic_uuid) zwt_ops.delete_sns_topic(my_sns_topic_uuid) for event_uuid in event_list: zwt_ops.unsubscribe_event(event_uuid) zwt_ops.delete_sns_application_endpoint(email_endpoint_uuid) zwt_ops.delete_sns_application_platform(email_platform_uuid) check_1 = zwt_ops.check_sns_email(pop_server, username, password, ps_disconnected, ps_event_sub_uuid) check_2 = zwt_ops.check_sns_email(pop_server, username, password, bs_disconnected, bs_event_sub_uuid) check_3 = zwt_ops.check_sns_email(pop_server, username, password, host_status_changed, host_status_event_sub_uuid) check_4 = zwt_ops.check_sns_email(pop_server, username, password, host_disconnected, host_disconnected_event_sub_uuid) if check_1 and check_2 and check_3 and check_4: test_util.test_pass('test host ,bs, ps disconnected event with email success!') else: test_util.test_fail('cannt receive all event mail')