"vrops_password",
),
}
+ valid_paas_providers = ["juju"]
+
+ def check_conflict_on_new(self, session, indata):
+ super().check_conflict_on_new(session, indata)
+ self._check_paas_account(indata)
+
+ def _is_paas_vim_type(self, indata):
+ return indata.get("vim_type") and indata["vim_type"] == "paas"
+
+ def _check_paas_account(self, indata):
+ if self._is_paas_vim_type(indata):
+ self._check_paas_provider_is_valid(indata)
+
+ def _check_paas_provider_is_valid(self, indata):
+ try:
+ paas_provider = indata["config"]["paas_provider"]
+ if paas_provider in self.valid_paas_providers:
+ return
+ except Exception:
+ pass
+ raise EngineException(
+ "Invalid paas_provider for VIM account '{}'.".format(indata["name"]),
+ HTTPStatus.UNPROCESSABLE_ENTITY,
+ )
def check_conflict_on_del(self, session, _id, db_content):
"""
)
super().check_conflict_on_del(session, _id, db_content)
+ def _send_msg(self, action, content, not_send_msg=None):
+ if self._is_paas_vim_type(content):
+ return
+ super()._send_msg(action, content, not_send_msg)
+
class WimAccountTopic(CommonVimWimSdn):
topic = "wim_accounts"
import unittest
from unittest import TestCase
-from unittest.mock import Mock, patch, call
+from unittest.mock import Mock, patch, call, ANY
from uuid import uuid4
from http import HTTPStatus
from time import time
UserTopicAuth,
CommonVimWimSdn,
VcaTopic,
+ VimAccountTopic,
)
from osm_nbi.engine import EngineException
from osm_nbi.authconn import AuthconnNotFoundException
)
+@patch("osm_nbi.admin_topics.CommonVimWimSdn.check_conflict_on_new")
+class TestVimAccountTopic(TestCase):
+ def setUp(self):
+ self.db = Mock(dbbase.DbBase())
+ self.fs = Mock(fsbase.FsBase())
+ self.msg = Mock(msgbase.MsgBase())
+ self.auth = Mock(authconn.Authconn(None, None, None))
+ self.topic = VimAccountTopic(self.db, self.fs, self.msg, self.auth)
+ self.topic.check_quota = Mock(return_value=None) # skip quota
+
+ self.fake_session = {
+ "username": test_name,
+ "project_id": (test_pid,),
+ "method": None,
+ "admin": True,
+ "force": False,
+ "public": False,
+ "allow_show_user_project_role": True,
+ }
+
+ def check_invalid_indata_raises_exception(self, indata, mock_common_vim_wim_sdn):
+ with self.assertRaises(EngineException) as error:
+ self.topic.check_conflict_on_new(self.fake_session, indata)
+ mock_common_vim_wim_sdn.assert_called_once_with(self.fake_session, indata)
+ error_msg = "Invalid paas_provider for VIM account '{}'.".format(indata["name"])
+ self.assertEqual(str(error.exception), error_msg)
+
+ def test_check_conflict_on_new_vim_type_paas(self, mock_common_vim_wim_sdn):
+ indata = {
+ "name": "juju_paas",
+ "vim_type": "paas",
+ "description": None,
+ "vim_url": "http://0.0.0.0:0",
+ "vim_user": "some_user",
+ "vim_password": "some_password",
+ "vim_tenant_name": "null",
+ "config": {"paas_provider": "juju"},
+ }
+ self.topic.check_conflict_on_new(self.fake_session, indata)
+ mock_common_vim_wim_sdn.assert_called_once_with(self.fake_session, indata)
+
+ def test_check_conflict_on_new_vim_type_paas_incorrect_provider(
+ self, mock_common_vim_wim_sdn
+ ):
+ indata = {
+ "name": "juju_paas",
+ "vim_type": "paas",
+ "description": None,
+ "vim_url": "http://0.0.0.0:0",
+ "vim_user": "some_user",
+ "vim_password": "some_password",
+ "vim_tenant_name": "null",
+ "config": {"paas_provider": "some_provider"},
+ }
+ self.check_invalid_indata_raises_exception(indata, mock_common_vim_wim_sdn)
+
+ def test_check_conflict_on_new_vim_type_paas_config_missing(
+ self, mock_common_vim_wim_sdn
+ ):
+ indata = {
+ "name": "juju_paas",
+ "vim_type": "paas",
+ "description": None,
+ "vim_url": "http://0.0.0.0:0",
+ "vim_user": "some_user",
+ "vim_password": "some_password",
+ "vim_tenant_name": "null",
+ }
+ self.check_invalid_indata_raises_exception(indata, mock_common_vim_wim_sdn)
+
+ def test_check_conflict_on_new_vim_type_paas_provider_missing(
+ self, mock_common_vim_wim_sdn
+ ):
+ indata = {
+ "name": "juju_paas",
+ "vim_type": "paas",
+ "description": None,
+ "vim_url": "http://0.0.0.0:0",
+ "vim_user": "some_user",
+ "vim_password": "some_password",
+ "vim_tenant_name": "null",
+ "config": {"some_param": None},
+ }
+ self.check_invalid_indata_raises_exception(indata, mock_common_vim_wim_sdn)
+
+ def test_kafka_message_is_not_sent_if_paas_vim(self, mock_common_vim_wim_sdn):
+ indata = {
+ "name": "juju_paas",
+ "vim_type": "paas",
+ "description": None,
+ "vim_url": "http://0.0.0.0:0",
+ "vim_user": "some_user",
+ "vim_password": "some_password",
+ "vim_tenant_name": "null",
+ "config": {"paas_provider": "juju"},
+ }
+ rollback = []
+
+ self.topic.new(rollback, self.fake_session, indata)
+ self.assertEqual(len(rollback), 1, "Wrong rollback length")
+ self.msg.write.assert_not_called()
+
+ def test_kafka_message_is_sent_if_not_paas_vim(self, mock_common_vim_wim_sdn):
+ indata = {
+ "name": "juju_paas",
+ "vim_type": "openstack",
+ "description": None,
+ "vim_url": "http://0.0.0.0:0",
+ "vim_user": "some_user",
+ "vim_password": "some_password",
+ "vim_tenant_name": "null",
+ }
+ rollback = []
+
+ self.topic.new(rollback, self.fake_session, indata)
+ self.assertEqual(len(rollback), 1, "Wrong rollback length")
+ mock_common_vim_wim_sdn.assert_called_once_with(self.fake_session, indata)
+ self.msg.write.assert_called_once_with("vim_account", "created", ANY)
+
+
if __name__ == "__main__":
unittest.main()