def testSuccess(self): data_disk = ecs.Disk('d2', 'data', 'ephemeral', 100) system_disk = ecs.Disk('d1', 'system', 'cloud', 100) self.conn.describe_instance_disks('i1').AndReturn( [data_disk, system_disk]) self.conn.create_snapshot( 'i1', 'd1', timeout_secs=mox.IsA(int)).AndReturn('s1') self.conn.create_image('s1', image_version=None, description=None, os_name=None).AndReturn('img1') time.sleep(mox.IsA(int)) self.mox.ReplayAll() self.assertEqual(('s1', 'img1'), self.conn.create_image_from_instance('i1')) self.mox.VerifyAll()
def testSystemDiskNotFound(self): data_disk = ecs.Disk('d2', 'data', 'ephemeral', 100) self.conn.describe_instance_disks('i1').AndReturn([data_disk]) self.mox.ReplayAll() try: self.conn.create_image_from_instance('i1') self.fail('Should throw error if system disk not found') except ecs.Error as err: self.assertTrue('not found' in str(err)) self.mox.VerifyAll()
def testSuccess(self): get_response = { 'Disks': { 'Disk': [ {'DiskId': 'd1', 'Type': 'system', 'Category': 'cloud', 'Size': '20'}, {'DiskId': 'd2', 'Type': 'data', 'Category': 'ephemeral', 'Size': '100'} ] } } expected_result = [ecs.Disk('d1', 'system', 'cloud', 20), ecs.Disk('d2', 'data', 'ephemeral', 100)] self.conn.get({'Action': 'DescribeInstanceDisks', 'InstanceId': 'i1'}).AndReturn(get_response) self.mox.ReplayAll() self.assertEqual( expected_result, self.conn.describe_instance_disks('i1')) self.mox.VerifyAll()
def testRepr(self): d1 = ecs.Disk('d1', 'system', 'cloud', 5) self.assertTrue( repr(d1).startswith(u'<Disk d1 of type system is 5GB at'))
def testNotEqual(self): d1 = ecs.Disk('d1', 'system', 'cloud', 5) d2 = ecs.Disk('d1', 'system', 'cloud', 6) self.assertNotEqual(d1, d2)