def test_snapshot_instance_not_found(self): boto.ec2.EC2Connection.create_image = mock.Mock() self._create_instance() GlanceImageServiceV2.update = mock.Mock() expected_calls = [{'args': (), 'kwargs': { 'task_state': task_states.IMAGE_UPLOADING, 'expected_state': task_states.IMAGE_SNAPSHOT}}] func_call_matcher = matchers.FunctionCallMatcher(expected_calls) self.assertRaises(exception.InstanceNotFound, self.conn.snapshot, self.context, self.instance, 'test-snapshot', func_call_matcher.call) boto.ec2.EC2Connection.create_image.assert_not_called() self.reset()
def test_snapshot(self, byname_mock): # Use mix-case to test that mixed-case image names succeed. snapshot_name = 'tEsT-SnAp' expected_calls = [{ 'args': (), 'kwargs': { 'task_state': task_states.IMAGE_PENDING_UPLOAD } }, { 'args': (), 'kwargs': { 'task_state': task_states.IMAGE_UPLOADING, 'expected_state': task_states.IMAGE_PENDING_UPLOAD } }] func_call_matcher = matchers.FunctionCallMatcher(expected_calls) instance_ref = utils.get_test_instance() properties = { 'instance_id': instance_ref['id'], 'user_id': str(self.context.user_id) } sent_meta = { 'name': snapshot_name, 'is_public': False, 'status': 'creating', 'properties': properties } # Because the docker driver doesn't push directly into Glance, we # cannot check that the images are correctly configured in the # fake image service, but we can ensuring naming and other # conventions are accurate. image_service = nova.tests.unit.image.fake.FakeImageService() recv_meta = image_service.create(context, sent_meta) with mock.patch.object(self.mock_client, 'load_image'): with mock.patch.object(self.mock_client, 'get_image'): self.connection.snapshot(self.context, instance_ref, recv_meta['id'], func_call_matcher.call) snapshot = image_service.show(context, recv_meta['id']) self.assertEqual(snapshot['properties']['image_state'], 'available') self.assertEqual(snapshot['status'], 'active') self.assertEqual(snapshot['disk_format'], 'raw') self.assertEqual(snapshot['container_format'], 'docker') self.assertEqual(snapshot['name'], snapshot_name)
def test_snapshot(self): self._create_vm_in_aws_nova() GlanceImageServiceV2.update = mock.Mock() expected_calls = [{'args': (), 'kwargs': { 'task_state': task_states.IMAGE_UPLOADING, 'expected_state': task_states.IMAGE_SNAPSHOT}}] func_call_matcher = matchers.FunctionCallMatcher(expected_calls) self.conn.snapshot(self.context, self.instance, 'test-snapshot', func_call_matcher.call) self.assertIsNone(func_call_matcher.match()) _, snapshot_name, metadata = GlanceImageServiceV2.update.call_args[0] aws_imgs = self.fake_ec2_conn.get_all_images() self.assertEqual(1, len(aws_imgs)) aws_img = aws_imgs[0] self.assertEqual(snapshot_name, 'test-snapshot') self.assertEqual(aws_img.name, 'test-snapshot') self.assertEqual(aws_img.id, metadata['properties']['ec2_image_id']) self.reset()