+ def _put_files(self, client):
+ setup_options = self.scenario_cfg["setup_options"]
+ rpm_dir = setup_options["rpm_dir"]
+ script_dir = setup_options["script_dir"]
+ image_dir = setup_options["image_dir"]
+ LOG.debug("Send RPMs from %s to workspace %s",
+ rpm_dir, self.WORKSPACE)
+ client.put(rpm_dir, self.WORKSPACE, recursive=True)
+ LOG.debug("Send scripts from %s to workspace %s",
+ script_dir, self.WORKSPACE)
+ client.put(script_dir, self.WORKSPACE, recursive=True)
+ LOG.debug("Send guest image from %s to workspace %s",
+ image_dir, self.WORKSPACE)
+ client.put(image_dir, self.WORKSPACE, recursive=True)
+
+ def _connect_host(self):
+ host = self.context_cfg["host"]
+ user = host.get("user", "root")
+ ip = host.get("ip", None)
+ key_filename = host.get("key_filename", "~/.ssh/id_rsa")
+
+ LOG.debug("user:%s, host:%s", user, ip)
+ self.host = ssh.SSH(user, ip, key_filename=key_filename)
+ self.host.wait(timeout=600)
+
+ def _connect_guest(self):
+ host = self.context_cfg["host"]
+ user = host.get("user", "root")
+ ip = host.get("ip", None)
+ ssh_port = host.get("ssh_port", 5555)
+ key_filename = host.get("key_filename", "~/.ssh/id_rsa")
+
+ LOG.debug("user:%s, host:%s", user, ip)
+ self.guest = ssh.SSH(user, ip, port=ssh_port,
+ key_filename=key_filename)
+ self.guest.wait(timeout=600)
+
+ def _run_setup_cmd(self, client, cmd):
+ LOG.debug("Run cmd: %s", cmd)
+ status, stdout, stderr = client.execute(cmd)
+ if status:
+ if re.search(self.REBOOT_CMD_PATTERN, cmd):
+ LOG.debug("Error on reboot")
+ else:
+ raise RuntimeError(stderr)
+
+ def _run_host_setup_scripts(self, scripts):
+ setup_options = self.scenario_cfg["setup_options"]
+ script_dir = os.path.basename(setup_options["script_dir"])
+
+ for script in scripts:
+ cmd = "cd %s/%s; export PATH=./:$PATH; %s" %\
+ (self.WORKSPACE, script_dir, script)
+ self._run_setup_cmd(self.host, cmd)
+
+ if re.search(self.REBOOT_CMD_PATTERN, cmd):
+ time.sleep(3)
+ self._connect_host()
+
+ def _run_guest_setup_scripts(self, scripts):
+ setup_options = self.scenario_cfg["setup_options"]
+ script_dir = os.path.basename(setup_options["script_dir"])
+
+ for script in scripts:
+ cmd = "cd %s/%s; export PATH=./:$PATH; %s" %\
+ (self.WORKSPACE, script_dir, script)
+ self._run_setup_cmd(self.guest, cmd)
+
+ if re.search(self.REBOOT_CMD_PATTERN, cmd):
+ time.sleep(3)
+ self._connect_guest()
+