Пример #1
0
    def test_put_v3_authpriv_config_create_success(self, mock_alert_source_get,
                                                   mock_alert_source_update):
        req = fakes.HTTPRequest.blank('/storages/fake_id/snmp-config')
        fake_storage_id = 'abcd-1234-5678'
        expected_alert_source = {'storage_id': 'abcd-1234-5678',
                                 'host': '127.0.0.1',
                                 'version': 'snmpv3',
                                 'engine_id': '800000d30300000e112245',
                                 'security_level': None,
                                 'username': '******',
                                 'auth_protocol': 'HMACMD5',
                                 'privacy_protocol': 'DES',
                                 'port': 161,
                                 'context_name': "",
                                 'retry_num': 1,
                                 'expiration': 1,
                                 "created_at": '2020-06-15T09:50:31.698956',
                                 "updated_at": '2020-06-15T09:50:31.698956'
                                 }
        mock_alert_source_update.return_value = fakes.fake_v3_alert_source()
        mock_alert_source_get.return_value = fakes.fake_v3_alert_source()

        alert_controller_inst = self._get_alert_controller()
        body = fakes.fake_v3_alert_source_config()

        output_alert_source = alert_controller_inst.put(req, fake_storage_id,
                                                        body=body)
        self.assertDictEqual(expected_alert_source, output_alert_source)
Пример #2
0
    def test_delete_v3_config_success(self, mock_alert_source_get,
                                      mock_alert_source_delete):
        req = fakes.HTTPRequest.blank('/storages/fake_id/snmp-config')
        fake_storage_id = 'abcd-1234-5678'
        mock_alert_source_delete.return_value = {}
        mock_alert_source_get.return_value = fakes.fake_v3_alert_source()

        alert_controller_inst = self._get_alert_controller()
        alert_controller_inst.delete(req, fake_storage_id)
        self.assertTrue(mock_alert_source_delete.called)
Пример #3
0
    def test_put_v3_snmp_validation_failure(self, mock_alert_source_get,
                                            mock_alert_source_update):
        req = fakes.HTTPRequest.blank('/storages/fake_id/alert-source')
        fake_storage_id = 'abcd-1234-5678'
        mock_alert_source_update.return_value = fakes.fake_v3_alert_source()
        mock_alert_source_get.return_value = fakes.fake_v3_alert_source()

        alert_controller_inst = self._get_alert_controller()
        body = fakes.fake_v3_alert_source_config()

        self.assertRaisesRegex(exception.InvalidResults, "The results are "
                               "invalid. "
                               "configuration "
                               "validation failed "
                               "with alert source "
                               "for reason: "
                               "Connection failed.",
                               alert_controller_inst.put,
                               req,
                               fake_storage_id,
                               body=body)
Пример #4
0
    def test_put_without_engine_id(self, mock_alert_source_get,
                                   mock_alert_source_update):
        req = fakes.HTTPRequest.blank('/storages/fake_id/snmp-config')
        fake_storage_id = 'abcd-1234-5678'
        mock_alert_source_update.return_value = {}
        mock_alert_source_get.return_value = fakes.fake_v3_alert_source()

        alert_controller_inst = self._get_alert_controller()
        body = fakes.fake_v3_alert_source_config()
        body['engine_id'] = ''

        self.assertRaisesRegex(exception.InvalidInput, "Invalid input "
                                                       "received. Invalid "
                                                       "input for "
                                                       "field/attribute "
                                                       "engine_id..",
                               alert_controller_inst.put, req, fake_storage_id,
                               body=body)
Пример #5
0
    def test_put_v3_authnopriv_no_auth_key(self,
                                           mock_alert_source_get,
                                           mock_alert_source_update):
        req = fakes.HTTPRequest.blank('/storages/fake_id/snmp-config')
        fake_storage_id = 'abcd-1234-5678'
        mock_alert_source_update.return_value = {}
        mock_alert_source_get.return_value = fakes.fake_v3_alert_source()

        alert_controller_inst = self._get_alert_controller()
        body = fakes.fake_v3_alert_source_config()
        body['security_level'] = 'authNoPriv'
        body['auth_key'] = ''

        self.assertRaisesRegex(exception.InvalidInput, "Invalid input for "
                                                       "field/attribute "
                                                       "auth_key",
                               alert_controller_inst.put, req, fake_storage_id,
                               body=body)
Пример #6
0
 def test_show_v3_config(self, mock_alert_source_get):
     req = fakes.HTTPRequest.blank('/storages/fake_id/alert-source')
     fake_storage_id = 'abcd-1234-5678'
     mock_alert_source_get.return_value = fakes.fake_v3_alert_source()
     expected_alert_source = {
         'storage_id': 'abcd-1234-5678',
         'host': '127.0.0.1',
         'community_string': None,
         'version': 'snmpv3',
         'engine_id': '800000d30300000e112245',
         'security_level': None,
         'username': '******',
         'auth_protocol': 'md5',
         'privacy_protocol': 'des',
         "created_at": '2020-06-15T09:50:31.698956',
         "updated_at": '2020-06-15T09:50:31.698956'
     }
     alert_controller_inst = self._get_alert_controller()
     output_alert_source = alert_controller_inst.show(req, fake_storage_id)
     self.assertDictEqual(expected_alert_source, output_alert_source)