def disable_forgery_protection(): starttime = time.time() ssh_client = SSHClient() logger.info('Turning off "allow_forgery_protection"') ssh_client.run_command( "sed -i \'s/allow_forgery_protection = true/allow_forgery_protection = false/\' " "/var/www/miq/vmdb/config/environments/production.rb") ssh_client.run_command("service evmserverd restart") ssh_client.close() timediff = time.time() - starttime logger.info( 'Turned off "allow_forgery_protection" in: {}'.format(timediff)) yield starttime = time.time() ssh_client = SSHClient() logger.info('Turning on "allow_forgery_protection"') ssh_client.run_command( "sed -i \'s/allow_forgery_protection = false/allow_forgery_protection = true/\' " "/var/www/miq/vmdb/config/environments/production.rb") ssh_client.run_command("service evmserverd restart") ssh_client.close() timediff = time.time() - starttime logger.info('Turned on "allow_forgery_protection" in: {}'.format(timediff))
def generate_version_files(): yield starttime = time.time() ssh_client = SSHClient() relative_path = os.path.relpath(str(results_path), str(os.getcwd())) relative_string = relative_path + '/{}*'.format(test_ts) directory_list = glob.glob(relative_string) for directory in directory_list: module_path = os.path.join(directory, 'version_info') if os.path.exists(str(module_path)): return else: os.mkdir(str(module_path)) generate_system_file(ssh_client, module_path) generate_processes_file(ssh_client, module_path) generate_gems_file(ssh_client, module_path) generate_rpms_file(ssh_client, module_path) timediff = time.time() - starttime logger.info('Generated all version files in {}'.format(timediff)) ssh_client.close()
def generate_version_files(): yield starttime = time.time() ssh_client = SSHClient() relative_path = os.path.relpath(str(results_path), str(os.getcwd())) # avoid importing outside perf testing from cfme.utils.smem_memory_monitor import test_ts relative_string = relative_path + f'/{test_ts}*' directory_list = glob.glob(relative_string) for directory in directory_list: module_path = os.path.join(directory, 'version_info') if os.path.exists(str(module_path)): return else: os.mkdir(str(module_path)) generate_system_file(ssh_client, module_path) generate_processes_file(ssh_client, module_path) generate_gems_file(ssh_client, module_path) generate_rpms_file(ssh_client, module_path) timediff = time.time() - starttime logger.info(f'Generated all version files in {timediff}') ssh_client.close()
def verify_revert_snapshot(full_test_vm, provider, soft_assert, register_event, request, active_snapshot=False): if provider.one_of(RHEVMProvider): # RHV snapshots have only description, no name snapshot1 = new_snapshot(full_test_vm, has_name=False) else: snapshot1 = new_snapshot(full_test_vm) full_template = getattr(provider.data.templates, 'full_template') # Define parameters of the ssh connection ssh_kwargs = { 'hostname': snapshot1.vm.provider.mgmt.get_ip_address(snapshot1.vm.name), 'username': credentials[full_template.creds]['username'], 'password': credentials[full_template.creds]['password'] } ssh_client = SSHClient(**ssh_kwargs) # We need to wait for ssh to become available on the vm, it can take a while. Without # this wait, the ssh command would fail with 'port 22 not available' error. # Easiest way to solve this is just mask the exception with 'handle_exception = True' # and wait for successful completition of the ssh command. # The 'fail_func' ensures we close the connection that failed with exception. # Without this, the connection would hang there and wait_for would fail with timeout. wait_for(lambda: ssh_client.run_command('touch snapshot1.txt').rc == 0, num_sec=400, delay=20, handle_exception=True, fail_func=ssh_client.close()) # Create first snapshot snapshot1.create() ssh_client.run_command('touch snapshot2.txt') # If we are not testing 'revert to active snapshot' situation, we create another snapshot if not active_snapshot: if provider.one_of(RHEVMProvider): snapshot2 = new_snapshot(full_test_vm, has_name=False) else: snapshot2 = new_snapshot(full_test_vm) snapshot2.create() # VM on RHV provider must be powered off before snapshot revert if provider.one_of(RHEVMProvider): full_test_vm.power_control_from_cfme(option=full_test_vm.POWER_OFF, cancel=False) full_test_vm.wait_for_vm_state_change( desired_state=full_test_vm.STATE_OFF, timeout=900) snapshot1.revert_to() # Wait for the snapshot to become active logger.info('Waiting for vm %s to become active', snapshot1.name) wait_for(lambda: snapshot1.active, num_sec=300, delay=20, fail_func=provider.browser.refresh) # VM state after revert should be OFF full_test_vm.wait_for_vm_state_change(desired_state=full_test_vm.STATE_OFF, timeout=720) # Let's power it ON again full_test_vm.power_control_from_cfme(option=full_test_vm.POWER_ON, cancel=False) full_test_vm.wait_for_vm_state_change(desired_state=full_test_vm.STATE_ON, timeout=900) soft_assert(full_test_vm.provider.mgmt.is_vm_running(full_test_vm.name), "vm not running") # Wait for successful ssh connection wait_for(lambda: ssh_client.run_command('test -e snapshot1.txt').rc == 0, num_sec=400, delay=20, handle_exception=True, fail_func=ssh_client.close()) try: result = ssh_client.run_command('test -e snapshot1.txt') assert not result.rc result = ssh_client.run_command('test -e snapshot2.txt') assert result.rc logger.info('Revert to snapshot %s successful', snapshot1.name) except: logger.exception('Revert to snapshot %s Failed', snapshot1.name) ssh_client.close()
def verify_revert_snapshot(full_test_vm, provider, soft_assert, register_event, request, active_snapshot=False): if provider.one_of(RHEVMProvider): # RHV snapshots have only description, no name snapshot1 = new_snapshot(full_test_vm, has_name=False) else: snapshot1 = new_snapshot(full_test_vm) full_template = getattr(provider.data.templates, 'full_template') # Define parameters of the ssh connection ssh_kwargs = { 'hostname': snapshot1.parent_vm.mgmt.ip, 'username': credentials[full_template.creds]['username'], 'password': credentials[full_template.creds]['password'] } ssh_client = SSHClient(**ssh_kwargs) # We need to wait for ssh to become available on the vm, it can take a while. Without # this wait, the ssh command would fail with 'port 22 not available' error. # Easiest way to solve this is just mask the exception with 'handle_exception = True' # and wait for successful completition of the ssh command. # The 'fail_func' ensures we close the connection that failed with exception. # Without this, the connection would hang there and wait_for would fail with timeout. wait_for(lambda: ssh_client.run_command('touch snapshot1.txt').success, num_sec=400, delay=20, handle_exception=True, fail_func=ssh_client.close(), message="Waiting for successful SSH connection") # Create first snapshot snapshot1.create() ssh_client.run_command('touch snapshot2.txt') # If we are not testing 'revert to active snapshot' situation, we create another snapshot if not active_snapshot: if provider.one_of(RHEVMProvider): snapshot2 = new_snapshot(full_test_vm, has_name=False) else: snapshot2 = new_snapshot(full_test_vm) snapshot2.create() # VM on RHV provider must be powered off before snapshot revert if provider.one_of(RHEVMProvider): full_test_vm.power_control_from_cfme(option=full_test_vm.POWER_OFF, cancel=False) full_test_vm.wait_for_vm_state_change( desired_state=full_test_vm.STATE_OFF, timeout=900) snapshot1.revert_to() # Wait for the snapshot to become active logger.info('Waiting for vm %s to become active', snapshot1.name) wait_for(lambda: snapshot1.active, num_sec=300, delay=20, fail_func=provider.browser.refresh, message="Waiting for the first snapshot to become active") # VM state after revert should be OFF full_test_vm.wait_for_vm_state_change(desired_state=full_test_vm.STATE_OFF, timeout=720) # Let's power it ON again full_test_vm.power_control_from_cfme(option=full_test_vm.POWER_ON, cancel=False) full_test_vm.wait_for_vm_state_change(desired_state=full_test_vm.STATE_ON, timeout=900) soft_assert(full_test_vm.mgmt.is_running, "vm not running") # Wait for successful ssh connection wait_for(lambda: ssh_client.run_command('test -e snapshot1.txt').success, num_sec=400, delay=10, handle_exception=True, fail_func=ssh_client.close(), message="Waiting for successful SSH connection after revert") try: result = ssh_client.run_command('test -e snapshot1.txt') assert result.success # file found, RC=0 result = ssh_client.run_command('test -e snapshot2.txt') assert result.failed # file not found, RC=1 logger.info('Revert to snapshot %s successful', snapshot1.name) except Exception: logger.exception('Revert to snapshot %s Failed', snapshot1.name) ssh_client.close()
def test_verify_revert_snapshot(full_test_vm, provider, soft_assert, register_event): """Tests revert snapshot Metadata: test_flag: snapshot, provision """ if provider.one_of(RHEVMProvider): snapshot1 = new_snapshot(full_test_vm, has_name=False) else: snapshot1 = new_snapshot(full_test_vm) full_template = getattr(provider.data.templates, 'full_template') ssh_kwargs = { 'hostname': snapshot1.vm.provider.mgmt.get_ip_address(snapshot1.vm.name), 'username': credentials[full_template.creds]['username'], 'password': credentials[full_template.creds]['password'] } ssh_client = SSHClient(**ssh_kwargs) # We need to wait for ssh to become available on the vm, it can take a while. Without # this wait, the ssh command would fail with 'port 22 not available' error. # Easiest way to solve this is just mask the exception with 'handle_exception = True' # and wait for successful completition of the ssh command. # The 'fail_func' ensures we close the connection that failed with exception. # Without this, the connection would hang there and wait_for would fail with timeout. wait_for(lambda: ssh_client.run_command('touch snapshot1.txt').rc == 0, num_sec=300, delay=20, handle_exception=True, fail_func=ssh_client.close()) snapshot1.create() register_event(target_type='VmOrTemplate', target_name=full_test_vm.name, event_type='vm_snapshot_complete') register_event(target_type='VmOrTemplate', target_name=full_test_vm.name, event_type='vm_snapshot') ssh_client.run_command('touch snapshot2.txt') if provider.one_of(RHEVMProvider): snapshot2 = new_snapshot(full_test_vm, has_name=False) else: snapshot2 = new_snapshot(full_test_vm) snapshot2.create() if provider.one_of(RHEVMProvider): full_test_vm.power_control_from_cfme(option=full_test_vm.POWER_OFF, cancel=False) full_test_vm.wait_for_vm_state_change( desired_state=full_test_vm.STATE_OFF, timeout=900) snapshot1.revert_to() # Wait for the snapshot to become active logger.info('Waiting for vm %s to become active', snapshot1.name) wait_for(lambda: snapshot1.active, num_sec=300, delay=20, fail_func=provider.browser.refresh) full_test_vm.wait_for_vm_state_change(desired_state=full_test_vm.STATE_OFF, timeout=720) full_test_vm.power_control_from_cfme(option=full_test_vm.POWER_ON, cancel=False) full_test_vm.wait_for_vm_state_change(desired_state=full_test_vm.STATE_ON, timeout=900) current_state = full_test_vm.find_quadicon().data['state'] soft_assert(current_state.startswith('currentstate-on'), "Quadicon state is {}".format(current_state)) soft_assert(full_test_vm.provider.mgmt.is_vm_running(full_test_vm.name), "vm not running") wait_for(lambda: ssh_client.run_command('test -e snapshot1.txt').rc == 0, num_sec=400, delay=20, handle_exception=True, fail_func=ssh_client.close()) try: result = ssh_client.run_command('test -e snapshot1.txt') assert not result.rc result = ssh_client.run_command('test -e snapshot2.txt') assert result.rc logger.info('Revert to snapshot %s successful', snapshot1.name) except: logger.exception('Revert to snapshot %s Failed', snapshot1.name) ssh_client.close()