def test_put_v3_config_noauthnopriv_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' mock_alert_source_update.return_value = fakes. \ fake_v3_alert_source_noauth_nopriv() mock_alert_source_get.return_value = fakes. \ fake_v3_alert_source_noauth_nopriv() expected_alert_source = {'storage_id': 'abcd-1234-5678', 'host': '127.0.0.1', 'version': 'snmpv3', 'engine_id': '800000d30300000e112245', 'security_level': 'noAuthnoPriv', 'username': '******', 'auth_protocol': None, 'privacy_protocol': None, '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' } alert_controller_inst = self._get_alert_controller() body = fakes.fake_v3_alert_source_config() body['security_level'] = 'noAuthnoPriv' output_alert_source = alert_controller_inst.put(req, fake_storage_id, body=body) self.assertDictEqual(expected_alert_source, output_alert_source)
def test_put_v3_authpriv_config_create_success(self, mock_alert_source_get, mock_alert_source_update): req = fakes.HTTPRequest.blank('/storages/fake_id/alert-source') fake_storage_id = 'abcd-1234-5678' 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' } 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)
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)
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)
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)