def prepare_ssl_env(): """ Do prepare for ssl spice connection """ # modify qemu.conf f_obj = open(qemu_conf, "r") cont = f_obj.read() # remove the existing setting left_cont = re.sub(r'\s*spice_tls\s*=.*', '', cont) left_cont = re.sub(r'\s*spice_tls_x509_cert_dir\s*=.*', '', left_cont) # write back to origin file with cut left content f_obj = open(qemu_conf, "w") f_obj.write(left_cont) f_obj.write("spice_tls = 1\n") f_obj.write("spice_tls_x509_cert_dir = \"/etc/pki/libvirt-spice\"") f_obj.close() # make modification effect utils_libvirtd.libvirtd_restart() # Generate CA cert utils_misc.create_x509_dir("/etc/pki/libvirt-spice", "/C=IL/L=Raanana/O=Red Hat/CN=my CA", "/C=IL/L=Raanana/O=Red Hat/CN=my server", passwd)
def prepare_ssl_env(): """ Clean ssl spice connection firstly """ # modify qemu.conf clean_ssl_env() # Append ssl spice configuration with open(qemu_conf, "a") as f_obj: f_obj.write("spice_tls = 1\n") f_obj.write("spice_tls_x509_cert_dir = \"/etc/pki/libvirt-spice\"") # Generate CA cert utils_misc.create_x509_dir("/etc/pki/libvirt-spice", "/C=IL/L=Raanana/O=Red Hat/CN=my CA", "/C=IL/L=Raanana/O=Red Hat/CN=my server", passwd)
def __init__(self, params, expected_result): spice_tls = params.get("spice_tls", "not_set") spice_listen = params.get("spice_listen", "not_set") vnc_tls = params.get("vnc_tls", "not_set") vnc_listen = params.get("vnc_listen", "not_set") spice_x509_dir = params.get("spice_x509_dir", "not_set") vnc_x509_dir = params.get("vnc_x509_dir", "not_set") spice_prepare_cert = params.get("spice_prepare_cert", "yes") vnc_prepare_cert = params.get("vnc_prepare_cert", "yes") port_min = params.get("remote_display_port_min", 'not_set') port_max = params.get("remote_display_port_max", 'not_set') auto_unix_socket = params.get("vnc_auto_unix_socket", 'not_set') tls_x509_verify = params.get("vnc_tls_x509_verify", 'not_set') if spice_x509_dir == 'not_set': self.spice_x509_dir_real = '/etc/pki/libvirt-spice' else: self.spice_x509_dir_real = spice_x509_dir self.spice_x509_dir_bak = self._backup_dir(self.spice_x509_dir_real) if spice_prepare_cert == 'yes': utils_misc.create_x509_dir( self.spice_x509_dir_real, '/C=NC/L=Raleigh/O=Red Hat/CN=virt-test', '/C=NC/L=Raleigh/O=Red Hat/CN=virt-test', 'none', True) if vnc_x509_dir == 'not_set': self.vnc_x509_dir_real = '/etc/pki/libvirt-vnc' else: self.vnc_x509_dir_real = vnc_x509_dir self.vnc_x509_dir_bak = self._backup_dir(self.vnc_x509_dir_real) if vnc_prepare_cert == 'yes': utils_misc.create_x509_dir( self.vnc_x509_dir_real, '/C=NC/L=Raleigh/O=Red Hat/CN=virt-test', '/C=NC/L=Raleigh/O=Red Hat/CN=virt-test', 'none', True) if spice_x509_dir == 'not_set': del self.qemu_config.spice_tls_x509_cert_dir else: self.qemu_config.spice_tls_x509_cert_dir = spice_x509_dir if vnc_x509_dir == 'not_set': del self.qemu_config.vnc_tls_x509_cert_dir else: self.qemu_config.vnc_tls_x509_cert_dir = vnc_x509_dir if spice_tls == 'not_set': del self.qemu_config.spice_tls else: self.qemu_config.spice_tls = spice_tls if vnc_tls == 'not_set': del self.qemu_config.vnc_tls else: self.qemu_config.vnc_tls = vnc_tls if port_min == 'not_set': del self.qemu_config.remote_display_port_min else: self.qemu_config.remote_display_port_min = port_min if port_max == 'not_set': del self.qemu_config.remote_display_port_max else: self.qemu_config.remote_display_port_max = port_max if spice_listen == 'not_set': del self.qemu_config.spice_listen elif spice_listen in ['valid_ipv4', 'valid_ipv6']: expected_ip = str(expected_result['spice_ips'][0]) self.qemu_config.spice_listen = expected_ip else: self.qemu_config.spice_listen = spice_listen if auto_unix_socket == 'not_set': del self.qemu_config.vnc_auto_unix_socket else: self.qemu_config.vnc_auto_unix_socket = auto_unix_socket if tls_x509_verify == 'not_set': del self.qemu_config.vnc_tls_x509_verify else: self.qemu_config.vnc_tls_x509_verify = tls_x509_verify if vnc_listen == 'not_set': del self.qemu_config.vnc_listen elif vnc_listen in ['valid_ipv4', 'valid_ipv6']: expected_ip = str(expected_result['vnc_ips'][0]) self.qemu_config.vnc_listen = expected_ip else: self.qemu_config.vnc_listen = vnc_listen self.libvirtd.restart()