コード例 #1
0
    def test_drives_as_links_when_storage_controller_is_embedded(self):
        """Tests Drives as Links when not configured properly

            Tests if Drive Resource blocks is empty when Storage Controllers
            are not configured properly for Redfish
        """

        profile_template = copy.deepcopy(self.server_profile_template)
        profile_template["localStorage"]["controllers"] = [{
            "deviceSlot":
            "Embedded",
            "mode":
            "HBA",
            "initialize":
            True,
            "driveWriteCache":
            "Unmanaged",
            "logicalDrives":
            None
        }]
        zone_id = "1f0ca9ef-7f81-45e3-9d64-341b46cf87e0"

        zone = Zone(zone_id, profile_template, self.server_hardware_list,
                    self.enclosure_name_none, self.drives)
        result = json.loads(zone.serialize())
        self.assertEqualMockup(self.zone_without_drives_mockup, result)
コード例 #2
0
    def test_drives_with_network_and_drive_links(self):
        """Tests when all is configured properly"""

        profile_template = copy.deepcopy(self.server_profile_template)
        zone_id = "1f0ca9ef-7f81-45e3-9d64-341b46cf87e0-0000000000A66101"

        zone = Zone(zone_id, profile_template, self.server_hardware_list,
                    self.enclosure_name, self.drives)
        result = json.loads(zone.serialize())

        self.assertEqualMockup(self.zone_mockup, result)
コード例 #3
0
    def test_serialize(self):
        # Tests the serialize function result against known result
        try:
            zone = Zone(self.server_profile_template, self.available_targets)
        except Exception as e:
            self.fail("Failed to instantiate Zone class."
                      " Error: {}".format(e))

        try:
            result = json.loads(zone.serialize())
        except Exception as e:
            self.fail("Failed to serialize. Error: {}".format(e))

        self.assertEqual(self.zone_mockup, result)
コード例 #4
0
    def test_spt_when_connections_are_not_configured(self):
        """Tests Zone when connections are not set to Server Profile Template

            The Zone must have a NetworkResourceBlock even when connections
            are not set in SPT
        """

        profile_template = copy.deepcopy(self.server_profile_template)
        profile_template["connectionSettings"]["connections"] = []
        zone_id = "1f0ca9ef-7f81-45e3-9d64-341b46cf87e0-0000000000A66101"

        zone = Zone(zone_id, profile_template, self.server_hardware_list,
                    self.enclosure_name, self.drives)
        result = json.loads(zone.serialize())
        self.assertEqualMockup(self.zone_mockup, result)
コード例 #5
0
    def test_drives_as_links_when_storage_controllers_are_not_configured(self):
        """Tests Drives as Links when not configured

            Tests if Drive Resource blocks is empty when Storage Controllers
            are not configured
        """

        profile_template = copy.deepcopy(self.server_profile_template)
        profile_template["localStorage"]["controllers"] = []
        zone_id = "1f0ca9ef-7f81-45e3-9d64-341b46cf87e0"

        zone = Zone(zone_id, profile_template, self.server_hardware_list,
                    self.enclosure_name_none, self.drives)
        result = json.loads(zone.serialize())

        self.assertEqualMockup(self.zone_without_drives_mockup, result)
コード例 #6
0
def get_zone(zone_uuid):
    """Get the Redfish Zone.

        Return Resource Zone redfish JSON.

        Logs exception of any error and return Internal
        Server Error or Not Found.

        Returns:
            JSON: Redfish json with Resource Zone.
    """
    template_id, enclosure_id = ZoneService.\
        split_zone_id_to_spt_uuid_and_enclosure_id(zone_uuid)

    profile_template = g.oneview_client.server_profile_templates.get_by_id(
        template_id).data
    sh_type_uri = profile_template['serverHardwareTypeUri']
    enclosure_name = None

    if enclosure_id:
        enclosure = g.oneview_client.enclosures.get_by_id(enclosure_id).data
        enclosure_name = enclosure["name"]
        drives = _get_drives(enclosure)
        sh_filter = [
            "locationUri='{}'".format(enclosure['uri']),
            "serverHardwareTypeUri='{}'".format(sh_type_uri)
        ]
    else:
        drives = []
        enclosure_group_uri = profile_template["enclosureGroupUri"]
        sh_filter = [
            "serverGroupUri='{}'".format(enclosure_group_uri),
            "serverHardwareTypeUri='{}'".format(sh_type_uri)
        ]

    server_hardware_list = g.oneview_client.server_hardware.get_all(
        filter=sh_filter)

    volume_list = g.oneview_client.volumes.get_all()
    filter_volume_list = [
        volume for volume in volume_list if volume["isShareable"]
    ]

    # Emptying volume list to suppress external storage changes for
    # current release.
    # In future, remove this line to enable external storage support
    filter_volume_list = []

    zone_data = Zone(zone_uuid, profile_template, server_hardware_list,
                     enclosure_name, drives, filter_volume_list)

    sh_count = len(server_hardware_list)
    blocks_count = len(zone_data.redfish["Links"]["ResourceBlocks"])
    logging_service.debug(
        COUNTER_LOGGER_NAME, "Drives retrieved: " + str(len(drives)),
        "ServerHardware retrieved: " + str(sh_count),
        "ResourceBlocks listed on Zone: " + str(blocks_count))

    return ResponseBuilder.success(zone_data)
