| 859 | |
| 860 | |
| 861 | class LocalCephCluster(tasks.cephfs.filesystem.CephClusterBase): |
| 862 | def __init__(self, ctx, cluster_name='ceph'): |
| 863 | # Deliberately skip calling CephCluster constructor |
| 864 | self._ctx = ctx |
| 865 | self.mon_manager = LocalCephManager(ctx=self._ctx, cluster_name=cluster_name) |
| 866 | self._conf = defaultdict(dict) |
| 867 | |
| 868 | @property |
| 869 | def admin_remote(self): |
| 870 | return LocalRemote() |
| 871 | |
| 872 | def get_config(self, key, service_type=None): |
| 873 | if service_type is None: |
| 874 | service_type = 'mon' |
| 875 | |
| 876 | # FIXME hardcoded vstart service IDs |
| 877 | service_id = { |
| 878 | 'mon': 'a', |
| 879 | 'mds': 'a', |
| 880 | 'osd': '0' |
| 881 | }[service_type] |
| 882 | |
| 883 | return self.json_asok(['config', 'get', key], service_type, service_id)[key] |
| 884 | |
| 885 | def _write_conf(self): |
| 886 | # In teuthology, we have the honour of writing the entire ceph.conf, but |
| 887 | # in vstart land it has mostly already been written and we need to carefully |
| 888 | # append to it. |
| 889 | conf_path = "./ceph.conf" |
| 890 | banner = "\n#LOCAL_TEST\n" |
| 891 | existing_str = open(conf_path).read() |
| 892 | |
| 893 | if banner in existing_str: |
| 894 | existing_str = existing_str[0:existing_str.find(banner)] |
| 895 | |
| 896 | existing_str += banner |
| 897 | |
| 898 | for subsys, kvs in self._conf.items(): |
| 899 | existing_str += "\n[{0}]\n".format(subsys) |
| 900 | for key, val in kvs.items(): |
| 901 | # Comment out existing instance if it exists |
| 902 | log.debug("Searching for existing instance {0}/{1}".format( |
| 903 | key, subsys |
| 904 | )) |
| 905 | existing_section = re.search(r"^\[{0}\]$([\n]|[^\[])+".format( |
| 906 | subsys |
| 907 | ), existing_str, re.MULTILINE) |
| 908 | |
| 909 | if existing_section: |
| 910 | section_str = existing_str[existing_section.start():existing_section.end()] |
| 911 | existing_val = re.search(r"^\s*[^#]({0}) =".format(key), section_str, re.MULTILINE) |
| 912 | if existing_val: |
| 913 | start = existing_section.start() + existing_val.start(1) |
| 914 | log.debug("Found string to replace at {0}".format( |
| 915 | start |
| 916 | )) |
| 917 | existing_str = existing_str[0:start] + "#" + existing_str[start:] |
| 918 | |