def do_query_side_effect(*args): if args[0] == TEST_QUERIES.NODES_PMM_MEMORY_MODE: return create_json_fixture_mock('prometheus_nodes_pmm_memory_mode').json()['data']['result'] elif args[0] == TEST_QUERIES.NODE_CAPACITY_RESOURCES_QUERY_MAP[ResourceType.MEMBW_READ]: return create_json_fixture_mock('prometheus_membw_capacity_read').json()['data']['result'] elif args[0] == TEST_QUERIES.NODE_CAPACITY_RESOURCES_QUERY_MAP[ResourceType.MEMBW_WRITE]: return create_json_fixture_mock('prometheus_membw_capacity_write').json()['data']['result'] elif args[0] == TEST_QUERIES.NODE_CAPACITY_RESOURCES_QUERY_MAP[ResourceType.WSS]: return create_json_fixture_mock('prometheus_node_capacity_mem_wss').json()['data']['result'] elif args[0] == TEST_QUERIES.APP_REQUESTED_RESOURCES_QUERY_MAP[ResourceType.CPU]: return create_json_fixture_mock( 'prometheus_app_requested_cpu').json()['data']['result'] elif args[0] == TEST_QUERIES.APP_REQUESTED_RESOURCES_QUERY_MAP[ResourceType.MEM]: return create_json_fixture_mock( 'prometheus_app_requested_mem').json()['data']['result'] elif args[0] == TEST_QUERIES.APP_REQUESTED_RESOURCES_QUERY_MAP[ResourceType.MEMBW_READ]: return create_json_fixture_mock( 'prometheus_app_requested_membw_read').json()['data']['result'] elif args[0] == TEST_QUERIES.APP_REQUESTED_RESOURCES_QUERY_MAP[ResourceType.MEMBW_WRITE]: return create_json_fixture_mock( 'prometheus_app_requested_membw_write').json()['data']['result'] elif args[0] == TEST_QUERIES.APP_REQUESTED_RESOURCES_QUERY_MAP[ResourceType.WSS]: return create_json_fixture_mock( 'prometheus_app_requested_wss').json()['data']['result'] elif args[0] == TEST_QUERIES.NODES_DRAM_HIT_RATIO: return create_json_fixture_mock('prometheus_nodes_dram_hit_ratio').json()['data']['result'] else: return []
def do_query_side_effect(*args, **kwargs): if args[0] == ClusterScoreDataProvider.app_profiles_query: return create_json_fixture_mock( 'prometheus_app_profile').json()['data']['result'] elif args[0] == ClusterScoreDataProvider.node_type_query: return create_json_fixture_mock( 'prometheus_node_type').json()['data']['result'] else: return do_query_side_effect_cluster_dp(*args)
# See the License for the specific language governing permissions and # limitations under the License. from unittest.mock import patch import pytest import requests from wca.config import ValidationError from wca.mesos import MesosNode, MesosTask from wca.nodes import TaskSynchronizationException from tests.testing import create_json_fixture_mock, create_open_mock @patch('requests.post', return_value=create_json_fixture_mock('mesos_get_state', __file__)) @patch('wca.mesos.find_cgroup', return_value='mesos/120-123') def test_get_tasks(find_cgroup_mock, post_mock): node = MesosNode() tasks = set(node.get_tasks() ) # Wrap with set to make sure that hash is implemented. assert len(tasks) == 1 task = tasks.pop() assert task == MesosTask( agent_id='e88fac89-2398-4e75-93f3-88cf4c35ec03-S9', cgroup_path='mesos/120-123', subcgroups_paths=[], container_id='ceab3bec-9282-43aa-b05f-095736cc169e', executor_id=
"""Creates kubernetes task.""" return KubernetesTask( name=name, task_id='task_id-' + name, qos=qos, labels={'exampleKey': 'value', QOS_LABELNAME: qos}, resources={'requests_cpu': 0.25, 'requests_memory': float(64*1024**2), 'cpus': 0.25, 'mem': float(64 * 1024 ** 2)}, cgroup_path='/kubepods/{}/pod{}'.format(qos, name), subcgroups_paths=['/kubepods/{}/pod{}/t1'.format(qos, name), '/kubepods/{}/pod{}/t2'.format(qos, name)]) @patch('requests.get', return_value=create_json_fixture_mock('kubernetes_get_state', __file__)) def test_get_tasks(get_mock): expected_tasks = [KubernetesTask( name='test', task_id='4d6a81df-3448-11e9-8e1d-246e96663c22', qos='burstable', labels={'exampleKey': 'value', QOS_LABELNAME: 'burstable'}, resources={'requests_cpu': 0.25, 'requests_memory': float(64*1024**2), 'cpus': 0.25, 'mem': float(64 * 1024 ** 2)}, cgroup_path='/kubepods/burstable/pod4d6a81df' '-3448-11e9-8e1d-246e96663c22', subcgroups_paths=['/kubepods/burstable/pod4d' '6a81df-3448-11e9-8e1d-246'
def request_kubeapi_side_effect(*args): if args[0] == '/api/v1/nodes': return create_json_fixture_mock('kubeapi_nodes').json() # CHANGE IT elif args[0] == '/api/v1/namespaces/default/pods': return create_json_fixture_mock('kubeapi_default_ns_pods').json()
}, resources={ 'requests_cpu': 0.25, 'requests_memory': float(64 * 1024**2), 'cpus': 0.25, 'mem': float(64 * 1024**2) }, cgroup_path='/kubepods/{}/pod{}'.format(qos, name), subcgroups_paths=[ '/kubepods/{}/pod{}/t1'.format(qos, name), '/kubepods/{}/pod{}/t2'.format(qos, name) ]) @patch('requests.get', return_value=create_json_fixture_mock('kubernetes_get_state', __file__)) @patch('os.path.exists', return_value=True) def test_get_tasks(mock_path_exists, get_mock): expected_tasks = [ KubernetesTask(name='default/test', task_id='4d6a81df-3448-11e9-8e1d-246e96663c22', qos='burstable', labels={ 'exampleKey': 'value', QOS_LABELNAME: 'burstable' }, resources={ 'requests_cpu': 0.25, 'requests_memory': float(64 * 1024**2), 'cpus': 0.25, 'mem': float(64 * 1024**2)
@pytest.mark.parametrize('host, score', ( (0, 1), (0, 1.1), (0, 'node1'), ('node1', 1.1), ('node1', '1'), ('node1', '1.1'), )) def test_improper_host_priority(host, score): with pytest.raises(ValidationError): HostPriority(host, score) POD = create_json_fixture_mock('kubeapi_single_pod').json() NODE_NAMES = ['node1', 'node2'] @pytest.mark.parametrize('nodes, pod, node_names', ( ([{}, {}], POD, NODE_NAMES), ([{}], POD, NODE_NAMES), )) def test_extender_args_unsupported_case_with_nodes(nodes, pod, node_names): with pytest.raises(UnsupportedCase): ExtenderArgs(nodes, pod, node_names) @pytest.mark.parametrize('nodes, pod, node_names', ((None, POD, NODE_NAMES), )) def test_extender_args_correct_data(nodes, pod, node_names): ExtenderArgs(nodes, pod, node_names)
# See the License for the specific language governing permissions and # limitations under the License. from unittest.mock import patch import pytest import requests from wca.config import ValidationError from wca.mesos import MesosNode, MesosTask from wca.nodes import TaskSynchronizationException from tests.testing import create_json_fixture_mock, create_open_mock @patch('requests.post', return_value=create_json_fixture_mock('mesos_get_state', __file__)) @patch('wca.mesos.find_cgroup', return_value='mesos/120-123') def test_get_tasks(find_cgroup_mock, post_mock): node = MesosNode() tasks = set(node.get_tasks()) # Wrap with set to make sure that hash is implemented. assert len(tasks) == 1 task = tasks.pop() assert task == MesosTask( agent_id='e88fac89-2398-4e75-93f3-88cf4c35ec03-S9', cgroup_path='mesos/120-123', subcgroups_paths=[], container_id='ceab3bec-9282-43aa-b05f-095736cc169e', executor_id='thermos-root-staging14-cassandra--9043-0-9ee9fbf1-b51b-4bb3-9748-6a4327fd7e0e', executor_pid=32620,