def get_role_service(self, service_name: str) -> str: """ Get service info by name. Args: service_name (Str): service name Returns: service (Dict) Raises: ResourceNotFound: when no resource with the provided is matched. """ out, _ = self.ls() for svc in loads(out): if service_name in svc.get("service_name"): return svc raise ResourceNotFoundError(f"No service names matched {service_name}")
def bootstrap(self: CephAdmProtocol, config: Dict): """ Execute cephadm bootstrap with the passed kwargs on the installer node.:: Bootstrap involves, - Creates /etc/ceph directory with permissions - CLI creation with bootstrap options with custom/default image - Execution of bootstrap command Args: config (Dict): Key/value pairs passed from the test case. Example:: config: command: bootstrap base_cmd_args: verbose: true args: custom_repo: custom repository path custom_image: <image path> or <boolean> mon-ip: <node_name> mgr-id: <mgr_id> fsid: <id> registry-url: <registry.url.name> registry-json: <registry.url.name> initial-dashboard-user: <admin123> initial-dashboard-password: <admin123> custom_image:: image path: compose path for example alpha build, ftp://partners.redhat.com/d960e6f2052ade028fa16dfc24a827f5/rhel-8/Tools/x86_64/os/ boolean: True: use latest image from test config False: do not use latest image from test config, and also indicates usage of default image from cephadm source-code. """ self.cluster.setup_ssh_keys() args = config.get("args") custom_repo = args.pop("custom_repo", "") custom_image = args.pop("custom_image", True) build_type = self.config.get("build_type") if build_type == "released" or custom_repo.lower() == "cdn": custom_image = False self.set_cdn_tool_repo() elif custom_repo: self.set_tool_repo(repo=custom_repo) else: self.set_tool_repo() self.install() cmd = "cephadm" if config.get("base_cmd_args"): cmd += config_dict_to_string(config["base_cmd_args"]) if custom_image: if isinstance(custom_image, str): cmd += f" --image {custom_image}" else: cmd += f" --image {self.config['container_image']}" cmd += " bootstrap" # Construct registry credentials as string or json. registry_url = args.pop("registry-url", None) if registry_url: cmd += construct_registry(self, registry_url) registry_json = args.pop("registry-json", None) if registry_json: cmd += construct_registry(self, registry_json, json_file=True) """ Generate dashboard certificate and key if bootstrap cli have this options as dashboard-key and dashboard-crt """ dashboard_key_path = args.pop("dashboard-key", False) dashboard_cert_path = args.pop("dashboard-crt", False) if dashboard_cert_path and dashboard_key_path: cmd += generate_ssl_certificate(self, dashboard_key_path, dashboard_cert_path) # To be generic, the mon-ip contains the global node name. Here, we replace the # name with the IP address. The replacement allows us to be inline with the # CLI option. # Todo: need to switch installer node on any other node name provided # other than installer node mon_node = args.pop("mon-ip", self.installer.node.shortname) if mon_node: for node in self.cluster.get_nodes(): # making sure conditions works in all the scenario if (node.shortname == mon_node or node.shortname.endswith(mon_node) or f"{mon_node}-" in node.shortname): cmd += f" --mon-ip {node.ip_address}" break else: raise ResourceNotFoundError(f"Unknown {mon_node} node name.") # apply-spec specs = args.get("apply-spec") if specs: spec_cls = GenerateServiceSpec(node=self.installer, cluster=self.cluster, specs=specs) args["apply-spec"] = spec_cls.create_spec_file() cmd += config_dict_to_string(args) out, err = self.installer.exec_command( sudo=True, cmd=cmd, timeout=1800, check_ec=True, ) out, err = out.read().decode(), err.read().decode() logger.info("Bootstrap output : %s", out) logger.error("Bootstrap error: %s", err) # The path to ssh public key mentioned in either output-pub-ssh-key or ssh-public-key options # will be considered for distributing the ssh public key, if these are not specified, # then the default ssh key path /etc/ceph/ceph.pub will be considered. self.distribute_cephadm_gen_pub_key( args.get("output-pub-ssh-key") or args.get("ssh-public-key")) # Copy all the ceph configuration files to default path /etc/ceph # if they are already not present in the default path copy_ceph_configuration_files(self, args) # The provided image is used by Grafana service only when # --skip-monitoring-stack is set to True during bootstrap. if self.config.get("grafana_image"): cmd = "cephadm shell --" cmd += " ceph config set mgr mgr/cephadm/container_image_grafana" cmd += f" {self.config['grafana_image']}" self.installer.exec_command(sudo=True, cmd=cmd) return out, err
def bootstrap(self: CephAdmProtocol, config: Dict): """ Execute cephadm bootstrap with the passed kwargs on the installer node.:: Bootstrap involves, - Creates /etc/ceph directory with permissions - CLI creation with bootstrap options with custom/default image - Execution of bootstrap command Args: config (Dict): Key/value pairs passed from the test case. Example:: config: command: bootstrap base_cmd_args: verbose: true args: custom_repo: custom repository path custom_image: <image path> or <boolean> mon-ip: <node_name> mgr-id: <mgr_id> fsid: <id> registry-url: <registry.url.name> registry-json: <registry.url.name> initial-dashboard-user: <admin123> initial-dashboard-password: <admin123> custom_image:: image path: compose path for example alpha build, ftp://partners.redhat.com/d960e6f2052ade028fa16dfc24a827f5/rhel-8/Tools/x86_64/os/ boolean: True: use latest image from test config False: do not use latest image from test config, and also indicates usage of default image from cephadm source-code. """ self.cluster.setup_ssh_keys() args = config.get("args") custom_repo = args.pop("custom_repo", "") custom_image = args.pop("custom_image", True) build_type = self.config.get("build_type") rhbuild = self.config.get("rhbuild") if build_type == "upstream": self.setup_upstream_repository() # work-around to enable ceph x86_64 RPM pkgs. # which is currently unavailable in upstream builds. self.set_cdn_tool_repo() elif build_type == "released" or custom_repo.lower() == "cdn": custom_image = False self.set_cdn_tool_repo() elif custom_repo: self.set_tool_repo(repo=custom_repo) else: self.set_tool_repo() ansible_run = config.get("cephadm-ansible", None) if ansible_run: cephadm_ansible = CephadmAnsible(cluster=self.cluster) cephadm_ansible.execute_playbook( playbook=ansible_run["playbook"], extra_vars=ansible_run.get("extra-vars"), extra_args=ansible_run.get("extra-args"), ) self.install() cmd = "cephadm" if config.get("base_cmd_args"): cmd += config_dict_to_string(config["base_cmd_args"]) if custom_image: if isinstance(custom_image, str): cmd += f" --image {custom_image}" else: cmd += f" --image {self.config['container_image']}" cmd += " bootstrap" # Construct registry credentials as string or json. registry_url = args.pop("registry-url", None) if registry_url: cmd += construct_registry(self, registry_url) registry_json = args.pop("registry-json", None) if registry_json: cmd += construct_registry(self, registry_json, json_file=True) """ Generate dashboard certificate and key if bootstrap cli have this options as dashboard-key and dashboard-crt """ dashboard_key_path = args.pop("dashboard-key", False) dashboard_cert_path = args.pop("dashboard-crt", False) if dashboard_cert_path and dashboard_key_path: cmd += generate_ssl_certificate(self, dashboard_key_path, dashboard_cert_path) # To be generic, the mon-ip contains the global node name. Here, we replace the # name with the IP address. The replacement allows us to be inline with the # CLI option. # Todo: need to switch installer node on any other node name provided # other than installer node mon_node = args.pop("mon-ip", self.installer.node.shortname) if mon_node: for node in self.cluster.get_nodes(): # making sure conditions works in all the scenario if (node.shortname == mon_node or node.shortname.endswith(mon_node) or f"{mon_node}-" in node.shortname): cmd += f" --mon-ip {node.ip_address}" break else: raise ResourceNotFoundError(f"Unknown {mon_node} node name.") # apply-spec specs = args.get("apply-spec") if specs: spec_cls = GenerateServiceSpec(node=self.installer, cluster=self.cluster, specs=specs) args["apply-spec"] = spec_cls.create_spec_file() # config conf = args.get("config") if conf: args["config"] = create_ceph_config_file(node=self.installer, config=conf) cmd += config_dict_to_string(args) # Todo: This patch is specific to 5.1 release, # should be removed for next 5.x development builds or release. if rhbuild.startswith("5.1"): cmd += " --yes-i-know" out, err = self.installer.exec_command( sudo=True, cmd=cmd, timeout=1800, check_ec=True, ) logger.info("Bootstrap output : %s", out) logger.error("Bootstrap error: %s", err) # The path to ssh public key mentioned in either output-pub-ssh-key or # ssh-public-key options will be considered for distributing the ssh public key, # if these are not specified, then the default ssh key path /etc/ceph/ceph.pub # will be considered. self.distribute_cephadm_gen_pub_key( args.get("output-pub-ssh-key") or args.get("ssh-public-key")) # Copy all the ceph configuration files to default path /etc/ceph # if they are already not present in the default path copy_ceph_configuration_files(self, args) # Check for image overrides if self.config.get("overrides"): override_dict = dict( item.split("=") for item in self.config["overrides"]) supported_overrides = [ "grafana", "keepalived", "haproxy", "prometheus", "node_exporter", "alertmanager", ] for image in supported_overrides: image_key = f"{image}_image" if override_dict.get(image_key): cmd = "cephadm shell --" cmd += f" ceph config set mgr mgr/cephadm/container_image_{image}" cmd += f" {override_dict[image_key]}" self.installer.exec_command(sudo=True, cmd=cmd) return out, err
def bootstrap(self: CephAdmProtocol, config: Dict) -> None: """ Execute cephadm bootstrap with the passed kwargs on the installer node. Bootstrap involves, - Creates /etc/ceph directory with permissions - CLI creation with bootstrap options with custom/default image - Execution of bootstrap command Args: config: Key/value pairs passed from the test case. Example: config: command: bootstrap base_cmd_args: verbose: true args: custom_image: true | false mon-ip: <node_name> mgr-id: <mgr_id> fsid: <id> """ self.cluster.setup_ssh_keys() self.set_tool_repo() self.install() cdn_cred = get_cephci_config().get("cdn_credentials") cmd = "cephadm" if config.get("base_cmd_args"): cmd += config_dict_to_string(config["base_cmd_args"]) args = config.get("args") custom_image = args.pop("custom_image", True) if custom_image: cmd += f" --image {self.config['container_image']}" cmd += " bootstrap" custom_image_args = (" --registry-url registry.redhat.io" " --registry-username {user}" " --registry-password {password}") cmd += custom_image_args.format( user=cdn_cred.get("username"), password=cdn_cred.get("password"), ) # To be generic, the mon-ip contains the global node name. Here, we replace the # name with the IP address. The replacement allows us to be inline with the # CLI option. # Todo: need to switch installer node on any other node name provided # other than installer node mon_node = args.pop("mon-ip", self.installer.node.shortname) if mon_node: for node in self.cluster.get_nodes(): if mon_node in node.shortname: cmd += f" --mon-ip {node.ip_address}" break else: raise ResourceNotFoundError(f"Unknown {mon_node} node name.") cmd += config_dict_to_string(args) out, err = self.installer.exec_command( sudo=True, cmd=cmd, timeout=1800, check_ec=True, ) logger.info("Bootstrap output : %s", out.read().decode()) logger.error("Bootstrap error: %s", err.read().decode()) self.distribute_cephadm_gen_pub_key()