Esempio n. 1
0
    def test_successful_play_from_jar_without_waiting_with_append_args(self):
        config_dir_override = os.path.join(os.path.dirname(__file__), "conf")
        sm_application = SmApplication(config_dir_override)
        context = SmContext(sm_application, None, False, False)
        service_resolver = ServiceResolver(sm_application)

        context.kill_everything()
        time.sleep(5)

        response1 = actions.start_one(context, "FAKE_NEXUS", True, False, None,
                                      None, None)
        self.assertTrue(response1)
        self.assertIsNotNone(context.get_service("FAKE_NEXUS").status())
        time.sleep(5)

        servicetostart = ["PLAY_NEXUS_END_TO_END_TEST"]
        appendArgs = {"PLAY_NEXUS_END_TO_END_TEST": ["-DFoo=Bar"]}
        fatJar = True
        release = False
        proxy = None
        port = None
        seconds_to_wait = None

        try:
            actions.start_and_wait(service_resolver, context, servicetostart,
                                   fatJar, release, proxy, port,
                                   seconds_to_wait, appendArgs)
            time.sleep(5)
            service = SmPlayService(context, "PLAY_NEXUS_END_TO_END_TEST")
            processes = SmProcess.processes_matching(service.pattern)
            self.assertEqual(len(processes), 1)
            self.assertTrue("-DFoo=Bar" in processes[0].args)
        finally:
            context.kill_everything()
Esempio n. 2
0
    def test_successful_play_from_jar_without_waiting_with_append_args(self):
        sm_application = SmApplication(self.config_dir_override)
        context = SmContext(sm_application, None, False, False)
        service_resolver = ServiceResolver(sm_application)

        context.kill_everything(True)

        self.startFakeNexus()

        servicetostart = ["PLAY_NEXUS_END_TO_END_TEST"]
        appendArgs = {"PLAY_NEXUS_END_TO_END_TEST": ["-DFoo=Bar"]}
        fatJar = True
        release = False
        proxy = None
        port = None
        seconds_to_wait = None

        actions.start_and_wait(service_resolver, context, servicetostart,
                               False, fatJar, release, proxy, port,
                               seconds_to_wait, appendArgs)
        service = SmPlayService(context, "PLAY_NEXUS_END_TO_END_TEST")
        self.waitForCondition(
            lambda: len(SmProcess.processes_matching(service.pattern)), 1)
        processes = SmProcess.processes_matching(service.pattern)
        self.assertTrue("-DFoo=Bar" in processes[0].args)
    def test_play_with_append_args(self):
        context = self.createContext()
        self.startFakeNexus()

        server = smserverlogic.SmServer(
            SmApplication(self.config_dir_override, None))
        request = dict()
        request["testId"] = "foo"
        request["services"] = [{
            "serviceName": "PLAY_NEXUS_END_TO_END_TEST",
            "runFrom": "SNAPSHOT",
            "appendArgs": ["-Dfoo=bar"]
        }]
        smserverlogic.SmStartRequest(server, request, True,
                                     False).process_request()

        self.waitForCondition(
            lambda: len(
                context.get_service("PLAY_NEXUS_END_TO_END_TEST").status()), 1)

        service = SmPlayService(context, "PLAY_NEXUS_END_TO_END_TEST")
        processes = SmProcess.processes_matching(service.pattern)
        self.assertEqual(len(processes), 1)
        self.assertTrue("-Dfoo=bar" in processes[0].args)

        context.kill_everything(True)
        self.assertEqual(
            context.get_service("PLAY_NEXUS_END_TO_END_TEST").status(), [])
Esempio n. 4
0
def get_log_file(context, service_name):
    def mtime(path):
        try:
            return os.path.getmtime(path)
        except os.error:
            return 0

    data = context.service_data(service_name)
    if "location" in data:
        logs = [
            context.application.workspace + data["location"] +
            "/logs/stdout.txt",
            context.application.workspace + data["location"] +
            "/target/logs/stdout.txt",
            SmPlayService.unzipped_dir_path(context, data["location"]) +
            "/logs/stdout.txt",
        ]
        if not any([os.path.exists(log) for log in logs]):
            raise ServiceManagerException("Cannot find log files for %s" %
                                          service_name)
        else:
            return sorted(logs, key=mtime, reverse=True)[0]
    else:
        raise ServiceManagerException("Cannot find a location for %s" %
                                      service_name)
Esempio n. 5
0
    def get_service(self, service_name):
        service_type = self.service_type(service_name)

        if service_type == "external":
            return SmExternalService(self, service_name)
        elif service_type == "dropwizard":
            return SmDropwizardService(self, service_name)
        elif service_type == "play":
            return SmPlayService(self, service_name)
        elif service_type == "assets":
            return SmPythonService(self, service_name)
        else:
            raise self.exception("Unknown service type '%s' for service '%s' - please check services.json" % (service_type, service_name))
Esempio n. 6
0
def get_log_file(context, service_name):

    def mtime(path):
        try:
            return os.path.getmtime(path)
        except os.error:
            return 0

    data = context.service_data(service_name)
    if "location" in data:
        logs = [context.application.workspace + data["location"] + "/logs/stdout.txt",
                context.application.workspace + data["location"] + "/target/logs/stdout.txt",
                SmPlayService.unzipped_dir_path(context, data["location"]) + "/logs/stdout.txt"]
        if not any([os.path.exists(log) for log in logs]):
            raise ServiceManagerException("Cannot find log files for %s" % service_name)
        else:
            return sorted(logs, key=mtime, reverse=True)[0]
    else:
        raise ServiceManagerException("Cannot find a location for %s" % service_name)
Esempio n. 7
0
    def test_play_with_append_args(self):
        config_dir_override = os.path.join(os.path.dirname(__file__), "conf")
        context = SmContext(SmApplication(config_dir_override), None, False,
                            False)
        context.kill_everything()

        # Start up fake nexus first
        response1 = actions.start_one(context,
                                      "FAKE_NEXUS",
                                      True,
                                      False,
                                      None,
                                      port=None)
        self.assertTrue(response1)
        self.assertIsNotNone(context.get_service("FAKE_NEXUS").status())
        time.sleep(5)

        server = smserverlogic.SmServer(
            SmApplication(config_dir_override, None))
        request = dict()
        request["testId"] = "foo"
        request["services"] = [{
            "serviceName": "PLAY_NEXUS_END_TO_END_TEST",
            "runFrom": "SNAPSHOT",
            "appendArgs": ["-Dfoo=bar"]
        }]
        smserverlogic.SmStartRequest(server, request, True,
                                     False).process_request()
        time.sleep(5)
        self.assertEqual(
            len(context.get_service("PLAY_NEXUS_END_TO_END_TEST").status()), 1)
        service = SmPlayService(context, "PLAY_NEXUS_END_TO_END_TEST")
        processes = SmProcess.processes_matching(service.pattern)
        self.assertEqual(len(processes), 1)
        self.assertTrue("-Dfoo=bar" in processes[0].args)
        context.kill_everything()
        self.assertEqual(context.get_service("TEST_ONE").status(), [])