Esempio n. 1
0
 def test_get_team(self):
     with mock.patch(
         'paasta_tools.monitoring_tools.__get_monitoring_config_value',
     ) as get_monitoring_config_value_patch:
         monitoring_tools.get_team(self.overrides, self.service, self.soa_dir)
         get_monitoring_config_value_patch.assert_called_once_with('team', self.overrides, self.service,
                                                                   self.soa_dir)
Esempio n. 2
0
 def test_get_team(self):
     with mock.patch(
         'paasta_tools.monitoring_tools.__get_monitoring_config_value',
     ) as get_monitoring_config_value_patch:
         monitoring_tools.get_team(self.overrides, self.service, self.soa_dir)
         get_monitoring_config_value_patch.assert_called_once_with('team', self.overrides, self.service,
                                                                   self.soa_dir)
Esempio n. 3
0
 def test_get_team(self):
     with mock.patch(
         "paasta_tools.monitoring_tools.__get_monitoring_config_value", autospec=True
     ) as get_monitoring_config_value_patch:
         monitoring_tools.get_team(self.overrides, self.service, self.soa_dir)
         get_monitoring_config_value_patch.assert_called_once_with(
             "team", self.overrides, self.service, self.soa_dir
         )
Esempio n. 4
0
 def test_get_monitoring_config_value_with_defaults(self):
     expected = None
     with mock.patch(
         "service_configuration_lib.read_service_configuration",
         autospec=True,
         return_value=self.empty_job_config,
     ) as service_configuration_lib_patch, mock.patch(
         "paasta_tools.monitoring_tools.read_monitoring_config",
         autospec=True,
         return_value=self.empty_monitor_config,
     ) as read_monitoring_patch, mock.patch(
         "paasta_tools.monitoring_tools.load_system_paasta_config", autospec=True
     ) as load_system_paasta_config_patch:
         load_system_paasta_config_patch.return_value.get_cluster = mock.Mock(
             return_value="fake_cluster"
         )
         actual = monitoring_tools.get_team(
             self.overrides, self.service, self.soa_dir
         )
         assert expected == actual
         service_configuration_lib_patch.assert_called_once_with(
             self.service, soa_dir=self.soa_dir
         )
         read_monitoring_patch.assert_called_once_with(
             self.service, soa_dir=self.soa_dir
         )
Esempio n. 5
0
def get_service_info(service):
    service_configuration = read_service_configuration(service)
    description = service_configuration.get('description', NO_DESCRIPTION_MESSAGE)
    external_link = service_configuration.get('external_link', NO_EXTERNAL_LINK_MESSAGE)
    pipeline_url = get_pipeline_url(service)
    smartstack_endpoints = get_smartstack_endpoints(service)
    git_url = get_git_url(service)

    output = []
    output.append('Service Name: %s' % service)
    output.append('Description: %s' % description)
    output.append('External Link: %s' % PaastaColors.cyan(external_link))
    output.append('Monitored By: team %s' % get_team(service=service, overrides={}))
    output.append('Runbook: %s' % PaastaColors.cyan(get_runbook(service=service, overrides={})))
    output.append('Git Repo: %s' % git_url)
    output.append('Jenkins Pipeline: %s' % pipeline_url)
    output.append('Deployed to the following clusters:')
    output.extend(get_deployments_strings(service))
    if smartstack_endpoints:
        output.append('Smartstack endpoint(s):')
        for endpoint in smartstack_endpoints:
            output.append(' - %s' % endpoint)
    output.append('Dashboard(s):')
    output.extend(get_dashboard_urls(service))

    return '\n'.join(output)
Esempio n. 6
0
def get_service_info(service, soa_dir):
    service_configuration = read_service_configuration(service, soa_dir)
    description = service_configuration.get("description",
                                            NO_DESCRIPTION_MESSAGE)
    external_link = service_configuration.get("external_link",
                                              NO_EXTERNAL_LINK_MESSAGE)
    smartstack_endpoints = get_smartstack_endpoints(service, soa_dir)
    git_url = get_git_url(service, soa_dir)

    output = []
    output.append("Service Name: %s" % service)
    output.append("Description: %s" % description)
    output.append("External Link: %s" % PaastaColors.cyan(external_link))
    output.append("Monitored By: team %s" %
                  get_team(service=service, overrides={}, soa_dir=soa_dir))
    output.append("Runbook: %s" % PaastaColors.cyan(
        get_runbook(service=service, overrides={}, soa_dir=soa_dir)))
    output.append("Git Repo: %s" % git_url)
    output.append("Deployed to the following clusters:")
    output.extend(get_deployments_strings(service, soa_dir))
    if smartstack_endpoints:
        output.append("Smartstack endpoint(s):")
        for endpoint in smartstack_endpoints:
            output.append(" - %s" % endpoint)
    output.append("Dashboard(s):")
    output.extend(get_dashboard_urls(service))

    return "\n".join(output)
