def get_preseed(self, request, version=None, system_id=None): """Render and return a preseed script for the given node.""" node = get_object_or_404(Node, system_id=system_id) # XXX: Set a charset for text/plain. Django automatically encodes # non-binary content using DEFAULT_CHARSET (which is UTF-8 by default) # but only sets the charset parameter in the content-type header when # a content-type is NOT provided. return HttpResponse(get_preseed(node), content_type="text/plain")
def get_context_data(self, **kwargs): context = super(NodePreseedView, self).get_context_data(**kwargs) node = self.get_object() # Display the preseed content exactly as generated by # `get_preseed`. This will be rendered in a <pre> tag. context['preseed'] = mark_safe(get_preseed(node)) context['is_commissioning'] = ( node.status == NODE_STATUS.COMMISSIONING) return context
def test_preseedview_node_displays_message_if_commissioning(self): node = factory.make_node( owner=self.logged_in_user, status=NODE_STATUS.COMMISSIONING, ) node_preseed_link = reverse('node-preseed-view', args=[node.system_id]) response = self.client.get(node_preseed_link) self.assertThat( response.content, ContainsAll([get_preseed(node), "This node is commissioning."]))
def test_compose_preseed_url_links_to_preseed_for_node(self): node = factory.make_node() response = self.client.get(compose_preseed_url(node)) self.assertEqual( (httplib.OK, get_preseed(node)), (response.status_code, response.content))
def test_get_preseed_returns_commissioning_preseed(self): node = factory.make_node(status=NODE_STATUS.COMMISSIONING) preseed = get_preseed(node) self.assertIn('#cloud-config', preseed)
def test_get_preseed_returns_default_preseed(self): node = factory.make_node() preseed = get_preseed(node) self.assertIn('preseed/late_command', preseed)
def get_preseed(self, request, version=None, system_id=None): """Render and return a preseed script for the given node.""" node = get_object_or_404(Node, system_id=system_id) return HttpResponse(get_preseed(node), mimetype="text/plain")
def test_compose_preseed_url_links_to_preseed_for_node(self): node = factory.make_node() response = self.client.get(compose_preseed_url(node)) self.assertEqual((httplib.OK, get_preseed(node)), (response.status_code, response.content))
def test_get_preseed_returns_curtin_preseed(self): node = factory.make_node() node.use_fastpath_installer() preseed = get_preseed(node) curtin_url = reverse('curtin-metadata') self.assertIn(curtin_url, preseed)
def test_preseedview_node_displays_preseed_data(self): node = factory.make_node(owner=self.logged_in_user) node_preseed_link = reverse('node-preseed-view', args=[node.system_id]) response = self.client.get(node_preseed_link) self.assertIn(get_preseed(node), response.content)