def _DisplayHostManifest(self, uuid): """Display live manifest view for a host. Args: uuid: str, computer uuid to display """ manifest = common.GetComputerManifest(uuid=uuid, packagemap=True) contents = manifest['plist'].GetContents() for itype in [ 'managed_installs', 'optional_installs', 'managed_updates' ]: for n in xrange(0, len(contents.get(itype, []))): if contents[itype][n] in manifest['packagemap']: contents[itype][n] = ( '(((a href="' '/admin/installs?pkg=%s' '")))%s(((/a)))' % (manifest['packagemap'][contents[itype][n]], contents[itype][n])) manifest_str = manifest['plist'].GetXml() manifest_str = manifest_str.replace('<', '<') manifest_str = manifest_str.replace('>', '>') manifest_str = manifest_str.replace('(((', '<') manifest_str = manifest_str.replace(')))', '>') self.response.out.write( RenderTemplate('templates/stats_host_manifest.html', { 'uuid': uuid, 'manifest': manifest_str, }))
def _DisplayHostManifest(self, uuid): """Display live manifest view for a host. Args: uuid: str, computer uuid to display """ if not uuid: self.response.set_status(404) return manifest = common.GetComputerManifest(uuid=uuid, packagemap=True) contents = manifest['plist'].GetContents() manifest_str = manifest['plist'].GetXml() if self.request.get('format') == 'xml': self.response.headers['Content-Type'] = 'text/xml; charset=utf-8' self.response.out.write(manifest_str) else: manifest_html = admin.XmlToHtml(manifest_str) self.Render( 'plist.html', { 'plist_type': 'host_manifest', 'title': 'Host Manifest: %s' % uuid, 'xml': manifest_html, 'raw_xml_link': '/admin/hostmanifest/%s?format=xml' % uuid, })
def testGetComputerManifestIsPanicMode(self): """Test ComputerInstallsPending().""" uuid = 'uuid' last_notified_datetime = self.mox.CreateMockAnything() client_id = { 'uuid': 'uuid', 'owner': 'owner', 'hostname': 'hostname', 'serial': 'serial', 'config_track': 'config_track', 'track': 'track', 'site': 'site', 'office': 'office', 'os_version': 'os_version', 'client_version': 'client_version', 'on_corp': True, 'last_notified_datetime': last_notified_datetime, 'uptime': None, 'root_disk_free': None, 'user_disk_free': None, } computer = test.GenericContainer(**client_id) computer.connections_on_corp = 2 computer.connections_off_corp = 1 computer.user_settings = None # PackageInfo entities package_infos = [ test.GenericContainer(plist='plistOtherPackage', version='1.0'), test.GenericContainer(plist='plistPackageInstalled1', version='1.0'), test.GenericContainer(plist='plistPackageInstalled2', version='1.0'), test.GenericContainer(plist='plistPackageNotInstalled1', version='1.0'), ] packagemap = {} self.mox.StubOutWithMock(common.models, 'Computer') self.mox.StubOutWithMock(common, 'IsPanicModeNoPackages') common.models.Computer.get_by_key_name(uuid).AndReturn(computer) common.IsPanicModeNoPackages().AndReturn(True) manifest_expected = '%s%s' % ( common.plist_module.PLIST_HEAD, common.plist_module.PLIST_FOOT) self.mox.ReplayAll() manifest = common.GetComputerManifest(uuid=uuid) self.assertEqual(manifest, manifest_expected) self.mox.VerifyAll()
def get(self, client_id_str=''): """Manifest get handler. Args: client_id: optional str client_id; only needed for user requests. Returns: A webapp.Response() response. """ session = auth.DoAnyAuth() client_id = handlers.GetClientIdForRequest(self.request, session=session, client_id_str=client_id_str) try: plist_xml = common.GetComputerManifest(client_id=client_id, packagemap=False) except common.ManifestNotFoundError, e: logging.warning('Invalid manifest requested: %s', str(e)) self.response.set_status(404) return
def testGetComputerManifest(self): """Test ComputerInstallsPending().""" uuid = 'uuid' last_notified_datetime = self.mox.CreateMockAnything() client_id = { 'uuid': 'uuid', 'owner': 'owner', 'hostname': 'hostname', 'serial': 'serial', 'config_track': 'config_track', 'track': 'track', 'site': 'site', 'office': 'office', 'os_version': 'os_version', 'client_version': 'client_version', 'on_corp': True, 'last_notified_datetime': last_notified_datetime, 'uptime': None, 'root_disk_free': None, 'user_disk_free': None, } computer = test.GenericContainer(**client_id) computer.connections_on_corp = 2 computer.connections_off_corp = 1 computer.user_settings = None # PackageInfo entities mock_pl1 = self.mox.CreateMockAnything() mock_pl2 = self.mox.CreateMockAnything() mock_pl3 = self.mox.CreateMockAnything() mock_pl4 = self.mox.CreateMockAnything() package_infos = [ test.GenericContainer(plist=mock_pl1, version='1.0', name='fooname1'), test.GenericContainer(plist=mock_pl2, version='1.0', name='fooname2'), test.GenericContainer(plist=mock_pl3, version='1.0', name='fooname3'), test.GenericContainer(plist=mock_pl4, version='1.0', name='fooname4'), ] packagemap = {} self.mox.StubOutWithMock(common.models, 'Computer') self.mox.StubOutWithMock(common, 'IsPanicModeNoPackages') self.mox.StubOutWithMock(common.models, 'Manifest') self.mox.StubOutWithMock(common, 'GenerateDynamicManifest') self.mox.StubOutWithMock(common.plist_module, 'MunkiManifestPlist') self.mox.StubOutWithMock(common.models, 'PackageInfo') self.mox.StubOutWithMock(common.plist_module, 'MunkiPackageInfoPlist') # mock manifest creation common.models.Computer.get_by_key_name(uuid).AndReturn(computer) common.IsPanicModeNoPackages().AndReturn(False) mock_plist = self.mox.CreateMockAnything() common.models.Manifest.MemcacheWrappedGet('track').AndReturn( test.GenericContainer(enabled=True, plist=mock_plist)) common.GenerateDynamicManifest( mock_plist, client_id, user_settings=None).AndReturn( 'manifest_plist') # mock manifest parsing mock_manifest_plist = self.mox.CreateMockAnything() common.plist_module.MunkiManifestPlist('manifest_plist').AndReturn( mock_manifest_plist) mock_manifest_plist.Parse().AndReturn(None) # mock manifest reading and package map creation mock_package_info = self.mox.CreateMockAnything() common.models.PackageInfo.all().AndReturn(mock_package_info) iter_return = [] for package_info in package_infos: iter_return.append(test.GenericContainer( plist=package_info.plist, name=package_info.name)) package_info.plist.get('display_name', None).AndReturn(None) package_info.plist.get('name').AndReturn(package_info.name) package_info.plist.get('version', '').AndReturn(package_info.version) packagemap[package_info.name] = '%s-%s' % ( package_info.name, package_info.version) def __iter_func(): for i in iter_return: yield i mock_package_info.__iter__().AndReturn(__iter_func()) manifest_expected = { 'plist': mock_manifest_plist, 'packagemap': packagemap, } self.mox.ReplayAll() manifest = common.GetComputerManifest(uuid=uuid, packagemap=True) self.assertEqual(manifest, manifest_expected) self.mox.VerifyAll()