def _get_snapshots(self): """ Generate a list of fake snapshots with names and dates. """ snaps = [] # Generate some dates offset by days, weeks, months now = datetime.now() dates = [ now, now - timedelta(days=1), now - timedelta(days=2), now - timedelta(days=7), now - timedelta(days=14), datetime(now.year, now.month, 1) - timedelta(days=30), datetime(now.year, now.month, 1) - timedelta(days=60), datetime(now.year, now.month, 1) - timedelta(days=90), ] for date in dates: # Create a fake snapshot for each date snap = Snapshot(self.ec2) snap.tags["Name"] = "foo" # Times are expected to be ISO8601 strings snap.start_time = date.strftime("%Y-%m-%dT%H:%M:%S.000Z") snaps.append(snap) return snaps
def _get_snapshots(self): """ Generate a list of fake snapshots with names and dates. """ snaps = [] # Generate some dates offset by days, weeks, months now = datetime.now() dates = [ now, now - timedelta(days=1), now - timedelta(days=2), now - timedelta(days=7), now - timedelta(days=14), datetime(now.year, now.month, 1) - timedelta(days=30), datetime(now.year, now.month, 1) - timedelta(days=60), datetime(now.year, now.month, 1) - timedelta(days=90) ] for date in dates: # Create a fake snapshot for each date snap = Snapshot(self.ec2) snap.tags['Name'] = 'foo' # Times are expected to be ISO8601 strings snap.start_time = date.strftime('%Y-%m-%dT%H:%M:%S.000Z') snaps.append(snap) return snaps
def _get_snapshots(self): """ Generate a list of fake snapshots with names and dates. """ snaps = [] # Generate some dates offset by days, weeks, months now = datetime.now() dates = [ now, now - timedelta(days=1), now - timedelta(days=2), now - timedelta(days=7), now - timedelta(days=14), # We want to simulate 30/60/90-day snapshots, but February is # short, so decrease by 2 days apiece. datetime(now.year, now.month, 1) - timedelta(days=28), datetime(now.year, now.month, 1) - timedelta(days=58), datetime(now.year, now.month, 1) - timedelta(days=88) ] for date in dates: # Create a fake snapshot for each date snap = Snapshot(self.ec2) snap.tags['Name'] = 'foo' # Times are expected to be ISO8601 strings snap.start_time = date.strftime('%Y-%m-%dT%H:%M:%S.000Z') snaps.append(snap) return snaps
def test_snapshots_returns_snapshots(self): snapshot_one = Snapshot() snapshot_one.volume_id = 1 snapshot_two = Snapshot() snapshot_two.volume_id = 2 self.volume_one.connection = mock.Mock() self.volume_one.connection.get_all_snapshots.return_value = [snapshot_one, snapshot_two] retval = self.volume_one.snapshots() self.assertEqual(retval, [snapshot_one])
def create_snapshot(self, volume_id, name=None, description=None): snapshot = Snapshot() snapshot.id = new_id() snapshot.status = 'pending' self.snapshots[snapshot.id] = snapshot if self.create_snapshot_callback: self.create_snapshot_callback(volume_id, snapshot) return snapshot
def wait_snapshot(ec2_conn, snap_id, logger=None, timeout=SNAPSHOT_TIMEOUT): ''' Waits until snapshot becomes 'completed' or 'error' ''' logger = logger or logging.getLogger(__name__) if isinstance(snap_id, basestring): snap = Snapshot(ec2_conn) snap.id = snap_id else: snap = snap_id logger.debug('Checking that snapshot %s is completed', snap.id) wait_until( lambda: snap.update() and snap.status != 'pending', logger=logger, timeout=timeout, error_text="EBS snapshot %s wasn't completed in a reasonable time" % snap.id ) if snap.status == 'error': raise PlatformError('Snapshot %s creation failed' % snap.id) elif snap.status == 'completed': logger.debug('Snapshot %s completed', snap.id)
def test_snapshot_progress_text(self): # One snapshot. s1 = Snapshot() s1.id = '1' s1.progress = u'25%' self.assertEqual('1: 25%', encrypt_ami._get_snapshot_progress_text([s1])) # Two snapshots. s2 = Snapshot() s2.id = '2' s2.progress = u'50%' self.assertEqual('1: 25%, 2: 50%', encrypt_ami._get_snapshot_progress_text([s1, s2]))
def test_snapshot_progress_text(self): # One snapshot. s1 = Snapshot() s1.id = "1" s1.progress = u"25%" self.assertEqual("1: 25%", encrypt_ami._get_snapshot_progress_text([s1])) # Two snapshots. s2 = Snapshot() s2.id = "2" s2.progress = u"50%" self.assertEqual("1: 25%, 2: 50%", encrypt_ami._get_snapshot_progress_text([s1, s2]))
def test_snapshot_progress_text(self): # One snapshot. s1 = Snapshot() s1.id = '1' s1.progress = u'25%' self.assertEqual( '1: 25%', encrypt_ami._get_snapshot_progress_text([s1]) ) # Two snapshots. s2 = Snapshot() s2.id = '2' s2.progress = u'50%' self.assertEqual( '1: 25%, 2: 50%', encrypt_ami._get_snapshot_progress_text([s1, s2]) )
def create_snapshot(self, volume_id, name=None, description=None): snapshot = Snapshot() snapshot.id = _new_id() snapshot.status = 'pending' self.snapshots[snapshot.id] = snapshot return snapshot