Esempio n. 7
0
def get_service_info(service, soa_dir):
    service_configuration = read_service_configuration(service, soa_dir)
    description = service_configuration.get('description',
                                            NO_DESCRIPTION_MESSAGE)
    external_link = service_configuration.get('external_link',
                                              NO_EXTERNAL_LINK_MESSAGE)
    smartstack_endpoints = get_smartstack_endpoints(service, soa_dir)
    git_url = get_git_url(service, soa_dir)

    output = []
    output.append('Service Name: %s' % service)
    output.append('Description: %s' % description)
    output.append('External Link: %s' % PaastaColors.cyan(external_link))
    output.append('Monitored By: team %s' %
                  get_team(service=service, overrides={}))
    output.append(
        'Runbook: %s' %
        PaastaColors.cyan(get_runbook(service=service, overrides={})))
    output.append('Git Repo: %s' % git_url)
    output.append('Deployed to the following clusters:')
    output.extend(get_deployments_strings(service, soa_dir))
    if smartstack_endpoints:
        output.append('Smartstack endpoint(s):')
        for endpoint in smartstack_endpoints:
            output.append(' - %s' % endpoint)
    output.append('Dashboard(s):')
    output.extend(get_dashboard_urls(service))

    return '\n'.join(output)
Esempio n. 8
0
 def test_get_monitoring_config_value_with_defaults(self):
     expected = None
     with contextlib.nested(
             mock.patch(
                 'service_configuration_lib.read_service_configuration',
                 autospec=True,
                 return_value=self.empty_job_config),
             mock.patch(
                 'paasta_tools.monitoring_tools.read_monitoring_config',
                 autospec=True,
                 return_value=self.empty_monitor_config),
             mock.patch(
                 'paasta_tools.monitoring_tools.load_system_paasta_config',
                 autospec=True),
     ) as (
             service_configuration_lib_patch,
             read_monitoring_patch,
             load_system_paasta_config_patch,
     ):
         load_system_paasta_config_patch.return_value.get_cluster = mock.Mock(
             return_value='fake_cluster')
         actual = monitoring_tools.get_team(self.overrides, self.service,
                                            self.soa_dir)
         assert expected == actual
         service_configuration_lib_patch.assert_called_once_with(
             self.service, soa_dir=self.soa_dir)
         read_monitoring_patch.assert_called_once_with(self.service,
                                                       soa_dir=self.soa_dir)
Esempio n. 9
0
def get_filters(args):
    """Figures out which filters to apply from an args object, and returns them

    :param args: args object
    :returns: list of functions that take an instance config and returns if the instance conf matches the filter
    """
    filters = []

    if args.service:
        filters.append(lambda conf: conf.get_service() in args.service.split(','))

    if args.clusters:
        filters.append(lambda conf: conf.get_cluster() in args.clusters.split(','))

    if args.instances:
        filters.append(lambda conf: conf.get_instance() in args.instances.split(','))

    if args.deploy_group:
        filters.append(lambda conf: conf.get_deploy_group() in args.deploy_group.split(','))

    if args.owner:
        owners = args.owner.split(',')

        filters.append(
            # If the instance owner is None, check the service owner, else check the instance owner
            lambda conf: get_team(
                overrides={},
                service=conf.get_service(),
                soa_dir=args.soa_dir,
            ) in owners if conf.get_team() is None else conf.get_team() in owners,
        )

    return filters
Esempio n. 10
0
def get_filters(args,) -> Sequence[Callable[[InstanceConfig], bool]]:
    """Figures out which filters to apply from an args object, and returns them

    :param args: args object
    :returns: list of functions that take an instance config and returns if the instance conf matches the filter
    """
    filters = []

    if args.service:
        filters.append(lambda conf: conf.get_service() in args.service.split(","))

    if args.clusters:
        filters.append(lambda conf: conf.get_cluster() in args.clusters.split(","))

    if args.instances:
        filters.append(lambda conf: conf.get_instance() in args.instances.split(","))

    if args.deploy_group:
        filters.append(
            lambda conf: conf.get_deploy_group() in args.deploy_group.split(",")
        )

    if args.registration:
        normalized_regs = normalize_registrations(
            service=args.service, registrations=args.registration.split(",")
        )
        filters.append(
            lambda conf: any(
                reg in normalized_regs
                for reg in (
                    conf.get_registrations()
                    if hasattr(conf, "get_registrations")
                    else []
                )
            )
        )

    if args.owner:
        owners = args.owner.split(",")

        filters.append(
            # If the instance owner is None, check the service owner, else check the instance owner
            lambda conf: get_team(
                overrides={}, service=conf.get_service(), soa_dir=args.soa_dir
            )
            in owners
            if conf.get_team() is None
            else conf.get_team() in owners
        )

    return filters
Esempio n. 11
0
def sensu_check(service, service_path):
    """Check whether monitoring.yaml exists in service directory,
    and that the team name is declared.

    :param service: name of service currently being examined
    :param service_path: path to loction of monitoring.yaml file"""
    if is_file_in_dir('monitoring.yaml', service_path):
        print PaastaCheckMessages.SENSU_MONITORING_FOUND
        team = get_team(service=service, overrides={})
        if team is None:
            print PaastaCheckMessages.SENSU_TEAM_MISSING
        else:
            print PaastaCheckMessages.sensu_team_found(team)
    else:
        print PaastaCheckMessages.SENSU_MONITORING_MISSING
