def test(): global vm vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_net') l3_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vm("test_resize_vm", image_name, l3_name) test_obj_dict.add_vm(vm) vm.check() vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size volume_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid set_size = 1024*1024*1024*5 vol_ops.resize_volume(volume_uuid, set_size) vm.update() vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size if set_size != vol_size_after: test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after) bs_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm) image_option = test_util.ImageOption() image_option.set_root_volume_uuid(volume_uuid) image_option.set_name('image_resize_template') image_option.set_backup_storage_uuid_list([bs_list[0].uuid]) image = img_ops.create_root_volume_template(image_option) new_vm = test_stub.create_vm("test_vm_after_resize", 'image_resize_template', l3_name) test_obj_dict.add_vm(new_vm) new_vm.check() new_volume_uuid = test_lib.lib_get_root_volume_uuid(new_vm.get_vm()) vol_size_after = test_lib.lib_get_root_volume(new_vm.get_vm()).size if set_size != vol_size_after: test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Create Template for Resize VM Test Success')
def test(): test_util.test_dsc('Create original vm') vm = test_stub.create_vlan_vm() test_obj_dict.add_vm(vm) vm1 = test_stub.create_vlan_vm() test_obj_dict.add_vm(vm1) root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) test_util.test_dsc('Stop vm before create snapshot.') vm.stop() test_util.test_dsc('create snapshot and check') snapshots = test_obj_dict.get_volume_snapshot(root_volume_uuid) snapshots.set_utility_vm(vm1) vm1.check() snapshots.create_snapshot('create_root_snapshot1') volume2 = snapshots.get_current_snapshot().create_data_volume('data_volume_for_root') test_obj_dict.add_volume(volume2) snapshots2 = test_obj_dict.get_volume_snapshot(volume2.get_volume().uuid) snapshots2.set_utility_vm(vm1) snapshots2.create_snapshot('create_root_snapshot2') snapshots2.use_snapshot(snapshots2.get_current_snapshot()) snapshots2.backup_snapshot(snapshots2.get_current_snapshot()) snapshots2.delete_backuped_snapshot(snapshots2.get_current_snapshot()) volume2.attach(vm) volume2.detach() snapshots.delete_snapshot(snapshots.get_current_snapshot()) test_util.test_dsc('start vm') vm.start() test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Do snapshot ops on VM root volume with VM ops successfully')
def test(): if conf_ops.get_global_config_value('vm', 'deletionPolicy') == 'Direct': test_util.test_skip('vm delete_policy is Direct, skip test.') return test_util.test_dsc('Create original vm') vm = test_stub.create_vm(vm_name='basic-test-vm') test_obj_dict.add_vm(vm) root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) test_util.test_dsc('Stop vm before create snapshot.') vm.stop() test_util.test_dsc('create snapshot and check') snapshots = test_obj_dict.get_volume_snapshot(root_volume_uuid) snapshots.set_utility_vm(vm) snapshots.create_snapshot('create_root_snapshot1') test_util.test_dsc('start vm') vm.destroy() vm.recover() vm.start() vm.destroy() vm.expunge() test_obj_dict.rm_vm(vm) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass( 'Do snapshot ops on VM root volume with VM ops successfully')
def test(): if res_ops.query_resource(res_ops.SFTP_BACKUP_STORAGE): test_util.test_skip("sftp backupstorage doesn't support for clone test. Skip test") global vm vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_net') l3_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vm("test_resize_vm", image_name, l3_name) test_obj_dict.add_vm(vm) vm.check() vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size volume_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid set_size = 1024*1024*1024*5 vol_ops.resize_volume(volume_uuid, set_size) vm.update() vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size if set_size != vol_size_after: test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after) new_vm = vm.clone(['vm_clone'])[0] test_obj_dict.add_vm(new_vm) new_volume_uuid = test_lib.lib_get_root_volume_uuid(new_vm.get_vm()) vol_size_after = test_lib.lib_get_root_volume(new_vm.get_vm()).size if set_size != vol_size_after: test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Resize VM Snapshot Test Success')
def test(): global vm vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_net') l3_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vm("test_resize_vm", image_name, l3_name) test_obj_dict.add_vm(vm) vm.check() vm.stop() vm.check() vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size volume_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid set_size = 1024 * 1024 * 1024 * 5 vol_ops.resize_volume(volume_uuid, set_size) vm.update() vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size if set_size != vol_size_after: test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after) new_vm = vm.clone(['vm_clone'])[0] test_obj_dict.add_vm(new_vm) new_volume_uuid = test_lib.lib_get_root_volume_uuid(new_vm.get_vm()) vol_size_after = test_lib.lib_get_root_volume(new_vm.get_vm()).size if set_size != vol_size_after: test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Resize VM Snapshot Test Success')
def test(): if res_ops.query_resource(res_ops.SFTP_BACKUP_STORAGE): test_util.test_skip( "sftp backupstorage doesn't support for clone test. Skip test") global vm vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_net') l3_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vm("test_resize_vm", image_name, l3_name) test_obj_dict.add_vm(vm) vm.check() vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size volume_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid set_size = 1024 * 1024 * 1024 * 5 vol_ops.resize_volume(volume_uuid, set_size) vm.update() vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size if set_size != vol_size_after: test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after) new_vm = vm.clone(['vm_clone'])[0] test_obj_dict.add_vm(new_vm) new_volume_uuid = test_lib.lib_get_root_volume_uuid(new_vm.get_vm()) vol_size_after = test_lib.lib_get_root_volume(new_vm.get_vm()).size if set_size != vol_size_after: test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Resize VM Snapshot Test Success')
def operate_vm_parall(self, vm_uuid): try: #test_lib.lib_get_root_volume_uuid(rebootvms.vms[0]) vm=test_lib.lib_get_vm_by_uuid(vm_uuid) root_volume_uuid=test_lib.lib_get_root_volume_uuid(vm) sp_option = test_util.SnapshotOption() sp_option.set_name('simple_schduler_snapshot') sp_option.set_volume_uuid(root_volume_uuid) schd = vol_ops.create_snapshot_scheduler(sp_option, 'simple', 'simple_create_snapshot_scheduler', 0, 1, 1) except: self.exc_info.append(sys.exc_info())
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid test_obj_dict.add_vm(vm) vm.check() root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) test_util.test_dsc('create snapshot and check') snapshots = test_obj_dict.get_volume_snapshot(root_volume_uuid) snapshots.set_utility_vm(vm) vm.check() snapshots.create_snapshot('create_root_snapshot1') snapshots.check() snapshot1 = snapshots.get_current_snapshot() host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'disable') test_stub.disable_all_pss() if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to running when PS change to disable state') vm.set_state(vm_header.RUNNING) vm.check() vm.stop() vm.check() test_util.test_dsc('Use snapshot, volume and check') snapshots.use_snapshot(snapshot1) snapshots.check() #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) vm.destroy() test_util.test_pass('PS disable mode Test Success')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid test_obj_dict.add_vm(vm) vm.check() root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) test_util.test_dsc('create snapshot and check') snapshots = test_obj_dict.get_volume_snapshot(root_volume_uuid) snapshots.set_utility_vm(vm) vm.check() snapshots.create_snapshot('create_root_snapshot1') snapshots.check() snapshot1 = snapshots.get_current_snapshot() host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'disable') test_stub.disable_all_pss() if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail( 'VM is expected to running when PS change to disable state') vm.set_state(vm_header.RUNNING) vm.check() vm.stop() vm.check() test_util.test_dsc('Use snapshot, volume and check') snapshots.use_snapshot(snapshot1) snapshots.check() #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) vm.destroy() test_util.test_pass('PS disable mode Test Success')
def test(): vm = test_stub.create_vlan_vm() #test_obj_dict.add_vm(vm) backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm) for bs in backup_storage_list: if bs.type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE: break #if bs.type == inventory.SFTP_BACKUP_STORAGE_TYPE: # break #if bs.type == inventory.CEPH_BACKUP_STORAGE_TYPE: # break else: vm.destroy() vm.expunge() test_util.test_skip('Not find image store type backup storage.') new_vms = vm.clone(vm_names) for new_vm in new_vms: test_obj_dict.add_vm(new_vm) if len(new_vms) != len(vm_names): test_util.test_fail('only %s VMs have been cloned, which is less than required: %s' % (len(new_vms), vm_names)) for new_vm in new_vms: new_vm = new_vm.get_vm() try: vm_names.remove(new_vm.name) test_util.test_logger('VM:%s name: %s is found' % (new_vm.uuid, new_vm.name)) except: test_util.test_fail('%s vm name: %s is not in list: %s' % (new_vm.uuid, new_vm.name, vm_names)) vm.destroy() check_imf2_cmd = "find /|grep imf|grep %s" % (test_lib.lib_get_root_volume_uuid(vm.get_vm())) host = test_lib.lib_find_host_by_vm(vm.get_vm()) ret, output, stderr = ssh.execute(check_imf2_cmd, host.managementIp, "root", "password", False, 22) test_util.test_logger('expect imf2 exist: %s,%s' % (output, ret)) if ret != 0: test_util.test_fail('imf2 is expected to exist') vm.expunge() ret, output, stderr = ssh.execute(check_imf2_cmd, host.managementIp, "root", "password", False, 22) test_util.test_logger('expect imf2 not exist: %s,%s' % (output, ret)) if ret == 0: test_util.test_fail('imf2 is expected to be deleted') test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Clone VM Test Success')
def check_operation_result(self): time.sleep(30) start_msg_mismatch = 1 for k in range(0, 1000): for i in range(0, self.i): vm_stat_flag=0 vm=test_lib.lib_get_vm_by_uuid(self.vms[i].uuid) root_volume_uuid=test_lib.lib_get_root_volume_uuid(vm) if not test_lib.lib_find_in_local_management_server_log(self.date+k, '[msg send]: {"org.zstack.header.volume.CreateVolumeSnapshotMsg', self.vms[i].uuid): test_util.test_warn('CreateVolumeSnapshotMsg is expected to execute at %s' % (self.date+k)) vm_stat_flag=1 start_msg_mismatch += 1 if vm_stat_flag == 0: break if start_msg_mismatch > 1000: test_util.test_fail('%s of 1000 CreateVolumeSnapshotMsg not executed at expected timestamp' % (start_msg_mismatch))
def test(): global vm vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_net') l3_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vm("test_resize_vm", image_name, l3_name) test_obj_dict.add_vm(vm) vm.check() vm.stop() vm.check() vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size volume_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid set_size = 1024 * 1024 * 1024 * 5 vol_ops.resize_volume(volume_uuid, set_size) vm.update() vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size if set_size != vol_size_after: test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after) bs_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm) image_option = test_util.ImageOption() image_option.set_root_volume_uuid(volume_uuid) image_option.set_name('image_resize_template') image_option.set_backup_storage_uuid_list([bs_list[0].uuid]) image = img_ops.create_root_volume_template(image_option) new_vm = test_stub.create_vm("test_vm_after_resize", 'image_resize_template', l3_name) test_obj_dict.add_vm(new_vm) new_vm.check() new_vm.stop() new_vm.check() new_volume_uuid = test_lib.lib_get_root_volume_uuid(new_vm.get_vm()) vol_size_after = test_lib.lib_get_root_volume(new_vm.get_vm()).size if set_size != vol_size_after: test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Create Template for Resize VM Test Success')
def test(): test_util.test_dsc('Create test vm as utility vm') vm = test_stub.create_vr_vm('migrate_vm_with_snapshot', 'imageName_net', 'l3VlanNetwork2') test_obj_dict.add_vm(vm) root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) test_util.test_dsc('create snapshot and check') snapshots = test_obj_dict.get_volume_snapshot(root_volume_uuid) snapshots.set_utility_vm(vm) times = 22 while times > 0: snapshot = snapshots.create_snapshot('create_snapshot_%s' % (44 - times)) if times == 11: snapshot1 = snapshots.get_current_snapshot() times = times - 1 test_util.test_dsc('migrate vm and check snapshot') test_stub.migrate_vm_to_random_host(vm) vm.check() snapshots.check() vm.stop() snapshots.use_snapshot(snapshot1) vm.start() snapshots.check() vm.check() test_util.test_dsc('migrate vm and check snapshot') test_stub.migrate_vm_to_random_host(vm) vm.check() snapshots.check() snapshots.delete() test_obj_dict.rm_volume_snapshot(snapshots) vm.destroy() test_util.test_pass( 'Create deep Snapshot chain with VM migration test Success')
def test(): test_util.test_dsc('Create test vm as utility vm') vm = test_stub.create_vm(vm_name = 'migrate_vm_with_snapshot') test_obj_dict.add_vm(vm) root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) test_util.test_dsc('create snapshot and check') snapshots = test_obj_dict.get_volume_snapshot(root_volume_uuid) snapshots.set_utility_vm(vm) times = 22 while times > 0 : vm.stop() snapshot = snapshots.create_snapshot('create_snapshot_%s' % (44 - times)) vm.start() if times == 11: snapshot1 = snapshots.get_current_snapshot() times = times - 1 test_util.test_dsc('migrate vm and check snapshot') test_stub.migrate_vm_to_random_host(vm, timeout=1200000) vm.check() snapshots.check() vm.stop() snapshots.use_snapshot(snapshot1) vm.start() snapshots.check() vm.check() test_util.test_dsc('migrate vm and check snapshot') test_stub.migrate_vm_to_random_host(vm, timeout=1200000) vm.check() snapshots.check() vm.destroy() snapshots.delete() test_obj_dict.rm_volume_snapshot(snapshots) test_util.test_pass('Create deep Snapshot chain with VM migration test Success')
def test(): if test_lib.lib_get_active_host_number() < 2: test_util.test_fail('Not available host to do maintenance, since there are not 2 hosts') vm = test_stub.create_vm(vm_name = 'migrate_stopped_vm_with_snapshot') host_uuid = vm.get_vm().hostUuid root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) test_obj_dict.add_vm(vm) test_util.test_dsc('Create volume for snapshot testing') disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_name('volume for snapshot testing') volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) #make sure utility vm is starting and running vm.check() volume.attach(vm) volume.detach() test_util.test_dsc('create snapshot and check') snapshots = test_obj_dict.get_volume_snapshot(volume.get_volume().uuid) snapshots.set_utility_vm(vm) snapshots.create_snapshot('create_snapshot1') snapshots.check() vm.stop() conditions = res_ops.gen_query_conditions('uuid', '!=', host_uuid) conditions = res_ops.gen_query_conditions('state', '=', host_header.ENABLED, conditions) conditions = res_ops.gen_query_conditions('status', '=', host_header.CONNECTED, conditions) rest_hosts = res_ops.query_resource(res_ops.HOST, conditions) target_host = random.choice(rest_hosts) test_util.test_dsc('migrate vm and volumes') vol_ops.migrate_volume(root_volume_uuid, target_host.uuid) vol_ops.migrate_volume(volume.get_volume().uuid, target_host.uuid) vm.start() vm.check() snapshots.check() snapshot1 = snapshots.get_current_snapshot() snapshots.create_snapshot('create_snapshot2') snapshots.check() snapshots.use_snapshot(snapshot1) snapshots.create_snapshot('create_snapshot1.1.1') snapshots.check() snapshots.use_snapshot(snapshot1) snapshots.create_snapshot('create_snapshot1.2.1') snapshots.check() snapshots.delete() test_obj_dict.rm_volume_snapshot(snapshots) volume.check() volume.delete() test_obj_dict.rm_volume(volume) vm.destroy() test_util.test_pass('Create Snapshot with VM migration test Success')
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 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(): test_util.test_dsc('Create test vm as utility vm') vm = test_stub.create_vr_vm('migrate_vm_with_snapshot', 'imageName_net', 'l3VlanNetwork2') test_obj_dict.add_vm(vm) vm.check() root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) test_util.test_dsc('create snapshot and check') snapshots = test_obj_dict.get_volume_snapshot(root_volume_uuid) snapshots.set_utility_vm(vm) snapshots.create_snapshot('create_snapshot1') snapshots.check() test_util.test_dsc('migrate vm and check snapshot') test_stub.migrate_vm_to_random_host(vm) vm.check() snapshots.check() snapshot1 = snapshots.get_current_snapshot() snapshots.create_snapshot('create_snapshot2') snapshots.check() snapshots.create_snapshot('create_snapshot3') snapshots.check() snapshot3 = snapshots.get_current_snapshot() vm.stop() snapshots.use_snapshot(snapshot1) vm.start() snapshots.create_snapshot('create_snapshot1.1.1') snapshots.check() snapshots.create_snapshot('create_snapshot1.1.2') snapshots.check() vm.stop() snapshots.use_snapshot(snapshot1) vm.start() snapshots.create_snapshot('create_snapshot1.2.1') snapshots.check() snapshot1_2_1 = snapshots.get_current_snapshot() snapshots.create_snapshot('create_snapshot1.2.2') snapshots.check() test_util.test_dsc('migrate vm and check snapshot') test_stub.migrate_vm_to_random_host(vm) vm.check() snapshots.check() vm.stop() snapshots.use_snapshot(snapshot3) vm.start() snapshots.check() snapshots.create_snapshot('create_snapshot4') snapshots.check() test_util.test_dsc('migrate vm and check snapshot') test_stub.migrate_vm_to_random_host(vm) vm.check() snapshots.check() test_util.test_dsc('Delete snapshot and check') snapshots.delete_snapshot(snapshot3) snapshots.check() test_util.test_dsc('migrate vm and check snapshot') test_stub.migrate_vm_to_random_host(vm) vm.check() snapshots.check() snapshots.delete_snapshot(snapshot1_2_1) snapshots.check() snapshots.delete() test_obj_dict.rm_volume_snapshot(snapshots) vm.destroy() test_util.test_pass('Create Snapshot with VM migration test Success')
def test(): vm = test_stub.create_user_vlan_vm() test_obj_dict.add_vm(vm) vm.check() vm_inv = vm.get_vm() vm_ip = vm_inv.vmNics[0].ip test_util.test_dsc('create test-file-1, test-file-2, test-file-3 and create snapshot1') num = 1 while num <= 3: cmd = 'touch /root/test-file-%s' % num rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) if rsp == False: test_util.test_fail('Fail to create test-file-%s in VM' % num) num = num + 1 root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) snapshots = test_obj_dict.get_volume_snapshot(root_volume_uuid) snapshots.set_utility_vm(vm) vm.check() snapshots.create_snapshot('create_root_snapshot1') test_util.test_dsc('delete test-file-1, create test-file-4, test-file-5 and create snapshot2') cmd = 'rm /root/test-file-1 || echo y' rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) if rsp == False: test_util.test_fail('Fail to delete test-file-1 in VM') num = 4 while num <= 5: cmd = 'touch /root/test-file-%s' % num rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) if rsp == False: test_util.test_fail('Fail to create test-file-%s in VM' % num) num = num + 1 root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) snapshots2 = test_obj_dict.get_volume_snapshot(root_volume_uuid) snapshots2.set_utility_vm(vm) vm.check() snapshots2.create_snapshot('create_root_snapshot2') test_util.test_dsc('delete test-file-2, test-file-4, create test-file-6 and create snapshot3') num_arr = [2, 4] for i in num_arr: cmd = 'rm /root/test-file-%s || echo y' % i rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) if rsp == False: test_util.test_fail('Fail to delete test-file-%s in VM' % i) cmd = 'touch /root/test-file-6' rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) if rsp == False: test_util.test_fail('Fail to create test-file-6 in VM') root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) snapshots3 = test_obj_dict.get_volume_snapshot(root_volume_uuid) snapshots3.set_utility_vm(vm) vm.check() snapshots3.create_snapshot('create_root_snapshot3') test_util.test_dsc('VM reinit') vm.stop() vm.reinit() vm.update() vm.check() vm.start() num = 1 while num <= 6: cmd = '[ -e /root/test-file-%s ] && echo yes || echo no' % num rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) if rsp == False: test_util.test_fail('test-file-%s should not exist' % num) num = num + 1 test_util.test_dsc('VM return to snapshot3') vm.stop() snapshots3.use_snapshot(snapshots.get_current_snapshot()) vm.start() vm.check() num_arr = [1, 2, 4] for i in num_arr: cmd = '[ -e /root/test-file-%s ] && echo yes || echo no' % i rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) if rsp == False: test_util.test_fail('test-file-%s should not exist' % i) num_arr = [3, 5, 6] for i in num_arr: cmd = '[ -e /root/test-file-%s ] && echo yes || echo no' % i rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) if rsp == False: test_util.test_fail('test-file-%s should exist' % i) vm.destroy() test_util.test_pass('Re-init VM Test Success')
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 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')
def test(): vm = test_stub.create_user_vlan_vm() test_obj_dict.add_vm(vm) vm.check() vm_inv = vm.get_vm() vm_ip = vm_inv.vmNics[0].ip test_util.test_dsc( 'create test-file-1, test-file-2, test-file-3 and create snapshot1') num = 1 while num <= 3: cmd = 'touch /root/test-file-%s' % num rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) if rsp == False: test_util.test_fail('Fail to create test-file-%s in VM' % num) num = num + 1 root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) snapshots = test_obj_dict.get_volume_snapshot(root_volume_uuid) snapshots.set_utility_vm(vm) vm.check() snapshots.create_snapshot('create_root_snapshot1') test_util.test_dsc( 'delete test-file-1, create test-file-4, test-file-5 and create snapshot2' ) cmd = 'rm /root/test-file-1 || echo y' rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) if rsp == False: test_util.test_fail('Fail to delete test-file-1 in VM') num = 4 while num <= 5: cmd = 'touch /root/test-file-%s' % num rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) if rsp == False: test_util.test_fail('Fail to create test-file-%s in VM' % num) num = num + 1 root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) snapshots2 = test_obj_dict.get_volume_snapshot(root_volume_uuid) snapshots2.set_utility_vm(vm) vm.check() snapshots2.create_snapshot('create_root_snapshot2') test_util.test_dsc( 'delete test-file-2, test-file-4, create test-file-6 and create snapshot3' ) num_arr = [2, 4] for i in num_arr: cmd = 'rm /root/test-file-%s || echo y' % i rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) if rsp == False: test_util.test_fail('Fail to delete test-file-%s in VM' % i) cmd = 'touch /root/test-file-6' rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) if rsp == False: test_util.test_fail('Fail to create test-file-6 in VM') root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) snapshots3 = test_obj_dict.get_volume_snapshot(root_volume_uuid) snapshots3.set_utility_vm(vm) vm.check() snapshots3.create_snapshot('create_root_snapshot3') test_util.test_dsc('VM reinit') vm.stop() vm.reinit() vm.update() vm.check() vm.start() vm.check() num = 1 while num <= 6: cmd = '[ -e /root/test-file-%s ] && echo yes || echo no' % num rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) if rsp == False: test_util.test_fail('test-file-%s should not exist' % num) num = num + 1 test_util.test_dsc('VM return to snapshot3') vm.stop() snapshots3.use_snapshot(snapshots.get_current_snapshot()) vm.start() vm.check() num_arr = [1, 2, 4] for i in num_arr: cmd = '[ -e /root/test-file-%s ] && echo yes || echo no' % i rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) if rsp == False: test_util.test_fail('test-file-%s should not exist' % i) num_arr = [3, 5, 6] for i in num_arr: cmd = '[ -e /root/test-file-%s ] && echo yes || echo no' % i rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) if rsp == False: test_util.test_fail('test-file-%s should exist' % i) vm.destroy() test_util.test_pass('Re-init VM Test Success')
def test(): test_util.test_dsc('Create test vm as utility vm') vm = test_stub.create_vr_vm('migrate_vm_with_snapshot', 'imageName_net', 'l3VlanNetwork2') test_obj_dict.add_vm(vm) vm.check() root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) test_util.test_dsc('create snapshot and check') snapshots = test_obj_dict.get_volume_snapshot(root_volume_uuid) snapshots.set_utility_vm(vm) snapshots.create_snapshot('create_snapshot1') snapshots.check() test_util.test_dsc('migrate vm and check snapshot') test_stub.migrate_vm_to_random_host(vm) vm.check() snapshots.check() snapshot1 = snapshots.get_current_snapshot() snapshots.create_snapshot('create_snapshot2') snapshots.check() snapshots.create_snapshot('create_snapshot3') snapshots.check() snapshot3 = snapshots.get_current_snapshot() vm.stop() snapshots.use_snapshot(snapshot1) vm.start() snapshots.create_snapshot('create_snapshot1.1.1') snapshots.check() snapshots.create_snapshot('create_snapshot1.1.2') snapshots.check() vm.stop() snapshots.use_snapshot(snapshot1) vm.start() snapshots.create_snapshot('create_snapshot1.2.1') snapshots.check() snapshot1_2_1 = snapshots.get_current_snapshot() snapshots.create_snapshot('create_snapshot1.2.2') snapshots.check() test_util.test_dsc('migrate vm and check snapshot') test_stub.migrate_vm_to_random_host(vm) vm.check() snapshots.check() vm.stop() snapshots.use_snapshot(snapshot3) vm.start() snapshots.check() snapshots.create_snapshot('create_snapshot4') snapshots.check() test_util.test_dsc('migrate vm and check snapshot') test_stub.migrate_vm_to_random_host(vm) vm.check() snapshots.check() test_util.test_dsc('Delete snapshot and check') snapshots.delete_snapshot(snapshot3) snapshots.check() test_util.test_dsc('migrate vm and check snapshot') test_stub.migrate_vm_to_random_host(vm) vm.check() snapshots.check() snapshots.delete_snapshot(snapshot1_2_1) snapshots.check() snapshots.delete() test_obj_dict.rm_volume_snapshot(snapshots) vm.destroy() test_util.test_pass('Create Snapshot with VM migration test Success')