aboutsummaryrefslogtreecommitdiffstats
path: root/app/test
diff options
context:
space:
mode:
authorKoren Lev <korenlev@gmail.com>2017-12-18 19:16:16 +0200
committerKoren Lev <korenlev@gmail.com>2017-12-18 19:16:16 +0200
commit98c3ac7c859e34fe60d061b9ca591aba429e4118 (patch)
tree3ff2629def8938b12c0a0147e463e74e475c9032 /app/test
parent4709d96cc240c0c4c5308d40361ca3c3da1152fd (diff)
release 1.2 + new tagging
Change-Id: I1e876451ec4a330f458dd57adadb15e39969b225 Signed-off-by: Koren Lev <korenlev@gmail.com>
Diffstat (limited to 'app/test')
-rw-r--r--app/test/api/responders_test/resource/test_clique_types.py108
-rw-r--r--app/test/api/responders_test/resource/test_environment_configs.py311
-rw-r--r--app/test/api/responders_test/test_data/base.py71
-rw-r--r--app/test/api/responders_test/test_data/clique_types.py201
-rw-r--r--app/test/api/responders_test/test_data/environment_configs.py6
-rw-r--r--app/test/api/test_base.py28
-rw-r--r--app/test/fetch/api_fetch/test_api_access.py73
-rw-r--r--app/test/fetch/api_fetch/test_api_fetch_project_hosts.py43
-rw-r--r--app/test/fetch/api_fetch/test_data/api_fetch_host_project_hosts.py21
-rw-r--r--app/test/fetch/link_finders/__init__.py9
-rw-r--r--app/test/fetch/link_finders/test_data/__init__.py9
-rw-r--r--app/test/fetch/link_finders/test_data/test_find_implicit_links.py303
-rw-r--r--app/test/fetch/link_finders/test_find_implicit_links.py107
-rw-r--r--app/test/scan/test_data/configurations.py1
-rw-r--r--app/test/scan/test_data/scanner.py13
-rw-r--r--app/test/scan/test_scan_metadata_parser.py2
-rw-r--r--app/test/scan/test_scanner.py8
-rwxr-xr-xapp/test/verify.sh4
18 files changed, 993 insertions, 325 deletions
diff --git a/app/test/api/responders_test/resource/test_clique_types.py b/app/test/api/responders_test/resource/test_clique_types.py
index f5e331e..5e52cea 100644
--- a/app/test/api/responders_test/resource/test_clique_types.py
+++ b/app/test/api/responders_test/resource/test_clique_types.py
@@ -17,10 +17,17 @@ from unittest.mock import patch
class TestCliqueTypes(TestBase):
- def test_get_clique_types_list_without_env_name(self):
- self.validate_get_request(clique_types.URL,
- params={},
- expected_code=base.BAD_REQUEST_CODE)
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_all_clique_types_list(self, read):
+ self.validate_get_request(
+ clique_types.URL,
+ params={},
+ mocks={
+ read: clique_types.CLIQUE_TYPES
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=clique_types.CLIQUE_TYPES_RESPONSE
+ )
def test_get_clique_types_with_invalid_filter(self):
self.validate_get_request(clique_types.URL,
@@ -53,6 +60,28 @@ class TestCliqueTypes(TestBase):
expected_code=base.SUCCESSFUL_CODE
)
+ def test_get_clique_type_with_insufficient_configuration(self):
+ self.validate_get_request(
+ clique_types.URL,
+ params={
+ "distribution_version": base.CORRECT_DIST_VER,
+ },
+ expected_code=base.BAD_REQUEST_CODE
+ )
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_clique_type_with_correct_configuration(self, read):
+ self.validate_get_request(
+ clique_types.URL,
+ params=clique_types.TEST_CONFIGURATION,
+ mocks={
+ read: clique_types.CLIQUE_TYPES_WITH_SPECIFIC_CONFIGURATION
+ },
+ expected_response=clique_types.
+ CLIQUE_TYPES_WITH_SPECIFIC_CONFIGURATION_RESPONSE,
+ expected_code=base.SUCCESSFUL_CODE
+ )
+
def test_get_clique_types_list_with_wrong_focal_point_type(self):
self.validate_get_request(clique_types.URL,
params={
@@ -204,9 +233,53 @@ class TestCliqueTypes(TestBase):
body=json.dumps(clique_types.NON_DICT_CLIQUE_TYPE),
expected_code=base.BAD_REQUEST_CODE)
- def test_post_clique_type_without_env_name(self):
+ @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME)
+ def test_post_clique_type_with_reserved_env_name(self, check_env_name):
+ self.validate_post_request(
+ clique_types.URL,
+ mocks={
+ check_env_name: True
+ },
+ body=json.dumps(clique_types.CLIQUE_TYPE_WITH_RESERVED_NAME),
+ expected_code=base.BAD_REQUEST_CODE
+ )
+
+ def test_post_clique_type_without_env_name_and_configuration(self):
+ self.validate_post_request(
+ clique_types.URL,
+ body=json.dumps(clique_types.CLIQUE_TYPE_WITHOUT_ENV_NAME_AND_CONF),
+ expected_code=base.BAD_REQUEST_CODE
+ )
+
+ def test_post_clique_type_with_both_env_name_and_configuration(self):
+ self.validate_post_request(
+ clique_types.URL,
+ body=json.dumps(
+ clique_types.CLIQUE_TYPE_WITH_BOTH_ENV_AND_CONF),
+ expected_code=base.BAD_REQUEST_CODE
+ )
+
+ @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME)
+ def test_post_clique_type_with_insufficient_configuration(self, check_env_name):
+ self.validate_post_request(
+ clique_types.URL,
+ mocks={
+ check_env_name: True
+ },
+ body=json.dumps(clique_types.CLIQUE_TYPE_WITH_INSUFFICIENT_CONF),
+ expected_code=base.BAD_REQUEST_CODE
+ )
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_post_clique_type_with_duplicate_configuration(self, read):
+ data = clique_types.CLIQUE_TYPES_WITH_SPECIFIC_CONFIGURATION[0]
+ resp = clique_types.CLIQUE_TYPES_WITH_SPECIFIC_CONFIGURATION_RESPONSE
+ test_data = self.get_updated_data(data, deleted_keys=['id'])
self.validate_post_request(clique_types.URL,
- body=json.dumps(clique_types.CLIQUE_TYPE_WITHOUT_ENVIRONMENT),
+ body=json.dumps(test_data),
+ mocks={
+ read: resp,
+ },
expected_code=base.BAD_REQUEST_CODE)
@patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME)
@@ -231,6 +304,17 @@ class TestCliqueTypes(TestBase):
CLIQUE_TYPE_WITH_WRONG_FOCAL_POINT_TYPE),
expected_code=base.BAD_REQUEST_CODE)
+ @patch(base.RESPONDER_BASE_READ)
+ def test_post_clique_type_with_duplicate_focal_point_type(self, read):
+ test_data = self.get_updated_data(clique_types.CLIQUE_TYPE,
+ updates={'name': 'test-name'})
+ self.validate_post_request(clique_types.URL,
+ body=json.dumps(test_data),
+ mocks={
+ read: [clique_types.CLIQUE_TYPE],
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
def test_post_clique_type_without_link_types(self):
self.validate_post_request(clique_types.URL,
body=json.dumps(
@@ -255,6 +339,18 @@ class TestCliqueTypes(TestBase):
body=json.dumps(clique_types.CLIQUE_TYPE_WITHOUT_NAME),
expected_code=base.BAD_REQUEST_CODE)
+ def test_post_clique_type_with_wrong_mechanism_drivers(self):
+ self.validate_post_request(clique_types.URL,
+ body=json.dumps(clique_types.
+ CLIQUE_TYPE_WITH_WRONG_MECH_DRIVERS),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_clique_type_with_wrong_type_drivers(self):
+ self.validate_post_request(clique_types.URL,
+ body=json.dumps(clique_types.
+ CLIQUE_TYPE_WITH_WRONG_TYPE_DRIVERS),
+ expected_code=base.BAD_REQUEST_CODE)
+
@patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME)
@patch(base.RESPONDER_BASE_WRITE)
def test_post_clique_type(self, write, check_environment_name):
diff --git a/app/test/api/responders_test/resource/test_environment_configs.py b/app/test/api/responders_test/resource/test_environment_configs.py
index 6356f06..4405f2b 100644
--- a/app/test/api/responders_test/resource/test_environment_configs.py
+++ b/app/test/api/responders_test/resource/test_environment_configs.py
@@ -9,7 +9,9 @@
###############################################################################
import json
+from api.responders.resource.environment_configs import EnvironmentConfigs
from test.api.responders_test.test_data import base
+from test.api.responders_test.test_data.base import CONSTANTS_BY_NAMES
from test.api.test_base import TestBase
from test.api.responders_test.test_data import environment_configs
from utils.constants import EnvironmentFeatures
@@ -23,35 +25,25 @@ class TestEnvironmentConfigs(TestBase):
def test_get_environment_configs_list(self, read):
self.validate_get_request(environment_configs.URL,
params={},
- mocks={
- read: environment_configs.ENV_CONFIGS
- },
+ mocks={read: environment_configs.ENV_CONFIGS},
expected_code=base.SUCCESSFUL_CODE,
expected_response=environment_configs.
- ENV_CONFIGS_RESPONSE
- )
+ ENV_CONFIGS_RESPONSE)
def test_get_environment_configs_list_with_invalid_filters(self):
self.validate_get_request(environment_configs.URL,
- params={
- "unknown": "unknown"
- },
+ params={"unknown": "unknown"},
expected_code=base.BAD_REQUEST_CODE)
@patch(base.RESPONDER_BASE_READ)
def test_get_environment_configs_list_with_name(self, read):
+ mocks = {read: environment_configs.ENV_CONFIGS_WITH_SPECIFIC_NAME}
self.validate_get_request(environment_configs.URL,
- params={
- "name": environment_configs.NAME
- },
- mocks={
- read: environment_configs.
- ENV_CONFIGS_WITH_SPECIFIC_NAME
- },
+ params={"name": environment_configs.NAME},
+ mocks=mocks,
expected_code=base.SUCCESSFUL_CODE,
expected_response=environment_configs.
- ENV_CONFIGS_WITH_SPECIFIC_NAME[0]
- )
+ ENV_CONFIGS_WITH_SPECIFIC_NAME[0])
@patch(base.RESPONDER_BASE_READ)
def test_get_environment_configs_list_with_unknown_name(self, read):
@@ -82,193 +74,151 @@ class TestEnvironmentConfigs(TestBase):
@patch(base.RESPONDER_BASE_READ)
def test_get_environment_configs_list_with_distribution(self, read):
+ config = environment_configs.ENV_CONFIGS_WITH_SPECIFIC_DISTRIBUTION
+ config_response = \
+ environment_configs.ENV_CONFIGS_WITH_SPECIFIC_DISTRIBUTION_RESPONSE
self.validate_get_request(environment_configs.URL,
params={
"distribution":
environment_configs.
CORRECT_DISTRIBUTION
},
- mocks={
- read: environment_configs.
- ENV_CONFIGS_WITH_SPECIFIC_DISTRIBUTION
- },
+ mocks={read: config},
expected_code=base.SUCCESSFUL_CODE,
- expected_response=environment_configs.
- ENV_CONFIGS_WITH_SPECIFIC_DISTRIBUTION_RESPONSE)
+ expected_response=config_response)
def test_get_environment_configs_list_with_wrong_mechanism_driver(self):
+ config = environment_configs.WRONG_MECHANISM_DRIVER
self.validate_get_request(environment_configs.URL,
- params={
- "mechanism_drivers":
- environment_configs.WRONG_MECHANISM_DRIVER
- },
+ params={"mechanism_drivers": config},
expected_code=base.BAD_REQUEST_CODE)
@patch(base.RESPONDER_BASE_READ)
def test_get_environment_configs_list_with_mechanism_driver(self, read):
+ mechanism = environment_configs.CORRECT_MECHANISM_DRIVER
+ config = environment_configs.ENV_CONFIGS_WITH_SPECIFIC_MECHANISM_DRIVER
+ config_response = environment_configs.\
+ ENV_CONFIGS_WITH_SPECIFIC_MECHANISM_DRIVER_RESPONSE
self.validate_get_request(environment_configs.URL,
- params={
- "mechanism_drivers":
- environment_configs.CORRECT_MECHANISM_DRIVER
- },
- mocks={
- read: environment_configs.
- ENV_CONFIGS_WITH_SPECIFIC_MECHANISM_DRIVER
- },
+ params={"mechanism_drivers": mechanism},
+ mocks={read: config},
expected_code=base.SUCCESSFUL_CODE,
- expected_response=environment_configs.
- ENV_CONFIGS_WITH_SPECIFIC_MECHANISM_DRIVER_RESPONSE
- )
+ expected_response=config_response)
def test_get_environment_configs_list_with_wrong_type_driver(self):
+ driver = environment_configs.WRONG_TYPE_DRIVER
self.validate_get_request(environment_configs.URL,
- params={
- "type_drivers":
- environment_configs.WRONG_TYPE_DRIVER
- },
+ params={"type_drivers": driver},
expected_code=base.BAD_REQUEST_CODE)
@patch(base.RESPONDER_BASE_READ)
def test_get_environment_configs_list_with_type_driver(self, read):
+ driver = environment_configs.CORRECT_TYPE_DRIVER
+ config = environment_configs.ENV_CONFIGS_WITH_SPECIFIC_TYPE_DRIVER
+ config_response = environment_configs.\
+ ENV_CONFIGS_WITH_SPECIFIC_TYPE_DRIVER_RESPONSE
self.validate_get_request(environment_configs.URL,
- params={
- "type_drivers":
- environment_configs.CORRECT_TYPE_DRIVER
- },
- mocks={
- read: environment_configs.
- ENV_CONFIGS_WITH_SPECIFIC_TYPE_DRIVER
- },
+ params={"type_drivers": driver},
+ mocks={read: config},
expected_code=base.SUCCESSFUL_CODE,
- expected_response=environment_configs.
- ENV_CONFIGS_WITH_SPECIFIC_TYPE_DRIVER_RESPONSE
+ expected_response=config_response
)
@patch(base.RESPONDER_BASE_READ)
def test_get_environment_configs_list_with_user(self, read):
+ config = environment_configs.ENV_CONFIGS_WITH_SPECIFIC_USER
+ config_response = \
+ environment_configs.ENV_CONFIGS_WITH_SPECIFIC_USER_RESPONSE
self.validate_get_request(environment_configs.URL,
- params={
- "user": environment_configs.USER
- },
- mocks={
- read: environment_configs.
- ENV_CONFIGS_WITH_SPECIFIC_USER
- },
+ params={"user": environment_configs.USER},
+ mocks={read: config},
expected_code=base.SUCCESSFUL_CODE,
- expected_response=environment_configs.
- ENV_CONFIGS_WITH_SPECIFIC_USER_RESPONSE
- )
+ expected_response=config_response)
def test_get_environment_configs_list_with_non_bool_listen(self):
self.validate_get_request(environment_configs.URL,
- params={
- "listen": environment_configs.NON_BOOL_LISTEN
- },
+ params={"listen": environment_configs.
+ NON_BOOL_LISTEN},
expected_code=base.BAD_REQUEST_CODE)
@patch(base.RESPONDER_BASE_READ)
def test_get_environment_configs_list_with_bool_listen(self, read):
+ config = environment_configs.ENV_CONFIGS_WITH_SPECIFIC_LISTEN
+ config_response = \
+ environment_configs.ENV_CONFIGS_WITH_SPECIFIC_LISTEN_RESPONSE
self.validate_get_request(environment_configs.URL,
- params={
- "listen": environment_configs.BOOL_LISTEN
- },
- mocks={
- read: environment_configs.
- ENV_CONFIGS_WITH_SPECIFIC_LISTEN
- },
+ params={"listen": environment_configs.
+ BOOL_LISTEN},
+ mocks={read: config},
expected_code=base.SUCCESSFUL_CODE,
- expected_response=environment_configs.
- ENV_CONFIGS_WITH_SPECIFIC_LISTEN_RESPONSE
- )
+ expected_response=config_response)
def test_get_environment_configs_list_with_non_bool_scanned(self):
self.validate_get_request(environment_configs.URL,
- params={
- "scanned": environment_configs.
- NON_BOOL_SCANNED
- },
+ params={"scanned": environment_configs.
+ NON_BOOL_SCANNED},
expected_code=base.BAD_REQUEST_CODE)
@patch(base.RESPONDER_BASE_READ)
def test_get_environment_configs_list_with_bool_scanned(self, read):
+ config = environment_configs.ENV_CONFIGS_WITH_SPECIFIC_SCANNED
+ config_response = \
+ environment_configs.ENV_CONFIGS_WITH_SPECIFIC_SCANNED_RESPONSE
self.validate_get_request(environment_configs.URL,
- params={
- "scanned": environment_configs.BOOL_SCANNED
- },
- mocks={
- read: environment_configs.
- ENV_CONFIGS_WITH_SPECIFIC_SCANNED
- },
+ params={"scanned": environment_configs.
+ BOOL_SCANNED},
+ mocks={read: config},
expected_code=base.SUCCESSFUL_CODE,
- expected_response=environment_configs.
- ENV_CONFIGS_WITH_SPECIFIC_SCANNED_RESPONSE
+ expected_response=config_response
)
- def test_get_environment_configs_list_with_non_bool_monitoring_setup_done(self):
+ def test_get_env_configs_list_with_non_bool_monitoring_setup_done(self):
self.validate_get_request(environment_configs.URL,
- params={
- "listen": environment_configs.
- NON_BOOL_MONITORING_SETUP_DONE
- },
+ params={"listen": environment_configs.
+ NON_BOOL_MONITORING_SETUP_DONE},
expected_code=base.BAD_REQUEST_CODE)
@patch(base.RESPONDER_BASE_READ)
- def test_get_environment_configs_list_with_bool_monitoring_setup_done(self, read):
+ def test_get_environment_configs_list_with_bool_monitoring_setup_done(self,
+ read):
+ config = environment_configs.\
+ ENV_CONFIGS_WITH_SPECIFIC_MONITORING_SETUP_DONE
+ config_response = environment_configs.\
+ ENV_CONFIGS_WITH_SPECIFIC_MONITORING_SETUP_DONE_RESPONSE
self.validate_get_request(environment_configs.URL,
- params={
- "scanned": environment_configs.
- BOOL_MONITORING_SETUP_DONE
- },
- mocks={
- read: environment_configs.
- ENV_CONFIGS_WITH_SPECIFIC_MONITORING_SETUP_DONE
- },
+ params={"scanned": environment_configs.
+ BOOL_MONITORING_SETUP_DONE},
+ mocks={read: config},
expected_code=base.SUCCESSFUL_CODE,
- expected_response=environment_configs.
- ENV_CONFIGS_WITH_SPECIFIC_MONITORING_SETUP_DONE_RESPONSE
- )
+ expected_response=config_response)
def test_get_environment_configs_list_with_non_int_page(self):
self.validate_get_request(environment_configs.URL,
- params={
- "page": base.NON_INT_PAGE
- },
+ params={"page": base.NON_INT_PAGE},
expected_code=base.BAD_REQUEST_CODE)
@patch(base.RESPONDER_BASE_READ)
def test_get_environment_configs_list_with_int_page(self, read):
+ config_response = environment_configs.ENV_CONFIGS_RESPONSE
self.validate_get_request(environment_configs.URL,
- params={
- "page": base.INT_PAGE
- },
- mocks={
- read: environment_configs.ENV_CONFIGS
- },
+ params={"page": base.INT_PAGE},
+ mocks={read: environment_configs.ENV_CONFIGS},
expected_code=base.SUCCESSFUL_CODE,
- expected_response=environment_configs.
- ENV_CONFIGS_RESPONSE
- )
+ expected_response=config_response)
def test_get_environment_configs_list_with_non_int_page_size(self):
self.validate_get_request(environment_configs.URL,
- params={
- "page_size": base.NON_INT_PAGESIZE
- },
+ params={"page_size": base.NON_INT_PAGESIZE},
expected_code=base.BAD_REQUEST_CODE)
@patch(base.RESPONDER_BASE_READ)
def test_get_environment_configs_list_with_int_page_size(self, read):
+ config_response = environment_configs.ENV_CONFIGS_RESPONSE
self.validate_get_request(environment_configs.URL,
- params={
- "page_size": base.INT_PAGESIZE
- },
- mocks={
- read: environment_configs.ENV_CONFIGS
- },
+ params={"page_size": base.INT_PAGESIZE},
+ mocks={read: environment_configs.ENV_CONFIGS},
expected_code=base.SUCCESSFUL_CODE,
- expected_response=environment_configs.
- ENV_CONFIGS_RESPONSE
- )
+ expected_response=config_response)
def test_post_environment_config_without_app_path(self):
test_data = self.get_updated_data(environment_configs.ENV_CONFIG,
@@ -292,8 +242,9 @@ class TestEnvironmentConfigs(TestBase):
expected_code=base.BAD_REQUEST_CODE)
def test_post_environment_config_with_wrong_distribution(self):
+ dist = environment_configs.WRONG_DISTRIBUTION
test_data = self.get_updated_data(environment_configs.ENV_CONFIG,
- updates={"distribution": environment_configs.WRONG_DISTRIBUTION})
+ updates={"distribution": dist})
self.validate_post_request(environment_configs.URL,
body=json.dumps(test_data),
expected_code=base.BAD_REQUEST_CODE)
@@ -306,8 +257,9 @@ class TestEnvironmentConfigs(TestBase):
expected_code=base.BAD_REQUEST_CODE)
def test_post_environment_config_with_wrong_listen(self):
+ listen_val = environment_configs.NON_BOOL_LISTEN
test_data = self.get_updated_data(environment_configs.ENV_CONFIG,
- updates={"listen": environment_configs.NON_BOOL_LISTEN})
+ updates={"listen": listen_val})
self.validate_post_request(environment_configs.URL,
body=json.dumps(test_data),
expected_code=base.BAD_REQUEST_CODE)
@@ -320,10 +272,10 @@ class TestEnvironmentConfigs(TestBase):
expected_code=base.BAD_REQUEST_CODE)
def test_post_environment_config_with_wrong_mechanism_driver(self):
+ mechanism = environment_configs.WRONG_MECHANISM_DRIVER
test_data = self.get_updated_data(environment_configs.ENV_CONFIG,
updates={
- "mechanism_drivers":
- [environment_configs.WRONG_MECHANISM_DRIVER]
+ "mechanism_drivers": [mechanism]
})
self.validate_post_request(environment_configs.URL,
body=json.dumps(test_data),
@@ -344,19 +296,17 @@ class TestEnvironmentConfigs(TestBase):
expected_code=base.BAD_REQUEST_CODE)
def test_post_environment_config_with_wrong_scanned(self):
+ scanned_val = environment_configs.NON_BOOL_SCANNED
test_data = self.get_updated_data(environment_configs.ENV_CONFIG,
- updates={
- "scanned": environment_configs.NON_BOOL_SCANNED
- })
+ updates={"scanned": scanned_val})
self.validate_post_request(environment_configs.URL,
body=json.dumps(test_data),
expected_code=base.BAD_REQUEST_CODE)
def test_post_environment_config_with_wrong_last_scanned(self):
+ scanned_val = base.WRONG_FORMAT_TIME
test_data = self.get_updated_data(environment_configs.ENV_CONFIG,
- updates={
- "last_scanned": base.WRONG_FORMAT_TIME
- })
+ updates={"last_scanned": scanned_val})
self.validate_post_request(environment_configs.URL,
body=json.dumps(test_data),
expected_code=base.BAD_REQUEST_CODE)
@@ -376,16 +326,81 @@ class TestEnvironmentConfigs(TestBase):
expected_code=base.BAD_REQUEST_CODE)
def test_post_environment_config_with_wrong_type_drivers(self):
+ driver = environment_configs.WRONG_TYPE_DRIVER
+ test_data = self.get_updated_data(environment_configs.ENV_CONFIG,
+ updates={"type_drivers": [driver]})
+ self.validate_post_request(environment_configs.URL,
+ body=json.dumps(test_data),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_environment_config_with_duplicate_configurations(self):
+ test_data = self.get_updated_data(environment_configs.ENV_CONFIG)
+ test_data["configuration"].append({
+ "name": "OpenStack"
+ })
+ self.validate_post_request(environment_configs.URL,
+ body=json.dumps(test_data),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_environment_config_with_empty_configuration(self):
+ test_data = self.get_updated_data(environment_configs.ENV_CONFIG)
+ test_data["configuration"].append({})
+ self.validate_post_request(environment_configs.URL,
+ body=json.dumps(test_data),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_environment_config_with_unknown_configuration(self):
+ test_data = self.get_updated_data(environment_configs.ENV_CONFIG)
+ test_data["configuration"].append({
+ "name": "Unknown configuration",
+ })
+ self.validate_post_request(environment_configs.URL,
+ body=json.dumps(test_data),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_environment_config_without_required_configurations(self):
+ for env_type in CONSTANTS_BY_NAMES["environment_types"]:
+ required_conf_list = (
+ EnvironmentConfigs.REQUIRED_CONFIGURATIONS_NAMES.get(env_type,
+ [])
+ )
+ if required_conf_list:
+ test_data = \
+ self.get_updated_data(environment_configs.ENV_CONFIG)
+ test_data['environment_type'] = env_type
+ test_data['configuration'] = [
+ c
+ for c in test_data['configuration']
+ if c['name'] != required_conf_list[0]
+ ]
+
+ self.validate_post_request(environment_configs.URL,
+ body=json.dumps(test_data),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_environment_config_with_incomplete_configuration(self):
test_data = self.get_updated_data(environment_configs.ENV_CONFIG,
updates={
- "type_drivers": [environment_configs.WRONG_TYPE_DRIVER]
+ "configuration": [{
+ "host": "10.56.20.239",
+ "name": "mysql",
+ "user": "root"
+ }, {
+ "name": "OpenStack",
+ "host": "10.56.20.239",
+ }, {
+ "host": "10.56.20.239",
+ "name": "CLI",
+ "user": "root"
+ }]
})
self.validate_post_request(environment_configs.URL,
body=json.dumps(test_data),
expected_code=base.BAD_REQUEST_CODE)
- def mock_validate_env_config_with_supported_envs(self, scanning,
- monitoring, listening):
+ @staticmethod
+ def mock_validate_env_config_with_supported_envs(scanning, monitoring,
+ listening):
InventoryMgr.is_feature_supported_in_env = \
lambda self, matches, feature: {
EnvironmentFeatures.SCANNING: scanning,
@@ -396,11 +411,12 @@ class TestEnvironmentConfigs(TestBase):
@patch(base.RESPONDER_BASE_WRITE)
def test_post_environment_config(self, write):
self.mock_validate_env_config_with_supported_envs(True, True, True)
+ post_body = json.dumps(environment_configs.ENV_CONFIG)
self.validate_post_request(environment_configs.URL,
mocks={
write: None
},
- body=json.dumps(environment_configs.ENV_CONFIG),
+ body=post_body,
expected_code=base.CREATED_CODE)
def test_post_unsupported_environment_config(self):
@@ -421,10 +437,11 @@ class TestEnvironmentConfigs(TestBase):
"listening": False
}
]
+ mock_validate = self.mock_validate_env_config_with_supported_envs
+ config = environment_configs.ENV_CONFIG
for test_case in test_cases:
- self.mock_validate_env_config_with_supported_envs(test_case["scanning"],
- test_case["monitoring"],
- test_case["listening"])
+ mock_validate(test_case["scanning"], test_case["monitoring"],
+ test_case["listening"])
self.validate_post_request(environment_configs.URL,
- body=json.dumps(environment_configs.ENV_CONFIG),
+ body=json.dumps(config),
expected_code=base.BAD_REQUEST_CODE)
diff --git a/app/test/api/responders_test/test_data/base.py b/app/test/api/responders_test/test_data/base.py
index b99d5bb..6d2422a 100644
--- a/app/test/api/responders_test/test_data/base.py
+++ b/app/test/api/responders_test/test_data/base.py
@@ -16,14 +16,14 @@ UNAUTHORIZED_CODE = "401"
CREATED_CODE = "201"
ENV_NAME = "Mirantis-Liberty-API"
-UNKNOWN_ENV = "Unkown-Environment"
+UNKNOWN_ENV = "Unknown-Environment"
NON_INT_PAGE = 1.4
INT_PAGE = 1
NON_INT_PAGESIZE = 2.4
INT_PAGESIZE = 2
WRONG_LINK_TYPE = "instance-host"
-CORRECT_LINK_TYPE= "instance-vnic"
+CORRECT_LINK_TYPE = "instance-vnic"
WRONG_LINK_STATE = "wrong"
CORRECT_LINK_STATE = "up"
@@ -41,7 +41,7 @@ WRONG_TYPE_DRIVER = "wrong_type"
CORRECT_TYPE_DRIVER = "local"
WRONG_MECHANISM_DRIVER = "wrong-mechanism-dirver"
-CORRECT_MECHANISM_DRIVER = "ovs"
+CORRECT_MECHANISM_DRIVER = "OVS"
WRONG_LOG_LEVEL = "wrong-log-level"
CORRECT_LOG_LEVEL = "critical"
@@ -71,16 +71,32 @@ NON_DICT_OBJ = ""
CONSTANTS_BY_NAMES = {
"link_types": [
"instance-vnic",
- "otep-vconnector",
- "otep-host_pnic",
+ "vnic-instance",
+ "vnic-vconnector",
+ "vconnector-vnic",
+ "vconnector-vedge",
+ "vedge-vconnector",
+ "vedge-host_pnic",
+ "host_pnic-vedge",
"host_pnic-network",
+ "network-host_pnic",
"vedge-otep",
- "vnic-vconnector",
+ "otep-vedge",
+ "otep-vconnector",
+ "vconnector-otep",
+ "otep-host_pnic",
+ "host_pnic-otep",
"vconnector-host_pnic",
- "vconnector-vedge",
+ "host_pnic-vconnector",
"vnic-vedge",
- "vedge-host_pnic",
- "vservice-vnic"
+ "vedge-vnic",
+ "vservice-vnic",
+ "vnic-vservice",
+ "switch_pnic-host_pnic",
+ "host_pnic-switch_pnic",
+ "switch_pnic-switch_pnic",
+ "switch_pnic-switch",
+ "switch-switch_pnic"
],
"link_states": [
"up",
@@ -117,9 +133,9 @@ CONSTANTS_BY_NAMES = {
"flat"
],
"mechanism_drivers": [
- "ovs",
- "vpp",
- "LinuxBridge",
+ "OVS",
+ "VPP",
+ "LXB",
"Arista",
"Nexus"
],
@@ -155,6 +171,10 @@ CONSTANTS_BY_NAMES = {
"Mirantis",
"RDO"
],
+ "distribution_versions": [
+ "8.0",
+ "9.0"
+ ],
"environment_operational_status": [
"stopped",
"running",
@@ -168,6 +188,30 @@ CONSTANTS_BY_NAMES = {
],
"environment_monitoring_types": [
"Sensu"
+ ],
+ "scans_statuses": [
+ "draft",
+ "pending",
+ "running",
+ "completed",
+ "completed_with_errors",
+ "failed",
+ "aborted"
+ ],
+ "configuration_targets": [
+ "AMQP",
+ "CLI",
+ "ACI",
+ "mysql",
+ "OpenStack",
+ "Monitoring",
+ "Kubernetes"
+ ],
+ "environment_types": [
+ "OpenStack",
+ "Kubernetes",
+ "VMware",
+ "Bare-metal"
]
}
@@ -175,7 +219,8 @@ CONSTANTS_BY_NAMES = {
RESPONDER_BASE_PATH = "api.responders.responder_base.ResponderBase"
RESPONDER_BASE_GET_OBJECTS_LIST = RESPONDER_BASE_PATH + ".get_objects_list"
RESPONDER_BASE_GET_OBJECT_BY_ID = RESPONDER_BASE_PATH + ".get_object_by_id"
-RESPONDER_BASE_CHECK_ENVIRONMENT_NAME = RESPONDER_BASE_PATH + ".check_environment_name"
+RESPONDER_BASE_CHECK_ENVIRONMENT_NAME = \
+ RESPONDER_BASE_PATH + ".check_environment_name"
RESPONDER_BASE_READ = RESPONDER_BASE_PATH + ".read"
RESPONDER_BASE_WRITE = RESPONDER_BASE_PATH + ".write"
RESPONDER_BASE_AGGREGATE = RESPONDER_BASE_PATH + ".aggregate"
diff --git a/app/test/api/responders_test/test_data/clique_types.py b/app/test/api/responders_test/test_data/clique_types.py
index ae962ce..0791bdf 100644
--- a/app/test/api/responders_test/test_data/clique_types.py
+++ b/app/test/api/responders_test/test_data/clique_types.py
@@ -8,13 +8,18 @@
# http://www.apache.org/licenses/LICENSE-2.0 #
###############################################################################
from test.api.responders_test.test_data import base
-
+from test.api.responders_test.test_data.base import WRONG_MECHANISM_DRIVER, \
+ CORRECT_MECHANISM_DRIVER, CORRECT_TYPE_DRIVER, WRONG_TYPE_DRIVER, \
+ CORRECT_DISTRIBUTION, CORRECT_DIST_VER
URL = "/clique_types"
WRONG_ID = base.WRONG_OBJECT_ID
NONEXISTENT_ID = "58ca73ae3a8a836d10ff3b44"
CORRECT_ID = base.CORRECT_OBJECT_ID
+SAMPLE_IDS = ['58ca73ae3a8a836d10ff3b80', '58ca73ae3a8a836d10ff3b81']
+
+RESERVED_ENV_NAME = 'ANY'
WRONG_FOCAL_POINT_TYPE = base.WRONG_OBJECT_TYPE
CORRECT_FOCAL_POINT_POINT_TYPE = base.CORRECT_OBJECT_TYPE
@@ -23,25 +28,52 @@ WRONG_LINK_TYPE = base.WRONG_LINK_TYPE
NONEXISTENT_LINK_TYPE = "otep-host_pnic"
CORRECT_LINK_TYPE = base.CORRECT_LINK_TYPE
+CLIQUE_TYPE = {
+ "environment": "Mirantis-Liberty-API",
+ "name": "instance_vconnector_clique",
+ "link_types": [
+ "instance-vnic",
+ "vnic-vconnector"
+ ],
+ "focal_point_type": "instance"
+}
+
+TEST_CONFIGURATION = {
+ "distribution": CORRECT_DISTRIBUTION,
+ "distribution_version": CORRECT_DIST_VER,
+ "mechanism_drivers": CORRECT_MECHANISM_DRIVER,
+ "type_drivers": CORRECT_TYPE_DRIVER
+}
+
+
+def get_payload(update: dict = None, delete: list = None):
+ payload = CLIQUE_TYPE.copy()
+ if update:
+ payload.update(update)
+ if delete:
+ for k in delete:
+ del payload[k]
+ return payload
+
+
CLIQUE_TYPES_WITH_SPECIFIC_ID = [
- {
- "environment": "Mirantis-Liberty-API",
- "focal_point_type": "host_pnic",
- "id": CORRECT_ID
- }
+ get_payload(update={'id': CORRECT_ID})
+]
+
+CLIQUE_TYPES_WITH_SPECIFIC_CONFIGURATION = [
+ get_payload(update={'id': SAMPLE_IDS[0],
+ **TEST_CONFIGURATION},
+ delete=['environment'])
]
+CLIQUE_TYPES_WITH_SPECIFIC_CONFIGURATION_RESPONSE = {
+ "clique_types": CLIQUE_TYPES_WITH_SPECIFIC_CONFIGURATION
+}
+
CLIQUE_TYPES_WITH_SPECIFIC_FOCAL_POINT_TYPE = [
- {
- "environment": "Mirantis-Liberty-API",
- "focal_point_type": CORRECT_FOCAL_POINT_POINT_TYPE,
- "id": "58ca73ae3a8a836d10ff3b80"
- },
- {
- "environment": "Mirantis-Liberty-API",
- "focal_point_type": CORRECT_FOCAL_POINT_POINT_TYPE,
- "id": "58ca73ae3a8a836d10ff3b81"
- }
+ get_payload(update={'id': _id,
+ 'focal_point_type': CORRECT_FOCAL_POINT_POINT_TYPE})
+ for _id in SAMPLE_IDS
]
CLIQUE_TYPES_WITH_SPECIFIC_FOCAL_POINT_TYPE_RESPONSE = {
@@ -49,20 +81,9 @@ CLIQUE_TYPES_WITH_SPECIFIC_FOCAL_POINT_TYPE_RESPONSE = {
}
CLIQUE_TYPES_WITH_SPECIFIC_LINK_TYPE = [
- {
- "environment": "Mirantis-Liberty-API",
- "link_types": [
- CORRECT_LINK_TYPE
- ],
- "id": "58ca73ae3a8a836d10ff3b80"
- },
- {
- "environment": "Mirantis-Liberty-API",
- "link_types": [
- CORRECT_LINK_TYPE
- ],
- "id": "58ca73ae3a8a836d10ff3b81"
- }
+ get_payload(update={'id': _id,
+ 'link_types': [CORRECT_LINK_TYPE]})
+ for _id in SAMPLE_IDS
]
CLIQUE_TYPES_WITH_SPECIFIC_LINK_TYPE_RESPONSE = {
@@ -70,16 +91,7 @@ CLIQUE_TYPES_WITH_SPECIFIC_LINK_TYPE_RESPONSE = {
}
CLIQUE_TYPES = [
- {
- "environment": "Mirantis-Liberty-API",
- "focal_point_type": "vnic",
- "id": "58ca73ae3a8a836d10ff3b80"
- },
- {
- "environment": "Mirantis-Liberty-API",
- "focal_point_type": "vnic",
- "id": "58ca73ae3a8a836d10ff3b81"
- }
+ get_payload(update={'id': _id}) for _id in SAMPLE_IDS
]
CLIQUE_TYPES_RESPONSE = {
@@ -88,83 +100,48 @@ CLIQUE_TYPES_RESPONSE = {
NON_DICT_CLIQUE_TYPE = base.NON_DICT_OBJ
-CLIQUE_TYPE_WITHOUT_ENVIRONMENT = {
- "name": "instance_vconnector_clique",
- "link_types": [
- "instance-vnic",
- "vnic-vconnector"
- ],
- "focal_point_type": "instance"
-}
+CLIQUE_TYPE_WITH_RESERVED_NAME = get_payload(
+ update={'environment': RESERVED_ENV_NAME}
+)
-CLIQUE_TYPE_WITH_UNKNOWN_ENVIRONMENT = {
- "environment": base.UNKNOWN_ENV,
- "id": "589a3969761b0555a3ef6093",
- "name": "instance_vconnector_clique",
- "link_types": [
- "instance-vnic",
- "vnic-vconnector"
- ],
- "focal_point_type": "instance"
-}
+CLIQUE_TYPE_WITHOUT_ENV_NAME_AND_CONF = get_payload(
+ delete=['environment']
+)
-CLIQUE_TYPE_WITHOUT_FOCAL_POINT_TYPE = {
- "environment": "Mirantis-Liberty-API",
- "name": "instance_vconnector_clique",
- "link_types": [
- "instance-vnic",
- "vnic-vconnector"
- ]
-}
+CLIQUE_TYPE_WITH_BOTH_ENV_AND_CONF = get_payload(
+ update=TEST_CONFIGURATION
+)
-CLIQUE_TYPE_WITH_WRONG_FOCAL_POINT_TYPE = {
- "environment": "Mirantis-Liberty-API",
- "name": "instance_vconnector_clique",
- "link_types": [
- "instance-vnic",
- "vnic-vconnector"
- ],
- "focal_point_type": WRONG_FOCAL_POINT_TYPE
-}
+CLIQUE_TYPE_WITH_INSUFFICIENT_CONF = get_payload(
+ update={'distribution_version': CORRECT_DIST_VER}
+)
-CLIQUE_TYPE_WITHOUT_LINK_TYPES = {
- "environment": "Mirantis-Liberty-API",
- "name": "instance_vconnector_clique",
- "focal_point_type": "instance"
-}
+CLIQUE_TYPE_WITH_UNKNOWN_ENVIRONMENT = get_payload(
+ update={'environment': base.UNKNOWN_ENV}
+)
-CLIQUE_TYPE_WITH_NON_LIST_LINK_TYPES = {
- "environment": "Mirantis-Liberty-API",
- "name": "instance_vconnector_clique",
- "link_types": "instance-vnic",
- "focal_point_type": "instance"
-}
+CLIQUE_TYPE_WITHOUT_FOCAL_POINT_TYPE = get_payload(delete=['focal_point_type'])
-CLIQUE_TYPE_WITH_WRONG_LINK_TYPE = {
- "environment": "Mirantis-Liberty-API",
- "name": "instance_vconnector_clique",
- "link_types": [
- WRONG_LINK_TYPE,
- "vnic-vconnector"
- ],
- "focal_point_type": "instance"
-}
+CLIQUE_TYPE_WITH_WRONG_FOCAL_POINT_TYPE = get_payload(
+ update={'focal_point_type': WRONG_FOCAL_POINT_TYPE}
+)
-CLIQUE_TYPE_WITHOUT_NAME = {
- "environment": "Mirantis-Liberty-API",
- "link_types": [
- "instance-vnic",
- "vnic-vconnector",
- ],
- "focal_point_type": "instance"
-}
+CLIQUE_TYPE_WITHOUT_LINK_TYPES = get_payload(delete=['link_types'])
-CLIQUE_TYPE = {
- "environment": "Mirantis-Liberty-API",
- "name": "instance_vconnector_clique",
- "link_types": [
- "instance-vnic",
- "vnic-vconnector"
- ],
- "focal_point_type": "instance"
-}
+CLIQUE_TYPE_WITH_NON_LIST_LINK_TYPES = get_payload(
+ update={'link_types': "instance-vnic"}
+)
+
+CLIQUE_TYPE_WITH_WRONG_LINK_TYPE = get_payload(
+ update={'link_types': [WRONG_LINK_TYPE, "vnic-vconnector"]}
+)
+
+CLIQUE_TYPE_WITHOUT_NAME = get_payload(delete=['name'])
+
+CLIQUE_TYPE_WITH_WRONG_MECH_DRIVERS = get_payload(
+ update={'mechanism_drivers': WRONG_MECHANISM_DRIVER}
+)
+
+CLIQUE_TYPE_WITH_WRONG_TYPE_DRIVERS = get_payload(
+ update={'type_drivers': WRONG_TYPE_DRIVER}
+) \ No newline at end of file
diff --git a/app/test/api/responders_test/test_data/environment_configs.py b/app/test/api/responders_test/test_data/environment_configs.py
index 4cea105..3e976ec 100644
--- a/app/test/api/responders_test/test_data/environment_configs.py
+++ b/app/test/api/responders_test/test_data/environment_configs.py
@@ -201,6 +201,7 @@ ENV_CONFIG = {
"provision": "None",
"env_type": "development",
"name": "Monitoring",
+ "install_monitoring_client": True,
"api_port": "4567",
"rabbitmq_port": "5671",
"rabbitmq_pass": "sensuaccess",
@@ -218,12 +219,13 @@ ENV_CONFIG = {
"last_scanned": "2017-03-16T11:14:54Z",
"listen": True,
"mechanism_drivers": [
- "ovs"
+ "OVS"
],
"name": "Mirantis-Liberty",
"operational": "running",
"scanned": True,
"type": "environment",
"type_drivers": "vxlan",
- "user": "WS7j8oTbWPf3LbNne"
+ "user": "WS7j8oTbWPf3LbNne",
+ "environment_type": "OpenStack"
}
diff --git a/app/test/api/test_base.py b/app/test/api/test_base.py
index 33185ec..edc59ae 100644
--- a/app/test/api/test_base.py
+++ b/app/test/api/test_base.py
@@ -34,8 +34,10 @@ class TestBase(TestCase):
self.original_auth_method = AuthenticationMiddleware.process_request
AuthenticationMiddleware.process_request = mock_auth_method
- ResponderBase.get_constants_by_name = MagicMock(side_effect=
- lambda name: base.CONSTANTS_BY_NAMES[name])
+ ResponderBase.get_constants_by_name = MagicMock(
+ side_effect=lambda name: base.CONSTANTS_BY_NAMES[name]
+ )
+
# mock mongo access
MongoAccess.mongo_connect = MagicMock()
MongoAccess.db = MagicMock()
@@ -47,8 +49,8 @@ class TestBase(TestCase):
log_level = 'debug'
self.app = App(log_level=log_level).get_app()
- def validate_get_request(self, url, params={}, headers=None, mocks={},
- side_effects={},
+ def validate_get_request(self, url, params=None, headers=None, mocks=None,
+ side_effects=None,
expected_code=base.SUCCESSFUL_CODE,
expected_response=None):
self.validate_request("GET", url, params, headers, "",
@@ -59,25 +61,27 @@ class TestBase(TestCase):
def validate_request(self, action, url, params, headers, body,
mocks, side_effects, expected_code,
expected_response):
- for mock_method, mock_data in mocks.items():
- mock_method.return_value = mock_data
+ if mocks:
+ for mock_method, mock_data in mocks.items():
+ mock_method.return_value = mock_data
- for mock_method, side_effect in side_effects.items():
- mock_method.side_effect = side_effect
+ if side_effects:
+ for mock_method, side_effect in side_effects.items():
+ mock_method.side_effect = side_effect
result = self.simulate_request(action, url, params=params, headers=headers, body=body)
self.assertEqual(result.status, expected_code)
if expected_response:
self.assertEqual(result.json, expected_response)
- def validate_post_request(self, url, headers={}, body="", mocks={},
- side_effects={},
+ def validate_post_request(self, url, headers=None, body="", mocks=None,
+ side_effects=None,
expected_code=base.CREATED_CODE, expected_response=None):
self.validate_request("POST", url, {}, headers, body, mocks, side_effects,
expected_code, expected_response)
- def validate_delete_request(self, url, params={}, headers={}, mocks={},
- side_effects={},
+ def validate_delete_request(self, url, params=None, headers=None, mocks=None,
+ side_effects=None,
expected_code=base.SUCCESSFUL_CODE, expected_response=None):
self.validate_request("DELETE", url, params, headers, "",
mocks, side_effects,
diff --git a/app/test/fetch/api_fetch/test_api_access.py b/app/test/fetch/api_fetch/test_api_access.py
index 0effc0e..440b730 100644
--- a/app/test/fetch/api_fetch/test_api_access.py
+++ b/app/test/fetch/api_fetch/test_api_access.py
@@ -7,9 +7,9 @@
# which accompanies this distribution, and is available at #
# http://www.apache.org/licenses/LICENSE-2.0 #
###############################################################################
-from unittest.mock import MagicMock, Mock
-
+import copy
import requests
+from unittest.mock import MagicMock, Mock
from discover.fetchers.api.api_access import ApiAccess
from test.fetch.api_fetch.test_data.api_access import *
@@ -35,38 +35,45 @@ class TestApiAccess(TestFetch):
def test_parse_illegal_time(self):
time = self.api_access.parse_time(ILLEGAL_TIME)
- self.assertEqual(time, None, "Can't get None when the time format is wrong")
+ self.assertEqual(time, None,
+ "Can't get None when the time format is wrong")
def test_get_existing_token(self):
self.api_access.tokens = VALID_TOKENS
token = self.api_access.get_existing_token(PROJECT)
- self.assertNotEqual(token, VALID_TOKENS[PROJECT], "Can't get existing token")
+ self.assertNotEqual(token, VALID_TOKENS[PROJECT],
+ "Can't get existing token")
def test_get_nonexistent_token(self):
self.api_access.tokens = EMPTY_TOKENS
token = self.api_access.get_existing_token(TEST_PROJECT)
- self.assertEqual(token, None, "Can't get None when the token doesn't " +
- "exist in tokens")
+ self.assertEqual(token, None,
+ "Can't get None when the token doesn't exist "
+ "in tokens")
def test_v2_auth(self):
self.api_access.get_existing_token = MagicMock(return_value=None)
self.response.json = Mock(return_value=CORRECT_AUTH_CONTENT)
# mock authentication info from OpenStack Api
- token_details = self.api_access.v2_auth(TEST_PROJECT, TEST_HEADER, TEST_BODY)
+ token_details = self.api_access.v2_auth(TEST_PROJECT, TEST_HEADER,
+ TEST_BODY)
self.assertNotEqual(token_details, None, "Can't get the token details")
def test_v2_auth_with_error_content(self):
self.api_access.get_existing_token = MagicMock(return_value=None)
self.response.json = Mock(return_value=ERROR_AUTH_CONTENT)
# authentication content from OpenStack Api will be incorrect
- token_details = self.api_access.v2_auth(TEST_PROJECT, TEST_HEADER, TEST_BODY)
- self.assertIs(token_details, None, "Can't get None when the content is wrong")
+ token_details = self.api_access.v2_auth(TEST_PROJECT, TEST_HEADER,
+ TEST_BODY)
+ self.assertIs(token_details, None,
+ "Can't get None when the content is wrong")
def test_v2_auth_with_error_token(self):
self.response.status_code = requests.codes.bad_request
self.response.json = Mock(return_value=ERROR_TOKEN_CONTENT)
# authentication info from OpenStack Api will not contain token info
- token_details = self.api_access.v2_auth(TEST_PROJECT, TEST_HEADER, TEST_BODY)
+ token_details = self.api_access.v2_auth(TEST_PROJECT, TEST_HEADER,
+ TEST_BODY)
self.assertIs(token_details, None, "Can't get None when the content " +
"doesn't contain any token info")
@@ -78,12 +85,13 @@ class TestApiAccess(TestFetch):
# the time will not be parsed
self.api_access.parse_time = MagicMock(return_value=None)
- token_details = self.api_access.v2_auth(TEST_PROJECT, TEST_HEADER, TEST_BODY)
+ token_details = self.api_access.v2_auth(TEST_PROJECT, TEST_HEADER,
+ TEST_BODY)
# reset original parse_time method
self.api_access.parse_time = original_method
- self.assertIs(token_details, None, "Can't get None when the time in token " +
- "can't be parsed")
+ self.assertIs(token_details, None,
+ "Can't get None when the time in token can't be parsed")
def test_v2_auth_pwd(self):
self.response.json = Mock(return_value=CORRECT_AUTH_CONTENT)
@@ -92,20 +100,30 @@ class TestApiAccess(TestFetch):
self.assertNotEqual(token, None, "Can't get token")
def test_get_url(self):
- self.response.json = Mock(return_value=GET_CONTENT)
+ get_response = copy.deepcopy(self.response)
+ get_response.status_code = requests.codes.ok
+ self.requests_get = requests.get
+ requests.get = MagicMock(return_value=get_response)
+ get_response.json = Mock(return_value=GET_CONTENT)
result = self.api_access.get_url(TEST_URL, TEST_HEADER)
# check whether it returns content message when the response is correct
self.assertNotEqual(result, None, "Can't get content when the "
"response is correct")
+ requests.get = self.requests_get
def test_get_url_with_error_response(self):
- self.response.status_code = requests.codes.bad_request
- self.response.json = Mock(return_value=None)
- self.response.text = "Bad request"
+ get_response = copy.deepcopy(self.response)
+ get_response.status_code = requests.codes.bad_request
+ get_response.text = "Bad request"
+ get_response.json = Mock(return_value=GET_CONTENT)
+ self.requests_get = requests.get
+ requests.get = MagicMock(return_value=get_response)
+
# the response will be wrong
result = self.api_access.get_url(TEST_URL, TEST_HEADER)
self.assertEqual(result, None, "Result returned" +
"when the response status is not 200")
+ requests.get = self.requests_get
def test_get_region_url(self):
region_url = self.api_access.get_region_url(REGION_NAME, SERVICE_NAME)
@@ -120,23 +138,30 @@ class TestApiAccess(TestFetch):
def test_get_region_url_without_service_endpoint(self):
# error service doesn't exist in region service endpoints
- region_url = self.api_access.get_region_url(REGION_NAME, ERROR_SERVICE_NAME)
- self.assertIs(region_url, None, "Can't get None with wrong service name")
+ region_url = self.api_access.get_region_url(REGION_NAME,
+ ERROR_SERVICE_NAME)
+ self.assertIs(region_url, None,
+ "Can't get None with wrong service name")
def test_region_url_nover(self):
- # mock return value of get_region_url, which has something starting from v2
+ # mock return value of get_region_url,
+ # which has something starting from v2
self.api_access.get_region_url = MagicMock(return_value=REGION_URL)
- region_url = self.api_access.get_region_url_nover(REGION_NAME, SERVICE_NAME)
+ region_url = self.api_access.get_region_url_nover(REGION_NAME,
+ SERVICE_NAME)
# get_region_nover will remove everything from v2
- self.assertNotIn("v2", region_url, "Can't get region url without v2 info")
+ self.assertNotIn("v2", region_url,
+ "Can't get region url without v2 info")
def test_get_service_region_endpoints(self):
region = REGIONS[REGION_NAME]
- result = self.api_access.get_service_region_endpoints(region, SERVICE_NAME)
+ result = self.api_access.get_service_region_endpoints(region,
+ SERVICE_NAME)
self.assertNotEqual(result, None, "Can't get service endpoint")
def test_get_service_region_endpoints_with_nonexistent_service(self):
region = REGIONS[REGION_NAME]
- result = self.api_access.get_service_region_endpoints(region, ERROR_SERVICE_NAME)
+ get_endpoints = self.api_access.get_service_region_endpoints
+ result = get_endpoints(region, ERROR_SERVICE_NAME)
self.assertIs(result, None, "Can't get None when the service name " +
"doesn't exist in region's services")
diff --git a/app/test/fetch/api_fetch/test_api_fetch_project_hosts.py b/app/test/fetch/api_fetch/test_api_fetch_project_hosts.py
index da3df17..784079e 100644
--- a/app/test/fetch/api_fetch/test_api_fetch_project_hosts.py
+++ b/app/test/fetch/api_fetch/test_api_fetch_project_hosts.py
@@ -7,6 +7,7 @@
# which accompanies this distribution, and is available at #
# http://www.apache.org/licenses/LICENSE-2.0 #
###############################################################################
+import copy
from unittest.mock import MagicMock
from discover.fetchers.api.api_fetch_project_hosts import ApiFetchProjectHosts
from test.fetch.test_fetch import TestFetch
@@ -36,23 +37,28 @@ class TestApiFetchProjectHosts(TestFetch):
"type in host_type")
def test_add_host_type_with_existent_host_type(self):
+ fetch_host_os_details = self.fetcher.fetch_host_os_details
+ self.fetcher.fetch_host_os_details = MagicMock()
# add nonexistent host type to host type
HOST_DOC["host_type"] = [NONEXISTENT_TYPE]
# try to add existing host type
self.fetcher.add_host_type(HOST_DOC, NONEXISTENT_TYPE, HOST_ZONE)
- self.assertEqual(len(HOST_DOC['host_type']), 1, "Add duplicate host type")
+ self.assertEqual(len(HOST_DOC['host_type']), 1,
+ "Add duplicate host type")
+ self.fetcher.fetch_host_os_details = fetch_host_os_details
def test_add_compute_host_type(self):
- HOST_DOC['host_type'] = []
+ doc = copy.deepcopy(HOST_DOC)
+ doc['host_type'] = []
# clear zone
- HOST_DOC['zone'] = None
+ doc['zone'] = None
# add compute host type
- self.fetcher.add_host_type(HOST_DOC, COMPUTE_TYPE, HOST_ZONE)
+ self.fetcher.add_host_type(doc, COMPUTE_TYPE, HOST_ZONE)
# for compute host type, zone information will be added
- self.assertEqual(HOST_DOC['zone'], HOST_ZONE, "Can't update zone " +
- "name for compute node")
- self.assertEqual(HOST_DOC['parent_id'], HOST_ZONE, "Can't update parent_id " +
- "for compute node")
+ self.assertEqual(doc['zone'], HOST_ZONE,
+ "Can't update zone name for compute node")
+ self.assertEqual(doc['parent_id'], HOST_ZONE,
+ "Can't update parent_id for compute node")
def test_fetch_compute_node_ip_address(self):
# mock ip address information fetched from DB
@@ -78,16 +84,24 @@ class TestApiFetchProjectHosts(TestFetch):
def test_get_host_details(self):
# test node have nova-conductor attribute, controller type will be added
+ fetch_host_os_details = self.fetcher.fetch_host_os_details
+ self.fetcher.fetch_host_os_details = MagicMock()
result = self.fetcher.get_host_details(AVAILABILITY_ZONE, HOST_NAME)
self.assertIn("Controller", result['host_type'], "Can't put controller type " +
"in the compute node host_type")
+ self.fetcher.fetch_host_os_details = fetch_host_os_details
def test_get_hosts_from_az(self):
+ fetch_host_os_details = self.fetcher.fetch_host_os_details
+ self.fetcher.fetch_host_os_details = MagicMock()
result = self.fetcher.get_hosts_from_az(AVAILABILITY_ZONE)
self.assertNotEqual(result, [], "Can't get hosts information from "
"availability zone")
+ self.fetcher.fetch_host_os_details = fetch_host_os_details
def test_get_for_region(self):
+ fetch_host_os_details = self.fetcher.fetch_host_os_details
+ self.fetcher.fetch_host_os_details = MagicMock()
# mock region url for nova node
self.fetcher.get_region_url = MagicMock(return_value=REGION_URL)
# mock the response from OpenStack Api
@@ -96,6 +110,7 @@ class TestApiFetchProjectHosts(TestFetch):
result = self.fetcher.get_for_region(self.region, TOKEN)
self.assertNotEqual(result, [], "Can't get hosts information for region")
+ self.fetcher.fetch_host_os_details = fetch_host_os_details
def test_get_for_region_without_token(self):
self.fetcher.get_region_url = MagicMock(return_value=REGION_URL)
@@ -112,6 +127,8 @@ class TestApiFetchProjectHosts(TestFetch):
self.assertEqual(result, [], "Can't get [] when the response is wrong")
def test_get_for_region_with_error_hypervisors_response(self):
+ fetch_host_os_details = self.fetcher.fetch_host_os_details
+ self.fetcher.fetch_host_os_details = MagicMock()
self.fetcher.get_region_url = MagicMock(return_value=REGION_URL)
# mock error hypervisors response from OpenStack Api
side_effect = [AVAILABILITY_ZONE_RESPONSE, HYPERVISORS_ERROR_RESPONSE]
@@ -120,6 +137,7 @@ class TestApiFetchProjectHosts(TestFetch):
result = self.fetcher.get_for_region(self.region, TOKEN)
self.assertNotEqual(result, [], "Can't get hosts information when " +
"the hypervisors response is wrong")
+ self.fetcher.fetch_host_os_details = fetch_host_os_details
def test_get(self):
original_method = self.fetcher.get_for_region
@@ -140,6 +158,15 @@ class TestApiFetchProjectHosts(TestFetch):
result = self.fetcher.get(PROJECT_NAME)
self.assertEqual(result, [], "Can't get [] when the token is invalid")
+ def test_fetch_host_os_details(self):
+ original_method = self.fetcher.run
+ self.fetcher.run = MagicMock(return_value=OS_DETAILS_INPUT)
+ doc = {'host': 'host1'}
+ self.fetcher.fetch_host_os_details(doc)
+ self.assertEqual(doc.get('OS', {}), OS_DETAILS)
+ self.fetcher.run = original_method
+
+
def tearDown(self):
super().tearDown()
ApiFetchProjectHosts.v2_auth_pwd = self._v2_auth_pwd
diff --git a/app/test/fetch/api_fetch/test_data/api_fetch_host_project_hosts.py b/app/test/fetch/api_fetch/test_data/api_fetch_host_project_hosts.py
index 3ef1ac7..ba42590 100644
--- a/app/test/fetch/api_fetch/test_data/api_fetch_host_project_hosts.py
+++ b/app/test/fetch/api_fetch/test_data/api_fetch_host_project_hosts.py
@@ -223,3 +223,24 @@ GET_FOR_REGION_INFO = [
"zone": "osdna-zone"
}
]
+
+OS_DETAILS_INPUT = """
+NAME="Ubuntu"
+VERSION="16.04 LTS (Xenial Xerus)"
+ID=ubuntu
+ID_LIKE=debian
+PRETTY_NAME="Ubuntu 16.04 LTS"
+VERSION_ID="16.04"
+HOME_URL="http://www.ubuntu.com/"
+SUPPORT_URL="http://help.ubuntu.com/"
+BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
+UBUNTU_CODENAME=xenial
+ARCHITECURE=x86_64
+"""
+OS_DETAILS = {
+ 'name': 'Ubuntu',
+ 'version': '16.04 LTS (Xenial Xerus)',
+ 'ID': 'ubuntu',
+ 'ID_LIKE': 'debian',
+ 'architecure': 'x86_64'
+}
diff --git a/app/test/fetch/link_finders/__init__.py b/app/test/fetch/link_finders/__init__.py
new file mode 100644
index 0000000..b0637e9
--- /dev/null
+++ b/app/test/fetch/link_finders/__init__.py
@@ -0,0 +1,9 @@
+###############################################################################
+# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
+# and others #
+# #
+# All rights reserved. This program and the accompanying materials #
+# are made available under the terms of the Apache License, Version 2.0 #
+# which accompanies this distribution, and is available at #
+# http://www.apache.org/licenses/LICENSE-2.0 #
+###############################################################################
diff --git a/app/test/fetch/link_finders/test_data/__init__.py b/app/test/fetch/link_finders/test_data/__init__.py
new file mode 100644
index 0000000..b0637e9
--- /dev/null
+++ b/app/test/fetch/link_finders/test_data/__init__.py
@@ -0,0 +1,9 @@
+###############################################################################
+# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
+# and others #
+# #
+# All rights reserved. This program and the accompanying materials #
+# are made available under the terms of the Apache License, Version 2.0 #
+# which accompanies this distribution, and is available at #
+# http://www.apache.org/licenses/LICENSE-2.0 #
+###############################################################################
diff --git a/app/test/fetch/link_finders/test_data/test_find_implicit_links.py b/app/test/fetch/link_finders/test_data/test_find_implicit_links.py
new file mode 100644
index 0000000..aef20f6
--- /dev/null
+++ b/app/test/fetch/link_finders/test_data/test_find_implicit_links.py
@@ -0,0 +1,303 @@
+###############################################################################
+# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
+# and others #
+# #
+# All rights reserved. This program and the accompanying materials #
+# are made available under the terms of the Apache License, Version 2.0 #
+# which accompanies this distribution, and is available at #
+# http://www.apache.org/licenses/LICENSE-2.0 #
+###############################################################################
+ENV = 'env1'
+CLIQUE_CONSTRAINTS = [
+ {
+ 'focal_point_type': 'instance',
+ 'constraints': ['network']
+ },
+ {
+ 'focal_point_type': 'dummy1',
+ 'constraints': []
+ },
+ {
+ 'focal_point_type': 'dummy2',
+ 'constraints': ['network', 'dummy_constraint']
+ },
+ {
+ 'focal_point_type': 'dummy3',
+ 'constraints': ['dummy_constraint2']
+ }
+]
+CONSTRAINTS = ['network', 'dummy_constraint', 'dummy_constraint2']
+
+LINK_ATTRIBUTES_NONE = {}
+LINK_ATTRIBUTES_NONE_2 = {}
+LINK_ATTRIBUTES_EMPTY = {'attributes': []}
+LINK_ATTR_V1 = {'attributes': {'network': 'v1'}}
+LINK_ATTR_V1_2 = {'attributes': {'network': 'v1'}}
+LINK_ATTR_V2 = {'attributes': {'network': 'v2'}}
+LINK_ATTR_V1_AND_A2V2 = {'attributes': {'network': 'v1', 'attr2': 'v2'}}
+
+LINK_TYPE_1 = {
+ 'link_type': 'instance-vnic',
+ 'source_id': 'instance1',
+ 'target_id': 'vnic1'
+}
+LINK_TYPE_1_REVERSED = {
+ 'link_type': 'instance-vnic',
+ 'source_id': 'vnic1',
+ 'target_id': 'instance1'
+}
+LINK_TYPE_1_2 = {
+ 'link_type': 'instance-vnic',
+ 'source_id': 'instance1',
+ 'target_id': 'vnic2'
+}
+LINK_TYPE_2 = {
+ 'link_type': 'vnic-vconnector',
+ 'source_id': 'vnic1',
+ 'target_id': 'vconnector1'
+}
+LINK_TYPE_3 = {
+ 'implicit': True,
+ 'link_type': 'instance-vconnector',
+ 'source_id': 'instance1',
+ 'target_id': 'vconnector1'
+}
+LINK_TYPE_4_NET1 = {
+ 'environment': ENV,
+ 'implicit': True,
+ 'link_type': 'instance-host_pnic',
+ 'source': 'instance1_dbid',
+ 'source_id': 'instance1',
+ 'target': 'host_pnic1_dbid',
+ 'target_id': 'host_pnic1',
+ 'host': 'host1',
+ 'link_name': '',
+ 'state': 'up',
+ 'source_label': '',
+ 'target_label': '',
+ 'link_weight': 0,
+ 'attributes': {'network': 'netID1'}
+}
+LINK_TYPE_5_NET2 = {
+ 'environment': ENV,
+ 'link_type': 'host_pnic-switch',
+ 'source_id': 'host_pnic1',
+ 'target': 'switch1_dbid',
+ 'target_id': 'switch1',
+ 'host': 'host2',
+ 'link_name': '',
+ 'state': 'up',
+ 'source_label': '',
+ 'target_label': '',
+ 'link_weight': 0,
+ 'attributes': {'network': 'netID2'}
+}
+LINK_TYPE_6_NET1 = {
+ 'environment': ENV,
+ 'link_type': 'host_pnic-switch',
+ 'source': 'host_pnic1_dbid',
+ 'source_id': 'host_pnic1',
+ 'target': 'switch2_dbid',
+ 'target_id': 'switch2',
+ 'host': 'host1',
+ 'link_name': '',
+ 'state': 'up',
+ 'source_label': '',
+ 'target_label': '',
+ 'link_weight': 0,
+ 'attributes': {'network': 'netID1'}
+}
+LINK_TYPE_7_NET1 = {
+ 'environment': ENV,
+ 'implicit': True,
+ 'link_type': 'instance-switch',
+ 'source': 'instance1_dbid',
+ 'source_id': 'instance1',
+ 'target': 'switch2_dbid',
+ 'target_id': 'switch2',
+ 'host': 'host1',
+ 'link_name': '',
+ 'state': 'up',
+ 'source_label': '',
+ 'target_label': '',
+ 'link_weight': 0,
+ 'attributes': {'network': 'netID1'}
+}
+
+LINK_FULL_A2B = {
+ 'environment': ENV,
+ 'link_type': 'instance-vnic',
+ 'source': 'instance1_dbid',
+ 'source_id': 'instance1',
+ 'target': 'vnic1_dbid',
+ 'target_id': 'vnic1',
+ 'host': 'host1',
+ 'link_name': '',
+ 'state': 'up',
+ 'source_label': '',
+ 'target_label': '',
+ 'link_weight': 0,
+ 'attributes': {'network': 'netID1'}
+}
+LINK_FULL_B2C = {
+ 'environment': ENV,
+ 'link_type': 'vnic-vconnector',
+ 'source': 'vnic1_dbid',
+ 'source_id': 'vnic1',
+ 'target': 'vconnector1_dbid',
+ 'target_id': 'vconnector1',
+ 'host': 'host1',
+ 'link_name': '',
+ 'state': 'up',
+ 'source_label': '',
+ 'target_label': '',
+ 'link_weight': 0,
+ 'attributes': {'network': 'netID1'}
+}
+LINK_FULL_C2D = {
+ 'environment': ENV,
+ 'link_type': 'vconnector-vedge',
+ 'source': 'vconnector1_dbid',
+ 'source_id': 'vconnector1',
+ 'target': 'vedge1_dbid',
+ 'target_id': 'vedge1',
+ 'host': 'host1',
+ 'link_name': '',
+ 'state': 'up',
+ 'source_label': '',
+ 'target_label': '',
+ 'link_weight': 0,
+ 'attributes': {'network': 'netID1'}
+}
+LINK_FULL_D2E = {
+ 'environment': ENV,
+ 'link_type': 'vedge-otep',
+ 'source': 'vedge1_dbid',
+ 'source_id': 'vedge1',
+ 'target': 'otep1_dbid',
+ 'target_id': 'otep1',
+ 'host': 'host1',
+ 'link_name': '',
+ 'state': 'up',
+ 'source_label': '',
+ 'target_label': '',
+ 'link_weight': 0,
+ 'attributes': {'network': 'netID1'}
+}
+LINK_FULL_A2C = {
+ 'environment': ENV,
+ 'implicit': True,
+ 'link_type': 'instance-vconnector',
+ 'source': 'instance1_dbid',
+ 'source_id': 'instance1',
+ 'target': 'vconnector1_dbid',
+ 'target_id': 'vconnector1',
+ 'host': 'host1',
+ 'link_name': '',
+ 'state': 'up',
+ 'source_label': '',
+ 'target_label': '',
+ 'link_weight': 0,
+ 'attributes': {'network': 'netID1'}
+}
+LINK_FULL_B2D = {
+ 'environment': ENV,
+ 'implicit': True,
+ 'link_type': 'vnic-vedge',
+ 'source': 'vnic1_dbid',
+ 'source_id': 'vnic1',
+ 'target': 'vedge1_dbid',
+ 'target_id': 'vedge1',
+ 'host': 'host1',
+ 'link_name': '',
+ 'state': 'up',
+ 'source_label': '',
+ 'target_label': '',
+ 'link_weight': 0,
+ 'attributes': {'network': 'netID1'}
+}
+LINK_FULL_C2E = {
+ 'environment': ENV,
+ 'implicit': True,
+ 'link_type': 'vconnector-otep',
+ 'source': 'vconnector1_dbid',
+ 'source_id': 'vconnector1',
+ 'target': 'otep1_dbid',
+ 'target_id': 'otep1',
+ 'host': 'host1',
+ 'link_name': '',
+ 'state': 'up',
+ 'source_label': '',
+ 'target_label': '',
+ 'link_weight': 0,
+ 'attributes': {'network': 'netID1'}
+}
+LINK_FULL_A2D = {
+ 'environment': ENV,
+ 'implicit': True,
+ 'link_type': 'instance-vedge',
+ 'source': 'instance1_dbid',
+ 'source_id': 'instance1',
+ 'target': 'vedge1_dbid',
+ 'target_id': 'vedge1',
+ 'host': 'host1',
+ 'link_name': '',
+ 'state': 'up',
+ 'source_label': '',
+ 'target_label': '',
+ 'link_weight': 0,
+ 'attributes': {'network': 'netID1'}
+}
+LINK_FULL_B2E = {
+ 'environment': ENV,
+ 'implicit': True,
+ 'link_type': 'vnic-otep',
+ 'source': 'vnic1_dbid',
+ 'source_id': 'vnic1',
+ 'target': 'otep1_dbid',
+ 'target_id': 'otep1',
+ 'host': 'host1',
+ 'link_name': '',
+ 'state': 'up',
+ 'source_label': '',
+ 'target_label': '',
+ 'link_weight': 0,
+ 'attributes': {'network': 'netID1'}
+}
+LINK_FULL_A2E = {
+ 'environment': ENV,
+ 'implicit': True,
+ 'link_type': 'instance-otep',
+ 'source': 'instance1_dbid',
+ 'source_id': 'instance1',
+ 'target': 'otep1_dbid',
+ 'target_id': 'otep1',
+ 'host': 'host1',
+ 'link_name': '',
+ 'state': 'up',
+ 'source_label': '',
+ 'target_label': '',
+ 'link_weight': 0,
+ 'attributes': {'network': 'netID1'}
+}
+BASE_LINKS = [
+ {'pass': 0, 'link': LINK_FULL_A2B},
+ {'pass': 0, 'link': LINK_FULL_B2C},
+ {'pass': 0, 'link': LINK_FULL_C2D},
+ {'pass': 0, 'link': LINK_FULL_D2E},
+]
+IMPLICIT_LINKS = [
+ [
+ {'pass': 1, 'link': LINK_FULL_A2C},
+ {'pass': 1, 'link': LINK_FULL_B2D},
+ {'pass': 1, 'link': LINK_FULL_C2E},
+ ],
+ [
+ {'pass': 2, 'link': LINK_FULL_A2D},
+ {'pass': 2, 'link': LINK_FULL_B2E},
+ ],
+ [
+ {'pass': 3, 'link': LINK_FULL_A2E},
+ ],
+ []
+]
diff --git a/app/test/fetch/link_finders/test_find_implicit_links.py b/app/test/fetch/link_finders/test_find_implicit_links.py
new file mode 100644
index 0000000..9931688
--- /dev/null
+++ b/app/test/fetch/link_finders/test_find_implicit_links.py
@@ -0,0 +1,107 @@
+###############################################################################
+# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
+# and others #
+# #
+# All rights reserved. This program and the accompanying materials #
+# are made available under the terms of the Apache License, Version 2.0 #
+# which accompanies this distribution, and is available at #
+# http://www.apache.org/licenses/LICENSE-2.0 #
+###############################################################################
+import bson
+
+from discover.link_finders.find_implicit_links import FindImplicitLinks
+from test.fetch.test_fetch import TestFetch
+from unittest.mock import MagicMock
+from test.fetch.link_finders.test_data.test_find_implicit_links import *
+
+from utils.inventory_mgr import InventoryMgr
+
+
+class TestFindImplicitLinks(TestFetch):
+
+ def setUp(self):
+ super().setUp()
+ self.configure_environment()
+ self.fetcher = FindImplicitLinks()
+ self.fetcher.set_env(ENV)
+ self.fetcher.constraint_attributes = ['network']
+ self.original_write_link = self.inv.write_link
+ self.inv.write_link = lambda x: x
+ self.original_objectid = bson.ObjectId
+ bson.ObjectId = lambda x: x
+
+ def tearDown(self):
+ super().tearDown()
+ bson.ObjectId = self.original_objectid
+ self.inv.write_link = self.original_write_link
+
+ def test_get_constraint_attributes(self):
+ original_find = InventoryMgr.find
+ InventoryMgr.find = MagicMock(return_value=CLIQUE_CONSTRAINTS)
+ constraint_types = self.fetcher.get_constraint_attributes()
+ self.assertEqual(sorted(constraint_types), sorted(CONSTRAINTS))
+ InventoryMgr.find = original_find
+
+ def test_constraints_match(self):
+ matcher = self.fetcher.constraints_match
+ self.assertTrue(matcher(LINK_ATTRIBUTES_NONE, LINK_ATTRIBUTES_NONE_2))
+ self.assertTrue(matcher(LINK_ATTRIBUTES_NONE, LINK_ATTRIBUTES_EMPTY))
+ self.assertTrue(matcher(LINK_ATTRIBUTES_NONE, LINK_ATTR_V1))
+ self.assertTrue(matcher(LINK_ATTRIBUTES_EMPTY, LINK_ATTR_V1))
+ self.assertTrue(matcher(LINK_ATTR_V1, LINK_ATTR_V1_2))
+ self.assertTrue(matcher(LINK_ATTR_V1,
+ LINK_ATTR_V1_AND_A2V2))
+ self.assertFalse(matcher(LINK_ATTR_V1, LINK_ATTR_V2))
+
+ def test_links_match(self):
+ matcher = self.fetcher.links_match
+ self.assertFalse(matcher(LINK_TYPE_1, LINK_TYPE_1_2))
+ self.assertFalse(matcher(LINK_TYPE_1, LINK_TYPE_1_REVERSED))
+ self.assertFalse(matcher(LINK_TYPE_4_NET1, LINK_TYPE_5_NET2))
+ self.assertFalse(matcher(LINK_TYPE_1_2, LINK_TYPE_2))
+ self.assertTrue(matcher(LINK_TYPE_1, LINK_TYPE_2))
+
+ def test_get_link_constraint_attributes(self):
+ getter = self.fetcher.get_link_constraint_attributes
+ self.assertEqual(getter(LINK_TYPE_1, LINK_TYPE_1_2), {})
+ self.assertEqual(getter(LINK_TYPE_1, LINK_TYPE_4_NET1),
+ LINK_TYPE_4_NET1.get('attributes'))
+ self.assertEqual(getter(LINK_TYPE_4_NET1, LINK_TYPE_1),
+ LINK_TYPE_4_NET1.get('attributes'))
+ self.assertEqual(getter(LINK_TYPE_1, LINK_TYPE_5_NET2),
+ LINK_TYPE_5_NET2.get('attributes'))
+ self.assertEqual(getter(LINK_TYPE_4_NET1, LINK_TYPE_6_NET1),
+ LINK_TYPE_4_NET1.get('attributes'))
+
+ def test_get_attr(self):
+ getter = self.fetcher.get_attr
+ self.assertIsNone(getter('host', {}, {}))
+ self.assertIsNone(getter('host', {'host': 'v1'}, {'host': 'v2'}))
+ self.assertEqual(getter('host', {'host': 'v1'}, {}), 'v1')
+ self.assertEqual(getter('host', {}, {'host': 'v2'}), 'v2')
+ self.assertEqual(getter('host', {'host': 'v1'}, {'host': 'v1'}), 'v1')
+
+ def test_add_implicit_link(self):
+ original_write_link = self.inv.write_link
+ self.inv.write_link = lambda x: x
+ original_objectid = bson.ObjectId
+ bson.ObjectId = lambda x: x
+ add_func = self.fetcher.add_implicit_link
+ self.assertEqual(add_func(LINK_TYPE_4_NET1, LINK_TYPE_6_NET1),
+ LINK_TYPE_7_NET1)
+ bson.ObjectId = original_objectid
+ self.inv.write_link = original_write_link
+
+ def test_get_transitive_closure(self):
+ self.fetcher.links = [
+ {'pass': 0, 'link': LINK_FULL_A2B},
+ {'pass': 0, 'link': LINK_FULL_B2C},
+ {'pass': 0, 'link': LINK_FULL_C2D},
+ {'pass': 0, 'link': LINK_FULL_D2E},
+ ]
+ self.fetcher.get_transitive_closure()
+ for pass_no in range(1, len(IMPLICIT_LINKS)):
+ implicit_links = [l for l in self.fetcher.links
+ if l['pass'] == pass_no]
+ self.assertEqual(implicit_links, IMPLICIT_LINKS[pass_no-1],
+ 'incorrect links for pass #{}'.format(pass_no))
diff --git a/app/test/scan/test_data/configurations.py b/app/test/scan/test_data/configurations.py
index 96dbc23..044ff0b 100644
--- a/app/test/scan/test_data/configurations.py
+++ b/app/test/scan/test_data/configurations.py
@@ -47,6 +47,7 @@ CONFIGURATIONS = {
"provision": "Deploy",
"env_type": "development",
"name": "Monitoring",
+ "install_monitoring_client": True,
"rabbitmq_port": "5672",
"rabbitmq_pass": "osdna",
"rabbitmq_user": "sensu",
diff --git a/app/test/scan/test_data/scanner.py b/app/test/scan/test_data/scanner.py
index 23838aa..500021d 100644
--- a/app/test/scan/test_data/scanner.py
+++ b/app/test/scan/test_data/scanner.py
@@ -17,6 +17,19 @@ METADATA = {
"scanners_package": "discover",
"scanners": {}
}
+LINK_FINDERS_METADATA = {
+ "finders_package": "discover.link_finders",
+ "base_finder": "FindLinks",
+ "link_finders": [
+ "FindLinksForInstanceVnics",
+ "FindLinksForOteps",
+ "FindLinksForVconnectors",
+ "FindLinksForVedges",
+ "FindLinksForVserviceVnics",
+ "FindLinksForPnics",
+ "FindImplicitLinks"
+ ]
+}
TYPE_TO_FETCH = {
"type": "host_pnic",
diff --git a/app/test/scan/test_scan_metadata_parser.py b/app/test/scan/test_scan_metadata_parser.py
index 91c11ef..5d91306 100644
--- a/app/test/scan/test_scan_metadata_parser.py
+++ b/app/test/scan/test_scan_metadata_parser.py
@@ -104,6 +104,8 @@ class TestScanMetadataParser(TestScan):
'input': METADATA_SCANNER_INCORRECT_FETCHER,
'msg': 'failed to find fetcher class f1 '
'in scanner ScanAggregate type #1'
+ ' (could not import module discover.fetchers.f1.f1: '
+ 'No module named \'discover.fetchers.f1\')'
},
{
'input': METADATA_SCANNER_WITH_INCORRECT_CHILD,
diff --git a/app/test/scan/test_scanner.py b/app/test/scan/test_scanner.py
index 4a7536e..e93a35b 100644
--- a/app/test/scan/test_scanner.py
+++ b/app/test/scan/test_scanner.py
@@ -10,6 +10,9 @@
from discover.scanner import Scanner
from test.scan.test_scan import TestScan
from unittest.mock import MagicMock, patch
+
+from discover.link_finders.find_links_metadata_parser \
+ import FindLinksMetadataParser
from discover.scan_metadata_parser import ScanMetadataParser
from test.scan.test_data.scanner import *
from monitoring.setup.monitoring_setup_manager import MonitoringSetupManager
@@ -19,7 +22,10 @@ class TestScanner(TestScan):
def setUp(self):
super().setUp()
- ScanMetadataParser.parse_metadata_file = MagicMock(return_value=METADATA)
+ ScanMetadataParser.parse_metadata_file = \
+ MagicMock(return_value=METADATA)
+ FindLinksMetadataParser.parse_metadata_file = \
+ MagicMock(return_value=LINK_FINDERS_METADATA)
self.scanner = Scanner()
self.scanner.set_env(self.env)
MonitoringSetupManager.create_setup = MagicMock()
diff --git a/app/test/verify.sh b/app/test/verify.sh
index a7ac9a2..681b5ed 100755
--- a/app/test/verify.sh
+++ b/app/test/verify.sh
@@ -11,4 +11,8 @@
set -o errexit
set -o nounset
set -o pipefail
+PYTHONPATH=$PWD/app python3 -m unittest discover -s app/test/api
+PYTHONPATH=$PWD/app python3 -m unittest discover -s app/test/event_based_scan
PYTHONPATH=$PWD/app python3 -m unittest discover -s app/test/fetch
+PYTHONPATH=$PWD/app python3 -m unittest discover -s app/test/scan
+PYTHONPATH=$PWD/app python3 -m unittest discover -s app/test/utils