예제 #1
0
    def testBlockingSucceeds(self):
        get_response = {
            'SnapshotId': 's1'
        }
        incomplete_snapshot = ecs.Snapshot('s1', None, 99,
                                           datetime.datetime.now())
        complete_snapshot = ecs.Snapshot('s1', None, 100,
                                         datetime.datetime.now())
        self.conn.get({'Action': 'CreateSnapshot',
                       'InstanceId': 'i1',
                       'DiskId': 'd1'}).AndReturn(get_response)
        time.sleep(mox.IsA(int))
        self.conn.describe_snapshot('s1').AndReturn(
            incomplete_snapshot)
        time.sleep(mox.IsA(int))
        self.conn.describe_snapshot('s1').AndReturn(
            incomplete_snapshot)
        time.sleep(mox.IsA(int))
        self.conn.describe_snapshot('s1').AndReturn(
            complete_snapshot)

        self.mox.ReplayAll()
        self.assertEqual('s1', self.conn.create_snapshot(
            'i1', 'd1', timeout_secs=300))
        self.mox.VerifyAll()
예제 #2
0
    def testSuccess(self):
        get_response = {
            'Snapshots': {
                'Snapshot': [
                    {'SnapshotId': 's1',
                     'SnapshotName': 'n1',
                     'Progress': '100',
                     'CreationTime': '2014-02-05T00:52:32Z'},
                    {'SnapshotId': 's2',
                     'Progress': '100',
                     'CreationTime': '2014-02-05T00:52:32Z'}
                ]
            }
        }
        expected_result = [ecs.Snapshot(
            's1', 'n1', 100, dateutil.parser.parse('2014-02-05T00:52:32Z')),
            ecs.Snapshot(
                's2', None, 100, dateutil.parser.parse(
                    '2014-02-05T00:52:32Z'))]
        self.conn.get({'Action': 'DescribeSnapshots',
                       'InstanceId': 'i1',
                       'DiskId': 'd1'}).AndReturn(get_response)

        self.mox.ReplayAll()
        self.assertEqual(
            expected_result,
            self.conn.describe_snapshots(
                'i1',
                'd1'))
        self.mox.VerifyAll()
예제 #3
0
    def testNoName(self):
        get_response = {
            'SnapshotId': 's1',
            'Progress': '100',
            'CreationTime': '2014-02-05T00:52:32Z'
        }
        expected_result = ecs.Snapshot(
            's1', None, 100,
            dateutil.parser.parse('2014-02-05T00:52:32Z'))
        self.conn.get({'Action': 'DescribeSnapshotAttribute',
                       'SnapshotId': 's1'}).AndReturn(get_response)

        self.mox.ReplayAll()
        self.assertEqual(expected_result, self.conn.describe_snapshot('s1'))
        self.mox.VerifyAll()
예제 #4
0
    def testBlockingTimesOut(self):
        get_response = {
            'SnapshotId': 's1'
        }
        incomplete_snapshot = ecs.Snapshot('s1', None, 99,
                                           datetime.datetime.now())
        self.conn.get({'Action': 'CreateSnapshot',
                       'InstanceId': 'i1',
                       'DiskId': 'd1'}).AndReturn(get_response)
        time.sleep(mox.IsA(int)).MultipleTimes()
        self.conn.describe_snapshot('s1').MultipleTimes().AndReturn(
            incomplete_snapshot)

        self.mox.ReplayAll()
        try:
            self.conn.create_snapshot(
                'i1', 'd1', timeout_secs=300)
            self.fail('Should error out on timeout')
        except ecs.Error as err:
            self.assertTrue('not ready' in str(err))
        self.mox.VerifyAll()
예제 #5
0
 def testRepr(self):
     s1 = ecs.Snapshot('s1', 'sn', 100, self.now)
     self.assertTrue(repr(s1).startswith(u'<Snapshot s1 is 100% ready at'))
예제 #6
0
 def testNotEqual(self):
     s1 = ecs.Snapshot('s1', 'sn', 100, self.now)
     s2 = ecs.Snapshot('s1', 'sn', 99, self.now)
     self.assertNotEqual(s1, s2)