def test_should_update(self, mc):
        mc.return_value = c = FakeV2Client()

        ad_id = '0495340b-58fd-4e1c-932b-5e6f9cc96490'
        ad_name = 'alarm_name'
        ad_desc = 'test_alarm_definition'
        ad_expr = 'avg(Test_Metric_1)>=10'
        ad_action_id = '16012650-0b62-4692-9103-2d04fe81cc93'
        ad_action_enabled = 'True'
        ad_match_by = 'hostname'
        ad_severity = 'CRITICAL'

        raw_args = [
            ad_id, ad_name, ad_desc, ad_expr, ad_action_id, ad_action_id,
            ad_action_id, ad_action_enabled, ad_match_by, ad_severity
        ]
        name, cmd_clazz = migr.create_command_class(
            'do_alarm_definition_update', shell)
        cmd = cmd_clazz(mock.Mock(), mock.Mock())

        parser = cmd.get_parser(name)
        parsed_args = parser.parse_args(raw_args)
        cmd.run(parsed_args)

        c.alarm_definitions.update.assert_called_once_with(
            actions_enabled=True,
            alarm_actions=[ad_action_id],
            alarm_id=ad_id,
            description=ad_desc,
            expression=ad_expr,
            match_by=[ad_match_by],
            name=ad_name,
            ok_actions=[ad_action_id],
            severity=ad_severity,
            undetermined_actions=[ad_action_id])
    def test_alarm_definitions_list(self, mc):
        mc.return_value = c = FakeV2Client()

        c.alarm_definitions.list.return_value = [{
            "name": "ntp_sync_check",
            "id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
            "expression": "(max(ntp.offset{}, deterministic)>=1)",
            "match_by": ['hostname'],
            "description": "NTP time sync check",
            "actions_enabled": True,
            "deterministic": True,
            "alarm_actions": ['aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'],
            "ok_actions": [],
            "undetermined_actions": [],
            "severity": "HIGH",
        }]

        name, cmd_class = migr.create_command_class(
            'do_alarm_definition_list',
            shell
        )
        cmd = cmd_class(mock.Mock(), mock.Mock())

        parser = cmd.get_parser(name)
        raw_args = []
        parsed_args = parser.parse_args(raw_args)
        cmd.run(parsed_args)

        c.alarm_definitions.list.assert_called_once()
Exemplo n.º 3
0
    def test_bad_metrics(self):
        raw_args_list = [['metric1'], ['123'], ['']]
        name, cmd_clazz = migr.create_command_class('do_metric_create', shell)

        for raw_args in raw_args_list:
            cmd = cmd_clazz(mock.Mock(), mock.Mock())
            parser = cmd.get_parser(name)
            self.assertRaises(SystemExit, parser.parse_args, raw_args)
Exemplo n.º 4
0
    def _find_actions(self, actions_module):
        for attr in (a for a in dir(actions_module) if a.startswith('do_')):
            name, clazz = migration.create_command_class(attr, actions_module)

            if 'help' == name:
                # help requires no auth
                clazz.auth_required = False

            self.command_manager.add_command(name, clazz)
Exemplo n.º 5
0
    def _find_actions(self, actions_module):
        for attr in (a for a in dir(actions_module) if a.startswith('do_')):
            name, clazz = migration.create_command_class(attr, actions_module)

            if 'help' == name:
                # help requires no auth
                clazz.auth_required = False

            self.command_manager.add_command(name, clazz)
    def test_bad_metrics(self):
        raw_args_list = [
            ['metric1'],
            ['123'],
            ['']
        ]
        name, cmd_clazz = migr.create_command_class('do_metric_create',
                                                    shell)

        for raw_args in raw_args_list:
            cmd = cmd_clazz(mock.Mock(), mock.Mock())
            parser = cmd.get_parser(name)
            self.assertRaises(SystemExit, parser.parse_args, raw_args)
Exemplo n.º 7
0
    def test_metric_create(self, mc):
        mc.return_value = c = FakeV2Client()

        raw_args = 'metric1 123 --time 1395691090'.split(' ')
        name, cmd_clazz = migr.create_command_class('do_metric_create', shell)
        cmd = cmd_clazz(mock.Mock(), mock.Mock())

        parser = cmd.get_parser(name)
        parsed_args = parser.parse_args(raw_args)
        cmd.run(parsed_args)

        data = {'timestamp': 1395691090, 'name': 'metric1', 'value': 123.0}

        c.metrics.create.assert_called_once_with(**data)
