예제 #1
0
    def test_some_cronjobs_are_added_between_containing_comments(self):
        with temp_file(
                "schedule,collector-slug,creds.json,token.json,performanceplatform.json"
        ) as jobs_path:
            generated_jobs = crontab.generate_crontab([], jobs_path,
                                                      "/path/to/my-app",
                                                      'some_id')
            assert_that(
                generated_jobs,
                has_item(
                    '# Begin performanceplatform.collector jobs for some_id'))

            assert_that(generated_jobs, has_item(contains_string("schedule")))
            assert_that(generated_jobs,
                        has_item(contains_string("-l collector-slug")))
            assert_that(
                generated_jobs,
                has_item(
                    contains_string("-c /path/to/my-app/config/creds.json")))
            assert_that(
                generated_jobs,
                has_item(
                    contains_string("-t /path/to/my-app/config/token.json")))
            assert_that(
                generated_jobs,
                has_item(
                    contains_string(
                        "-b /path/to/my-app/config/performanceplatform.json")))

            assert_that(
                generated_jobs,
                has_item(
                    '# End performanceplatform.collector jobs for some_id'))
    def test_some_cronjobs_are_added_between_containing_comments(self):
        with temp_file("schedule,query.json,creds.json,token.json,performanceplatform.json") as jobs_path:
            generated_jobs = crontab.generate_crontab(
                [],
                jobs_path,
                "/path/to/my-app",
                'some_id')
            assert_that(generated_jobs,
                        has_item('# Begin performanceplatform.collector jobs for some_id'))

            assert_that(generated_jobs,
                        has_item(contains_string("schedule")))
            assert_that(generated_jobs,
                        has_item(
                            contains_string("-q /path/to/my-app/config/query.json")))
            assert_that(generated_jobs,
                        has_item(
                            contains_string("-c /path/to/my-app/config/creds.json")))
            assert_that(generated_jobs,
                        has_item(
                            contains_string("-t /path/to/my-app/config/token.json")))
            assert_that(generated_jobs,
                        has_item(
                            contains_string("-b /path/to/my-app/config/performanceplatform.json")))

            assert_that(generated_jobs,
                        has_item('# End performanceplatform.collector jobs for some_id'))
예제 #3
0
 def test_other_cronjobs_are_preserved(self):
     with temp_file("") as jobs_path:
         generated_jobs = crontab.generate_crontab(['other cronjob'],
                                                   jobs_path,
                                                   "/path/to/app",
                                                   "some_id")
         assert_that(generated_jobs, has_item("other cronjob"))
 def test_invalid_jobs_file_causes_failure(self):
     with temp_file("afeg    ;efhv   2[\-r u1\-ry1r") as jobs_path:
         assert_raises(crontab.ParseError,
                       crontab.generate_crontab,
                       [],
                       jobs_path,
                       "/path/to/app",
                       "some_id")
 def test_other_cronjobs_are_preserved(self):
     with temp_file("") as jobs_path:
         generated_jobs = crontab.generate_crontab(
             ['other cronjob'],
             jobs_path,
             "/path/to/app",
             "some_id")
         assert_that(generated_jobs, has_item("other cronjob"))
 def test_config_file_must_be_json(self):
     with capture_stderr() as stderr:
         with temp_file("not json") as config_path:
             with json_file({}) as query_path:
                 args = ["-c", config_path, "-q", query_path]
                 assert_raises(
                     SystemExit, parse_args, args=args)
                 ok_("invalid _load_json_file value" in stderr.getvalue())
예제 #7
0
 def test_added_jobs_run_the_crontab_module(self):
     with temp_file(
             "schedule,collector-slug,creds.json,token.json,performanceplatform.json"
     ) as jobs_path:
         generated_jobs = crontab.generate_crontab([], jobs_path,
                                                   "/path/to/my-app",
                                                   "some_id")
         assert_that(generated_jobs,
                     has_item(contains_string("pp-collector")))
    def test_with_jobs(self):
        with temp_file('one,two,three,four,five') as path_to_jobs:
            output = self.run_crontab_script(
                'current crontab', '/path/to/my-app', path_to_jobs, 'some_id')

            cronjobs = output.split("\n")

            assert_that(cronjobs,
                        has_item(contains_string('pp-collector')))
 def test_added_jobs_run_the_crontab_module(self):
     with temp_file("schedule,query.json,creds.json,token.json,performanceplatform.json") as jobs_path:
         generated_jobs = crontab.generate_crontab(
             [],
             jobs_path,
             "/path/to/my-app",
             "some_id")
         assert_that(generated_jobs,
                     has_item(
                         contains_string("pp-collector")))
