+ self.assertEqual(
+ self.db.get_one.call_args[0][0], self.topic.topic, "Wrong topic"
+ )
+ self.assertEqual(
+ self.db.get_one.call_args[0][1]["_id"], cid, "Wrong CIM identifier"
+ )
+ self.assertEqual(
+ self.db.del_one.call_args[0][0], self.topic.topic, "Wrong topic"
+ )
+ self.assertEqual(
+ self.db.del_one.call_args[0][1]["_id"], cid, "Wrong CIM identifier"
+ )
+ self.topic._send_msg.assert_called_once_with(
+ "deleted", {"_id": cid, "op_id": None}, not_send_msg=None
+ )
+
+
+@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_with(self.fake_session, indata)
+ error_msg = "Invalid config 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):
+ valid_juju_paas_config = {
+ "paas_provider": "juju",
+ "ca_cert_content": "file_content",
+ "cloud": "microk8s",
+ "cloud_credentials": "cloud_credential_name",
+ "authorized_keys": "keys",
+ }
+ 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": valid_juju_paas_config,
+ }
+ 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_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_invalid_config(
+ self, mock_common_vim_wim_sdn
+ ):
+ invalid_configs = [
+ {
+ "paas_provider": "some_paas_provider",
+ "ca_cert_content": "file_content",
+ "cloud": "microk8s",
+ "cloud_credentials": "cloud_credential_name",
+ },
+ {
+ "ca_cert_content": "file_content",
+ "cloud": "microk8s",
+ "cloud_credentials": "cloud_credential_name",
+ },
+ {
+ "paas_provider": "juju",
+ "cloud": "microk8s",
+ "cloud_credentials": "cloud_credential_name",
+ },
+ {
+ "paas_provider": "juju",
+ "ca_cert_content": "file_content",
+ "cloud_credentials": "cloud_credential_name",
+ },
+ {
+ "paas_provider": "juju",
+ "ca_cert_content": "file_content",
+ "cloud": "microk8s",
+ },
+ {
+ "some_param": None,
+ },
+ {},
+ ]
+ for config in invalid_configs:
+ with self.subTest():
+ 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": config,
+ }
+ 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):
+ valid_juju_paas_config = {
+ "paas_provider": "juju",
+ "ca_cert_content": "file_content",
+ "cloud": "microk8s",
+ "cloud_credentials": "cloud_credential_name",
+ "authorized_keys": "keys",
+ }
+ 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": valid_juju_paas_config,
+ }
+ rollback = []
+ self.topic.temporal = Mock()
+
+ self.topic.new(rollback, self.fake_session, indata)
+ self.assertEqual(len(rollback), 1, "Wrong rollback length")
+ self.msg.write.assert_not_called()
+ self.topic.temporal.start_vim_workflow.assert_called_once()
+
+ 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)