Exemple #1
0
    def test_search_resource_not_found(self, _, get_oneview_client,
                                       oneview_client_mockup, request,
                                       get_config):
        self.config_obj.set('oneview_config', 'ip',
                            '10.0.0.1, 10.0.0.2, 10.0.0.3')
        self.config_obj.set('redfish', 'authentication_mode', 'session')

        get_config.return_value = self.config_obj

        client_session._set_new_client_by_token(self.redfish_token,
                                                self.ov_tokens)

        # Mocking redfish token on request property
        request.headers.get.return_value = self.redfish_token

        oneview_client_mockup.enclosures.get.side_effect = [
            self.not_found_error,  # 10.0.0.1
            self.not_found_error,  # 10.0.0.2
            self.not_found_error,  # 10.0.0.3
        ]

        get_oneview_client.return_value = oneview_client_mockup
        handler_multiple_ov = \
            handler_multiple_oneview.MultipleOneViewResource()

        with self.assertRaises(HPOneViewException):
            handler_multiple_ov.enclosures.get('UUID_1')

        get_oneview_client.assert_has_calls(
            [call("10.0.0.1"),
             call("10.0.0.2"),
             call("10.0.0.3")])
Exemple #2
0
        def check_authentication():
            # Cached OneView's connections for the same request
            g.ov_connections = dict()

            g.elapsed_time_ov = 0

            g.oneview_client = \
                handler_multiple_oneview.MultipleOneViewResource()
Exemple #3
0
    def test_searching_again_in_other_ov_when_resource_cached_is_not_found(
            self, _, get_oneview_client, oneview_client_mockup, request,
            get_config):
        self.config_obj.set('oneview_config', 'ip',
                            '10.0.0.1, 10.0.0.2, 10.0.0.3')
        self.config_obj.set('redfish', 'authentication_mode', 'session')

        get_config.return_value = self.config_obj

        client_session._set_new_client_by_token(self.redfish_token,
                                                self.ov_tokens)

        # Mocking redfish token on request property
        request.headers.get.return_value = self.redfish_token

        with open(
                'oneview_redfish_toolkit/mockups/oneview/Enclosure.json') as f:
            enclosure = json.load(f)

        oneview_client_mockup.enclosures.get.side_effect = [
            self.not_found_error,  # 10.0.0.1
            enclosure,  # 10.0.0.2 found the resource here
            self.not_found_error,  # 10.0.0.2
            self.not_found_error,  # 10.0.0.1
            enclosure,  # 10.0.0.3 found the resource here (2th time)
            self.not_found_error,  # 10.0.0.3
            self.not_found_error,  # 10.0.0.1
            self.not_found_error  # 10.0.0.2
        ]

        get_oneview_client.return_value = oneview_client_mockup
        handler_multiple_ov = \
            handler_multiple_oneview.MultipleOneViewResource()

        handler_multiple_ov.enclosures.get('UUID_1')
        mapped_ov_ip = multiple_oneview.get_ov_ip_by_resource('UUID_1')

        # Check OneView IP matchs the mapped one
        self.assertEqual(mapped_ov_ip, '10.0.0.2')
        get_oneview_client.assert_has_calls(
            [call("10.0.0.1"), call("10.0.0.2")])

        handler_multiple_ov.enclosures.get('UUID_1')
        mapped_ov_ip = multiple_oneview.get_ov_ip_by_resource('UUID_1')

        self.assertEqual(mapped_ov_ip, '10.0.0.3')
        get_oneview_client.assert_has_calls(
            [call("10.0.0.2"),
             call("10.0.0.1"),
             call("10.0.0.3")])

        with self.assertRaises(HPOneViewException):
            handler_multiple_ov.enclosures.get('UUID_1')

        get_oneview_client.assert_has_calls(
            [call("10.0.0.3"),
             call("10.0.0.1"),
             call("10.0.0.2")])
    def check_authentication():
        # If authenticating do not check for anything
        if request.url_rule and \
           request.url_rule.rule == SessionCollection.BASE_URI and \
           request.method == "POST":
            return None

        if connection.is_service_root():
            return None

        if config.auth_mode_is_session():
            x_auth_token = request.headers.get('x-auth-token')
            client_session.check_authentication(x_auth_token)

        g.oneview_client = \
            handler_multiple_oneview.MultipleOneViewResource()