예제 #10
0
 def test_existing_pp_cronjobs_are_purged(self):
     with temp_file(
             "schedule,collector-slug,creds.json,token.json,performanceplatform.json"
     ) as jobs_path:
         generated_jobs = crontab.generate_crontab([
             '# Begin performanceplatform.collector jobs for some_id',
             'other job',
             '# End performanceplatform.collector jobs for some_id'
         ], jobs_path, "/path/to/my-app", 'some_id')
         assert_that(generated_jobs,
                     is_not(has_item(contains_string("other job"))))
예제 #11
0
    def test_can_handle_whitespace_and_comments(self):
        temp_contents = (
            "# some comment\n"
            "          \n"
            "schedule,collector-slug,creds,token,performanceplatform\n")

        with temp_file(temp_contents) as something:
            generated_jobs = crontab.generate_crontab([], something,
                                                      "/path/to/my-app",
                                                      "unique-id-of-my-app")
            job_contains = "pp-collector -l collector-slug"
            assert_that(generated_jobs,
                        has_item(contains_string(job_contains)))
 def test_existing_pp_cronjobs_are_purged(self):
     with temp_file("schedule,query.json,creds.json,token.json,performanceplatform.json") as jobs_path:
         generated_jobs = crontab.generate_crontab(
             [
                 '# Begin performanceplatform.collector jobs for some_id',
                 'other job',
                 '# End performanceplatform.collector jobs for some_id'
             ],
             jobs_path,
             "/path/to/my-app",
             'some_id')
         assert_that(generated_jobs,
                     is_not(has_item(contains_string("other job"))))
예제 #13
0
 def test_can_use_id_for_generating_crontab_entries(self):
     with temp_file("something, something, something, something, dark side"
                    ) as something:
         generated_jobs = crontab.generate_crontab([], something,
                                                   "/path/to/my-app",
                                                   "unique-id-of-my-app")
         assert_that(
             generated_jobs,
             has_item('# Begin performanceplatform.collector jobs '
                      'for unique-id-of-my-app'))
         assert_that(
             generated_jobs,
             has_item('# End performanceplatform.collector jobs '
                      'for unique-id-of-my-app'))
 def test_can_use_id_for_generating_crontab_entries(self):
     with temp_file("something, something, something, something, dark side") as something:
         generated_jobs = crontab.generate_crontab(
             [],
             something,
             "/path/to/my-app",
             "unique-id-of-my-app"
         )
         assert_that(generated_jobs,
                     has_item('# Begin performanceplatform.collector jobs '
                              'for unique-id-of-my-app'))
         assert_that(generated_jobs,
                     has_item('# End performanceplatform.collector jobs '
                              'for unique-id-of-my-app'))
    def test_can_handle_whitespace_and_comments(self):
        temp_contents = ("# some comment\n"
                         "          \n"
                         "schedule,query,creds,token,performanceplatforn\n")

        with temp_file(temp_contents) as something:
            generated_jobs = crontab.generate_crontab(
                [],
                something,
                "/path/to/my-app",
                "unique-id-of-my-app"
            )
            job_contains = "pp-collector -q /path/to/my-app/config/query"
            assert_that(generated_jobs,
                        has_item(
                            contains_string(job_contains)))
    def test_jobs_based_on_hostname_with_3(self, hostname):
        hostname.return_value = 'development-3'

        temp_contents = ("schedule,query,creds,token,performanceplatforn\n"
                         "schedule2,query2,creds2,token2,performanceplatforn\n"
                         "schedule3,query2,creds3,token3,performanceplatforn\n"
                         )

        with temp_file(temp_contents) as something:
            generated_jobs = crontab.generate_crontab(
                [],
                something,
                "/path/to/my-app",
                "unique-id-of-my-app"
            )

            assert_that(generated_jobs, has_length(3))