コード例 #7
0
 def test_class_instantiation(self):
     # Tests if class is correctly instantiated and validated
     try:
         zone = Zone(self.server_profile_template, self.available_targets)
     except Exception as e:
         self.fail("Failed to instantiate Zone class."
                   " Error: {}".format(e))
     self.assertIsInstance(zone, Zone)
コード例 #8
0
    def test_zone_when_external_storage_available(self):
        """Tests when all is configured properly"""

        profile_template = copy.deepcopy(self.server_profile_template)
        zone_id = "1f0ca9ef-7f81-45e3-9d64-341b46cf87e0-0000000000A66101"

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

        zone = Zone(zone_id,
                    profile_template,
                    self.server_hardware_list,
                    self.enclosure_name,
                    self.drives,
                    [])
        result = json.loads(zone.serialize())
        self.assertEqualMockup(zone_with_external_storage_mockup, result)
コード例 #9
0
def get_zone(zone_uuid):
    """Get the Redfish Zone.

        Return Resource Zone redfish JSON.

        Logs exception of any error and return Internal
        Server Error or Not Found.

        Returns:
            JSON: Redfish json with Resource Zone.
    """
    template_id, enclosure_id = ZoneService.\
        split_zone_id_to_spt_uuid_and_enclosure_id(zone_uuid)

    profile_template = g.oneview_client.server_profile_templates.get(
        template_id)
    sh_type_uri = profile_template['serverHardwareTypeUri']
    enclosure_name = None

    if enclosure_id:
        enclosure = g.oneview_client.enclosures.get(enclosure_id)
        enclosure_name = enclosure["name"]
        drives = _get_drives(enclosure)
        sh_filter = [
            "locationUri='{}'".format(enclosure['uri']),
            "serverHardwareTypeUri='{}'".format(sh_type_uri)
        ]
    else:
        drives = []
        enclosure_group_uri = profile_template["enclosureGroupUri"]
        sh_filter = [
            "serverGroupUri='{}'".format(enclosure_group_uri),
            "serverHardwareTypeUri='{}'".format(sh_type_uri)
        ]

    server_hardware_list = g.oneview_client.server_hardware.get_all(
        filter=sh_filter)

    zone_data = Zone(zone_uuid, profile_template, server_hardware_list,
                     enclosure_name, drives)

    sh_count = len(server_hardware_list)
    blocks_count = len(zone_data.redfish["Links"]["ResourceBlocks"])
    logging_service.debug(
        COUNTER_LOGGER_NAME, "Drives retrieved: " + str(len(drives)),
        "ServerHardware retrieved: " + str(sh_count),
        "ResourceBlocks listed on Zone: " + str(blocks_count))

    return ResponseBuilder.success(zone_data)
コード例 #10
0
def get_zone(uuid):
    """Get the Redfish Zone.

        Return Resource Zone redfish JSON.

        Logs exception of any error and return Internal
        Server Error or Not Found.

        Returns:
            JSON: Redfish json with Resource Zone.
    """
    profile_template = g.oneview_client.server_profile_templates.get(uuid)

    encl_group_uri = profile_template['enclosureGroupUri']
    sh_type_uri = profile_template['serverHardwareTypeUri']

    available_targets = g.oneview_client\
        .server_profiles\
        .get_available_targets(enclosureGroupUri=encl_group_uri,
                               serverHardwareTypeUri=sh_type_uri)

    zone_data = Zone(profile_template, available_targets)

    return ResponseBuilder.success(zone_data)