def discover_ceph_nodes(ip): """ Return list of ceph's nodes ips """ ips = {} if ip != 'local': executor = ssh_execute(connect(ip)) else: executor = local_execute osd_ips = get_osds_ips(executor, get_osds_list(executor)) mon_ips = get_mons_or_mds_ips(executor, "mon") mds_ips = get_mons_or_mds_ips(executor, "mds") for ip in osd_ips: url = "ssh://%s" % ip ips.setdefault(url, []).append("ceph-osd") for ip in mon_ips: url = "ssh://%s" % ip ips.setdefault(url, []).append("ceph-mon") for ip in mds_ips: url = "ssh://%s" % ip ips.setdefault(url, []).append("ceph-mds") return [Node(url, list(roles)) for url, roles in ips.items()]
def discover_ceph_nodes(ip): """ Return list of ceph's nodes ips """ ips = {} if ip != 'local': executor = ssh_execute(connect(ip)) else: executor = local_execute osd_ips = get_osds_ips(executor, get_osds_list(executor)) mon_ips = get_mons_or_mds_ips(executor, "mon") mds_ips = get_mons_or_mds_ips(executor, "mds") for ip in osd_ips: url = "ssh://%s" % ip ips.setdefault(url, []).append("ceph-osd") for ip in mon_ips: url = "ssh://%s" % ip ips.setdefault(url, []).append("ceph-mon") for ip in mds_ips: url = "ssh://%s" % ip ips.setdefault(url, []).append("ceph-mds") return [Node(url, list(roles)) for url, roles in ips.items()]
def test_ssh_executor1(self): id_rsa_path = os.path.expanduser('~/.ssh/id_rsa') ssh_url = "ssh://localhost::" + id_rsa_path expected = sorted(os.listdir('/')) conn = ssh_utils.connect(ssh_url) out = ssh_utils.run_over_ssh(conn, "ls /") ok(sorted(out.split())) == expected
def test_ssh_executor1(self): id_rsa_path = os.path.expanduser('~/.ssh/id_rsa') ssh_url = "ssh://localhost::" + id_rsa_path expected = sorted(os.listdir('/')) conn = ssh_utils.connect(ssh_url) out = ssh_utils.run_over_ssh(conn, "ls /") ok(sorted(out.split())) == expected
def connect_ext(conn_url): try: return ssh_utils.connect(conn_url, conn_timeout=conn_timeout) except Exception as exc: logger.error("During connect to {0}: {1!s}".format(conn_url, exc)) return None
def connect_ext(conn_url): try: return ssh_utils.connect(conn_url, conn_timeout=conn_timeout) except Exception as exc: logger.error("During connect to {0}: {1!s}".format(conn_url, exc)) return None
def discover_fuel_nodes(fuel_data, var_dir, discover_nodes=True): username, tenant_name, password = parse_creds(fuel_data["creds"]) creds = {"username": username, "tenant_name": tenant_name, "password": password} conn = KeystoneAuth(fuel_data["url"], creds, headers=None) msg = "openstack_env should be provided in fuel config" check_input_param("openstack_env" in fuel_data, msg) cluster_id = get_cluster_id(conn, fuel_data["openstack_env"]) cluster = reflect_cluster(conn, cluster_id) if not discover_nodes: logger.warning("Skip fuel cluster discovery") return ([], None, cluster.get_openrc()) version = FuelInfo(conn).get_version() fuel_nodes = list(cluster.get_nodes()) logger.info("Found FUEL {0}".format(".".join(map(str, version)))) network = "fuelweb_admin" if version >= [6, 0] else "admin" ssh_creds = fuel_data["ssh_creds"] fuel_host = urlparse(fuel_data["url"]).hostname fuel_ip = socket.gethostbyname(fuel_host) try: ssh_conn = connect("{0}@{1}".format(ssh_creds, fuel_host)) except AuthenticationException: raise StopTestError("Wrong fuel credentials") except Exception: logger.exception("While connection to FUEL") raise StopTestError("Failed to connect to FUEL") fuel_ext_iface = get_external_interface(ssh_conn, fuel_ip) logger.debug("Downloading fuel master key") fuel_key = download_master_key(ssh_conn) nodes = [] ips_ports = [] logger.info("Forwarding ssh ports from FUEL nodes to localhost") fuel_usr, fuel_passwd = ssh_creds.split(":", 1) ips = [str(fuel_node.get_ip(network)) for fuel_node in fuel_nodes] port_fw = forward_ssh_ports(fuel_host, fuel_usr, fuel_passwd, ips) listen_ip = get_ip_for_target(fuel_host) for port, fuel_node, ip in zip(port_fw, fuel_nodes, ips): logger.debug("SSH port forwarding {0} => localhost:{1}".format(ip, port)) conn_url = "ssh://[email protected]:{0}".format(port) set_key_for_node(("127.0.0.1", port), fuel_key) node = Node(conn_url, fuel_node["roles"]) node.monitor_ip = listen_ip nodes.append(node) ips_ports.append((ip, port)) logger.debug("Found %s fuel nodes for env %r" % (len(nodes), fuel_data["openstack_env"])) if version > [6, 0]: openrc = cluster.get_openrc() else: logger.warning("Getting openrc on fuel 6.0 is broken, skip") openrc = None return (nodes, (ssh_conn, fuel_ext_iface, ips_ports), openrc)
def discover_fuel_nodes(fuel_data, var_dir, discover_nodes=True): username, tenant_name, password = parse_creds(fuel_data['creds']) creds = {"username": username, "tenant_name": tenant_name, "password": password} conn = KeystoneAuth(fuel_data['url'], creds, headers=None) msg = "openstack_env should be provided in fuel config" check_input_param('openstack_env' in fuel_data, msg) cluster_id = get_cluster_id(conn, fuel_data['openstack_env']) cluster = reflect_cluster(conn, cluster_id) version = FuelInfo(conn).get_version() if not discover_nodes: logger.warning("Skip fuel cluster discovery") return ([], None, cluster.get_openrc(), version) fuel_nodes = list(cluster.get_nodes()) logger.info("Found FUEL {0}".format(".".join(map(str, version)))) network = 'fuelweb_admin' if version >= [6, 0] else 'admin' ssh_creds = fuel_data['ssh_creds'] fuel_host = urlparse(fuel_data['url']).hostname fuel_ip = socket.gethostbyname(fuel_host) try: ssh_conn = connect("{0}@{1}".format(ssh_creds, fuel_host)) except AuthenticationException: raise StopTestError("Wrong fuel credentials") except Exception: logger.exception("While connection to FUEL") raise StopTestError("Failed to connect to FUEL") fuel_ext_iface = get_external_interface(ssh_conn, fuel_ip) logger.debug("Downloading fuel master key") fuel_key = download_master_key(ssh_conn) nodes = [] ips_ports = [] logger.info("Forwarding ssh ports from FUEL nodes to localhost") fuel_usr, fuel_passwd = ssh_creds.split(":", 1) ips = [str(fuel_node.get_ip(network)) for fuel_node in fuel_nodes] port_fw = forward_ssh_ports(fuel_host, fuel_usr, fuel_passwd, ips) listen_ip = get_ip_for_target(fuel_host) for port, fuel_node, ip in zip(port_fw, fuel_nodes, ips): logger.debug( "SSH port forwarding {0} => localhost:{1}".format(ip, port)) conn_url = "ssh://[email protected]:{0}".format(port) set_key_for_node(('127.0.0.1', port), fuel_key) node = Node(conn_url, fuel_node['roles']) node.monitor_ip = listen_ip nodes.append(node) ips_ports.append((ip, port)) logger.debug("Found %s fuel nodes for env %r" % (len(nodes), fuel_data['openstack_env'])) return (nodes, (ssh_conn, fuel_ext_iface, ips_ports), cluster.get_openrc(), version)