def __init__(self, *args, **kwargs): super(LongTermBackupRetentionPolicyAction, self).__init__( BackupRetentionPolicyHelper.LONG_TERM_SQL_OPERATIONS, *args, **kwargs) self.backup_type = BackupRetentionPolicyHelper.LongTermBackupType[ self.data.get('backup-type')] retention_period = self.data['retention-period'] retention_period_units = RetentionPeriod.Units[ self.data['retention-period-units']] self.iso8601_duration = RetentionPeriod.iso8601_duration( retention_period, retention_period_units)
def get_retention_from_backup_policy(self, retention_policy): actual_retention_iso8601 = self.backup_type.get_retention_from_backup_policy( retention_policy) try: actual_duration, actual_duration_units = RetentionPeriod.parse_iso8601_retention_period( actual_retention_iso8601) except ValueError: return None if actual_duration_units.iso8601_symbol != self.retention_period_units.iso8601_symbol: return None return actual_duration
def test_iso8601_duration_days(self): duration = RetentionPeriod.iso8601_duration(23, RetentionPeriod.Units.days) self.assertEqual(duration, "P23D")
def test_parse_iso8601_retention_period_months(self): duration = "P8M" period, unit = RetentionPeriod.parse_iso8601_retention_period(duration) self.assertEqual(period, 8) self.assertEqual(unit.iso8601_symbol, 'M')
def test_parse_iso8601_retention_period_years(self): duration = "P5Y" period, unit = RetentionPeriod.parse_iso8601_retention_period(duration) self.assertEqual(period, 5) self.assertEqual(unit.iso8601_symbol, 'Y')
def test_parse_iso8601_retention_period_weeks(self): duration = "P17W" period, unit = RetentionPeriod.parse_iso8601_retention_period(duration) self.assertEqual(period, 17) self.assertEqual(unit.iso8601_symbol, 'W')
def test_parse_iso8601_retention_period_days(self): duration = "P31D" period, unit = RetentionPeriod.parse_iso8601_retention_period(duration) self.assertEqual(period, 31) self.assertEqual(unit.iso8601_symbol, 'D')
def test_iso8601_duration_years(self): duration = RetentionPeriod.iso8601_duration( 3, RetentionPeriod.Units.years) self.assertEqual(duration, "P3Y")
def test_iso8601_duration_months(self): duration = RetentionPeriod.iso8601_duration( 7, RetentionPeriod.Units.months) self.assertEqual(duration, "P7M")
def test_iso8601_duration_weeks(self): duration = RetentionPeriod.iso8601_duration( 12, RetentionPeriod.Units.weeks) self.assertEqual(duration, "P12W")