Exemplo n.º 8
0
    def test_bad_notifications_patch(self, mc):
        mc.return_value = c = FakeV2Client()

        id_str = '0495340b-58fd-4e1c-932b-5e6f9cc96490'
        raw_args = ('{0} --type EMAIL --address [email protected] '
                    '--period 60').format(id_str).split(' ')
        name, cmd_clazz = migr.create_command_class('do_notification_patch',
                                                    shell)
        cmd = cmd_clazz(mock.Mock(), mock.Mock())

        parser = cmd.get_parser(name)
        parsed_args = parser.parse_args(raw_args)
        cmd.run(parsed_args)

        c.notifications.patch.assert_not_called()
    def _patch_test(mc, args, called=True, **kwargs):
        mc.return_value = c = FakeV2Client()

        name, cmd_clazz = migr.create_command_class(
            'do_alarm_definition_patch', shell)

        cmd = cmd_clazz(mock.Mock(), mock.Mock())

        parser = cmd.get_parser(name)
        parsed_args = parser.parse_args(args)
        cmd.run(parsed_args)

        if called:
            c.alarm_definitions.patch.assert_called_once_with(**kwargs)
        else:
            c.alarm_definitions.patch.assert_not_called()
Exemplo n.º 10
0
    def _patch_test(mc, args, data):
        mc.return_value = c = FakeV2Client()

        id_str = '0495340b-58fd-4e1c-932b-5e6f9cc96490'
        raw_args = '{0} {1}'.format(id_str, args).split(' ')
        name, cmd_clazz = migr.create_command_class('do_notification_patch',
                                                    shell)
        cmd = cmd_clazz(mock.Mock(), mock.Mock())

        parser = cmd.get_parser(name)
        parsed_args = parser.parse_args(raw_args)
        cmd.run(parsed_args)

        # add notification_id to data
        data['notification_id'] = id_str

        c.notifications.patch.assert_called_once_with(**data)
Exemplo n.º 11
0
    def test_notification_create_email(self, mc):
        mc.return_value = c = FakeV2Client()

        raw_args = ['email1', 'EMAIL', '*****@*****.**']
        name, cmd_clazz = migr.create_command_class('do_notification_create',
                                                    shell)
        cmd = cmd_clazz(mock.Mock(), mock.Mock())

        parser = cmd.get_parser(name)
        parsed_args = parser.parse_args(raw_args)
        cmd.run(parsed_args)

        data = {'name': 'email1',
                'type': 'EMAIL',
                'address': '*****@*****.**'}

        c.notifications.create.assert_called_once_with(**data)
Exemplo n.º 12
0
    def test_metric_create(self, mc):
        mc.return_value = c = FakeV2Client()

        raw_args = 'metric1 123 --time 1395691090'.split(' ')
        name, cmd_clazz = migr.create_command_class('do_metric_create',
                                                    shell)
        cmd = cmd_clazz(mock.Mock(), mock.Mock())

        parser = cmd.get_parser(name)
        parsed_args = parser.parse_args(raw_args)
        cmd.run(parsed_args)

        data = {'timestamp': 1395691090,
                'name': 'metric1',
                'value': 123.0}

        c.metrics.create.assert_called_once_with(**data)
Exemplo n.º 13
0
    def test_notification_create_webhook(self, mc):
        mc.return_value = c = FakeV2Client()

        raw_args = ['mypost', 'WEBHOOK', 'http://localhost:8080']
        name, cmd_clazz = migr.create_command_class('do_notification_create',
                                                    shell)
        cmd = cmd_clazz(mock.Mock(), mock.Mock())

        parser = cmd.get_parser(name)
        parsed_args = parser.parse_args(raw_args)
        cmd.run(parsed_args)

        data = {'name': 'mypost',
                'type': 'WEBHOOK',
                'address': 'http://localhost:8080'}

        c.notifications.create.assert_called_once_with(**data)
    def test_notification_types_list(self, mc):
        mc.return_value = c = FakeV2Client()
        c.notificationtypes.list.return_value = [
            {"type": "WEBHOOK"},
            {"type": "EMAIL"},
            {"type": "PAGERDUTY"}
        ]

        raw_args = []
        name, cmd_clazz = migr.create_command_class('do_notification_type_list',
                                                    shell)
        cmd = cmd_clazz(mock.Mock(), mock.Mock())

        parser = cmd.get_parser(name)
        parsed_args = parser.parse_args(raw_args)
        cmd.run(parsed_args)

        c.notificationtypes.list.assert_called_once()
    def _patch_test(mc, args, called=True, **kwargs):
        mc.return_value = c = FakeV2Client()

        name, cmd_clazz = migr.create_command_class(
            'do_alarm_definition_patch',
            shell
        )

        cmd = cmd_clazz(mock.Mock(), mock.Mock())

        parser = cmd.get_parser(name)
        parsed_args = parser.parse_args(args)
        cmd.run(parsed_args)

        if called:
            c.alarm_definitions.patch.assert_called_once_with(**kwargs)
        else:
            c.alarm_definitions.patch.assert_not_called()
