def testRunPostflight(self): pkgs_to_install = ['pkg1', 'pkg2'] updates_to_install = ['update1', 'update2'] client_id = { 'uuid': 'abcd4077-0b34-4572-ba91-cc7aad032b5c', 'on_corp': '1', } expected_report = { 'apple_updates_to_install': updates_to_install, 'client_id': 'fake_string', 'pkgs_to_install': pkgs_to_install, } mock_url = 'http://test-url' mock_client = self.mox.CreateMockAnything() self.mox.StubOutWithMock(postflight.flight_common, 'GetServerURL') self.mox.StubOutWithMock(postflight.flight_common, 'GetAuth1Token') self.mox.StubOutWithMock(postflight.flight_common, 'GetClientIdentifier') self.mox.StubOutWithMock(postflight.flight_common, 'GetRemainingPackagesToInstall') self.mox.StubOutWithMock(postflight.mac_client, 'SimianAuthClient') # mock out DictToStr because of hash randomization. self.mox.StubOutWithMock(postflight.flight_common, 'DictToStr') self.mox.StubOutWithMock(postflight.flight_common, 'UploadAllManagedInstallReports') self.mox.StubOutWithMock(postflight.munkicommon, 'cleanUpTmpDir') self.mox.StubOutWithMock(postflight, 'IsAppInPlace') self.mox.StubOutWithMock(postflight, 'NoteLastSuccess') postflight.flight_common.GetServerURL().AndReturn(mock_url) postflight.flight_common.GetAuth1Token().AndReturn('fake_auth') postflight.flight_common.GetClientIdentifier('auto').AndReturn( client_id) postflight.mac_client.SimianAuthClient( 'abcd4077-0b34-4572-ba91-cc7aad032b5c', hostname=mock_url).AndReturn(mock_client) mock_client.SetAuthToken('fake_auth') postflight.flight_common.GetClientIdentifier('auto').AndReturn( client_id) postflight.flight_common.GetRemainingPackagesToInstall().AndReturn( (pkgs_to_install, updates_to_install)) postflight.flight_common.DictToStr(client_id).AndReturn('fake_string') mock_client.PostReport('postflight', expected_report) postflight.flight_common.UploadAllManagedInstallReports( mock_client, client_id['on_corp']) postflight.IsAppInPlace().AndReturn(True) mock_client.LogoutAuthToken().AndReturn(True) postflight.munkicommon.cleanUpTmpDir() postflight.NoteLastSuccess().AndReturn(None) self.mox.ReplayAll() postflight.RunPostflight('auto') self.mox.VerifyAll()
def main(args): opts, args = getopt.gnu_getopt(args, '', ['debug', 'server=']) action = args[0] if args else None if action not in ACTIONS: PrintOptions() return 1 logging.getLogger().setLevel(logging.WARNING) server_url = None for option, value in opts: if option == '--debug': logging.getLogger().setLevel(logging.DEBUG) # override logging.exception to print helpful tracebacks. def NewLoggingException(msg, *args): logging.debug(msg, exc_info=sys.exc_info(), *args) logging.exception = NewLoggingException elif option == '--server': server_url = value # munki passes a "runtype" to preflight/postflight; i.e. auto, manual, etc. runtype = args[1] if len(args) > 1 else 'custom' if action == 'preflight': preflight.RunPreflight(runtype, server_url=server_url) elif action == 'postflight': postflight.RunPostflight(runtype) elif action == 'report_broken_client': report_broken_client.main() elif action == 'version': print version.Version(args) else: PrintOptions() return 1 return 0