def _create_resource(self, name, snippet, stack, status='Running'): value = mock.MagicMock(uuid=self.resource_id) self.client.containers.run.return_value = value get_rv = mock.MagicMock(status=status) self.client.containers.get.return_value = get_rv c = container.Container(name, snippet, stack) return c
def test_create_failed(self): c = container.Container('container', self.rsrc_defn, self.stack) self.client.containers.run.side_effect = Exception('error') exc = self.assertRaises(exception.ResourceFailure, scheduler.TaskRunner(c.run)) expected_state = (c.CREATE, c.FAILED) self.assertEqual(expected_state, c.state) self.assertIn('Exception: resources.container: error', six.text_type(exc))
def _create_resource(self, name, snippet, stack): c = container.Container(name, snippet, stack) value = mock.MagicMock(id='12345') self.client.containers.create.return_value = value self.client.containers.get.return_value = value scheduler.TaskRunner(c.create)() args = self.client.containers.create.call_args[1] self.assertEqual(self.rsrc_defn._properties, args) self.assertEqual('12345', c.resource_id) return c