예제 #17
0
    def test_jobs_based_on_hostname_with_1(self, hostname):
        hostname.return_value = 'development-1'

        temp_contents = (
            "schedule,collector-slug,creds,token,performanceplatform\n"
            "schedule2,collector-slug2,creds2,token2,performanceplatform\n"
            "schedule3,collector-slug2,creds3,token3,performanceplatform\n")

        with temp_file(temp_contents) as something:
            generated_jobs = crontab.generate_crontab([], something,
                                                      "/path/to/my-app",
                                                      "unique-id-of-my-app")

            assert_that(removeCommentsFromCrontab(generated_jobs),
                        has_length(1))
            assert_that(
                removeCommentsFromCrontab(generated_jobs)[0],
                contains_string("schedule2 "))
 def run_crontab_script(self, current_crontab, path_to_app, path_to_jobs,
                        unique_id):
     with temp_file(current_crontab) as stdin_path:
         args = [
             sys.executable,
             '-m', 'performanceplatform.collector.crontab',
             path_to_app, path_to_jobs, unique_id
         ]
         # Bleh Python 2.6 :(
         proc = subprocess.Popen(args,
                                 stdin=open(stdin_path),
                                 stderr=subprocess.STDOUT,
                                 stdout=subprocess.PIPE)
         output = proc.communicate()
         if proc.returncode != 0:
             raise ProcessFailureError(
                 proc.returncode, ' '.join(args), output=output[0])
         return output[0]
예제 #19
0
 def run_crontab_script(self, current_crontab, path_to_app, path_to_jobs,
                        unique_id):
     with temp_file(current_crontab) as stdin_path:
         args = [
             sys.executable, '-m', 'performanceplatform.collector.crontab',
             path_to_app, path_to_jobs, unique_id
         ]
         # Bleh Python 2.6 :(
         proc = subprocess.Popen(args,
                                 stdin=open(stdin_path),
                                 stderr=subprocess.STDOUT,
                                 stdout=subprocess.PIPE)
         output = proc.communicate()
         if proc.returncode != 0:
             raise ProcessFailureError(proc.returncode,
                                       ' '.join(args),
                                       output=output[0])
         return output[0]
    def test_jobs_based_on_hostname_with_1(self, hostname):
        hostname.return_value = 'development-1'

        temp_contents = ("schedule,collector-slug,creds,token,performanceplatform\n"
                         "schedule2,collector-slug2,creds2,token2,performanceplatform\n"
                         "schedule3,collector-slug2,creds3,token3,performanceplatform\n"
                         )

        with temp_file(temp_contents) as something:
            generated_jobs = crontab.generate_crontab(
                [],
                something,
                "/path/to/my-app",
                "unique-id-of-my-app"
            )

            assert_that(
                removeCommentsFromCrontab(generated_jobs), has_length(1))
            assert_that(removeCommentsFromCrontab(
                generated_jobs)[0], contains_string("schedule2 "))
예제 #21
0
 def test_happy_path(self):
     with temp_file('') as path_to_jobs:
         output = self.run_crontab_script('current crontab', '/path/to/app',
                                          path_to_jobs, 'some_id')
         assert_that(output.strip(), is_('current crontab'))
예제 #22
0
 def test_invalid_jobs_file_causes_failure(self):
     with temp_file("afeg    ;efhv   2[\-r u1\-ry1r") as jobs_path:
         assert_raises(crontab.ParseError, crontab.generate_crontab, [],
                       jobs_path, "/path/to/app", "some_id")
 def test_happy_path(self):
     with temp_file('') as path_to_jobs:
         output = self.run_crontab_script(
             'current crontab', '/path/to/app', path_to_jobs, 'some_id')
         assert_that(output.strip(),
                     is_('current crontab'))
예제 #24
0
 def test_config_file_must_be_json(self):
     with capture_stderr() as stderr:
         with temp_file("not json") as config_path:
             args = ["-c", config_path]
             assert_raises(SystemExit, parse_args, args=args)
             ok_("invalid _load_json_file value" in stderr.getvalue())