Changeset 40945
- Timestamp:
- Oct 15, 2019, 12:27:24 PM (7 years ago)
- Location:
- branches/ipp-259_genericise_backups/tools/backups
- Files:
-
- 1 added
- 4 edited
-
backup.py (modified) (7 diffs)
-
backup_test.py (modified) (1 diff)
-
testing/backup_test.config (added)
-
utils/config_parse_helper.py (modified) (2 diffs)
-
utils/config_parse_helper_test.py (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/ipp-259_genericise_backups/tools/backups/backup.py
r40944 r40945 10 10 import backups.utils.errors as errs 11 11 import backups.utils.subprocess_utils as sub_utils 12 from backups.utils.config_parse_helper import ConfigSchema , ConfigSchemaLine12 from backups.utils.config_parse_helper import ConfigSchemaSection, ConfigSchemaLine 13 13 14 14 DEFAULT_CONFIG_FILE = path.join(path.dirname(__file__), 'atlassian_backups.config') … … 68 68 return self.run_mysqldump 69 69 70 DEFAULT_SCHEMA = ConfigSchema ('DEFAULT',70 DEFAULT_SCHEMA = ConfigSchemaSection('DEFAULT', 71 71 [ ConfigSchemaLine('backup_paths', True, list, cfg_help.SpecialSchemaProcessing.commma_separated) 72 72 , ConfigSchemaLine('source_machine', True, str) … … 76 76 ) 77 77 78 def read_default_section(self, config: ConfigParser, schema: ConfigSchema =DEFAULT_SCHEMA):78 def read_default_section(self, config: ConfigParser, schema: ConfigSchemaSection=DEFAULT_SCHEMA): 79 79 self.default_dict = cfg_help.parse_config(config, schema) 80 80 self.hostname_is_valid() 81 81 self.maybe_make_backup_dirs() 82 82 83 COPY_SCHEMA = ConfigSchema ('COPY',83 COPY_SCHEMA = ConfigSchemaSection('COPY', 84 84 [ ConfigSchemaLine('sources', True, list, cfg_help.SpecialSchemaProcessing.commma_separated) 85 85 , ConfigSchemaLine('additional_args', False, list, cfg_help.SpecialSchemaProcessing.space_separated) … … 87 87 ) 88 88 89 def read_copy_config_section(self, config: ConfigParser, schema: ConfigSchema =COPY_SCHEMA):89 def read_copy_config_section(self, config: ConfigParser, schema: ConfigSchemaSection=COPY_SCHEMA): 90 90 self.copy_dict = cfg_help.parse_config(config, schema) 91 91 92 TAR_SCHEMA = ConfigSchema ('TAR',92 TAR_SCHEMA = ConfigSchemaSection('TAR', 93 93 [ ConfigSchemaLine('sources', True, list, cfg_help.SpecialSchemaProcessing.commma_separated) 94 94 , ConfigSchemaLine('additional_args', False, list, cfg_help.SpecialSchemaProcessing.space_separated) … … 98 98 ) 99 99 100 def read_tar_config_section(self, config: ConfigParser, schema: ConfigSchema =TAR_SCHEMA):100 def read_tar_config_section(self, config: ConfigParser, schema: ConfigSchemaSection=TAR_SCHEMA): 101 101 self.tar_dict = cfg_help.parse_config(config, schema) 102 102 103 RSYNC_SCHEMA = ConfigSchema ('RSYNC',103 RSYNC_SCHEMA = ConfigSchemaSection('RSYNC', 104 104 [ ConfigSchemaLine('sources', True, list, cfg_help.SpecialSchemaProcessing.commma_separated) 105 105 , ConfigSchemaLine('additional_args', False, list, cfg_help.SpecialSchemaProcessing.space_separated) … … 107 107 ) 108 108 109 def read_rsync_config_section(self, config: ConfigParser, schema: ConfigSchema =RSYNC_SCHEMA):109 def read_rsync_config_section(self, config: ConfigParser, schema: ConfigSchemaSection=RSYNC_SCHEMA): 110 110 self.rsync_dict = cfg_help.parse_config(config, schema) 111 111 112 MYSQLDUMP_SCHEMA = ConfigSchema ('MYSQLDUMP',112 MYSQLDUMP_SCHEMA = ConfigSchemaSection('MYSQLDUMP', 113 113 [ ConfigSchemaLine('user', True, str) 114 114 , ConfigSchemaLine('password', True, str) … … 120 120 ) 121 121 122 def read_mysqldump_config_section(self, config: ConfigParser, schema: ConfigSchema =MYSQLDUMP_SCHEMA):122 def read_mysqldump_config_section(self, config: ConfigParser, schema: ConfigSchemaSection=MYSQLDUMP_SCHEMA): 123 123 self.mysqldump_dict = cfg_help.parse_config(config, schema) 124 124 -
branches/ipp-259_genericise_backups/tools/backups/backup_test.py
r40944 r40945 10 10 11 11 12 TEST_DEFAULT_CONFIG_FILE = os.path.join(os.path.dirname(__file__), 'testing/ full_backup_config.config')12 TEST_DEFAULT_CONFIG_FILE = os.path.join(os.path.dirname(__file__), 'testing/backup_test.config') 13 13 14 14 -
branches/ipp-259_genericise_backups/tools/backups/utils/config_parse_helper.py
r40937 r40945 35 35 36 36 37 class ConfigSchema ():37 class ConfigSchemaSection(): 38 38 """Defines a schema to be used. Consists of a single section name and 39 39 multiple config lines""" … … 76 76 77 77 78 def parse_config(config: ConfigParser(), schema: ConfigSchema ) -> dict:78 def parse_config(config: ConfigParser(), schema: ConfigSchemaSection) -> dict: 79 79 """For a given config it will extract all values defined by the schema 80 80 and return them as a dictionary of the keys and the assoicated value as the -
branches/ipp-259_genericise_backups/tools/backups/utils/config_parse_helper_test.py
r40919 r40945 41 41 42 42 43 class TestConfigSchema ():43 class TestConfigSchemaSection(): 44 44 45 45 def test_initalising_schema(self): … … 48 48 csl3 = helper.ConfigSchemaLine('some_float', False, float) 49 49 50 schema = helper.ConfigSchema ( 'section_name', [csl1, csl2, csl3] )50 schema = helper.ConfigSchemaSection( 'section_name', [csl1, csl2, csl3] ) 51 51 assert schema.options == { 'is_cool' : csl1 52 52 , 'fav_word' : csl2 … … 54 54 } 55 55 56 def test_empty_schema_ ok(self):57 helper.ConfigSchema ("ok_with_none", None)58 helper.ConfigSchema ("ok_with_empty", [])59 60 def test_schema_ fails_if_options_are_not_a_list(self):56 def test_empty_schema_section_ok(self): 57 helper.ConfigSchemaSection("ok_with_none", None) 58 helper.ConfigSchemaSection("ok_with_empty", []) 59 60 def test_schema_section_fails_if_options_are_not_a_list(self): 61 61 with pytest.raises(ValidationError): 62 helper.ConfigSchema ("fails_if_not_a_list", True)62 helper.ConfigSchemaSection("fails_if_not_a_list", True) 63 63 64 64 csl = helper.ConfigSchemaLine('key1', True, bool) 65 65 with pytest.raises(ValidationError): 66 helper.ConfigSchema ("even_fails_on_a_single_csl", csl)66 helper.ConfigSchemaSection("even_fails_on_a_single_csl", csl) 67 67 68 68 def test_adding_to_schema(self): 69 config = helper.ConfigSchema ("adding", [])69 config = helper.ConfigSchemaSection("adding", []) 70 70 assert config.options == {} 71 71 … … 88 88 89 89 def test_adding_a_duplicate_key_to_schema_replaces_previous(self): 90 config = helper.ConfigSchema ("adding", [])90 config = helper.ConfigSchemaSection("adding", []) 91 91 assert config.options == {} 92 92 … … 153 153 154 154 csl1 = helper.ConfigSchemaLine('Required_key', True, bool) 155 schema = helper.ConfigSchema ('DEFAULT', [csl1] )155 schema = helper.ConfigSchemaSection('DEFAULT', [csl1] ) 156 156 157 157 with pytest.raises(ConfigError): 158 158 helper.parse_config(config, schema) 159 159 160 def test_schema_ of_only_optional_values_is_ok(self):160 def test_schema_section_with_only_optional_values_is_ok(self): 161 161 csl1 = helper.ConfigSchemaLine('not_required', False, bool) 162 162 csl2 = helper.ConfigSchemaLine('not_required_either', False, float) 163 schema = helper.ConfigSchema ('DEFAULT', [csl1, csl2] )163 schema = helper.ConfigSchemaSection('DEFAULT', [csl1, csl2] ) 164 164 config = self.make_simple_config() 165 165 result = helper.parse_config(config, schema) 166 166 assert result == {} 167 167 168 def test_parsing_schema_ with_ints(self):168 def test_parsing_schema_section_with_ints(self): 169 169 csl1 = helper.ConfigSchemaLine('inty', False, int) 170 schema = helper.ConfigSchema ('DEFAULT', [csl1] )170 schema = helper.ConfigSchemaSection('DEFAULT', [csl1] ) 171 171 config = self.make_simple_config() 172 172 result = helper.parse_config(config, schema) 173 173 assert result == { 'inty' : 3} 174 174 175 def test_parsing_schema_ with_floats(self):175 def test_parsing_schema_section_with_floats(self): 176 176 csl1 = helper.ConfigSchemaLine('floaty', False, float) 177 schema = helper.ConfigSchema ('DEFAULT', [csl1] )177 schema = helper.ConfigSchemaSection('DEFAULT', [csl1] ) 178 178 config = self.make_simple_config() 179 179 result = helper.parse_config(config, schema) 180 180 assert result == { 'floaty' : 3.141 } 181 181 182 def test_parsing_schema_ with_bools(self):182 def test_parsing_schema_section_with_bools(self): 183 183 csl1 = helper.ConfigSchemaLine('mr_bool', True, bool) 184 schema = helper.ConfigSchema ('DEFAULT', [csl1] )184 schema = helper.ConfigSchemaSection('DEFAULT', [csl1] ) 185 185 config = self.make_simple_config() 186 186 result = helper.parse_config(config, schema) 187 187 assert result == { 'mr_bool' : True } 188 188 189 def test_parsing_schema_ with_strs(self):189 def test_parsing_schema_section_with_strs(self): 190 190 csl1 = helper.ConfigSchemaLine('stringer', True, str) 191 schema = helper.ConfigSchema ('DEFAULT', [csl1] )191 schema = helper.ConfigSchemaSection('DEFAULT', [csl1] ) 192 192 config = self.make_simple_config() 193 193 result = helper.parse_config(config, schema) 194 194 assert result == { 'stringer' : 'bell' } 195 195 196 def test_parsing_schema_ with_lists_comma_separated(self):196 def test_parsing_schema_section_with_lists_comma_separated(self): 197 197 csl1 = helper.ConfigSchemaLine('listo_comma', False, list, 198 198 helper.SpecialSchemaProcessing.commma_separated) 199 schema = helper.ConfigSchema ('DEFAULT', [csl1] )199 schema = helper.ConfigSchemaSection('DEFAULT', [csl1] ) 200 200 config = self.make_simple_config() 201 201 result = helper.parse_config(config, schema) … … 207 207 } 208 208 209 def test_parsing_schema_ with_lists_space_separated(self):209 def test_parsing_schema_section_with_lists_space_separated(self): 210 210 csl1 = helper.ConfigSchemaLine('listo_space', False, list, 211 211 helper.SpecialSchemaProcessing.space_separated) 212 schema = helper.ConfigSchema ('DEFAULT', [csl1] )212 schema = helper.ConfigSchemaSection('DEFAULT', [csl1] ) 213 213 config = self.make_simple_config() 214 214 result = helper.parse_config(config, schema) … … 231 231 helper.SpecialSchemaProcessing.commma_separated) 232 232 233 schema = helper.ConfigSchema ('DEFAULT', [csl_float])233 schema = helper.ConfigSchemaSection('DEFAULT', [csl_float]) 234 234 result = helper.parse_config(config, schema) 235 235 assert result == { 'floaty' : 3.141 } 236 236 assert type(result['floaty']) is float 237 237 238 schema = helper.ConfigSchema ('DEFAULT', [csl_int])238 schema = helper.ConfigSchemaSection('DEFAULT', [csl_int]) 239 239 with pytest.raises(ValueError): 240 240 helper.parse_config(config, schema) 241 241 242 schema = helper.ConfigSchema ('DEFAULT', [csl_bool])242 schema = helper.ConfigSchemaSection('DEFAULT', [csl_bool]) 243 243 with pytest.raises(ValueError): 244 244 helper.parse_config(config, schema) 245 245 246 schema = helper.ConfigSchema ('DEFAULT', [csl_str])246 schema = helper.ConfigSchemaSection('DEFAULT', [csl_str]) 247 247 result = helper.parse_config(config, schema) 248 248 assert result == { 'floaty' : '3.141' } 249 249 assert type(result['floaty']) is str 250 250 251 schema = helper.ConfigSchema ('DEFAULT', [csl_list])251 schema = helper.ConfigSchemaSection('DEFAULT', [csl_list]) 252 252 result = helper.parse_config(config, schema) 253 253 assert result == { 'floaty' : ['3.141'] } 254 254 assert type(result['floaty']) is list 255 255 256 def test_parsing_schema_ fails_with_unknown_type(self):256 def test_parsing_schema_line_fails_with_unknown_type(self): 257 257 csl1 = helper.ConfigSchemaLine('floaty', True, dict) 258 schema = helper.ConfigSchema ('DEFAULT', [csl1] )258 schema = helper.ConfigSchemaSection('DEFAULT', [csl1] ) 259 259 config = self.make_simple_config() 260 260 with pytest.raises(ConfigError): … … 267 267 for e in helper.SpecialSchemaProcessing: 268 268 csl = helper.ConfigSchemaLine('enum_checker', False, list, e) 269 schema = helper.ConfigSchema ('DEFAULT', [csl])269 schema = helper.ConfigSchemaSection('DEFAULT', [csl]) 270 270 271 271 result = helper.parse_config(config, schema) … … 283 283 csl6 = helper.ConfigSchemaLine('listo_space', False, list, 284 284 helper.SpecialSchemaProcessing.space_separated) 285 schema = helper.ConfigSchema ('FULL_TEST', [csl1, csl2, csl3, csl4, csl5, csl6])285 schema = helper.ConfigSchemaSection('FULL_TEST', [csl1, csl2, csl3, csl4, csl5, csl6]) 286 286 287 287 result = helper.parse_config(config, schema)
Note:
See TracChangeset
for help on using the changeset viewer.