Esempio n. 12
0
File: check.py Progetto: seco/paasta
def sensu_check(service, service_path, soa_dir):
    """Check whether monitoring.yaml exists in service directory,
    and that the team name is declared.

    :param service: name of service currently being examined
    :param service_path: path to loction of monitoring.yaml file"""
    if is_file_in_dir('monitoring.yaml', service_path):
        print PaastaCheckMessages.SENSU_MONITORING_FOUND
        team = get_team(service=service, overrides={}, soa_dir=soa_dir)
        if team is None:
            print PaastaCheckMessages.SENSU_TEAM_MISSING
        else:
            print PaastaCheckMessages.sensu_team_found(team)
    else:
        print PaastaCheckMessages.SENSU_MONITORING_MISSING
Esempio n. 13
0
 def test_get_monitoring_config_value_with_service_config(self):
     expected = 'general_test_team'
     with mock.patch(
         'service_configuration_lib.read_service_configuration', autospec=True,
         return_value=self.fake_general_service_config,
     ) as service_configuration_lib_patch, mock.patch(
         'paasta_tools.monitoring_tools.read_monitoring_config',
         autospec=True, return_value=self.empty_monitor_config,
     ) as read_monitoring_patch, mock.patch(
         'paasta_tools.monitoring_tools.load_system_paasta_config', autospec=True,
     ) as load_system_paasta_config_patch:
         load_system_paasta_config_patch.return_value.get_cluster = mock.Mock(return_value='fake_cluster')
         actual = monitoring_tools.get_team(self.overrides, self.service, self.soa_dir)
         assert expected == actual
         service_configuration_lib_patch.assert_called_once_with(self.service, soa_dir=self.soa_dir)
         read_monitoring_patch.assert_called_once_with(self.service, soa_dir=self.soa_dir)
Esempio n. 14
0
 def test_get_monitoring_config_value_with_defaults(self):
     expected = None
     with contextlib.nested(
         mock.patch('service_configuration_lib.read_service_configuration', autospec=True,
                    return_value=self.empty_job_config),
         mock.patch('paasta_tools.monitoring_tools.read_monitoring_config',
                    autospec=True, return_value=self.empty_monitor_config),
         mock.patch('paasta_tools.monitoring_tools.load_system_paasta_config', autospec=True),
     ) as (
         service_configuration_lib_patch,
         read_monitoring_patch,
         load_system_paasta_config_patch,
     ):
         load_system_paasta_config_patch.return_value.get_cluster = mock.Mock(return_value='fake_cluster')
         actual = monitoring_tools.get_team(self.overrides, self.service, self.soa_dir)
         assert expected == actual
         service_configuration_lib_patch.assert_called_once_with(self.service, soa_dir=self.soa_dir)
         read_monitoring_patch.assert_called_once_with(self.service, soa_dir=self.soa_dir)
Esempio n. 15
0
def generate_pipeline(service):
    email_address = get_team_email_address(service=service)
    repo = get_git_repo_for_fab_repo(service)
    if email_address is None:
        owner = get_team(overrides={}, service=service)
    else:
        # fab_repo tacks on the domain, so we only want the first
        # part of the email.
        owner = re.sub('@.*', '', email_address)
    cmds = [
        'fab_repo setup_jenkins:services/%s,'
        'profile=paasta,job_disabled=False,owner=%s,repo=%s' % (service, owner, repo),
        'fab_repo setup_jenkins:services/%s,'
        'profile=paasta_boilerplate,owner=%s,repo=%s' % (service, owner, repo),
    ]
    for cmd in cmds:
        print "INFO: Executing %s" % cmd
        returncode, output = _run(cmd, timeout=90)
        if returncode != 0:
            print "ERROR: Failed to generate Jenkins pipeline"
            print output
            sys.exit(returncode)
Esempio n. 16
0
def generate_pipeline(service):
    email_address = get_team_email_address(service=service)
    repo = get_git_repo_for_fab_repo(service)
    if email_address is None:
        owner = get_team(overrides={}, service=service)
    else:
        # fab_repo tacks on the domain, so we only want the first
        # part of the email.
        owner = re.sub('@.*', '', email_address)
    cmds = [
        'fab_repo setup_jenkins:services/%s,'
        'profile=paasta,job_disabled=False,owner=%s,repo=%s' %
        (service, owner, repo),
        'fab_repo setup_jenkins:services/%s,'
        'profile=paasta_boilerplate,owner=%s,repo=%s' % (service, owner, repo),
    ]
    for cmd in cmds:
        print "INFO: Executing %s" % cmd
        returncode, output = _run(cmd, timeout=90)
        if returncode != 0:
            print "ERROR: Failed to generate Jenkins pipeline"
            print output
            sys.exit(returncode)
Esempio n. 17
0
 def get_owner(self):
     overrides = self.get_monitoring()
     return monitoring_tools.get_team(overrides=overrides,
                                      service=self.get_service())
Esempio n. 18
0
 def get_owner(self):
     overrides = self.get_monitoring()
     return monitoring_tools.get_team(overrides=overrides, service=self.get_service())