Home | History | Annotate | Download | only in tests
      1 import logging, time
      2 
      3 
      4 def internal_yum_update(session, command, prompt, timeout):
      5     """
      6     Helper function to perform the yum update test.
      7 
      8     @param session: shell session stablished to the host
      9     @param command: Command to be sent to the shell session
     10     @param prompt: Machine prompt
     11     @param timeout: How long to wait until we get an appropriate output from
     12             the shell session.
     13     """
     14     session.sendline(command)
     15     end_time = time.time() + timeout
     16     while time.time() < end_time:
     17         match = session.read_until_last_line_matches(
     18                                                 ["[Ii]s this [Oo][Kk]", prompt],
     19                                                 timeout=timeout)[0]
     20         if match == 0:
     21             logging.info("Got 'Is this ok'; sending 'y'")
     22             session.sendline("y")
     23         elif match == 1:
     24             logging.info("Got shell prompt")
     25             return True
     26         else:
     27             logging.info("Timeout or process exited")
     28             return False
     29 
     30 
     31 def run_yum_update(test, params, env):
     32     """
     33     Runs yum update and yum update kernel on the remote host (yum enabled
     34     hosts only).
     35 
     36     @param test: kvm test object.
     37     @param params: Dictionary with test parameters.
     38     @param env: Dictionary with the test environment.
     39     """
     40     vm = env.get_vm(params["main_vm"])
     41     vm.verify_alive()
     42     timeout = int(params.get("login_timeout", 360))
     43     session = vm.wait_for_login(timeout=timeout)
     44 
     45     internal_yum_update(session, "yum update", params.get("shell_prompt"), 600)
     46     internal_yum_update(session, "yum update kernel",
     47                         params.get("shell_prompt"), 600)
     48 
     49     session.close()
     50