def test_get_flavors_detail(): api = OpenstackSDKApi(None) api.connection = MockOpenstackConnection() flavors = api.get_flavors_detail(query_params={}) for i in range(len(flavors)): for key, value in common.EXAMPLE_GET_FLAVORS_DETAIL_RETURN_VALUE[i].items(): assert value == flavors[i][key]
def test_get_networks(): api = OpenstackSDKApi(None) api.connection = MockOpenstackConnection() networks = api.get_networks() for i in range(len(networks)): for key, value in common.EXAMPLE_GET_NETWORKS_RETURN_VALUE[i].items(): assert value == networks[i][key]
def test_get_os_aggregates(): api = OpenstackSDKApi(None) api.connection = MockOpenstackConnection() aggregates = api.get_os_aggregates() for i in range(len(aggregates)): for key, value in common.EXAMPLE_GET_OS_AGGREGATES_RETURN_VALUE[i].items(): assert value == aggregates[i][key]
def test_get_project_limit(): api = OpenstackSDKApi(None) api.connection = MockOpenstackConnection() assert api.get_project_limits(u'680031a39ce040e1b81289ea8c73fb11') == common.EXAMPLE_GET_PROJECT_LIMITS_RETURN_VALUE with pytest.raises(SDKException): api.get_project_limits('invalid_id')
def test_get_os_hypervisors_detail(): api = OpenstackSDKApi(None) api.connection = MockOpenstackConnection() assert api.get_os_hypervisors_detail() == common.EXAMPLE_GET_OS_HYPERVISORS_RETURN_VALUE
def test_get_project(): api = OpenstackSDKApi(None) api.connection = MockOpenstackConnection() assert api.get_projects() == EXAMPLE_PROJECTS_VALUE
def test_get_endpoint(): api = OpenstackSDKApi(None) with pytest.raises(AuthenticationNeeded): api._check_authentication() api.connection = MockOpenstackConnection() assert api.get_keystone_endpoint() == u'http://10.0.3.44:5000/v3/endpoints/a536052eba574bd4baf89ff83e3a23db' assert api.get_nova_endpoint() == u'http://10.0.3.44:5000/v3/endpoints/0adb9d108440437fa6841d31a989ed89' assert api.get_neutron_endpoint() == u'http://10.0.3.44:5000/v3/endpoints/408fbfd00abf4bd1a71044f4849abf66' # Test cache assert api.get_keystone_endpoint() == u'http://10.0.3.44:5000/v3/endpoints/a536052eba574bd4baf89ff83e3a23db' assert api.get_nova_endpoint() == u'http://10.0.3.44:5000/v3/endpoints/0adb9d108440437fa6841d31a989ed89' assert api.get_neutron_endpoint() == u'http://10.0.3.44:5000/v3/endpoints/408fbfd00abf4bd1a71044f4849abf66' with mock.patch('datadog_checks.openstack_controller.api.OpenstackSDKApi._get_service', return_value={u'id': 'invalid_id'}): api.endpoints = {} with pytest.raises(KeystoneUnreachable): api.get_keystone_endpoint() with pytest.raises(MissingNovaEndpoint): api.get_nova_endpoint() with pytest.raises(MissingNeutronEndpoint): api.get_neutron_endpoint()