Exemplo n.º 16
0
    def test_notification_types_list(self, mc):
        mc.return_value = c = FakeV2Client()
        c.notificationtypes.list.return_value = [{
            "type": "WEBHOOK"
        }, {
            "type": "EMAIL"
        }, {
            "type": "PAGERDUTY"
        }]

        raw_args = []
        name, cmd_clazz = migr.create_command_class(
            'do_notification_type_list', shell)
        cmd = cmd_clazz(mock.Mock(), mock.Mock())

        parser = cmd.get_parser(name)
        parsed_args = parser.parse_args(raw_args)
        cmd.run(parsed_args)

        c.notificationtypes.list.assert_called_once()
Exemplo n.º 17
0
    def test_metric_create_with_project_id(self, mc):
        mc.return_value = c = FakeV2Client()

        project_id = 'd48e63e76a5c4e05ba26a1185f31d4aa'
        raw_args = ('metric1 123 --time 1395691090 --project-id %s'
                    % project_id).split(' ')
        name, cmd_clazz = migr.create_command_class('do_metric_create',
                                                    shell)
        cmd = cmd_clazz(mock.Mock(), mock.Mock())

        parser = cmd.get_parser(name)
        parsed_args = parser.parse_args(raw_args)
        cmd.run(parsed_args)

        data = {'timestamp': 1395691090,
                'name': 'metric1',
                'tenant_id': project_id,
                'value': 123.0}

        c.metrics.create.assert_called_once_with(**data)
Exemplo n.º 18
0
    def test_metric_create_with_project_id(self, mc):
        mc.return_value = c = FakeV2Client()

        project_id = 'd48e63e76a5c4e05ba26a1185f31d4aa'
        raw_args = ('metric1 123 --time 1395691090 --project-id %s' %
                    project_id).split(' ')
        name, cmd_clazz = migr.create_command_class('do_metric_create', shell)
        cmd = cmd_clazz(mock.Mock(), mock.Mock())

        parser = cmd.get_parser(name)
        parsed_args = parser.parse_args(raw_args)
        cmd.run(parsed_args)

        data = {
            'timestamp': 1395691090,
            'name': 'metric1',
            'tenant_id': project_id,
            'value': 123.0
        }

        c.metrics.create.assert_called_once_with(**data)
    def test_should_update(self, mc):
        mc.return_value = c = FakeV2Client()

        ad_id = '0495340b-58fd-4e1c-932b-5e6f9cc96490'
        ad_name = 'alarm_name'
        ad_desc = 'test_alarm_definition'
        ad_expr = 'avg(Test_Metric_1)>=10'
        ad_action_id = '16012650-0b62-4692-9103-2d04fe81cc93'
        ad_action_enabled = 'True'
        ad_match_by = 'hostname'
        ad_severity = 'CRITICAL'

        raw_args = [
            ad_id, ad_name, ad_desc, ad_expr,
            ad_action_id, ad_action_id, ad_action_id, ad_action_enabled,
            ad_match_by, ad_severity
        ]
        name, cmd_clazz = migr.create_command_class(
            'do_alarm_definition_update',
            shell
        )
        cmd = cmd_clazz(mock.Mock(), mock.Mock())

        parser = cmd.get_parser(name)
        parsed_args = parser.parse_args(raw_args)
        cmd.run(parsed_args)

        c.alarm_definitions.update.assert_called_once_with(
            actions_enabled=True,
            alarm_actions=[ad_action_id],
            alarm_id=ad_id,
            description=ad_desc,
            expression=ad_expr,
            match_by=[ad_match_by],
            name=ad_name,
            ok_actions=[ad_action_id],
            severity=ad_severity,
            undetermined_actions=[ad_action_id]
        )
Exemplo n.º 20
0
    def test_good_notifications_update(self, mc):
        mc.return_value = c = FakeV2Client()

        id_str = '0495340b-58fd-4e1c-932b-5e6f9cc96491'
        raw_args = ('{0} notification_updated_name '
                    'EMAIL [email protected] 0').format(id_str).split(' ')
        name, cmd_clazz = migr.create_command_class('do_notification_update',
                                                    shell)
        cmd = cmd_clazz(mock.Mock(), mock.Mock())

        parser = cmd.get_parser(name)
        parsed_args = parser.parse_args(raw_args)

        cmd.run(parsed_args)

        data = {
            'name': 'notification_updated_name',
            'type': 'EMAIL',
            'address': '*****@*****.**',
            'period': 0,
            'notification_id': id_str
        }

        c.notifications.update.assert_called_once_with(**data)