def testRunPreflight(self): client_id = { 'mgmt_enabled': True, 'on_corp': '1', 'owner': 'crosbym', 'track': 'testing', 'uptime': 1211865.2038304806, 'uuid': 'abcd4077-0b34-4572-ba91-cc7aad032b5c', } feedback = { 'upload_logs': 1, 'pkill_installd': 1, 'repair': 1, 'logging_level': 2, } prefs = {'SoftwareRepoURL': 'test_url'} secure_config = {'track': 'testing'} user_settings = {'setting1': 'value1'} self.mox.StubOutWithMock(preflight, 'NoteLastRun') self.mox.StubOutWithMock(preflight.munkicommon, 'ManagedInstallsPreferences') self.mox.StubOutWithMock(preflight.flight_common, 'GetClientIdentifier') self.mox.StubOutWithMock(preflight.munkicommon, 'SecureManagedInstallsPreferences') self.mox.StubOutWithMock(preflight.flight_common, 'GetUserSettings') self.mox.StubOutWithMock(preflight, 'LoginToServer') self.mox.StubOutWithMock(preflight, 'WriteRootCaCerts') self.mox.StubOutWithMock(preflight.flight_common, 'UploadClientLogFiles') self.mox.StubOutWithMock(preflight.flight_common, 'RepairClient') self.mox.StubOutWithMock(preflight, 'CreateEmptyDirectory') self.mox.StubOutWithMock(preflight.flight_common, 'UploadAllManagedInstallReports') mock_client = self.mox.CreateMockAnything() preflight.NoteLastRun().AndReturn(None) preflight.munkicommon.ManagedInstallsPreferences().AndReturn(prefs) preflight.munkicommon.SecureManagedInstallsPreferences().AndReturn( secure_config) preflight.flight_common.GetClientIdentifier('auto').AndReturn( client_id) preflight.flight_common.GetUserSettings().AndReturn(user_settings) preflight.LoginToServer(secure_config, client_id, user_settings, None).AndReturn((mock_client, feedback)) preflight.WriteRootCaCerts(mock_client) preflight.flight_common.UploadClientLogFiles(mock_client) preflight.flight_common.RepairClient() preflight.CreateEmptyDirectory().AndReturn('/test/path') preflight.flight_common.UploadAllManagedInstallReports( mock_client, client_id['on_corp']) self.mox.ReplayAll() preflight.RunPreflight('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