Exemple #5
0
    def test_search_in_all_ov_found_on_second(self, req_context,
                                              get_oneview_client,
                                              oneview_client_mockup, request,
                                              get_config):
        # Mocking configuration read from config file
        self.config_obj.set('oneview_config', 'ip', '10.0.0.1, 10.0.0.2')
        self.config_obj.set('redfish', 'authentication_mode', 'session')

        # Mocking globals['config'] of config file
        get_config.return_value = self.config_obj

        # Mocking redfish->Oneview tokens
        client_session._set_new_client_by_token(self.redfish_token,
                                                self.ov_tokens)

        # Mocking redfish token on request property
        request.headers.get.return_value = self.redfish_token

        # Mocking OneView client call returning resource for the second
        # one, ip: 10.0.0.2
        oneview_client_mockup.server_profiles.get.side_effect = [
            self.not_found_server_profile,
            self.server_profile,
        ]

        # Mocking connection.get_oneview_client() to return mocked
        # OneView Client
        get_oneview_client.return_value = oneview_client_mockup

        # Create new handler for multiple OneView support
        handler_multiple_ov = \
            handler_multiple_oneview.MultipleOneViewResource()

        # Query resource
        handler_multiple_ov.server_profiles.get(self.sp_uuid)

        # Check if resource was queried on two of three OneViews
        oneview_client_mockup.server_profiles.get.assert_has_calls(
            [call(self.sp_uuid), call(self.sp_uuid)])

        # Check if resource was queried on first and the second OneViews
        get_oneview_client.assert_has_calls(
            [call("10.0.0.1"), call("10.0.0.2")])
Exemple #6
0
    def test_search_mapped_after_search_in_all(self, req_context,
                                               get_oneview_client,
                                               oneview_client_mockup, request,
                                               get_config):
        # Mocking configuration read from config file
        self.config_obj.set('oneview_config', 'ip',
                            '10.0.0.1, 10.0.0.2, 10.0.0.3')
        self.config_obj.set('redfish', 'authentication_mode', 'session')

        # Mocking globals['config'] of config file
        get_config.return_value = self.config_obj

        # Mocking redfish->Oneview tokens
        client_session._set_new_client_by_token(self.redfish_token,
                                                self.ov_tokens)

        # Mocking redfish token on request property
        request.headers.get.return_value = self.redfish_token

        # Mocking OneView client call returning resource just for the last
        # one, ip: 10.0.0.3
        oneview_client_mockup.server_profiles.get.side_effect = [
            self.not_found_server_profile,
            self.not_found_server_profile,
            self.server_profile,
        ]

        # Mocking connection.get_oneview_client() to return mocked
        # OneView Client
        get_oneview_client.return_value = oneview_client_mockup

        # Create new handler for multiple OneView support
        handler_multiple_ov = \
            handler_multiple_oneview.MultipleOneViewResource()

        # Query resource
        handler_multiple_ov.server_profiles.get(self.sp_uuid)

        # Check if resource was queried for all OneViews before found on
        # last one
        oneview_client_mockup.server_profiles.get.assert_has_calls(
            [call(self.sp_uuid),
             call(self.sp_uuid),
             call(self.sp_uuid)])

        # Check if resource was queried on each one for all OneViews
        get_oneview_client.assert_has_calls(
            [call("10.0.0.1"),
             call("10.0.0.2"),
             call("10.0.0.3")])

        # Mocking OneView client call returning resource
        oneview_client_mockup.server_profiles.get.side_effect = [
            self.server_profile,
        ]

        # Query resource again, now already mapped on cache
        handler_multiple_ov.server_profiles.get(self.sp_uuid)

        # Check if resource was queried on just one OneView, the mapped one
        # for the resource
        oneview_client_mockup.server_profiles.get.assert_has_calls(
            [call(self.sp_uuid)])

        # Check if resource was queried on just one OneViews that was mapped
        # for the resource
        get_oneview_client.assert_has_calls([call("10.0.0.3")])

        # Get the OneView IP mapped for the resource
        mapped_ov_ip = multiple_oneview.get_ov_ip_by_resource(self.sp_uuid)

        # Check OneView IP matchs the mapped one
        self.assertEqual(mapped_ov_ip, "10.0.0.3")