def testGetComputerManifestWhenEmptyDynamic(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') 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(None) self.mox.ReplayAll() self.assertRaises( common.ManifestNotFoundError, common.GetComputerManifest, uuid=uuid) self.mox.VerifyAll()
def testGenerateDynamicManifestWhenNoMods(self): """Test GenerateDynamicManifest() when no manifest mods are available.""" self.mox.StubOutWithMock(common.models, 'SiteManifestModification') self.mox.StubOutWithMock(common.models, 'OSVersionManifestModification') self.mox.StubOutWithMock(common.models, 'OwnerManifestModification') self.mox.StubOutWithMock(common.models, 'UuidManifestModification') self.mox.StubOutWithMock(common.models.db.Key, 'from_path') self.mox.StubOutWithMock(common.models.Tag, 'GetAllTagNamesForKey') client_id = { 'site': 'sitex', 'os_version': 'os_versionx', 'owner': 'ownerx', 'uuid': 'uuidx', 'track': 'trackx', } user_settings = None plist_xml = '<plist xml>' common.models.SiteManifestModification.MemcacheWrappedGetAllFilter( (('site =', client_id['site']),)).AndReturn([]) common.models.OSVersionManifestModification.MemcacheWrappedGetAllFilter( (('os_version =', client_id['os_version']),)).AndReturn([]) common.models.OwnerManifestModification.MemcacheWrappedGetAllFilter( (('owner =', client_id['owner']),)).AndRaise([]) common.models.UuidManifestModification.MemcacheWrappedGetAllFilter( (('uuid =', client_id['uuid']),)).AndRaise([]) common.models.db.Key.from_path('Computer', client_id['uuid']).AndReturn('k') common.models.Tag.GetAllTagNamesForKey('k').AndReturn([]) self.mox.ReplayAll() self.assertTrue( common.GenerateDynamicManifest( plist_xml, client_id, user_settings) is plist_xml) self.mox.VerifyAll()
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()
def testGenerateDynamicManifestWhenOnlyUserSettingsMods(self): """Test GenerateDynamicManifest() when only user_settings mods exist.""" self.mox.StubOutWithMock(common.models, 'SiteManifestModification') self.mox.StubOutWithMock(common.models, 'OSVersionManifestModification') self.mox.StubOutWithMock(common.models, 'OwnerManifestModification') self.mox.StubOutWithMock(common.models, 'UuidManifestModification') self.mox.StubOutWithMock(common.models, 'TagManifestModification') self.mox.StubOutWithMock(common.models.db.Key, 'from_path') self.mox.StubOutWithMock(common.models.Tag, 'GetAllTagNamesForKey') client_id = { 'site': 'sitex', 'os_version': 'os_versionx', 'owner': 'ownerx', 'uuid': 'uuidx', 'track': 'trackx', } blocked_package_name = 'FooPackage' user_settings = { 'BlockPackages': [blocked_package_name], 'FlashDeveloper': True, } plist_xml = '<plist xml>' common.models.SiteManifestModification.MemcacheWrappedGetAllFilter( (('site =', client_id['site']),)).AndReturn([]) common.models.OSVersionManifestModification.MemcacheWrappedGetAllFilter( (('os_version =', client_id['os_version']),)).AndReturn([]) common.models.OwnerManifestModification.MemcacheWrappedGetAllFilter( (('owner =', client_id['owner']),)).AndReturn([]) common.models.UuidManifestModification.MemcacheWrappedGetAllFilter( (('uuid =', client_id['uuid']),)).AndReturn([]) common.models.db.Key.from_path('Computer', client_id['uuid']).AndReturn('k') common.models.Tag.GetAllTagNamesForKey('k').AndReturn(['tag']) common.models.TagManifestModification.MemcacheWrappedGetAllFilter( (('tag_key_name =', 'tag'),)).AndReturn([]) managed_installs = [ 'FooPkg', blocked_package_name, common.FLASH_PLUGIN_NAME] managed_updates = [] mock_plist = self.mox.CreateMockAnything() self.mox.StubOutWithMock(common.plist_module, 'MunkiManifestPlist') common.plist_module.MunkiManifestPlist(plist_xml).AndReturn(mock_plist) mock_plist.Parse().AndReturn(None) # FlashDeveloper is True, so managed_updates and managed_installs are read. mock_plist.__getitem__(common.common.MANAGED_UPDATES).AndReturn( managed_updates) mock_plist.__getitem__(common.common.MANAGED_UPDATES).AndReturn( managed_installs) for blocked_pkg in user_settings['BlockPackages']: for install_type in common.common.INSTALL_TYPES: if install_type == 'managed_installs': mock_plist.get(install_type, []).AndReturn(managed_installs) if blocked_pkg == blocked_package_name: mock_plist.__getitem__(install_type).AndReturn(managed_installs) else: mock_plist.get(install_type, []).AndReturn([]) mock_plist.GetXml().AndReturn(plist_xml) self.mox.ReplayAll() xml_out = common.GenerateDynamicManifest( plist_xml, client_id, user_settings=user_settings) self.assertEqual(plist_xml, xml_out) self.assertTrue(blocked_package_name not in managed_installs) # non-debug flashplugin should be removed from managed_updates self.assertTrue(common.FLASH_PLUGIN_NAME not in managed_installs) self.assertTrue(common.FLASH_PLUGIN_DEBUG_NAME in managed_updates) self.mox.VerifyAll()
def testGenerateDynamicManifest(self): """Tests GenerateDynamicManifest().""" plist_xml = 'fooxml' manifest = 'stable' site = 'foosite' os_version = '10.6.5' owner = 'foouser' uuid = '12345' client_id = { 'track': manifest, 'site': site, 'os_version': os_version, 'owner': owner, 'uuid': uuid, } blocked_package_name = 'FooBlockedPkg' user_settings = { 'BlockPackages': [blocked_package_name] } install_type_optional_installs = 'optional_installs' install_type_managed_updates = 'managed_updates' value_one = 'foopkg' site_mod_one = self.mox.CreateMockAnything() site_mod_one.manifests = [manifest] site_mod_one.enabled = True site_mod_one.install_types = [install_type_optional_installs] site_mod_one.value = value_one site_mod_disabled = self.mox.CreateMockAnything() site_mod_disabled.enabled = False site_mods = [site_mod_one, site_mod_disabled] self.mox.StubOutWithMock( common.models.SiteManifestModification, 'MemcacheWrappedGetAllFilter') common.models.SiteManifestModification.MemcacheWrappedGetAllFilter( (('site =', site),)).AndReturn(site_mods) os_version_mod_one = self.mox.CreateMockAnything() os_version_mod_one.manifests = [manifest] os_version_mod_one.enabled = True os_version_mod_one.install_types = [install_type_managed_updates] os_version_mod_one.value = 'foo os version pkg' os_version_mods = [os_version_mod_one] self.mox.StubOutWithMock( common.models.OSVersionManifestModification, 'MemcacheWrappedGetAllFilter') common.models.OSVersionManifestModification.MemcacheWrappedGetAllFilter( (('os_version =', os_version),)).AndReturn(os_version_mods) owner_mod_one = self.mox.CreateMockAnything() owner_mod_one.manifests = [manifest] owner_mod_one.enabled = True owner_mod_one.install_types = [ install_type_optional_installs, install_type_managed_updates] owner_mod_one.value = 'foo owner pkg' owner_mods = [owner_mod_one] self.mox.StubOutWithMock( common.models.OwnerManifestModification, 'MemcacheWrappedGetAllFilter') common.models.OwnerManifestModification.MemcacheWrappedGetAllFilter( (('owner =', client_id['owner']),)).AndReturn(owner_mods) uuid_mod_one = self.mox.CreateMockAnything() uuid_mod_one.enabled = False uuid_mods = [uuid_mod_one] self.mox.StubOutWithMock( common.models.UuidManifestModification, 'MemcacheWrappedGetAllFilter') common.models.UuidManifestModification.MemcacheWrappedGetAllFilter( (('uuid =', client_id['uuid']),)).AndReturn(uuid_mods) computer_tags = ['footag1', 'footag2'] self.mox.StubOutWithMock(common.models.Tag, 'GetAllTagNamesForKey') self.mox.StubOutWithMock(common.models.db.Key, 'from_path') common.models.db.Key.from_path('Computer', client_id['uuid']).AndReturn('k') common.models.Tag.GetAllTagNamesForKey('k').AndReturn(computer_tags) tag_mod_one = self.mox.CreateMockAnything() tag_mod_one.enabled = False tag_mods = [tag_mod_one] self.mox.StubOutWithMock( common.models.TagManifestModification, 'MemcacheWrappedGetAllFilter') common.models.TagManifestModification.MemcacheWrappedGetAllFilter( (('tag_key_name =', 'footag1'),)).AndReturn([]) common.models.TagManifestModification.MemcacheWrappedGetAllFilter( (('tag_key_name =', 'footag2'),)).AndReturn(tag_mods) mock_plist = self.mox.CreateMockAnything() managed_installs = ['FooPkg', blocked_package_name] self.mox.StubOutWithMock(common.plist_module, 'UpdateIterable') self.mox.StubOutWithMock(common.plist_module, 'MunkiManifestPlist') common.plist_module.MunkiManifestPlist(plist_xml).AndReturn(mock_plist) mock_plist.Parse().AndReturn(None) common.plist_module.UpdateIterable( mock_plist, site_mod_one.install_types[0], site_mod_one.value, default=[], op=common._ModifyList) common.plist_module.UpdateIterable( mock_plist, os_version_mod_one.install_types[0], os_version_mod_one.value, default=[], op=common._ModifyList) common.plist_module.UpdateIterable( mock_plist, owner_mod_one.install_types[0], owner_mod_one.value, default=[], op=common._ModifyList) common.plist_module.UpdateIterable( mock_plist, owner_mod_one.install_types[1], owner_mod_one.value, default=[], op=common._ModifyList) for install_type in common.common.INSTALL_TYPES: if install_type == 'managed_installs': mock_plist.get(install_type, []).AndReturn(managed_installs) mock_plist.__getitem__(install_type).AndReturn(managed_installs) else: mock_plist.get(install_type, []).AndReturn([]) mock_plist.GetXml().AndReturn(plist_xml) self.mox.ReplayAll() xml_out = common.GenerateDynamicManifest( plist_xml, client_id, user_settings=user_settings) self.assertEqual(plist_xml, xml_out) self.assertTrue(blocked_package_name not in managed_installs) self.mox.VerifyAll()