def get_service_root():
    """Gets ServiceRoot

        Recover OneView UUID from appliance and creates
        ServiceRoot redfish JSON
    """

    try:
        ov_ip = config.get_oneview_multiple_ips()[0]
        appliance_node_information = \
            connection.request_oneview(ov_ip,
                                       '/rest/appliance/nodeinfo/version')
        uuid = appliance_node_information['uuid']

        sr = ServiceRoot(uuid)
        json_str = sr.serialize()
        return Response(response=json_str,
                        status=200,
                        mimetype='application/json')
    except HPOneViewException as e:
        if e.oneview_response['errorCode'] == "RESOURCE_NOT_FOUND":
            logging.exception("Resource not found: {}".format(e))
            abort(status.HTTP_404_NOT_FOUND, "Appliance not found")
        else:
            logging.exception("OneView Exception: {}".format(e))
            abort(status.HTTP_500_INTERNAL_SERVER_ERROR)
    except Exception as e:
        logging.exception('ServiceRoot error: {}'.format(e))
        abort(status.HTTP_500_INTERNAL_SERVER_ERROR)
    def test_when_auth_mode_is_session(self, config_mock):
        config_mock.return_value = "session"

        service_root = ServiceRoot('00000000-0000-0000-0000-000000000000')
        result = json.loads(service_root.serialize())

        self.assertEqualMockup(self.service_root_mockup, result)
    def test_when_auth_mode_is_conf(self, config_mock):
        config_mock.return_value = "conf"

        service_root = ServiceRoot('00000000-0000-0000-0000-000000000000')
        result = json.loads(service_root.serialize())

        self.service_root_mockup['Links']['Sessions'] = {}

        self.assertEqualMockup(self.service_root_mockup, result)
示例#4
0
    def test_serialize(self):
        """Tests the serialize function result against known result"""

        service_root = ServiceRoot('00000000-0000-0000-0000-000000000000')
        result = json.loads(service_root.serialize())

        with open(
            'oneview_redfish_toolkit/mockups/redfish/ServiceRoot.json'
        ) as f:
            service_root_mockup = json.load(f)
        self.assertEqual(service_root_mockup, result)
示例#5
0
    def test_when_auth_mode_is_session(self, config_mock):
        config_mock.return_value = "session"

        service_root = ServiceRoot('00000000-0000-0000-0000-000000000000')
        result = json.loads(service_root.serialize())

        with open(
            'oneview_redfish_toolkit/mockups/redfish/ServiceRoot.json'
        ) as f:
            service_root_mockup = json.load(f)

        self.assertEqualMockup(service_root_mockup, result)
示例#6
0
    def test_class_instantiation(self):
        """Tests class instantiation and validation"""

        try:
            service_root = ServiceRoot('00000000-0000-0000-0000-000000000000')
        except Exception as e:
            self.fail("Failed to instantiate service root. Error: ".format(e))
        self.assertIsInstance(service_root, ServiceRoot)
示例#7
0
    def test_serialize(self, config_mock):
        """Tests the serialize function result against known result"""
        def side_effect(section, option):
            if section == "redfish" and option == "authentication_mode":
                return "conf"
            else:
                return util.config.get(section, option)

        config_mock.get.side_effect = side_effect

        service_root = ServiceRoot('00000000-0000-0000-0000-000000000000')
        result = json.loads(service_root.serialize())

        with open('oneview_redfish_toolkit/mockups/redfish/ServiceRoot.json'
                  ) as f:
            service_root_mockup = json.load(f)
        self.assertEqual(service_root_mockup, result)