def test_get_nested_attr(self): expected_attr = Mock() intermediate_attr = Mock(spec=["expected_attr"]) containing_obj = Mock(spec=["intermediate_attr"]) intermediate_attr.expected_attr = expected_attr containing_obj.intermediate_attr = intermediate_attr existing_attr_path = ["intermediate_attr", "expected_attr"] self.assertEqual( expected_attr, utils.get_nested_attr(containing_obj, existing_attr_path)) missing_attrs_pathes = [ ["missing_attr", "expected_attr"], ["intermediate_attr", "missing_attr"], ] for attr_path in missing_attrs_pathes: self.assertIsNone(utils.get_nested_attr(containing_obj, attr_path))
def test_get_nested_attr(self): expected_attr = Mock() intermediate_attr = Mock(spec=["expected_attr"]) containing_obj = Mock(spec=["intermediate_attr"]) intermediate_attr.expected_attr = expected_attr containing_obj.intermediate_attr = intermediate_attr existing_attr_path = ["intermediate_attr", "expected_attr"] self.assertEqual( expected_attr, utils.get_nested_attr(containing_obj, existing_attr_path) ) missing_attrs_pathes = [ ["missing_attr", "expected_attr"], ["intermediate_attr", "missing_attr"], ] for attr_path in missing_attrs_pathes: self.assertIsNone( utils.get_nested_attr(containing_obj, attr_path) )
def get_info_from_os_resource_manager(client_provider, resource_name): """Use OpenStack resource manager to retrieve information about resource Utilize clients provided by client_provider instance to retrieve data for resource_name, description of which is stored in resources_description data structure. :param client_provider: objects that provides instances of openstack clients as its attributes :param resource_name: string that contains name of resource for which info should be collected from installation :returns: data that store collected info """ resource_description = resources_description[resource_name] client_name = resource_description["retrieved_from_component"] client_inst = getattr(client_provider, client_name) client_api_version = utils.get_nested_attr( client_inst, client_provider.clients_version_attr_path[client_name] ) matched_api = \ resource_description["supported_api_versions"][client_api_version] resource_manager_name = matched_api["resource_manager_name"] resource_manager = getattr(client_inst, resource_manager_name) attributes_white_list = matched_api["attributes_white_list"] additional_display_options = \ matched_api.get("additional_display_options", {}) resource_info = _get_data_from_resource_manager( resource_manager, attributes_white_list, additional_display_options ) return resource_info
def get_info_from_os_resource_manager(client_provider, resource_name): """Use OpenStack resource manager to retrieve information about resource Utilize clients provided by client_provider instance to retrieve data for resource_name, description of which is stored in resources_description data structure. :param client_provider: objects that provides instances of openstack clients as its attributes :param resource_name: string that contains name of resource for which info should be collected from installation :returns: data that store collected info """ resource_description = resources_description[resource_name] client_name = resource_description["retrieved_from_component"] client_inst = getattr(client_provider, client_name) client_api_version = utils.get_nested_attr( client_inst, client_provider.clients_version_attr_path[client_name]) matched_api = \ resource_description["supported_api_versions"][client_api_version] resource_manager_name = matched_api["resource_manager_name"] resource_manager = getattr(client_inst, resource_manager_name) attributes_white_list = matched_api["attributes_white_list"] additional_display_options = \ matched_api.get("additional_display_options", {}) resource_info = _get_data_from_resource_manager( resource_manager, attributes_white_list, additional_display_options) return resource_info