__date__ = "$2019-10-019"
import unittest
+import random
from unittest import TestCase
from unittest.mock import Mock, patch, call, ANY
from uuid import uuid4
from http import HTTPStatus
from time import time
-from random import randint
from osm_common import dbbase, fsbase, msgbase
from osm_nbi import authconn, validation
from osm_nbi.admin_topics import (
with self.subTest(i=1):
self.auth.get_project_list.side_effect = [[proj], []]
new_name = "new-project-name"
- quotas = {"vnfds": randint(0, 100), "nsds": randint(0, 100)}
+ quotas = {
+ "vnfds": random.SystemRandom().randint(0, 100),
+ "nsds": random.SystemRandom().randint(0, 100),
+ }
self.topic.edit(
self.fake_session, pid, {"name": new_name, "quotas": quotas}
)
self.assertEqual(content["quotas"], quotas, "Wrong quotas")
with self.subTest(i=2):
new_name = "other-project-name"
- quotas = {"baditems": randint(0, 100)}
+ quotas = {"baditems": random.SystemRandom().randint(0, 100)}
self.auth.get_project_list.side_effect = [[proj], []]
with self.assertRaises(EngineException, msg="Accepted wrong quotas") as e:
self.topic.edit(
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"])
+ 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",
"vim_user": "some_user",
"vim_password": "some_password",
"vim_tenant_name": "null",
- "config": {"paas_provider": "juju"},
+ "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_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
):
}
self.check_invalid_indata_raises_exception(indata, mock_common_vim_wim_sdn)
- def test_check_conflict_on_new_vim_type_paas_provider_missing(
+ def test_check_conflict_on_new_vim_type_paas_invalid_config(
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)
+ 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",
"vim_user": "some_user",
"vim_password": "some_password",
"vim_tenant_name": "null",
- "config": {"paas_provider": "juju"},
+ "config": valid_juju_paas_config,
}
rollback = []
self.topic.temporal = Mock()