ceph_safe_disk/
osdmap.rs

1#[derive(Deserialize, Debug, PartialEq, Clone)]
2pub struct OsdMap {
3    pub pool_max: i32,
4    pub max_osd: i32,
5    pub created: String,
6    pub modified: String,
7    pub osd_xinfo: Vec<OsdXinfo>,
8    pub osds: Vec<Osds>,
9    pub epoch: i32,
10    pub flags: String,
11    pub cluster_snapshot: String,
12    pub pools: Vec<Pools>,
13    pub fsid: String,
14}
15
16#[derive(Deserialize, Debug, PartialEq, Clone)]
17pub struct Default {
18    pub k: String,
19    pub technique: String,
20    pub m: String,
21    pub plugin: String,
22}
23
24#[derive(Deserialize, Debug, PartialEq, Clone)]
25pub struct Osds {
26    pub heartbeat_back_addr: String,
27    pub uuid: String,
28    pub weight: serde_json::Value,
29    pub up_from: i32,
30    pub heartbeat_front_addr: String,
31    pub down_at: i32,
32    pub up: i32,
33    pub lost_at: i32,
34    pub primary_affinity: serde_json::Value,
35    pub state: Vec<String>,
36    pub last_clean_begin: i32,
37    pub last_clean_end: i32,
38    pub public_addr: String,
39    pub up_thru: i32,
40    pub cluster_addr: String,
41    pub osd: i32,
42}
43
44#[derive(Deserialize, Debug, PartialEq, Clone)]
45pub struct OsdXinfo {
46    pub laggy_probability: serde_json::Value,
47    pub laggy_interval: i32,
48    pub features: u64,
49    pub old_weight: Option<i32>,
50    pub down_stamp: String,
51    pub osd: i32,
52}
53
54#[derive(Deserialize, Debug, PartialEq, Clone)]
55pub struct Pools {
56    pub cache_target_full_ratio_micro: i32,
57    pub fast_read: Option<bool>,
58    pub stripe_width: i32,
59    pub flags_names: String,
60    pub tier_of: i32,
61    pub hit_set_grade_decay_rate: Option<i32>,
62    pub pg_placement_num: i32,
63    pub use_gmt_hitset: Option<bool>,
64    pub quota_max_bytes: i32,
65    pub erasure_code_profile: String,
66    pub expected_num_objects: Option<i32>,
67    // "replicated size"
68    pub size: i32,
69    pub snap_seq: i32,
70    pub auid: i32,
71    pub cache_min_flush_age: i32,
72    pub hit_set_period: i32,
73    pub min_read_recency_for_promote: i32,
74    pub target_max_objects: i32,
75    pub pg_num: i32,
76    pub crush_ruleset: Option<i32>,
77    pub crush_rule: Option<i32>,
78    pub pool_name: String,
79    pub cache_min_evict_age: i32,
80    pub snap_mode: String,
81    pub cache_mode: String,
82    pub min_size: i32,
83    pub cache_target_dirty_high_ratio_micro: Option<i32>,
84    pub crash_replay_interval: Option<i32>,
85    pub object_hash: i32,
86    pub write_tier: i32,
87    pub cache_target_dirty_ratio_micro: i32,
88    pub pool: i32,
89    pub removed_snaps: String,
90    pub last_force_op_resend: String,
91    pub quota_max_objects: i32,
92    pub hit_set_count: i32,
93    pub flags: i32,
94    pub target_max_bytes: i32,
95    pub snap_epoch: i32,
96    pub hit_set_search_last_n: Option<i32>,
97    pub last_change: String,
98    pub min_write_recency_for_promote: Option<i32>,
99    pub read_tier: i32,
100}
101
102#[cfg(test)]
103mod tests {
104    use super::OsdMap;
105    use crate::from::FromFile;
106
107    // Luminous tests
108    #[test]
109    #[should_panic]
110    fn osdmap_from_luminous_file_panic() {
111        let osdmap = OsdMap::from_file("test/luminous/osd_dump_non_safe.json").unwrap();
112        // If this is safe to remove then osd's len should be min_size + 1
113        assert_eq!(osdmap.osds.len(), (osdmap.pools[0].min_size + 1) as usize);
114    }
115
116    // Jewel tests
117    #[test]
118    #[should_panic]
119    fn osdmap_from_jewel_file_panic() {
120        let osdmap = OsdMap::from_file("test/jewel/osd_dump_safe.json").unwrap();
121        // If this is safe to remove then osd's len should be min_size + 1
122        assert_eq!(osdmap.osds.len(), 0);
123    }
124
125    #[test]
126    fn osdmap_from_jewel_file() {
127        let osdmap = OsdMap::from_file("test/jewel/osd_dump_safe.json").unwrap();
128        // Default config for min_size is 2
129        assert_eq!(osdmap.pools.first().unwrap().min_size, 2);
130    }
131
132    #[test]
133    #[should_panic]
134    fn osdmap_from_jewel_file_no_osd_panic() {
135        let osdmap = OsdMap::from_file("test/jewel/osd_dump_no_osd.json").unwrap();
136        // This has no osds so len should be 0
137        assert_eq!(osdmap.osds.len(), 3);
138    }
139
140    #[test]
141    fn osdmap_from_jewel_file_no_osd() {
142        let osdmap = OsdMap::from_file("test/jewel/osd_dump_no_osd.json").unwrap();
143        let mut osds_up: Vec<i32> = Vec::new();
144        // There should be no OSDs present
145        for osd in osdmap.osds {
146            if osd.up == 1 {
147                osds_up.push(1);
148            }
149        }
150        assert_eq!(osds_up.len(), 0);
151    }
152
153    #[test]
154    fn osdmap_from_jewel_file_non_safe() {
155        let osdmap = OsdMap::from_file("test/jewel/osd_dump_non_safe.json").unwrap();
156        let mut osds_up: Vec<i32> = Vec::new();
157        // Since this is non-safe there should be min_size or less OSDs present
158        for osd in osdmap.osds {
159            if osd.up == 1 {
160                osds_up.push(1);
161            }
162        }
163        assert_eq!(osds_up.len() as i32, osdmap.pools.first().unwrap().min_size);
164    }
165
166    // Firefly tests
167    #[test]
168    fn osdmap_from_firefly_file() {
169        let osdmap = OsdMap::from_file("test/firefly/osd_dump_safe.json").unwrap();
170        assert_eq!(osdmap.pools.first().unwrap().min_size, 2);
171    }
172
173    #[test]
174    #[should_panic]
175    fn osdmap_from_firefly_file_panic() {
176        let osdmap = OsdMap::from_file("test/firefly/osd_dump_safe.json").unwrap();
177        // If this is safe to remove then osd's len should be min_size + 1
178        assert_eq!(osdmap.osds.len() as i32, 0);
179    }
180
181    #[test]
182    #[should_panic]
183    fn osdmap_from_ceph_panic() {
184        use crate::from::FromCeph;
185        let osdmap = OsdMap::from_ceph("osd dump");
186        assert_eq!(osdmap.is_ok(), true);
187    }
188}